X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fxanalogtv.c;h=80cc7d91734d8ad29eb6b350e69b3ed3fea0eebd;hb=c85f503f5793839a6be4c818332aca4a96927bb2;hp=589d475cd26942edeceead53bd2e05f6972c135a;hpb=5f9c47ca98dd43d8f59b7c27d3fde6edfde4fe21;p=xscreensaver diff --git a/hacks/xanalogtv.c b/hacks/xanalogtv.c index 589d475c..80cc7d91 100644 --- a/hacks/xanalogtv.c +++ b/hacks/xanalogtv.c @@ -1,4 +1,4 @@ -/* xanalogtv, Copyright (c) 2003 Trevor Blackwell +/* xanalogtv, Copyright (c) 2003-2018 Trevor Blackwell * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -18,10 +18,6 @@ * pictures from your images directory, some show color bars, and some * just have static. Some channels receive two stations simultaneously * so you see a ghostly, misaligned image. - * - * It's easy to add some test patterns by compiling in an XPM, but I - * can't find any that are clearly freely redistributable. - * */ #ifdef HAVE_CONFIG_H @@ -34,18 +30,24 @@ # include #endif -#ifndef HAVE_COCOA +#ifndef HAVE_JWXYZ # include /* for XtDatabase in hack_resources() */ #endif #include "screenhack.h" -#include "xpm-pixmap.h" +#include "ximage-loader.h" #include "analogtv.h" -#include "images/logo-50.xpm" +#define USE_TEST_PATTERNS + +#include "images/gen/logo-180_png.h" + +#ifdef USE_TEST_PATTERNS +# include "images/gen/testcard_rca_png.h" +# include "images/gen/testcard_pm5544_png.h" +# include "images/gen/testcard_bbcf_png.h" +#endif -/* #define DEBUG 1 */ -/* #define USE_TEST_PATTERNS */ #define countof(x) (sizeof((x))/sizeof((*x))) @@ -75,6 +77,10 @@ struct state { int n_stations; analogtv_input *stations[MAX_STATIONS]; Bool image_loading_p; + XImage *logo, *logo_mask; +# ifdef USE_TEST_PATTERNS + XImage *test_patterns[MAX_STATIONS]; +# endif int curinputi; int change_ticks; @@ -82,7 +88,7 @@ struct state { chansetting *cs; int change_now; - + int colorbars_only_p; }; @@ -155,12 +161,18 @@ update_smpte_colorbars(analogtv_input *input) ypos=ANALOGTV_V/5; xpos=ANALOGTV_VIS_START + ANALOGTV_VIS_LEN/2; + /* if (! st->colorbars_only_p) */ { char localname[256]; if (gethostname (localname, sizeof (localname))==0) { + int L; localname[sizeof(localname)-1]=0; /* "The returned name is null- terminated unless insufficient space is provided" */ + L = strlen(localname); + if (L > 6 && !strcmp(".local", localname+L-6)) + localname[L-6] = 0; + localname[24]=0; /* limit length */ analogtv_draw_string_centered(input, &st->ugly_font, localname, @@ -169,8 +181,15 @@ update_smpte_colorbars(analogtv_input *input) } ypos += st->ugly_font.char_h*5/2; - analogtv_draw_xpm(st->tv, input, - logo_50_xpm, xpos - 100, ypos); + if (st->logo) + { + int w2 = st->tv->xgwa.width * 0.2; + int h2 = st->tv->xgwa.height * 0.2; + analogtv_load_ximage (st->tv, input, st->logo, st->logo_mask, + (st->tv->xgwa.width - w2) / 2, + st->tv->xgwa.height * 0.28, + w2, h2); + } ypos += 58; @@ -180,6 +199,7 @@ update_smpte_colorbars(analogtv_input *input) ypos += st->ugly_font.char_h*4; #endif + /* if (! st->colorbars_only_p) */ { char timestamp[256]; time_t t = time ((time_t *) 0); @@ -196,72 +216,6 @@ update_smpte_colorbars(analogtv_input *input) input->next_update_time += 1.0; } -#if 0 -static void -draw_color_square(analogtv_input *input) -{ - double xs,ys; - - analogtv_draw_solid_rel_lcp(input, 0.0, 1.0, 0.0, 1.0, - 30.0, 0.0, 0.0); - - for (xs=0.0; xs<0.9999; xs+=1.0/15.0) { - analogtv_draw_solid_rel_lcp(input, xs, xs, 0.0, 1.0, - 100.0, 0.0, 0.0); - } - - for (ys=0.0; ys<0.9999; ys+=1.0/11.0) { - analogtv_draw_solid_rel_lcp(input, 0.0, 1.0, ys, ys, - 100.0, 0.0, 0.0); - } - - for (ys=0.0; ys<0.9999; ys+=0.01) { - - analogtv_draw_solid_rel_lcp(input, 0.0/15, 1.0/15, ys, ys+0.01, - 40.0, 45.0, 103.5*(1.0-ys) + 347.0*ys); - - analogtv_draw_solid_rel_lcp(input, 14.0/15, 15.0/15, ys, ys+0.01, - 40.0, 45.0, 103.5*(ys) + 347.0*(1.0-ys)); - } - - for (ys=0.0; ys<0.9999; ys+=0.02) { - analogtv_draw_solid_rel_lcp(input, 1.0/15, 2.0/15, ys*2.0/11.0+1.0/11.0, - (ys+0.01)*2.0/11.0+1.0/11.0, - 100.0*(1.0-ys), 0.0, 0.0); - } - - -} -#endif - -static const char *xanalogtv_defaults [] = { - ".background: black", - ".foreground: white", - "*delay: 5", - "*grabDesktopImages: False", /* HAVE_COCOA */ - "*chooseRandomImages: True", /* HAVE_COCOA */ - ANALOGTV_DEFAULTS - 0, -}; - -static XrmOptionDescRec xanalogtv_options [] = { - { "-delay", ".delay", XrmoptionSepArg, 0 }, - ANALOGTV_OPTIONS - { 0, 0, 0, 0 } -}; - - -#ifdef USE_TEST_PATTERNS - -#include "images/earth.xpm" - -char **test_patterns[] = { - earth_xpm, -}; - -#endif - - static int getticks(struct state *st) { @@ -281,7 +235,7 @@ getticks(struct state *st) static void hack_resources (Display *dpy) { -#ifndef HAVE_COCOA +#ifndef HAVE_JWXYZ static int count = -1; count++; @@ -301,7 +255,7 @@ hack_resources (Display *dpy) value.size = strlen(buf2); XrmPutResource (&db, buf1, "String", &value); } -#endif /* HAVE_COCOA */ +#endif /* HAVE_JWXYZ */ } @@ -342,7 +296,7 @@ static void image_loaded_cb (Screen *screen, Window window, Drawable pixmap, XFreePixmap(st->dpy, pixmap); analogtv_setup_sync(input, 1, (random()%20)==0); - analogtv_load_ximage(st->tv, input, image); + analogtv_load_ximage(st->tv, input, image, 0, 0, 0, 0, 0); if (image) XDestroyImage(image); st->chansettings[this].image_loaded_p = True; #if 0 @@ -384,26 +338,6 @@ analogtv_load_random_image(struct state *st) } -#if 0 -static int -analogtv_load_xpm(analogtv *it, analogtv_input *input, char **xpm) -{ - Pixmap pixmap; - XImage *image; - int width,height; - int rc; - - pixmap=xpm_data_to_pixmap (it->dpy, it->window, xpm, - &width, &height, NULL); - image = XGetImage(it->dpy, pixmap, 0, 0, width, height, ~0L, ZPixmap); - XFreePixmap(it->dpy, pixmap); - rc=analogtv_load_ximage(it, input, image); - if (image) XDestroyImage(image); - return rc; -} -#endif - - static void add_stations(struct state *st) { while (st->n_stations < MAX_STATIONS) { @@ -421,15 +355,20 @@ static void load_station_images(struct state *st) analogtv_input *input = st->stations[i]; st->chansettings[i].image_loaded_p = True; - if (i == 0) { /* station 0 is always colorbars */ + if (i == 0 || /* station 0 is always colorbars */ + st->colorbars_only_p) { input->updater = update_smpte_colorbars; input->do_teletext=1; } #ifdef USE_TEST_PATTERNS else if (random()%5==0) { - j=random()%countof(test_patterns); - analogtv_setup_sync(input); - analogtv_load_xpm(tv, input, test_patterns[j]); + int count = 0, j; + for (count = 0; st->test_patterns[count]; count++) + ; + j=random()%count; + analogtv_setup_sync(input, 1, 0); + analogtv_load_ximage(st->tv, input, st->test_patterns[j], + 0, 0, 0, 0, 0); analogtv_setup_teletext(input); } #endif @@ -449,6 +388,7 @@ xanalogtv_init (Display *dpy, Window window) int i; int last_station=42; int delay = get_integer_resource(dpy, "delay", "Integer"); + if (delay < 1) delay = 1; analogtv_make_font(dpy, window, &st->ugly_font, 7, 10, "6x10"); @@ -457,6 +397,51 @@ xanalogtv_init (Display *dpy, Window window) st->window = window; st->tv=analogtv_allocate(dpy, window); + st->colorbars_only_p = + get_boolean_resource(dpy, "colorbarsOnly", "ColorbarsOnly"); + + /* if (!st->colorbars_only_p) */ + { + int w, h; + Pixmap mask = 0; + Pixmap p = image_data_to_pixmap (dpy, window, + logo_180_png, sizeof(logo_180_png), + &w, &h, &mask); + st->logo = XGetImage (dpy, p, 0, 0, w, h, ~0L, ZPixmap); + XFreePixmap (dpy, p); + if (mask) + { + st->logo_mask = XGetImage (dpy, mask, 0, 0, w, h, ~0L, ZPixmap); + XFreePixmap (dpy, mask); + } + } + +# ifdef USE_TEST_PATTERNS + { + int i = 0; + int w, h; + Pixmap p; + p = image_data_to_pixmap (dpy, window, + testcard_rca_png, sizeof(testcard_rca_png), + &w, &h, 0); + st->test_patterns[i++] = XGetImage (dpy, p, 0, 0, w, h, ~0L, ZPixmap); + XFreePixmap (dpy, p); + + p = image_data_to_pixmap (dpy, window, + testcard_pm5544_png, sizeof(testcard_pm5544_png), + &w, &h, 0); + st->test_patterns[i++] = XGetImage (dpy, p, 0, 0, w, h, ~0L, ZPixmap); + XFreePixmap (dpy, p); + + p = image_data_to_pixmap (dpy, window, + testcard_bbcf_png, sizeof(testcard_bbcf_png), + &w, &h, 0); + st->test_patterns[i++] = XGetImage (dpy, p, 0, 0, w, h, ~0L, ZPixmap); + XFreePixmap (dpy, p); + } +# endif /* USE_TEST_PATTERNS */ + + add_stations(st); analogtv_set_defaults(st->tv, ""); @@ -531,10 +516,14 @@ xanalogtv_draw (Display *dpy, Window window, void *closure) int curticks=getticks(st); double curtime=curticks*0.001; - if (st->change_now || - (curticks >= st->change_ticks && st->tv->powerup > 10.0)) { + const analogtv_reception *recs[MAX_MULTICHAN]; + unsigned rec_count = 0; + + int auto_change = curticks >= st->change_ticks && st->tv->powerup > 10.0 ? 1 : 0; + + if (st->change_now || auto_change) { + st->curinputi=(st->curinputi+st->change_now+auto_change+N_CHANNELS)%N_CHANNELS; st->change_now = 0; - st->curinputi=(st->curinputi+1)%N_CHANNELS; st->cs = &st->chansettings[st->curinputi]; #if 0 fprintf (stderr, "%s: channel %d, %s\n", progname, st->curinputi, @@ -559,17 +548,21 @@ xanalogtv_draw (Display *dpy, Window window, void *closure) st->tv->powerup=curtime; - analogtv_init_signal(st->tv, st->cs->noise_level); for (i=0; ics->recs[i]; - analogtv_input *inp=rec->input; - if (!inp) continue; - - analogtv_reception_update(rec); - analogtv_add_signal(st->tv, rec); + if (rec->input) { + analogtv_reception_update(rec); + recs[rec_count] = rec; + ++rec_count; + } } - analogtv_draw(st->tv); - return 10000; + analogtv_draw(st->tv, st->cs->noise_level, recs, rec_count); + +#ifdef HAVE_MOBILE + return 0; +#else + return 5000; +#endif } static void @@ -587,7 +580,8 @@ xanalogtv_event (Display *dpy, Window window, void *closure, XEvent *event) if (event->type == ButtonPress) { - st->change_now = 1; + unsigned button = event->xbutton.button; + st->change_now = button == 2 || button == 3 || button == 5 ? -1 : 1; return True; } else if (event->type == KeyPress) @@ -595,11 +589,26 @@ xanalogtv_event (Display *dpy, Window window, void *closure, XEvent *event) KeySym keysym; char c = 0; XLookupString (&event->xkey, &c, 1, &keysym, 0); - if (c == ' ' || c == '\t' || c == '\r' || c == '\n') + if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || + keysym == XK_Up || keysym == XK_Right || keysym == XK_Prior) { st->change_now = 1; return True; } + else if (c == '\b' || + keysym == XK_Down || keysym == XK_Left || keysym == XK_Next) + { + st->change_now = -1; + return True; + } + else if (screenhack_event_helper (dpy, window, event)) + goto DEF; + } + else if (screenhack_event_helper (dpy, window, event)) + { + DEF: + st->change_now = ((random() & 1) ? 1 : -1); + return True; } return False; @@ -610,8 +619,36 @@ xanalogtv_free (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; analogtv_release(st->tv); + if (st->logo) XDestroyImage (st->logo); + if (st->logo_mask) XDestroyImage (st->logo_mask); +# ifdef USE_TEST_PATTERNS + { + int i; + for (i = 0; i < countof(st->test_patterns); i++) + if (st->test_patterns[i]) XDestroyImage (st->test_patterns[i]); + } +# endif free (st); } +static const char *xanalogtv_defaults [] = { + ".background: black", + ".foreground: white", + "*delay: 5", + "*grabDesktopImages: False", /* HAVE_JWXYZ */ + "*chooseRandomImages: True", /* HAVE_JWXYZ */ + "*colorbarsOnly: False", + ANALOGTV_DEFAULTS + 0, +}; + +static XrmOptionDescRec xanalogtv_options [] = { + { "-delay", ".delay", XrmoptionSepArg, 0 }, + { "-colorbars-only", ".colorbarsOnly", XrmoptionNoArg, "True" }, + ANALOGTV_OPTIONS + { 0, 0, 0, 0 } +}; + + XSCREENSAVER_MODULE ("XAnalogTV", xanalogtv)