Java Code Examples for java.awt.image.DataBuffer#setElem()

The following examples show how to use java.awt.image.DataBuffer#setElem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SHRPictureFile1.java    From DiskBrowser with GNU General Public License v3.0 6 votes vote down vote up
@Override
void createMonochromeImage ()
// ---------------------------------------------------------------------------------//
{
  image = new BufferedImage (320, 200, BufferedImage.TYPE_BYTE_GRAY);
  DataBuffer db = image.getRaster ().getDataBuffer ();

  int element = 0;
  int ptr = 0;
  for (int row = 0; row < 200; row++)
    for (int col = 0; col < 160; col++)
    {
      int pix1 = (buffer[ptr] & 0xF0) >> 4;
      int pix2 = buffer[ptr] & 0x0F;
      if (pix1 > 0)
        db.setElem (element, 255);
      if (pix2 > 0)
        db.setElem (element + 1, 255);
      element += 2;
      ptr++;
    }
}
 
Example 2
Source File: Wiz4Image.java    From DiskBrowser with GNU General Public License v3.0 6 votes vote down vote up
public Wiz4Image (String name, byte[] buffer, int rows, int cols)   // 5, 6
// ---------------------------------------------------------------------------------//
{
  super (name, buffer);

  image = new BufferedImage (cols * 7, rows * 8, BufferedImage.TYPE_BYTE_GRAY);
  DataBuffer db = image.getRaster ().getDataBuffer ();
  int element = 0;

  int rowSize = cols * 8;
  for (int row = 0; row < rows; row++)
    for (int line = 0; line < 8; line++)
      for (int col = 0; col < cols; col++)
      {
        byte b = buffer[row * rowSize + col * 8 + line];
        for (int bit = 0; bit < 7; bit++)
        {
          if ((b & 0x01) == 0x01)
            db.setElem (element, 255);
          b >>>= 1;
          element++;
        }
      }
}
 
Example 3
Source File: ImageV2.java    From DiskBrowser with GNU General Public License v3.0 6 votes vote down vote up
ImageV2 (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{
  super (name, buffer);

  image = new BufferedImage (70, 48, BufferedImage.TYPE_BYTE_GRAY); // width/height
  DataBuffer db = image.getRaster ().getDataBuffer ();
  int offset = 0;
  int size = 7;

  for (int i = 0; i < 6; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 7; k >= 0; k--)
      {
        int element = i * 560 + j * 7 + k * 70;
        int bits = buffer[offset++] & 0xFF;
        for (int m = size - 1; m >= 0; m--)
        {
          if ((bits & 1) == 1)
            db.setElem (element, 255);
          bits >>= 1;
          element++;
        }
      }
}
 
Example 4
Source File: CharacterRom.java    From DiskBrowser with GNU General Public License v3.0 6 votes vote down vote up
public CharacterRomCharacter (byte[] buffer, int ptr)
// -------------------------------------------------------------------------------//
{
  super (sizeX, sizeY);

  DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
  int element = 0;

  for (int i = 0; i < sizeY; i++)
  {
    int value = buffer[ptr++] & 0xFF;
    for (int j = 0; j < sizeX; j++)
    {
      dataBuffer.setElem (element++, (value & 0x80) == 0 ? 0 : 0xFF);
      value <<= 1;
    }
  }
}
 
Example 5
Source File: ShapeTable.java    From DiskBrowser with GNU General Public License v3.0 6 votes vote down vote up
void convertGrid (int offsetRows, int offsetColumns, int rows, int columns)
{
  //      System.out.printf ("Converting shape # %d%n", index);
  //      System.out.printf ("offsetRows %d offsetCols %d%n", offsetRows,
  // offsetColumns);
  //      System.out.printf ("rows %d cols %d%n", rows, columns);

  displayGrid = new int[rows][columns];
  for (int row = 0; row < rows; row++)
    for (int col = 0; col < columns; col++)
      displayGrid[row][col] = grid[offsetRows + row][offsetColumns + col];
  grid = null;

  // draw the image
  image = new BufferedImage (columns, rows, BufferedImage.TYPE_BYTE_GRAY);
  DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
  int element = 0;
  for (int row = 0; row < rows; row++)
    for (int col = 0; col < columns; col++)
      dataBuffer.setElem (element++, displayGrid[row][col] == 0 ? 0 : 255);

  startRow -= offsetRows;
  startCol -= offsetColumns;
  //      endRow -= offsetRows;
  //      endCol -= offsetColumns;
}
 
Example 6
Source File: FontFile.java    From DiskBrowser with GNU General Public License v3.0 6 votes vote down vote up
public FontFileCharacter (byte[] buffer, int ptr)
// -------------------------------------------------------------------------------//
{
  super (sizeX, sizeY);

  DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
  int element = 0;

  for (int i = 0; i < sizeY; i++)
  {
    int value = buffer[ptr++] & 0xFF;
    for (int j = 0; j < sizeX; j++)
    {
      dataBuffer.setElem (element++, (value & 0x01) == 0 ? 0 : 0xFF);
      value >>>= 1;
    }
  }
}
 
Example 7
Source File: DiffImage.java    From pdfcompare with Apache License 2.0 5 votes vote down vote up
private static void mark(final DataBuffer image, final int x, final int y, final int imageWidth, final int markerRGB) {
    final int yOffset = y * imageWidth;
    for (int i = 0; i < MARKER_WIDTH; i++) {
        image.setElem(x + i * imageWidth, markerRGB);
        image.setElem(i + yOffset, markerRGB);
    }
}
 
Example 8
Source File: HiResImage.java    From DiskBrowser with GNU General Public License v3.0 5 votes vote down vote up
int draw (DataBuffer dataBuffer, int element, int... rgbList)
// ---------------------------------------------------------------------------------//
{
  if (dataBuffer.getSize () < rgbList.length + element)
  {
    System.out.printf ("Bollocks: %d %d %d%n", dataBuffer.getSize (), rgbList.length,
        element);
    return element;
  }

  for (int rgb : rgbList)
    dataBuffer.setElem (element++, rgb);

  return element;
}
 
Example 9
Source File: QuickDrawFont.java    From DiskBrowser with GNU General Public License v3.0 5 votes vote down vote up
public QuickDrawCharacter (int strikeOffset, int strikeWidth)
// -------------------------------------------------------------------------------//
{
  super (strikeWidth, fRectHeight);

  DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();

  int element = 0;
  for (int row = 0; row < fRectHeight; row++)
    for (int j = strikeOffset; j < strikeOffset + strikeWidth; j++)
      dataBuffer.setElem (element++, strike[row].get (j) ? 255 : 0);
}
 
Example 10
Source File: DataParser.java    From commons-imaging with Apache License 2.0 5 votes vote down vote up
public final void parseData(final int[][][] data, final BufferedImage bi,
        final PsdImageContents imageContents) {
    final DataBuffer buffer = bi.getRaster().getDataBuffer();

    final PsdHeaderInfo header = imageContents.header;
    final int width = header.columns;
    final int height = header.rows;

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            final int rgb = getRGB(data, x, y, imageContents);
            buffer.setElem(y * width + x, rgb);
        }
    }
}
 
