Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * tiles.c: the tiles system
  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. #ifdef USE_TILES
  24. pipi_tile_t *pipi_get_tile(pipi_image_t *img, int x, int y, int zoom,
  25. pipi_format_t fmt, int plane)
  26. {
  27. pipi_tile_t * ret;
  28. int i;
  29. /* If the tile already exists, return it. */
  30. for(i = 0; i < img->ntiles; i++)
  31. {
  32. if(img->tiles[i]->x == x && img->tiles[i]->y == y
  33. && img->tiles[i]->fmt == fmt
  34. && img->tiles[i]->zoom == zoom
  35. && img->tiles[i]->plane == plane)
  36. {
  37. img->tiles[i]->refcount++;
  38. return img->tiles[i];
  39. }
  40. }
  41. /* Create a tile. When the image provides a tile creation function,
  42. * we should use it. */
  43. ret = pipi_create_tile(fmt, plane);
  44. ret->x = x;
  45. ret->y = y;
  46. ret->refcount = 1;
  47. /* Insert tile and return it. */
  48. img->ntiles++;
  49. img->tiles = realloc(img->tiles, img->ntiles * sizeof(pipi_tile_t *));
  50. img->tiles[img->ntiles - 1] = ret;
  51. return ret;
  52. }
  53. void pipi_release_tile(pipi_image_t *img, pipi_tile_t *tile)
  54. {
  55. int i;
  56. for(i = 0; i < img->ntiles; i++)
  57. {
  58. if(img->tiles[i] == tile)
  59. {
  60. img->tiles[i]->refcount--;
  61. if(img->tiles[i]->refcount <= 0)
  62. {
  63. free(img->tiles[i]);
  64. img->tiles[i] = img->tiles[img->ntiles - 1];
  65. img->ntiles--;
  66. }
  67. return;
  68. }
  69. }
  70. }
  71. pipi_tile_t *pipi_create_tile(pipi_format_t fmt, int plane)
  72. {
  73. pipi_tile_t * ret;
  74. size_t bytes;
  75. switch(fmt)
  76. {
  77. case PIPI_PIXELS_RGBA_U8:
  78. case PIPI_PIXELS_BGR_U8:
  79. bytes = sizeof(uint8_t) * TILE_SIZE * TILE_SIZE;
  80. break;
  81. case PIPI_PIXELS_RGBA_F32:
  82. case PIPI_PIXELS_Y_F32:
  83. bytes = sizeof(float) * TILE_SIZE * TILE_SIZE;
  84. break;
  85. default:
  86. bytes = 0;
  87. break;
  88. }
  89. ret = malloc(sizeof(pipi_tile_t) + bytes);
  90. ret->fmt = fmt;
  91. ret->plane = plane;
  92. ret->data.u8 = ret->align.u8;
  93. return ret;
  94. }
  95. #endif /* USE_TILES */