25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

pipi.c 2.0 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * 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. /** \brief Return the \e libpipi version.
  25. *
  26. * Return a read-only string with the \e libpipi version information.
  27. *
  28. * This function never fails.
  29. *
  30. * \return The \e libpipi version information.
  31. */
  32. char const * pipi_get_version(void)
  33. {
  34. return PACKAGE_VERSION;
  35. }
  36. /*
  37. static int init = 0;
  38. void _pipi_init(void)
  39. {
  40. if(init)
  41. return;
  42. _pipi_init_pixels();
  43. }
  44. */
  45. pipi_image_t *pipi_new(int w, int h)
  46. {
  47. pipi_image_t *img;
  48. img = malloc(sizeof(pipi_image_t));
  49. memset(img, 0, sizeof(pipi_image_t));
  50. img->w = w;
  51. img->h = h;
  52. img->last_modified = PIPI_PIXELS_UNINITIALISED;
  53. img->codec_format = PIPI_PIXELS_UNINITIALISED;
  54. img->wrap = 0;
  55. img->u8 = 1;
  56. return img;
  57. }
  58. pipi_image_t *pipi_copy(pipi_image_t *src)
  59. {
  60. pipi_image_t *dst = pipi_new(src->w, src->h);
  61. /* Copy properties */
  62. dst->wrap = src->wrap;
  63. dst->u8 = src->u8;
  64. /* Copy pixels, if any */
  65. if(src->last_modified != PIPI_PIXELS_UNINITIALISED)
  66. {
  67. pipi_pixels_t *srcp, *dstp;
  68. srcp = &src->p[src->last_modified];
  69. dstp = &dst->p[src->last_modified];
  70. memcpy(dstp, srcp, sizeof(pipi_pixels_t));
  71. dstp->pixels = malloc(dstp->bytes);
  72. memcpy(dstp->pixels, srcp->pixels, dstp->bytes);
  73. dst->last_modified = src->last_modified;
  74. }
  75. return dst;
  76. }