diff options
| author | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-05-03 14:38:52 +0200 | 
|---|---|---|
| committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-05-03 14:38:52 +0200 | 
| commit | ee7304700b2f058864d6ef588531399eb9104ea9 (patch) | |
| tree | a346d15138d07b403fcd13c794bd30b32e86a383 /plugingui | |
| parent | f07c7bb8707f3c07d98f8c7f5c4cb78a5b285b7b (diff) | |
PNG error handling, extreme
Diffstat (limited to 'plugingui')
| -rw-r--r-- | plugingui/image.cc | 57 | ||||
| -rw-r--r-- | plugingui/image.h | 2 | ||||
| -rw-r--r-- | plugingui/resource_data.cc | 164 | ||||
| -rwxr-xr-x | plugingui/resources/createrc.sh | 2 | ||||
| -rw-r--r-- | plugingui/resources/png_error | bin | 0 -> 2608 bytes | 
5 files changed, 207 insertions, 18 deletions
| diff --git a/plugingui/image.cc b/plugingui/image.cc index 32994b6..d0afe70 100644 --- a/plugingui/image.cc +++ b/plugingui/image.cc @@ -26,24 +26,15 @@   */  #include "image.h" -#include "resource.h" -  #include <unistd.h>  #include <stdlib.h>  #include <stdio.h>  #include <string.h>  #include <stdarg.h> -void abort_(const char * s, ...) -{ -  va_list args; -  va_start(args, s); -  vfprintf(stderr, s, args); -  fprintf(stderr, "\n"); -  va_end(args); -  abort(); -} +#include <hugin.hpp> +#include "resource.h"  // http://blog.hammerian.net/2009/reading-png-images-from-memory/  typedef struct { @@ -77,29 +68,59 @@ GUI::Image::~Image()  {  } +void GUI::Image::setError(int err) +{ +  GUI::Resource rc(":png_error"); + +  const char *p = rc.data(); + +  memcpy(&w, p, 4); p += 4; +  memcpy(&h, p, 4); p += 4; + +  DEBUG(image, "w:%d, h:%d\n", w, h); + +  row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * h); +  for(unsigned int y = 0; y < h; y++) { +    size_t size = w * sizeof(unsigned int); +    DEBUG(image, "rc.size:%d >= p:%d (rowsize: %d)\n", +          rc.size(), p - rc.data(), size); +    row_pointers[y] = (png_byte*)malloc(size); +    memcpy(row_pointers[y], p, size); +    p += size; +  } +} +  void GUI::Image::load(const char* data, size_t size)  {    const char *header = data;    // test for it being a png:    if(png_sig_cmp((png_byte*)header, 0, 8)) { -    abort_("[read_png_file] File is not recognized as a PNG file"); +    ERR(image, "[read_png_file] File is not recognized as a PNG file"); +    setError(0); +    return;    }    // initialize stuff    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);    if(!png_ptr) { -    abort_("[read_png_file] png_create_read_struct failed"); +    ERR(image, "[read_png_file] png_create_read_struct failed"); +    setError(1); +    return;    }    info_ptr = png_create_info_struct(png_ptr);    if(!info_ptr) { -    abort_("[read_png_file] png_create_info_struct failed"); +    ERR(image, "[read_png_file] png_create_info_struct failed"); +    setError(2); +    return;    }    if(setjmp(png_jmpbuf(png_ptr))) { -    abort_("[read_png_file] Error during init_io"); +    ERR(image, "[read_png_file] Error during init_io"); +    setError(3); +    return;    }    //png_init_io(png_ptr, fp); @@ -122,9 +143,11 @@ void GUI::Image::load(const char* data, size_t size)    png_read_update_info(png_ptr, info_ptr); -  /* read file */ +  // read file    if (setjmp(png_jmpbuf(png_ptr))) { -    abort_("[read_png_file] Error during read_image"); +    ERR(image, "[read_png_file] Error during read_image"); +    setError(4); +    return;    }    row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * h); diff --git a/plugingui/image.h b/plugingui/image.h index 1df248f..0181ce8 100644 --- a/plugingui/image.h +++ b/plugingui/image.h @@ -47,6 +47,8 @@ public:    Colour getPixel(size_t x, size_t y);  private: +  void setError(int err); +    void load(const char* data, size_t size);    size_t w, h; diff --git a/plugingui/resource_data.cc b/plugingui/resource_data.cc index badddec..ce29fd8 100644 --- a/plugingui/resource_data.cc +++ b/plugingui/resource_data.cc @@ -3415,5 +3415,169 @@ const rc_data_t rc_data[] =     "\47\111\335\27\346\155\0\60\41\4\122\112\345\103\13\140"     "\226\243\41\306\130\242\5\270\1\2\112\32\211\154\353\20"     "\253\0\0\0\0\111\105\116\104\256\102\140\202" }, +  { ":png_error", 2608, +   "\101\0\0\0\12\0\0\0\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\0\0\0\377\0\0\0\377" +   "\377\377\377\377\0\0\0\377\0\0\0\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\0\0\0\377\0\0\0\377" +   "\0\0\0\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\0\0\0\377\0\0\0\377" +   "\0\0\0\377\0\0\0\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\0\0\0\377" +   "\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\0\0\0\377\0\0\0\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377" +   "\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" },    { "", 0, 0 }  }; diff --git a/plugingui/resources/createrc.sh b/plugingui/resources/createrc.sh index 44afead..838713a 100755 --- a/plugingui/resources/createrc.sh +++ b/plugingui/resources/createrc.sh @@ -1,2 +1,2 @@  #!/bin/bash -../rcgen *.png > ../resource_data.cc
\ No newline at end of file +../rcgen *.png png_error > ../resource_data.cc diff --git a/plugingui/resources/png_error b/plugingui/resources/png_errorBinary files differ new file mode 100644 index 0000000..cadb45e --- /dev/null +++ b/plugingui/resources/png_error | 
