Package net.sourceforge.jiu.data

Examples of net.sourceforge.jiu.data.Paletted8Image


      grayImage.getByteSamples(0, getBoundsX1(), y, getBoundsWidth(), 1, row, offs);
    }
    else
    if (image instanceof Paletted8Image)
    {
      Paletted8Image palImage = (Paletted8Image)image;
      palImage.getByteSamples(0, getBoundsX1(), y, getBoundsWidth(), 1, row, offs);
    }
    else
    if (image instanceof RGB24Image)
    {
      RGB24Image rgbImage = (RGB24Image)image;
View Full Code Here


  {
    if (colorType != COLOR_TYPE_INDEXED)
    {
      return;
    }
    Paletted8Image image = (Paletted8Image)getImage();
    Palette pal = image.getPalette();
    int numEntries = pal.getNumEntries();
    byte[] data = new byte[numEntries * 3];
    for (int i = 0, j = 0; i < numEntries; i++, j += 3)
    {
      data[j] = (byte)pal.getSample(RGBIndex.INDEX_RED, i);
View Full Code Here

    }
  }

  private void storeInterlacedAdam7Indexed(int pass, int y, byte[] buffer)
  {
    Paletted8Image palImage = (Paletted8Image)image;
    int x = ADAM7_FIRST_COLUMN[pass];
    final int incr = ADAM7_COLUMN_INCREMENT[pass];
    final int x1 = getBoundsX1();
    final int x2 = getBoundsX2();
    int offset = 0;
    int numColumns = computeColumnsAdam7(pass);
    int numPackedBytes = computeBytesPerRow(numColumns);
    byte[] dest = new byte[numColumns + 7];
    switch(precision)
    {
      case(1):
      {
        ArrayConverter.decodePacked1Bit(buffer, 0, dest, 0, numPackedBytes);
        while (x <= x2)
        {
          if (x >= x1)
          {
            palImage.putByteSample(x - x1, y, dest[offset]);
          }
          x += incr;
          offset++;
        }
        break;
      }
      case(2):
      {
        ArrayConverter.decodePacked2Bit(buffer, 0, dest, 0, numPackedBytes);
        while (x <= x2)
        {
          if (x >= x1)
          {
            palImage.putByteSample(x - x1, y, dest[offset]);
          }
          x += incr;
          offset++;
        }
        break;
      }
      case(4):
      {
        ArrayConverter.decodePacked4Bit(buffer, 0, dest, 0, numPackedBytes);
        while (x <= x2)
        {
          if (x >= x1)
          {
            palImage.putByteSample(x - x1, y, dest[offset]);
          }
          x += incr;
          offset++;
        }
        break;
      }
      case(8):
      {
        while (x <= x2)
        {
          if (x >= x1)
          {
            palImage.putSample(x - x1, y, buffer[offset]);
          }
          x += incr;
          offset++;
        }
        break;
View Full Code Here

    }
  }

  private void storeNonInterlacedIndexed(int y, byte[] buffer)
  {
    Paletted8Image palImage = (Paletted8Image)image;
    switch(precision)
    {
      case(1):
      {
        byte[] dest = new byte[width + 7];
        ArrayConverter.decodePacked1Bit(buffer, 0, dest, 0, buffer.length);
        palImage.putByteSamples(0, 0, y, getBoundsWidth(), 1, dest, getBoundsX1());
        break;
      }
      case(2):
      {
        byte[] dest = new byte[width + 3];
        ArrayConverter.decodePacked2Bit(buffer, 0, dest, 0, buffer.length);
        palImage.putByteSamples(0, 0, y, getBoundsWidth(), 1, dest, getBoundsX1());
        break;
      }
      case(4):
      {
        byte[] dest = new byte[width + 1];
        ArrayConverter.decodePacked4Bit(buffer, 0, dest, 0, buffer.length);
        palImage.putByteSamples(0, 0, y, getBoundsWidth(), 1, dest, getBoundsX1());
        break;
      }
      case(8):
      {
        int offset = getBoundsX1();
        int x = 0;
        int k = getBoundsWidth();
        while (k > 0)
        {
          palImage.putSample(0, x++, y, buffer[offset++]);
          k--;
        }
        break;
      }
    }
View Full Code Here

    }
  }

  private void loadCompressedPaletted4Stream() throws IOException
  {
    Paletted8Image image = (Paletted8Image)getImage();
    int imageBytesPerRow = imageWidth;
    int bytesPerRow = imageBytesPerRow;
    int mod = bytesPerRow % 4;
    if (mod != 0)
    {
      bytesPerRow += 4 - mod;
    }
    final int COLUMNS = getBoundsWidth();
    final int ROWS = imageHeight - getBoundsY1();
    final int X1 = getBoundsX1();
    int processedRows = 0;
    byte[] row = new byte[bytesPerRow];
    int x = 0;
    int y = imageHeight - 1;
    boolean endOfBitmap = false;
    boolean delta = false;
    int newX = 0;
    int newY = 0;
    while (processedRows < ROWS)
    {
      int v1 = in.readUnsignedByte();
      int v2 = in.readUnsignedByte();
      if (v1 == 0)
      {
        switch(v2)
        {
          case(0):
          {
            // end of line
            if (x != 0)
            {
              x = bytesPerRow;
            }
            break;
          }
          case(1):
          {
            // end of bitmap
            x = bytesPerRow;
            endOfBitmap = true;
            break;
          }
          case(2):
          {
            // delta
            delta = true;
            newX = x + in.readUnsignedByte();
            newY = y - in.readUnsignedByte();
            x = bytesPerRow;
            break;
          }
          default:
          {
            // copy the next v2 (3..255) samples from file to output
            // two samples are packed into one byte
            // if the number of bytes used to pack is not a multiple of 2,
            // an additional padding byte is in the stream and must be skipped
            boolean paddingByte = (((v2 + 1) / 2) % 2) != 0;
            while (v2 > 1)
            {
              int packed = in.readUnsignedByte();
              int sample1 = (packed >> 4) & 0x0f;
              int sample2 = packed & 0x0f;
              row[x++] = (byte)sample1;
              row[x++] = (byte)sample2;
              v2 -= 2;
            }
            if (v2 == 1)
            {
              int packed = in.readUnsignedByte();
              int sample = (packed >> 4) & 0x0f;
              row[x++] = (byte)sample;
            }
            if (paddingByte)
            {
              v2 = in.readUnsignedByte();
            }
            break;
          }
        }
      }
      else
      {
        // rle: replicate the two samples in v2 as many times as v1 says
        byte sample1 = (byte)((v2 >> 4) & 0x0f);
        byte sample2 = (byte)(v2 & 0x0f);
        while (v1 > 1)
        {
          row[x++] = sample1;
          row[x++] = sample2;
          v1 -= 2;
        }
        if (v1 == 1)
        {
          row[x++] = sample1;
        }
      }
      // end of line?
      if (x == bytesPerRow)
      {
        if (y <= getBoundsY2())
        {
          image.putByteSamples(0, 0, y - getBoundsY1(), COLUMNS, 1, row, X1);
        }
        if (delta)
        {
          x = newX;
          y = newY;
View Full Code Here

    }
  }

  private void loadCompressedPaletted8Stream() throws IOException
  {
    Paletted8Image image = (Paletted8Image)getImage();
    int imageBytesPerRow = imageWidth;
    int bytesPerRow = imageBytesPerRow;
    int mod = bytesPerRow % 4;
    if (mod != 0)
    {
      bytesPerRow += 4 - mod;
    }
    final int COLUMNS = getBoundsWidth();
    final int ROWS = imageHeight - getBoundsY1();
    final int X1 = getBoundsX1();
    int processedRows = 0;
    byte[] row = new byte[bytesPerRow];
    int x = 0;
    int y = imageHeight - 1;
    boolean endOfBitmap = false;
    boolean delta = false;
    int newX = 0;
    int newY = 0;
    while (processedRows < ROWS)
    {
      int v1 = in.readUnsignedByte();
      int v2 = in.readUnsignedByte();
      if (v1 == 0)
      {
        switch(v2)
        {
          case(0):
          {
            // end of line
            if (x != 0)
            {
              x = bytesPerRow;
            }
            break;
          }
          case(1):
          {
            // end of bitmap
            x = bytesPerRow;
            endOfBitmap = true;
            break;
          }
          case(2):
          {
            // delta
            delta = true;
            newX = x + in.readUnsignedByte();
            newY = y - in.readUnsignedByte();
            x = bytesPerRow;
            break;
          }
          default:
          {
            // copy the next v2 (3..255) bytes from file to output
            boolean paddingByte = (v2 % 2) != 0;
            while (v2-- > 0)
            {
              row[x++] = (byte)in.readUnsignedByte();
            }
            if (paddingByte)
            {
              v2 = in.readUnsignedByte();
            }
            break;
          }
        }
      }
      else
      {
        // rle: replicate v2 as many times as v1 says
        byte value = (byte)v2;
        while (v1-- > 0)
        {
          row[x++] = value;
        }
      }
      // end of line?
      if (x == bytesPerRow)
      {
        if (y <= getBoundsY2())
        {
          image.putByteSamples(0, 0, y - getBoundsY1(), COLUMNS, 1, row, X1);
        }
        if (delta)
        {
          x = newX;
          y = newY;
View Full Code Here

  }

  private void loadUncompressedPaletted4Stream() throws
    IOException
  {
    Paletted8Image image = (Paletted8Image)getImage();
    int imageBytesPerRow = (imageWidth + 1) / 2;
    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 X1 = getBoundsX1();
    int y = image.getHeight() - 1;
    int processedRows = 0;
    byte[] row = new byte[bytesPerRow];
    byte[] samples = new byte[bytesPerRow * 2];
    while (processedRows < ROWS)
    {
      in.readFully(row);
      ArrayConverter.decodePacked4Bit(row, 0, samples, 0, row.length);
      image.putByteSamples(0, 0, y, COLUMNS, 1, samples, X1);
      y--;
      setProgress(processedRows, ROWS);
      processedRows++;
    }
  }
View Full Code Here

    }
  }

  private void loadUncompressedPaletted8Stream() throws IOException
  {
    Paletted8Image image = (Paletted8Image)getImage();
    int imageBytesPerRow = imageWidth;
    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 X1 = getBoundsX1();
    int y = image.getHeight() - 1;
    int processedRows = 0;
    byte[] row = new byte[bytesPerRow];
    while (processedRows < ROWS)
    {
      in.readFully(row);
      image.putByteSamples(0, 0, y, COLUMNS, 1, row, X1);
      y--;
      setProgress(processedRows, ROWS);
      processedRows++;
    }
  }
View Full Code Here

TOP

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

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.