Changeset 407 for pwntcha/trunk/src/image.c
- Timestamp:
- Jan 4, 2005, 11:30:52 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/src/image.c
r389 r407 16 16 #include "common.h" 17 17 18 #if defined(HAVE_CV_H) 18 #if defined(HAVE_SDL_IMAGE_H) 19 # include <SDL_image.h> 20 #elif defined(HAVE_IMLIB2_H) 21 # include <Imlib2.h> 22 #elif defined(HAVE_CV_H) 19 23 # include <cv.h> 20 24 # include <highgui.h> 21 #elif defined(HAVE_IMLIB2_H)22 # include <Imlib2.h>23 25 #else 24 26 # error "No imaging library" … … 28 30 { 29 31 struct image *img; 30 #if defined(HAVE_CV_H) 32 #if defined(HAVE_SDL_IMAGE_H) 33 SDL_Surface *priv = IMG_Load(name); 34 #elif defined(HAVE_IMLIB2_H) 35 Imlib_Image priv = imlib_load_image(name); 36 #elif defined(HAVE_CV_H) 31 37 IplImage *priv = cvLoadImage(name, -1); 32 #elif defined(HAVE_IMLIB2_H)33 Imlib_Image priv = imlib_load_image(name);34 38 #endif 35 39 … … 38 42 39 43 img = malloc(sizeof(struct image)); 40 #if defined(HAVE_ CV_H)41 img->width = priv->w idth;42 img->height = priv->h eight;43 img->pitch = priv-> widthStep;44 img->channels = priv-> nChannels;45 img->pixels = priv-> imageData;44 #if defined(HAVE_SDL_IMAGE_H) 45 img->width = priv->w; 46 img->height = priv->h; 47 img->pitch = priv->pitch; 48 img->channels = priv->format->BytesPerPixel; 49 img->pixels = priv->pixels; 46 50 #elif defined(HAVE_IMLIB2_H) 47 51 imlib_context_set_image(priv); … … 51 55 img->channels = 4; 52 56 img->pixels = (char *)imlib_image_get_data(); 53 #endif 54 img->priv = (void *)priv; 55 56 return img; 57 } 58 59 struct image *image_new(int width, int height) 60 { 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) 65 Imlib_Image priv = imlib_create_image(width, height); 66 #endif 67 68 if(!priv) 69 return NULL; 70 71 img = malloc(sizeof(struct image)); 72 #if defined(HAVE_CV_H) 57 #elif defined(HAVE_CV_H) 73 58 img->width = priv->width; 74 59 img->height = priv->height; … … 76 61 img->channels = priv->nChannels; 77 62 img->pixels = priv->imageData; 63 #endif 64 img->priv = (void *)priv; 65 66 return img; 67 } 68 69 struct image *image_new(int width, int height) 70 { 71 struct image *img; 72 #if defined(HAVE_SDL_IMAGE_H) 73 SDL_Surface *priv; 74 Uint32 rmask, gmask, bmask, amask; 75 # if SDL_BYTEORDER == SDL_BIG_ENDIAN 76 rmask = 0xff000000; 77 gmask = 0x00ff0000; 78 bmask = 0x0000ff00; 79 amask = 0x000000ff; 80 # else 81 rmask = 0x000000ff; 82 gmask = 0x0000ff00; 83 bmask = 0x00ff0000; 84 amask = 0xff000000; 85 # endif 86 priv = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 87 rmask, gmask, bmask, amask); 88 #elif defined(HAVE_IMLIB2_H) 89 Imlib_Image priv = imlib_create_image(width, height); 90 #elif defined(HAVE_CV_H) 91 IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); 92 #endif 93 94 if(!priv) 95 return NULL; 96 97 img = malloc(sizeof(struct image)); 98 #if defined(HAVE_SDL_IMAGE_H) 99 img->width = priv->w; 100 img->height = priv->h; 101 img->pitch = priv->pitch; 102 img->channels = priv->format->BytesPerPixel; 103 img->pixels = priv->pixels; 78 104 #elif defined(HAVE_IMLIB2_H) 79 105 imlib_context_set_image(priv); … … 83 109 img->channels = 4; 84 110 img->pixels = (char *)imlib_image_get_data(); 111 #elif defined(HAVE_CV_H) 112 img->width = priv->width; 113 img->height = priv->height; 114 img->pitch = priv->widthStep; 115 img->channels = priv->nChannels; 116 img->pixels = priv->imageData; 85 117 #endif 86 118 img->priv = (void *)priv; … … 91 123 void image_free(struct image *img) 92 124 { 93 #if defined(HAVE_CV_H) 125 #if defined(HAVE_SDL_IMAGE_H) 126 SDL_FreeSurface(img->priv); 127 #elif defined(HAVE_IMLIB2_H) 128 imlib_context_set_image(img->priv); 129 imlib_free_image(); 130 #elif defined(HAVE_CV_H) 94 131 IplImage *iplimg; 95 132 iplimg = (IplImage *)img->priv; 96 133 cvReleaseImage(&iplimg); 97 #elif defined(HAVE_IMLIB2_H)98 imlib_context_set_image(img->priv);99 imlib_free_image();100 134 #endif 101 135 … … 147 181 void image_display(struct image *img) 148 182 { 149 #if defined(HAVE_CV_H) 183 #if defined(HAVE_SDL_IMAGE_H) 184 //Nothing to do here 185 #elif defined(HAVE_IMLIB2_H) 186 //char name[BUFSIZ]; 187 //static int i = 0; 188 //sprintf(name, "image%i-%ix%i.png", i++, img->width, img->height); 189 //imlib_context_set_image(img->priv); 190 //imlib_save_image(name); 191 //fprintf(stderr, "saved to %s\n", name); 192 #elif defined(HAVE_CV_H) 150 193 char name[BUFSIZ]; 151 194 sprintf(name, "Image %p (%i x %i)", img, img->width, img->height); … … 155 198 while((unsigned char)cvWaitKey(0) != 0x1b) 156 199 ; 157 #elif defined(HAVE_IMLIB2_H) 158 //char name[BUFSIZ]; 159 //static int i = 0; 160 //sprintf(name, "image%i-%ix%i.png", i++, img->width, img->height); 161 //imlib_context_set_image(img->priv); 162 //imlib_save_image(name); 163 //fprintf(stderr, "saved to %s\n", name); 164 #endif 165 } 166 200 #endif 201 } 202
Note: See TracChangeset
for help on using the changeset viewer.