30 |
|
#include "pic.h" |
31 |
|
#include "x11raster.h" |
32 |
|
#include "random.h" |
33 |
– |
#include "x11icon.h" |
33 |
|
|
34 |
|
#define FONTNAME "8x13" /* text font we'll use */ |
35 |
|
|
37 |
|
|
38 |
|
#define BORWIDTH 5 /* border width */ |
39 |
|
|
40 |
+ |
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
41 |
+ |
|
42 |
|
#define ourscreen DefaultScreen(thedisplay) |
43 |
|
#define ourblack BlackPixel(thedisplay,ourscreen) |
44 |
|
#define ourwhite WhitePixel(thedisplay,ourscreen) |
81 |
|
|
82 |
|
int wrongformat = 0; /* input in another format? */ |
83 |
|
|
84 |
+ |
int imready = 0; /* is image up? */ |
85 |
+ |
|
86 |
|
GC revgc; /* graphics context with GXinvert */ |
87 |
|
|
88 |
|
XRASTER *ourras; /* our stored image */ |
94 |
|
|
95 |
|
char *geometry = NULL; /* geometry specification */ |
96 |
|
|
97 |
+ |
char icondata[ICONSIZ*ICONSIZ/8]; /* icon bitmap data */ |
98 |
+ |
int iconwidth = 0, iconheight = 0; |
99 |
+ |
|
100 |
|
char *progname; |
101 |
|
|
102 |
|
char errmsg[128]; |
248 |
|
XSetFont(thedisplay, ourgc, fontid); |
249 |
|
revgc = XCreateGC(thedisplay, wind, 0, 0); |
250 |
|
XSetFunction(thedisplay, revgc, GXinvert); |
245 |
– |
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
251 |
|
XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, |
252 |
|
XC_diamond_cross)); |
253 |
|
if (geometry != NULL) { |
276 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
277 |
|
ourxwmhints.input = True; |
278 |
|
ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, |
279 |
< |
wind, x11icon_bits, x11icon_width, x11icon_height); |
279 |
> |
wind, icondata, iconwidth, iconheight); |
280 |
|
XSetWMHints(thedisplay, wind, &ourxwmhints); |
281 |
|
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
282 |
|
|ButtonMotionMask|StructureNotifyMask |
283 |
|
|KeyPressMask|ExposureMask); |
284 |
|
XMapWindow(thedisplay, wind); |
285 |
+ |
/* make sure the image is up */ |
286 |
+ |
do |
287 |
+ |
getevent(); |
288 |
+ |
while (!imready); |
289 |
+ |
/* store name as ready signal */ |
290 |
+ |
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
291 |
|
return; |
292 |
|
memerr: |
293 |
|
quiterr("out of memory"); |
394 |
|
break; |
395 |
|
case Expose: |
396 |
|
redraw(e.e.x, e.e.y, e.e.width, e.e.height); |
397 |
+ |
imready++; |
398 |
|
break; |
399 |
|
case ButtonPress: |
400 |
|
if (e.b.state & (ShiftMask|ControlMask)) |
639 |
|
if (getscan(y) < 0) |
640 |
|
quiterr("seek error in getmono"); |
641 |
|
normcolrs(scanline, xmax, scale); |
642 |
+ |
add2icon(y, scanline); |
643 |
|
err = 0; |
644 |
|
for (x = 0; x < xmax; x++) { |
645 |
|
if (!(x&7)) |
656 |
|
} |
657 |
|
|
658 |
|
|
659 |
+ |
add2icon(y, scan) /* add a scanline to our icon data */ |
660 |
+ |
int y; |
661 |
+ |
COLR *scan; |
662 |
+ |
{ |
663 |
+ |
static short cerr[ICONSIZ]; |
664 |
+ |
static int ynext; |
665 |
+ |
static char *dp; |
666 |
+ |
register int err; |
667 |
+ |
register int x, ti; |
668 |
+ |
|
669 |
+ |
if (iconheight == 0) { /* initialize */ |
670 |
+ |
if (xmax <= ICONSIZ && ymax <= ICONSIZ) { |
671 |
+ |
iconwidth = xmax; |
672 |
+ |
iconheight = ymax; |
673 |
+ |
} else if (xmax > ymax) { |
674 |
+ |
iconwidth = ICONSIZ; |
675 |
+ |
iconheight = ICONSIZ*ymax/xmax; |
676 |
+ |
} else { |
677 |
+ |
iconwidth = ICONSIZ*xmax/ymax; |
678 |
+ |
iconheight = ICONSIZ; |
679 |
+ |
} |
680 |
+ |
ynext = 0; |
681 |
+ |
dp = icondata - 1; |
682 |
+ |
} |
683 |
+ |
if (y < ynext*ymax/iconheight) /* skip this one */ |
684 |
+ |
return; |
685 |
+ |
err = 0; |
686 |
+ |
for (x = 0; x < iconwidth; x++) { |
687 |
+ |
if (!(x&7)) |
688 |
+ |
*++dp = 0; |
689 |
+ |
ti = x*xmax/iconwidth; |
690 |
+ |
err += normbright(scan[ti]) + cerr[x]; |
691 |
+ |
if (err > 127) |
692 |
+ |
err -= 255; |
693 |
+ |
else |
694 |
+ |
*dp |= 1<<(x&07); |
695 |
+ |
cerr[x] = err >>= 1; |
696 |
+ |
} |
697 |
+ |
ynext++; |
698 |
+ |
} |
699 |
+ |
|
700 |
+ |
|
701 |
|
getfull() /* get full (24-bit) data */ |
702 |
|
{ |
703 |
|
int y; |
713 |
|
if (scale) |
714 |
|
shiftcolrs(scanline, xmax, scale); |
715 |
|
colrs_gambs(scanline, xmax); |
716 |
+ |
add2icon(y, scanline); |
717 |
|
for (x = 0; x < xmax; x++) { |
718 |
|
*dp++ = scanline[x][RED]; |
719 |
|
*dp++ = scanline[x][GRN]; |
781 |
|
quiterr("cannot seek for picreadline"); |
782 |
|
/* convert scanline */ |
783 |
|
normcolrs(scanline, xmax, scale); |
784 |
+ |
add2icon(y, scanline); |
785 |
|
for (i = 0; i < xmax; i++) { |
786 |
|
l3[i].r = scanline[i][RED]; |
787 |
|
l3[i].g = scanline[i][GRN]; |