diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-06-13 18:47:00 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-06-13 18:47:00 +0200 |
commit | c91de71d69265a0d619b25d0c04ae1adb0785f33 (patch) | |
tree | 83176a79b8ed2d83f962758972e5a37a69d8259d /texturepng.cpp | |
parent | a6417af853180b5568c7f96c903057dd2c454204 (diff) |
Diffstat (limited to 'texturepng.cpp')
-rwxr-xr-x | texturepng.cpp | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/texturepng.cpp b/texturepng.cpp deleted file mode 100755 index 19dd4ab..0000000 --- a/texturepng.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include <iostream> -#include <stdexcept> -#include <png.h> -#include "texturepng.h" - -TexturePNG::TexturePNG(const char* filename) { - FILE *file = fopen(filename, "rb"); - if(!file) { - throw(std::runtime_error("TexturePNG file not found")); - } - png_byte header[8]; - fread(header, 1, 8, file); - if(png_sig_cmp(header, 0, 8)) { - throw(std::runtime_error("Invalid PNG file")); - } - png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); - if(!png_ptr) { - throw(std::runtime_error("LibPNG Error (png_ptr)")); - } - png_infop info_ptr = png_create_info_struct(png_ptr); - if(!info_ptr) { - throw(std::runtime_error("LibPNG Error (info_ptr)")); - } - png_infop end_info = png_create_info_struct(png_ptr); - if(!end_info) { - throw(std::runtime_error("LibPNG Error (end_info)")); - } - if (setjmp(png_jmpbuf(png_ptr))) { - throw(std::runtime_error("LibPNG Error")); - } - png_init_io(png_ptr, file); - png_set_sig_bytes(png_ptr, 8); - png_read_png(png_ptr, info_ptr, 0, 0); - png_bytep* row_pointers = png_get_rows(png_ptr, info_ptr); - width = png_get_image_width(png_ptr, info_ptr); - height = png_get_image_height(png_ptr, info_ptr); - data = new unsigned char[width * height * 4]; - for(int y = 0; y < height; y++) { - for(int x = 0; x < width * 4; x++) { - data[x + y*width*4] = row_pointers[y][x]; - } - } - build(); - png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); -} |