void PNGTests::testWriter() { static const int width = 256; static const int height = 256; // create an image and fill it with random data auto_ptr<Image> image(CreateImage(width, height, PF_R8G8B8A8)); setRandomBytes((byte*)image->getPixels(), width * height * 4); // generate filename char* filename = tmpnam(0); CPPUNIT_ASSERT_MESSAGE("opening temporary file", filename != 0); // save image CPPUNIT_ASSERT(SaveImage(filename, FF_PNG, image.get()) == true); // load it back auto_ptr<Image> img2(OpenImage(filename, PF_R8G8B8A8)); CPPUNIT_ASSERT_MESSAGE("reloading image file", img2.get() != 0); AssertImagesEqual( "comparing saved with loaded", image.get(), img2.get()); // force pixel format conversion (don't destroy the old image) auto_ptr<Image> img3(OpenImage(filename, PF_R8G8B8)); CPPUNIT_ASSERT(SaveImage(filename, FF_PNG, img3.get()) == true); remove(filename); //== PALETTIZED SAVING TEST == // disabled until loading palettized PNGs with a correct palette format // is implemented. #if 0 char* plt_filename = tmpnam(0); CPPUNIT_ASSERT_MESSAGE("opening temporary file (palette)", plt_filename != 0); auto_ptr<Image> plt(CreateImage(256, 256, PF_I8, 256, PF_R8G8B8)); setRandomBytes((byte*)plt->getPixels(), 256 * 256); setRandomBytes((byte*)plt->getPalette(), 256); CPPUNIT_ASSERT(SaveImage(plt_filename, FF_PNG, plt.get()) == true); auto_ptr<Image> plt2(OpenImage(plt_filename, FF_PNG)); CPPUNIT_ASSERT_MESSAGE("reloading palettized image", plt2.get() != 0); CPPUNIT_ASSERT(plt2->getPaletteSize() == 256); CPPUNIT_ASSERT(plt2->getPaletteFormat() == PF_R8G8B8); CPPUNIT_ASSERT(plt2->getFormat() == PF_I8); AssertImagesEqual("Comparing palettized image", plt.get(), plt2.get()); remove(plt_filename); #endif }
void JPEGTests::testLoader() { static string images[] = { "63", "63-1-subsampling", "63-floating", "63-high", "63-low", "63-progressive", "63-restart", "64", "comic-progressive", }; static const int image_count = sizeof(images) / sizeof(*images); static const string img_prefix("images/jpeg/"); static const string img_suffix(".jpeg"); static const string ref_prefix("images/jpeg/ref/"); static const string ref_suffix(".png"); for (int i = 0; i < image_count; ++i) { AssertImagesEqual(img_prefix + images[i] + img_suffix, ref_prefix + images[i] + ref_suffix); } }
void PCXTests::testLoader() { static string images[] = { "greyscale", "greyscale_odd", "palettized", "palettized_odd", "test", "test_odd", // we don't support these yet //"test_v0", //"test_v0_odd", //"test_v2", //"test_v2_odd", }; static const int image_count = sizeof(images) / sizeof(*images); static const string img_prefix("images/pcx/"); static const string img_suffix(".pcx"); static const string ref_prefix("images/pcx/ref/"); static const string ref_suffix(".png"); for (int i = 0; i < image_count; ++i) { AssertImagesEqual(img_prefix + images[i] + img_suffix, ref_prefix + images[i] + ref_suffix); } }
void BMPTests::testLoader() { static const string base = "images/bmpsuite/"; static const string reference_base = "images/bmpsuite/reference/"; static Comparison images[] = { { "g01bg.bmp", "01bg.png" }, { "g01bw.bmp", "01bw.png" }, { "g01p1.bmp", "01p1.png" }, { "g01wb.bmp", "01bw.png" }, { "g04.bmp", "04.png" }, { "g04p4.bmp", "04p4.png" }, { "g04rle.bmp", "04.png" }, { "g08.bmp", "08.png" }, { "g08offs.bmp", "08.png" }, { "g08os2.bmp", "08.png" }, { "g08p256.bmp", "08.png" }, { "g08p64.bmp", "08p64.png" }, { "g08pi256.bmp", "08.png" }, { "g08pi64.bmp", "08.png" }, { "g08res11.bmp", "08.png" }, { "g08res21.bmp", "08.png" }, { "g08res22.bmp", "08.png" }, { "g08rle.bmp", "08.png" }, { "g08s0.bmp", "08.png" }, { "g08w124.bmp", "08w124.png" }, { "g08w125.bmp", "08w125.png" }, { "g08w126.bmp", "08w126.png" }, { "g16bf555.bmp", "16bf555.png" }, { "g16bf565.bmp", "16bf565.png" }, { "g16def555.bmp", "16bf555.png" }, { "g24.bmp", "24.png" }, { "g32bf.bmp", "24.png" }, { "g32def.bmp", "24.png" }, }; static const int image_count = sizeof(images) / sizeof(*images); for (int i = 0; i < image_count; ++i) { AssertImagesEqual(base + images[i].image, reference_base + images[i].reference); } }
void APITests::testBasicOperations(int width, int height) { const PixelFormat format = PF_R8G8B8A8; const int bpp = 4; auto_ptr<Image> image(CreateImage(width, height, format)); CPPUNIT_ASSERT(image->getWidth() == width); CPPUNIT_ASSERT(image->getHeight() == height); CPPUNIT_ASSERT(image->getFormat() == format); // verify that the image is black byte* pixels = (byte*)image->getPixels(); for (int i = 0; i < width * height * bpp; ++i) { CPPUNIT_ASSERT(pixels[i] == 0); } // fill the image with random pixels for (int i = 0; i < width * height * bpp; ++i) { pixels[i] = rand() % 256; } auto_ptr<Image> create_clone( CreateImage(image->getWidth(), image->getHeight(), image->getFormat(), image->getPixels())); CPPUNIT_ASSERT(create_clone.get() != 0); CPPUNIT_ASSERT(image->getWidth() == create_clone->getWidth()); CPPUNIT_ASSERT(image->getHeight() == create_clone->getHeight()); CPPUNIT_ASSERT(image->getFormat() == create_clone->getFormat()); CPPUNIT_ASSERT(memcmp(image->getPixels(), create_clone->getPixels(), width * height * bpp) == 0); // clone the image (use same pixel format) auto_ptr<Image> identical_clone(CloneImage(image.get())); CPPUNIT_ASSERT(image->getWidth() == identical_clone->getWidth()); CPPUNIT_ASSERT(image->getHeight() == identical_clone->getHeight()); CPPUNIT_ASSERT(image->getFormat() == identical_clone->getFormat()); CPPUNIT_ASSERT(memcmp(image->getPixels(), identical_clone->getPixels(), width * height * bpp) == 0); // clone the image, removing the alpha channel auto_ptr<Image> other_clone(CloneImage(identical_clone.get(), PF_R8G8B8)); CPPUNIT_ASSERT(image->getWidth() == other_clone->getWidth()); CPPUNIT_ASSERT(image->getHeight() == other_clone->getHeight()); CPPUNIT_ASSERT(other_clone->getFormat() == PF_R8G8B8); byte* image_p = (byte*)image->getPixels(); byte* other_p = (byte*)other_clone->getPixels(); for (int i = 0; i < width * height; ++i) { CPPUNIT_ASSERT(*image_p++ == *other_p++); CPPUNIT_ASSERT(*image_p++ == *other_p++); CPPUNIT_ASSERT(*image_p++ == *other_p++); ++image_p; // skip alpha } // flip the image // clone source first, since flip frees the original auto_ptr<Image> flip_none(FlipImage(CloneImage(image.get()), 0)); auto_ptr<Image> flip_x (FlipImage(CloneImage(image.get()), CA_X)); auto_ptr<Image> flip_y (FlipImage(CloneImage(image.get()), CA_Y)); auto_ptr<Image> flip_xy (FlipImage(CloneImage(image.get()), CA_X | CA_Y)); AssertImagesEqual("No flipping", flip_none.get(), image.get()); CPPUNIT_ASSERT(flip_x.get() != 0); CPPUNIT_ASSERT(width == flip_x->getWidth()); CPPUNIT_ASSERT(height == flip_x->getHeight()); CPPUNIT_ASSERT(format == flip_x->getFormat()); CPPUNIT_ASSERT(flip_y.get() != 0); CPPUNIT_ASSERT(width == flip_y->getWidth()); CPPUNIT_ASSERT(height == flip_y->getHeight()); CPPUNIT_ASSERT(format == flip_y->getFormat()); CPPUNIT_ASSERT(flip_xy.get() != 0); CPPUNIT_ASSERT(width == flip_xy->getWidth()); CPPUNIT_ASSERT(height == flip_xy->getHeight()); CPPUNIT_ASSERT(format == flip_xy->getFormat()); const byte* flip_x_pixels = (const byte*)flip_x->getPixels(); const byte* flip_y_pixels = (const byte*)flip_y->getPixels(); const byte* flip_xy_pixels = (const byte*)flip_xy->getPixels(); for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { const int image_index = (h * width + w) * bpp; const int opp_w = width - 1 - w; const int opp_h = height - 1 - h; const int flip_x_index = (opp_h * width + w) * bpp; const int flip_y_index = (h * width + opp_w) * bpp; const int flip_xy_index = (opp_h * width + opp_w) * bpp; for (int p = 0; p < bpp; p++) { CPPUNIT_ASSERT(pixels[image_index] == flip_x_pixels [flip_x_index]); CPPUNIT_ASSERT(pixels[image_index] == flip_y_pixels [flip_y_index]); CPPUNIT_ASSERT(pixels[image_index] == flip_xy_pixels[flip_xy_index]); } } } }