Java Code Examples for java.awt.image.BufferedImage.TYPE_USHORT_565_RGB

The following are Jave code examples for showing how to use TYPE_USHORT_565_RGB of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: java-sense-hat   File: Clock.java   View Source Code Vote up 6 votes
@Override
public void run() {
    BufferedImage bufferedImage = new BufferedImage(8,8,BufferedImage.TYPE_USHORT_565_RGB);

    while (!stop) {

        LocalTime now = LocalTime.now(clock);

        drawTime(bufferedImage, now);

        try {
            senseHat.fadeTo(bufferedImage, Duration.ofMillis(500));
        } catch (IOException e) {
            log.error(e.getLocalizedMessage(), e);
            throw new RuntimeException(e);
        }
    }
}
 
Example 2
Project: openjdk-jdk10   File: ColConvTest.java   View Source Code Vote up 6 votes
static String getImageTypeName(int type) {
    switch(type) {
        case BufferedImage.TYPE_INT_ARGB:
            return "TYPE_INT_ARGB";
        case BufferedImage.TYPE_INT_RGB:
            return "TYPE_INT_RGB";
        case BufferedImage.TYPE_INT_BGR:
            return "TYPE_INT_BGR";
        case BufferedImage.TYPE_INT_ARGB_PRE:
            return "TYPE_INT_ARGB_PRE";
        case BufferedImage.TYPE_3BYTE_BGR:
            return "TYPE_3BYTE_BGR";
        case BufferedImage.TYPE_4BYTE_ABGR:
            return "TYPE_4BYTE_ABGR";
        case BufferedImage.TYPE_4BYTE_ABGR_PRE:
            return "TYPE_4BYTE_ABGR_PRE";
        case BufferedImage.TYPE_BYTE_BINARY:
            return "TYPE_BYTE_BINARY";
        case BufferedImage.TYPE_BYTE_GRAY:
            return "TYPE_BYTE_GRAY";
        case BufferedImage.TYPE_BYTE_INDEXED:
            return "TYPE_BYTE_INDEXED";
        case BufferedImage.TYPE_USHORT_555_RGB:
            return "TYPE_USHORT_555_RGB";
        case BufferedImage.TYPE_USHORT_565_RGB:
            return "TYPE_USHORT_565_RGB";
        case BufferedImage.TYPE_USHORT_GRAY:
            return "TYPE_USHORT_GRAY";
    }
    return "UNKNOWN";
}
 
Example 3
Project: openjdk-jdk10   File: ImageTypeSpecifierBitsPerBand.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    int biType = BufferedImage.TYPE_USHORT_565_RGB;
    ImageTypeSpecifier type =
        ImageTypeSpecifier.createFromBufferedImageType(biType);

    int b0 = type.getBitsPerBand(0);
    int b1 = type.getBitsPerBand(1);
    int b2 = type.getBitsPerBand(2);

    if (b0 != 5 || b1 != 6 || b2 != 5) {
        throw new RuntimeException("Got incorrect bits per band value!");
    }

    boolean gotIAE = false;
    try {
        int b3 = type.getBitsPerBand(3);
    } catch (IllegalArgumentException e) {
        gotIAE = true;
    }
    if (!gotIAE) {
        throw new RuntimeException
            ("Failed to get IllegalArgumentException for band == 3!");
    }
}
 
