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, char* prog_path)
00029 {
00030 Image *image ;
00031 ExceptionInfo
00032 exception;
00033
00034 ImageInfo
00035 *image_info;
00036
00037
00038
00039
00040 InitializeMagick(prog_path);
00041
00042 GetExceptionInfo(&exception);
00043 image_info=CloneImageInfo((ImageInfo *) NULL);
00044 sprintf(image_info->filename,"%s", filename);
00045 image=ReadImage(image_info,&exception);
00046
00047 if (image == (Image *) NULL)
00048 return NULL ;
00049
00050 w = image->columns ;
00051 h = image->rows ;
00052
00053
00054 DestroyImageInfo(image_info);
00055 DestroyExceptionInfo(&exception);
00056
00057 return (void*)image ;
00058 }
00059
00060 void im_get_data(void *img, int *rgb)
00061 {
00062 unsigned int cnt ;
00063 PixelPacket *pp ;
00064 int *optr ;
00065 PixelPacket *iptr ;
00066 unsigned int sz ;
00067 Image *image ;
00068
00069 image = (Image*)img ;
00070
00071 pp = GetImagePixels( image, 0, 0, image->columns, image->rows) ;
00072
00073 sz = image->columns*image->rows ;
00074
00075 for(cnt=0,iptr=pp, optr=rgb ; cnt<sz ; cnt++, iptr++){
00076 *(optr++) = iptr->red >> 8 ;
00077 *(optr++) = iptr->green >> 8 ;
00078 *(optr++) = iptr->blue >> 8 ;
00079 }
00080 }
00081
00082 void im_get_data_grey(void *img, int *d)
00083 {
00084 unsigned int cnt ;
00085 PixelPacket *pp ;
00086 int *optr ;
00087 PixelPacket *iptr ;
00088 unsigned int sz ;
00089 Image *image ;
00090
00091 image = (Image*)img ;
00092
00093 pp = GetImagePixels( image, 0, 0, image->columns, image->rows) ;
00094
00095 sz = image->columns*image->rows ;
00096
00097 for(cnt=0,iptr=pp, optr=d ; cnt<sz ; cnt++, iptr++, optr++){
00098 *optr = iptr->red >> 8 ;
00099 *optr += iptr->green >> 8 ;
00100 *optr += iptr->blue >> 8 ;
00101 *optr /= 3 ;
00102 }
00103 }
00104
00105 void im_free(void *img)
00106 {
00107 Image *image ;
00108
00109 image = (Image*)img ;
00110
00111 DestroyImage(image);
00112
00113 }