ext/jpeg_jpeg.c in jpeg-0.1.1 vs ext/jpeg_jpeg.c in jpeg-0.1.2
- old
+ new
@@ -18,17 +18,23 @@
rb_define_singleton_method(Jpeg, "open", jpeg_jpeg_s_open, -1);
rb_define_method(Jpeg, "width", jpeg_jpeg_width, 0);
rb_define_method(Jpeg, "height", jpeg_jpeg_height, 0);
rb_define_method(Jpeg, "size", jpeg_jpeg_size, 0);
}
+void jpeg_jpeg_exit(j_common_ptr jpeg) {
+ char buffer[JMSG_LENGTH_MAX];
+ jpeg->err->format_message(jpeg, buffer);
+ rb_raise(rb_eRuntimeError, buffer);
+}
static VALUE jpeg_jpeg_alloc(VALUE klass) {
struct jpeg_jpeg *jpeg = ALLOC(struct jpeg_jpeg);
jpeg->read = (void *)ALLOC(struct jpeg_decompress_struct);
jpeg->error = (void *)ALLOC(struct jpeg_error_mgr);
jpeg->read->err = jpeg_std_error(jpeg->error);
+ jpeg->error->error_exit = jpeg_jpeg_exit;
jpeg_create_decompress(jpeg->read);
return Data_Wrap_Struct(klass, jpeg_jpeg_mark, jpeg_jpeg_free, jpeg);
}
@@ -36,11 +42,11 @@
}
static void jpeg_jpeg_free(struct jpeg_jpeg *p) {
if (p->read) {
- jpeg_destroy_compress(p->read);
+ jpeg_destroy_decompress(p->read);
free(p->read);
}
if (p->error) {
free(p->error);
}
@@ -61,9 +67,10 @@
if ((fp = fopen(RSTRING_PTR(path), "rb")) == NULL) {
rb_raise(rb_eRuntimeError, "Open file failed");
}
jpeg_stdio_src(p_jpeg->read, fp);
+
jpeg_read_header(p_jpeg->read, TRUE);
jpeg_start_decompress(p_jpeg->read);
fclose(fp);
return jpeg;
}