+/*
+ * This will replace the standard output_message method when the user
+ * wants us to be silent (verbose==false). We must have such method instead of
+ * simply using NULL for cinfo->err->output_message because it's called
+ * unconditionally from within libjpeg when there's "garbage input".
+ */
+CPP_METHODDEF(void) wx_ignore_message (j_common_ptr WXUNUSED(cinfo))
+{
+}
+
+void wx_jpeg_io_src( j_decompress_ptr cinfo, wxInputStream& infile )
+{
+ wx_src_ptr src;
+
+ if (cinfo->src == NULL) { /* first time for this JPEG object? */
+ cinfo->src = (struct jpeg_source_mgr *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ sizeof(wx_source_mgr));
+ }
+ src = (wx_src_ptr) cinfo->src;
+ src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
+ src->buffer = new JOCTET[JPEG_IO_BUFFER_SIZE];
+ src->pub.next_input_byte = NULL; /* until buffer loaded */
+ src->stream = &infile;
+
+ src->pub.init_source = wx_init_source;
+ src->pub.fill_input_buffer = wx_fill_input_buffer;
+ src->pub.skip_input_data = wx_skip_input_data;
+ src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
+ src->pub.term_source = wx_term_source;
+}
+
+} // extern "C"
+
+static inline void wx_cmyk_to_rgb(unsigned char* rgb, const unsigned char* cmyk)
+{
+ register int k = 255 - cmyk[3];
+ register int k2 = cmyk[3];
+ register int c;
+
+ c = k + k2 * (255 - cmyk[0]) / 255;
+ rgb[0] = (unsigned char)((c > 255) ? 0 : (255 - c));
+
+ c = k + k2 * (255 - cmyk[1]) / 255;
+ rgb[1] = (unsigned char)((c > 255) ? 0 : (255 - c));