aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorKaroly Lorentey2006-04-28 14:48:18 +0000
committerKaroly Lorentey2006-04-28 14:48:18 +0000
commitb33c71f58623306001d4d4fe4f7354d8c360edaa (patch)
tree3bcc8154133fcb19081850754bb725f38f86b56f /src/image.c
parent717a00ef34c0f55bfbad80584f00d86c090d547f (diff)
parenta48b489eb94a238c1eca6a0c4bdf7d5b80503240 (diff)
downloademacs-b33c71f58623306001d4d4fe4f7354d8c360edaa.tar.gz
emacs-b33c71f58623306001d4d4fe4f7354d8c360edaa.zip
Merged from emacs@sv.gnu.org
Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-234 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-235 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-236 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-237 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-238 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-239 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-240 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-241 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-242 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-243 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-244 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-245 (Ffield_beginning, find_field): Undo change of 2006-04-23. * emacs@sv.gnu.org/emacs--devo--0--patch-246 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-247 Rcirc patch from Ryan Yeske * emacs@sv.gnu.org/emacs--devo--0--patch-248 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-249 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-250 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-251 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-87 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-88 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-89 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-90 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-91 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-92 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-93 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-94 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-95 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-553
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c136
1 files changed, 105 insertions, 31 deletions
diff --git a/src/image.c b/src/image.c
index a6b3c8f19c5..eae25fdb02e 100644
--- a/src/image.c
+++ b/src/image.c
@@ -603,7 +603,9 @@ x_destroy_all_bitmaps (dpyinfo)
603/* Useful functions defined in the section 603/* Useful functions defined in the section
604 `Image type independent image structures' below. */ 604 `Image type independent image structures' below. */
605 605
606static unsigned long four_corners_best P_ ((XImagePtr ximg, unsigned long width, 606static unsigned long four_corners_best P_ ((XImagePtr ximg,
607 int *corners,
608 unsigned long width,
607 unsigned long height)); 609 unsigned long height));
608 610
609static int x_create_x_image_and_pixmap P_ ((struct frame *f, int width, int height, 611static int x_create_x_image_and_pixmap P_ ((struct frame *f, int width, int height,
@@ -657,7 +659,7 @@ x_create_bitmap_mask (f, id)
657 return -1; 659 return -1;
658 } 660 }
659 661
660 bg = four_corners_best (ximg, width, height); 662 bg = four_corners_best (ximg, NULL, width, height);
661 663
662 for (y = 0; y < ximg->height; ++y) 664 for (y = 0; y < ximg->height; ++y)
663 { 665 {
@@ -732,7 +734,7 @@ Lisp_Object Qxbm;
732/* Keywords. */ 734/* Keywords. */
733 735
734extern Lisp_Object QCwidth, QCheight, QCforeground, QCbackground, QCfile; 736extern Lisp_Object QCwidth, QCheight, QCforeground, QCbackground, QCfile;
735extern Lisp_Object QCdata, QCtype; 737extern Lisp_Object QCdata, QCtype, Qcount;
736extern Lisp_Object Qcenter; 738extern Lisp_Object Qcenter;
737Lisp_Object QCascent, QCmargin, QCrelief; 739Lisp_Object QCascent, QCmargin, QCrelief;
738Lisp_Object QCconversion, QCcolor_symbols, QCheuristic_mask; 740Lisp_Object QCconversion, QCcolor_symbols, QCheuristic_mask;
@@ -1141,6 +1143,27 @@ or omitted means use the selected frame. */)
1141 return mask; 1143 return mask;
1142} 1144}
1143 1145
1146DEFUN ("image-extension-data", Fimage_extension_data, Simage_extension_data, 1, 2, 0,
1147 doc: /* Return extension data for image SPEC.
1148FRAME is the frame on which the image will be displayed. FRAME nil
1149or omitted means use the selected frame. */)
1150 (spec, frame)
1151 Lisp_Object spec, frame;
1152{
1153 Lisp_Object ext;
1154
1155 ext = Qnil;
1156 if (valid_image_p (spec))
1157 {
1158 struct frame *f = check_x_frame (frame);
1159 int id = lookup_image (f, spec);
1160 struct image *img = IMAGE_FROM_ID (f, id);
1161 ext = img->data.lisp_val;
1162 }
1163
1164 return ext;
1165}
1166
1144 1167
1145/*********************************************************************** 1168/***********************************************************************
1146 Image type independent image structures 1169 Image type independent image structures
@@ -1171,6 +1194,7 @@ make_image (spec, hash)
1171 img->data.lisp_val = Qnil; 1194 img->data.lisp_val = Qnil;
1172 img->ascent = DEFAULT_IMAGE_ASCENT; 1195 img->ascent = DEFAULT_IMAGE_ASCENT;
1173 img->hash = hash; 1196 img->hash = hash;
1197 img->corners[BOT_CORNER] = -1; /* Full image */
1174 return img; 1198 return img;
1175} 1199}
1176 1200
@@ -1322,30 +1346,41 @@ image_ascent (img, face, slice)
1322 On W32, XIMG is assumed to a device context with the bitmap selected. */ 1346 On W32, XIMG is assumed to a device context with the bitmap selected. */
1323 1347
1324static RGB_PIXEL_COLOR 1348static RGB_PIXEL_COLOR
1325four_corners_best (ximg, width, height) 1349four_corners_best (ximg, corners, width, height)
1326 XImagePtr_or_DC ximg; 1350 XImagePtr_or_DC ximg;
1351 int *corners;
1327 unsigned long width, height; 1352 unsigned long width, height;
1328{ 1353{
1329 RGB_PIXEL_COLOR corners[4], best; 1354 RGB_PIXEL_COLOR corner_pixels[4], best;
1330 int i, best_count; 1355 int i, best_count;
1331 1356
1332 /* Get the colors at the corners of ximg. */ 1357 if (corners && corners[BOT_CORNER] >= 0)
1333 corners[0] = GET_PIXEL (ximg, 0, 0); 1358 {
1334 corners[1] = GET_PIXEL (ximg, width - 1, 0); 1359 /* Get the colors at the corner_pixels of ximg. */
1335 corners[2] = GET_PIXEL (ximg, width - 1, height - 1); 1360 corner_pixels[0] = GET_PIXEL (ximg, corners[LEFT_CORNER], corners[TOP_CORNER]);
1336 corners[3] = GET_PIXEL (ximg, 0, height - 1); 1361 corner_pixels[1] = GET_PIXEL (ximg, corners[RIGHT_CORNER] - 1, corners[TOP_CORNER]);
1337 1362 corner_pixels[2] = GET_PIXEL (ximg, corners[RIGHT_CORNER] - 1, corners[BOT_CORNER] - 1);
1363 corner_pixels[3] = GET_PIXEL (ximg, corners[LEFT_CORNER], corners[BOT_CORNER] - 1);
1364 }
1365 else
1366 {
1367 /* Get the colors at the corner_pixels of ximg. */
1368 corner_pixels[0] = GET_PIXEL (ximg, 0, 0);
1369 corner_pixels[1] = GET_PIXEL (ximg, width - 1, 0);
1370 corner_pixels[2] = GET_PIXEL (ximg, width - 1, height - 1);
1371 corner_pixels[3] = GET_PIXEL (ximg, 0, height - 1);
1372 }
1338 /* Choose the most frequently found color as background. */ 1373 /* Choose the most frequently found color as background. */
1339 for (i = best_count = 0; i < 4; ++i) 1374 for (i = best_count = 0; i < 4; ++i)
1340 { 1375 {
1341 int j, n; 1376 int j, n;
1342 1377
1343 for (j = n = 0; j < 4; ++j) 1378 for (j = n = 0; j < 4; ++j)
1344 if (corners[i] == corners[j]) 1379 if (corner_pixels[i] == corner_pixels[j])
1345 ++n; 1380 ++n;
1346 1381
1347 if (n > best_count) 1382 if (n > best_count)
1348 best = corners[i], best_count = n; 1383 best = corner_pixels[i], best_count = n;
1349 } 1384 }
1350 1385
1351 return best; 1386 return best;
@@ -1404,7 +1439,7 @@ image_background (img, f, ximg)
1404#endif /* !HAVE_NTGUI */ 1439#endif /* !HAVE_NTGUI */
1405 } 1440 }
1406 1441
1407 img->background = four_corners_best (ximg, img->width, img->height); 1442 img->background = four_corners_best (ximg, img->corners, img->width, img->height);
1408 1443
1409 if (free_ximg) 1444 if (free_ximg)
1410 Destroy_Image (ximg, prev); 1445 Destroy_Image (ximg, prev);
@@ -1449,7 +1484,7 @@ image_background_transparent (img, f, mask)
1449 } 1484 }
1450 1485
1451 img->background_transparent 1486 img->background_transparent
1452 = (four_corners_best (mask, img->width, img->height) == PIX_MASK_RETAIN); 1487 = (four_corners_best (mask, img->corners, img->width, img->height) == PIX_MASK_RETAIN);
1453 1488
1454 if (free_mask) 1489 if (free_mask)
1455 Destroy_Image (mask, prev); 1490 Destroy_Image (mask, prev);
@@ -4462,6 +4497,10 @@ xpm_load_image (f, img, contents, end)
4462 img->width = width; 4497 img->width = width;
4463 img->height = height; 4498 img->height = height;
4464 4499
4500 /* Maybe fill in the background field while we have ximg handy. */
4501 if (NILP (image_spec_value (img->spec, QCbackground, NULL)))
4502 IMAGE_BACKGROUND (img, f, ximg);
4503
4465 x_put_x_image (f, ximg, img->pixmap, width, height); 4504 x_put_x_image (f, ximg, img->pixmap, width, height);
4466 x_destroy_x_image (ximg); 4505 x_destroy_x_image (ximg);
4467 if (have_mask) 4506 if (have_mask)
@@ -5356,7 +5395,7 @@ x_build_heuristic_mask (f, img, how)
5356 } 5395 }
5357 5396
5358 if (use_img_background) 5397 if (use_img_background)
5359 bg = four_corners_best (ximg, img->width, img->height); 5398 bg = four_corners_best (ximg, img->corners, img->width, img->height);
5360 5399
5361 /* Set all bits in mask_img to 1 whose color in ximg is different 5400 /* Set all bits in mask_img to 1 whose color in ximg is different
5362 from the background color bg. */ 5401 from the background color bg. */
@@ -7449,6 +7488,7 @@ tiff_load (f, img)
7449 7488
7450static int gif_image_p P_ ((Lisp_Object object)); 7489static int gif_image_p P_ ((Lisp_Object object));
7451static int gif_load P_ ((struct frame *f, struct image *img)); 7490static int gif_load P_ ((struct frame *f, struct image *img));
7491static void gif_clear_image P_ ((struct frame *f, struct image *img));
7452 7492
7453/* The symbol `gif' identifying images of this type. */ 7493/* The symbol `gif' identifying images of this type. */
7454 7494
@@ -7497,10 +7537,22 @@ static struct image_type gif_type =
7497 &Qgif, 7537 &Qgif,
7498 gif_image_p, 7538 gif_image_p,
7499 gif_load, 7539 gif_load,
7500 x_clear_image, 7540 gif_clear_image,
7501 NULL 7541 NULL
7502}; 7542};
7503 7543
7544/* Free X resources of GIF image IMG which is used on frame F. */
7545
7546static void
7547gif_clear_image (f, img)
7548 struct frame *f;
7549 struct image *img;
7550{
7551 /* IMG->data.ptr_val may contain extension data. */
7552 img->data.lisp_val = Qnil;
7553 x_clear_image (f, img);
7554}
7555
7504/* Return non-zero if OBJECT is a valid GIF image specification. */ 7556/* Return non-zero if OBJECT is a valid GIF image specification. */
7505 7557
7506static int 7558static int
@@ -7621,7 +7673,7 @@ gif_load (f, img)
7621 GifFileType *gif; 7673 GifFileType *gif;
7622 struct gcpro gcpro1; 7674 struct gcpro gcpro1;
7623 Lisp_Object image; 7675 Lisp_Object image;
7624 int ino, image_left, image_top, image_width, image_height; 7676 int ino, image_height, image_width;
7625 gif_memory_source memsrc; 7677 gif_memory_source memsrc;
7626 unsigned char *raster; 7678 unsigned char *raster;
7627 7679
@@ -7698,17 +7750,19 @@ gif_load (f, img)
7698 return 0; 7750 return 0;
7699 } 7751 }
7700 7752
7701 image_top = gif->SavedImages[ino].ImageDesc.Top; 7753 img->corners[TOP_CORNER] = gif->SavedImages[ino].ImageDesc.Top;
7702 image_left = gif->SavedImages[ino].ImageDesc.Left; 7754 img->corners[LEFT_CORNER] = gif->SavedImages[ino].ImageDesc.Left;
7703 image_width = gif->SavedImages[ino].ImageDesc.Width;
7704 image_height = gif->SavedImages[ino].ImageDesc.Height; 7755 image_height = gif->SavedImages[ino].ImageDesc.Height;
7756 img->corners[BOT_CORNER] = img->corners[TOP_CORNER] + image_height;
7757 image_width = gif->SavedImages[ino].ImageDesc.Width;
7758 img->corners[RIGHT_CORNER] = img->corners[LEFT_CORNER] + image_width;
7705 7759
7706 width = img->width = max (gif->SWidth, 7760 width = img->width = max (gif->SWidth,
7707 max (gif->Image.Left + gif->Image.Width, 7761 max (gif->Image.Left + gif->Image.Width,
7708 image_left + image_width)); 7762 img->corners[RIGHT_CORNER]));
7709 height = img->height = max (gif->SHeight, 7763 height = img->height = max (gif->SHeight,
7710 max (gif->Image.Top + gif->Image.Height, 7764 max (gif->Image.Top + gif->Image.Height,
7711 image_top + image_height)); 7765 img->corners[BOT_CORNER]));
7712 7766
7713 if (!check_image_size (f, width, height)) 7767 if (!check_image_size (f, width, height))
7714 { 7768 {
@@ -7751,19 +7805,19 @@ gif_load (f, img)
7751 requires more than can be done here (see the gif89 spec, 7805 requires more than can be done here (see the gif89 spec,
7752 disposal methods). Let's simply assume that the part 7806 disposal methods). Let's simply assume that the part
7753 not covered by a sub-image is in the frame's background color. */ 7807 not covered by a sub-image is in the frame's background color. */
7754 for (y = 0; y < image_top; ++y) 7808 for (y = 0; y < img->corners[TOP_CORNER]; ++y)
7755 for (x = 0; x < width; ++x) 7809 for (x = 0; x < width; ++x)
7756 XPutPixel (ximg, x, y, FRAME_BACKGROUND_PIXEL (f)); 7810 XPutPixel (ximg, x, y, FRAME_BACKGROUND_PIXEL (f));
7757 7811
7758 for (y = image_top + image_height; y < height; ++y) 7812 for (y = img->corners[BOT_CORNER]; y < height; ++y)
7759 for (x = 0; x < width; ++x) 7813 for (x = 0; x < width; ++x)
7760 XPutPixel (ximg, x, y, FRAME_BACKGROUND_PIXEL (f)); 7814 XPutPixel (ximg, x, y, FRAME_BACKGROUND_PIXEL (f));
7761 7815
7762 for (y = image_top; y < image_top + image_height; ++y) 7816 for (y = img->corners[TOP_CORNER]; y < img->corners[BOT_CORNER]; ++y)
7763 { 7817 {
7764 for (x = 0; x < image_left; ++x) 7818 for (x = 0; x < img->corners[LEFT_CORNER]; ++x)
7765 XPutPixel (ximg, x, y, FRAME_BACKGROUND_PIXEL (f)); 7819 XPutPixel (ximg, x, y, FRAME_BACKGROUND_PIXEL (f));
7766 for (x = image_left + image_width; x < width; ++x) 7820 for (x = img->corners[RIGHT_CORNER]; x < width; ++x)
7767 XPutPixel (ximg, x, y, FRAME_BACKGROUND_PIXEL (f)); 7821 XPutPixel (ximg, x, y, FRAME_BACKGROUND_PIXEL (f));
7768 } 7822 }
7769 7823
@@ -7793,8 +7847,8 @@ gif_load (f, img)
7793 for (x = 0; x < image_width; x++) 7847 for (x = 0; x < image_width; x++)
7794 { 7848 {
7795 int i = raster[(y * image_width) + x]; 7849 int i = raster[(y * image_width) + x];
7796 XPutPixel (ximg, x + image_left, row + image_top, 7850 XPutPixel (ximg, x + img->corners[LEFT_CORNER],
7797 pixel_colors[i]); 7851 row + img->corners[TOP_CORNER], pixel_colors[i]);
7798 } 7852 }
7799 7853
7800 row += interlace_increment[pass]; 7854 row += interlace_increment[pass];
@@ -7806,10 +7860,29 @@ gif_load (f, img)
7806 for (x = 0; x < image_width; ++x) 7860 for (x = 0; x < image_width; ++x)
7807 { 7861 {
7808 int i = raster[y * image_width + x]; 7862 int i = raster[y * image_width + x];
7809 XPutPixel (ximg, x + image_left, y + image_top, pixel_colors[i]); 7863 XPutPixel (ximg, x + img->corners[LEFT_CORNER],
7864 y + img->corners[TOP_CORNER], pixel_colors[i]);
7810 } 7865 }
7811 } 7866 }
7812 7867
7868 /* Save GIF image extension data for `image-extension-data'.
7869 Format is (count IMAGES FUNCTION "BYTES" ...). */
7870 img->data.lisp_val = Qnil;
7871 if (gif->SavedImages[ino].ExtensionBlockCount > 0)
7872 {
7873 ExtensionBlock *ext = gif->SavedImages[ino].ExtensionBlocks;
7874 for (i = 0; i < gif->SavedImages[ino].ExtensionBlockCount; i++, ext++)
7875 /* Append (... FUNCTION "BYTES") */
7876 img->data.lisp_val = Fcons (make_unibyte_string (ext->Bytes, ext->ByteCount),
7877 Fcons (make_number (ext->Function),
7878 img->data.lisp_val));
7879 img->data.lisp_val = Fnreverse (img->data.lisp_val);
7880 }
7881 if (gif->ImageCount > 1)
7882 img->data.lisp_val = Fcons (Qcount,
7883 Fcons (make_number (gif->ImageCount),
7884 img->data.lisp_val));
7885
7813 fn_DGifCloseFile (gif); 7886 fn_DGifCloseFile (gif);
7814 7887
7815 /* Maybe fill in the background field while we have ximg handy. */ 7888 /* Maybe fill in the background field while we have ximg handy. */
@@ -8555,6 +8628,7 @@ non-numeric, there is no explicit limit on the size of images. */);
8555 defsubr (&Sclear_image_cache); 8628 defsubr (&Sclear_image_cache);
8556 defsubr (&Simage_size); 8629 defsubr (&Simage_size);
8557 defsubr (&Simage_mask_p); 8630 defsubr (&Simage_mask_p);
8631 defsubr (&Simage_extension_data);
8558 8632
8559#if GLYPH_DEBUG 8633#if GLYPH_DEBUG
8560 defsubr (&Simagep); 8634 defsubr (&Simagep);