void GuiImageData::LoadTIFF(const u8 *img, int imgSize) { gdImagePtr gdImg = gdImageCreateFromTiffPtr(imgSize, (u8*) img); if(gdImg == 0) return; data = GDImageToRGBA8(&gdImg, &width, &height); gdImageDestroy(gdImg); }
int main(int argc, char **argv) { gdImagePtr ptr; char* buffer; int size; int res; if (argc<2) { printf("Usage: %s <input_file>\n", argv[0]); return 0; } size = read_file(argv[1], &buffer); if (size <= 0) { return 0; } char ext[6]; res = read_extenstion(buffer, size, ext); if (res < 0) { //printf("ext: %s\n", ext); //printf("extention not correct\n"); exit(0); } switch (res) { case 1: //open png printf("openning png\n"); ptr = gdImageCreateFromPngPtr(size-5, (void *)buffer); break; case 2: //open gif printf("openning gif\n"); ptr = gdImageCreateFromGifPtr(size-5, (void *)buffer); break; case 3: //open jpg printf("openning jpg\n"); ptr = gdImageCreateFromJpegPtr(size-5, (void *)buffer); break; case 4: //open tga printf("openning tga\n"); ptr = gdImageCreateFromTgaPtr(size-5, (void *)buffer); break; case 5: //open tiff printf("openning tiff\n"); ptr = gdImageCreateFromTiffPtr(size-5, (void *)buffer); break; // case 6: // //open webp // printf("openning webp\n"); // exit(0); // //gdImageWebpPtr() // break; default: printf("error!\n"); exit(0); } printf("ptr: %p\n", ptr); //gdImagePtr ptr2; int new_size; FILE *output; output = fopen("/dev/null", "wb"); gdImageWebp(ptr, output); return 0; // char * filename = argv[1]; // printf("opening: %s\n", filename); // FILE *in; // in = fopen(filename, "r"); // if (in!=NULL) // { // im = gdImageCreateFromPng(in); // printf("imageptr: %p\n", im); // } //printf("Main\n"); return 0; }
int main() { gdImagePtr src, dst; int r, res_x, res_y; void *p; int size = 0; int status = 0; src = gdImageCreate(100, 100); if (src == NULL) { printf("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); gdImageFilledRectangle(src, 0, 0, 99, 99, r); // gd default DPI is 96; libtiff default is 72. // Use something else so we know the value has been // written / read correctly. res_x = 100; res_y = 200; src->res_x = res_x; src->res_y = res_y; #define OUTPUT_TIFF(name) do { \ FILE *fp; \ \ fp = fopen("tiff_dpi_" #name ".tiff", "wb"); \ if (fp) { \ gdImageTiff(name, fp); \ fclose(fp); \ } \ } while (0) OUTPUT_TIFF(src); p = gdImageTiffPtr(src, &size); if (p == NULL) { status = 1; printf("p is null\n"); goto door0; } if (size <= 0) { status = 1; printf("size is non-positive\n"); goto door1; } dst = gdImageCreateFromTiffPtr(size, p); if (dst == NULL) { status = 1; printf("could not create dst\n"); goto door1; } if (dst->res_x != res_x) { status = 1; printf("mismatch in res_x (got %d, expected %d)", dst->res_x, res_x); } if (dst->res_y != res_y) { status = 1; printf("mismatch in res_y (got %d, expected %d)", dst->res_y, res_y); } gdImageDestroy(dst); door1: gdFree(p); door0: gdImageDestroy(src); return status; }
result_t Image::load(Buffer_base *data) { std::string strBuf; data->toString(strBuf); if (strBuf.length() < 2) return CHECK_ERROR(CALL_E_INVALIDARG); int32_t format; unsigned char ch1 = (unsigned char) strBuf[0]; unsigned char ch2 = (unsigned char) strBuf[1]; if (ch1 == 0x47 && ch2 == 0x49) format = gd_base::_GIF; else if (ch1 == 0x89 && ch2 == 0x50) format = gd_base::_PNG; else if (ch1 == 0xff && ch2 == 0xd8) format = gd_base::_JPEG; else if ((ch1 == 0x49 && ch2 == 0x49) || (ch1 == 0x4d && ch2 == 0x4d)) format = gd_base::_TIFF; else if (ch1 == 0x42 && ch2 == 0x4d) format = gd_base::_BMP; else if (ch1 == 0x52 && ch2 == 0x49) format = gd_base::_WEBP; else return CHECK_ERROR(CALL_E_INVALID_DATA); switch (format) { case gd_base::_GIF: m_image = gdImageCreateFromGifPtr((int32_t) strBuf.length(), (void *) strBuf.c_str()); break; case gd_base::_PNG: m_image = gdImageCreateFromPngPtr((int32_t) strBuf.length(), (void *) strBuf.c_str()); break; case gd_base::_JPEG: m_image = gdImageCreateFromJpegPtr((int32_t) strBuf.length(), (void *) strBuf.c_str()); if (m_image != NULL) { EXIFInfo result; result.parseFrom((const unsigned char *) strBuf.c_str(), (uint32_t)strBuf.length()); switch (result.Orientation) { case 2: gdImageFlipHorizontal(m_image); break; case 3: gdImageFlipBoth(m_image); break; case 4: gdImageFlipVertical(m_image); break; case 5: gdImageFlipVertical(m_image); case 6: rotate(gd_base::_RIGHT); break; case 7: gdImageFlipVertical(m_image); case 8: rotate(gd_base::_LEFT); break; } } break; case gd_base::_TIFF: m_image = gdImageCreateFromTiffPtr((int32_t) strBuf.length(), (void *) strBuf.c_str()); break; case gd_base::_BMP: m_image = gdImageCreateFromBmpPtr((int32_t) strBuf.length(), (void *) strBuf.c_str()); break; case gd_base::_WEBP: m_image = gdImageCreateFromWebpPtr((int32_t) strBuf.length(), (void *) strBuf.c_str()); break; } if (m_image == NULL) return CHECK_ERROR(CALL_E_INVALIDARG); setExtMemory(); m_type = format; return 0; }
gdImagePtr ImageRead( struct ImageLibrary *im, File *rootDev, const char *path ) { gdImagePtr img = NULL; FHandler *fh = rootDev->f_FSys; File *rfp = (File *)fh->FileOpen( rootDev, path, "rb" ); if( rfp != NULL ) { BufString *bs = BufStringNew( ); char buffer[ 20048 ]; int len = 0; while( ( len = fh->FileRead( rfp, buffer, 20048 ) ) > 0 ) { BufStringAddSize( bs, buffer, len ); } img = gdImageCreateFromJpegPtr( bs->bs_Size, (void *)bs->bs_Buffer ) ; if( img == NULL ) { if( img == NULL ) { img = gdImageCreateFromBmpPtr( bs->bs_Size, (void *)bs->bs_Buffer ) ; if( img == NULL ) { img = gdImageCreateFromGifPtr( bs->bs_Size, (void *)bs->bs_Buffer ) ; if( img == NULL ) { img = gdImageCreateFromPngPtr( bs->bs_Size, (void *)bs->bs_Buffer ) ; if( img == NULL ) { img = gdImageCreateFromTgaPtr( bs->bs_Size, (void *)bs->bs_Buffer ) ; if( img == NULL ) { img = gdImageCreateFromTiffPtr( bs->bs_Size, (void *)bs->bs_Buffer ) ; if( img == NULL ) { img = gdImageCreateFromWBMPPtr( bs->bs_Size, (void *)bs->bs_Buffer ) ; if( img == NULL ) { img = gdImageCreateFromWebpPtr( bs->bs_Size, (void *)bs->bs_Buffer ) ; } } } } } } } } if( img == NULL ) { ERROR("Graphics format not recognized\n"); } BufStringDelete( bs ); fh->FileClose( rootDev, rfp ); } else { ERROR("Cannot open file: %s to read\n", path ); } return img; }