tif_dumpmode.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 DumpFixupTags(TIFF *tif)
  31. {
  32. (void)tif;
  33. return (1);
  34. }
  35. /*
  36. * Encode a hunk of pixels.
  37. */
  38. static int DumpModeEncode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
  39. {
  40. (void)s;
  41. while (cc > 0)
  42. {
  43. tmsize_t n;
  44. n = cc;
  45. if (tif->tif_rawcc + n > tif->tif_rawdatasize)
  46. n = tif->tif_rawdatasize - tif->tif_rawcc;
  47. assert(n > 0);
  48. /*
  49. * Avoid copy if client has setup raw
  50. * data buffer to avoid extra copy.
  51. */
  52. if (tif->tif_rawcp != pp)
  53. _TIFFmemcpy(tif->tif_rawcp, pp, n);
  54. tif->tif_rawcp += n;
  55. tif->tif_rawcc += n;
  56. pp += n;
  57. cc -= n;
  58. if (tif->tif_rawcc >= tif->tif_rawdatasize && !TIFFFlushData1(tif))
  59. return (0);
  60. }
  61. return (1);
  62. }
  63. /*
  64. * Decode a hunk of pixels.
  65. */
  66. static int DumpModeDecode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
  67. {
  68. static const char module[] = "DumpModeDecode";
  69. (void)s;
  70. if (tif->tif_rawcc < cc)
  71. {
  72. TIFFErrorExtR(tif, module,
  73. "Not enough data for scanline %" PRIu32
  74. ", expected a request for at most %" TIFF_SSIZE_FORMAT
  75. " bytes, got a request for %" TIFF_SSIZE_FORMAT " bytes",
  76. tif->tif_row, tif->tif_rawcc, cc);
  77. return (0);
  78. }
  79. /*
  80. * Avoid copy if client has setup raw
  81. * data buffer to avoid extra copy.
  82. */
  83. if (tif->tif_rawcp != buf)
  84. _TIFFmemcpy(buf, tif->tif_rawcp, cc);
  85. tif->tif_rawcp += cc;
  86. tif->tif_rawcc -= cc;
  87. return (1);
  88. }
  89. /*
  90. * Seek forwards nrows in the current strip.
  91. */
  92. static int DumpModeSeek(TIFF *tif, uint32_t nrows)
  93. {
  94. tif->tif_rawcp += nrows * tif->tif_scanlinesize;
  95. tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
  96. return (1);
  97. }
  98. /*
  99. * Initialize dump mode.
  100. */
  101. int TIFFInitDumpMode(TIFF *tif, int scheme)
  102. {
  103. (void)scheme;
  104. tif->tif_fixuptags = DumpFixupTags;
  105. tif->tif_decoderow = DumpModeDecode;
  106. tif->tif_decodestrip = DumpModeDecode;
  107. tif->tif_decodetile = DumpModeDecode;
  108. tif->tif_encoderow = DumpModeEncode;
  109. tif->tif_encodestrip = DumpModeEncode;
  110. tif->tif_encodetile = DumpModeEncode;
  111. tif->tif_seek = DumpModeSeek;
  112. return (1);
  113. }