Mercurial > emacs
comparison src/image.c @ 66430:2f521eba6f82
[MAC_OS] (image_load_qt_1): Check image size.
Use GraphicsImportGetImageDescription instead of
GraphicsImportGetNaturalBounds.
[MAC_OSX] (image_load_quartz2d): Check image size.
[MAC_OS] (xpm_load_image): Likewise.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Tue, 25 Oct 2005 08:12:44 +0000 |
parents | 5414bd89ffde |
children | 7929133d8782 |
comparison
equal
deleted
inserted
replaced
66429:2b2388e245c9 | 66430:2f521eba6f82 |
---|---|
2289 { | 2289 { |
2290 OSErr err; | 2290 OSErr err; |
2291 GraphicsImportComponent gi; | 2291 GraphicsImportComponent gi; |
2292 Rect rect; | 2292 Rect rect; |
2293 int width, height; | 2293 int width, height; |
2294 ImageDescriptionHandle desc_handle; | |
2294 short draw_all_pixels; | 2295 short draw_all_pixels; |
2295 Lisp_Object specified_bg; | 2296 Lisp_Object specified_bg; |
2296 XColor color; | 2297 XColor color; |
2297 XImagePtr ximg; | 2298 XImagePtr ximg; |
2298 RGBColor bg_color; | 2299 RGBColor bg_color; |
2324 image_error ("Cannot set data handle to graphics importer for `%s'", | 2325 image_error ("Cannot set data handle to graphics importer for `%s'", |
2325 img->spec, Qnil); | 2326 img->spec, Qnil); |
2326 goto error; | 2327 goto error; |
2327 } | 2328 } |
2328 } | 2329 } |
2329 err = GraphicsImportGetNaturalBounds (gi, &rect); | 2330 err = GraphicsImportGetImageDescription (gi, &desc_handle); |
2330 if (err != noErr) | 2331 if (err != noErr || desc_handle == NULL) |
2331 { | 2332 { |
2332 image_error ("Error reading `%s'", img->spec, Qnil); | 2333 image_error ("Error reading `%s'", img->spec, Qnil); |
2333 goto error; | 2334 goto error; |
2334 } | 2335 } |
2335 width = img->width = rect.right - rect.left; | 2336 width = img->width = (*desc_handle)->width; |
2336 height = img->height = rect.bottom - rect.top; | 2337 height = img->height = (*desc_handle)->height; |
2338 DisposeHandle ((Handle)desc_handle); | |
2339 | |
2340 if (!check_image_size (f, width, height)) | |
2341 { | |
2342 image_error ("Invalid image size", Qnil, Qnil); | |
2343 goto error; | |
2344 } | |
2345 | |
2337 err = GraphicsImportDoesDrawAllPixels (gi, &draw_all_pixels); | 2346 err = GraphicsImportDoesDrawAllPixels (gi, &draw_all_pixels); |
2338 #if 0 | 2347 #if 0 |
2339 /* Don't check the error code here. It may have an undocumented | 2348 /* Don't check the error code here. It may have an undocumented |
2340 value -32766. */ | 2349 value -32766. */ |
2341 if (err != noErr) | 2350 if (err != noErr) |
2533 { | 2542 { |
2534 UNGCPRO; | 2543 UNGCPRO; |
2535 image_error ("Error reading image `%s'", img->spec, Qnil); | 2544 image_error ("Error reading image `%s'", img->spec, Qnil); |
2536 return 0; | 2545 return 0; |
2537 } | 2546 } |
2547 width = img->width = CGImageGetWidth (image); | |
2548 height = img->height = CGImageGetHeight (image); | |
2549 | |
2550 if (!check_image_size (f, width, height)) | |
2551 { | |
2552 UNGCPRO; | |
2553 image_error ("Invalid image size", Qnil, Qnil); | |
2554 return 0; | |
2555 } | |
2538 | 2556 |
2539 if (png_p) | 2557 if (png_p) |
2540 { | 2558 { |
2541 specified_bg = image_spec_value (img->spec, QCbackground, NULL); | 2559 specified_bg = image_spec_value (img->spec, QCbackground, NULL); |
2542 if (!STRINGP (specified_bg) || | 2560 if (!STRINGP (specified_bg) || |
2546 color.red = RED16_FROM_ULONG (color.pixel); | 2564 color.red = RED16_FROM_ULONG (color.pixel); |
2547 color.green = GREEN16_FROM_ULONG (color.pixel); | 2565 color.green = GREEN16_FROM_ULONG (color.pixel); |
2548 color.blue = BLUE16_FROM_ULONG (color.pixel); | 2566 color.blue = BLUE16_FROM_ULONG (color.pixel); |
2549 } | 2567 } |
2550 } | 2568 } |
2551 width = img->width = CGImageGetWidth (image); | 2569 |
2552 height = img->height = CGImageGetHeight (image); | |
2553 if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) | 2570 if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) |
2554 { | 2571 { |
2555 CGImageRelease (image); | 2572 CGImageRelease (image); |
2556 UNGCPRO; | 2573 UNGCPRO; |
2557 return 0; | 2574 return 0; |
4188 if (sscanf (buffer, "%d %d %d %d", &width, &height, | 4205 if (sscanf (buffer, "%d %d %d %d", &width, &height, |
4189 &num_colors, &chars_per_pixel) != 4 | 4206 &num_colors, &chars_per_pixel) != 4 |
4190 || width <= 0 || height <= 0 | 4207 || width <= 0 || height <= 0 |
4191 || num_colors <= 0 || chars_per_pixel <= 0) | 4208 || num_colors <= 0 || chars_per_pixel <= 0) |
4192 goto failure; | 4209 goto failure; |
4210 | |
4211 if (!check_image_size (f, width, height)) | |
4212 { | |
4213 image_error ("Invalid image size", Qnil, Qnil); | |
4214 goto failure; | |
4215 } | |
4216 | |
4193 expect (','); | 4217 expect (','); |
4194 | 4218 |
4195 XSETFRAME (frame, f); | 4219 XSETFRAME (frame, f); |
4196 if (!NILP (Fxw_display_color_p (frame))) | 4220 if (!NILP (Fxw_display_color_p (frame))) |
4197 best_key = XPM_COLOR_KEY_C; | 4221 best_key = XPM_COLOR_KEY_C; |