Example 4
Project: openjdk-jdk10   File: BMPSubsamplingTest.java   View Source Code Vote up 5 votes
private String getImageTypeName(int t) {
    switch(t) {
      case BufferedImage.TYPE_INT_RGB:
          return "TYPE_INT_RGB";
      case BufferedImage.TYPE_INT_BGR:
          return "TYPE_INT_BGR";
      case TYPE_INT_GRB:
          return "TYPE_INT_GRB";
      case TYPE_INT_GBR:
          return "TYPE_INT_GBR";
      case TYPE_INT_RBG:
          return "TYPE_INT_RBG";
      case TYPE_INT_BRG:
          return "TYPE_INT_BRG";
      case BufferedImage.TYPE_USHORT_555_RGB:
          return "TYPE_USHORT_555_RGB";
      case BufferedImage.TYPE_USHORT_565_RGB:
          return "TYPE_USHORT_565_RGB";
      case TYPE_USHORT_555_GRB:
          return "TYPE_USHORT_555_GRB";
      case TYPE_USHORT_555_BGR:
          return "TYPE_USHORT_555_BGR";
      case TYPE_USHORT_565_BGR:
          return "TYPE_USHORT_565_BGR";
      case BufferedImage.TYPE_3BYTE_BGR:
          return "TYPE_3BYTE_BGR";
      case TYPE_3BYTE_RGB:
          return "TYPE_3BYTE_RGB";
      case TYPE_3BYTE_GRB:
          return "TYPE_3BYTE_GRB";
      case BufferedImage.TYPE_BYTE_INDEXED:
          return "TYPE_BYTE_INDEXED";
      case TYPE_4BPP_INDEXED:
          return "TYPE_BYTE_INDEXED (4bpp)";
      default:
          throw new IllegalArgumentException("Unknown image type: " + t);
    }
}
 
Example 5
Project: CDN-FX-2.2   File: IconImageUtils.java   View Source Code Vote up 5 votes
public static BufferedImage readImageFromStream(ByteArrayInputStream is, int width, int height, PixelFormat pixelFormat) throws Exception{
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_565_RGB);
    int ay = 0;
    while(ay < height){
        int ax = 0;
        while(ax < width){
            decodeTile(8, 8, ax, ay, img, is, pixelFormat);
            ax += 8;
        }
        ay += 8;
    }
    return img;
}
 
Example 6
Project: jdk8u-jdk   File: ColConvTest.java   View Source Code Vote up 5 votes
static String getImageTypeName(int type) {
    switch(type) {
        case BufferedImage.TYPE_INT_ARGB:
            return "TYPE_INT_ARGB";
        case BufferedImage.TYPE_INT_RGB:
            return "TYPE_INT_RGB";
        case BufferedImage.TYPE_INT_BGR:
            return "TYPE_INT_BGR";
        case BufferedImage.TYPE_INT_ARGB_PRE:
            return "TYPE_INT_ARGB_PRE";
        case BufferedImage.TYPE_3BYTE_BGR:
            return "TYPE_3BYTE_BGR";
        case BufferedImage.TYPE_4BYTE_ABGR:
            return "TYPE_4BYTE_ABGR";
        case BufferedImage.TYPE_4BYTE_ABGR_PRE:
            return "TYPE_4BYTE_ABGR_PRE";
        case BufferedImage.TYPE_BYTE_BINARY:
            return "TYPE_BYTE_BINARY";
        case BufferedImage.TYPE_BYTE_GRAY:
            return "TYPE_BYTE_GRAY";
        case BufferedImage.TYPE_BYTE_INDEXED:
            return "TYPE_BYTE_INDEXED";
        case BufferedImage.TYPE_USHORT_555_RGB:
            return "TYPE_USHORT_555_RGB";
        case BufferedImage.TYPE_USHORT_565_RGB:
            return "TYPE_USHORT_565_RGB";
        case BufferedImage.TYPE_USHORT_GRAY:
            return "TYPE_USHORT_GRAY";
    }
    return "UNKNOWN";
}
 
Example 7
Project: jdk8u-jdk   File: BMPSubsamplingTest.java   View Source Code Vote up 5 votes
private boolean canEncodeImage(String compression,
                               ImageTypeSpecifier imgType, int rawType)
{
    int biType = imgType.getBufferedImageType();
    if ((!compression.equals("BI_BITFIELDS")) &&
        ((rawType == BufferedImage.TYPE_USHORT_565_RGB) ||
         (rawType == TYPE_USHORT_565_BGR)))
    {
        return false;
    }

    int bpp = imgType.getColorModel().getPixelSize();
    if (compression.equals("BI_RLE4") && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compression.equals("BI_RLE8") && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }

    if (compression.equals("BI_PNG") &&
        ((rawType == TYPE_USHORT_555_GRB) ||
         (rawType == TYPE_USHORT_555_BGR)))
    {
        return false;
    }

    return true;
}
 
