iljpgutil.c 3.4 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: iljpgutil.c /main/3 1995/10/23 15:57:43 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. #include "iljpgint.h"
  40. /* JPEG zigzag scanning order */
  41. ILJPG_PRIVATE
  42. int _iljpgZigzagTable[64] = {
  43. 0, 1, 5, 6,14,15,27,28,
  44. 2, 4, 7,13,16,26,29,42,
  45. 3, 8,12,17,25,30,41,43,
  46. 9,11,18,24,31,40,44,53,
  47. 10,19,23,32,39,45,52,54,
  48. 20,22,33,38,46,51,55,60,
  49. 21,34,37,47,50,56,59,61,
  50. 35,36,48,49,57,58,62,63
  51. };
  52. /* -------------------- _iljpgValidPars -------------------------- */
  53. /* Validate the given parameter block and return true iff valid.
  54. */
  55. ILJPG_PRIVATE
  56. iljpgBool _iljpgValidPars (
  57. iljpgDataPtr pData
  58. )
  59. {
  60. int comp;
  61. iljpgCompDataPtr pCompData;
  62. unsigned int index;
  63. #define VALID_FACTOR(_f) ( ((_f) == 1) || ((_f) == 2) || ((_f) == 4) )
  64. /* Validate *pData: valid hori/vertFactor, tables present, etc. */
  65. if ((pData->nComps <= 0)
  66. || (pData->nComps > ILJPG_MAX_COMPS)
  67. || (pData->nComps > ILJPG_MAX_COMPS)
  68. || !VALID_FACTOR (pData->maxHoriFactor)
  69. || !VALID_FACTOR (pData->maxVertFactor)
  70. || (pData->width <= 0)
  71. || (pData->height <= 0))
  72. return FALSE;
  73. for (comp = 0, pCompData = pData->comp; comp < pData->nComps; comp++, pCompData++) {
  74. if (!VALID_FACTOR (pCompData->horiFactor)
  75. || !VALID_FACTOR (pCompData->vertFactor))
  76. return FALSE;
  77. index = (unsigned int)pCompData->QTableIndex;
  78. if ((index > 3) || !pData->QTables[index])
  79. return FALSE;
  80. index = (unsigned int)pCompData->DCTableIndex;
  81. if ((index > 3) || !pData->DCTables[index])
  82. return FALSE;
  83. index = (unsigned int)pCompData->ACTableIndex;
  84. if ((index > 3) || !pData->ACTables[index])
  85. return FALSE;
  86. }
  87. return TRUE;
  88. }