-
-
-static const char hextonib[128] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,
- 0, 10,11,12,13,14,15,0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 10,11,12,13,14,15,0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
-/*
- Much of this function was adapted from logo.c
- */
-void
-analogtv_draw_xpm(analogtv *tv, analogtv_input *input,
- const char * const *xpm, int left, int top)
-{
- int xpmw,xpmh;
- int x,y,tvx,tvy,i;
- int rawy,rawi,rawq;
- int ncolors, nbytes;
- char dummyc;
- struct {
- int r; int g; int b;
- } cmap[256];
-
-
- if (4 != sscanf ((const char *) *xpm,
- "%d %d %d %d %c",
- &xpmw, &xpmh, &ncolors, &nbytes, &dummyc))
- abort();
- if (ncolors < 1 || ncolors > 255)
- abort();
- if (nbytes != 1) /* a serious limitation */
- abort();
- xpm++;
-
- for (i = 0; i < ncolors; i++) {
- const char *line = *xpm;
- int colori = ((unsigned char)*line++)&0xff;
- while (*line)
- {
- int r, g, b;
- char which;
- while (*line == ' ' || *line == '\t')
- line++;
- which = *line++;
- if (which != 'c' && which != 'm')
- abort();
- while (*line == ' ' || *line == '\t')
- line++;
- if (!strncasecmp(line, "None", 4))
- {
- r = g = b = -1;
- line += 4;
- }
- else
- {
- if (*line == '#')
- line++;
- r = (hextonib[(int) line[0]] << 4) | hextonib[(int) line[1]];
- line += 2;
- g = (hextonib[(int) line[0]] << 4) | hextonib[(int) line[1]];
- line += 2;
- b = (hextonib[(int) line[0]] << 4) | hextonib[(int) line[1]];
- line += 2;
- }
-
- if (which == 'c')
- {
- cmap[colori].r = r;
- cmap[colori].g = g;
- cmap[colori].b = b;
- }
- }
-
- xpm++;
- }
-
- for (y=0; y<xpmh; y++) {
- const char *line = *xpm++;
- tvy=y+top;
- if (tvy<ANALOGTV_TOP || tvy>=ANALOGTV_BOT) continue;
-
- for (x=0; x<xpmw; x++) {
- int cbyte=((unsigned char)line[x])&0xff;
- int ntsc[4];
- tvx=x*4+left;
- if (tvx<ANALOGTV_PIC_START || tvx+4>ANALOGTV_PIC_END) continue;
-
- rawy=( 5*cmap[cbyte].r + 11*cmap[cbyte].g + 2*cmap[cbyte].b) / 64;
- rawi=(10*cmap[cbyte].r - 4*cmap[cbyte].g - 5*cmap[cbyte].b) / 64;
- rawq=( 3*cmap[cbyte].r - 8*cmap[cbyte].g + 5*cmap[cbyte].b) / 64;
-
- ntsc[0]=rawy+rawq;
- ntsc[1]=rawy-rawi;
- ntsc[2]=rawy-rawq;
- ntsc[3]=rawy+rawi;
-
- for (i=0; i<4; i++) {
- if (ntsc[i]>ANALOGTV_WHITE_LEVEL) ntsc[i]=ANALOGTV_WHITE_LEVEL;
- if (ntsc[i]<ANALOGTV_BLACK_LEVEL) ntsc[i]=ANALOGTV_BLACK_LEVEL;
- }
-
- input->signal[tvy][tvx+0]= ntsc[(tvx+0)&3];
- input->signal[tvy][tvx+1]= ntsc[(tvx+1)&3];
- input->signal[tvy][tvx+2]= ntsc[(tvx+2)&3];
- input->signal[tvy][tvx+3]= ntsc[(tvx+3)&3];
- }
- }
-}
-
-extern XtAppContext app;
-
-int
-analogtv_handle_events (analogtv *it)
-{
- XSync(it->dpy, False);
- if (XtAppPending (app) & (XtIMTimer|XtIMAlternateInput))
- XtAppProcessEvent (app, XtIMTimer|XtIMAlternateInput);
-
- while (XPending (it->dpy))
- {
- XEvent event;
- XNextEvent (it->dpy, &event);
- switch (event.xany.type)
- {
- case ButtonPress:
- return 1;
-
- case KeyPress:
- {
- KeySym keysym;
- char c = 0;
-
- if (it->key_handler) {
- if (it->key_handler (it->dpy, &event, it->key_data))
- return 1;
- } else {
- XLookupString (&event.xkey, &c, 1, &keysym, 0);
- if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
- return 1;
- }
- }
- break;
-
- /* I don't seem to get an event when clicking the "full
- screen" window manager icon, at least when using
- metacity. Thus, it doesn't change the video size. Is this
- some separate WM_* message I have to deal with?
- */
- case ConfigureNotify:
- if (event.xconfigure.width != it->xgwa.width ||
- event.xconfigure.height != it->xgwa.height)
- analogtv_reconfigure(it);
- break;
-
- case Expose:
- case GraphicsExpose:
- it->need_clear=1;
- break;
-
- default:
- break;
- }
- if (it->event_handler) {
- (*it->event_handler) (it->dpy, &event);
- }
- }
- return 0;
-}
-