source: libpipi/trunk/pipi/resize.c @ 2244

Last change on this file since 2244 was 2244, checked in by Sam Hocevar, 14 years ago
  • Starting image resizing. X-wise resize works so far.
File size: 1.5 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 * resize.c: image resizing functions
17 */
18
19#include "config.h"
20#include "common.h"
21
22#include "pipi_internals.h"
23#include "pipi.h"
24
25pipi_image_t *pipi_resize(pipi_image_t const *src, int w, int h)
26{
27    pipi_image_t *dst;
28    int x, y, x0, y0;
29    dst = pipi_new(w, h);
30
31    int sw = src->width;
32    int dw = dst->width;
33
34    for(y = 0, y0 = 0; y < dst->height; y++)
35    {
36        for(x = 0, x0 = 0; x < dst->width; x++)
37        {
38            int rem = 0, tot = 0;
39            int ar = 0, ag = 0, ab = 0;
40            int r = 0, g = 0, b = 0;
41            int n;
42
43            while(tot < sw)
44            {
45                if(rem == 0)
46                {
47                    pipi_getpixel(src, x0, y, &r, &g, &b);
48                    x0++;
49                    rem = dw;
50                }
51
52                n = (tot + rem <= sw) ? rem : sw - tot;
53                ar += n * r; ag += n * g; ab += n * b;
54                tot += n;
55                rem -= n;
56            }
57
58            pipi_setpixel(dst, x, y, ar / sw, ag / sw, ab / sw);
59        }
60    }
61
62    return dst;
63}
64
Note: See TracBrowser for help on using the repository browser.