glue.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. Copyright (c) 2022 Bruce A Henderson
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely, subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not
  10. claim that you wrote the original software. If you use this software
  11. in a product, an acknowledgment in the product documentation would be
  12. appreciated but is not required.
  13. 2. Altered source versions must be plainly marked as such, and must not be
  14. misrepresented as being the original software.
  15. 3. This notice may not be removed or altered from any source
  16. distribution.
  17. */
  18. #include "tiffiop.h"
  19. #include "brl.mod/blitz.mod/blitz.h"
  20. extern BBULONG image_tiff__stream_seek(BBObject * stream, BBLONG pos, int whence);
  21. extern int image_tiff__stream_read(BBObject * stream, void * buf, size_t count);
  22. extern void image_tiff__stream_close(BBObject * stream);
  23. extern BBLONG image_tiff__stream_size(BBObject * stream);
  24. static tmsize_t bmx_readProc(thandle_t handle, void *buf, tmsize_t size) {
  25. return image_tiff__stream_read((BBObject*)handle, buf, size);
  26. }
  27. static tmsize_t bmx_writeProc(thandle_t handle, void *buf, tmsize_t size) {
  28. return 0;
  29. }
  30. static toff_t bmx_seekProc(thandle_t handle, toff_t off, int whence) {
  31. return image_tiff__stream_seek((BBObject*)handle, off, whence);
  32. }
  33. static int bmx_closeProc(thandle_t handle) {
  34. image_tiff__stream_close((BBObject*)handle);
  35. return 0;
  36. }
  37. static toff_t bmx_sizeProc(thandle_t handle) {
  38. return image_tiff__stream_size((BBObject*)handle);
  39. }
  40. static int bmx_mapProc(thandle_t handle, void** base, toff_t* size) {
  41. return 0;
  42. }
  43. static void bmx_unmapProc(thandle_t handle, void* base, toff_t size) {
  44. }
  45. TIFF * bmx_tiff_clientOpen(BBObject * stream) {
  46. return TIFFClientOpen("image.tif", "r", stream, bmx_readProc, bmx_writeProc, bmx_seekProc, bmx_closeProc, bmx_sizeProc, bmx_mapProc, bmx_unmapProc);
  47. }
  48. void bmx_tiff_dimensions(TIFF * tiff, BBUINT * width, BBUINT * height) {
  49. TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, width);
  50. TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, height);
  51. }
  52. int bmx_tiff_readRGBAImage(TIFF * tiff, BBUINT width, BBUINT height, void * pixels, int stopOnError) {
  53. return TIFFReadRGBAImageOriented(tiff, width, height, pixels, ORIENTATION_TOPLEFT, stopOnError);
  54. }
  55. void bmx_tiff_close(TIFF * tiff) {
  56. TIFFClose(tiff);
  57. }
  58. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  59. void * _TIFFmalloc(tmsize_t s) {
  60. return malloc(s);
  61. }
  62. void * _TIFFcalloc(tmsize_t nmemb, tmsize_t siz) {
  63. if (nmemb == 0 || siz == 0) {
  64. return ((void *)NULL);
  65. }
  66. return calloc((size_t)nmemb, (size_t)siz);
  67. }
  68. void * _TIFFrealloc(void * p, tmsize_t s) {
  69. return realloc(p, s);
  70. }
  71. void _TIFFmemset(void * p, int v, tmsize_t c) {
  72. memset(p, v, (size_t)c);
  73. }
  74. void _TIFFmemcpy(void * d, const void * s, tmsize_t c) {
  75. memcpy(d, s, (size_t)c);
  76. }
  77. int _TIFFmemcmp(const void * p1, const void * p2, tmsize_t c) {
  78. return (memcmp(p1, p2, (size_t)c));
  79. }
  80. void _TIFFfree(void *p) {
  81. free(p);
  82. }
  83. static void bmx_tiff_handler(const char* module, const char* fmt, va_list ap) {
  84. //printf(fmt, ap);fflush(stdout);
  85. }
  86. TIFFErrorHandler _TIFFwarningHandler = bmx_tiff_handler;
  87. TIFFErrorHandler _TIFFerrorHandler = bmx_tiff_handler;