File size: 1,032 Bytes
0c51b93 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
#include "png.h"
#include <iostream>
#define STB_IMAGE_IMPLEMENTATION
#include "../external/stb_image/stb_image.h"
bool PngLoad(const char* filename, PngImage& image)
{
int x, y, c;
uint8_t* data = stbi_load(filename, &x, &y, &c, 4);
if (data)
{
int s = x*y;
image.m_data = new uint32_t[s];
memcpy(image.m_data, data, s*sizeof(char)*4);
image.m_width = (unsigned short)x;
image.m_height = (unsigned short)y;
stbi_image_free(data);
return true;
}
else
{
return false;
}
}
void PngFree(PngImage& image)
{
delete[] image.m_data;
}
bool HdrLoad(const char* filename, HdrImage& image)
{
int x, y, c;
float* data = stbi_loadf(filename, &x, &y, &c, 4);
if (data)
{
int s = x*y;
image.m_data = new float[s*4];
memcpy(image.m_data, data, s*sizeof(float)*4);
image.m_width = (unsigned short)x;
image.m_height = (unsigned short)y;
stbi_image_free(data);
return true;
}
else
{
return false;
}
}
void HdrFree(HdrImage& image)
{
delete[] image.m_data;
}
|