34 bool ImageConverter::initializeSFImage( )
38 image->numComponents = 0;
39 image->pixels.clear();
60 SFImage* ImageConverter::convert(
string url )
63 string ext = url.substr( url.rfind(
'.' ) );
66 transform( ext.begin(), ext.end(), ext.begin(), (
int(*)(
int))tolower );
69 if( !ext.compare(
".png" ) )
74 else if( !ext.compare(
".jpg" ) )
86 image->numComponents = 0;
87 image->pixels.resize(0);
105 ImageConverter::loadPNG(
109 initializeSFImage( );
116 fp = fopen( filePath.c_str(),
"rb" );
117 if( !fp )
throw "File open error.";
125 fread( header, 1, number, fp );
127 if( !is_png )
throw "File is not png.";
134 if( !pPng )
throw "Failed to create png_struct";
144 throw "Failed to create png_info";
169 #if PNG_LIBPNG_VER_MINOR >= 4 210 image->pixels.resize(rowbytes*height);
212 row_pointers[
i] = &(
image->pixels[
i*rowbytes]);
218 image->numComponents = numComponents;
229 cout <<
"PNG read error: " << str <<
'\n';
230 if( fp ) fclose( fp );
251 ImageConverter::loadJPEG(
254 initializeSFImage( );
261 fp = fopen( filePath.c_str(),
"rb" );
262 if( !fp )
throw "File open error.";
284 (
void)jpeg_start_decompress( &cinfo );
295 for (
int i = 0;
i <
image->height;
i++ )
320 cout <<
"JPEG read error: " << str <<
'\n';
321 if( fp ) fclose( fp );
png_uint_32 PNGAPI png_get_image_width(png_structp png_ptr, png_infop info_ptr)
void PNGAPI png_set_packing(png_structp png_ptr)
jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)
void PNGAPI png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
png_infop PNGAPI png_create_info_struct(png_structp png_ptr)
void PNGAPI png_set_palette_to_rgb(png_structp png_ptr)
png_uint_32 PNGAPI png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
#define PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_GRAY_ALPHA
#define PNG_COLOR_TYPE_PALETTE
#define PNG_LIBPNG_VER_STRING
void PNGAPI png_set_sig_bytes(png_structp png_ptr, int num_bytes)
#define PNG_COLOR_TYPE_RGB_ALPHA
void PNGAPI png_set_strip_16(png_structp png_ptr)
#define jpeg_create_decompress(cinfo)
png_infop png_uint_32 * width
void PNGAPI png_set_gray_1_2_4_to_8(png_structp png_ptr)
png_byte FAR *FAR * png_bytepp
png_infop png_bytepp row_pointers
png_struct FAR * png_structp
png_infop png_uint_32 png_uint_32 * height
#define PNG_COLOR_TYPE_GRAY
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
jpeg_stdio_src(j_decompress_ptr cinfo, FILE *infile)
Header file of Image Converter class.
int PNGAPI png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
jpeg_finish_decompress(j_decompress_ptr cinfo)
void PNGAPI png_read_info(png_structp png_ptr, png_infop info_ptr)
jpeg_destroy_decompress(j_decompress_ptr cinfo)
png_byte PNGAPI png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
JDIMENSION output_scanline
png_structp PNGAPI png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn)
png_infop png_uint_32 png_uint_32 int int * color_type
void PNGAPI png_set_tRNS_to_alpha(png_structp png_ptr)
void PNGAPI png_read_image(png_structp png_ptr, png_bytepp image)
jpeg_std_error(struct jpeg_error_mgr *err)
png_uint_32 PNGAPI png_get_image_height(png_structp png_ptr, png_infop info_ptr)
unsigned long png_uint_32
png_uint_32 PNGAPI png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
void PNGAPI png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)
png_byte PNGAPI png_get_color_type(png_structp png_ptr, png_infop info_ptr)
void PNGAPI png_read_update_info(png_structp png_ptr, png_infop info_ptr)
void PNGAPI png_init_io(png_structp png_ptr, png_FILE_p fp)