source: libpipi/trunk/pipi/pixels.c @ 2228

Last change on this file since 2228 was 2228, checked in by Sam Hocevar, 15 years ago
  • Import image loading features from PWNtcha. As they are more than 4-year old, they will certainly require some cleanup, eg. pkg-config transitions.
File size: 1.8 KB
Line 
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 * pixels.c: pixel-level image manipulation
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22
23#include "config.h"
24#include "common.h"
25
26#include "pipi_internals.h"
27#include "pipi.h"
28
29int pipi_getgray(pipi_image_t const *img, int x, int y, int *g)
30{
31    if(x < 0 || y < 0 || x >= img->width || y >= img->height)
32    {
33        *g = 255;
34        return -1;
35    }
36
37    *g = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 1];
38
39    return 0;
40}
41
42int pipi_getpixel(pipi_image_t const *img,
43                  int x, int y, int *r, int *g, int *b)
44{
45    if(x < 0 || y < 0 || x >= img->width || y >= img->height)
46    {
47        *r = 255;
48        *g = 255;
49        *b = 255;
50        return -1;
51    }
52
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];
56
57    return 0;
58}
59
60int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b)
61{
62    if(x < 0 || y < 0 || x >= img->width || y >= img->height)
63        return -1;
64
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;
68
69    return 0;
70}
71
Note: See TracBrowser for help on using the repository browser.