iljpgencodedefs.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: iljpgencodedefs.h /main/3 1995/10/23 15:56:20 rswiston $ */
  24. /**---------------------------------------------------------------------
  25. ***
  26. *** (c)Copyright 1992 Hewlett-Packard Co.
  27. ***
  28. *** RESTRICTED RIGHTS LEGEND
  29. *** Use, duplication, or disclosure by the U.S. Government is subject to
  30. *** restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
  31. *** Technical Data and Computer Software clause in DFARS 252.227-7013.
  32. *** Hewlett-Packard Company
  33. *** 3000 Hanover Street
  34. *** Palo Alto, CA 94304 U.S.A.
  35. *** Rights for non-DOD U.S. Government Departments and Agencies are as set
  36. *** forth in FAR 52.227-19(c)(1,2).
  37. ***
  38. ***-------------------------------------------------------------------*/
  39. #ifndef ILJPGENCODEDEFS_H
  40. #define ILJPGENCODEDEFS_H
  41. #include "ilint.h"
  42. #include "ilerrors.h"
  43. /* Equate ILJPG errors to IL errors */
  44. #define ILJPG_ERROR_ENCODE_MALLOC IL_ERROR_MALLOC
  45. #define ILJPG_ERROR_ENCODE_PARS IL_ERROR_COMPRESSED_DATA
  46. #define ILJPG_ERROR_ENCODE_DCAC_TABLE IL_ERROR_COMPRESSED_DATA
  47. #define ILJPG_ERROR_ENCODE_Q_TABLE IL_ERROR_COMPRESSED_DATA
  48. /* Define a JPEG stream: "pBuffer" points to a buffer in
  49. memory, "pPastEndBuffer" points to byte just past end
  50. (buffer is of size "pPastEndBuffer" - "pBuffer") and
  51. pDst points to the place to store the next byte.
  52. */
  53. typedef struct {
  54. ilPtr pBuffer;
  55. ilPtr pDst;
  56. ilPtr pPastEndBuffer;
  57. } ilJPEGEncodeStream, *ilJPEGEncodeStreamPtr;
  58. #define ILJPG_ENCODE_STREAM ilJPEGEncodeStreamPtr
  59. /* Called by ILJPG_ENCODE_PUT_BYTE() macro to reallocate the buffer
  60. defined by "pStream" so that there is space for *exactly* "nBytes" bytes
  61. to be written. Zero (0) is returned if success else an error code.
  62. */
  63. IL_EXTERN iljpgError _ilReallocJPEGEncode (
  64. ilJPEGEncodeStreamPtr pStream,
  65. long nBytes
  66. );
  67. /* # of bytes by which to expand the size of the output buffer
  68. when realloc'ing to write one byte. NOTE: must be >= 1!
  69. */
  70. #define ILJPG_REALLOC_EXTRA 1024
  71. /* Macro to put a byte to a stream. Return one (1) from macro
  72. if success, else return zero (0) and set "_error" to a
  73. non-zero error code.
  74. */
  75. #define ILJPG_ENCODE_PUT_BYTE(_stream, _byte, _error) ( \
  76. ((_stream)->pDst >= (_stream)->pPastEndBuffer) ? \
  77. ((_error = _ilReallocJPEGEncode (_stream, ILJPG_REALLOC_EXTRA)) ? 0 : \
  78. (*(_stream)->pDst++ = _byte, 1)) : \
  79. (*(_stream)->pDst++ = _byte, 1) )
  80. /* Macro to return position within dst buffer, like ftell() */
  81. #define ILJPG_ENCODE_OFFSET(_stream) \
  82. ((_stream)->pDst - (_stream)->pBuffer)
  83. #endif