/src/FreeImage/Source/LibTIFF/tif_dumpmode.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 126 lines · 59 code · 9 blank · 58 comment · 8 complexity · cbdfe17b43ec99bd4c80e5cff2b1a207 MD5 · raw file

  1. /* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_dumpmode.c,v 1.37 2011/04/10 17:14:09 drolon 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. /*
  32. * Encode a hunk of pixels.
  33. */
  34. static int
  35. DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
  36. {
  37. (void) s;
  38. while (cc > 0) {
  39. tsize_t n;
  40. n = cc;
  41. if (tif->tif_rawcc + n > tif->tif_rawdatasize)
  42. n = tif->tif_rawdatasize - tif->tif_rawcc;
  43. assert( n > 0 );
  44. /*
  45. * Avoid copy if client has setup raw
  46. * data buffer to avoid extra copy.
  47. */
  48. if (tif->tif_rawcp != pp)
  49. _TIFFmemcpy(tif->tif_rawcp, pp, n);
  50. tif->tif_rawcp += n;
  51. tif->tif_rawcc += n;
  52. pp += n;
  53. cc -= n;
  54. if (tif->tif_rawcc >= tif->tif_rawdatasize &&
  55. !TIFFFlushData1(tif))
  56. return (-1);
  57. }
  58. return (1);
  59. }
  60. /*
  61. * Decode a hunk of pixels.
  62. */
  63. static int
  64. DumpModeDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
  65. {
  66. (void) s;
  67. /* fprintf(stderr,"DumpModeDecode: scanline %ld, expected %ld bytes, got %ld bytes\n", */
  68. /* (long) tif->tif_row, (long) tif->tif_rawcc, (long) cc); */
  69. if (tif->tif_rawcc < cc) {
  70. TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
  71. "DumpModeDecode: Not enough data for scanline %d",
  72. tif->tif_row);
  73. return (0);
  74. }
  75. /*
  76. * Avoid copy if client has setup raw
  77. * data buffer to avoid extra copy.
  78. */
  79. if (tif->tif_rawcp != buf)
  80. _TIFFmemcpy(buf, tif->tif_rawcp, cc);
  81. tif->tif_rawcp += cc;
  82. tif->tif_rawcc -= cc;
  83. return (1);
  84. }
  85. /*
  86. * Seek forwards nrows in the current strip.
  87. */
  88. static int
  89. DumpModeSeek(TIFF* tif, uint32 nrows)
  90. {
  91. tif->tif_rawcp += nrows * tif->tif_scanlinesize;
  92. tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
  93. return (1);
  94. }
  95. /*
  96. * Initialize dump mode.
  97. */
  98. int
  99. TIFFInitDumpMode(TIFF* tif, int scheme)
  100. {
  101. (void) scheme;
  102. tif->tif_decoderow = DumpModeDecode;
  103. tif->tif_decodestrip = DumpModeDecode;
  104. tif->tif_decodetile = DumpModeDecode;
  105. tif->tif_encoderow = DumpModeEncode;
  106. tif->tif_encodestrip = DumpModeEncode;
  107. tif->tif_encodetile = DumpModeEncode;
  108. tif->tif_seek = DumpModeSeek;
  109. return (1);
  110. }
  111. /*
  112. * Local Variables:
  113. * mode: c
  114. * c-basic-offset: 8
  115. * fill-column: 78
  116. * End:
  117. */