apple_png 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/apple_png/apple_png.c +9 -5
- data/lib/apple_png.rb +2 -0
- metadata +1 -1
data/ext/apple_png/apple_png.c
CHANGED
@@ -220,11 +220,14 @@ static VALUE ApplePng_convert_apple_png(VALUE self, VALUE data) {
|
|
220
220
|
switch (error) {
|
221
221
|
case APPLE_PNG_STREAM_ERROR:
|
222
222
|
case APPLE_PNG_DATA_ERROR:
|
223
|
-
|
223
|
+
{
|
224
|
+
VALUE eNotValidApplePng = rb_path2class("NotValidApplePngError");
|
225
|
+
rb_raise(eNotValidApplePng, "Could not process the input data. Please make sure this is valid Apple PNG format data.");
|
226
|
+
}
|
224
227
|
case APPLE_PNG_ZLIB_VERSION_ERROR:
|
225
|
-
rb_raise(
|
228
|
+
rb_raise(rb_eStandardError, "Unexpected Zlib version encountered. The caller was expecting Zlib " ZLIB_VERSION ".");
|
226
229
|
case APPLE_PNG_NO_MEM_ERROR:
|
227
|
-
rb_raise(
|
230
|
+
rb_raise(rb_eNoMemError, "Ran out of memory while processing the PNG data.");
|
228
231
|
default:
|
229
232
|
rb_raise(rb_eStandardError, "An unexpected error was encountered while processing the PNG data. Please make sure the input is valid Apple PNG format data.");
|
230
233
|
}
|
@@ -242,13 +245,14 @@ Get the width and height from PNG data without actually converting it.
|
|
242
245
|
@param data [String] Binary string containing Apple PNG data
|
243
246
|
*/
|
244
247
|
static VALUE ApplePng_get_dimensions(VALUE self, VALUE data) {
|
248
|
+
VALUE eNotValidApplePng = rb_path2class("NotValidApplePngError");
|
245
249
|
const char *oldPNG = StringValuePtr(data);
|
246
250
|
size_t oldPNG_length = RSTRING_LEN(data);
|
247
251
|
size_t cursor = 8;
|
248
252
|
|
249
253
|
/* check whether this is actually a png file */
|
250
254
|
if (strncmp(PNG_HEADER, oldPNG, 8) != 0) {
|
251
|
-
rb_raise(
|
255
|
+
rb_raise(eNotValidApplePng, "Input data is not a valid PNG file (missing the PNG magic bytes).");
|
252
256
|
}
|
253
257
|
|
254
258
|
while (cursor < oldPNG_length) {
|
@@ -266,7 +270,7 @@ static VALUE ApplePng_get_dimensions(VALUE self, VALUE data) {
|
|
266
270
|
}
|
267
271
|
}
|
268
272
|
|
269
|
-
rb_raise(
|
273
|
+
rb_raise(eNotValidApplePng, "Input data is not a valid PNG file (missing IHDR chunk).");
|
270
274
|
}
|
271
275
|
|
272
276
|
void Init_apple_png(void) {
|
data/lib/apple_png.rb
CHANGED