+ whlp_text(h, "This third topic is not nearly as boring as the first, "
+ "because it has a picture: ");
+ {
+#ifndef PICTURE_FROM_CMDLINE
+ const unsigned long palette[] = {
+ 0xFF0000,
+ 0xFFFF00,
+ 0x00FF00,
+ 0x00FFFF,
+ 0x0000FF,
+ };
+ const unsigned char picture[] = {
+ 0, 0, 0, 0, 1, 2, 3, 4,
+ 0, 0, 0, 0, 1, 2, 3, 4,
+ 0, 0, 0, 0, 1, 2, 3, 4,
+ 0, 0, 0, 1, 2, 3, 4, 4,
+ 0, 0, 0, 1, 2, 3, 4, 4,
+ 0, 0, 0, 1, 2, 3, 4, 4,
+ 0, 0, 1, 2, 3, 4, 4, 4,
+ 0, 0, 1, 2, 3, 4, 4, 4,
+ 0, 0, 1, 2, 3, 4, 4, 4,
+ 0, 1, 2, 3, 4, 4, 4, 4,
+ 0, 1, 2, 3, 4, 4, 4, 4,
+ 0, 1, 2, 3, 4, 4, 4, 4,
+ };
+ int wid = 8, ht = 12;
+#else
+ png_pixel ppalette[256];
+ unsigned long palette[256];
+ unsigned char *picture;
+ png *png;
+ colquant *cq;
+ int plen, i, err, wid, ht;
+
+ if (argc < 2) {
+ fprintf(stderr, "in this mode I need a .png file on the"
+ " command line\n");
+ return 1;
+ }
+ png = png_decode_file(argv[1], &err);
+ if (!png) {
+ fprintf(stderr, "%s: PNG read error: %s\n", argv[1],
+ png_error_msg[err]);
+ return 1;
+ }
+
+ cq = colquant_new(256, 8);
+ colquant_data(cq, png->pixels, png->width * png->height);
+ plen = colquant_get_palette(cq, ppalette);
+ colquant_free(cq);
+ assert(plen <= 256);
+ for (i = 0; i < plen; i++) {
+ palette[i] = ppalette[i].r >> 8;
+ palette[i] <<= 8;
+ palette[i] |= ppalette[i].g >> 8;
+ palette[i] <<= 8;
+ palette[i] |= ppalette[i].b >> 8;
+ }
+ picture = malloc(png->width * png->height);
+ dither_image(png->width, png->height, png->pixels,
+ ppalette, plen, picture);
+ wid = png->width;
+ ht = png->height;
+ png_free(png);
+
+#endif
+ whlp_ref_picture(h, whlp_add_picture(h, wid, ht, picture, palette));
+ }