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.6 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. if(src->last_modified != PIPI_PIXELS_UNINITIALISED)
  48. {
  49. pipi_pixels_t *srcp, *dstp;
  50. srcp = &src->p[src->last_modified];
  51. dstp = &dst->p[src->last_modified];
  52. memcpy(dstp, srcp, sizeof(pipi_pixels_t));
  53. dstp->pixels = malloc(dstp->bytes);
  54. memcpy(dstp->pixels, srcp->pixels, dstp->bytes);
  55. dst->last_modified = src->last_modified;
  56. }
  57. return dst;
  58. }