Example 11
Source File: DiffImage.java    From pdfcompare with Apache License 2.0 4 votes vote down vote up
public void diffImages() {
    BufferedImage expectBuffImage = this.expectedImage.bufferedImage;
    BufferedImage actualBuffImage = this.actualImage.bufferedImage;
    expectedBuffer = expectBuffImage.getRaster().getDataBuffer();
    actualBuffer = actualBuffImage.getRaster().getDataBuffer();

    expectedImageWidth = expectBuffImage.getWidth();
    expectedImageHeight = expectBuffImage.getHeight();
    actualImageWidth = actualBuffImage.getWidth();
    actualImageHeight = actualBuffImage.getHeight();

    resultImageWidth = Math.max(expectedImageWidth, actualImageWidth);
    resultImageHeight = Math.max(expectedImageHeight, actualImageHeight);
    resultImage = new BufferedImage(resultImageWidth, resultImageHeight, actualBuffImage.getType());
    DataBuffer resultBuffer = resultImage.getRaster().getDataBuffer();

    diffCalculator = new PageDiffCalculator(resultImageWidth * resultImageHeight, environment.getAllowedDiffInPercent());

    int expectedElement;
    int actualElement;
    final PageExclusions pageExclusions = exclusions.forPage(page + 1);

    for (int y = 0; y < resultImageHeight; y++) {
        final int expectedLineOffset = y * expectedImageWidth;
        final int actualLineOffset = y * actualImageWidth;
        final int resultLineOffset = y * resultImageWidth;
        for (int x = 0; x < resultImageWidth; x++) {
            expectedElement = getExpectedElement(x, y, expectedLineOffset);
            actualElement = getActualElement(x, y, actualLineOffset);
            int element = getElement(expectedElement, actualElement);
            if (pageExclusions.contains(x, y)) {
                element = ImageTools.fadeExclusion(element);
                if (expectedElement != actualElement) {
                    diffCalculator.diffFoundInExclusion();
                }
            } else {
                if (expectedElement != actualElement) {
                    extendDiffArea(x, y);
                    diffCalculator.diffFound();
                    LOG.trace("Difference found on page: {} at x: {}, y: {}", page + 1, x, y);
                    mark(resultBuffer, x, y, resultImageWidth, MARKER_RGB);
                }
            }
            resultBuffer.setElem(x + resultLineOffset, element);
        }
    }
    if (diffCalculator.differencesFound()) {
        diffCalculator.addDiffArea(new PageArea(page + 1, diffAreaX1, diffAreaY1, diffAreaX2, diffAreaY2));
        LOG.info("Differences found at { page: {}, x1: {}, y1: {}, x2: {}, y2: {} }", page + 1, diffAreaX1, diffAreaY1, diffAreaX2,
                diffAreaY2);
    }
    final float maxWidth = Math.max(expectedImage.width, actualImage.width);
    final float maxHeight = Math.max(expectedImage.height, actualImage.height);
    compareResult.addPage(diffCalculator, page, expectedImage, actualImage, new ImageWithDimension(resultImage, maxWidth, maxHeight));
}
 
