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

Last change on this file since 2725 was 2725, checked in by Sam Hocevar, 12 years ago
  • color.c: implement pipi_brightness() and pipi_contrast().
  • pipi.c: add --brightness and --contrast.
File size: 1.3 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 * tile.c: Tiling function
17 */
18
19#include "config.h"
20#include "common.h"
21
22#include <strings.h>
23
24#include "pipi.h"
25#include "pipi_internals.h"
26
27pipi_image_t *pipi_tile(pipi_image_t *tile, int w, int h)
28{
29    pipi_image_t *dst;
30    pipi_pixels_t *tilep, *dstp;
31    float *tiledata, *dstdata;
32    int x, y, tw, th, todo;
33
34    tw = tile->w;
35    th = tile->h;
36
37    dst = pipi_new(w, h);
38    dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
39    dstdata = (float *)dstp->pixels;
40
41    tilep = pipi_getpixels(tile, PIPI_PIXELS_RGBA_F);
42    tiledata = (float *)tilep->pixels;
43
44    for(y = 0; y < h; y++)
45    {
46        for(x = 0; x < w; x += todo)
47        {
48            todo = (x + tw > w) ? w - x : tw;
49            memcpy(dstdata + 4 * (y * w + x),
50                   tiledata + 4 * (y % th) * tw,
51                   4 * todo * sizeof(float));
52        }
53    }
54
55    return dst;
56}
57
Note: See TracBrowser for help on using the repository browser.