diff --git a/image/png_load.cpp b/image/png_load.cpp index 33618ea868..3f48c12c84 100644 --- a/image/png_load.cpp +++ b/image/png_load.cpp @@ -2,7 +2,11 @@ #include #include +#ifdef USING_QT_UI +#include +#else #include "libpng17/png.h" +#endif #include "png_load.h" #include "base/logging.h" @@ -10,6 +14,20 @@ // *image_data_ptr should be deleted with free() // return value of 1 == success. int pngLoad(const char *file, int *pwidth, int *pheight, unsigned char **image_data_ptr, bool flip) { +#ifdef USING_QT_UI + QImage image(file, "PNG"); + if (image.isNull()) { + ELOG("pngLoad: Error loading image %s", file); + return 0; + } + if (flip) + image = image.mirrored(); + image.convertToFormat(QImage::Format_RGB32); + *pwidth = image.width(); + *pheight = image.height(); + *image_data_ptr = (unsigned char *)malloc(image.byteCount()); + memcpy(image.bits(), *image_data_ptr, image.byteCount()); +#else if (flip) ELOG("pngLoad: flip flag not supported, image will be loaded upside down"); png_image png; @@ -30,12 +48,27 @@ int pngLoad(const char *file, int *pwidth, int *pheight, unsigned char **image_d int stride = PNG_IMAGE_ROW_STRIDE(png); *image_data_ptr = (unsigned char *)malloc(PNG_IMAGE_SIZE(png)); png_image_finish_read(&png, NULL, *image_data_ptr, stride, NULL); +#endif return 1; } int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth, int *pheight, unsigned char **image_data_ptr, bool flip) { +#ifdef USING_QT_UI + QImage image; + if (!image.loadFromData(input_ptr, input_len)) { + ELOG("pngLoad: Error loading image"); + return 0; + } + if (flip) + image = image.mirrored(); + image.convertToFormat(QImage::Format_RGB32); + *pwidth = image.width(); + *pheight = image.height(); + *image_data_ptr = (unsigned char *)malloc(image.byteCount()); + memcpy(image.bits(), *image_data_ptr, image.byteCount()); +#else if (flip) ELOG("pngLoad: flip flag not supported, image will be loaded upside down"); png_image png; @@ -56,6 +89,7 @@ int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth, in int stride = PNG_IMAGE_ROW_STRIDE(png); *image_data_ptr = (unsigned char *)malloc(PNG_IMAGE_SIZE(png)); png_image_finish_read(&png, NULL, *image_data_ptr, stride, NULL); +#endif return 1; }