Example 8
Project: jdk8u-jdk   File: BMPSubsamplingTest.java   View Source Code Vote up 5 votes
private String getImageTypeName(int t) {
    switch(t) {
      case BufferedImage.TYPE_INT_RGB:
          return "TYPE_INT_RGB";
      case BufferedImage.TYPE_INT_BGR:
          return "TYPE_INT_BGR";
      case TYPE_INT_GRB:
          return "TYPE_INT_GRB";
      case TYPE_INT_GBR:
          return "TYPE_INT_GBR";
      case TYPE_INT_RBG:
          return "TYPE_INT_RBG";
      case TYPE_INT_BRG:
          return "TYPE_INT_BRG";
      case BufferedImage.TYPE_USHORT_555_RGB:
          return "TYPE_USHORT_555_RGB";
      case BufferedImage.TYPE_USHORT_565_RGB:
          return "TYPE_USHORT_565_RGB";
      case TYPE_USHORT_555_GRB:
          return "TYPE_USHORT_555_GRB";
      case TYPE_USHORT_555_BGR:
          return "TYPE_USHORT_555_BGR";
      case TYPE_USHORT_565_BGR:
          return "TYPE_USHORT_565_BGR";
      case BufferedImage.TYPE_3BYTE_BGR:
          return "TYPE_3BYTE_BGR";
      case TYPE_3BYTE_RGB:
          return "TYPE_3BYTE_RGB";
      case TYPE_3BYTE_GRB:
          return "TYPE_3BYTE_GRB";
      case BufferedImage.TYPE_BYTE_INDEXED:
          return "TYPE_BYTE_INDEXED";
      case TYPE_4BPP_INDEXED:
          return "TYPE_BYTE_INDEXED (4bpp)";
      default:
          throw new IllegalArgumentException("Unknown image type: " + t);
    }
}
 
Example 9
Project: java-sense-hat   File: SenseHat.java   View Source Code Vote up 5 votes
public BufferedImage getImage() throws IOException {
    BufferedImage image = new BufferedImage(8, 8, BufferedImage.TYPE_USHORT_565_RGB);

    short[] data = getDisplayData();
    image.getRaster().setDataElements(0, 0, 8, 8, data);

    return image;
}
 
Example 10
Project: java-sense-hat   File: SenseHat.java   View Source Code Vote up 5 votes
public void setImage(BufferedImage image) throws IOException {
    if (image.getType() == BufferedImage.TYPE_USHORT_565_RGB) {

        short[] data = (short[]) image.getRaster().getDataElements(0, 0, 8, 8, new short[64]);
        setDisplayData(data);

    } else {
        BufferedImage convertedImg = convertImage(image);

        setImage(convertedImg);
    }
}
 
Example 11
Project: openjdk-jdk10   File: TestCompressionBI_BITFIELDS.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws IOException {
    // buffered image types listed below can be saved as BI_BITFIELDS BMP
    int[] types = {BufferedImage.TYPE_3BYTE_BGR,
                   BufferedImage.TYPE_USHORT_555_RGB,
                   BufferedImage.TYPE_USHORT_565_RGB,
                   BufferedImage.TYPE_BYTE_GRAY,
                   BufferedImage.TYPE_BYTE_BINARY,
                   BufferedImage.TYPE_BYTE_INDEXED,
                   BufferedImage.TYPE_INT_BGR,
                   BufferedImage.TYPE_INT_RGB};

    for (int i = 0; i < types.length; i++) {
        System.out.println("Test image " + types[i]);
        TestCompressionBI_BITFIELDS t = new TestCompressionBI_BITFIELDS();

        BufferedImage src =
            t.createTestImage(types[i]);
        System.out.println("Image for test: " + src);
        System.out.println("SampleModel: " + src.getSampleModel());

        BufferedImage dst = null;
        try {
            dst = t.writeAndRead(src);
        } catch (IOException e) {
            e.printStackTrace(System.out);
        }


        t.compareImages(src, dst);
    }
}
 
