25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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