Package java.awt.image

Examples of java.awt.image.ColorModel$SRGBColorModel


                outname = fileName.substring(0, fileName.length() - 4) + ".jpg";
            } else {
                outname = fileName + ".jpg";
            }
            RenderedOp img = JAI.create("fileload", fileName);
            ColorModel cm = img.getColorModel();
            WritableRaster imgRaster = img.copyData();
            BufferedImage bi = new BufferedImage(cm, imgRaster, false, new Hashtable());
            ImageIO.write((RenderedImage) bi, "jpg", new File(outname));
            System.out.println("...done, " + outname);
        } catch (Exception e) {
View Full Code Here


    {
      image = (BufferedImage) img;
    }
    else
    {
      final ColorModel cm = img.getColorModel();
      final int width = img.getWidth();
      final int height = img.getHeight();
      final WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
      final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
      final Hashtable properties = new Hashtable();
      final String[] keys = img.getPropertyNames();
      if (keys != null)
      {
        final int keyCount = keys.length;
View Full Code Here

  public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
      BufferedImage image = null;
      if (img instanceof BufferedImage) {
          image = (BufferedImage)img;
      } else {
          ColorModel cm = img.getColorModel();
          int width = img.getWidth();
          int height = img.getHeight();
          WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
          boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
          Hashtable<String, Object> properties = new Hashtable<String, Object>();
          String[] keys = img.getPropertyNames();
          if (keys!=null) {
              for (int i = 0; i < keys.length; i++) {
                  properties.put(keys[i], img.getProperty(keys[i]));
View Full Code Here

  public static JRRenderable getInstance(Image img, OnErrorTypeEnum onErrorType) throws JRException
  {
    byte type = JRRenderable.IMAGE_TYPE_JPEG;
    if (img instanceof RenderedImage)
    {
      ColorModel colorModel = ((RenderedImage) img).getColorModel();
      //if the image has transparency, encode as PNG
      if (colorModel.hasAlpha()
          && colorModel.getTransparency() != Transparency.OPAQUE)
      {
        type = JRRenderable.IMAGE_TYPE_PNG;
      }
    }
   
View Full Code Here

    if (getImageType().equals("gif")) {
      // Increase color depth to 16M RGB
      try {
        javax.media.jai.ImageLayout layout = new javax.media.jai.ImageLayout();

        ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                                 new int[] {8,8,8}, false, false,
                                                 Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
        layout.setColorModel(cm);
        layout.setSampleModel(cm.createCompatibleSampleModel(oRenderedImg.getWidth(),oRenderedImg.getHeight()));
        RenderingHints hints = new RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, layout);
        javax.media.jai.ParameterBlockJAI pb = new javax.media.jai.ParameterBlockJAI( "format" );
        pb.addSource( oRenderedImg );
        oRenderedImg = javax.media.jai.JAI.create( "format", pb, hints );
      } catch (IllegalArgumentException iae) {
View Full Code Here

     * @see ImageConsumer
     * @see ColorModel#getRGBdefault
     */
    public void setColorModel(ColorModel model) {
  if (canFilterIndexColorModel && (model instanceof IndexColorModel)) {
      ColorModel newcm = filterIndexColorModel((IndexColorModel)model);
      substituteColorModel(model, newcm);
      consumer.setColorModel(newcm);
  } else {
      consumer.setColorModel(ColorModel.getRGBdefault());
  }
View Full Code Here

     * @since 1.4
     */
    public DisplayMode getDisplayMode() {
        GraphicsConfiguration gc = getDefaultConfiguration();
        Rectangle r = gc.getBounds();
        ColorModel cm = gc.getColorModel();
        return new DisplayMode(r.width, r.height, cm.getPixelSize(), 0);
    }
View Full Code Here

        } else {
            rdrdImage = rdblImage.createDefaultRendering();
        }
       
        // And its ColorModel
        ColorModel colorModel = rdrdImage.getColorModel();
        Raster raster = rdrdImage.getData();
        SampleModel sampleModel = raster.getSampleModel();
        DataBuffer dataBuffer = raster.getDataBuffer();
       
        if (colorModel == null) {
            colorModel = ColorModel.getRGBdefault();
        }
        int minX = raster.getMinX();
        int minY = raster.getMinY();
        int width = raster.getWidth();
        int height = raster.getHeight();
       
        Enumeration icList;
        ImageConsumer ic;
        // Set up the ImageConsumers
        icList = ics.elements();
        while (icList.hasMoreElements()) {
            ic = (ImageConsumer)icList.nextElement();
            ic.setDimensions(width,height);
            ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
                        ImageConsumer.COMPLETESCANLINES |
                        ImageConsumer.SINGLEPASS |
                        ImageConsumer.SINGLEFRAME);
        }
       
        // Get RGB pixels from the raster scanline by scanline and
        // send to consumers.
        int pix[] = new int[width];
        int i,j;
        int numBands = sampleModel.getNumBands();
        int tmpPixel[] = new int[numBands];
        for (j = 0; j < height; j++) {
            for(i = 0; i < width; i++) {
                sampleModel.getPixel(i, j, tmpPixel, dataBuffer);
                pix[i] = colorModel.getDataElement(tmpPixel, 0);
            }
            // Now send the scanline to the Consumers
            icList = ics.elements();
            while (icList.hasMoreElements()) {
                ic = (ImageConsumer)icList.nextElement();
View Full Code Here

          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
          // construction borrowed from BufferedImage constructor, for BufferedImage.TYPE_3BYTE_BGR
                  final ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
                  int[] nBits = {8, 8, 8};
                  //int[] bOffs = {2, 1, 0};
                  final ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false,
                                                       Transparency.OPAQUE,
                                                       DataBuffer.TYPE_BYTE);
                  final BufferedImage bi = new BufferedImage(colorModel, r, false, null);
          return bi;
        }
        else if (bitsPerPixel == 32)
        {
          final DataBufferByte db = new DataBufferByte(new byte[][] {bytes}, bytes.length);
          final ComponentSampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, pixelStride, lineStride, new int[] {redMask - 1, greenMask -1, blueMask -1, 3})// TODO: what to do with alpha?
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
          // construction borrowed from BufferedImage constructor, for BufferedImage.TYPE_4BYTE_ABGR
                  final ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
                  int[] nBits = {8, 8, 8, 8};
                  //int[] bOffs = {3, 2, 1, 0};
                  final ColorModel colorModel = new ComponentColorModel(cs, nBits, true, false,
                                                       Transparency.TRANSLUCENT,
                                                       DataBuffer.TYPE_BYTE);
                  final BufferedImage bi = new BufferedImage(colorModel, r, false, null);
          return bi;
        }
        else if (bitsPerPixel == 8)
        {
          final DataBufferByte db = new DataBufferByte(new byte[][] {bytes}, bytes.length);
          final SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, w, h, lineStride, new int[] {redMask, greenMask, blueMask});
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
                  final ColorModel colorModel = new DirectColorModel(bitsPerPixel, redMask, greenMask, blueMask);
                  final BufferedImage bi = new BufferedImage(colorModel, r, false, null);
          return bi;
        }
        else
        {
          final BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
          final int [] pixels = new int[w * h];
          int pixelIndex = 0;
          int lineOffset = 0;
          if (flipped)
            lineOffset = (h - 1) * lineStride;
         
          for (int y = 0; y < h; ++y)
          {
            int off = lineOffset;
            for (int x = 0; x < w; ++x)
            {
              final byte r = bytes[off + redMask - 1];
              final byte g = bytes[off + greenMask - 1];
              final byte b = bytes[off + blueMask - 1];
              int pixel = 0;
              pixel += r & 0xff// red
              pixel *= 256;
              pixel += g & 0xff; // green
              pixel *= 256;
              pixel += b & 0xff// blue
              pixels[pixelIndex++] = pixel;
              off += pixelStride;
            }
            if (flipped)
              lineOffset -= lineStride;
            else
              lineOffset += lineStride;
          }
         
          bi.setRGB(0,0,w,h,pixels,0,w);
          return bi;
        }

       
      }else if (dataType == Format.shortArray) {
        final short[] shorts = (short[]) buffer.getData();
        if (bitsPerPixel == 16)
        {
          final DataBufferUShort db = new DataBufferUShort(new short[][] {shorts}, shorts.length);
          final SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT, w, h, lineStride, new int[] {redMask, greenMask, blueMask});
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
                  final ColorModel colorModel = new DirectColorModel(bitsPerPixel, redMask, greenMask, blueMask);
                  final BufferedImage bi = new BufferedImage(colorModel, r, false, null);
          return bi;
        }else{
          throw new UnsupportedOperationException()// TODO
        }
      }
      else if (dataType == Format.intArray)
      {
//        if (true)
        {
          // optimized, don't copy data or iterate through pixels:
          final int[] bytes = (int[]) buffer.getData();
          final DataBufferInt db = new DataBufferInt(new int[][] {bytes}, bytes.length);
          final SinglePixelPackedSampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h, new int[] {redMask, greenMask, blueMask});
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
         
                  final ColorModel colorModel = new DirectColorModel(24,
                            redMask,   // Red
                            greenMask,  // Green
                            blueMask,   // Blue
                            0x0         // Alpha
                            );
View Full Code Here

            Block[] mcu = allocateMCUMemory();
            Block[] scaledMCU = new Block[mcu.length];
            for (int i = 0; i < scaledMCU.length; i++)
                scaledMCU[i] = new Block(hSize, vSize);
            int[] preds = new int[sofnSegment.numberOfComponents];
            ColorModel colorModel;
            WritableRaster raster;
            if (sofnSegment.numberOfComponents == 3)
            {
                colorModel = new DirectColorModel(24,
                        0x00ff0000, 0x0000ff00, 0x000000ff);
                raster = WritableRaster.createPackedRaster(DataBuffer.TYPE_INT,
                        sofnSegment.width, sofnSegment.height,
                        new int[]{0x00ff0000,0x0000ff00,0x000000ff}, null);
            }
            else if (sofnSegment.numberOfComponents == 1)
            {
                colorModel = new DirectColorModel(24,
                        0x00ff0000, 0x0000ff00, 0x000000ff);
                raster = WritableRaster.createPackedRaster(DataBuffer.TYPE_INT,
                        sofnSegment.width, sofnSegment.height,
                        new int[]{0x00ff0000,0x0000ff00,0x000000ff}, null);
                // FIXME: why do images come out too bright with CS_GRAY?
//                colorModel = new ComponentColorModel(
//                        ColorSpace.getInstance(ColorSpace.CS_GRAY), false, true,
//                        Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
//                raster = colorModel.createCompatibleWritableRaster(
//                        sofnSegment.width, sofnSegment.height);
            }
            else
                throw new ImageReadException(sofnSegment.numberOfComponents +
                        " components are invalid or unsupported");
            DataBuffer dataBuffer = raster.getDataBuffer();

           
            for (int y1 = 0; y1 < vSize*yMCUs; y1 += vSize)
            {
                for (int x1 = 0; x1 < hSize*xMCUs; x1 += hSize)
                {
                    readMCU(bitInputStream, preds, mcu);
                    rescaleMCU(mcu, hSize, vSize, scaledMCU);
                    int srcRowOffset = 0;
                    int dstRowOffset = y1*sofnSegment.width + x1;
                    for (int y2 = 0; y2 < vSize && y1 + y2 < sofnSegment.height; y2++)
                    {
                        for (int x2 = 0; x2 < hSize && x1 + x2 < sofnSegment.width; x2++)
                        {
                            if (scaledMCU.length == 3)
                            {
                                int Y = scaledMCU[0].samples[srcRowOffset + x2];
                                int Cb = scaledMCU[1].samples[srcRowOffset + x2];
                                int Cr = scaledMCU[2].samples[srcRowOffset + x2];
                                int rgb = YCbCrConverter.convertYCbCrToRGB(Y, Cb, Cr);
                                dataBuffer.setElem(dstRowOffset + x2, rgb);
                            }
                            else if (mcu.length == 1)
                            {
                                int Y = scaledMCU[0].samples[srcRowOffset + x2];
                                dataBuffer.setElem(dstRowOffset + x2,
                                        (Y << 16) | (Y << 8) | Y);
                            }
                            else
                                throw new ImageReadException("Unsupported JPEG with " +
                                        mcu.length + " components");
                        }
                        srcRowOffset += hSize;
                        dstRowOffset += sofnSegment.width;
                    }
                }
            }
            image = new BufferedImage(colorModel, raster,
                    colorModel.isAlphaPremultiplied(), new Properties());
            //byte[] remainder = super.getStreamBytes(is);
            //for (int i = 0; i < remainder.length; i++)
            //{
            //    System.out.println("" + i + " = " + Integer.toHexString(remainder[i]));
            //}
View Full Code Here

TOP

Related Classes of java.awt.image.ColorModel$SRGBColorModel

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.