Changeset 1217


Ignore:
Timestamp:
08/03/06 14:18:22 (14 years ago)
Author:
curtis
Message:

Use new TiffTools.overwriteIFDValue method to update TIFF comment.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils/EditOMETIFF.java

    r1181 r1217  
    33// 
    44 
    5 import java.awt.image.BufferedImage; 
    65import java.io.*; 
    76import java.util.Hashtable; 
    8 import loci.formats.*; 
    9 import loci.formats.in.TiffReader; 
    10 import loci.formats.out.TiffWriter; 
     7import loci.formats.RandomAccessStream; 
     8import loci.formats.TiffTools; 
    119 
    1210/** Allows raw user OME-XML comment editing for the given OME-TIFF files. */ 
     
    1816      return; 
    1917    } 
    20     TiffReader opener = new TiffReader(); 
    21     TiffWriter saver = new TiffWriter(); 
    22     BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 
     18    BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); 
    2319    for (int i=0; i<args.length; i++) { 
    2420      String f = args[i]; 
    25       String nf = "new-" + f; 
    26       System.out.print("Reading " + f + " "); 
     21      System.out.println("Reading " + f + " "); 
    2722      RandomAccessStream fin = new RandomAccessStream(f); 
    2823      Hashtable ifd = TiffTools.getFirstIFD(fin); 
    2924      fin.close(); 
     25      if (ifd == null) System.out.println("Warning: first IFD is null!"); 
    3026      String ome = (String) 
    3127        TiffTools.getIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION); 
     
    3430      System.out.println(ome); 
    3531      System.out.println("Enter new OME-XML block (no line breaks):"); 
    36       String xml = in.readLine(); 
     32      String xml = cin.readLine(); 
    3733      System.out.print("Saving " + f); 
    38       int num = opener.getImageCount(f); 
    39       for (int j=0; j<num; j++) { 
    40         System.out.print("."); 
    41         BufferedImage img = opener.openImage(f, j); 
    42  
    43         ifd = new Hashtable(); 
    44         if (j == 0) { 
    45           // update OME-XML block 
    46           TiffTools.putIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION, xml); 
    47         } 
    48  
    49         // write file to disk 
    50         saver.saveImage(nf, img, ifd, j == num - 1); 
    51       } 
    52       File oldFile = new File(f); 
    53       File newFile = new File(nf); 
    54       oldFile.delete(); 
    55       newFile.renameTo(oldFile); 
     34      RandomAccessFile raf = new RandomAccessFile(args[i], "rw"); 
     35      TiffTools.overwriteIFDValue(raf, 0, TiffTools.IMAGE_DESCRIPTION, xml); 
     36      raf.close(); 
    5637      System.out.println(" [done]"); 
    5738    } 
Note: See TracChangeset for help on using the changeset viewer.