Package java.awt.image

Examples of java.awt.image.SinglePixelPackedSampleModel


          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
View Full Code Here


        if (sm instanceof ComponentSampleModel) {
            return getDefaultColorModel(sm.getDataType(), bands);

        } else if (sm instanceof SinglePixelPackedSampleModel) {
            SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sm;

            int[] bitMasks = sppsm.getBitMasks();
            int rmask = 0;
            int gmask = 0;
            int bmask = 0;
            int amask = 0;

            int numBands = bitMasks.length;
            if (numBands <= 2) {
                rmask = gmask = bmask = bitMasks[0];
                if (numBands == 2) {
                    amask = bitMasks[1];
                }
            } else {
                rmask = bitMasks[0];
                gmask = bitMasks[1];
                bmask = bitMasks[2];
                if (numBands == 4) {
                    amask = bitMasks[3];
                }
            }

            int[] sampleSize = sppsm.getSampleSize();
            int bits = 0;
            for (int i = 0; i < sampleSize.length; i++) {
                bits += sampleSize[i];
            }
View Full Code Here

      else
    colorModel = new IndexColorModel(bitsPerPixel, size, r, g, b);
  } else if (bitsPerPixel == 16) {
      numBands = 3;
            sampleModel =
    new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT,
            width, height,
            new int[] {redMask, greenMask, blueMask});

      colorModel =
    new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
             16, redMask, greenMask, blueMask, 0,
             false, DataBuffer.TYPE_USHORT);
  } else if (bitsPerPixel == 32) {
      numBands = alphaMask == 0 ? 3 : 4;

            // The number of bands in the SampleModel is determined by
            // the length of the mask array passed in.
            int[] bitMasks = numBands == 3 ?
                new int[] {redMask, greenMask, blueMask} :
                new int[] {redMask, greenMask, blueMask, alphaMask};

      sampleModel =
          new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
             width, height,
             bitMasks);

      colorModel =
    new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
View Full Code Here

            numBanks = 1;
            int dataTypeSize = DataBuffer.getDataTypeSize(type);
            size = mppsm.getScanlineStride()*mppsm.getHeight() +
                (mppsm.getDataBitOffset() + dataTypeSize - 1)/dataTypeSize;
        } else if(sampleModel instanceof SinglePixelPackedSampleModel) {
            SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
            numBanks = 1;
            size = sppsm.getScanlineStride()*(sppsm.getHeight() - 1) +
                sppsm.getWidth();
        }

        if(size != 0) {
            Object array =
                getRecycledArray(type, numBanks, size);
View Full Code Here

            numBanks = 1;
            int dataTypeSize = DataBuffer.getDataTypeSize(type);
            size = mppsm.getScanlineStride()*mppsm.getHeight() +
                (mppsm.getDataBitOffset() + dataTypeSize - 1)/dataTypeSize;
        } else if(sampleModel instanceof SinglePixelPackedSampleModel) {
            SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
            numBanks = 1;
            size = sppsm.getScanlineStride()*(sppsm.getHeight() - 1) +
                sppsm.getWidth();
        }

        if(size != 0) {
            Object array =
                getRecycledArray(type, numBanks, size);
View Full Code Here

                    (MultiPixelPackedSampleModel)sm2;
                return mpp1.getPixelBitStride() == mpp2.getPixelBitStride() &&
                    mpp1.getScanlineStride() == mpp2.getScanlineStride() &&
                    mpp1.getDataBitOffset() == mpp2.getDataBitOffset();
            } else if(sm1 instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel spp1 =
                    (SinglePixelPackedSampleModel)sm1;
                SinglePixelPackedSampleModel spp2 =
                    (SinglePixelPackedSampleModel)sm2;
                return spp1.getScanlineStride() == spp2.getScanlineStride() &&
                    Arrays.equals(spp1.getBitMasks(), spp2.getBitMasks());
            }
        }

        return false;
    }
View Full Code Here

                SampleModel sm1 = src.getSampleModel();
                int pos = 0;
                int startX = srcRect.x - src.getSampleModelTranslateX();
                int startY = srcRect.y - src.getSampleModelTranslateY();
                if (sm1 instanceof SinglePixelPackedSampleModel) {
                    SinglePixelPackedSampleModel sppsm =
                        (SinglePixelPackedSampleModel)sm1;
                    pos = sppsm.getOffset(startX, startY);
                }

                switch(dataType) {
                    case DataBuffer.TYPE_SHORT:
                    short[] sdata =
View Full Code Here

                out.writeObject(sm.getBankIndices());
            }
            out.writeObject(sm.getBandOffsets());
        } else if(sampleModel instanceof
                  SinglePixelPackedSampleModel) {
            SinglePixelPackedSampleModel sm =
                (SinglePixelPackedSampleModel)sampleModel;
            out.writeInt(TYPE_SINGLE_PIXEL_PACKED);
            out.writeInt(sm.getTransferType());
            out.writeInt(sm.getWidth());
            out.writeInt(sm.getHeight());
            out.writeInt(sm.getScanlineStride());
            out.writeObject(sm.getBitMasks());
        } else if(sampleModel instanceof MultiPixelPackedSampleModel) {
            MultiPixelPackedSampleModel sm =
                (MultiPixelPackedSampleModel)sampleModel;
            out.writeInt(TYPE_MULTI_PIXEL_PACKED);
            out.writeInt(sm.getTransferType());
            out.writeInt(sm.getWidth());
            out.writeInt(sm.getHeight());
            out.writeInt(sm.getPixelBitStride());
            out.writeInt(sm.getScanlineStride());
            out.writeInt(sm.getDataBitOffset());
        } else {
            throw new RuntimeException(JaiI18N.getString("SampleModelProxy0"));
        }
    }
View Full Code Here

                                         in.readInt(),
                                         (int[])in.readObject(),
                                         (int[])in.readObject());
            break;
        case TYPE_SINGLE_PIXEL_PACKED:
            sampleModel = new SinglePixelPackedSampleModel(in.readInt(),
                                                           in.readInt(),
                                                           in.readInt(),
                                                           in.readInt(),
                                                           (int[])in.readObject());
            break;
View Full Code Here

                out.writeObject(sm.getBankIndices());
            }
            out.writeObject(sm.getBandOffsets());
        } else if(sampleModel instanceof
                  SinglePixelPackedSampleModel) {
            SinglePixelPackedSampleModel sm =
                (SinglePixelPackedSampleModel)sampleModel;
            out.writeInt(TYPE_SINGLE_PIXEL_PACKED);
            out.writeInt(sm.getTransferType());
            out.writeInt(sm.getWidth());
            out.writeInt(sm.getHeight());
            out.writeInt(sm.getScanlineStride());
            out.writeObject(sm.getBitMasks());
        } else if(sampleModel instanceof MultiPixelPackedSampleModel) {
            MultiPixelPackedSampleModel sm =
                (MultiPixelPackedSampleModel)sampleModel;
            out.writeInt(TYPE_MULTI_PIXEL_PACKED);
            out.writeInt(sm.getTransferType());
            out.writeInt(sm.getWidth());
            out.writeInt(sm.getHeight());
            out.writeInt(sm.getPixelBitStride());
            out.writeInt(sm.getScanlineStride());
            out.writeInt(sm.getDataBitOffset());
        } else {
            throw new RuntimeException(JaiI18N.getString("SampleModelState0"));
        }
    }
View Full Code Here

TOP

Related Classes of java.awt.image.SinglePixelPackedSampleModel

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.