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

im_magick.cpp.old

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, char* prog_path)
00029 {
00030   Image *image ;
00031   ExceptionInfo
00032         exception;
00033 
00034       ImageInfo
00035         *image_info;
00036 
00037       /*
00038         Initialize the image info structure and read an image.
00039       */
00040       InitializeMagick(prog_path); // Should really pass argv[0] (only req'd under 
00041                               // windows)
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     // Tidy up
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 }

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