image_intensities 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/ext/image_intensities/Makefile +73 -4
  3. data/ext/image_intensities/turbojpeg/cderror.h +137 -0
  4. data/ext/image_intensities/turbojpeg/cdjpeg.h +157 -0
  5. data/ext/image_intensities/turbojpeg/cmyk.h +61 -0
  6. data/ext/image_intensities/turbojpeg/jaricom.c +157 -0
  7. data/ext/image_intensities/turbojpeg/jcapimin.c +295 -0
  8. data/ext/image_intensities/turbojpeg/jcapistd.c +162 -0
  9. data/ext/image_intensities/turbojpeg/jcarith.c +932 -0
  10. data/ext/image_intensities/turbojpeg/jccoefct.c +449 -0
  11. data/ext/image_intensities/turbojpeg/jccolext.c +144 -0
  12. data/ext/image_intensities/turbojpeg/jccolor.c +710 -0
  13. data/ext/image_intensities/turbojpeg/jcdctmgr.c +721 -0
  14. data/ext/image_intensities/turbojpeg/jchuff.c +1096 -0
  15. data/ext/image_intensities/turbojpeg/jchuff.h +42 -0
  16. data/ext/image_intensities/turbojpeg/jcicc.c +105 -0
  17. data/ext/image_intensities/turbojpeg/jcinit.c +77 -0
  18. data/ext/image_intensities/turbojpeg/jcmainct.c +162 -0
  19. data/ext/image_intensities/turbojpeg/jcmarker.c +664 -0
  20. data/ext/image_intensities/turbojpeg/jcmaster.c +640 -0
  21. data/ext/image_intensities/turbojpeg/jcomapi.c +109 -0
  22. data/ext/image_intensities/turbojpeg/jconfig.h +73 -0
  23. data/ext/image_intensities/turbojpeg/jconfigint.h +31 -0
  24. data/ext/image_intensities/turbojpeg/jcparam.c +541 -0
  25. data/ext/image_intensities/turbojpeg/jcphuff.c +1105 -0
  26. data/ext/image_intensities/turbojpeg/jcprepct.c +351 -0
  27. data/ext/image_intensities/turbojpeg/jcsample.c +539 -0
  28. data/ext/image_intensities/turbojpeg/jctrans.c +400 -0
  29. data/ext/image_intensities/turbojpeg/jdapimin.c +407 -0
  30. data/ext/image_intensities/turbojpeg/jdapistd.c +639 -0
  31. data/ext/image_intensities/turbojpeg/jdarith.c +773 -0
  32. data/ext/image_intensities/turbojpeg/jdatadst-tj.c +203 -0
  33. data/ext/image_intensities/turbojpeg/jdatadst.c +293 -0
  34. data/ext/image_intensities/turbojpeg/jdatasrc-tj.c +194 -0
  35. data/ext/image_intensities/turbojpeg/jdatasrc.c +295 -0
  36. data/ext/image_intensities/turbojpeg/jdcoefct.c +692 -0
  37. data/ext/image_intensities/turbojpeg/jdcoefct.h +82 -0
  38. data/ext/image_intensities/turbojpeg/jdcol565.c +384 -0
  39. data/ext/image_intensities/turbojpeg/jdcolext.c +143 -0
  40. data/ext/image_intensities/turbojpeg/jdcolor.c +883 -0
  41. data/ext/image_intensities/turbojpeg/jdct.h +208 -0
  42. data/ext/image_intensities/turbojpeg/jddctmgr.c +352 -0
  43. data/ext/image_intensities/turbojpeg/jdhuff.c +831 -0
  44. data/ext/image_intensities/turbojpeg/jdhuff.h +238 -0
  45. data/ext/image_intensities/turbojpeg/jdicc.c +171 -0
  46. data/ext/image_intensities/turbojpeg/jdinput.c +408 -0
  47. data/ext/image_intensities/turbojpeg/jdmainct.c +460 -0
  48. data/ext/image_intensities/turbojpeg/jdmainct.h +71 -0
  49. data/ext/image_intensities/turbojpeg/jdmarker.c +1377 -0
  50. data/ext/image_intensities/turbojpeg/jdmaster.c +737 -0
  51. data/ext/image_intensities/turbojpeg/jdmaster.h +28 -0
  52. data/ext/image_intensities/turbojpeg/jdmerge.c +617 -0
  53. data/ext/image_intensities/turbojpeg/jdmrg565.c +354 -0
  54. data/ext/image_intensities/turbojpeg/jdmrgext.c +184 -0
  55. data/ext/image_intensities/turbojpeg/jdphuff.c +687 -0
  56. data/ext/image_intensities/turbojpeg/jdpostct.c +294 -0
  57. data/ext/image_intensities/turbojpeg/jdsample.c +518 -0
  58. data/ext/image_intensities/turbojpeg/jdsample.h +50 -0
  59. data/ext/image_intensities/turbojpeg/jdtrans.c +155 -0
  60. data/ext/image_intensities/turbojpeg/jerror.c +251 -0
  61. data/ext/image_intensities/turbojpeg/jfdctflt.c +169 -0
  62. data/ext/image_intensities/turbojpeg/jfdctfst.c +227 -0
  63. data/ext/image_intensities/turbojpeg/jfdctint.c +288 -0
  64. data/ext/image_intensities/turbojpeg/jidctflt.c +240 -0
  65. data/ext/image_intensities/turbojpeg/jidctfst.c +371 -0
  66. data/ext/image_intensities/turbojpeg/jidctint.c +2627 -0
  67. data/ext/image_intensities/turbojpeg/jidctred.c +409 -0
  68. data/ext/image_intensities/turbojpeg/jinclude.h +88 -0
  69. data/ext/image_intensities/turbojpeg/jmemmgr.c +1179 -0
  70. data/ext/image_intensities/turbojpeg/jmemnobs.c +115 -0
  71. data/ext/image_intensities/turbojpeg/jmemsys.h +178 -0
  72. data/ext/image_intensities/turbojpeg/jpeg_nbits_table.h +4098 -0
  73. data/ext/image_intensities/turbojpeg/jpegcomp.h +31 -0
  74. data/ext/image_intensities/turbojpeg/jquant1.c +859 -0
  75. data/ext/image_intensities/turbojpeg/jquant2.c +1285 -0
  76. data/ext/image_intensities/turbojpeg/jsimd.h +117 -0
  77. data/ext/image_intensities/turbojpeg/jsimd_none.c +418 -0
  78. data/ext/image_intensities/turbojpeg/jsimddct.h +70 -0
  79. data/ext/image_intensities/turbojpeg/jstdhuff.c +143 -0
  80. data/ext/image_intensities/turbojpeg/jutils.c +133 -0
  81. data/ext/image_intensities/turbojpeg/jversion.h +52 -0
  82. data/ext/image_intensities/turbojpeg/libturbojpeg.a +0 -0
  83. data/ext/image_intensities/turbojpeg/rdbmp.c +689 -0
  84. data/ext/image_intensities/turbojpeg/rdppm.c +766 -0
  85. data/ext/image_intensities/turbojpeg/tjutil.h +47 -0
  86. data/ext/image_intensities/turbojpeg/transupp.c +1628 -0
  87. data/ext/image_intensities/turbojpeg/transupp.h +210 -0
  88. data/ext/image_intensities/turbojpeg/turbojpeg.c +2150 -0
  89. data/ext/image_intensities/turbojpeg/wrbmp.c +558 -0
  90. data/ext/image_intensities/turbojpeg/wrppm.c +365 -0
  91. data/image_intensities.gemspec +1 -1
  92. data/lib/image_intensities/version.rb +1 -1
  93. metadata +91 -3