Example 12
Project: openjdk-jdk10   File: NoExtraBytesTest.java   View Source Code Vote up 5 votes
private static String getImageTypeName(int t) {
    switch(t) {
        case BufferedImage.TYPE_INT_RGB:
            return "TYPE_INT_RGB";
        case BufferedImage.TYPE_INT_BGR:
            return "TYPE_INT_BGR";
        case BufferedImage.TYPE_3BYTE_BGR:
            return "TYPE_3BYTE_BGR";
        case BufferedImage.TYPE_USHORT_555_RGB:
            return "TYPE_USHORT_555_RGB";
        case BufferedImage.TYPE_USHORT_565_RGB:
            return "TYPE_USHORT_565_RGB";
        case TYPE_INT_GRB:
            return "TYPE_INT_GRB";
        case TYPE_INT_GBR:
            return "TYPE_INT_GBR";
        case TYPE_INT_RBG:
            return "TYPE_INT_RBG";
        case TYPE_INT_BRG:
            return "TYPE_INT_BRG";
        case TYPE_INT_555_GRB:
            return "TYPE_INT_555_GRB";
        case TYPE_3BYTE_RGB:
            return "TYPE_3BYTE_RGB";
        case TYPE_3BYTE_GRB:
            return "TYPE_3BYTE_GRB";
        default:
            throw new IllegalArgumentException("Unknown image type: " + t);
    }
}
 
Example 13
Project: openjdk-jdk10   File: WritingColorChangeTest.java   View Source Code Vote up 5 votes
private void doTest() {
    BufferedImage src = createTestImage(type);
    System.out.println("Sample model is " + src.getSampleModel());

    BufferedImage dst = doModification(src);

    Object dstPixel = dst.getRaster().getDataElements(width/2, height/2, null);
    Object srcPixel = src.getRaster().getDataElements(width/2, height/2, null);

    if (src.getType() == BufferedImage.TYPE_USHORT_555_RGB ||
        src.getType() == BufferedImage.TYPE_USHORT_565_RGB ) {

        Color cmpColor = new Color(dst.getColorModel().getRed(dstPixel),
                                   dst.getColorModel().getGreen(dstPixel),
                                   dst.getColorModel().getBlue(dstPixel));
        BufferedImage cmp = createTestImage(src.getType(), cmpColor);

        Object cmpPixel = cmp.getRaster().getDataElements(width/2, height/2, null);

        dst = cmp;
        dstPixel = cmpPixel;
    }

    if ( (src.getColorModel().getRed(srcPixel) != dst.getColorModel().getRed(dstPixel)) ||
         (src.getColorModel().getGreen(srcPixel) != dst.getColorModel().getGreen(dstPixel)) ||
         (src.getColorModel().getBlue(srcPixel) != dst.getColorModel().getBlue(dstPixel)) ||
         (src.getColorModel().getAlpha(srcPixel) != dst.getColorModel().getAlpha(dstPixel)) ) {

        showPixel(src, width/2, height/2);
        showPixel(dst, width/2, height/2);

        showRes(dst, src);
        throw new RuntimeException(
            "Colors are different: " +
            Integer.toHexString(src.getColorModel().getRGB(srcPixel)) + " and " +
            Integer.toHexString(dst.getColorModel().getRGB(dstPixel)));
    }
}
 
Example 14
Project: openjdk-jdk10   File: BMPSubsamplingTest.java   View Source Code Vote up 5 votes
private boolean canEncodeImage(String compression,
                               ImageTypeSpecifier imgType, int rawType)
{
    int biType = imgType.getBufferedImageType();
    if ((!compression.equals("BI_BITFIELDS")) &&
        ((rawType == BufferedImage.TYPE_USHORT_565_RGB) ||
         (rawType == TYPE_USHORT_565_BGR)))
    {
        return false;
    }

    int bpp = imgType.getColorModel().getPixelSize();
    if (compression.equals("BI_RLE4") && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compression.equals("BI_RLE8") && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }

    if (compression.equals("BI_PNG") &&
        ((rawType == TYPE_USHORT_555_GRB) ||
         (rawType == TYPE_USHORT_555_BGR)))
    {
        return false;
    }

    return true;
}
 
