From 4f9f95a05a41bfbcc9965eaaf7f2d14c6af9f261 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 12 Apr 2009 15:42:04 +0000 Subject: Write C++ libdimension-png wrapper. --- tests/pngxx.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tests/pngxx.cpp (limited to 'tests/pngxx.cpp') diff --git a/tests/pngxx.cpp b/tests/pngxx.cpp new file mode 100644 index 0000000..ed7cffd --- /dev/null +++ b/tests/pngxx.cpp @@ -0,0 +1,102 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes * + * * + * This file is part of The Dimension Test Suite. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as published * + * by the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * Dimension is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * . * + *************************************************************************/ + +#include "../libdimensionxx/dimensionxx.hpp" +#include + +int +main() +{ + dmnsn_set_resilience(DMNSN_SEVERITY_LOW); + + const unsigned int width = 333, height = 300; + + { + std::ofstream ofstr("dimensionxx1.png", std::ios::binary); + Dimension::PNG_Canvas ocanvas(3*width, height, ofstr); + + Dimension::CIE_xyY xyY; + Dimension::CIE_Lab Lab; + Dimension::CIE_Luv Luv; + Dimension::sRGB RGB; + Dimension::Color color; + + for (unsigned int x = 0; x < width; ++x) { + for (unsigned int y = 0; y < height; ++y) { + /* CIE xyY colorspace */ + xyY = Dimension::CIE_xyY(static_cast(x)/(width - 1), + static_cast(y)/(height - 1), + 0.5); + color = xyY; + RGB = color; + + if (RGB.R() > 1.0 || RGB.G() > 1.0 || RGB.B() > 1.0 + || RGB.R() < 0.0 || RGB.G() < 0.0 || RGB.B() < 0.0) { + /* Out of sRGB gamut */ + color.trans(0.5); + } + + ocanvas.pixel(x, y, color); + + /* CIE Lab colorspace */ + + Lab = Dimension::CIE_Lab(75.0, + 200.0*(static_cast(x)/ + (width - 1) - 0.5), + 200.0*(static_cast(y)/ + (height - 1) - 0.5)); + color = Lab; + RGB = color; + + if (RGB.R() > 1.0 || RGB.G() > 1.0 || RGB.B() > 1.0 + || RGB.R() < 0.0 || RGB.G() < 0.0 || RGB.B() < 0.0) { + /* Out of sRGB gamut */ + color.trans(0.5); + } + + ocanvas.pixel(x + width, y, color); + + /* CIE Luv colorspace */ + + Luv = Dimension::CIE_Luv(75.0, + 200.0*(static_cast(x)/ + (width - 1) - 0.5), + 200.0*(static_cast(y)/ + (height - 1) - 0.5)); + color = Luv; + RGB = color; + + if (RGB.R() > 1.0 || RGB.G() > 1.0 || RGB.B() > 1.0 + || RGB.R() < 0.0 || RGB.G() < 0.0 || RGB.B() < 0.0) { + /* Out of sRGB gamut */ + color.trans(0.5); + } + + ocanvas.pixel(x + 2*width, y, color); + } + } + } + + std::ifstream ifstr("dimensionxx1.png", std::ios::binary); + std::ofstream ofstr("dimensionxx2.png", std::ios::binary); + Dimension::PNG_Canvas iocanvas(ifstr, ofstr); + + return 0; +} -- cgit v1.2.3