- jpeg_create_decompress(&cinfo);
- try {
- source_manager src;
- buffer = JvNewByteArray(INPUT_BUF_SIZE);
- src.pub.init_source = init_source;
- src.pub.fill_input_buffer = fill_input_buffer;
- src.pub.skip_input_data = skip_input_data;
- src.pub.resync_to_restart = jpeg_resync_to_restart;
- src.pub.term_source = term_source;
- src.myself = this;
- src.pub.next_input_byte = (JOCTET*)elements(buffer);
- src.pub.bytes_in_buffer = 0;
- cinfo.src = (jpeg_source_mgr*)&src;
-
- jpeg_read_header(&cinfo, 1);
- jpeg_start_decompress(&cinfo);
- width = cinfo.output_width;
- height = cinfo.output_height;
- data = JvNewIntArray(width * height);
-
- while (cinfo.output_scanline < cinfo.output_height) {
- JSAMPLE* dest = (JSAMPLE*)(elements(data) + cinfo.output_scanline * width);
- jpeg_read_scanlines(&cinfo, &dest, 1);
- }
-
- jpeg_finish_decompress(&cinfo);
-
- // fill in the alpha components
- for(int i=0; i<data->length; i++)
- elements(data)[i] |= (jint)0xff000000;
-
- } catch (java::lang::Throwable* t) {
+ src.is = is;
+ src.buf = JvNewByteArray(16384);
+
+ src.pub.init_source = init_source;
+ src.pub.fill_input_buffer = fill_input_buffer;
+ src.pub.skip_input_data = skip_input_data;
+ src.pub.resync_to_restart = jpeg_resync_to_restart;
+ src.pub.term_source = term_source;
+ src.pub.next_input_byte = NULL;
+ src.pub.bytes_in_buffer = 0;
+
+ if (setjmp(jerr.setjmp_buffer)) {
+ // FEATURE - we should handle errors better than this
+ char msgbuf[JMSG_LENGTH_MAX];
+ (jerr.pub.format_message)((j_common_ptr)&cinfo, msgbuf);
+ Log::log(&GCJ::class$,JvNewStringLatin1(msgbuf));