Example 15
Project: OpenJSharp   File: PixelTests.java   View Source Code Vote up 4 votes
public static void init() {
    pixelroot = new Group("pixel", "Pixel Access Benchmarks");

    pixeloptroot = new Group(pixelroot, "opts", "Pixel Access Options");
    doRenderTo = new Option.Toggle(pixeloptroot, "renderto",
                                   "Render to Image before test",
                                   Option.Toggle.Off);
    doRenderFrom = new Option.Toggle(pixeloptroot, "renderfrom",
                                     "Render from Image before test",
                                     Option.Toggle.Off);

    // BufferedImage Sources
    bufimgsrcroot = new Group.EnableSet(pixelroot, "src",
                                        "BufferedImage Sources");
    new BufImg(BufferedImage.TYPE_BYTE_BINARY, 1);
    new BufImg(BufferedImage.TYPE_BYTE_BINARY, 2);
    new BufImg(BufferedImage.TYPE_BYTE_BINARY, 4);
    new BufImg(BufferedImage.TYPE_BYTE_INDEXED);
    new BufImg(BufferedImage.TYPE_BYTE_GRAY);
    new BufImg(BufferedImage.TYPE_USHORT_555_RGB);
    new BufImg(BufferedImage.TYPE_USHORT_565_RGB);
    new BufImg(BufferedImage.TYPE_USHORT_GRAY);
    new BufImg(BufferedImage.TYPE_3BYTE_BGR);
    new BufImg(BufferedImage.TYPE_4BYTE_ABGR);
    new BufImg(BufferedImage.TYPE_INT_RGB);
    new BufImg(BufferedImage.TYPE_INT_BGR);
    new BufImg(BufferedImage.TYPE_INT_ARGB);

    // BufferedImage Tests
    bufimgtestroot = new Group(pixelroot, "bimgtests",
                               "BufferedImage Tests");
    new BufImgTest.GetRGB();
    new BufImgTest.SetRGB();

    // Raster Tests
    rastertestroot = new Group(pixelroot, "rastests",
                               "Raster Tests");
    new RasTest.GetDataElements();
    new RasTest.SetDataElements();
    new RasTest.GetPixel();
    new RasTest.SetPixel();

    // DataBuffer Tests
    dbtestroot = new Group(pixelroot, "dbtests",
                           "DataBuffer Tests");
    new DataBufTest.GetElem();
    new DataBufTest.SetElem();
}
 
Example 16
Project: OpenJSharp   File: BMPImageWriter.java   View Source Code Vote up 4 votes
protected int getPreferredCompressionType(ImageTypeSpecifier imageType) {
    if (imageType.getBufferedImageType() == BufferedImage.TYPE_USHORT_565_RGB) {
        return  BI_BITFIELDS;
    }
    return BI_RGB;
}
 
Example 17
Project: java-sense-hat   File: TextDisplay.java   View Source Code Vote up 4 votes
public void displayText(String text) throws IOException {
    BufferedImage image = new BufferedImage(8, 8, BufferedImage.TYPE_USHORT_565_RGB);

    Graphics2D graphics = image.createGraphics();

    if (big) {
        text = text.toUpperCase();
    }

    Font sansSerif = new Font("SansSerif", Font.PLAIN, big ? 10 : 8);
    graphics.setFont(sansSerif);
    int i = graphics.getFontMetrics().stringWidth(text) - 8;
    if (i <= 0) {
        i = 1;
    }

    long durationInMillis = duration.toMillis();

    for (int j = 0; j <= i; j++) {
        long start = System.currentTimeMillis();
        graphics.setColor(background);
        graphics.setPaint(background);
        graphics.fillRect(0, 0, 8, 8);

        graphics.setColor(foreground);
        graphics.setPaint(foreground);
        graphics.drawString(text, -j, big ? 8 : 7);
        senseHat.fadeTo(image, duration.dividedBy(2));

        long timeToSleep = durationInMillis - (System.currentTimeMillis() - start);
        if(timeToSleep > 0) {
            try {
                Thread.sleep(timeToSleep);
            } catch (InterruptedException e) {
                log.error(e.getLocalizedMessage(), e);
            }
        }
    }

    graphics.dispose();
}
 
Example 18
Project: java-sense-hat   File: SenseHat.java   View Source Code Vote up 4 votes
private BufferedImage convertImage(BufferedImage image) {
    BufferedImage convertedImg = new BufferedImage(8, 8, BufferedImage.TYPE_USHORT_565_RGB);
    Graphics graphics = convertedImg.getGraphics();
    graphics.drawImage(image, 0, 0, null);
    return convertedImg;
}
 
