Package net.sourceforge.jiu.data

Examples of net.sourceforge.jiu.data.BilevelImage


    PixelImage image = getImage();
    int x1 = getBoundsX1();
    int w = getBoundsWidth();
    if (image instanceof BilevelImage)
    {
      BilevelImage bilevelImage = (BilevelImage)image;
      bilevelImage.getPackedBytes(x1, y, w, row, offs, 0);
    }
    else
    if (image instanceof Gray16Image)
    {
      Gray16Image grayImage = (Gray16Image)image;
View Full Code Here


    byte[] dest = new byte[numColumns + 7];
    switch(precision)
    {
      case(1):
      {
        BilevelImage bilevelImage = (BilevelImage)image;
        ArrayConverter.decodePacked1Bit(buffer, 0, dest, 0, numPackedBytes);
        while (x <= x2)
        {
          if (x >= x1)
          {
            if (dest[offset] == 0)
            {
              bilevelImage.putBlack(x - x1, y);
            }
            else
            {
              bilevelImage.putWhite(x - x1, y);
            }
          }
          x += incr;
          offset++;
        }
View Full Code Here

  {
    switch(precision)
    {
      case(1):
      {
        BilevelImage bilevelImage = (BilevelImage)image;
        int x1 = getBoundsX1();
        bilevelImage.putPackedBytes(0, y, getBoundsWidth(), buffer, x1 / 8, x1 % 8);
        break;
      }
      case(2):
      {
        Gray8Image grayImage = (Gray8Image)image;
View Full Code Here

  private void loadBilevelImageAscii() throws
    InvalidFileStructureException,
    IOException
  {
    BilevelImage image = (BilevelImage)getImage();
    // skip the pixels of the first getBoundsY1() rows
    int pixelsToSkip = width * getBoundsY1();
    for (int i = 0; i < pixelsToSkip; i++)
    {
      loadAsciiNumber();
    }
    final int NUM_ROWS = getBoundsHeight();
    final int COLUMNS = getBoundsWidth();
    final int X1 = getBoundsX1();
    int[] row = new int[width];
    // now read and store getBoundsHeight() rows
    for (int y = 0; y < NUM_ROWS; y++)
    {
      for (int x = 0; x < width; x++)
      {
        int value = loadAsciiNumber();
        if (value == 0)
        {
          row[x] = BilevelImage.WHITE;
        }
        else
        if (value == 1)
        {
          row[x] = BilevelImage.BLACK;
        }
        else
        {
          throw new InvalidFileStructureException("Loaded " +
            "number for position x=" + x + ", y=" + (y + getBoundsY1()) +
            " is neither 0 nor 1 in PBM stream: " + value);
        }
      }
      image.putSamples(0, 0, y, COLUMNS, 1, row, X1);
      setProgress(y, NUM_ROWS);
    }
  }
View Full Code Here

  private void loadBilevelImageBinary() throws
    InvalidFileStructureException,
    IOException
  {
    BilevelImage image = (BilevelImage)getImage();
    int bytesPerRow = (width + 7) / 8;
    // skip the first getBoundsY1() rows
    long bytesToSkip = (long)getBoundsY1() * (long)bytesPerRow;
    // Note:
    // removed in.skip(bytesToSkip) because that was only available in Java 1.2
    // instead the following while loop is used
    while (bytesToSkip-- > 0)
    {
      in.read();
    }
    // allocate buffer large enough for a complete row
    byte[] row = new byte[bytesPerRow];
    final int numRows = getBoundsHeight();
    // read and store the next getBoundsHeight() rows
    for (int y = 0; y < numRows; y++)
    {
      // read bytesPerRow bytes into row
      int bytesToRead = bytesPerRow;
      int index = 0;
      while (bytesToRead > 0)
      {
        int result = in.read(row, index, bytesToRead);
        if (result >= 0)
        {
          index += result;
          bytesToRead -= result;
        }
        else
        {
          throw new InvalidFileStructureException("Unexpected end of input stream while reading.");
        }
      }
      // invert values
      for (int x = 0; x < row.length; x++)
      {
        row[x] = (byte)~row[x];
      }
      //image.putPackedBytes(0, y, bytesPerRow, buffer, 0);
      if (isRowRequired(y))
      {
        image.putPackedBytes(0, y - getBoundsY1(), getBoundsWidth(), row, getBoundsX1() >> 3, getBoundsX1() & 7);
      }
      setProgress(y, numRows);
    }
  }
View Full Code Here

  {
    if ((getBoundsX1() % 8) != 0)
    {
      throw new OperationFailedException("When loading bilevel images, horizontal X1 bounds must be a multiple of 8; got " + getBoundsX1());
    }
    BilevelImage image = (BilevelImage)getImage();
    int imageBytesPerRow = (imageWidth + 7) / 8;
    int bytesPerRow = imageBytesPerRow;
    int mod = bytesPerRow % 4;
    if (mod != 0)
    {
      bytesPerRow += 4 - mod;
    }
    int bottomRowsToSkip = imageHeight - 1 - getBoundsY2();
    int bytesToSkip = bottomRowsToSkip * bytesPerRow;
    while (bytesToSkip > 0)
    {
      int skipped = in.skipBytes(bytesToSkip);
      if (skipped > 0)
      {
        bytesToSkip -= skipped;
      }
    }
    final int COLUMNS = getBoundsWidth();
    final int ROWS = getBoundsHeight();
    final int SRC_OFFSET = getBoundsX1() / 8;
    final int SRC_BIT_OFFSET = getBoundsX1() % 8;
    int y = image.getHeight() - 1;
    int processedRows = 0;
    byte[] row = new byte[bytesPerRow];
    while (processedRows < ROWS)
    {
      in.readFully(row);
      image.putPackedBytes(0, y, COLUMNS, row, SRC_OFFSET, SRC_BIT_OFFSET);
      y--;
      setProgress(processedRows, ROWS);
      processedRows++;
    }
  }
View Full Code Here

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

    y -= getBoundsY1();
    switch(bitsPerPixel)
    {
      case(1):
      {
        BilevelImage bimage = (BilevelImage)image;
        invertBilevelData(row);
        bimage.putPackedBytes(0, y, getBoundsWidth(), row, getBoundsX1() / 8, getBoundsX1() % 8);
        break;
      }
      case(2):
      {
        byte[] dest = new byte[bytesPerRow * 4];
 
View Full Code Here

    numPixels -= (rightPixels + leftPixels);
    switch(ifd.getImageType())
    {
      case(TIFFImageFileDirectory.TYPE_BILEVEL_BYTE):
      {
        BilevelImage image = (BilevelImage)codec.getImage();
        int index = offset + leftPixels;
        int x = getX1() - codec.getBoundsX1() + leftPixels;
        while (numPixels-- > 0)
        {
          if (data[index++] == (byte)BilevelImage.BLACK)
          {
            image.putBlack(x++, y);
          }
          else
          {
            image.putWhite(x++, y);
          }
        }
        break;
      }
      case(TIFFImageFileDirectory.TYPE_BILEVEL_PACKED):
      {
        BilevelImage image = (BilevelImage)codec.getImage();
        int x = getX1() - codec.getBoundsX1() + leftPixels;
        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.BilevelImage

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.