Changeset 2629
- Timestamp:
- Aug 2, 2008, 2:00:51 AM (14 years ago)
- Location:
- libpipi/trunk/pipi
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libpipi/trunk/pipi/codec.c
r2607 r2629 39 39 } 40 40 41 pipi_image_t *pipi_new(int width, int height)42 {43 #if USE_SDL44 return pipi_new_sdl(width, height);45 #elif USE_IMLIB246 return pipi_new_imlib2(width, height);47 #elif USE_OPENCV48 return pipi_new_opencv(width, height);49 #endif50 }51 52 41 void pipi_free(pipi_image_t *img) 53 42 { 54 unsignedint i;43 int i; 55 44 56 45 for(i = 0; i < PIPI_PIXELS_MAX; i++) … … 59 48 60 49 #if USE_SDL 61 returnpipi_free_sdl(img);50 pipi_free_sdl(img); 62 51 #elif USE_IMLIB2 63 returnpipi_free_imlib2(img);52 pipi_free_imlib2(img); 64 53 #elif USE_OPENCV 65 returnpipi_free_opencv(img);54 pipi_free_opencv(img); 66 55 #endif 56 57 free(img); 67 58 } 68 59 -
libpipi/trunk/pipi/codec/imlib.c
r2605 r2629 37 37 return NULL; 38 38 39 img = (pipi_image_t *)malloc(sizeof(pipi_image_t));40 memset(img, 0, sizeof(pipi_image_t));41 42 39 imlib_context_set_image(priv); 43 img->w = imlib_image_get_width(); 44 img->h = imlib_image_get_height(); 40 img = pipi_new(imlib_image_get_width(), imlib_image_get_height()); 45 41 46 42 img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data(); 47 img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width(); 48 img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height(); 49 img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width(); 50 img->last_modified = PIPI_PIXELS_RGBA32; 51 52 img->codec_priv = (void *)priv; 53 img->codec_format = PIPI_PIXELS_RGBA32; 54 55 return img; 56 } 57 58 pipi_image_t *pipi_new_imlib2(int width, int height) 59 { 60 pipi_image_t *img; 61 Imlib_Image priv = imlib_create_image(width, height); 62 63 if(!priv) 64 return NULL; 65 66 img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); 67 memset(img, 0, sizeof(pipi_image_t)); 68 69 imlib_context_set_image(priv); 70 img->w = imlib_image_get_width(); 71 img->h = imlib_image_get_height(); 72 73 img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data(); 74 img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width(); 75 img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height(); 76 img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width(); 43 img->p[PIPI_PIXELS_RGBA32].w = img->w; 44 img->p[PIPI_PIXELS_RGBA32].h = img->h; 45 img->p[PIPI_PIXELS_RGBA32].pitch = 4 * img->w; 77 46 img->last_modified = PIPI_PIXELS_RGBA32; 78 47 … … 87 56 imlib_context_set_image(img->codec_priv); 88 57 imlib_free_image(); 89 90 free(img);91 58 } 92 59 93 60 void pipi_save_imlib2(pipi_image_t *img, const char *name) 94 61 { 62 if(!img->codec_priv) 63 { 64 Imlib_Image priv = imlib_create_image(img->w, img->h); 65 void *data; 66 67 imlib_context_set_image(priv); 68 data = imlib_image_get_data(); 69 70 /* FIXME: check pitch differences here */ 71 if(img->last_modified == PIPI_PIXELS_RGBA32) 72 { 73 memcpy(data, img->p[PIPI_PIXELS_RGBA32].pixels, 74 4 * img->w * img->h); 75 free(img->p[PIPI_PIXELS_RGBA32].pixels); 76 } 77 78 img->p[PIPI_PIXELS_RGBA32].pixels = data; 79 img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width(); 80 img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height(); 81 img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width(); 82 83 img->codec_priv = (void *)priv; 84 img->codec_format = PIPI_PIXELS_RGBA32; 85 } 86 95 87 pipi_getpixels(img, img->codec_format); 96 88 imlib_context_set_image(img->codec_priv); -
libpipi/trunk/pipi/codec/opencv.c
r2605 r2629 30 30 #include "pipi_internals.h" 31 31 32 /* FIXME: this whole file is broken until we support BGR24 images */ 33 32 34 pipi_image_t *pipi_load_opencv(const char *name) 33 35 { … … 59 61 { 60 62 pipi_image_t *img; 61 IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);63 IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 4); 62 64 63 65 if(!priv) -
libpipi/trunk/pipi/codec/sdl.c
r2605 r2629 29 29 #include "pipi_internals.h" 30 30 31 static SDL_Surface *create_32bpp_surface(int w, int h); 32 31 33 pipi_image_t *pipi_load_sdl(const char *name) 32 34 { … … 39 41 if(priv->format->BytesPerPixel != 4) 40 42 { 41 img = pipi_new(priv->w, priv->h);42 SDL_BlitSurface(priv, NULL, img->codec_priv, NULL);43 SDL_Surface *tmp = create_32bpp_surface(priv->w, priv->h); 44 SDL_BlitSurface(priv, NULL, tmp, NULL); 43 45 SDL_FreeSurface(priv); 44 return img;46 priv = tmp; 45 47 } 46 48 47 img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); 48 memset(img, 0, sizeof(pipi_image_t)); 49 50 img->w = priv->w; 51 img->h = priv->h; 52 53 img->p[PIPI_PIXELS_RGBA32].pixels = priv->pixels; 54 img->p[PIPI_PIXELS_RGBA32].w = priv->w; 55 img->p[PIPI_PIXELS_RGBA32].h = priv->h; 56 img->p[PIPI_PIXELS_RGBA32].pitch = priv->pitch; 57 img->last_modified = PIPI_PIXELS_RGBA32; 58 59 img->codec_priv = (void *)priv; 60 img->codec_format = PIPI_PIXELS_RGBA32; 61 62 return img; 63 } 64 65 pipi_image_t *pipi_new_sdl(int width, int height) 66 { 67 pipi_image_t *img; 68 SDL_Surface *priv; 69 Uint32 rmask, gmask, bmask, amask; 70 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 71 rmask = 0xff000000; 72 gmask = 0x00ff0000; 73 bmask = 0x0000ff00; 74 amask = 0x00000000; 75 #else 76 rmask = 0x000000ff; 77 gmask = 0x0000ff00; 78 bmask = 0x00ff0000; 79 amask = 0x00000000; 80 #endif 81 priv = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 82 rmask, gmask, bmask, amask); 83 84 if(!priv) 85 return NULL; 86 87 img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); 88 memset(img, 0, sizeof(pipi_image_t)); 89 90 img->w = priv->w; 91 img->h = priv->h; 49 img = pipi_new(priv->w, priv->h); 92 50 93 51 img->p[PIPI_PIXELS_RGBA32].pixels = priv->pixels; … … 106 64 { 107 65 SDL_FreeSurface(img->codec_priv); 108 109 free(img);110 66 } 111 67 112 68 void pipi_save_sdl(pipi_image_t *img, const char *name) 113 69 { 70 if(!img->codec_priv) 71 { 72 SDL_Surface *priv = create_32bpp_surface(img->w, img->h); 73 74 /* FIXME: check pitch differences here */ 75 if(img->last_modified == PIPI_PIXELS_RGBA32) 76 { 77 memcpy(priv->pixels, img->p[PIPI_PIXELS_RGBA32].pixels, 78 priv->pitch * priv->h); 79 free(img->p[PIPI_PIXELS_RGBA32].pixels); 80 } 81 82 img->p[PIPI_PIXELS_RGBA32].pixels = priv->pixels; 83 img->p[PIPI_PIXELS_RGBA32].w = priv->w; 84 img->p[PIPI_PIXELS_RGBA32].h = priv->h; 85 img->p[PIPI_PIXELS_RGBA32].pitch = priv->pitch; 86 87 img->codec_priv = (void *)priv; 88 img->codec_format = PIPI_PIXELS_RGBA32; 89 } 90 114 91 pipi_getpixels(img, img->codec_format); 115 92 SDL_SaveBMP(img->codec_priv, name); 116 93 } 117 94 95 /* 96 * The following functions are local. 97 */ 98 99 static SDL_Surface *create_32bpp_surface(int w, int h) 100 { 101 Uint32 rmask, gmask, bmask, amask; 102 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 103 rmask = 0xff000000; 104 gmask = 0x00ff0000; 105 bmask = 0x0000ff00; 106 amask = 0x00000000; 107 #else 108 rmask = 0x000000ff; 109 gmask = 0x0000ff00; 110 bmask = 0x00ff0000; 111 amask = 0x00000000; 112 #endif 113 114 return SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 115 rmask, gmask, bmask, amask); 116 } 117 -
libpipi/trunk/pipi/pipi.c
r2605 r2629 39 39 */ 40 40 41 pipi_image_t *pipi_new(int w, int h) 42 { 43 pipi_image_t *img; 44 45 img = malloc(sizeof(pipi_image_t)); 46 memset(img, 0, sizeof(pipi_image_t)); 47 48 img->w = w; 49 img->h = h; 50 img->last_modified = PIPI_PIXELS_UNINITIALISED; 51 52 return img; 53 } 54 -
libpipi/trunk/pipi/pipi.h
r2617 r2629 30 30 typedef enum 31 31 { 32 PIPI_PIXELS_UNINITIALISED = -1, 33 32 34 PIPI_PIXELS_RGBA32 = 0, 33 35 PIPI_PIXELS_RGBA_F = 1,
Note: See TracChangeset
for help on using the changeset viewer.