📄 blkimgdatasrcimageproducer.java
字号:
/* * CVS identifier: * * $Id: BlkImgDataSrcImageProducer.java,v 1.13 2000/12/04 17:18:54 grosbois Exp $ * * Class: BlkImgDataSrcImageProducer * * Description: Creates an Java AWT ImapeProducer from a * BlkImgDataSrc * * * * COPYRIGHT: * * This software module was originally developed by Rapha雔 Grosbois and * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel * Askel鰂 (Ericsson Radio Systems AB); and Bertrand Berthelot, David * Bouchard, F閘ix Henry, Gerard Mozelle and Patrice Onno (Canon Research * Centre France S.A) in the course of development of the JPEG2000 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This * software module is an implementation of a part of the JPEG 2000 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio * Systems AB and Canon Research Centre France S.A (collectively JJ2000 * Partners) agree not to assert against ISO/IEC and users of the JPEG * 2000 Standard (Users) any of their rights under the copyright, not * including other intellectual property rights, for this software module * with respect to the usage by ISO/IEC and Users of this software module * or modifications thereof for use in hardware or software products * claiming conformance to the JPEG 2000 Standard. Those intending to use * this software module in hardware or software products are advised that * their use may infringe existing patents. The original developers of * this software module, JJ2000 Partners and ISO/IEC assume no liability * for use of this software module or modifications thereof. No license * or right to this software module is granted for non JPEG 2000 Standard * conforming products. JJ2000 Partners have full right to use this * software module for his/her own purpose, assign or donate this * software module to any third party and to inhibit third parties from * using this software module for non JPEG 2000 Standard conforming * products. This copyright notice must be included in all copies or * derivative works of this software module. * * Copyright (c) 1999/2000 JJ2000 Partners. * */package jj2000.disp;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.*;import java.awt.image.*;import java.util.*;import java.awt.*;/** * This class provides an ImageProducer for the BlkImgDataSrc interface. It * will request data from the BlkImgDataSrc source and deliver it to the * registered image consumers. The data is requested line by line, starting at * the top of each tile. The tiles are requested in raster-scan order. * * <P>The image data is not rescaled to fit the available dynamic range (not * even the alpha values for RGBA data). * * <P>BlkImgDataSrc sources with 1, 3 and 4 components are supported. If 1, * it is assumed to be gray-level data. If 3 it is assumed to be RGB data, in * that order. If 4 it is assumed to be RGBA data (RGB plus alpha plane), in * that order. All components must have the same size. * * @see ImageProducer * * @see BlkImgDataSrc * */public class BlkImgDataSrcImageProducer implements ImageProducer { /** The list of image consumers for this image producer */ private volatile Vector consumers; /** The source of image data */ private BlkImgDataSrc src; /** The type of image: GRAY, RGB or RGBA */ private int type; /** The gray-level image type (256 levels). For this type the source of * image data must have only 1 component. */ private static final int GRAY = 0; /** The color image type (24 bits RGB). No alpha plane. For this type the * source of image data must have 3 components, which are considered to be * R, G and B, in that order */ private static final int RGB = 1; /** The color image type (32 bits RGBA). For this type the source of image * data must have 4 components, which are considered to be R, G, B and A, * in that order. */ private static final int RGBA = 2; /** The default color model (0xAARRGGBB) used in Java */ private static final ColorModel cm = ColorModel.getRGBdefault(); /** * Creates an image producer which uses 'src' as the source of image * data. If 'once' is true then the image is produced only once. * * @param src The source of image data * * @param once If the image is to be produced only once or not. * */ public BlkImgDataSrcImageProducer(BlkImgDataSrc src){ int i; // Check for image type switch (src.getNumComps()) { case 1: type = GRAY; break; case 3: type = RGB; break; case 4: type = RGBA; break; default: throw new IllegalArgumentException("Only 1, 3, and 4 components "+ "supported"); } // Check component sizes and bitdepths for (i=src.getNumComps()-1; i>=0; i--) { if (src.getCompImgHeight(i) != src.getImgHeight() || src.getCompImgWidth(i) != src.getImgWidth()) { throw new IllegalArgumentException("All components must have "+ "the same dimensions and no"+ "subsampling"); } if (src.getNomRangeBits(i) > 8) { throw new IllegalArgumentException("Depths greater than 8 "+ "bits per component is not "+ "supported"); } } this.src = src; consumers = new Vector(); } /** * Returns an Image object given an BlkImgDataSrc source. It will use a * new J2KImageProducer object as the underlying image producer. * * <P>This method uses the JVM default Toolkit, which might not be what it * is desired. * * @param src The source of image data * * @return An image which has a J2KImageProducer object as the underlying * image producer. * */ public static Image createImage(BlkImgDataSrc src){ // Use the system toolkit's createImage method return Toolkit.getDefaultToolkit(). createImage(new BlkImgDataSrcImageProducer(src)); } /** * Returns an Image object given an BlkImgDataSrc source. It will use a * new J2KImageProducer object as the underlying image producer. * * <P>This method uses the component's toolkit. The toolkit of a component * may change if it is moved from one frame to another one, since it is * the frame that controls which toolkit is used. * * @param src The source of image data * * @param c The component to use to generate the 'Image' object from the * 'ImageProducer'. * * @return An image which has a J2KImageProducer object as the underlying * image producer. * */ public static Image createImage(BlkImgDataSrc src, Component c){ // Use the component's toolkit createImage method return c.getToolkit(). createImage(new BlkImgDataSrcImageProducer(src)); } /** * Registers an image consumer with this image producer. The delivery of * image data does not start immediately. It will only start after the * next call to the startProduction() method. * * @param ic The image consumer to which image data has to be delivered. * * @see #startProduction * */ public final synchronized void addConsumer(ImageConsumer ic) { if (ic != null && !consumers.contains(ic)) { consumers.addElement(ic); } } /** * This method determines if the given image consumer, 'ic', is registered * with this image producer. * * @param ic The image consumer to test. * * @return True if 'ic' is registered with this image producer, false * otherwise. * */ public boolean isConsumer(ImageConsumer ic) { return consumers.contains(ic); } /** * Removes the given image consumer 'ic' from the list of consumers * registered with this producer. This image producer will stop sending * pixel data to 'ic' as soon as it is feasible. The method call is * ignored if 'ic' has not been registered with this image producer. * * @param ic The image consumer to be removed * */ public synchronized void removeConsumer(ImageConsumer ic) { consumers.removeElement(ic); } /** * Registers the given ImageConsumer object as a consumer and starts an * immediate reconstruction of the image data which will then be delivered * to this consumer and any other consumer which may have already been * registered with the producer. * * <P> Delivery is performed in "parallel" to all the registered image * consumers. By "parallel" it is meant that each line of the image is * delivered to all consumers before delivering the next line. * * <P>If the data returned by the BlkImgDataSrc source happens to be * progressive (see BlkImgDataSrc and DataBlk) then the abort condition is * sent to the image consumers and no further data is delivered. * * <P>Once all the data is sent to a consumer this one is automatically * removed from the list of registered ones, unless an abort happens. * * <P>To start the BlkImgDataSrc is set to tile (0,0), and the tiles are * produced in raster sacn order. Once the last tile is produced, * setTile(0,0) is called again, which signals that we are done with the * current tile, which might free up resources. * * @param ic The image consumer to register * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -