< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFImageWriter.java

Print this page




2420             }
2421 
2422             if(colorModel == null) {
2423                 colorModel = image.getColorModel();
2424             }
2425         }
2426 
2427         this.imageType = new ImageTypeSpecifier(colorModel, sampleModel);
2428 
2429         ImageUtil.canEncodeImage(this, this.imageType);
2430 
2431         // Compute output dimensions
2432         int destWidth = (sourceWidth + periodX - 1)/periodX;
2433         int destHeight = (sourceHeight + periodY - 1)/periodY;
2434         if (destWidth <= 0 || destHeight <= 0) {
2435             throw new IllegalArgumentException("Empty source region!");
2436         }
2437 
2438         clearAbortRequest();
2439         processImageStarted(0);




2440 
2441         // Optionally write the header.
2442         if (writeHeader) {
2443             // Clear previous stream metadata.
2444             this.streamMetadata = null;
2445 
2446             // Try to convert non-null input stream metadata.
2447             if (sm != null) {
2448                 this.streamMetadata =
2449                     (TIFFStreamMetadata)convertStreamMetadata(sm, param);
2450             }
2451 
2452             // Set to default if not converted.
2453             if(this.streamMetadata == null) {
2454                 this.streamMetadata =
2455                     (TIFFStreamMetadata)getDefaultStreamMetadata(param);
2456             }
2457 
2458             // Write the header.
2459             writeHeader();


2572             for (int ti = 0; ti < tilesAcross; ti++) {
2573                 long pos = stream.getStreamPosition();
2574 
2575                 // Write the (possibly compressed) tile data
2576 
2577                 Rectangle tileRect =
2578                     new Rectangle(sourceXOffset + ti*tileWidth*periodX,
2579                                   sourceYOffset + tj*tileLength*periodY,
2580                                   tileWidth*periodX,
2581                                   tileLength*periodY);
2582 
2583                 try {
2584                     int byteCount = writeTile(tileRect, compressor);
2585 
2586                     if(pos + byteCount > nextSpace) {
2587                         nextSpace = pos + byteCount;
2588                     }
2589 
2590                     pixelsDone += tileRect.width*tileRect.height;
2591                     processImageProgress(100.0F*pixelsDone/totalPixels);




2592 
2593                     // Fill in the offset and byte count for the file
2594                     stream.mark();
2595                     stream.seek(stripOrTileOffsetsPosition);
2596                     stream.writeInt((int)pos);
2597                     stripOrTileOffsetsPosition += 4;
2598 
2599                     stream.seek(stripOrTileByteCountsPosition);
2600                     stream.writeInt(byteCount);
2601                     stripOrTileByteCountsPosition += 4;
2602                     stream.reset();
2603                 } catch (IOException e) {
2604                     throw new IIOException("I/O error writing TIFF file!", e);
2605                 }
2606 
2607                 if (abortRequested()) {
2608                     processWriteAborted();
2609                     return;
2610                 }
2611             }
2612         }
2613 
2614         processImageComplete();
2615         currentImage++;
2616     }
2617 
2618     public boolean canWriteSequence() {
2619         return true;
2620     }
2621 
2622     public void prepareWriteSequence(IIOMetadata streamMetadata)
2623         throws IOException {
2624         if (getOutput() == null) {
2625             throw new IllegalStateException("getOutput() == null!");
2626         }
2627 
2628         // Set up stream metadata.
2629         if (streamMetadata != null) {




2420             }
2421 
2422             if(colorModel == null) {
2423                 colorModel = image.getColorModel();
2424             }
2425         }
2426 
2427         this.imageType = new ImageTypeSpecifier(colorModel, sampleModel);
2428 
2429         ImageUtil.canEncodeImage(this, this.imageType);
2430 
2431         // Compute output dimensions
2432         int destWidth = (sourceWidth + periodX - 1)/periodX;
2433         int destHeight = (sourceHeight + periodY - 1)/periodY;
2434         if (destWidth <= 0 || destHeight <= 0) {
2435             throw new IllegalArgumentException("Empty source region!");
2436         }
2437 
2438         clearAbortRequest();
2439         processImageStarted(0);
2440         if (abortRequested()) {
2441             processWriteAborted();
2442             return;
2443         }
2444 
2445         // Optionally write the header.
2446         if (writeHeader) {
2447             // Clear previous stream metadata.
2448             this.streamMetadata = null;
2449 
2450             // Try to convert non-null input stream metadata.
2451             if (sm != null) {
2452                 this.streamMetadata =
2453                     (TIFFStreamMetadata)convertStreamMetadata(sm, param);
2454             }
2455 
2456             // Set to default if not converted.
2457             if(this.streamMetadata == null) {
2458                 this.streamMetadata =
2459                     (TIFFStreamMetadata)getDefaultStreamMetadata(param);
2460             }
2461 
2462             // Write the header.
2463             writeHeader();


2576             for (int ti = 0; ti < tilesAcross; ti++) {
2577                 long pos = stream.getStreamPosition();
2578 
2579                 // Write the (possibly compressed) tile data
2580 
2581                 Rectangle tileRect =
2582                     new Rectangle(sourceXOffset + ti*tileWidth*periodX,
2583                                   sourceYOffset + tj*tileLength*periodY,
2584                                   tileWidth*periodX,
2585                                   tileLength*periodY);
2586 
2587                 try {
2588                     int byteCount = writeTile(tileRect, compressor);
2589 
2590                     if(pos + byteCount > nextSpace) {
2591                         nextSpace = pos + byteCount;
2592                     }
2593 
2594                     pixelsDone += tileRect.width*tileRect.height;
2595                     processImageProgress(100.0F*pixelsDone/totalPixels);
2596                     if (abortRequested()) {
2597                         processWriteAborted();
2598                         return;
2599                     }
2600 
2601                     // Fill in the offset and byte count for the file
2602                     stream.mark();
2603                     stream.seek(stripOrTileOffsetsPosition);
2604                     stream.writeInt((int)pos);
2605                     stripOrTileOffsetsPosition += 4;
2606 
2607                     stream.seek(stripOrTileByteCountsPosition);
2608                     stream.writeInt(byteCount);
2609                     stripOrTileByteCountsPosition += 4;
2610                     stream.reset();
2611                 } catch (IOException e) {
2612                     throw new IIOException("I/O error writing TIFF file!", e);





2613                 }
2614             }
2615         }
2616 
2617         processImageComplete();
2618         currentImage++;
2619     }
2620 
2621     public boolean canWriteSequence() {
2622         return true;
2623     }
2624 
2625     public void prepareWriteSequence(IIOMetadata streamMetadata)
2626         throws IOException {
2627         if (getOutput() == null) {
2628             throw new IllegalStateException("getOutput() == null!");
2629         }
2630 
2631         // Set up stream metadata.
2632         if (streamMetadata != null) {


< prev index next >