@@ -0,0 +1,155 @@
1
+ /*
2
+ * jdtrans.c
3
+ *
4
+ * This file was part of the Independent JPEG Group's software:
5
+ * Copyright (C) 1995-1997, Thomas G. Lane.
6
+ * It was modified by The libjpeg-turbo Project to include only code relevant
7
+ * to libjpeg-turbo.
8
+ * For conditions of distribution and use, see the accompanying README.ijg
9
+ * file.
10
+ *
11
+ * This file contains library routines for transcoding decompression,
12
+ * that is, reading raw DCT coefficient arrays from an input JPEG file.
13
+ * The routines in jdapimin.c will also be needed by a transcoder.
14
+ */
15
+
16
+ #define JPEG_INTERNALS
17
+ #include "jinclude.h"
18
+ #include "jpeglib.h"
19
+
20
+
21
+ /* Forward declarations */
22
+ LOCAL(void) transdecode_master_selection(j_decompress_ptr cinfo);
23
+
24
+
25
+ /*
26
+ * Read the coefficient arrays from a JPEG file.
27
+ * jpeg_read_header must be completed before calling this.
28
+ *
29
+ * The entire image is read into a set of virtual coefficient-block arrays,
30
+ * one per component. The return value is a pointer to the array of
31
+ * virtual-array descriptors. These can be manipulated directly via the
32
+ * JPEG memory manager, or handed off to jpeg_write_coefficients().
33
+ * To release the memory occupied by the virtual arrays, call
34
+ * jpeg_finish_decompress() when done with the data.
35
+ *
36
+ * An alternative usage is to simply obtain access to the coefficient arrays
37
+ * during a buffered-image-mode decompression operation. This is allowed
38
+ * after any jpeg_finish_output() call. The arrays can be accessed until
39
+ * jpeg_finish_decompress() is called. (Note that any call to the library
40
+ * may reposition the arrays, so don't rely on access_virt_barray() results
41
+ * to stay valid across library calls.)
42
+ *
43
+ * Returns NULL if suspended. This case need be checked only if
44
+ * a suspending data source is used.
45
+ */
46
+
47
+ GLOBAL(jvirt_barray_ptr *)
48
+ jpeg_read_coefficients(j_decompress_ptr cinfo)
49
+ {
50
+ if (cinfo->global_state == DSTATE_READY) {
51
+ /* First call: initialize active modules */
52
+ transdecode_master_selection(cinfo);
53
+ cinfo->global_state = DSTATE_RDCOEFS;
54
+ }
55
+ if (cinfo->global_state == DSTATE_RDCOEFS) {
56
+ /* Absorb whole file into the coef buffer */
57
+ for (;;) {
58
+ int retcode;
59
+ /* Call progress monitor hook if present */
60
+ if (cinfo->progress != NULL)
61
+ (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
62
+ /* Absorb some more input */
63
+ retcode = (*cinfo->inputctl->consume_input) (cinfo);
64
+ if (retcode == JPEG_SUSPENDED)
65
+ return NULL;
66
+ if (retcode == JPEG_REACHED_EOI)
67
+ break;
68
+ /* Advance progress counter if appropriate */
69
+ if (cinfo->progress != NULL &&
70
+ (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
71
+ if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
72
+ /* startup underestimated number of scans; ratchet up one scan */
73
+ cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows;
74
+ }
75
+ }
76
+ }
77
+ /* Set state so that jpeg_finish_decompress does the right thing */
78
+ cinfo->global_state = DSTATE_STOPPING;
79
+ }
80
+ /* At this point we should be in state DSTATE_STOPPING if being used
81
+ * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access
82
+ * to the coefficients during a full buffered-image-mode decompression.
83
+ */
84
+ if ((cinfo->global_state == DSTATE_STOPPING ||
85
+ cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
86
+ return cinfo->coef->coef_arrays;
87
+ }
88
+ /* Oops, improper usage */
89
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
90
+ return NULL; /* keep compiler happy */
91
+ }
92
+
93
+
94
+ /*
95
+ * Master selection of decompression modules for transcoding.
96
+ * This substitutes for jdmaster.c's initialization of the full decompressor.
97
+ */
98
+
99
+ LOCAL(void)
100
+ transdecode_master_selection(j_decompress_ptr cinfo)
101
+ {
102
+ /* This is effectively a buffered-image operation. */
103
+ cinfo->buffered_image = TRUE;
104
+
105
+ #if JPEG_LIB_VERSION >= 80
106
+ /* Compute output image dimensions and related values. */
107
+ jpeg_core_output_dimensions(cinfo);
108
+ #endif
109
+
110
+ /* Entropy decoding: either Huffman or arithmetic coding. */
111
+ if (cinfo->arith_code) {
112
+ #ifdef D_ARITH_CODING_SUPPORTED
113
+ jinit_arith_decoder(cinfo);
114
+ #else
115
+ ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
116
+ #endif
117
+ } else {
118
+ if (cinfo->progressive_mode) {
119
+ #ifdef D_PROGRESSIVE_SUPPORTED
120
+ jinit_phuff_decoder(cinfo);
121
+ #else
122
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
123
+ #endif
124
+ } else
125
+ jinit_huff_decoder(cinfo);
126
+ }
127
+
128
+ /* Always get a full-image coefficient buffer. */
129
+ jinit_d_coef_controller(cinfo, TRUE);
130
+
131
+ /* We can now tell the memory manager to allocate virtual arrays. */
132
+ (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
133
+
134
+ /* Initialize input side of decompressor to consume first scan. */
135
+ (*cinfo->inputctl->start_input_pass) (cinfo);
136
+
137
+ /* Initialize progress monitoring. */
138
+ if (cinfo->progress != NULL) {
139
+ int nscans;
140
+ /* Estimate number of scans to set pass_limit. */
141
+ if (cinfo->progressive_mode) {
142
+ /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
143
+ nscans = 2 + 3 * cinfo->num_components;
144
+ } else if (cinfo->inputctl->has_multiple_scans) {
145
+ /* For a nonprogressive multiscan file, estimate 1 scan per component. */
146
+ nscans = cinfo->num_components;
147
+ } else {
148
+ nscans = 1;
149
+ }
150
+ cinfo->progress->pass_counter = 0L;
151
+ cinfo->progress->pass_limit = (long)cinfo->total_iMCU_rows * nscans;
152
+ cinfo->progress->completed_passes = 0;
153
+ cinfo->progress->total_passes = 1;
154
+ }
155
+ }
@@ -0,0 +1,251 @@
1
+ /*
2
+ * jerror.c
3
+ *
4
+ * This file was part of the Independent JPEG Group's software:
5
+ * Copyright (C) 1991-1998, Thomas G. Lane.
6
+ * It was modified by The libjpeg-turbo Project to include only code relevant
7
+ * to libjpeg-turbo.
8
+ * For conditions of distribution and use, see the accompanying README.ijg
9
+ * file.
10
+ *
11
+ * This file contains simple error-reporting and trace-message routines.
12
+ * These are suitable for Unix-like systems and others where writing to
13
+ * stderr is the right thing to do. Many applications will want to replace
14
+ * some or all of these routines.
15
+ *
16
+ * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile,
17
+ * you get a Windows-specific hack to display error messages in a dialog box.
18
+ * It ain't much, but it beats dropping error messages into the bit bucket,
19
+ * which is what happens to output to stderr under most Windows C compilers.
20
+ *
21
+ * These routines are used by both the compression and decompression code.
22
+ */
23
+
24
+ /* this is not a core library module, so it doesn't define JPEG_INTERNALS */
25
+ #include "jinclude.h"
26
+ #include "jpeglib.h"
27
+ #include "jversion.h"
28
+ #include "jerror.h"
29
+
30
+ #ifdef USE_WINDOWS_MESSAGEBOX
31
+ #include <windows.h>
32
+ #endif
33
+
34
+ #ifndef EXIT_FAILURE /* define exit() codes if not provided */
35
+ #define EXIT_FAILURE 1
36
+ #endif
37
+
38
+
39
+ /*
40
+ * Create the message string table.
41
+ * We do this from the master message list in jerror.h by re-reading
42
+ * jerror.h with a suitable definition for macro JMESSAGE.
43
+ * The message table is made an external symbol just in case any applications
44
+ * want to refer to it directly.
45
+ */
46
+
47
+ #define JMESSAGE(code, string) string,
48
+
49
+ const char * const jpeg_std_message_table[] = {
50
+ #include "jerror.h"
51
+ NULL
52
+ };
53
+
54
+
55
+ /*
56
+ * Error exit handler: must not return to caller.
57
+ *
58
+ * Applications may override this if they want to get control back after
59
+ * an error. Typically one would longjmp somewhere instead of exiting.
60
+ * The setjmp buffer can be made a private field within an expanded error
61
+ * handler object. Note that the info needed to generate an error message
62
+ * is stored in the error object, so you can generate the message now or
63
+ * later, at your convenience.
64
+ * You should make sure that the JPEG object is cleaned up (with jpeg_abort
65
+ * or jpeg_destroy) at some point.
66
+ */
67
+
68
+ METHODDEF(void)
69
+ error_exit(j_common_ptr cinfo)
70
+ {
71
+ /* Always display the message */
72
+ (*cinfo->err->output_message) (cinfo);
73
+
74
+ /* Let the memory manager delete any temp files before we die */
75
+ jpeg_destroy(cinfo);
76
+
77
+ exit(EXIT_FAILURE);
78
+ }
79
+
80
+
81
+ /*
82
+ * Actual output of an error or trace message.
83
+ * Applications may override this method to send JPEG messages somewhere
84
+ * other than stderr.
85
+ *
86
+ * On Windows, printing to stderr is generally completely useless,
87
+ * so we provide optional code to produce an error-dialog popup.
88
+ * Most Windows applications will still prefer to override this routine,
89
+ * but if they don't, it'll do something at least marginally useful.
90
+ *
91
+ * NOTE: to use the library in an environment that doesn't support the
92
+ * C stdio library, you may have to delete the call to fprintf() entirely,
93
+ * not just not use this routine.
94
+ */
95
+
96
+ METHODDEF(void)
97
+ output_message(j_common_ptr cinfo)
98
+ {
99
+ char buffer[JMSG_LENGTH_MAX];
100
+
101
+ /* Create the message */
102
+ (*cinfo->err->format_message) (cinfo, buffer);
103
+
104
+ #ifdef USE_WINDOWS_MESSAGEBOX
105
+ /* Display it in a message dialog box */
106
+ MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
107
+ MB_OK | MB_ICONERROR);
108
+ #else
109
+ /* Send it to stderr, adding a newline */
110
+ fprintf(stderr, "%s\n", buffer);
111
+ #endif
112
+ }
113
+
114
+
115
+ /*
116
+ * Decide whether to emit a trace or warning message.
117
+ * msg_level is one of:
118
+ * -1: recoverable corrupt-data warning, may want to abort.
119
+ * 0: important advisory messages (always display to user).
120
+ * 1: first level of tracing detail.
121
+ * 2,3,...: successively more detailed tracing messages.
122
+ * An application might override this method if it wanted to abort on warnings
123
+ * or change the policy about which messages to display.
124
+ */
125
+
126
+ METHODDEF(void)
127
+ emit_message(j_common_ptr cinfo, int msg_level)
128
+ {
129
+ struct jpeg_error_mgr *err = cinfo->err;
130
+
131
+ if (msg_level < 0) {
132
+ /* It's a warning message. Since corrupt files may generate many warnings,
133
+ * the policy implemented here is to show only the first warning,
134
+ * unless trace_level >= 3.
135
+ */
136
+ if (err->num_warnings == 0 || err->trace_level >= 3)
137
+ (*err->output_message) (cinfo);
138
+ /* Always count warnings in num_warnings. */
139
+ err->num_warnings++;
140
+ } else {
141
+ /* It's a trace message. Show it if trace_level >= msg_level. */
142
+ if (err->trace_level >= msg_level)
143
+ (*err->output_message) (cinfo);
144
+ }
145
+ }
146
+
147
+
148
+ /*
149
+ * Format a message string for the most recent JPEG error or message.
150
+ * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
151
+ * characters. Note that no '\n' character is added to the string.
152
+ * Few applications should need to override this method.
153
+ */
154
+
155
+ METHODDEF(void)
156
+ format_message(j_common_ptr cinfo, char *buffer)
157
+ {
158
+ struct jpeg_error_mgr *err = cinfo->err;
159
+ int msg_code = err->msg_code;
160
+ const char *msgtext = NULL;
161
+ const char *msgptr;
162
+ char ch;
163
+ boolean isstring;
164
+
165
+ /* Look up message string in proper table */
166
+ if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
167
+ msgtext = err->jpeg_message_table[msg_code];
168
+ } else if (err->addon_message_table != NULL &&
169
+ msg_code >= err->first_addon_message &&
170
+ msg_code <= err->last_addon_message) {
171
+ msgtext = err->addon_message_table[msg_code - err->first_addon_message];
172
+ }
173
+
174
+ /* Defend against bogus message number */
175
+ if (msgtext == NULL) {
176
+ err->msg_parm.i[0] = msg_code;
177
+ msgtext = err->jpeg_message_table[0];
178
+ }
179
+
180
+ /* Check for string parameter, as indicated by %s in the message text */
181
+ isstring = FALSE;
182
+ msgptr = msgtext;
183
+ while ((ch = *msgptr++) != '\0') {
184
+ if (ch == '%') {
185
+ if (*msgptr == 's') isstring = TRUE;
186
+ break;
187
+ }
188
+ }
189
+
190
+ /* Format the message into the passed buffer */
191
+ if (isstring)
192
+ sprintf(buffer, msgtext, err->msg_parm.s);
193
+ else
194
+ sprintf(buffer, msgtext,
195
+ err->msg_parm.i[0], err->msg_parm.i[1],
196
+ err->msg_parm.i[2], err->msg_parm.i[3],
197
+ err->msg_parm.i[4], err->msg_parm.i[5],
198
+ err->msg_parm.i[6], err->msg_parm.i[7]);
199
+ }
200
+
201
+
202
+ /*
203
+ * Reset error state variables at start of a new image.
204
+ * This is called during compression startup to reset trace/error
205
+ * processing to default state, without losing any application-specific
206
+ * method pointers. An application might possibly want to override
207
+ * this method if it has additional error processing state.
208
+ */
209
+
210
+ METHODDEF(void)
211
+ reset_error_mgr(j_common_ptr cinfo)
212
+ {
213
+ cinfo->err->num_warnings = 0;
214
+ /* trace_level is not reset since it is an application-supplied parameter */
215
+ cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
216
+ }
217
+
218
+
219
+ /*
220
+ * Fill in the standard error-handling methods in a jpeg_error_mgr object.
221
+ * Typical call is:
222
+ * struct jpeg_compress_struct cinfo;
223
+ * struct jpeg_error_mgr err;
224
+ *
225
+ * cinfo.err = jpeg_std_error(&err);
226
+ * after which the application may override some of the methods.
227
+ */
228
+
229
+ GLOBAL(struct jpeg_error_mgr *)
230
+ jpeg_std_error(struct jpeg_error_mgr *err)
231
+ {
232
+ err->error_exit = error_exit;
233
+ err->emit_message = emit_message;
234
+ err->output_message = output_message;
235
+ err->format_message = format_message;
236
+ err->reset_error_mgr = reset_error_mgr;
237
+
238
+ err->trace_level = 0; /* default = no tracing */
239
+ err->num_warnings = 0; /* no warnings emitted yet */
240
+ err->msg_code = 0; /* may be useful as a flag for "no error" */
241
+
242
+ /* Initialize message table pointers */
243
+ err->jpeg_message_table = jpeg_std_message_table;
244
+ err->last_jpeg_message = (int)JMSG_LASTMSGCODE - 1;
245
+
246
+ err->addon_message_table = NULL;
247
+ err->first_addon_message = 0; /* for safety */
248
+ err->last_addon_message = 0;
249
+
250
+ return err;
251
+ }
@@ -0,0 +1,169 @@
1
+ /*
2
+ * jfdctflt.c
3
+ *
4
+ * Copyright (C) 1994-1996, Thomas G. Lane.
5
+ * This file is part of the Independent JPEG Group's software.
6
+ * For conditions of distribution and use, see the accompanying README.ijg
7
+ * file.
8
+ *
9
+ * This file contains a floating-point implementation of the
10
+ * forward DCT (Discrete Cosine Transform).
11
+ *
12
+ * This implementation should be more accurate than either of the integer
13
+ * DCT implementations. However, it may not give the same results on all
14
+ * machines because of differences in roundoff behavior. Speed will depend
15
+ * on the hardware's floating point capacity.
16
+ *
17
+ * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
18
+ * on each column. Direct algorithms are also available, but they are
19
+ * much more complex and seem not to be any faster when reduced to code.
20
+ *
21
+ * This implementation is based on Arai, Agui, and Nakajima's algorithm for
22
+ * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
23
+ * Japanese, but the algorithm is described in the Pennebaker & Mitchell
24
+ * JPEG textbook (see REFERENCES section in file README.ijg). The following
25
+ * code is based directly on figure 4-8 in P&M.
26
+ * While an 8-point DCT cannot be done in less than 11 multiplies, it is
27
+ * possible to arrange the computation so that many of the multiplies are
28
+ * simple scalings of the final outputs. These multiplies can then be
29
+ * folded into the multiplications or divisions by the JPEG quantization
30
+ * table entries. The AA&N method leaves only 5 multiplies and 29 adds
31
+ * to be done in the DCT itself.
32
+ * The primary disadvantage of this method is that with a fixed-point
33
+ * implementation, accuracy is lost due to imprecise representation of the
34
+ * scaled quantization values. However, that problem does not arise if
35
+ * we use floating point arithmetic.
36
+ */
37
+
38
+ #define JPEG_INTERNALS
39
+ #include "jinclude.h"
40
+ #include "jpeglib.h"
41
+ #include "jdct.h" /* Private declarations for DCT subsystem */
42
+
43
+ #ifdef DCT_FLOAT_SUPPORTED
44
+
45
+
46
+ /*
47
+ * This module is specialized to the case DCTSIZE = 8.
48
+ */
49
+
50
+ #if DCTSIZE != 8
51
+ Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
52
+ #endif
53
+
54
+
55
+ /*
56
+ * Perform the forward DCT on one block of samples.
57
+ */
58
+
59
+ GLOBAL(void)
60
+ jpeg_fdct_float(FAST_FLOAT *data)
61
+ {
62
+ FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
63
+ FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
64
+ FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
65
+ FAST_FLOAT *dataptr;
66
+ int ctr;
67
+
68
+ /* Pass 1: process rows. */
69
+
70
+ dataptr = data;
71
+ for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) {
72
+ tmp0 = dataptr[0] + dataptr[7];
73
+ tmp7 = dataptr[0] - dataptr[7];
74
+ tmp1 = dataptr[1] + dataptr[6];
75
+ tmp6 = dataptr[1] - dataptr[6];
76
+ tmp2 = dataptr[2] + dataptr[5];
77
+ tmp5 = dataptr[2] - dataptr[5];
78
+ tmp3 = dataptr[3] + dataptr[4];
79
+ tmp4 = dataptr[3] - dataptr[4];
80
+
81
+ /* Even part */
82
+
83
+ tmp10 = tmp0 + tmp3; /* phase 2 */
84
+ tmp13 = tmp0 - tmp3;
85
+ tmp11 = tmp1 + tmp2;
86
+ tmp12 = tmp1 - tmp2;
87
+
88
+ dataptr[0] = tmp10 + tmp11; /* phase 3 */
89
+ dataptr[4] = tmp10 - tmp11;
90
+
91
+ z1 = (tmp12 + tmp13) * ((FAST_FLOAT)0.707106781); /* c4 */
92
+ dataptr[2] = tmp13 + z1; /* phase 5 */
93
+ dataptr[6] = tmp13 - z1;
94
+
95
+ /* Odd part */
96
+
97
+ tmp10 = tmp4 + tmp5; /* phase 2 */
98
+ tmp11 = tmp5 + tmp6;
99
+ tmp12 = tmp6 + tmp7;
100
+
101
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
102
+ z5 = (tmp10 - tmp12) * ((FAST_FLOAT)0.382683433); /* c6 */
103
+ z2 = ((FAST_FLOAT)0.541196100) * tmp10 + z5; /* c2-c6 */
104
+ z4 = ((FAST_FLOAT)1.306562965) * tmp12 + z5; /* c2+c6 */
105
+ z3 = tmp11 * ((FAST_FLOAT)0.707106781); /* c4 */
106
+
107
+ z11 = tmp7 + z3; /* phase 5 */
108
+ z13 = tmp7 - z3;
109
+
110
+ dataptr[5] = z13 + z2; /* phase 6 */
111
+ dataptr[3] = z13 - z2;
112
+ dataptr[1] = z11 + z4;
113
+ dataptr[7] = z11 - z4;
114
+
115
+ dataptr += DCTSIZE; /* advance pointer to next row */
116
+ }
117
+
118
+ /* Pass 2: process columns. */
119
+
120
+ dataptr = data;
121
+ for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) {
122
+ tmp0 = dataptr[DCTSIZE * 0] + dataptr[DCTSIZE * 7];
123
+ tmp7 = dataptr[DCTSIZE * 0] - dataptr[DCTSIZE * 7];
124
+ tmp1 = dataptr[DCTSIZE * 1] + dataptr[DCTSIZE * 6];
125
+ tmp6 = dataptr[DCTSIZE * 1] - dataptr[DCTSIZE * 6];
126
+ tmp2 = dataptr[DCTSIZE * 2] + dataptr[DCTSIZE * 5];
127
+ tmp5 = dataptr[DCTSIZE * 2] - dataptr[DCTSIZE * 5];
128
+ tmp3 = dataptr[DCTSIZE * 3] + dataptr[DCTSIZE * 4];
129
+ tmp4 = dataptr[DCTSIZE * 3] - dataptr[DCTSIZE * 4];
130
+
131
+ /* Even part */
132
+
133
+ tmp10 = tmp0 + tmp3; /* phase 2 */
134
+ tmp13 = tmp0 - tmp3;
135
+ tmp11 = tmp1 + tmp2;
136
+ tmp12 = tmp1 - tmp2;
137
+
138
+ dataptr[DCTSIZE * 0] = tmp10 + tmp11; /* phase 3 */
139
+ dataptr[DCTSIZE * 4] = tmp10 - tmp11;
140
+
141
+ z1 = (tmp12 + tmp13) * ((FAST_FLOAT)0.707106781); /* c4 */
142
+ dataptr[DCTSIZE * 2] = tmp13 + z1; /* phase 5 */
143
+ dataptr[DCTSIZE * 6] = tmp13 - z1;
144
+
145
+ /* Odd part */
146
+
147
+ tmp10 = tmp4 + tmp5; /* phase 2 */
148
+ tmp11 = tmp5 + tmp6;
149
+ tmp12 = tmp6 + tmp7;
150
+
151
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
152
+ z5 = (tmp10 - tmp12) * ((FAST_FLOAT)0.382683433); /* c6 */
153
+ z2 = ((FAST_FLOAT)0.541196100) * tmp10 + z5; /* c2-c6 */
154
+ z4 = ((FAST_FLOAT)1.306562965) * tmp12 + z5; /* c2+c6 */
155
+ z3 = tmp11 * ((FAST_FLOAT)0.707106781); /* c4 */
156
+
157
+ z11 = tmp7 + z3; /* phase 5 */
158
+ z13 = tmp7 - z3;
159
+
160
+ dataptr[DCTSIZE * 5] = z13 + z2; /* phase 6 */
161
+ dataptr[DCTSIZE * 3] = z13 - z2;
162
+ dataptr[DCTSIZE * 1] = z11 + z4;
163
+ dataptr[DCTSIZE * 7] = z11 - z4;
164
+
165
+ dataptr++; /* advance pointer to next column */
166
+ }
167
+ }
168
+
169
+ #endif /* DCT_FLOAT_SUPPORTED */