Example 12
Source File: PixelTests.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void runTest(Object context, int numReps) {
    DataBuffer db = ((Context) context).db;
    do {
        db.setElem(numReps&7, 0);
    } while (--numReps > 0);
}
 
Example 13
Source File: PixelTests.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void runTest(Object context, int numReps) {
    DataBuffer db = ((Context) context).db;
    do {
        db.setElem(numReps&7, 0);
    } while (--numReps > 0);
}
 
Example 14
Source File: PixelTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void runTest(Object context, int numReps) {
    DataBuffer db = ((Context) context).db;
    do {
        db.setElem(numReps&7, 0);
    } while (--numReps > 0);
}
 
Example 15
Source File: PixelTests.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void runTest(Object context, int numReps) {
    DataBuffer db = ((Context) context).db;
    do {
        db.setElem(numReps&7, 0);
    } while (--numReps > 0);
}
 
Example 16
Source File: PixelTests.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void runTest(Object context, int numReps) {
    DataBuffer db = ((Context) context).db;
    do {
        db.setElem(numReps&7, 0);
    } while (--numReps > 0);
}
 
Example 17
Source File: PixelTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void runTest(Object context, int numReps) {
    DataBuffer db = ((Context) context).db;
    do {
        db.setElem(numReps&7, 0);
    } while (--numReps > 0);
}
 
Example 18
Source File: TestImage3.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static PlanarImage decodeImage (String[] rows)
    {
        // Create the DataBuffer to hold the pixel samples
        final int width = rows[0].length();
        final int height = rows.length;

        // Create Raster
        Raster raster;
        if (true) {
            raster = Raster.createPackedRaster
            (DataBuffer.TYPE_INT, width, height,
             new int[] {0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},// bandMasks RGBA
             null);
        } else {
            raster = Raster.createInterleavedRaster
                (DataBuffer.TYPE_BYTE, width, height,
                 4,// num of bands
                 null);
        }

        // Populate the data buffer
        DataBuffer dataBuffer = raster.getDataBuffer();
        int index = 0;
        for (String row : rows) {
            for (int x = 0; x < width; x++) {
                int argb = toARGB(row.charAt(x));
                dataBuffer.setElem(index, argb);
                index++;
            }
        }

        // Dump
//         final int size = width * height;
//         System.out.println("DataBuffer :");
//         for (int i = 0; i < size; i++) {
//             if (i % width == 0) {
//                 System.out.println();
//             }
//             System.out.print(String.format("%8x ", dataBuffer.getElem(i)));
//         }
//         System.out.println();

        // Create the image
        BufferedImage bufferedImage = new BufferedImage
                (width, height, BufferedImage.TYPE_INT_ARGB);
        bufferedImage.setData(raster);

        // Dump
//         System.out.println("BufferedImage :");
//         for (int y = 0; y < height; y++) {
//             System.out.println();
//             for (int x = 0; x < width; x++) {
//                 System.out.print(String.format("%8x ", bufferedImage.getRGB(x, y)));
//             }
//         }
//         System.out.println();

        return PlanarImage.wrapRenderedImage(bufferedImage);
    }
 
Example 19
Source File: PixelTests.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void runTest(Object context, int numReps) {
    DataBuffer db = ((Context) context).db;
    do {
        db.setElem(numReps&7, 0);
    } while (--numReps > 0);
}
 
Example 20
Source File: PixelTests.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void runTest(Object context, int numReps) {
    DataBuffer db = ((Context) context).db;
    do {
        db.setElem(numReps&7, 0);
    } while (--numReps > 0);
}