Package net.sourceforge.jiu.data

Examples of net.sourceforge.jiu.data.RGB24Image


      return image;
    }
    else
    if (performColorConversion)
    {
      RGB24Image image = new MemoryRGB24Image(width, height);
      int offset = 0;
      for (int y = 0; y < height; y++)
      {
        for (int x = 0; x < width; x++)
        {
          image.putByteSample(RGB24Image.INDEX_RED, x, y, data[0][offset]);
          image.putByteSample(RGB24Image.INDEX_GREEN, x, y, data[1][offset]);
          image.putByteSample(RGB24Image.INDEX_BLUE, x, y, data[2][offset]);
          offset++;
        }
      }
      return image;
    }
View Full Code Here


      createExtraHalfbritePalette();
    }
    int numBytesPerPlane = (width + 7) / 8;
    PixelImage image = null;
    Paletted8Image palettedImage = null;
    RGB24Image rgbImage = null;
    if (numPlanes == 24 || ham)
    {
      rgbImage = new MemoryRGB24Image(getBoundsWidth(), getBoundsHeight());
      image = rgbImage;
    }
    else
    {
      palettedImage = new MemoryPaletted8Image(getBoundsWidth(), getBoundsHeight(), palette);
      image = palettedImage;
    }
    /* only matters for uncompressed files;
       will be true if the number of bytes is odd;
       is computed differently for PBM and ILBM types
    */
    boolean oddBytesPerRow = (((numBytesPerPlane * numPlanes) % 2) != 0);
    if (type == MAGIC_PBM)
    {
      oddBytesPerRow = ((width % 2) == 1);
    }
    // plane data will have numPlanes planes for ILBM and 1 plane for PBM
    byte[][] planes = null;
    int numChannels = 1;
   
    if (type == MAGIC_ILBM)
    {
      int allocBytes = numBytesPerPlane;
      if ((numBytesPerPlane % 2) == 1)
      {
        allocBytes++;
      }
      // allocate numPlanes byte arrays
      planes = new byte[numPlanes][];
      if (rgb24 || ham)
      {
        numChannels = 3;
      }
      // for each of these byte arrays allocate numBytesPerPlane bytes
      for (int i = 0; i < numPlanes; i++)
      {
        planes[i] = new byte[allocBytes];
      }
    }
    else
    {
      // only one plane, but each plane has width bytes instead of
      // numBytesPerPlane
      planes = new byte[1][];
      planes[0] = new byte[width];
    }
    byte[][] dest = new byte[numChannels][];
    for (int i = 0; i < numChannels; i++)
    {
      dest[i] = new byte[width];
    }
    for (int y = 0, destY = 0 - getBoundsY1(); y <= getBoundsY2(); y++, destY++)
    {
      // load one row, different approach for PBM and ILBM
      if (type == MAGIC_ILBM)
      {
        // decode all planes for a complete row
        for (int p = 0; p < numPlanes; p++)
        {
          loadBytes(in, planes[p], numBytesPerPlane, y);
        }
      }
      else
      if (type == MAGIC_PBM)
      {
        loadBytes(in, planes[0], numBytesPerPlane, y);
      }
      /* all uncompressed rows must have an even number of bytes
         so in case the number of bytes per row is odd, one byte
         is read and dropped */
      if (compression == COMPRESSION_NONE && oddBytesPerRow)
      {
        in.readByte();
      }
      setProgress(y, getBoundsY2() + 1);
      // if we do not need the row we just loaded we continue loading
      // the next row
      if (!isRowRequired(y))
      {
        continue;
      }
      //System.out.println("storing row " + y + " as " + destY + ", numPlanes="+ numPlanes + ",type=" + type);
      // compute offset into pixel data array
      if (type == MAGIC_ILBM)
      {
        convertRow(planes, dest);
        if (rgb24 || ham)
        {
          rgbImage.putByteSamples(RGB24Image.INDEX_RED, 0, destY,
            getBoundsWidth(), 1, dest[0], getBoundsX1());
          rgbImage.putByteSamples(RGB24Image.INDEX_GREEN, 0, destY,
            getBoundsWidth(), 1, dest[1], getBoundsX1());
          rgbImage.putByteSamples(RGB24Image.INDEX_BLUE, 0, destY,
            getBoundsWidth(), 1, dest[2], getBoundsX1());
        }
        else
        {
          palettedImage.putByteSamples(0, 0, destY,
View Full Code Here

      palImage.getByteSamples(0, getBoundsX1(), y, getBoundsWidth(), 1, row, offs);
    }
    else
    if (image instanceof RGB24Image)
    {
      RGB24Image rgbImage = (RGB24Image)image;
      while (w-- > 0)
      {
        row[offs++] = rgbImage.getByteSample(RGBIndex.INDEX_RED, x1, y);
        row[offs++] = rgbImage.getByteSample(RGBIndex.INDEX_GREEN, x1, y);
        row[offs++] = rgbImage.getByteSample(RGBIndex.INDEX_BLUE, x1, y);
        x1++;
      }
    }
    else
    if (image instanceof RGB48Image)
    {
      RGB48Image rgbImage = (RGB48Image)image;
      while (w-- > 0)
      {
        short sample = rgbImage.getShortSample(RGBIndex.INDEX_RED, x1, y);
        ArrayConverter.setShortBE(row, offs, sample);
        offs += 2;

        sample = rgbImage.getShortSample(RGBIndex.INDEX_GREEN, x1, y);
        ArrayConverter.setShortBE(row, offs, sample);
        offs += 2;

        sample = rgbImage.getShortSample(RGBIndex.INDEX_BLUE, x1, y);
        ArrayConverter.setShortBE(row, offs, sample);
        offs += 2;

        x1++;
      }
View Full Code Here

    final int x2 = getBoundsX2();
    final int incr = ADAM7_COLUMN_INCREMENT[pass];
    int offset = 0;
    if (precision == 8)
    {
      RGB24Image rgbImage = (RGB24Image)image;
      while (x <= x2)
      {
        if (x >= x1)
        {
          rgbImage.putSample(RGB24Image.INDEX_RED, x, y, buffer[offset]);
          rgbImage.putSample(RGB24Image.INDEX_GREEN, x, y, buffer[offset + 1]);
          rgbImage.putSample(RGB24Image.INDEX_BLUE, x, y, buffer[offset + 2]);
        }
        x += incr;
        offset += 3;
      }
    }
    else
    if (precision == 16)
    {
      RGB48Image rgbImage = (RGB48Image)image;
      while (x <= x2)
      {
        if (x >= x1)
        {
          int red = (buffer[offset] & 0xff) << 8;
          red |= buffer[offset + 1] & 0xff;
          rgbImage.putSample(RGB24Image.INDEX_RED, x, y, red);
 
          int green = (buffer[offset + 2] & 0xff) << 8;
          green |= buffer[offset + 3] & 0xff;
          rgbImage.putSample(RGB24Image.INDEX_GREEN, x, y, green);
   
          int blue = (buffer[offset + 4] & 0xff) << 8;
          blue |= buffer[offset + 5] & 0xff;
          rgbImage.putSample(RGB24Image.INDEX_BLUE, x, y, blue);
        }
        x += incr;
        offset += 6;
      }
    }
View Full Code Here

    final int x2 = getBoundsX2();
    final int incr = ADAM7_COLUMN_INCREMENT[pass];
    int offset = 0;
    if (precision == 8)
    {
      RGB24Image rgbImage = (RGB24Image)image;
      while (x <= x2)
      {
        if (x >= x1)
        {
          rgbImage.putSample(RGB24Image.INDEX_RED, x, y, buffer[offset]);
          rgbImage.putSample(RGB24Image.INDEX_GREEN, x, y, buffer[offset + 1]);
          rgbImage.putSample(RGB24Image.INDEX_BLUE, x, y, buffer[offset + 2]);
          // store alpha
        }
        x += incr;
        offset += 4;
      }
    }
    else
    if (precision == 16)
    {
      RGB48Image rgbImage = (RGB48Image)image;
      while (x <= x2)
      {
        if (x >= x1)
        {
          int red = (buffer[offset] & 0xff) << 8;
          red |= buffer[offset + 1] & 0xff;
          rgbImage.putSample(RGB24Image.INDEX_RED, x, y, red);
 
          int green = (buffer[offset + 2] & 0xff) << 8;
          green |= buffer[offset + 3] & 0xff;
          rgbImage.putSample(RGB24Image.INDEX_GREEN, x, y, green);
   
          int blue = (buffer[offset + 4] & 0xff) << 8;
          blue |= buffer[offset + 5] & 0xff;
          rgbImage.putSample(RGB24Image.INDEX_BLUE, x, y, blue);
         
          // store alpha
        }
        x += incr;
        offset += 8;
View Full Code Here

  }

  private void loadColorImage() throws InvalidFileStructureException, IOException
  {
    RGBIntegerImage image = null;
    RGB24Image image24 = null;
    RGB48Image image48 = null;
    if (maxSample <= 255)
    {
      image24 = new MemoryRGB24Image(width, height);
      image = image24;
      setImage(image);
    }
    else
    {
      image48 = new MemoryRGB48Image(width, height);
      image = image48;
      setImage(image);
    }
    for (int y = 0, destY = - getBoundsY1(); y < height; y++, destY++)
    {
      if (getAscii().booleanValue())
      {
        for (int x = 0; x < width; x++)
        {
          int red = loadAsciiNumber();
          if (red < 0 || red > maxSample)
          {
            throw new InvalidFileStructureException("Invalid " +
              "sample value " + red + " for red sample at " +
              "(x=" + x + ", y=" + y + ").");
          }
          image.putSample(RGBIndex.INDEX_RED, x, y, red);

          int green = loadAsciiNumber();
          if (green < 0 || green > maxSample)
          {
            throw new InvalidFileStructureException("Invalid " +
              "sample value " + green + " for green sample at " +
              "(x=" + x + ", y=" + y + ").");
          }
          image.putSample(RGBIndex.INDEX_GREEN, x, y, green);

          int blue = loadAsciiNumber();
          if (blue < 0 || blue > maxSample)
          {
            throw new InvalidFileStructureException("Invalid " +
              "sample value " + blue + " for blue sample at " +
              "(x=" + x + ", y=" + y + ").");
          }
          image.putSample(RGBIndex.INDEX_BLUE, x, y, blue);
        }
      }
      else
      {
        if (image24 != null)
        {
          for (int x = 0; x < width; x++)
          {
            int red = in.read();
            if (red == -1)
            {
              throw new InvalidFileStructureException("Unexpected " +
                "end of file while reading red sample for pixel " +
                "x=" + x + ", y=" + y + ".");
            }
            image24.putByteSample(RGBIndex.INDEX_RED, x, y, (byte)(red & 0xff));
            int green = in.read();
            if (green == -1)
            {
              throw new InvalidFileStructureException("Unexpected " +
                "end of file while reading green sample for pixel " +
                "x=" + x + ", y=" + y + ".");
            }
            image24.putByteSample(RGBIndex.INDEX_GREEN, x, y, (byte)(green & 0xff));
            int blue = in.read();
            if (blue == -1)
            {
              throw new InvalidFileStructureException("Unexpected " +
                "end of file while reading blue sample for pixel " +
                "x=" + x + ", y=" + y + ".");
            }
            image24.putByteSample(RGBIndex.INDEX_BLUE, x, y, (byte)(blue & 0xff));
          }
        }
        else if (image48 != null)
        {
          for (int x = 0; x < width; x++)
View Full Code Here

    }
    if ((pg.getStatus() & ImageObserver.ABORT) != 0)
    {
      return null;
    }
    RGB24Image result = new MemoryRGB24Image(width, height);
    int offset = 0;
    for (int y = 0; y < height; y++)
    {
      for (int x = 0; x < width; x++)
      {
        int pixel = pixels[offset++] & 0xffffff;
        // TODO: store alpha value; requires some sort of
        // transparency channel data type yet to be implemented
        result.putSample(RGBIndex.INDEX_RED, x, y, pixel >> 16);
        result.putSample(RGBIndex.INDEX_GREEN, x, y, (pixel >> 8) & 0xff);
        result.putSample(RGBIndex.INDEX_BLUE, x, y, pixel & 0xff);
      }
    }
    return result;
  }
View Full Code Here

  private void storeNonInterlacedRgb(int y, byte[] buffer)
  {
    if (precision == 8)
    {
      RGB24Image rgbImage = (RGB24Image)image;
      int offset = getBoundsX1() * 3;
      int x = 0;
      int k = getBoundsWidth();
      while (k > 0)
      {
        rgbImage.putSample(RGB24Image.INDEX_RED, x, y, buffer[offset++]);
        rgbImage.putSample(RGB24Image.INDEX_GREEN, x, y, buffer[offset++]);
        rgbImage.putSample(RGB24Image.INDEX_BLUE, x, y, buffer[offset++]);
        x++;
        k--;
      }
    }
    else
    if (precision == 16)
    {
      RGB48Image rgbImage = (RGB48Image)image;
      int offset = getBoundsX1() * 6;
      int x = 0;
      int k = getBoundsWidth();
      while (k > 0)
      {
        int red = (buffer[offset++] & 0xff) << 8;
        red |= buffer[offset++] & 0xff;
        rgbImage.putSample(RGB24Image.INDEX_RED, x, y, red);

        int green = (buffer[offset++] & 0xff) << 8;
        green |= buffer[offset++] & 0xff;
        rgbImage.putSample(RGB24Image.INDEX_GREEN, x, y, green);
 
        int blue = (buffer[offset++] & 0xff) << 8;
        blue |= buffer[offset++] & 0xff;
        rgbImage.putSample(RGB24Image.INDEX_BLUE, x, y, blue);
 
        x++;
        k--;
      }
    }
View Full Code Here

  {
    switch(precision)
    {
      case(8):
      {
        RGB24Image rgbImage = (RGB24Image)image;
        int offset = getBoundsX1() * 3;
        int x = 0;
        int k = getBoundsWidth();
        while (k > 0)
        {
          rgbImage.putSample(RGB24Image.INDEX_RED, x, y, buffer[offset++]);
          rgbImage.putSample(RGB24Image.INDEX_GREEN, x, y, buffer[offset++]);
          rgbImage.putSample(RGB24Image.INDEX_BLUE, x, y, buffer[offset++]);
          offset++; // skip alpha; TODO: store in TransparencyInformation object
          x++;
          k--;
        }
        break;
      }
      case(16):
      {
        RGB48Image rgbImage = (RGB48Image)image;
        int offset = getBoundsX1() * 8;
        int x = 0;
        int k = getBoundsWidth();
        while (k > 0)
        {
          int red = (buffer[offset++] & 0xff) << 8;
          red |= buffer[offset++] & 0xff;
          rgbImage.putSample(RGB24Image.INDEX_RED, x, y, red);
   
          int green = (buffer[offset++] & 0xff) << 8;
          green |= buffer[offset++] & 0xff;
          rgbImage.putSample(RGB24Image.INDEX_GREEN, x, y, green);
   
          int blue = (buffer[offset++] & 0xff) << 8;
          blue |= buffer[offset++] & 0xff;
          rgbImage.putSample(RGB24Image.INDEX_BLUE, x, y, blue);
   
          offset += 2; // skip alpha; TODO: store in TransparencyInformation object
          x++;
          k--;
        }
View Full Code Here

    }
  }

  private void loadUncompressedRgb24Stream() throws IOException
  {
    RGB24Image image = (RGB24Image)getImage();
    int imageBytesPerRow = imageWidth * 3;
    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[COLUMNS];
    while (processedRows < ROWS)
    {
      in.readFully(row);
      // copy red samples to array samples and store those samples
      for (int x = X1 * 3 + 2, i = 0; i < COLUMNS; x += 3, i++)
      {
        samples[i] = row[x];
      }
      image.putByteSamples(RGBIndex.INDEX_RED, 0, y, COLUMNS, 1, samples, 0);
      // copy green samples to array samples and store those samples
      for (int x = X1 * 3 + 1, i = 0; i < COLUMNS; x += 3, i++)
      {
        samples[i] = row[x];
      }
      image.putByteSamples(RGBIndex.INDEX_GREEN, 0, y, COLUMNS, 1, samples, 0);
      // copy blue samples to array samples and store those samples
      for (int x = X1 * 3, i = 0; i < COLUMNS; x += 3, i++)
      {
        samples[i] = row[x];
      }
      image.putByteSamples(RGBIndex.INDEX_BLUE, 0, y, COLUMNS, 1, samples, 0);
      y--;
      setProgress(processedRows, ROWS);
      processedRows++;
    }
  }
View Full Code Here

TOP

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

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.