Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

pipi.c 1.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. img->wrap = 0;
  43. img->u8 = 1;
  44. return img;
  45. }
  46. pipi_image_t *pipi_copy(pipi_image_t *src)
  47. {
  48. pipi_image_t *dst = pipi_new(src->w, src->h);
  49. /* Copy properties */
  50. dst->wrap = src->wrap;
  51. dst->u8 = src->u8;
  52. /* Copy pixels, if any */
  53. if(src->last_modified != PIPI_PIXELS_UNINITIALISED)
  54. {
  55. pipi_pixels_t *srcp, *dstp;
  56. srcp = &src->p[src->last_modified];
  57. dstp = &dst->p[src->last_modified];
  58. memcpy(dstp, srcp, sizeof(pipi_pixels_t));
  59. dstp->pixels = malloc(dstp->bytes);
  60. memcpy(dstp->pixels, srcp->pixels, dstp->bytes);
  61. dst->last_modified = src->last_modified;
  62. }
  63. return dst;
  64. }