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.
 
 
 
 
 
 

81 regels
1.7 KiB

  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. * pipi.c: core library routines
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "pipi.h"
  23. #include "pipi_internals.h"
  24. /*
  25. static int init = 0;
  26. void _pipi_init(void)
  27. {
  28. if(init)
  29. return;
  30. _pipi_init_pixels();
  31. }
  32. */
  33. pipi_image_t *pipi_new(int w, int h)
  34. {
  35. pipi_image_t *img;
  36. img = malloc(sizeof(pipi_image_t));
  37. memset(img, 0, sizeof(pipi_image_t));
  38. img->w = w;
  39. img->h = h;
  40. img->last_modified = PIPI_PIXELS_UNINITIALISED;
  41. img->codec_format = PIPI_PIXELS_UNINITIALISED;
  42. return img;
  43. }
  44. pipi_image_t *pipi_copy(pipi_image_t *src)
  45. {
  46. pipi_image_t *dst = pipi_new(src->w, src->h);
  47. /* Copy properties */
  48. dst->wrap = src->wrap;
  49. /* Copy pixels, if any */
  50. if(src->last_modified != PIPI_PIXELS_UNINITIALISED)
  51. {
  52. pipi_pixels_t *srcp, *dstp;
  53. srcp = &src->p[src->last_modified];
  54. dstp = &dst->p[src->last_modified];
  55. memcpy(dstp, srcp, sizeof(pipi_pixels_t));
  56. dstp->pixels = malloc(dstp->bytes);
  57. memcpy(dstp->pixels, srcp->pixels, dstp->bytes);
  58. dst->last_modified = src->last_modified;
  59. }
  60. return dst;
  61. }