Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

im_magick.cpp

00001 /*************************************************************************
00006  *
00007  * Source code for Real Time Image Library (libRTImage)
00008  *
00009  * Leeds Vision Group give permission for this code to be copied, modified
00010  * and distributed within the University of Leeds subject to the following
00011  * conditions:-
00012  *
00013  * - The code is not to be used for commercial gain.
00014  * - The code and use thereof will be attributed to the authors where
00015  *   appropriate (including demonstrations which rely on it's use).
00016  * - All modified, distributions of the source files will retain this header.
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         Initialize the image info structure and read an image.
00040       */
00041       InitializeMagick(prog_path); // Should really pass argv[0] (only req'd under 
00042                               // windows)
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     // Tidy up
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 }

Generated at Fri Aug 13 17:29:20 2004 for libRTImage by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001