You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

57 line
1.3 KiB

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