| 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 "pipi.h" |
|---|
| 23 | #include "pipi_internals.h" |
|---|
| 24 | |
|---|
| 25 | pipi_image_t *pipi_tile(pipi_image_t *tile, int w, int h) |
|---|
| 26 | { |
|---|
| 27 | pipi_image_t *dst; |
|---|
| 28 | pipi_pixels_t *tilep, *dstp; |
|---|
| 29 | float *tiledata, *dstdata; |
|---|
| 30 | int x, y, tw, th, todo; |
|---|
| 31 | |
|---|
| 32 | tw = tile->w; |
|---|
| 33 | th = tile->h; |
|---|
| 34 | |
|---|
| 35 | dst = pipi_new(w, h); |
|---|
| 36 | dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F); |
|---|
| 37 | dstdata = (float *)dstp->pixels; |
|---|
| 38 | |
|---|
| 39 | tilep = pipi_getpixels(tile, PIPI_PIXELS_RGBA_F); |
|---|
| 40 | tiledata = (float *)tilep->pixels; |
|---|
| 41 | |
|---|
| 42 | for(y = 0; y < h; y++) |
|---|
| 43 | { |
|---|
| 44 | for(x = 0; x < w; x += todo) |
|---|
| 45 | { |
|---|
| 46 | todo = (x + tw > w) ? w - x : tw; |
|---|
| 47 | memcpy(dstdata + 4 * (y * w + x), |
|---|
| 48 | tiledata + 4 * (y % th) * tw, |
|---|
| 49 | 4 * todo * sizeof(float)); |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | return dst; |
|---|
| 54 | } |
|---|
| 55 | |
|---|