Example 19
Project: java-sense-hat   File: SenseHat.java   View Source Code Vote up 4 votes
public void fadeTo(BufferedImage image, Duration duration) throws IOException {

        if(image.getType() == BufferedImage.TYPE_USHORT_565_RGB) {
            short[] oldData = getDisplayData();
            SenseHatColor[] oldColors = new SenseHatColor[64];

            short[] newData = (short[]) image.getRaster().getDataElements(0, 0, 8, 8, new short[64]);
            SenseHatColor[] newColors = new SenseHatColor[64];

            for (int i = 0; i < 64; i++) {
                oldColors[i] = new SenseHatColor(oldData[i]);
                newColors[i] = new SenseHatColor(newData[i]);
            }

            short[] data = new short[64];

            long sleepTime = Math.max(10, duration.toMillis() / 64);

            float durationInMillis = duration.toMillis();
            long start = System.currentTimeMillis();
            while (true) {
                long currentDuration = System.currentTimeMillis() - start;
                float factor = currentDuration / durationInMillis;

                if (factor < 1d) {
                    for (int i = 0; i < 64; i++) {
                        data[i] = (short) oldColors[i].mix(newColors[i], factor).getSenseHatColor();
                    }
                    setDisplayData(data);
                    try {
                        Thread.sleep(sleepTime);
                    } catch (InterruptedException e) {
                        log.error(e.getLocalizedMessage(), e);
                    }
                } else {
                    setDisplayData(newData);
                    break;
                }
            }

        } else {
            fadeTo(convertImage(image), duration);
        }
    }
 
Example 20
Project: openjdk-jdk10   File: PixelTests.java   View Source Code Vote up 4 votes
public static void init() {
    pixelroot = new Group("pixel", "Pixel Access Benchmarks");

    pixeloptroot = new Group(pixelroot, "opts", "Pixel Access Options");
    doRenderTo = new Option.Toggle(pixeloptroot, "renderto",
                                   "Render to Image before test",
                                   Option.Toggle.Off);
    doRenderFrom = new Option.Toggle(pixeloptroot, "renderfrom",
                                     "Render from Image before test",
                                     Option.Toggle.Off);

    // BufferedImage Sources
    bufimgsrcroot = new Group.EnableSet(pixelroot, "src",
                                        "BufferedImage Sources");
    new BufImg(BufferedImage.TYPE_BYTE_BINARY, 1);
    new BufImg(BufferedImage.TYPE_BYTE_BINARY, 2);
    new BufImg(BufferedImage.TYPE_BYTE_BINARY, 4);
    new BufImg(BufferedImage.TYPE_BYTE_INDEXED);
    new BufImg(BufferedImage.TYPE_BYTE_GRAY);
    new BufImg(BufferedImage.TYPE_USHORT_555_RGB);
    new BufImg(BufferedImage.TYPE_USHORT_565_RGB);
    new BufImg(BufferedImage.TYPE_USHORT_GRAY);
    new BufImg(BufferedImage.TYPE_3BYTE_BGR);
    new BufImg(BufferedImage.TYPE_4BYTE_ABGR);
    new BufImg(BufferedImage.TYPE_INT_RGB);
    new BufImg(BufferedImage.TYPE_INT_BGR);
    new BufImg(BufferedImage.TYPE_INT_ARGB);

    // BufferedImage Tests
    bufimgtestroot = new Group(pixelroot, "bimgtests",
                               "BufferedImage Tests");
    new BufImgTest.GetRGB();
    new BufImgTest.SetRGB();

    // Raster Tests
    rastertestroot = new Group(pixelroot, "rastests",
                               "Raster Tests");
    new RasTest.GetDataElements();
    new RasTest.SetDataElements();
    new RasTest.GetPixel();
    new RasTest.SetPixel();

    // DataBuffer Tests
    dbtestroot = new Group(pixelroot, "dbtests",
                           "DataBuffer Tests");
    new DataBufTest.GetElem();
    new DataBufTest.SetElem();
}