source: libpipi/trunk/test/u8tof32tou8.c

Last change on this file was 3342, checked in by Sam Hocevar, 14 years ago

Change _C pixel format suffixes into _U8 for more clarity.

File size: 1.6 KB
Line 
1/*
2 *  libpipi       Pathetic image processing interface 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 * loadsave.c: unit test to check that converting an image to float values
17 * and back to 8-bit integers does not change it.
18 */
19
20#include "config.h"
21
22#include <stdio.h>
23#include <stdlib.h>
24
25#include <pipi.h>
26
27int main(int argc, char *argv[])
28{
29    pipi_image_t *img1, *img2;
30    pipi_pixels_t *pix1, *pix2;
31    uint32_t *data1, *data2;
32    int x, y, ret = EXIT_SUCCESS;
33
34    img1 = pipi_load("mona.png");
35    img2 = pipi_load("mona.png");
36
37    pix1 = pipi_get_pixels(img1, PIPI_PIXELS_RGBA_U8);
38    data1 = (uint32_t *)pix1->pixels;
39
40    pipi_get_pixels(img2, PIPI_PIXELS_RGBA_F32);
41    pix2 = pipi_get_pixels(img2, PIPI_PIXELS_RGBA_U8);
42    data2 = (uint32_t *)pix2->pixels;
43
44    for(y = 0; y < pix1->h; y++)
45    {
46        for(x = 0; x < pix1->w; x++)
47        {
48            uint32_t a = data1[y * pix1->w + x];
49            uint32_t b = data2[y * pix2->w + x];
50
51            if(a != b)
52            {
53                printf("loadsave: %08x != %08x at (%i,%i)\n", a, b, x, y);
54                ret = EXIT_FAILURE;
55            }
56        }
57    }
58
59    pipi_free(img1);
60    pipi_free(img2);
61
62    return ret;
63}
64
Note: See TracBrowser for help on using the repository browser.