Browse Source

* Resizing in libpipi is now gamma-aware.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2247 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 17 years ago
parent
commit
7a2b8fcc65
2 changed files with 22 additions and 9 deletions
  1. +1
    -1
      genethumb/genethumb.c
  2. +21
    -8
      pipi/pixels.c

+ 1
- 1
genethumb/genethumb.c View File

@@ -8,7 +8,7 @@ int main(void)
pipi_image_t *i, *j;

i = pipi_load("irc.png");
j = pipi_resize(i, 240, 240);
j = pipi_resize(i, 180, 180);
pipi_save(j, "irc.bmp");
pipi_free(i);
pipi_free(j);


+ 21
- 8
pipi/pixels.c View File

@@ -16,16 +16,21 @@
* pixels.c: pixel-level image manipulation
*/

#include "config.h"
#include "common.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "common.h"
#include <math.h>

#include "pipi_internals.h"
#include "pipi.h"

#define C2I(p) ((int)255.999*pow(((double)p)/255., 2.2))
#define I2C(p) ((int)255.999*pow(((double)p)/255., 1./2.2))

int pipi_getgray(pipi_image_t const *img, int x, int y, int *g)
{
if(x < 0 || y < 0 || x >= img->width || y >= img->height)
@@ -42,6 +47,8 @@ int pipi_getgray(pipi_image_t const *img, int x, int y, int *g)
int pipi_getpixel(pipi_image_t const *img,
int x, int y, int *r, int *g, int *b)
{
uint8_t *pixel;

if(x < 0 || y < 0 || x >= img->width || y >= img->height)
{
*r = 255;
@@ -50,21 +57,27 @@ int pipi_getpixel(pipi_image_t const *img,
return -1;
}

*b = (unsigned char)img->pixels[y * img->pitch + x * img->channels];
*g = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 1];
*r = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 2];
pixel = img->pixels + y * img->pitch + x * img->channels;

*b = C2I((unsigned char)pixel[0]);
*g = C2I((unsigned char)pixel[1]);
*r = C2I((unsigned char)pixel[2]);

return 0;
}

int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b)
{
uint8_t *pixel;

if(x < 0 || y < 0 || x >= img->width || y >= img->height)
return -1;

img->pixels[y * img->pitch + x * img->channels] = b;
img->pixels[y * img->pitch + x * img->channels + 1] = g;
img->pixels[y * img->pitch + x * img->channels + 2] = r;
pixel = img->pixels + y * img->pitch + x * img->channels;

pixel[0] = I2C(b);
pixel[1] = I2C(g);
pixel[2] = I2C(r);

return 0;
}


Loading…
Cancel
Save