Package net.sourceforge.jiu.data

Examples of net.sourceforge.jiu.data.ByteChannelImage


  {
    PixelImage image = getImage();
    setBoundsIfNecessary(image.getWidth(), image.getHeight());
    int width = getBoundsWidth();
    int height = getBoundsHeight();
    ByteChannelImage bcimg = null;
    BilevelImage bilevelImage = null;
    RGB24Image rgbimg = null;
    int bytesPerRow = 0;
    int offset = 54;
    int numBits = 0;
    int numPackedBytes = 0;
    if (image instanceof Paletted8Image ||
        image instanceof Gray8Image)
    {
      bcimg = (ByteChannelImage)image;
      bytesPerRow = width;
      offset += 1024;
      numBits = 8;
    }
    else
    if (image instanceof BilevelImage)
    {
      bilevelImage = (BilevelImage)image;
      numPackedBytes = (width + 7) / 8;
      bytesPerRow = numPackedBytes;
      offset += 8;
      numBits = 1;
    }
    else
    if (image instanceof RGB24Image)
    {
      rgbimg = (RGB24Image)image;
      bytesPerRow = width * 3;
      numBits = 24;
    }
    if ((bytesPerRow % 4) != 0)
    {
      bytesPerRow = ((bytesPerRow + 3) / 4) * 4;
    }
    int filesize = offset + bytesPerRow * height;
    writeHeader(image, filesize, offset, numBits);
    writePalette();
    byte[] row = new byte[bytesPerRow];
    final int X1 = getBoundsX1();
    for (int y = getBoundsY2(), processed = 0; processed < height; y--, processed++)
    {
      if (bilevelImage != null)
      {
        bilevelImage.getPackedBytes(X1, y, width, row, 0, 0);
      }
      else
      if (bcimg != null)
      {
        bcimg.getByteSamples(0, 0, y, width, 1, row, 0);
      }
      else
      if (rgbimg != null)
      {
        int offs = 0;
View Full Code Here


      }
      case(2):
      {
        byte[] dest = new byte[bytesPerRow * 4];
        ArrayConverter.decodePacked2Bit(row, 0, dest, 0, bytesPerRow);
        ByteChannelImage bcimg = (ByteChannelImage)image;
        bcimg.putByteSamples(0, 0, y, getBoundsWidth(), 1, dest, getBoundsX1());
        break;
      }
      case(4):
      {
        byte[] dest = new byte[bytesPerRow * 2];
        ArrayConverter.decodePacked4Bit(row, 0, dest, 0, bytesPerRow);
        ByteChannelImage bcimg = (ByteChannelImage)image;
        bcimg.putByteSamples(0, 0, y, getBoundsWidth(), 1, dest, getBoundsX1());
        break;
      }
      case(8):
      {
        ByteChannelImage bcimg = (ByteChannelImage)image;
        bcimg.putByteSamples(0, 0, y, getBoundsWidth(), 1, row, getBoundsX1());
        break;
      }
      case(16):
      {
        ArrayConverter.decodePackedRGB565BigEndianToRGB24(
View Full Code Here

        image.putPackedBytes(x, y, numPixels, data, offset + (leftPixels / 8), leftPixels % 8);
        break;
      }
      case(TIFFImageFileDirectory.TYPE_GRAY4):
      {
        ByteChannelImage image = (ByteChannelImage)codec.getImage();
        byte[] dest = new byte[data.length * 2];
        ArrayConverter.decodePacked4Bit(data, 0, dest, 0, data.length);
        for (int i = 0; i < dest.length; i++)
        {
          int value = dest[i] & 15;
          value = (value << 4) | value;
          dest[i] = (byte)value;
        }
        image.putByteSamples(0, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, offset + leftPixels);
        break;
      }
      case(TIFFImageFileDirectory.TYPE_PALETTED4):
      {
        ByteChannelImage image = (ByteChannelImage)codec.getImage();
        byte[] dest = new byte[data.length * 2];
        ArrayConverter.decodePacked4Bit(data, 0, dest, 0, data.length);
        image.putByteSamples(0, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, offset + leftPixels);
        break;
      }
      case(TIFFImageFileDirectory.TYPE_GRAY8):
      case(TIFFImageFileDirectory.TYPE_PALETTED8):
      {
        ByteChannelImage image = (ByteChannelImage)codec.getImage();
        image.putByteSamples(0, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, data, offset + leftPixels);
        break;
      }
      case(TIFFImageFileDirectory.TYPE_CMYK32_INTERLEAVED):
      {
        ByteChannelImage image = (ByteChannelImage)codec.getImage();
        byte[] dest = new byte[data.length];
        int numSamples = ifd.getTileWidth();
        CMYKConversion.convertCMYK32InterleavedToRGB24Planar(
          data, 0,
          dest, 0,
          dest, numSamples,
          dest, numSamples * 2,
          numSamples);
        image.putByteSamples(RGBIndex.INDEX_RED, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, leftPixels);
        image.putByteSamples(RGBIndex.INDEX_GREEN, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, numSamples + leftPixels);
        image.putByteSamples(RGBIndex.INDEX_BLUE, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, 2 * numSamples + leftPixels);
        break;
      }
/*      case(TIFFImageFileDirectory.TYPE_CMYK32_PLANAR):
      {
        ByteChannelImage image = (ByteChannelImage)codec.getImage();
        byte[] dest = new byte[data.length];
        int numSamples = ifd.getTileWidth();
        CMYKConversion.convertCMYK32PlanarToRGB24Planar(
          data, 0,
          data, numPixels,
          data, numPixels * 2,
          data, numPixels * 3,
          dest, 0,
          dest, numSamples,
          dest, numSamples * 2,
          numSamples);
        image.putByteSamples(RGBIndex.INDEX_RED, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, leftPixels);
        image.putByteSamples(RGBIndex.INDEX_GREEN, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, numSamples + leftPixels);
        image.putByteSamples(RGBIndex.INDEX_BLUE, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, 2 * numSamples + leftPixels);
        break;
      }*/
      case(TIFFImageFileDirectory.TYPE_RGB24_INTERLEAVED):
      {
        ByteChannelImage image = (ByteChannelImage)codec.getImage();
        offset += leftPixels * 3;
        for (int i = 0, x = getX1() - codec.getBoundsX1() + leftPixels; i < numPixels; i++, x++)
        {
          image.putByteSample(RGBIndex.INDEX_RED, x, y, data[offset++]);
          image.putByteSample(RGBIndex.INDEX_GREEN, x, y, data[offset++]);
          image.putByteSample(RGBIndex.INDEX_BLUE, x, y, data[offset++]);
        }
        break;
      }
      case(TIFFImageFileDirectory.TYPE_RGB48_INTERLEAVED):
      {
        ShortChannelImage image = (ShortChannelImage)codec.getImage();
        offset += leftPixels * 3;
        short[] triplet = new short[3];
        boolean littleEndian = codec.getByteOrder() == TIFFCodec.BYTE_ORDER_INTEL;
        for (int i = 0, x = getX1() - codec.getBoundsX1() + leftPixels; i < numPixels; i++, x++)
        {
          for (int j = 0; j < 3; j++, offset += 2)
          {
            if (littleEndian)
            {
              triplet[j] = ArrayConverter.getShortLE(data, offset);
            }
            else
            {
              triplet[j] = ArrayConverter.getShortBE(data, offset);
            }
          }
          image.putShortSample(RGBIndex.INDEX_RED, x, y, triplet[0]);
          image.putShortSample(RGBIndex.INDEX_GREEN, x, y, triplet[1]);
          image.putShortSample(RGBIndex.INDEX_BLUE, x, y, triplet[2]);
        }
        break;
      }
      case(TIFFImageFileDirectory.TYPE_LOGLUV32_INTERLEAVED):
      {
        if (getImageFileDirectory().getCompression() == TIFFConstants.COMPRESSION_SGI_LOG_RLE)
        {
          ByteChannelImage image = (ByteChannelImage)codec.getImage();
          int numSamples = ifd.getTileWidth();
          byte[] red = new byte[numSamples];
          byte[] green = new byte[numSamples];
          byte[] blue = new byte[numSamples];
          LogLuvConversion.convertLogLuv32InterleavedtoRGB24Planar(data, red, green, blue, numSamples);
          image.putByteSamples(RGBIndex.INDEX_RED, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, red, leftPixels);
          image.putByteSamples(RGBIndex.INDEX_GREEN, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, green, leftPixels);
          image.putByteSamples(RGBIndex.INDEX_BLUE, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, blue, leftPixels);
        }
        else
        if (getImageFileDirectory().getCompression() == TIFFConstants.COMPRESSION_SGI_LOG_24_PACKED)
        {
          ByteChannelImage image = (ByteChannelImage)codec.getImage();
          int numSamples = ifd.getTileWidth();
          byte[] red = new byte[numSamples];
          byte[] green = new byte[numSamples];
          byte[] blue = new byte[numSamples];
          LogLuvConversion.convertLogLuv24InterleavedtoRGB24Planar(data, red, green, blue, numSamples);
          image.putByteSamples(RGBIndex.INDEX_RED, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, red, leftPixels);
          image.putByteSamples(RGBIndex.INDEX_GREEN, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, green, leftPixels);
          image.putByteSamples(RGBIndex.INDEX_BLUE, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, blue, leftPixels);
        }
        break;
      }
      case(TIFFImageFileDirectory.TYPE_LOGL):
      {
        ByteChannelImage image = (ByteChannelImage)codec.getImage();
        int numSamples = ifd.getTileWidth();
        byte[] gray = new byte[numSamples];
        LogLuvConversion.convertLogL16toGray8(data, gray, numSamples);
        image.putByteSamples(0, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, gray, leftPixels);
        break;
      }
    }
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.jiu.data.ByteChannelImage

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.