Ignore:
Timestamp:
Jan 4, 2005, 11:30:52 AM (18 years ago)
Author:
Sam Hocevar
Message:
  • src/image.c: SDL_image support.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pwntcha/trunk/src/image.c

    r389 r407  
    1616#include "common.h"
    1717
    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)
    1923#   include <cv.h>
    2024#   include <highgui.h>
    21 #elif defined(HAVE_IMLIB2_H)
    22 #   include <Imlib2.h>
    2325#else
    2426#   error "No imaging library"
     
    2830{
    2931    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)
    3137    IplImage *priv = cvLoadImage(name, -1);
    32 #elif defined(HAVE_IMLIB2_H)
    33     Imlib_Image priv = imlib_load_image(name);
    3438#endif
    3539
     
    3842
    3943    img = malloc(sizeof(struct image));
    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;
     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;
    4650#elif defined(HAVE_IMLIB2_H)
    4751    imlib_context_set_image(priv);
     
    5155    img->channels = 4;
    5256    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)
    7358    img->width = priv->width;
    7459    img->height = priv->height;
     
    7661    img->channels = priv->nChannels;
    7762    img->pixels = priv->imageData;
     63#endif
     64    img->priv = (void *)priv;
     65
     66    return img;
     67}
     68
     69struct 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;
    78104#elif defined(HAVE_IMLIB2_H)
    79105    imlib_context_set_image(priv);
     
    83109    img->channels = 4;
    84110    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;
    85117#endif
    86118    img->priv = (void *)priv;
     
    91123void image_free(struct image *img)
    92124{
    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)
    94131    IplImage *iplimg;
    95132    iplimg = (IplImage *)img->priv;
    96133    cvReleaseImage(&iplimg);
    97 #elif defined(HAVE_IMLIB2_H)
    98     imlib_context_set_image(img->priv);
    99     imlib_free_image();
    100134#endif
    101135
     
    147181void image_display(struct image *img)
    148182{
    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)
    150193    char name[BUFSIZ];
    151194    sprintf(name, "Image %p (%i x %i)", img, img->width, img->height);
     
    155198    while((unsigned char)cvWaitKey(0) != 0x1b)
    156199        ;
    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.