Changeset 389 for pwntcha/trunk/src/image.c
- Timestamp:
- Jan 3, 2005, 10:48:54 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/src/image.c
r387 r389 16 16 #include "common.h" 17 17 18 #if defined(HAVE_IMLIB2_H) 19 # include <Imlib2.h> 20 #elif defined(HAVE_CV_H) 18 #if defined(HAVE_CV_H) 21 19 # include <cv.h> 22 20 # include <highgui.h> 21 #elif defined(HAVE_IMLIB2_H) 22 # include <Imlib2.h> 23 23 #else 24 24 # error "No imaging library" 25 25 #endif 26 26 27 struct image * 27 struct image *image_load(char *name) 28 28 { 29 struct image * img; 30 #if defined(HAVE_IMLIB2_H) 29 struct image *img; 30 #if defined(HAVE_CV_H) 31 IplImage *priv = cvLoadImage(name, -1); 32 #elif defined(HAVE_IMLIB2_H) 31 33 Imlib_Image priv = imlib_load_image(name); 32 #elif defined(HAVE_CV_H)33 IplImage * priv = cvLoadImage(name, -1);34 34 #endif 35 35 … … 38 38 39 39 img = malloc(sizeof(struct image)); 40 #if defined(HAVE_IMLIB2_H) 40 #if defined(HAVE_CV_H) 41 img->width = priv->width; 42 img->height = priv->height; 43 img->pitch = priv->widthStep; 44 img->channels = priv->nChannels; 45 img->pixels = priv->imageData; 46 #elif defined(HAVE_IMLIB2_H) 41 47 imlib_context_set_image(priv); 42 48 img->width = imlib_image_get_width(); … … 45 51 img->channels = 4; 46 52 img->pixels = (char *)imlib_image_get_data(); 47 #elif defined(HAVE_CV_H)48 img->width = priv->width;49 img->height = priv->height;50 img->pitch = priv->widthStep;51 img->channels = priv->nChannels;52 img->pixels = priv->imageData;53 53 #endif 54 54 img->priv = (void *)priv; … … 57 57 } 58 58 59 struct image * 59 struct image *image_new(int width, int height) 60 60 { 61 struct image * img; 62 #if defined(HAVE_IMLIB2_H) 61 struct image *img; 62 #if defined(HAVE_CV_H) 63 IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); 64 #elif defined(HAVE_IMLIB2_H) 63 65 Imlib_Image priv = imlib_create_image(width, height); 64 #elif defined(HAVE_CV_H)65 IplImage * priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);66 66 #endif 67 67 … … 70 70 71 71 img = malloc(sizeof(struct image)); 72 #if defined(HAVE_IMLIB2_H) 72 #if defined(HAVE_CV_H) 73 img->width = priv->width; 74 img->height = priv->height; 75 img->pitch = priv->widthStep; 76 img->channels = priv->nChannels; 77 img->pixels = priv->imageData; 78 #elif defined(HAVE_IMLIB2_H) 73 79 imlib_context_set_image(priv); 74 80 img->width = imlib_image_get_width(); … … 77 83 img->channels = 4; 78 84 img->pixels = (char *)imlib_image_get_data(); 79 #elif defined(HAVE_CV_H)80 img->width = priv->width;81 img->height = priv->height;82 img->pitch = priv->widthStep;83 img->channels = priv->nChannels;84 img->pixels = priv->imageData;85 85 #endif 86 86 img->priv = (void *)priv; 87 87 88 88 return img; 89 } 90 91 void image_free(struct image *img) 92 { 93 #if defined(HAVE_CV_H) 94 IplImage *iplimg; 95 iplimg = (IplImage *)img->priv; 96 cvReleaseImage(&iplimg); 97 #elif defined(HAVE_IMLIB2_H) 98 imlib_context_set_image(img->priv); 99 imlib_free_image(); 100 #endif 101 102 free(img); 89 103 } 90 104 … … 133 147 void image_display(struct image *img) 134 148 { 135 #if defined(HAVE_IMLIB2_H) 149 #if defined(HAVE_CV_H) 150 char name[BUFSIZ]; 151 sprintf(name, "Image %p (%i x %i)", img, img->width, img->height); 152 cvNamedWindow(name, 0); 153 cvShowImage(name, img->priv); 154 cvResizeWindow(name, img->width * 2, img->height * 2 + 50); 155 while((unsigned char)cvWaitKey(0) != 0x1b) 156 ; 157 #elif defined(HAVE_IMLIB2_H) 136 158 //char name[BUFSIZ]; 137 159 //static int i = 0; … … 140 162 //imlib_save_image(name); 141 163 //fprintf(stderr, "saved to %s\n", name); 142 #elif defined(HAVE_CV_H)143 char name[BUFSIZ];144 sprintf(name, "Image %p (%i x %i)", img, img->width, img->height);145 cvNamedWindow(name, 0);146 cvShowImage(name, img->priv);147 cvResizeWindow(name, 320, 120);148 164 #endif 149 165 }
Note: See TracChangeset
for help on using the changeset viewer.