< prev index next > modules/javafx.graphics/src/main/native-iio/jpegloader.c
Print this page
j_decompress_ptr cinfo = (j_decompress_ptr) data->jpegObj;
struct jpeg_source_mgr *src = cinfo->src;
sun_jpeg_error_ptr jerr;
int bytes_per_row = cinfo->output_width * cinfo->output_components;
int offset = 0;
-
- JSAMPROW scanline_ptr = (JSAMPROW) malloc(bytes_per_row * sizeof (JSAMPLE));
- if (scanline_ptr == NULL) {
- ThrowByName(env,
- "java/lang/OutOfMemoryError",
- "Reading JPEG Stream");
- return JNI_FALSE;
- }
+ JSAMPROW scanline_ptr = NULL;
if (!SAFE_TO_MULT(cinfo->output_width, cinfo->output_components) ||
!SAFE_TO_MULT(bytes_per_row, cinfo->output_height) ||
((*env)->GetArrayLength(env, barray) <
(bytes_per_row * cinfo->output_height)))
{
- free(scanline_ptr);
ThrowByName(env,
"java/lang/OutOfMemoryError",
"Reading JPEG Stream");
return JNI_FALSE;
}
if (GET_ARRAYS(env, data, &cinfo->src->next_input_byte) == NOT_OK) {
- free(scanline_ptr);
ThrowByName(env,
"java/io/IOException",
"Array pin failed");
return JNI_FALSE;
}
jerr = (sun_jpeg_error_ptr) cinfo->err;
if (setjmp(jerr->setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error
while reading. */
- free(scanline_ptr);
if (!(*env)->ExceptionOccurred(env)) {
char buffer[JMSG_LENGTH_MAX];
(*cinfo->err->format_message) ((struct jpeg_common_struct *) cinfo,
buffer);
ThrowByName(env, "java/io/IOException", buffer);
}
RELEASE_ARRAYS(env, data, cinfo->src->next_input_byte);
return JNI_FALSE;
}
+ scanline_ptr = (JSAMPROW) malloc(bytes_per_row * sizeof(JSAMPLE));
+ if (scanline_ptr == NULL) {
+ ThrowByName(env,
+ "java/lang/OutOfMemoryError",
+ "Reading JPEG Stream");
+ return JNI_FALSE;
+ }
+
while (cinfo->output_scanline < cinfo->output_height) {
int num_scanlines;
if (report_progress == JNI_TRUE) {
RELEASE_ARRAYS(env, data, cinfo->src->next_input_byte);
(*env)->CallVoidMethod(env, this,
memcpy(body+offset,scanline_ptr, bytes_per_row);
(*env)->ReleasePrimitiveArrayCritical(env, barray, body, JNI_ABORT);
offset += bytes_per_row;
}
}
+ free(scanline_ptr);
if (report_progress == JNI_TRUE) {
RELEASE_ARRAYS(env, data, cinfo->src->next_input_byte);
(*env)->CallVoidMethod(env, this,
JPEGImageLoader_updateImageProgressID,
cinfo->output_height);
if ((*env)->ExceptionCheck(env)) {
- free(scanline_ptr);
return JNI_FALSE;
}
if (GET_ARRAYS(env, data, &cinfo->src->next_input_byte) == NOT_OK) {
- free(scanline_ptr);
ThrowByName(env,
"java/io/IOException",
"Array pin failed");
return JNI_FALSE;
}
}
jpeg_finish_decompress(cinfo);
- free(scanline_ptr);
RELEASE_ARRAYS(env, data, cinfo->src->next_input_byte);
return JNI_TRUE;
}
< prev index next >