2
0

tif_dumpmode.c 3.8 KB

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