Changeset 2605


Ignore:
Timestamp:
Jul 29, 2008, 1:01:29 AM (12 years ago)
Author:
Sam Hocevar
Message:
  • Big API reorganisation. Now libpipi can transparently convert between colour spaces for a given image. For instance, if pipi_gaussian_blur is applied to a 32-bpp image, it is automatically converted to gamma-corrected 32-bit floats beforehands, then converted back to normal.
  • TODO: clipping, regions of interest, more formats, getpixel macros...
Location:
libpipi/trunk/pipi
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/codec.c

    r2261 r2605  
    5050}
    5151
    52 pipi_image_t *pipi_copy(pipi_image_t const *img)
    53 {
    54     pipi_image_t *dst;
    55     int x, y;
    56     dst = pipi_new(img->width, img->height);
    57     for(y = 0; y < img->height; y++)
    58     {
    59         for(x = 0; x < img->width; x++)
    60         {
    61             double r, g, b;
    62             pipi_getpixel(img, x, y, &r, &g, &b);
    63             pipi_setpixel(dst, x, y, r, g, b);
    64         }
    65     }
    66     return dst;
    67 }
    68 
    6952void pipi_free(pipi_image_t *img)
    7053{
  • libpipi/trunk/pipi/codec/imlib.c

    r2261 r2605  
    3838
    3939    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
     40    memset(img, 0, sizeof(pipi_image_t));
     41
    4042    imlib_context_set_image(priv);
    41     img->width = imlib_image_get_width();
    42     img->height = imlib_image_get_height();
    43     img->pitch = 4 * imlib_image_get_width();
    44     img->channels = 4;
    45     img->pixels = (char *)imlib_image_get_data();
    46     img->priv = (void *)priv;
     43    img->w = imlib_image_get_width();
     44    img->h = imlib_image_get_height();
     45
     46    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;
    4754
    4855    return img;
     
    5865
    5966    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
     67    memset(img, 0, sizeof(pipi_image_t));
     68
    6069    imlib_context_set_image(priv);
    61     img->width = imlib_image_get_width();
    62     img->height = imlib_image_get_height();
    63     img->pitch = 4 * imlib_image_get_width();
    64     img->channels = 4;
    65     img->pixels = (char *)imlib_image_get_data();
    66     img->priv = (void *)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();
     77    img->last_modified = PIPI_PIXELS_RGBA32;
     78
     79    img->codec_priv = (void *)priv;
     80    img->codec_format = PIPI_PIXELS_RGBA32;
    6781
    6882    return img;
     
    7185void pipi_free_imlib2(pipi_image_t *img)
    7286{
    73     imlib_context_set_image(img->priv);
     87    imlib_context_set_image(img->codec_priv);
    7488    imlib_free_image();
    7589
     
    7993void pipi_save_imlib2(pipi_image_t *img, const char *name)
    8094{
    81     imlib_context_set_image(img->priv);
     95    pipi_getpixels(img, img->codec_format);
     96    imlib_context_set_image(img->codec_priv);
    8297    imlib_save_image(name);
    8398}
  • libpipi/trunk/pipi/codec/opencv.c

    r2261 r2605  
    3939
    4040    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
    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     img->priv = (void *)priv;
     41    memset(img, 0, sizeof(pipi_image_t));
     42
     43    img->w = priv->width;
     44    img->h = priv->height;
     45
     46    img->p[PIPI_PIXELS_RGBA32].pixels = priv->imageData;
     47    img->p[PIPI_PIXELS_RGBA32].w = priv->width;
     48    img->p[PIPI_PIXELS_RGBA32].h = priv->height;
     49    img->p[PIPI_PIXELS_RGBA32].pitch = priv->widthStep;
     50    img->last_modified = PIPI_PIXELS_RGBA32;
     51
     52    img->codec_priv = (void *)priv;
     53    img->codec_format = PIPI_PIXELS_RGBA32;
    4754
    4855    return img;
     
    5865
    5966    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
    60     img->width = priv->width;
    61     img->height = priv->height;
    62     img->pitch = priv->widthStep;
    63     img->channels = priv->nChannels;
    64     img->pixels = priv->imageData;
    65     img->priv = (void *)priv;
     67    memset(img, 0, sizeof(pipi_image_t));
     68
     69    img->w = priv->width;
     70    img->h = priv->height;
     71
     72    img->p[PIPI_PIXELS_RGBA32].pixels = priv->imageData;
     73    img->p[PIPI_PIXELS_RGBA32].w = priv->width;
     74    img->p[PIPI_PIXELS_RGBA32].h = priv->height;
     75    img->p[PIPI_PIXELS_RGBA32].pitch = priv->widthStep;
     76    img->last_modified = PIPI_PIXELS_RGBA32;
     77
     78    img->codec_priv = (void *)priv;
     79    img->codec_format = PIPI_PIXELS_RGBA32;
    6680
    6781    return img;
     
    7185{
    7286    IplImage *iplimg;
    73     iplimg = (IplImage *)img->priv;
     87    iplimg = (IplImage *)img->codec_priv;
    7488    cvReleaseImage(&iplimg);
    7589
     
    7993void pipi_save_opencv(pipi_image_t *img, const char *name)
    8094{
    81     cvSaveImage(name, img->priv);
     95    pipi_getpixels(img, img->codec_format);
     96    cvSaveImage(name, img->codec_priv);
    8297}
    8398
  • libpipi/trunk/pipi/codec/sdl.c

    r2261 r2605  
    3737        return NULL;
    3838
    39     if(priv->format->BytesPerPixel == 1)
     39    if(priv->format->BytesPerPixel != 4)
    4040    {
    4141        img = pipi_new(priv->w, priv->h);
    42         SDL_BlitSurface(priv, NULL, img->priv, NULL);
     42        SDL_BlitSurface(priv, NULL, img->codec_priv, NULL);
    4343        SDL_FreeSurface(priv);
    4444        return img;
     
    4646
    4747    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
    48     img->width = priv->w;
    49     img->height = priv->h;
    50     img->pitch = priv->pitch;
    51     img->channels = priv->format->BytesPerPixel;
    52     img->pixels = priv->pixels;
    53     img->priv = (void *)priv;
     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;
    5461
    5562    return img;
     
    7986
    8087    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
    81     img->width = priv->w;
    82     img->height = priv->h;
    83     img->pitch = priv->pitch;
    84     img->channels = priv->format->BytesPerPixel;
    85     img->pixels = priv->pixels;
    86     img->priv = (void *)priv;
     88    memset(img, 0, sizeof(pipi_image_t));
     89
     90    img->w = priv->w;
     91    img->h = priv->h;
     92
     93    img->p[PIPI_PIXELS_RGBA32].pixels = priv->pixels;
     94    img->p[PIPI_PIXELS_RGBA32].w = priv->w;
     95    img->p[PIPI_PIXELS_RGBA32].h = priv->h;
     96    img->p[PIPI_PIXELS_RGBA32].pitch = priv->pitch;
     97    img->last_modified = PIPI_PIXELS_RGBA32;
     98
     99    img->codec_priv = (void *)priv;
     100    img->codec_format = PIPI_PIXELS_RGBA32;
    87101
    88102    return img;
     
    91105void pipi_free_sdl(pipi_image_t *img)
    92106{
    93     SDL_FreeSurface(img->priv);
     107    SDL_FreeSurface(img->codec_priv);
    94108
    95109    free(img);
     
    98112void pipi_save_sdl(pipi_image_t *img, const char *name)
    99113{
    100     SDL_SaveBMP(img->priv, name);
     114    pipi_getpixels(img, img->codec_format);
     115    SDL_SaveBMP(img->codec_priv, name);
    101116}
    102117
  • libpipi/trunk/pipi/dither.c

    r2263 r2605  
    2929void pipi_dither_24to16(pipi_image_t *img)
    3030{
     31/* XXX: disabled because this is not the right place... see pixels.c instead */
     32#if 0
    3133    int *error, *nexterror;
    3234    uint32_t *p32;
     
    8587    free(error);
    8688    free(nexterror);
     89#endif
    8790}
    8891
  • libpipi/trunk/pipi/filter/blur.c

    r2603 r2605  
    2828#include "pipi_internals.h"
    2929
    30 pipi_image_t *pipi_gaussian_blur(pipi_image_t const *src, float radius)
     30pipi_image_t *pipi_gaussian_blur(pipi_image_t *src, float radius)
    3131{
    3232    pipi_image_t *dst;
     33    pipi_pixels_t *srcp, *dstp;
     34    float *srcdata, *dstdata;
    3335    double *kernel;
    3436    double K, L, t = 0.;
    3537    int x, y, i, j, w, h, kr, kw;
    3638
    37     w = src->width;
    38     h = src->height;
     39    w = src->w;
     40    h = src->h;
     41
     42    srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
     43    srcdata = (float *)srcp->pixels;
     44
     45    dst = pipi_new(w, h);
     46    dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
     47    dstdata = (float *)dstp->pixels;
    3948
    4049    kr = (int)(3. * radius + 0.99999);
     
    5362            kernel[(j + kr) * kw + (i + kr)] /= t;
    5463
    55     dst = pipi_new(w, h);
    56 
    5764    for(y = 0; y < h; y++)
    5865    {
     
    6471                for(i = -kr; i <= kr; i++)
    6572                {
    66                     double r, g, b, f = kernel[(j + kr) * kw + (i + kr)];
     73                    double f = kernel[(j + kr) * kw + (i + kr)];
    6774
    68                     pipi_getpixel(src, x + i, y + j, &r, &g, &b);
    69                     R += f * r;
    70                     G += f * g;
    71                     B += f * b;
     75                    R += f * srcdata[((y + j) * w + x + i) * 4];
     76                    G += f * srcdata[((y + j) * w + x + i) * 4 + 1];
     77                    B += f * srcdata[((y + j) * w + x + i) * 4 + 2];
    7278                }
    7379
    74             pipi_setpixel(dst, x, y, R, G, B);
     80            dstdata[(y * w + x) * 4] = R;
     81            dstdata[(y * w + x) * 4 + 1] = G;
     82            dstdata[(y * w + x) * 4 + 2] = B;
    7583        }
    7684    }
  • libpipi/trunk/pipi/pipi.c

    r2227 r2605  
     1/*
     2 *  libpipi       Proper image processing implementation library
     3 *  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
     4 *                All Rights Reserved
     5 *
     6 *  $Id$
     7 *
     8 *  This library is free software. It comes without any warranty, to
     9 *  the extent permitted by applicable law. You can redistribute it
     10 *  and/or modify it under the terms of the Do What The Fuck You Want
     11 *  To Public License, Version 2, as published by Sam Hocevar. See
     12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
     13 */
     14
     15/*
     16 * pipi.c: core library routines
     17 */
     18
     19#include "config.h"
     20#include "common.h"
     21
     22#include <stdio.h>
     23#include <stdlib.h>
     24#include <string.h>
     25
     26#include "pipi.h"
     27#include "pipi_internals.h"
     28
     29/*
     30static int init = 0;
     31
     32void _pipi_init(void)
     33{
     34    if(init)
     35        return;
     36
     37    _pipi_init_pixels();
     38}
     39*/
     40
  • libpipi/trunk/pipi/pipi.h

    r2603 r2605  
    2525#endif
    2626
     27/* pipi_format_t: this enum is a list of all possible pixel formats for
     28 * our internal images. RGBA32 is the most usual format when an image has
     29 * just been loaded, but RGBA_F is a lot better for complex operations. */
     30typedef enum
     31{
     32    PIPI_PIXELS_RGBA32 = 0,
     33    PIPI_PIXELS_RGBA_F = 1,
     34
     35    PIPI_PIXELS_MAX = 2
     36}
     37pipi_format_t;
     38
     39/* pipi_pixels_t: this structure stores a pixel view of an image. */
     40typedef struct
     41{
     42    void *pixels;
     43    int w, h, pitch;
     44}
     45pipi_pixels_t;
     46
     47/* pipi_image_t: the main image type */
    2748typedef struct pipi_image pipi_image_t;
    2849
    29 extern pipi_image_t *pipi_load(const char *name);
    30 extern pipi_image_t *pipi_new(int width, int height);
    31 extern pipi_image_t *pipi_copy(const pipi_image_t *img);
    32 extern void pipi_free(pipi_image_t *img);
    33 extern void pipi_save(pipi_image_t *img, const char *name);
    3450
    35 extern int pipi_getgray(pipi_image_t const *img, int x, int y, int *g);
    36 extern int pipi_getpixel(pipi_image_t const *img,
    37                          int x, int y, double *r, double *g, double *b);
    38 extern int pipi_setpixel(pipi_image_t *img, int x, int y,
    39                          double r, double g, double b);
     51extern pipi_image_t *pipi_load(const char *);
     52extern pipi_image_t *pipi_new(int, int);
     53extern void pipi_free(pipi_image_t *);
     54extern void pipi_save(pipi_image_t *, const char *);
    4055
    41 extern pipi_image_t *pipi_resize(pipi_image_t const *, int, int);
     56extern pipi_pixels_t *pipi_getpixels(pipi_image_t *, pipi_format_t);
    4257
    43 extern pipi_image_t *pipi_gaussian_blur(pipi_image_t const *, float);
     58extern pipi_image_t *pipi_resize(pipi_image_t *, int, int);
    4459
    45 extern void pipi_dither_24to16(pipi_image_t *img);
     60extern pipi_image_t *pipi_gaussian_blur(pipi_image_t *, float);
     61
     62extern void pipi_dither_24to16(pipi_image_t *);
    4663
    4764extern void pipi_test(pipi_image_t *);
  • libpipi/trunk/pipi/pipi_internals.h

    r2261 r2605  
    1717 */
    1818
    19 #ifndef __CACA_INTERNALS_H__
    20 #define __CACA_INTERNALS_H__
     19#ifndef __PIPI_INTERNALS_H__
     20#define __PIPI_INTERNALS_H__
    2121
     22/* pipi_image_t: the image structure. This is probably going to be the most
     23 * complex structure in the library, but right now it only has fairly normal
     24 * stuff, like width and height and pointers to pixel areas. */
    2225struct pipi_image
    2326{
    24     int width, height, pitch, channels;
    25     unsigned char *pixels;
    26     void *priv;
     27    int w, h, pitch;
     28    pipi_format_t codec_format, last_modified;
     29
     30    /* List of all possible pixel formats */
     31    pipi_pixels_t p[PIPI_PIXELS_MAX];
     32
     33    /* Private data used by the codec */
     34    void *codec_priv;
    2735};
    2836
  • libpipi/trunk/pipi/pixels.c

    r2602 r2605  
    3232#define I2C(p) ((int)255.999*pow(((double)p), 1./2.2))
    3333
    34 int pipi_getgray(pipi_image_t const *img, int x, int y, int *g)
     34/* Return a direct pointer to an image's pixels. */
     35pipi_pixels_t *pipi_getpixels(pipi_image_t *img, pipi_format_t type)
    3536{
    36     if(x < 0 || y < 0 || x >= img->width || y >= img->height)
     37    size_t bytes = 0;
     38    int x, y, i;
     39
     40    if(type < 0 || type >= PIPI_PIXELS_MAX)
     41        return NULL;
     42
     43    if(img->last_modified == type)
     44        return &img->p[type];
     45
     46    /* Allocate pixels if necessary */
     47    if(!img->p[type].pixels)
    3748    {
    38         *g = 255;
    39         return -1;
     49        switch(type)
     50        {
     51        case PIPI_PIXELS_RGBA32:
     52            bytes = img->w * img->h * 4 * sizeof(uint8_t);
     53            break;
     54        case PIPI_PIXELS_RGBA_F:
     55            bytes = img->w * img->h * 4 * sizeof(float);
     56            break;
     57        default:
     58            return NULL;
     59        }
     60
     61        img->p[type].pixels = malloc(bytes);
    4062    }
    4163
    42     *g = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 1];
     64    /* Convert pixels */
     65    if(img->last_modified == PIPI_PIXELS_RGBA32
     66                  && type == PIPI_PIXELS_RGBA_F)
     67    {
     68        uint8_t *src = (uint8_t *)img->p[PIPI_PIXELS_RGBA32].pixels;
     69        float *dest = (float *)img->p[type].pixels;
    4370
    44     return 0;
     71        for(y = 0; y < img->h; y++)
     72            for(x = 0; x < img->w; x++)
     73                for(i = 0; i < 4; i++)
     74                    dest[4 * (y * img->w + x) + i]
     75                        = C2I(src[4 * (y * img->w + x) + i]);
     76    }
     77    else if(img->last_modified == PIPI_PIXELS_RGBA_F
     78                       && type == PIPI_PIXELS_RGBA32)
     79    {
     80        float *src = (float *)img->p[PIPI_PIXELS_RGBA_F].pixels;
     81        uint8_t *dest = (uint8_t *)img->p[type].pixels;
     82
     83        for(y = 0; y < img->h; y++)
     84            for(x = 0; x < img->w; x++)
     85                for(i = 0; i < 4; i++)
     86                    dest[4 * (y * img->w + x) + i]
     87                        = I2C(src[4 * (y * img->w + x) + i]);
     88    }
     89    else
     90    {
     91        memset(img->p[type].pixels, 0, bytes);
     92    }
     93
     94    img->last_modified = type;
     95
     96    return &img->p[type];
    4597}
    4698
    47 int pipi_getpixel(pipi_image_t const *img,
    48                   int x, int y, double *r, double *g, double *b)
    49 {
    50     uint8_t *pixel;
    51 
    52     if(x < 0) x = 0;
    53     else if(x >= img->width) x = img->width - 1;
    54 
    55     if(y < 0) y = 0;
    56     else if(y >= img->height) y = img->height - 1;
    57 
    58     pixel = img->pixels + y * img->pitch + x * img->channels;
    59 
    60     *b = C2I((unsigned char)pixel[0]);
    61     *g = C2I((unsigned char)pixel[1]);
    62     *r = C2I((unsigned char)pixel[2]);
    63 
    64     return 0;
    65 }
    66 
    67 int pipi_setpixel(pipi_image_t *img, int x, int y, double r, double g, double b)
    68 {
    69     uint8_t *pixel;
    70 
    71     if(x < 0 || y < 0 || x >= img->width || y >= img->height)
    72         return -1;
    73 
    74     pixel = img->pixels + y * img->pitch + x * img->channels;
    75 
    76     pixel[0] = I2C(b);
    77     pixel[1] = I2C(g);
    78     pixel[2] = I2C(r);
    79 
    80     return 0;
    81 }
    82 
  • libpipi/trunk/pipi/resize.c

    r2260 r2605  
    2626#include "pipi_internals.h"
    2727
    28 pipi_image_t *pipi_resize(pipi_image_t const *src, int w, int h)
     28pipi_image_t *pipi_resize(pipi_image_t *src, int w, int h)
    2929{
    30     double *aline, *line;
     30    float *srcdata, *dstdata, *aline, *line;
    3131    pipi_image_t *dst;
     32    pipi_pixels_t *srcp, *dstp;
    3233    int x, y, x0, y0, sw, dw, sh, dh, remy;
    3334
     35    srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
     36    srcdata = (float *)srcp->pixels;
     37
    3438    dst = pipi_new(w, h);
     39    dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
     40    dstdata = (float *)dstp->pixels;
    3541
    36     sw = src->width; sh = src->height;
    37     dw = dst->width; dh = dst->height;
     42    sw = src->w; sh = src->h;
     43    dw = dst->w; dh = dst->h;
    3844
    39     aline = malloc(3 * dw * sizeof(double));
    40     line = malloc(3 * dw * sizeof(double));
     45    aline = malloc(3 * dw * sizeof(float));
     46    line = malloc(3 * dw * sizeof(float));
    4147
    42     memset(line, 0, 3 * dw * sizeof(double));
     48    memset(line, 0, 3 * dw * sizeof(float));
    4349    remy = 0;
    4450
    45     for(y = 0, y0 = 0; y < dst->height; y++)
     51    for(y = 0, y0 = 0; y < dh; y++)
    4652    {
    4753        int toty = 0, ny;
    4854
    49         memset(aline, 0, 3 * dw * sizeof(double));
     55        memset(aline, 0, 3 * dw * sizeof(float));
    5056
    5157        while(toty < sh)
     
    5359            if(remy == 0)
    5460            {
    55                 double r = 0, g = 0, b = 0;
     61                float r = 0, g = 0, b = 0;
    5662                int remx = 0;
    5763
    58                 for(x = 0, x0 = 0; x < dst->width; x++)
     64                for(x = 0, x0 = 0; x < dw; x++)
    5965                {
    60                     double ar = 0, ag = 0, ab = 0;
     66                    float ar = 0, ag = 0, ab = 0;
    6167                    int totx = 0, nx;
    6268
     
    6571                        if(remx == 0)
    6672                        {
    67                             pipi_getpixel(src, x0, y0, &r, &g, &b);
     73                            r = srcdata[(y0 * sw + x0) * 4];
     74                            g = srcdata[(y0 * sw + x0) * 4 + 1];
     75                            b = srcdata[(y0 * sw + x0) * 4 + 2];
    6876                            x0++;
    6977                            remx = dw;
     
    8694
    8795            ny = (toty + remy <= sh) ? remy : sh - toty;
    88             for(x = 0; x < dst->width; x++)
     96            for(x = 0; x < dw; x++)
    8997            {
    9098                aline[3 * x] += ny * line[3 * x];
     
    96104        }
    97105
    98         for(x = 0; x < dst->width; x++)
    99             pipi_setpixel(dst, x, y,
    100                           aline[3 * x] / (sw * sh),
    101                           aline[3 * x + 1] / (sw * sh),
    102                           aline[3 * x + 2] / (sw * sh));
     106        for(x = 0; x < dw; x++)
     107        {
     108            dstdata[(y * dw + x) * 4] = aline[3 * x] / (sw * sh);
     109            dstdata[(y * dw + x) * 4 + 1] = aline[3 * x + 1] / (sw * sh);
     110            dstdata[(y * dw + x) * 4 + 2] = aline[3 * x + 2] / (sw * sh);
     111        }
    103112    }
    104113
  • libpipi/trunk/pipi/test.c

    r2600 r2605  
    2828void pipi_test(pipi_image_t *img)
    2929{
     30    pipi_pixels_t *pixels;
     31    float *data;
    3032    int x, y;
    3133
    32     for(y = 0; y < img->height; y++)
     34    pixels = pipi_getpixels(img, PIPI_PIXELS_RGBA_F);
     35    data = (float *)pixels->pixels;
     36
     37    for(y = 0; y < img->h; y++)
    3338    {
    34         for(x = 0; x < img->width; x++)
     39        for(x = 0; x < img->w; x++)
    3540        {
    3641            double r = 0, g = 0, b = 0;
    3742
    38             pipi_getpixel(img, x, y, &r, &g, &b);
     43            r = data[(y * img->w + x) * 4];
     44            g = data[(y * img->w + x) * 4 + 1];
     45            b = data[(y * img->w + x) * 4 + 2];
     46
    3947            if(r + g + b == 0)
    4048                r = g = b = 1. / 3;
     
    5462                r += d; g -= d; b -= d;
    5563            }
    56             pipi_setpixel(img, x, y, r, g, b);
     64
     65            data[(y * img->w + x) * 4] = r;
     66            data[(y * img->w + x) * 4 + 1] = g;
     67            data[(y * img->w + x) * 4 + 2] = b;
    5768        }
    5869    }
Note: See TracChangeset for help on using the changeset viewer.