imagenes.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <stdio.h>
  2. #include "../tp2.h"
  3. #include "imagenes.h"
  4. #include "libbmp.h"
  5. BMP *src_img, *src_img2, *dst_img;
  6. void setear_buffer(buffer_info_t *buffer, BMP *bmp)
  7. {
  8. buffer->bytes = bmp_data(bmp);
  9. buffer->width = bmp_width(bmp);
  10. buffer->height = bmp_height(bmp);
  11. buffer->width_with_padding = bmp_bytes_per_row(bmp);
  12. }
  13. void imagenes_abrir(configuracion_t *config)
  14. {
  15. // Cargo la imagen
  16. if ( (src_img = bmp_read (config->archivo_entrada)) == 0 ) {
  17. fprintf(stderr, "Error abriendo la imagen fuente\n");
  18. exit(EXIT_FAILURE);
  19. }
  20. if (bmp_compression(src_img) != BI_RGB) {
  21. fprintf(stderr, "Error: La imagen fuente esta comprimida\n");
  22. exit(EXIT_FAILURE);
  23. }
  24. if (bmp_bit_count(src_img) == 24) {
  25. bmp_convert_24_to_32_bpp(src_img);
  26. }
  27. dst_img = bmp_copy( src_img, 1 );
  28. if (config->archivo_entrada_2 != NULL) {
  29. if ( (src_img2 = bmp_read (config->archivo_entrada_2)) == 0 ) {
  30. fprintf(stderr, "Error abriendo la imagen fuente 2\n");
  31. exit(EXIT_FAILURE);
  32. }
  33. if (bmp_compression(src_img2) != BI_RGB) {
  34. fprintf(stderr, "Error: La imagen fuente 2 esta comprimida\n");
  35. exit(EXIT_FAILURE);
  36. }
  37. if (bmp_bit_count(src_img2) == 24) {
  38. bmp_convert_24_to_32_bpp(src_img2);
  39. }
  40. setear_buffer(&config->src_2, src_img2);
  41. } else {
  42. src_img2 = NULL;
  43. }
  44. setear_buffer(&config->src, src_img);
  45. setear_buffer(&config->dst, dst_img);
  46. }
  47. void imagenes_guardar(configuracion_t *config)
  48. {
  49. bmp_save(config->archivo_salida, dst_img);
  50. }
  51. void imagenes_liberar()
  52. {
  53. bmp_delete(src_img);
  54. if (src_img2 != NULL) {
  55. bmp_delete(src_img2);
  56. }
  57. bmp_delete(dst_img);
  58. }