/* * libpipi Proper image processing implementation library * Copyright (c) 2004-2008 Sam Hocevar * All Rights Reserved * * $Id$ * * This library is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/wtfpl/COPYING for more details. */ /* * pixels.c: pixel-level image manipulation */ #include #include #include #include "config.h" #include "common.h" #include "pipi_internals.h" #include "pipi.h" 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) { *g = 255; return -1; } *g = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 1]; return 0; } int pipi_getpixel(pipi_image_t const *img, int x, int y, int *r, int *g, int *b) { if(x < 0 || y < 0 || x >= img->width || y >= img->height) { *r = 255; *g = 255; *b = 255; 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]; return 0; } int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b) { 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; return 0; }