[DEV] try update to the png 1.6.21 version

This commit is contained in:
Edouard DUPIN 2016-04-22 21:12:20 +02:00
parent f60b5f34ed
commit 15f133a61c
5 changed files with 244 additions and 146 deletions

View File

@ -11,40 +11,79 @@
#include <egami/ImagePrivate.h>
#include <memory>
std::ostream& egami::operator <<(std::ostream& _os, const enum egami::colorType _type) {
switch (_type) {
case egami::colorType::RGBA8:
_os << "egami::colorType::RGBA8";
break;
case egami::colorType::RGB8:
_os << "egami::colorType::RGB8";
break;
case egami::colorType::RGBAf:
_os << "egami::colorType::RGBAf";
break;
case egami::colorType::RGBf:
_os << "egami::colorType::RGBf";
break;
case egami::colorType::unsignedInt16:
_os << "egami::colorType::unsignedInt16";
break;
case egami::colorType::unsignedInt32:
_os << "egami::colorType::unsignedInt32";
break;
case egami::colorType::float32:
_os << "egami::colorType::float32";
break;
case egami::colorType::float64:
_os << "egami::colorType::float64";
break;
}
return _os;
}
egami::Image::Image(const ivec2& _size, enum colorType _type) :
m_data(nullptr) {
switch (_type) {
case colorRGBA8:
case egami::colorType::RGBA8:
//m_data = std::make_shared<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t>>(_size));
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t>>(_size));
break;
case colorRGB8:
case egami::colorType::RGB8:
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t, 3>>(_size));
break;
case colorRGBAf:
case egami::colorType::RGBAf:
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<float>>(_size));
break;
case colorRGBf:
case egami::colorType::RGBf:
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<float, 3>>(_size));
break;
case colorU16:
case egami::colorType::unsignedInt16:
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint16_t, 1>>(_size));
break;
case colorU32:
case egami::colorType::unsignedInt32:
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint32_t, 1>>(_size));
break;
case colorFloat:
case egami::colorType::float32:
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<float, 1>>(_size));
break;
case colorDouble:
case egami::colorType::float64:
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<double, 1>>(_size));
break;
}
}
enum egami::colorType egami::Image::getType() {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image (nullptr)");
return egami::colorType::RGBA8;
}
return m_data->getType();
}
void* egami::Image::getTextureDataPointer() {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not get internal data pointer");
EGAMI_WARNING("No internal data for image (nullptr)");
return nullptr;
}
return m_data->getTextureDataPointer();
@ -52,7 +91,7 @@ void* egami::Image::getTextureDataPointer() {
void egami::Image::resize(const ivec2& _size, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->resize(_size, _startPos);
@ -60,42 +99,42 @@ void egami::Image::resize(const ivec2& _size, const ivec2& _startPos) {
void egami::Image::resize(const ivec2& _size, const etk::Color<>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<float>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<uint16_t, 1>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<uint32_t, 1>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<float, 1>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<double, 1>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->resize(_size, _color, _startPos);
@ -103,7 +142,7 @@ void egami::Image::resize(const ivec2& _size, const etk::Color<double, 1>& _colo
const ivec2& egami::Image::getSize() const {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
static const ivec2 error(0,0);
return error;
}
@ -112,7 +151,7 @@ const ivec2& egami::Image::getSize() const {
int32_t egami::Image::getWidth() const {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
return 0;
}
return m_data->getWidth();
@ -120,7 +159,7 @@ int32_t egami::Image::getWidth() const {
int32_t egami::Image::getHeight() const {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
EGAMI_WARNING("No internal data for image (nullptr)");
return 0;
}
return m_data->getHeight();
@ -129,7 +168,7 @@ int32_t egami::Image::getHeight() const {
void egami::Image::scale(const ivec2& _size) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not scale");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
resize(_size);
@ -137,42 +176,42 @@ void egami::Image::scale(const ivec2& _size) {
void egami::Image::clear(const etk::Color<>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<float>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<uint16_t, 1>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<uint32_t, 1>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<float, 1>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<double, 1>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->clear();
@ -187,11 +226,11 @@ etk::Color<> egami::Image::get(const ivec2& _pos) const {
void egami::Image::insert(const ivec2& _pos, const egami::Image& _input) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not insert image");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
if (_input.m_data == nullptr) {
EGAMI_WARNING("No input data for image : Can not insert nullptr image");
EGAMI_WARNING("No input data for image (nullptr)");
return;
}
enum colorType destType = m_data->getType();
@ -210,7 +249,7 @@ void egami::Image::insert(const ivec2& _pos, const egami::Image& _input) {
void egami::Image::set(const ivec2& _pos, const etk::Color<>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->set(_pos, _newColor);
@ -218,7 +257,7 @@ void egami::Image::set(const ivec2& _pos, const etk::Color<>& _newColor) {
void egami::Image::set(const ivec2& _pos, const etk::Color<float>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->set(_pos, _newColor);
@ -226,7 +265,7 @@ void egami::Image::set(const ivec2& _pos, const etk::Color<float>& _newColor) {
void egami::Image::set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->set(_pos, _newColor);
@ -234,7 +273,7 @@ void egami::Image::set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newCol
void egami::Image::set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->set(_pos, _newColor);
@ -242,7 +281,7 @@ void egami::Image::set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newCol
void egami::Image::set(const ivec2& _pos, const etk::Color<float, 1>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->set(_pos, _newColor);
@ -250,7 +289,7 @@ void egami::Image::set(const ivec2& _pos, const etk::Color<float, 1>& _newColor)
void egami::Image::set(const ivec2& _pos, const etk::Color<double, 1>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->set(_pos, _newColor);
@ -258,7 +297,7 @@ void egami::Image::set(const ivec2& _pos, const etk::Color<double, 1>& _newColor
void egami::Image::set(const std::vector<etk::Color<float,4>>& _data, const ivec2& _size) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->set(_data, _size);
@ -266,7 +305,7 @@ void egami::Image::set(const std::vector<etk::Color<float,4>>& _data, const ivec
void egami::Image::set(const std::vector<etk::Color<uint8_t,4>>& _data, const ivec2& _size) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
EGAMI_WARNING("No internal data for image (nullptr)");
return;
}
m_data->set(_data, _size);

View File

@ -15,28 +15,31 @@
#include <memory>
namespace egami {
enum colorType {
colorRGBA8,
colorRGB8,
colorRGBAf,
colorRGBf,
colorU16,
colorU32,
colorFloat,
colorDouble,
enum class colorType {
RGBA8,
RGB8,
RGBAf,
RGBf,
//unsignedInt8,
unsignedInt16,
unsignedInt32,
float32,
float64,
};
std::ostream& operator <<(std::ostream& _os, const enum egami::colorType _obj);
class ImagePrivate;
class Image {
private:
std::shared_ptr<ImagePrivate> m_data;
std::shared_ptr<ImagePrivate> m_data; //!< data of the image
public:
// constructor :
Image(const ivec2& _size=ivec2(32,32), enum colorType _type=colorRGBA8);
Image(const ivec2& _size=ivec2(32,32), enum colorType _type=egami::colorType::RGBA8);
// destructor
~Image() { };
// EWOL internal API for Texture system :
public:
void* getTextureDataPointer();
enum colorType getType();
// -----------------------------------------------
// -- basic tools :
// -----------------------------------------------

View File

@ -28,6 +28,11 @@ namespace egami {
void* getTextureDataPointer() {
return &m_data[0];
};
/*
enum colorType getType() {
return egami::colorType::unsignedInt8;
};
*/
// -----------------------------------------------
// -- basic tools :
// -----------------------------------------------

View File

@ -21,7 +21,7 @@ namespace egami {
virtual const ivec2& getSize()=0;
virtual int32_t getWidth() const { return 0; };
virtual int32_t getHeight() const { return 0; };
virtual enum colorType getType() { return colorRGBA8; };
virtual enum colorType getType() { return egami::colorType::RGBA8; };
virtual void clear() = 0;
virtual void resize(const ivec2& _size, const etk::Color<uint8_t, 4>& _color, const ivec2& _startPos) = 0;
virtual void resize(const ivec2& _size, const etk::Color<float, 4>& _color, const ivec2& _startPos) = 0;
@ -252,28 +252,28 @@ namespace egami {
}
};
template <> enum colorType ImageTemplate<etk::Color<uint8_t>>::getType() {
return colorRGBA8;
return egami::colorType::RGBA8;
}
template <> enum colorType ImageTemplate<etk::Color<uint8_t, 3>>::getType() {
return colorRGB8;
return egami::colorType::RGB8;
}
template <> enum colorType ImageTemplate<etk::Color<float>>::getType() {
return colorRGBAf;
return egami::colorType::RGBAf;
}
template <> enum colorType ImageTemplate<etk::Color<float, 3>>::getType() {
return colorRGBf;
return egami::colorType::RGBf;
}
template <> enum colorType ImageTemplate<etk::Color<uint16_t, 1>>::getType() {
return colorU16;
return egami::colorType::unsignedInt16;
}
template <> enum colorType ImageTemplate<etk::Color<uint32_t, 1>>::getType() {
return colorU32;
return egami::colorType::unsignedInt32;
}
template <> enum colorType ImageTemplate<etk::Color<float, 1>>::getType() {
return colorFloat;
return egami::colorType::float32;
}
template <> enum colorType ImageTemplate<etk::Color<double, 1>>::getType() {
return colorDouble;
return egami::colorType::float64;
}
};

View File

@ -38,25 +38,27 @@ static void localFlushData(png_structp png_ptr)
}
*/
void user_error_fn(png_structp _pngPtr, png_const_charp _errorMsg) {
EGAMI_DEBUG("libpng error: '" << _errorMsg << "'");
}
void user_warning_fn(png_structp _pngPtr, png_const_charp _warningMsg) {
EGAMI_DEBUG("libpng warning: '" << _warningMsg << "'");
}
bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
etk::FSNode fileName(_inputFile);
if (false == fileName.exist()) {
EGAMI_ERROR("File does not existed=\"" << fileName << "\"");
if (fileName.exist() == false) {
EGAMI_ERROR("File does not existed='" << fileName << "'");
return false;
}
if(false == fileName.fileOpenRead() ) {
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
if(fileName.fileOpenRead() == false) {
EGAMI_ERROR("Can not find the file name='" << fileName << "'");
return false;
}
// Vars
int x, y = 0;
int rowbytes;
unsigned char header[8];
png_infop info_ptr;
png_structp png_ptr;
png_bytep * row_pointers;
if (fileName.fileRead(header,1,8) != 8) {
EGAMI_ERROR("error loading file header");
@ -69,123 +71,170 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
}
// PNG read setup
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, user_error_fn, user_warning_fn);
if (png_ptr == nullptr) {
EGAMI_ERROR("Can not Allocate PNG structure");
fileName.fileClose();
return false;
}
info_ptr = png_create_info_struct(png_ptr);
setjmp(png_jmpbuf(png_ptr));
if (info_ptr == nullptr) {
EGAMI_ERROR("Can not Allocate PNG info structure");
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
fileName.fileClose();
return false;
}
/*
if (setjmp(png_jmpbuf(png_ptr))) {
EGAMI_ERROR(" Can not set the JUMP buffer adresses");
// Free all of the memory associated with the png_ptr and info_ptr
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
fileName.fileClose();
return false;
}
*/
// overwrite the read and write function :
#if 1
png_set_read_fn(png_ptr,
&fileName,
&local_ReadData);
/*
png_set_write_fn(png_ptr,
&fileName,
&LocalWriteData,
&localFlushData);
*/
#else
png_init_io(png_ptr, fp);
#endif
png_set_read_fn(png_ptr,
&fileName,
&local_ReadData);
/*
png_set_write_fn(png_ptr,
&fileName,
&LocalWriteData,
&localFlushData);
*/
// If we have already read some of the signature
png_set_sig_bytes(png_ptr, 8);
png_read_info(png_ptr, info_ptr);
int32_t width = png_get_image_width(png_ptr, info_ptr);
int32_t height = png_get_image_height(png_ptr, info_ptr);
png_uint_32 width = 0;
png_uint_32 height = 0;
int bit_depth = 0;
int color_type = 0;
int interlace_type = 0;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);
// reallocate the image
EGAMI_VERBOSE("Load PNG image : (" << width << "," << height << ")" );
_ouputImage.resize(ivec2(width,height));
int32_t bit_depth = png_get_bit_depth(png_ptr, info_ptr);
png_read_update_info(png_ptr, info_ptr);
setjmp(png_jmpbuf(png_ptr));
/* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
* transparency chunks to full alpha channel; strip 16-bit-per-sample
* images to 8 bits per sample; and convert grayscale to RGB[A] */
// TODO : TEMPORARY section : [START]
int32_t color_type = png_get_color_type(png_ptr, info_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_expand(png_ptr);
}
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
png_set_expand(png_ptr);
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_set_expand(png_ptr);
}
if (bit_depth == 16) {
// Tell libpng to strip 16 bits/color files down to 8 bits/color. Use accurate scaling if it's available, otherwise just chop off the low byte.
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_set_scale_16(png_ptr);
#else
png_set_strip_16(png_ptr);
#endif
// Strip alpha bytes from the input data without combining with the background (not recommended).
//png_set_strip_alpha(png_ptr);
// Extract multiple pixels with bit depths of 1, 2, and 4 from a single byte into separate bytes (useful for paletted and grayscale images).
png_set_packing(png_ptr);
// Change the order of packed pixels to least significant bit first (not useful if you are using png_set_packing).
png_set_packswap(png_ptr);
/* Expand paletted colors into true RGB triplets */
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(png_ptr);
}
/*
// Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel
if ( color_type == PNG_COLOR_TYPE_GRAY
|| color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
png_set_gray_to_rgb(png_ptr);
&& bit_depth < 8) {
png_set_expand_gray_1_2_4_to_8(png_ptr);
}
// Expand paletted or RGB images with transparency to full alpha channels so the data will be available as RGBA quartets.
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) != 0) {
png_set_tRNS_to_alpha(png_ptr);
}
/* Set the background color to draw transparent and alpha images over.
* It is possible to set the red, green, and blue components directly
* for paletted images instead of supplying a palette index. Note that
* even if the PNG file supplies a background, you are not required to
* use it - you should use the (solid) application background if it has one.
*/
/*
png_color_16 my_background, *image_background;
if (png_get_bKGD(png_ptr, info_ptr, &image_background) != 0) {
png_set_background(png_ptr, image_background, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
} else {
png_set_background(png_ptr, &my_background, PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
}
*/
// TODO : TEMPORARY section : [STOP]
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
/* Optional call to gamma correct and add the background to the palette
* and update info structure. REQUIRED if you are expecting libpng to
* update the palette for you (ie you selected such a transform above).
*/
png_read_update_info(png_ptr, info_ptr);
row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
rowbytes = width * ((bit_depth == 16) ? 8 : 4);
// File read
for (y = 0; y < height; y++) {
row_pointers[y] = (png_byte*) malloc(rowbytes);
// Allocate the memory to hold the image using the fields of info_ptr.
// The easiest way to read the image:
png_bytep row_pointers[height];
/* Clear the pointer array */
for (png_uint_32 row = 0; row < height; row++) {
row_pointers[row] = nullptr;
}
for (png_uint_32 row = 0; row < height; row++) {
row_pointers[row] = (png_bytep)png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));
}
EGAMI_ERROR("Load image: " << _inputFile);
png_read_image(png_ptr, row_pointers);
png_set_expand(png_ptr);
png_set_strip_16(png_ptr);
EGAMI_ERROR("Load image: " << _inputFile << " DONE");
// Read rest of file, and get additional chunks in info_ptr - REQUIRED
png_read_end(png_ptr, info_ptr);
//png_set_expand(png_ptr);
etk::Color<> tmpColor(0,0,0,0);
switch (png_get_color_type(png_ptr, info_ptr) ) {
switch (color_type) {
case PNG_COLOR_TYPE_RGBA:
EGAMI_ERROR("plop: PNG_COLOR_TYPE_RGBA");
// Conversion to OpenGL texture
for (y = 0; y < height; y++) {
png_byte* row = row_pointers[y];
for (x = 0; x < width; x++) {
png_byte* ptr = &(row[x*4]);
tmpColor.set(ptr[0], ptr[1],ptr[2],ptr[3]);
_ouputImage.set(ivec2(x,y), tmpColor);
for (png_uint_32 yyy = 0; yyy < height; ++yyy) {
png_byte* row = row_pointers[yyy];
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
png_byte* ptr = &(row[xxx*4]);
tmpColor.set(ptr[0], ptr[1], ptr[2], ptr[3]);
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
}
free(row_pointers[y]);
}
break;
case PNG_COLOR_TYPE_RGB:
EGAMI_ERROR("plop: PNG_COLOR_TYPE_RGB");
// Conversion to OpenGL texture
for (y = 0; y < height; y++) {
png_byte* row = row_pointers[y];
for (x = 0; x < width; x++) {
png_byte* ptr = &(row[x*3]);
tmpColor.set(ptr[0], ptr[1],ptr[2]);
_ouputImage.set(ivec2(x,y), tmpColor);
for (png_uint_32 yyy = 0; yyy < height; ++yyy) {
png_byte* row = row_pointers[yyy];
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
png_byte* ptr = &(row[xxx*3]);
tmpColor.set(ptr[0], ptr[1], ptr[2]);
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
}
free(row_pointers[y]);
}
break;
case PNG_COLOR_TYPE_GRAY:
EGAMI_ERROR("plop: PNG_COLOR_TYPE_GRAY");
// Conversion to OpenGL texture
for (y = 0; y < height; y++) {
png_byte* row = row_pointers[y];
for (x = 0; x < width; x++) {
png_byte* ptr = &(row[x]);
tmpColor.set(ptr[0],ptr[0],ptr[0]);
_ouputImage.set(ivec2(x,y), tmpColor);
for (png_uint_32 yyy = 0; yyy < height; ++yyy) {
png_byte* row = row_pointers[yyy];
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
png_byte* ptr = &(row[xxx]);
tmpColor.set(ptr[0], ptr[0], ptr[0]);
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
}
free(row_pointers[y]);
}
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
EGAMI_ERROR("plop: PNG_COLOR_TYPE_GRAY_ALPHA");
// Conversion to OpenGL texture
for (y = 0; y < height; y++) {
png_byte* row = row_pointers[y];
for (x = 0; x < width; x++) {
png_byte* ptr = &(row[x*2]);
tmpColor.set(ptr[0],ptr[0],ptr[0],ptr[1]);
_ouputImage.set(ivec2(x,y), tmpColor);
for (png_uint_32 yyy = 0; yyy < height; ++yyy) {
png_byte* row = row_pointers[yyy];
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
png_byte* ptr = &(row[xxx*2]);
tmpColor.set(ptr[0], ptr[0], ptr[0], ptr[1]);
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
}
free(row_pointers[y]);
}
break;
default:
@ -202,6 +251,8 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
return false;
}
fileName.fileClose();
// Clean up after the read, and free any memory allocated - REQUIRED
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return true;
}