use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestImplConvertBitmap method checkPlanarToArray.
public void checkPlanarToArray(Method m, Bitmap.Config config) {
Bitmap dst = Bitmap.createBitmap(w, h, config);
Class[] params = m.getParameterTypes();
try {
int numBands = Bitmap.Config.ARGB_8888 == config ? 4 : 3;
Class msType = m.getName().contains("U8") ? GrayU8.class : GrayF32.class;
Planar src = new Planar(msType, w, h, numBands);
GeneralizedImageOps.set(src.getBand(0), 1, 2, 0x38);
GeneralizedImageOps.set(src.getBand(1), 1, 2, 0x64);
GeneralizedImageOps.set(src.getBand(2), 1, 2, 0xFF);
if (numBands == 4)
GeneralizedImageOps.set(src.getBand(3), 1, 2, 0xFF);
Object array;
String info = params[0].getSimpleName();
if (params[2] == int[].class) {
info += " Array32";
array = buffer32;
} else {
info += " Array8";
array = buffer8;
}
info += " " + config;
m.invoke(null, src, array, config);
if (params[2] == int[].class) {
dst.copyPixelsFromBuffer(IntBuffer.wrap(buffer32));
} else {
dst.copyPixelsFromBuffer(ByteBuffer.wrap(buffer8));
}
if (config == Bitmap.Config.ARGB_8888) {
assertEquals(info, 0xFF3864FF, (int) dst.getPixel(1, 2));
assertEquals(info, 0x00000000, dst.getPixel(0, 0));
} else {
assertEquals(info, expected565(0x38, 0x64, 0xFF), (int) dst.getPixel(1, 2));
assertEquals(info, 0xFF000000, dst.getPixel(0, 0));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestImplConvertBitmap method checkPlanarToBitmapRGB.
public void checkPlanarToBitmapRGB(Method m, Bitmap.Config config) {
Bitmap dst = Bitmap.createBitmap(w, h, config);
Class[] params = m.getParameterTypes();
try {
int numBands = Bitmap.Config.ARGB_8888 == config ? 4 : 3;
Class msType = m.getName().contains("U8") ? GrayU8.class : GrayF32.class;
Planar src = new Planar(msType, w, h, numBands);
GeneralizedImageOps.set(src.getBand(0), 1, 2, 0x38);
GeneralizedImageOps.set(src.getBand(1), 1, 2, 0x64);
GeneralizedImageOps.set(src.getBand(2), 1, 2, 0xFF);
if (numBands == 4)
GeneralizedImageOps.set(src.getBand(3), 1, 2, 0xFF);
String info = m.getName() + " " + config;
m.invoke(null, src, dst);
if (config == Bitmap.Config.ARGB_8888) {
assertEquals(info, 0xFF3864FF, (int) dst.getPixel(1, 2));
assertEquals(info, 0x00000000, dst.getPixel(0, 0));
} else {
assertEquals(info, expected565(0x38, 0x64, 0xFF), (int) dst.getPixel(1, 2));
assertEquals(info, 0xFF000000, dst.getPixel(0, 0));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestImplConvertBitmap method checkArrayToPlanar.
public void checkArrayToPlanar(Method m, Bitmap.Config config) {
Bitmap orig = Bitmap.createBitmap(w, h, config);
orig.setPixel(1, 2, 0xFF204010);
Class[] params = m.getParameterTypes();
try {
int numBands = Bitmap.Config.ARGB_8888 == config ? 4 : 3;
Class msType = m.getName().contains("U8") ? GrayU8.class : GrayF32.class;
Planar found = new Planar(msType, w, h, numBands);
Object array;
String info = params[2].getSimpleName();
if (params[0] == int[].class) {
info += " Array32";
orig.copyPixelsToBuffer(IntBuffer.wrap(buffer32));
array = buffer32;
} else {
info += " Array8";
orig.copyPixelsToBuffer(ByteBuffer.wrap(buffer8));
array = buffer8;
}
info += " " + config;
m.invoke(null, array, config, found);
assertEquals(0x20, (int) GeneralizedImageOps.get(found.getBand(0), 1, 2));
assertEquals(0x40, (int) GeneralizedImageOps.get(found.getBand(1), 1, 2));
assertEquals(0x10, (int) GeneralizedImageOps.get(found.getBand(2), 1, 2));
if (numBands == 4)
assertEquals(0xFF, (int) GeneralizedImageOps.get(found.getBand(3), 1, 2));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class JCodecSimplified method getGuiImage.
@Override
public <InternalImage> InternalImage getGuiImage() {
Planar<GrayU8> boofColor = new Planar<>(GrayU8.class, frameCurrent.getWidth(), frameCurrent.getHeight(), 3);
BufferedImage output = new BufferedImage(boofColor.width, boofColor.height, BufferedImage.TYPE_INT_RGB);
UtilJCodec.convertToBoof(frameCurrent, boofColor);
ConvertBufferedImage.convertTo(boofColor, output, true);
return (InternalImage) output;
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestUtilImageIO method loadImage_saveImage_PPM.
@Test
public void loadImage_saveImage_PPM() throws IOException {
Planar<GrayU8> orig = new Planar<>(GrayU8.class, width, height, 3);
GImageMiscOps.fillUniform(orig, rand, 0, 256);
File temp = File.createTempFile("temp", ".png");
UtilImageIO.savePPM(orig, temp.getPath(), null);
Planar<GrayU8> found = UtilImageIO.loadPPM_U8(temp.getPath(), null, null);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
for (int k = 0; k < 3; k++) assertEquals(orig.getBand(k).get(x, y), found.getBand(k).get(x, y));
}
}
// clean up
// no assertTrue() here because in windows it will fail
temp.delete();
}
Aggregations