source: libpipi/trunk/pipi/paint/tile.c @ 4866

Revision 3342, 1.3 KB checked in by sam, 4 years ago (diff)

Change _C pixel format suffixes into _U8 for more clarity.

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 * tile.c: Tiling function
17 */
18
19#include "config.h"
20
21#include <string.h>
22
23#include "pipi.h"
24#include "pipi_internals.h"
25
26pipi_image_t *pipi_tile(pipi_image_t *tile, int w, int h)
27{
28    pipi_image_t *dst;
29    pipi_pixels_t *tilep, *dstp;
30    float *tiledata, *dstdata;
31    int x, y, tw, th, todo;
32
33    tw = tile->w;
34    th = tile->h;
35
36    dst = pipi_new(w, h);
37    dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
38    dstdata = (float *)dstp->pixels;
39
40    tilep = pipi_get_pixels(tile, PIPI_PIXELS_RGBA_F32);
41    tiledata = (float *)tilep->pixels;
42
43    for(y = 0; y < h; y++)
44    {
45        for(x = 0; x < w; x += todo)
46        {
47            todo = (x + tw > w) ? w - x : tw;
48            memcpy(dstdata + 4 * (y * w + x),
49                   tiledata + 4 * (y % th) * tw,
50                   4 * todo * sizeof(float));
51        }
52    }
53
54    return dst;
55}
56
Note: See TracBrowser for help on using the repository browser.