Ignore:
Timestamp:
02/27/08 01:41:32 (5 years ago)
Author:
sam
Message:
  • Resizing in libpipi is now gamma-aware.
File:
1 edited

Legend:

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

    r2228 r2247  
    1717 */ 
    1818 
     19#include "config.h" 
     20#include "common.h" 
     21 
    1922#include <stdio.h> 
    2023#include <stdlib.h> 
    2124#include <string.h> 
    2225 
    23 #include "config.h" 
    24 #include "common.h" 
     26#include <math.h> 
    2527 
    2628#include "pipi_internals.h" 
    2729#include "pipi.h" 
     30 
     31#define C2I(p) ((int)255.999*pow(((double)p)/255., 2.2)) 
     32#define I2C(p) ((int)255.999*pow(((double)p)/255., 1./2.2)) 
    2833 
    2934int pipi_getgray(pipi_image_t const *img, int x, int y, int *g) 
     
    4348                  int x, int y, int *r, int *g, int *b) 
    4449{ 
     50    uint8_t *pixel; 
     51 
    4552    if(x < 0 || y < 0 || x >= img->width || y >= img->height) 
    4653    { 
     
    5158    } 
    5259 
    53     *b = (unsigned char)img->pixels[y * img->pitch + x * img->channels]; 
    54     *g = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 1]; 
    55     *r = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 2]; 
     60    pixel = img->pixels + y * img->pitch + x * img->channels; 
     61 
     62    *b = C2I((unsigned char)pixel[0]); 
     63    *g = C2I((unsigned char)pixel[1]); 
     64    *r = C2I((unsigned char)pixel[2]); 
    5665 
    5766    return 0; 
     
    6069int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b) 
    6170{ 
     71    uint8_t *pixel; 
     72 
    6273    if(x < 0 || y < 0 || x >= img->width || y >= img->height) 
    6374        return -1; 
    6475 
    65     img->pixels[y * img->pitch + x * img->channels] = b; 
    66     img->pixels[y * img->pitch + x * img->channels + 1] = g; 
    67     img->pixels[y * img->pitch + x * img->channels + 2] = r; 
     76    pixel = img->pixels + y * img->pitch + x * img->channels; 
     77 
     78    pixel[0] = I2C(b); 
     79    pixel[1] = I2C(g); 
     80    pixel[2] = I2C(r); 
    6881 
    6982    return 0; 
Note: See TracChangeset for help on using the changeset viewer.