tif_dumpmode.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 1988-1997 Sam Leffler
  3. * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and
  6. * its documentation for any purpose is hereby granted without fee, provided
  7. * that (i) the above copyright notices and this permission notice appear in
  8. * all copies of the software and related documentation, and (ii) the names of
  9. * Sam Leffler and Silicon Graphics may not be used in any advertising or
  10. * publicity relating to the software without the specific, prior written
  11. * permission of Sam Leffler and Silicon Graphics.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  18. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  21. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22. * OF THIS SOFTWARE.
  23. */
  24. /*
  25. * TIFF Library.
  26. *
  27. * "Null" Compression Algorithm Support.
  28. */
  29. #include "tiffiop.h"
  30. static int
  31. DumpFixupTags(TIFF* tif)
  32. {
  33. (void) tif;
  34. return (1);
  35. }
  36. /*
  37. * Encode a hunk of pixels.
  38. */
  39. static int
  40. DumpModeEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s)
  41. {
  42. (void) s;
  43. while (cc > 0) {
  44. tmsize_t n;
  45. n = cc;
  46. if (tif->tif_rawcc + n > tif->tif_rawdatasize)
  47. n = tif->tif_rawdatasize - tif->tif_rawcc;
  48. assert( n > 0 );
  49. /*
  50. * Avoid copy if client has setup raw
  51. * data buffer to avoid extra copy.
  52. */
  53. if (tif->tif_rawcp != pp)
  54. _TIFFmemcpy(tif->tif_rawcp, pp, n);
  55. tif->tif_rawcp += n;
  56. tif->tif_rawcc += n;
  57. pp += n;
  58. cc -= n;
  59. if (tif->tif_rawcc >= tif->tif_rawdatasize &&
  60. !TIFFFlushData1(tif))
  61. return (0);
  62. }
  63. return (1);
  64. }
  65. /*
  66. * Decode a hunk of pixels.
  67. */
  68. static int
  69. DumpModeDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
  70. {
  71. static const char module[] = "DumpModeDecode";
  72. (void) s;
  73. if (tif->tif_rawcc < cc) {
  74. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  75. TIFFErrorExt(tif->tif_clientdata, module,
  76. "Not enough data for scanline %lu, expected a request for at most %I64d bytes, got a request for %I64d bytes",
  77. (unsigned long) tif->tif_row,
  78. (signed __int64) tif->tif_rawcc,
  79. (signed __int64) cc);
  80. #else
  81. TIFFErrorExt(tif->tif_clientdata, module,
  82. "Not enough data for scanline %lu, expected a request for at most %lld bytes, got a request for %lld bytes",
  83. (unsigned long) tif->tif_row,
  84. (signed long long) tif->tif_rawcc,
  85. (signed long long) cc);
  86. #endif
  87. return (0);
  88. }
  89. /*
  90. * Avoid copy if client has setup raw
  91. * data buffer to avoid extra copy.
  92. */
  93. if (tif->tif_rawcp != buf)
  94. _TIFFmemcpy(buf, tif->tif_rawcp, cc);
  95. tif->tif_rawcp += cc;
  96. tif->tif_rawcc -= cc;
  97. return (1);
  98. }
  99. /*
  100. * Seek forwards nrows in the current strip.
  101. */
  102. static int
  103. DumpModeSeek(TIFF* tif, uint32 nrows)
  104. {
  105. tif->tif_rawcp += nrows * tif->tif_scanlinesize;
  106. tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
  107. return (1);
  108. }
  109. /*
  110. * Initialize dump mode.
  111. */
  112. int
  113. TIFFInitDumpMode(TIFF* tif, int scheme)
  114. {
  115. (void) scheme;
  116. tif->tif_fixuptags = DumpFixupTags;
  117. tif->tif_decoderow = DumpModeDecode;
  118. tif->tif_decodestrip = DumpModeDecode;
  119. tif->tif_decodetile = DumpModeDecode;
  120. tif->tif_encoderow = DumpModeEncode;
  121. tif->tif_encodestrip = DumpModeEncode;
  122. tif->tif_encodetile = DumpModeEncode;
  123. tif->tif_seek = DumpModeSeek;
  124. return (1);
  125. }
  126. /*
  127. * Local Variables:
  128. * mode: c
  129. * c-basic-offset: 8
  130. * fill-column: 78
  131. * End:
  132. */