comparison src/glyphs-x.c @ 114:8619ce7e4c50 r20-1b9

Import from CVS: tag r20-1b9
author cvs
date Mon, 13 Aug 2007 09:21:54 +0200
parents 48d667d6f17f
children 9f59509498e1
comparison
equal deleted inserted replaced
113:2ec2fe4a4c89 114:8619ce7e4c50
138 sprintf (buf, "/0x%lx", (unsigned long) IMAGE_INSTANCE_X_MASK (p)); 138 sprintf (buf, "/0x%lx", (unsigned long) IMAGE_INSTANCE_X_MASK (p));
139 write_c_string (buf, printcharfun); 139 write_c_string (buf, printcharfun);
140 } 140 }
141 write_c_string (")", printcharfun); 141 write_c_string (")", printcharfun);
142 break; 142 break;
143 #if HAVE_SUBWINDOWS
143 case IMAGE_SUBWINDOW: 144 case IMAGE_SUBWINDOW:
144 /* #### implement me */ 145 /* #### implement me */
146 #endif
145 default: 147 default:
146 break; 148 break;
147 } 149 }
148 } 150 }
149 151
200 case IMAGE_COLOR_PIXMAP: 202 case IMAGE_COLOR_PIXMAP:
201 case IMAGE_POINTER: 203 case IMAGE_POINTER:
202 if (IMAGE_INSTANCE_X_NPIXELS (p1) != IMAGE_INSTANCE_X_NPIXELS (p2)) 204 if (IMAGE_INSTANCE_X_NPIXELS (p1) != IMAGE_INSTANCE_X_NPIXELS (p2))
203 return 0; 205 return 0;
204 break; 206 break;
207 #if HAVE_SUBWINDOWS
205 case IMAGE_SUBWINDOW: 208 case IMAGE_SUBWINDOW:
206 /* #### implement me */ 209 /* #### implement me */
210 #endif
207 break; 211 break;
208 default: 212 default:
209 break; 213 break;
210 } 214 }
211 215
219 { 223 {
220 case IMAGE_MONO_PIXMAP: 224 case IMAGE_MONO_PIXMAP:
221 case IMAGE_COLOR_PIXMAP: 225 case IMAGE_COLOR_PIXMAP:
222 case IMAGE_POINTER: 226 case IMAGE_POINTER:
223 return IMAGE_INSTANCE_X_NPIXELS (p); 227 return IMAGE_INSTANCE_X_NPIXELS (p);
228 #if HAVE_SUBWINDOWS
224 case IMAGE_SUBWINDOW: 229 case IMAGE_SUBWINDOW:
225 /* #### implement me */ 230 /* #### implement me */
231 #endif
226 return 0; 232 return 0;
227 default: 233 default:
228 return 0; 234 return 0;
229 } 235 }
230 } 236 }
1051 1057
1052 #include "jpeglib.h" 1058 #include "jpeglib.h"
1053 #include "jerror.h" 1059 #include "jerror.h"
1054 1060
1055 /* The in-core jpeg code doesn't work, so I'm avoiding it for now. -sb */ 1061 /* The in-core jpeg code doesn't work, so I'm avoiding it for now. -sb */
1056 #define USE_TEMP_FILES_FOR_JPEG_IMAGES 1 1062 /* Late-breaking update, we're going to give it a try, I think it's */
1063 /* fixed now -sb */
1064 /*#define USE_TEMP_FILES_FOR_JPEG_IMAGES 1*/
1057 #define USE_TEMP_FILES_FOR_PNG_IMAGES 1 1065 #define USE_TEMP_FILES_FOR_PNG_IMAGES 1
1058 1066
1059 static void 1067 static void
1060 jpeg_validate (Lisp_Object instantiator) 1068 jpeg_validate (Lisp_Object instantiator)
1061 { 1069 {
1173 METHODDEF(boolean) 1181 METHODDEF(boolean)
1174 #else 1182 #else
1175 METHODDEF boolean 1183 METHODDEF boolean
1176 #endif 1184 #endif
1177 our_fill_input_buffer (j_decompress_ptr cinfo) { 1185 our_fill_input_buffer (j_decompress_ptr cinfo) {
1178 ERREXIT(cinfo,JERR_INPUT_EOF); 1186 /* Insert a fake EOI marker */
1179 return FALSE; 1187 struct jpeg_source_mgr *src = (struct jpeg_source_mgr *) cinfo->src;
1188 static JOCTET buffer[2];
1189
1190 buffer[0] = (JOCTET) 0xFF;
1191 buffer[1] = (JOCTET) JPEG_EOI;
1192
1193 src->next_input_byte = buffer;
1194 src->bytes_in_buffer = 2;
1195 return TRUE;
1180 } 1196 }
1181 1197
1182 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) 1198 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
1183 METHODDEF(void) 1199 METHODDEF(void)
1184 #else 1200 #else
1185 METHODDEF void 1201 METHODDEF void
1186 #endif 1202 #endif
1187 our_skip_input_data (j_decompress_ptr cinfo, long num_bytes) { 1203 our_skip_input_data (j_decompress_ptr cinfo, long num_bytes) {
1204 struct jpeg_source_mgr *src = NULL;
1205
1206 src = (struct jpeg_source_mgr *) cinfo->src;
1207
1208 if (!src) {
1209 return;
1210 } else if (num_bytes > src->bytes_in_buffer) {
1211 ERREXIT(cinfo, JERR_INPUT_EOF);
1212 /*NOTREACHED*/
1213 }
1214
1215 src->bytes_in_buffer -= num_bytes;
1216 src->next_input_byte += num_bytes;
1188 } 1217 }
1189 1218
1190 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) 1219 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
1191 METHODDEF(void) 1220 METHODDEF(void)
1192 #else 1221 #else
1197 1226
1198 typedef struct { 1227 typedef struct {
1199 struct jpeg_source_mgr pub; 1228 struct jpeg_source_mgr pub;
1200 } our_jpeg_source_mgr; 1229 } our_jpeg_source_mgr;
1201 1230
1202 static void jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, 1231 static void
1203 unsigned int len) 1232 jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, unsigned int len)
1204 { 1233 {
1205 struct jpeg_source_mgr *src = NULL; 1234 struct jpeg_source_mgr *src = NULL;
1206 1235
1207 if (cinfo->src == NULL) { /* first time for this JPEG object? */ 1236 if (cinfo->src == NULL) { /* first time for this JPEG object? */
1208 cinfo->src = (struct jpeg_source_mgr *) 1237 cinfo->src = (struct jpeg_source_mgr *)
1603 } 1632 }
1604 1633
1605 return Qnil; 1634 return Qnil;
1606 } 1635 }
1607 1636
1637 #if 0
1608 /* We provide our own version of DGifSlurp() because the standardly 1638 /* We provide our own version of DGifSlurp() because the standardly
1609 provided one doesn't handle interlaced GIFs. This is based on 1639 provided one doesn't handle interlaced GIFs. This is based on
1610 code in gif2x11.c. */ 1640 code in gif2x11.c. */
1611 1641
1612 /* Return value is GIF_ERROR, GIF_OK, or -1. 1642 /* Return value is GIF_ERROR, GIF_OK, or -1.
1709 1739
1710 done: 1740 done:
1711 1741
1712 return GIF_OK; 1742 return GIF_OK;
1713 } 1743 }
1744 #endif
1714 1745
1715 static void 1746 static void
1716 gif_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 1747 gif_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1717 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 1748 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1718 int dest_mask) 1749 int dest_mask)
1758 { 1789 {
1759 gif_decode_error: 1790 gif_decode_error:
1760 signal_simple_error ("Unable to decode GIF", 1791 signal_simple_error ("Unable to decode GIF",
1761 build_string (EmacsPrintGifError ())); 1792 build_string (EmacsPrintGifError ()));
1762 } 1793 }
1763 #if 1 1794 #if 0
1764 if (our_own_dgif_slurp_from_gif2x11_c(unwind.giffile) != GIF_OK) 1795 if (our_own_dgif_slurp_from_gif2x11_c(unwind.giffile) != GIF_OK)
1765 #else 1796 #else
1766 /* DGifSlurp() doesn't handle interlaced files. */ 1797 /* DGifSlurp() doesn't handle interlaced files. */
1798 /* Actually, it does, sort of. It just sets the Interlace flag
1799 and stores RasterBits in interlaced order. We handle that below. */
1767 if (DGifSlurp (unwind.giffile) != GIF_OK) 1800 if (DGifSlurp (unwind.giffile) != GIF_OK)
1768 #endif 1801 #endif
1769 goto gif_decode_error; 1802 goto gif_decode_error;
1770 } 1803 }
1771 1804
1800 { 1833 {
1801 int height = unwind.giffile->SHeight; 1834 int height = unwind.giffile->SHeight;
1802 int width = unwind.giffile->SWidth; 1835 int width = unwind.giffile->SWidth;
1803 int depth; 1836 int depth;
1804 int bitmap_pad; 1837 int bitmap_pad;
1805 int i, j; 1838 int i, j, row, pass, interlace;
1839 /* interlaced gifs have rows in this order:
1840 0, 8, 16, ..., 4, 12, 20, ..., 2, 6, 10, ..., 1, 3, 5, ... */
1841 static int InterlacedOffset[] = { 0, 4, 2, 1 };
1842 static int InterlacedJumps[] = { 8, 8, 4, 2 };
1843
1806 1844
1807 depth = DefaultDepthOfScreen (scr); 1845 depth = DefaultDepthOfScreen (scr);
1808 1846
1809 /* first get bitmap_pad (from XPM) */ 1847 /* first get bitmap_pad (from XPM) */
1810 if (depth > 16) 1848 if (depth > 16)
1833 long run, what with all the XPM overhead. If this proves 1871 long run, what with all the XPM overhead. If this proves
1834 to be a bottleneck here, maybe we should just copy the 1872 to be a bottleneck here, maybe we should just copy the
1835 optimization routines from XPM (they're in turn mostly 1873 optimization routines from XPM (they're in turn mostly
1836 copied from the Xlib source code). */ 1874 copied from the Xlib source code). */
1837 1875
1876 /* Note: We just use the first image in the file and ignore the rest.
1877 We check here that that image covers the full "screen" size.
1878 I don't know whether that's always the case.
1879 -dkindred@cs.cmu.edu */
1880 if (unwind.giffile->SavedImages[0].ImageDesc.Height != height
1881 || unwind.giffile->SavedImages[0].ImageDesc.Width != width
1882 || unwind.giffile->SavedImages[0].ImageDesc.Left != 0
1883 || unwind.giffile->SavedImages[0].ImageDesc.Top != 0)
1884 signal_simple_error ("First image in GIF file is not full size",
1885 instantiator);
1886
1887 interlace = unwind.giffile->SavedImages[0].ImageDesc.Interlace;
1888 pass = 0;
1889 row = interlace ? InterlacedOffset[pass] : 0;
1838 for (i = 0; i < height; i++) 1890 for (i = 0; i < height; i++)
1839 for (j = 0; j < width; j++) 1891 {
1840 XPutPixel (unwind.ximage, j, i, 1892 if (interlace && row >= height)
1841 unwind.pixels[(unsigned char) 1893 row = InterlacedOffset[++pass];
1842 /* incorrect signed declaration 1894
1843 of RasterBits[] */ 1895 for (j = 0; j < width; j++)
1844 (unwind.giffile->SavedImages-> 1896 XPutPixel (unwind.ximage, j, row,
1845 RasterBits[i * width + j])]); 1897 unwind.pixels[(unsigned char)
1898 /* incorrect signed declaration
1899 of RasterBits[] */
1900 (unwind.giffile->SavedImages[0].
1901 RasterBits[i * width + j])]);
1902
1903 row += interlace ? InterlacedJumps[pass] : 1;
1904 }
1846 } 1905 }
1847 1906
1848 /* 4. Now create the pixmap and set up the image instance */ 1907 /* 4. Now create the pixmap and set up the image instance */
1849 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask, 1908 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask,
1850 unwind.pixels, unwind.npixels, 1909 unwind.pixels, unwind.npixels,
3431 return 1; 3490 return 1;
3432 } 3491 }
3433 } 3492 }
3434 3493
3435 3494
3495 #if HAVE_SUBWINDOWS
3436 /************************************************************************/ 3496 /************************************************************************/
3437 /* subwindows */ 3497 /* subwindows */
3438 /************************************************************************/ 3498 /************************************************************************/
3439 3499
3440 Lisp_Object Qsubwindowp; 3500 Lisp_Object Qsubwindowp;
3706 XMapWindow (DisplayOfScreen (XSUBWINDOW (subwindow)->xscreen), 3766 XMapWindow (DisplayOfScreen (XSUBWINDOW (subwindow)->xscreen),
3707 XSUBWINDOW (subwindow)->subwindow); 3767 XSUBWINDOW (subwindow)->subwindow);
3708 3768
3709 return subwindow; 3769 return subwindow;
3710 } 3770 }
3711 3771 #endif
3712 3772
3713 /************************************************************************/ 3773 /************************************************************************/
3714 /* initialization */ 3774 /* initialization */
3715 /************************************************************************/ 3775 /************************************************************************/
3716 3776
3717 void 3777 void
3718 syms_of_glyphs_x (void) 3778 syms_of_glyphs_x (void)
3719 { 3779 {
3780 #if HAVE_SUBWINDOWS
3720 defsymbol (&Qsubwindowp, "subwindowp"); 3781 defsymbol (&Qsubwindowp, "subwindowp");
3721 3782
3722 DEFSUBR (Fmake_subwindow); 3783 DEFSUBR (Fmake_subwindow);
3723 DEFSUBR (Fchange_subwindow_property); 3784 DEFSUBR (Fchange_subwindow_property);
3724 DEFSUBR (Fsubwindowp); 3785 DEFSUBR (Fsubwindowp);
3725 DEFSUBR (Fsubwindow_width); 3786 DEFSUBR (Fsubwindow_width);
3726 DEFSUBR (Fsubwindow_height); 3787 DEFSUBR (Fsubwindow_height);
3727 DEFSUBR (Fsubwindow_xid); 3788 DEFSUBR (Fsubwindow_xid);
3728 DEFSUBR (Fresize_subwindow); 3789 DEFSUBR (Fresize_subwindow);
3729 DEFSUBR (Fforce_subwindow_map); 3790 DEFSUBR (Fforce_subwindow_map);
3791 #endif
3730 3792
3731 defkeyword (&Q_mask_file, ":mask-file"); 3793 defkeyword (&Q_mask_file, ":mask-file");
3732 defkeyword (&Q_mask_data, ":mask-data"); 3794 defkeyword (&Q_mask_data, ":mask-data");
3733 defkeyword (&Q_hotspot_x, ":hotspot-x"); 3795 defkeyword (&Q_hotspot_x, ":hotspot-x");
3734 defkeyword (&Q_hotspot_y, ":hotspot-y"); 3796 defkeyword (&Q_hotspot_y, ":hotspot-y");