Package com.lightcrafts.jai.opimage

Examples of com.lightcrafts.jai.opimage.CachedImage


            ImageLayout cacheLayout = new ImageLayout(0, 0, rgbImage.getWidth(), rgbImage.getHeight(),
                                     0, 0, JAIContext.TILE_WIDTH, JAIContext.TILE_HEIGHT,
                                     colorModel.createCompatibleSampleModel(JAIContext.TILE_WIDTH, JAIContext.TILE_HEIGHT),
                                     colorModel);

            final CachedImage cache = new CachedImage(cacheLayout, JAIContext.fileCache);

            long tilingTime = System.currentTimeMillis();

            Rectangle bounds = cache.getBounds();
            bounds.translate(rgbImage.getMinX(), rgbImage.getMinY());
            final Point[] tileIndices = rgbImage.getTileIndices(bounds);

            // rgbImage.queueTiles(tileIndices);

            int processors = Runtime.getRuntime().availableProcessors();

            if (processors > 1) {
                Thread threads[] = new Thread[processors];

                final PlanarImage image = rgbImage;

                final Point jobs[][] = new Point[processors][];
                int k = 0;

                for (int i = 0; i < processors; i++) {
                    if (i < processors - 1)
                        jobs[i] = new Point[tileIndices.length/processors];
                    else
                        jobs[i] = new Point[tileIndices.length - (processors - 1) * (tileIndices.length/processors)];

                    for (int j = 0; j < jobs[i].length; j++)
                        jobs[i][j] = tileIndices[k++];
                }

                for (int i = 0; i < processors; i++) {
                    final Point job[] = jobs[i];
                    Runnable runnable = new Runnable() {
                        public void run() {
                            for (Point ti : job) {
                                Raster tile = image.getTile(ti.x, ti.y);
                                tile = tile.createTranslatedChild(tile.getMinX()-image.getMinX(),
                                                                  tile.getMinY()-image.getMinY());
                                cache.setData(tile);
                            }
                        }
                    };

                    threads[i] = new Thread(runnable, "RAW Processor " + i);
                    threads[i].start();
                }
                for (int i = 0; i < processors; i++) {
                    try {
                        threads[i].join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            } else {
                for (Point ti : tileIndices) {
                    Raster tile = rgbImage.getTile(ti.x, ti.y);
                    tile = tile.createTranslatedChild(tile.getMinX()-rgbImage.getMinX(), tile.getMinY()-rgbImage.getMinY());
                    cache.setData(tile);
                }
            }

            System.out.println("retiling: " + (System.currentTimeMillis() - tilingTime));

            rgbImage = cache;
        } else {
            ImageLayout layout = new ImageLayout(0, 0, dcrawImage.getWidth(), dcrawImage.getHeight(),
                                     0, 0, JAIContext.TILE_WIDTH, JAIContext.TILE_HEIGHT,
                                     colorModel.createCompatibleSampleModel(JAIContext.TILE_WIDTH, JAIContext.TILE_HEIGHT),
                                     colorModel);

            CachedImage cache = new CachedImage(layout, JAIContext.fileCache);

            for (int x = 0; x <= cache.getMaxTileX(); x++)
                for (int y = 0; y <= cache.getMaxTileY(); y++) {
                    Functions.copyData(cache.getWritableTile(x, y), dcrawImage.getRaster());
                }

             rgbImage = cache;
        }

View Full Code Here


                if (operation.isActive() /* && !(inactive && operation.isDeactivatable()) */) {
                    PlanarImage result = operation.render(processedImage, scaleFactor < 1 ? scaleFactor : 1);
                    if (result != null) {
                        Point[] indices = result.getTileIndices(area);
                        if (indices != null) {
                            CachedImage cachedResult = new CachedImage(new ImageLayout(result), JAIContext.fileCache);

                            result.prefetchTiles(indices);
                            for (Point tile : indices) {
                                Raster newTile = result.getTile(tile.x, tile.y);
                                WritableRaster cachedTile = cachedResult.getWritableTile(tile.x, tile.y);
                                Functions.copyData(cachedTile, newTile);
                            }

                            result = cachedResult;
                        }
View Full Code Here

            0, 0, m_width, m_height, 0, 0, JAIContext.TILE_WIDTH,
            JAIContext.TILE_HEIGHT, tsm, ccm
        );

        // The output image itself, directly allocated in the file cache.
        final CachedImage image =
            new CachedImage( layout, JAIContext.fileCache );

        // Load Image Data
        int tileY = 0;
        int totalLinesRead = 0;
        while ( totalLinesRead < m_height ) {
            if ( thread != null && thread.isCanceled() )
                throw new UserCanceledException();
            final int tileHeight =
                Math.min( JAIContext.TILE_HEIGHT, m_height - totalLinesRead );

            // Wrap the data buffer with a Raster representing the input data.
            final WritableRaster raster = Raster.createWritableRaster(
                jpegTsm, db, new Point( 0, tileY * JAIContext.TILE_HEIGHT )
            );

            final int linesRead = readScanLines(
                ((DataBufferByte)db).getData(), 0, tileHeight
            );
            if ( linesRead <= 0 ) {
                System.out.println("Problem with readScanLines, returned: " + linesRead );
                break;
            }

            if ( m_hasAdobeSegment && m_colorsPerPixel == 4 ) {
                //
                // CMYK JPEG images generated by Photoshop are inverted, so we
                // have to invert the data to make it look right.
                //
                final byte data[] = ((DataBufferByte) db).getData();
                for (int i = 0; i < data.length; i++)
                    data[i] = (byte)~data[i];
            }

            totalLinesRead += linesRead;
            tileY++;

            image.setData( raster );

            if ( indicator != null )
                indicator.incrementBy( linesRead );
        }
        if ( indicator != null )
View Full Code Here

        out.close();

        // Add thumbnail data for the browser:
        RenderedImage thumb = engine.getRendering(new Dimension(320, 320));
        // divorce the preview from the document
        thumb = new CachedImage((PlanarImage) thumb, JAIContext.fileCache);
        ImageInfo info = ImageInfo.getInstanceFor(file);
        LZNImageType.INSTANCE.putImage(info, thumb);

        // Cache a high resolution preview:
        int size = PreviewUpdater.PreviewSize;
        RenderedImage preview = engine.getRendering(new Dimension(size, size));
        // divorce the preview from the document
        preview = new CachedImage((PlanarImage) preview, JAIContext.fileCache);
        PreviewUpdater.cachePreviewForImage(file, preview);
    }
View Full Code Here

                pb.add(transposeAngle);
                RenderedOp transposed = JAI.create("Transpose", pb, null);
                transposed.setProperty(JAIContext.PERSISTENT_CACHE_TAG, Boolean.TRUE);
                // sourceImage = transposed;

                CachedImage cache = new CachedImage(new ImageLayout(transposed), JAIContext.fileCache);

                // Fast hack for daya copy, assumes that images have identical layout
                for (int x = 0; x <= cache.getMaxTileX(); x++)
                    for (int y = 0; y <= cache.getMaxTileY(); y++) {
                        if (transposed.getSampleModel().getDataType() == DataBuffer.TYPE_USHORT) {
                            short[] srcData = ((DataBufferUShort) transposed.getTile(x, y).getDataBuffer()).getData();
                            short[] dstData = ((DataBufferUShort) cache.getWritableTile(x, y).getDataBuffer()).getData();
                            System.arraycopy(srcData, 0, dstData, 0, srcData.length);
                        } else if (transposed.getSampleModel().getDataType() == DataBuffer.TYPE_BYTE) {
                            byte[] srcData = ((DataBufferByte) transposed.getTile(x, y).getDataBuffer()).getData();
                            byte[] dstData = ((DataBufferByte) cache.getWritableTile(x, y).getDataBuffer()).getData();
                            System.arraycopy(srcData, 0, dstData, 0, srcData.length);
                        } else
                            throw new IllegalArgumentException("Unknown image data type: " + transposed.getSampleModel().getDataType());
                        // transposed.copyData(cache.getWritableTile(x, y));
                    }
View Full Code Here

                                                   0, 0,
                                                   JAIContext.TILE_WIDTH, JAIContext.TILE_HEIGHT,
                                                   tsm, imageCcm);

        // The output image itself, directly allocated in the file cache
        CachedImage image = new CachedImage(layout, JAIContext.fileCache);

        final int maxTileX = image.getNumXTiles();

        ProgressIndicator indicator = null;
        if ( thread != null )
            indicator = thread.getProgressIndicator();
        if ( indicator != null )
            indicator.setMaximum( tf.tiles );

        int bandList[] = new int[tf.samplesPerPixel];
        for (int i = 0; i < tf.samplesPerPixel; i++)
            bandList[i] = i;

        Rectangle imageBounds = new Rectangle(0, 0, tf.imageWidth, tf.imageHeight);

        for ( int tile = 0; tile < tf.tiles; tile++ ) {
            if ( thread != null && thread.isCanceled() )
                throw new UserCanceledException();
            final int tileX = tf.tiled ? tile % maxTileX : 0;
            final int tileY = tf.tiled ? tile / maxTileX : tile;

            // The actual tile bounds, clipping on the image bounds
            Rectangle tileBounds = new Rectangle(tileX * tf.tiffTileWidth,
                                                 tileY * tf.tiffTileHeight,
                                                 tf.tiffTileWidth,
                                                 tf.tiffTileHeight).intersection(imageBounds);

            // the corresponding tile data
            int tileData = (tf.samplesPerPixel / tf.planes) * tileBounds.width * tileBounds.height * (tf.bitsPerSample == 8 ? 1 : 2);

            /* If the TIFF image is tiled and it doesn't have an alpha channel
               then we can read directly into the destination image buffer,
               don't allocate an intermediate raster */

            WritableRaster raster =
                    !tf.tiled || tf.hasAlpha
                    ? Raster.createWritableRaster(tf.tiffTsm, db, new Point(tileBounds.x, tileBounds.y))
                    : null;

            for ( int plane = 0; plane < tf.planes; plane++ ) {
                if ( tf.tiled ) {
                    if (!tf.hasAlpha)
                        raster = image.getWritableTile( tileX, tileY );

                    if ( tf.bitsPerSample == 8 ) {
                        final byte[] buffer =
                            ((DataBufferByte)raster.getDataBuffer()).getData(
                                plane );
                        int read = readTileByte( tile + plane * tf.tiles, buffer, 0, tileData );
                        if (read != tileData)
                            throw new LCImageLibException("Broken TIFF File");
                    } else {
                        final short[] buffer =
                            ((DataBufferUShort)raster.getDataBuffer()).getData(
                                plane );
                        int read = readTileShort( tile + plane * tf.tiles, buffer, 0, tileData );
                        if (read != tileData)
                            throw new LCImageLibException("Broken TIFF File");
                    }
                } else {
                    if ( tf.bitsPerSample == 8 ) {
                        final byte[] buffer =
                            ((DataBufferByte)db).getData( plane );
                        int read = readStripByte( tileY + plane * tf.tiles, buffer, 0, tileData );
                        if (read != tileData)
                            throw new LCImageLibException("Broken TIFF File");
                    } else {
                        final short[] buffer =
                            ((DataBufferUShort)db).getData( plane );
                        int read = readStripShort( tileY + plane * tf.tiles, buffer, 0, tileData );
                        if (read != tileData)
                            throw new LCImageLibException("Broken TIFF File");
                    }
                }
            }
            if (!tf.tiled || tf.hasAlpha)
                image.setData(raster.createChild(raster.getMinX(), raster.getMinY(),
                                                 raster.getWidth(), raster.getHeight(),
                                                 raster.getMinX(), raster.getMinY(),
                                                 bandList));
            if ( indicator != null )
                indicator.incrementBy( 1 );
View Full Code Here

            Document doc = Application.createDocumentHeadless(file);
            Engine engine = doc.getEngine();
            Dimension dim = new Dimension(size, size);
            RenderedImage preview = engine.getRendering(dim);
            // divorce the preview from the document
            preview = new CachedImage(
                (PlanarImage) preview, JAIContext.fileCache
            );
            doc.dispose();
            return preview;
        }
View Full Code Here

TOP

Related Classes of com.lightcrafts.jai.opimage.CachedImage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.