00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <time.h>
00025 #include <sys/types.h>
00026 #include <magick/api.h>
00027
00028 void * im_load(char *filename, unsigned int &w, unsigned int &h,
00029 char* prog_path)
00030 {
00031 Image *image ;
00032 ExceptionInfo
00033 exception;
00034
00035 ImageInfo
00036 *image_info;
00037
00038
00039
00040
00041 InitializeMagick(prog_path);
00042
00043 GetExceptionInfo(&exception);
00044 image_info=CloneImageInfo((ImageInfo *) NULL);
00045 sprintf(image_info->filename,"%s", filename);
00046 image=ReadImage(image_info,&exception);
00047
00048 if (image == (Image *) NULL)
00049 return NULL ;
00050
00051 w = image->columns ;
00052 h = image->rows ;
00053
00054
00055 DestroyImageInfo(image_info);
00056 DestroyExceptionInfo(&exception);
00057
00058 return (void*)image ;
00059 }
00060
00061 void im_get_data(void *img, int *rgb)
00062 {
00063 unsigned int cnt ;
00064 PixelPacket *pp ;
00065 int *optr ;
00066 PixelPacket *iptr ;
00067 unsigned int sz ;
00068 Image *image ;
00069
00070 image = (Image*)img ;
00071
00072 pp = GetImagePixels( image, 0, 0, image->columns, image->rows) ;
00073
00074 sz = image->columns*image->rows ;
00075
00076 for(cnt=0,iptr=pp, optr=rgb ; cnt<sz ; cnt++, iptr++){
00077 *(optr++) = iptr->red >> 8 ;
00078 *(optr++) = iptr->green >> 8 ;
00079 *(optr++) = iptr->blue >> 8 ;
00080 }
00081 }
00082
00083 void im_get_data_grey(void *img, int *d)
00084 {
00085 unsigned int cnt ;
00086 PixelPacket *pp ;
00087 int *optr ;
00088 PixelPacket *iptr ;
00089 unsigned int sz ;
00090 Image *image ;
00091
00092 image = (Image*)img ;
00093
00094 pp = GetImagePixels( image, 0, 0, image->columns, image->rows) ;
00095
00096 sz = image->columns*image->rows ;
00097
00098 for(cnt=0,iptr=pp, optr=d ; cnt<sz ; cnt++, iptr++, optr++){
00099 *optr = iptr->red >> 8 ;
00100 *optr += iptr->green >> 8 ;
00101 *optr += iptr->blue >> 8 ;
00102 *optr /= 3 ;
00103 }
00104 }
00105
00106 void im_free(void *img)
00107 {
00108 Image *image ;
00109
00110 image = (Image*)img ;
00111
00112 DestroyImage(image);
00113
00114 }