--- devimage.c.org 2004-02-05 00:42:01.000000000 +0700 +++ devimage.c 2004-02-05 00:44:30.000000000 +0700 @@ -49,7 +49,7 @@ unsigned long offset; /* The current offset within the buffer */ unsigned long size; /* The total size of the buffer */ } buffer_t; - + static void ComputePitch(int bpp, int width, int *pitch, int *bytesperpixel); #if defined(HAVE_BMP_SUPPORT) @@ -396,6 +396,103 @@ free(pimage); return 0; /* image loading error*/ } +/** + * write by : Van Duc Uy (c) Sunyard-Vietnam .Co .LTD + * uyvd@sunyard.net.tw + * Load an image from a file and return PMWIMAGEHDR structure. + * + * @param psd Drawing surface. + * @param path The file containing the image data. + * @param flags If nonzero, JPEG images will be loaded as grayscale. Yuck! + */ +PMWIMAGEHDR +GdLoadImage(PSD psd, char *path, int flags) +{ + int loadOK = 0; + PMWIMAGEHDR pimage=NULL; + int fd; + struct stat s; + void *buffer = 0; + buffer_t src; + + fd = open(path, O_RDONLY); + if (fd < 0 || fstat(fd, &s) < 0) { + EPRINTF("GdLoadImage: can't open image: %s\n", path); + return(NULL); + } + + buffer = malloc(s.st_size); + if (!buffer) { + EPRINTF("GdLoadImage: Couldn't load image %s\n", path); + close(fd); + goto err; + } + + if (read(fd, buffer, s.st_size) != s.st_size) { + EPRINTF("GdLoadImage: Couldn't load image %s\n", path); + close(fd); + goto err; + } + + binit(&src, buffer, s.st_size); + close(fd); + + /* allocate image struct*/ + pimage = (PMWIMAGEHDR)malloc(sizeof(MWIMAGEHDR)); + if(!pimage) { + return NULL; + } + pimage->imagebits = NULL; + pimage->palette = NULL; + pimage->transcolor = -1L; + +#if defined(HAVE_TIFF_SUPPORT) + /* must be first... no buffer support yet*/ + if (path) + loadOK = LoadTIFF(path, pimage); +#endif +#if defined(HAVE_BMP_SUPPORT) + if (loadOK == 0) + loadOK = LoadBMP(&src, pimage); +#endif +#if defined(HAVE_GIF_SUPPORT) + if (loadOK == 0) + loadOK = LoadGIF(&src, pimage); +#endif +#if defined(HAVE_JPEG_SUPPORT) + if (loadOK == 0) + loadOK = LoadJPEG(&src, pimage, psd, flags); +#endif +#if defined(HAVE_PNG_SUPPORT) + if (loadOK == 0) + loadOK = LoadPNG(&src, pimage); +#endif +#if defined(HAVE_PNM_SUPPORT) + if(loadOK == 0) + loadOK = LoadPNM(&src, pimage); +#endif +#if defined(HAVE_XPM_SUPPORT) + if (loadOK == 0) + loadOK = LoadXPM(&src, pimage, psd); +#endif + + if (loadOK == 0) { + EPRINTF("GdLoadImageFromFile: unknown image type\n"); + goto err; /* image loading error*/ + } + if (loadOK != 1) + goto err; /* image loading error*/ + + free(buffer); + return pimage; + +err: + free(pimage); + free(buffer); + return NULL; /* image loading error*/ + +} + static PIMAGEITEM findimage(int id) @@ -475,6 +572,7 @@ free(image2.imagebits); } else GdDrawImage(psd, x, y, pimage); + } /** @@ -546,6 +644,28 @@ return TRUE; } +/** + * write by : Van Duc Uy (c) Sunyard-Vietnam .Co .LTD + * uyvd@sunyard.net.tw + * Get image data from list via image handle. + * + * @param id Image to query. + * @return Pointer to Image data. + */ + +PMWIMAGEHDR +GdGetImageData(int id) +{ + PIMAGEITEM pItem; + + pItem = findimage(id); + if (!pItem) { + return NULL; + } + + return pItem->pimage; + +} #define PIX2BYTES(n) (((n)+7)/8) /* * compute image line size and bytes per pixel