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.
 
 
 
 
 
 

118 satır
2.8 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. * sdl.c: SDL_image I/O functions
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <SDL_image.h>
  23. #include "pipi.h"
  24. #include "pipi_internals.h"
  25. pipi_image_t *pipi_load_sdl(const char *name)
  26. {
  27. pipi_image_t *img;
  28. SDL_Surface *priv = IMG_Load(name);
  29. if(!priv)
  30. return NULL;
  31. if(priv->format->BytesPerPixel != 4)
  32. {
  33. img = pipi_new(priv->w, priv->h);
  34. SDL_BlitSurface(priv, NULL, img->codec_priv, NULL);
  35. SDL_FreeSurface(priv);
  36. return img;
  37. }
  38. img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
  39. memset(img, 0, sizeof(pipi_image_t));
  40. img->w = priv->w;
  41. img->h = priv->h;
  42. img->p[PIPI_PIXELS_RGBA32].pixels = priv->pixels;
  43. img->p[PIPI_PIXELS_RGBA32].w = priv->w;
  44. img->p[PIPI_PIXELS_RGBA32].h = priv->h;
  45. img->p[PIPI_PIXELS_RGBA32].pitch = priv->pitch;
  46. img->last_modified = PIPI_PIXELS_RGBA32;
  47. img->codec_priv = (void *)priv;
  48. img->codec_format = PIPI_PIXELS_RGBA32;
  49. return img;
  50. }
  51. pipi_image_t *pipi_new_sdl(int width, int height)
  52. {
  53. pipi_image_t *img;
  54. SDL_Surface *priv;
  55. Uint32 rmask, gmask, bmask, amask;
  56. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  57. rmask = 0xff000000;
  58. gmask = 0x00ff0000;
  59. bmask = 0x0000ff00;
  60. amask = 0x00000000;
  61. #else
  62. rmask = 0x000000ff;
  63. gmask = 0x0000ff00;
  64. bmask = 0x00ff0000;
  65. amask = 0x00000000;
  66. #endif
  67. priv = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
  68. rmask, gmask, bmask, amask);
  69. if(!priv)
  70. return NULL;
  71. img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
  72. memset(img, 0, sizeof(pipi_image_t));
  73. img->w = priv->w;
  74. img->h = priv->h;
  75. img->p[PIPI_PIXELS_RGBA32].pixels = priv->pixels;
  76. img->p[PIPI_PIXELS_RGBA32].w = priv->w;
  77. img->p[PIPI_PIXELS_RGBA32].h = priv->h;
  78. img->p[PIPI_PIXELS_RGBA32].pitch = priv->pitch;
  79. img->last_modified = PIPI_PIXELS_RGBA32;
  80. img->codec_priv = (void *)priv;
  81. img->codec_format = PIPI_PIXELS_RGBA32;
  82. return img;
  83. }
  84. void pipi_free_sdl(pipi_image_t *img)
  85. {
  86. SDL_FreeSurface(img->codec_priv);
  87. free(img);
  88. }
  89. void pipi_save_sdl(pipi_image_t *img, const char *name)
  90. {
  91. pipi_getpixels(img, img->codec_format);
  92. SDL_SaveBMP(img->codec_priv, name);
  93. }