]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/jpeg6/jutils.cpp
more eol-style
[xonotic/netradiant.git] / libs / jpeg6 / jutils.cpp
index f5454a6e56f9ac0e7baebe439b045fb5f5e4f91b..f22be932bad7b01d437c0269c199b0f615b3e4d5 100644 (file)
-/*\r
-\r
- * jutils.c\r
-\r
- *\r
-\r
- * Copyright (C) 1991-1995, Thomas G. Lane.\r
-\r
- * This file is part of the Independent JPEG Group's software.\r
-\r
- * For conditions of distribution and use, see the accompanying README file.\r
-\r
- *\r
-\r
- * This file contains tables and miscellaneous utility routines needed\r
-\r
- * for both compression and decompression.\r
-\r
- * Note we prefix all global names with "j" to minimize conflicts with\r
-\r
- * a surrounding application.\r
-\r
- */\r
-\r
-\r
-\r
-#define JPEG_INTERNALS\r
-\r
-#include "jinclude.h"\r
-\r
-#include "radiant_jpeglib.h"\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element\r
-\r
- * of a DCT block read in natural order (left to right, top to bottom).\r
-\r
- */\r
-\r
-\r
-\r
-const int jpeg_zigzag_order[DCTSIZE2] = {\r
-\r
-   0,  1,  5,  6, 14, 15, 27, 28,\r
-\r
-   2,  4,  7, 13, 16, 26, 29, 42,\r
-\r
-   3,  8, 12, 17, 25, 30, 41, 43,\r
-\r
-   9, 11, 18, 24, 31, 40, 44, 53,\r
-\r
-  10, 19, 23, 32, 39, 45, 52, 54,\r
-\r
-  20, 22, 33, 38, 46, 51, 55, 60,\r
-\r
-  21, 34, 37, 47, 50, 56, 59, 61,\r
-\r
-  35, 36, 48, 49, 57, 58, 62, 63\r
-\r
-};\r
-\r
-\r
-\r
-/*\r
-\r
- * jpeg_natural_order[i] is the natural-order position of the i'th element\r
-\r
- * of zigzag order.\r
-\r
- *\r
-\r
- * When reading corrupted data, the Huffman decoders could attempt\r
-\r
- * to reference an entry beyond the end of this array (if the decoded\r
-\r
- * zero run length reaches past the end of the block).  To prevent\r
-\r
- * wild stores without adding an inner-loop test, we put some extra\r
-\r
- * "63"s after the real entries.  This will cause the extra coefficient\r
-\r
- * to be stored in location 63 of the block, not somewhere random.\r
-\r
- * The worst case would be a run-length of 15, which means we need 16\r
-\r
- * fake entries.\r
-\r
- */\r
-\r
-\r
-\r
-const int jpeg_natural_order[DCTSIZE2+16] = {\r
-\r
-  0,  1,  8, 16,  9,  2,  3, 10,\r
-\r
- 17, 24, 32, 25, 18, 11,  4,  5,\r
-\r
- 12, 19, 26, 33, 40, 48, 41, 34,\r
-\r
- 27, 20, 13,  6,  7, 14, 21, 28,\r
-\r
- 35, 42, 49, 56, 57, 50, 43, 36,\r
-\r
- 29, 22, 15, 23, 30, 37, 44, 51,\r
-\r
- 58, 59, 52, 45, 38, 31, 39, 46,\r
-\r
- 53, 60, 61, 54, 47, 55, 62, 63,\r
-\r
- 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */\r
-\r
- 63, 63, 63, 63, 63, 63, 63, 63\r
-\r
-};\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Arithmetic utilities\r
-\r
- */\r
-\r
-\r
-\r
-GLOBAL long\r
-\r
-jdiv_round_up (long a, long b)\r
-\r
-/* Compute a/b rounded up to next integer, ie, ceil(a/b) */\r
-\r
-/* Assumes a >= 0, b > 0 */\r
-\r
-{\r
-\r
-  return (a + b - 1L) / b;\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-GLOBAL long\r
-\r
-jround_up (long a, long b)\r
-\r
-/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */\r
-\r
-/* Assumes a >= 0, b > 0 */\r
-\r
-{\r
-\r
-  a += b - 1L;\r
-\r
-  return a - (a % b);\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays\r
-\r
- * and coefficient-block arrays.  This won't work on 80x86 because the arrays\r
-\r
- * are FAR and we're assuming a small-pointer memory model.  However, some\r
-\r
- * DOS compilers provide far-pointer versions of memcpy() and memset() even\r
-\r
- * in the small-model libraries.  These will be used if USE_FMEM is defined.\r
-\r
- * Otherwise, the routines below do it the hard way.  (The performance cost\r
-\r
- * is not all that great, because these routines aren't very heavily used.)\r
-\r
- */\r
-\r
-\r
-\r
-#ifndef NEED_FAR_POINTERS      /* normal case, same as regular macros */\r
-\r
-#define FMEMCOPY(dest,src,size)        MEMCOPY(dest,src,size)\r
-\r
-#define FMEMZERO(target,size)  MEMZERO(target,size)\r
-\r
-#else                          /* 80x86 case, define if we can */\r
-\r
-#ifdef USE_FMEM\r
-\r
-#define FMEMCOPY(dest,src,size)        _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))\r
-\r
-#define FMEMZERO(target,size)  _fmemset((void FAR *)(target), 0, (size_t)(size))\r
-\r
-#endif\r
-\r
-#endif\r
-\r
-\r
-\r
-\r
-\r
-GLOBAL void\r
-\r
-jcopy_sample_rows (JSAMPARRAY input_array, int source_row,\r
-\r
-                  JSAMPARRAY output_array, int dest_row,\r
-\r
-                  int num_rows, JDIMENSION num_cols)\r
-\r
-/* Copy some rows of samples from one place to another.\r
-\r
- * num_rows rows are copied from input_array[source_row++]\r
-\r
- * to output_array[dest_row++]; these areas may overlap for duplication.\r
-\r
- * The source and destination arrays must be at least as wide as num_cols.\r
-\r
- */\r
-\r
-{\r
-\r
-  register JSAMPROW inptr, outptr;\r
-\r
-#ifdef FMEMCOPY\r
-\r
-  register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));\r
-\r
-#else\r
-\r
-  register JDIMENSION count;\r
-\r
-#endif\r
-\r
-  register int row;\r
-\r
-\r
-\r
-  input_array += source_row;\r
-\r
-  output_array += dest_row;\r
-\r
-\r
-\r
-  for (row = num_rows; row > 0; row--) {\r
-\r
-    inptr = *input_array++;\r
-\r
-    outptr = *output_array++;\r
-\r
-#ifdef FMEMCOPY\r
-\r
-    FMEMCOPY(outptr, inptr, count);\r
-\r
-#else\r
-\r
-    for (count = num_cols; count > 0; count--)\r
-\r
-      *outptr++ = *inptr++;    /* needn't bother with GETJSAMPLE() here */\r
-\r
-#endif\r
-\r
-  }\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-GLOBAL void\r
-\r
-jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,\r
-\r
-                JDIMENSION num_blocks)\r
-\r
-/* Copy a row of coefficient blocks from one place to another. */\r
-\r
-{\r
-\r
-#ifdef FMEMCOPY\r
-\r
-  FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));\r
-\r
-#else\r
-\r
-  register JCOEFPTR inptr, outptr;\r
-\r
-  register long count;\r
-\r
-\r
-\r
-  inptr = (JCOEFPTR) input_row;\r
-\r
-  outptr = (JCOEFPTR) output_row;\r
-\r
-  for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {\r
-\r
-    *outptr++ = *inptr++;\r
-\r
-  }\r
-\r
-#endif\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-GLOBAL void\r
-\r
-jzero_far (void FAR * target, size_t bytestozero)\r
-\r
-/* Zero out a chunk of FAR memory. */\r
-\r
-/* This might be sample-array data, block-array data, or alloc_large data. */\r
-\r
-{\r
-\r
-#ifdef FMEMZERO\r
-\r
-  FMEMZERO(target, bytestozero);\r
-\r
-#else\r
-\r
-  register char FAR * ptr = (char FAR *) target;\r
-\r
-  register size_t count;\r
-\r
-\r
-\r
-  for (count = bytestozero; count > 0; count--) {\r
-\r
-    *ptr++ = 0;\r
-\r
-  }\r
-\r
-#endif\r
-\r
-}\r
-\r
+/*
+
+ * jutils.c
+
+ *
+
+ * Copyright (C) 1991-1995, Thomas G. Lane.
+
+ * This file is part of the Independent JPEG Group's software.
+
+ * For conditions of distribution and use, see the accompanying README file.
+
+ *
+
+ * This file contains tables and miscellaneous utility routines needed
+
+ * for both compression and decompression.
+
+ * Note we prefix all global names with "j" to minimize conflicts with
+
+ * a surrounding application.
+
+ */
+
+
+
+#define JPEG_INTERNALS
+
+#include "jinclude.h"
+
+#include "radiant_jpeglib.h"
+
+
+
+
+
+/*
+
+ * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
+
+ * of a DCT block read in natural order (left to right, top to bottom).
+
+ */
+
+
+
+const int jpeg_zigzag_order[DCTSIZE2] = {
+
+   0,  1,  5,  6, 14, 15, 27, 28,
+
+   2,  4,  7, 13, 16, 26, 29, 42,
+
+   3,  8, 12, 17, 25, 30, 41, 43,
+
+   9, 11, 18, 24, 31, 40, 44, 53,
+
+  10, 19, 23, 32, 39, 45, 52, 54,
+
+  20, 22, 33, 38, 46, 51, 55, 60,
+
+  21, 34, 37, 47, 50, 56, 59, 61,
+
+  35, 36, 48, 49, 57, 58, 62, 63
+
+};
+
+
+
+/*
+
+ * jpeg_natural_order[i] is the natural-order position of the i'th element
+
+ * of zigzag order.
+
+ *
+
+ * When reading corrupted data, the Huffman decoders could attempt
+
+ * to reference an entry beyond the end of this array (if the decoded
+
+ * zero run length reaches past the end of the block).  To prevent
+
+ * wild stores without adding an inner-loop test, we put some extra
+
+ * "63"s after the real entries.  This will cause the extra coefficient
+
+ * to be stored in location 63 of the block, not somewhere random.
+
+ * The worst case would be a run-length of 15, which means we need 16
+
+ * fake entries.
+
+ */
+
+
+
+const int jpeg_natural_order[DCTSIZE2+16] = {
+
+  0,  1,  8, 16,  9,  2,  3, 10,
+
+ 17, 24, 32, 25, 18, 11,  4,  5,
+
+ 12, 19, 26, 33, 40, 48, 41, 34,
+
+ 27, 20, 13,  6,  7, 14, 21, 28,
+
+ 35, 42, 49, 56, 57, 50, 43, 36,
+
+ 29, 22, 15, 23, 30, 37, 44, 51,
+
+ 58, 59, 52, 45, 38, 31, 39, 46,
+
+ 53, 60, 61, 54, 47, 55, 62, 63,
+
+ 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
+
+ 63, 63, 63, 63, 63, 63, 63, 63
+
+};
+
+
+
+
+
+/*
+
+ * Arithmetic utilities
+
+ */
+
+
+
+GLOBAL long
+
+jdiv_round_up (long a, long b)
+
+/* Compute a/b rounded up to next integer, ie, ceil(a/b) */
+
+/* Assumes a >= 0, b > 0 */
+
+{
+
+  return (a + b - 1L) / b;
+
+}
+
+
+
+
+
+GLOBAL long
+
+jround_up (long a, long b)
+
+/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
+
+/* Assumes a >= 0, b > 0 */
+
+{
+
+  a += b - 1L;
+
+  return a - (a % b);
+
+}
+
+
+
+
+
+/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
+
+ * and coefficient-block arrays.  This won't work on 80x86 because the arrays
+
+ * are FAR and we're assuming a small-pointer memory model.  However, some
+
+ * DOS compilers provide far-pointer versions of memcpy() and memset() even
+
+ * in the small-model libraries.  These will be used if USE_FMEM is defined.
+
+ * Otherwise, the routines below do it the hard way.  (The performance cost
+
+ * is not all that great, because these routines aren't very heavily used.)
+
+ */
+
+
+
+#ifndef NEED_FAR_POINTERS      /* normal case, same as regular macros */
+
+#define FMEMCOPY(dest,src,size)        MEMCOPY(dest,src,size)
+
+#define FMEMZERO(target,size)  MEMZERO(target,size)
+
+#else                          /* 80x86 case, define if we can */
+
+#ifdef USE_FMEM
+
+#define FMEMCOPY(dest,src,size)        _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
+
+#define FMEMZERO(target,size)  _fmemset((void FAR *)(target), 0, (size_t)(size))
+
+#endif
+
+#endif
+
+
+
+
+
+GLOBAL void
+
+jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
+
+                  JSAMPARRAY output_array, int dest_row,
+
+                  int num_rows, JDIMENSION num_cols)
+
+/* Copy some rows of samples from one place to another.
+
+ * num_rows rows are copied from input_array[source_row++]
+
+ * to output_array[dest_row++]; these areas may overlap for duplication.
+
+ * The source and destination arrays must be at least as wide as num_cols.
+
+ */
+
+{
+
+  register JSAMPROW inptr, outptr;
+
+#ifdef FMEMCOPY
+
+  register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
+
+#else
+
+  register JDIMENSION count;
+
+#endif
+
+  register int row;
+
+
+
+  input_array += source_row;
+
+  output_array += dest_row;
+
+
+
+  for (row = num_rows; row > 0; row--) {
+
+    inptr = *input_array++;
+
+    outptr = *output_array++;
+
+#ifdef FMEMCOPY
+
+    FMEMCOPY(outptr, inptr, count);
+
+#else
+
+    for (count = num_cols; count > 0; count--)
+
+      *outptr++ = *inptr++;    /* needn't bother with GETJSAMPLE() here */
+
+#endif
+
+  }
+
+}
+
+
+
+
+
+GLOBAL void
+
+jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
+
+                JDIMENSION num_blocks)
+
+/* Copy a row of coefficient blocks from one place to another. */
+
+{
+
+#ifdef FMEMCOPY
+
+  FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
+
+#else
+
+  register JCOEFPTR inptr, outptr;
+
+  register long count;
+
+
+
+  inptr = (JCOEFPTR) input_row;
+
+  outptr = (JCOEFPTR) output_row;
+
+  for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
+
+    *outptr++ = *inptr++;
+
+  }
+
+#endif
+
+}
+
+
+
+
+
+GLOBAL void
+
+jzero_far (void FAR * target, size_t bytestozero)
+
+/* Zero out a chunk of FAR memory. */
+
+/* This might be sample-array data, block-array data, or alloc_large data. */
+
+{
+
+#ifdef FMEMZERO
+
+  FMEMZERO(target, bytestozero);
+
+#else
+
+  register char FAR * ptr = (char FAR *) target;
+
+  register size_t count;
+
+
+
+  for (count = bytestozero; count > 0; count--) {
+
+    *ptr++ = 0;
+
+  }
+
+#endif
+
+}
+