Changeset 407 for pwntcha


Ignore:
Timestamp:
Jan 4, 2005, 11:30:52 AM (16 years ago)
Author:
Sam Hocevar
Message:
  • src/image.c: SDL_image support.
Location:
pwntcha/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pwntcha/trunk/configure.ac

    r406 r407  
    2020
    2121AC_CHECK_FUNCS(getopt_long)
     22
     23# Use SDL?
     24ac_cv_my_have_sdl="no"
     25save_CPPFLAGS="${CPPFLAGS}"
     26AC_PATH_PROG(SDL_CONFIG, sdl-config, no)
     27if test "${SDL_CONFIG}" != "no"; then
     28  CPPFLAGS="${CPPFLAGS} `sdl-config --cflags`"
     29fi
     30AC_CHECK_HEADERS(SDL_image.h,
     31 [ac_cv_my_have_sdl="yes"],
     32 [ac_cv_my_have_sdl="no"])
     33CPPFLAGS="${save_CPPFLAGS}"
     34AM_CONDITIONAL(USE_SDL, test "${ac_cv_my_have_sdl}" = "yes")
    2235
    2336# Use OpenCV?
     
    4760AM_CONDITIONAL(USE_IMLIB2, test "${ac_cv_my_have_imlib2}" = "yes")
    4861
    49 if test "${ac_cv_my_have_imlib2}" = "no" -a "${ac_cv_my_have_opencv}" = "no"; then
    50   AC_MSG_ERROR([[cannot find Imlib2 or OpenCV, please install one of them]])
     62if test "${ac_cv_my_have_sdl}" = "yes" -a "${ac_cv_my_have_imlib2}" = "no" -a "${ac_cv_my_have_opencv}" = "no"; then
     63  AC_MSG_ERROR([[cannot find SDL_Image, Imlib2 or OpenCV, please install one of them]])
    5164fi
    5265
  • pwntcha/trunk/src/Makefile.am

    r400 r407  
    1414    test.c
    1515
    16 if USE_OPENCV
    17 ADDITIONAL_CFLAGS = `opencv-config --cflags`
    18 ADDITIONAL_LDFLAGS = `opencv-config --libs opencv highgui`
     16if USE_SDL
     17ADDITIONAL_CFLAGS = `sdl-config --cflags`
     18ADDITIONAL_LDFLAGS = `sdl-config --libs` -lSDL_image
    1919else
    2020if USE_IMLIB2
     
    2222ADDITIONAL_LDFLAGS = `imlib2-config --libs`
    2323else
     24if USE_OPENCV
     25ADDITIONAL_CFLAGS = `opencv-config --cflags`
     26ADDITIONAL_LDFLAGS = `opencv-config --libs opencv highgui`
     27else
    2428ADDITIONAL_CFLAGS =
    2529ADDITIONAL_LDFLAGS =
    2630endif
    2731endif
     32endif
    2833
  • 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.