+ 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));