Qt: Use inbuilt png handler to resolve conflicts.

This commit is contained in:
Sacha committed 2014-06-18 16:15:10 +10:00
1 parent 1c93a58223
commit dbfb4d9962
1 file changed
+34
+34
View File
@@ -2,7 +2,11 @@
#include <stdlib.h>
#include <string.h>
#ifdef USING_QT_UI
#include <QImage>
#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;
}