Ignore:
Timestamp:
Jan 3, 2005, 10:48:54 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • use OpenCV rather than Imlib2 if both are available.
  • cleaned up the slashdot code.
  • decode phpBB captchas.
  • added filter_contrast.
File:
1 edited

Legend:

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

    r387 r389  
    1616#include "common.h"
    1717
    18 #if defined(HAVE_IMLIB2_H)
    19 #   include <Imlib2.h>
    20 #elif defined(HAVE_CV_H)
     18#if defined(HAVE_CV_H)
    2119#   include <cv.h>
    2220#   include <highgui.h>
     21#elif defined(HAVE_IMLIB2_H)
     22#   include <Imlib2.h>
    2323#else
    2424#   error "No imaging library"
    2525#endif
    2626
    27 struct image * image_load(char *name)
     27struct image *image_load(char *name)
    2828{
    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)
    3133    Imlib_Image priv = imlib_load_image(name);
    32 #elif defined(HAVE_CV_H)
    33     IplImage * priv = cvLoadImage(name, -1);
    3434#endif
    3535
     
    3838
    3939    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)
    4147    imlib_context_set_image(priv);
    4248    img->width = imlib_image_get_width();
     
    4551    img->channels = 4;
    4652    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;
    5353#endif
    5454    img->priv = (void *)priv;
     
    5757}
    5858
    59 struct image * image_new(int width, int height)
     59struct image *image_new(int width, int height)
    6060{
    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)
    6365    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);
    6666#endif
    6767
     
    7070
    7171    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)
    7379    imlib_context_set_image(priv);
    7480    img->width = imlib_image_get_width();
     
    7783    img->channels = 4;
    7884    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;
    8585#endif
    8686    img->priv = (void *)priv;
    8787
    8888    return img;
     89}
     90
     91void 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);
    89103}
    90104
     
    133147void image_display(struct image *img)
    134148{
    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)
    136158    //char name[BUFSIZ];
    137159    //static int i = 0;
     
    140162    //imlib_save_image(name);
    141163    //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);
    148164#endif
    149165}
Note: See TracChangeset for help on using the changeset viewer.