/* TkWin version 0.1 -- Tk for Windows
 * Copyright (C) 1994 K. K. Kubota
 * Mathematical Sciences Computing Facility, University of Kentucky,
 * Lexington, KY 40506, USA (e-mail: ken@ms.uky.edu)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License version 2 as published by the Free Software Foundation
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* x2wbit.c -- simple program for converting X bitmaps into
 * Windows type monochrome bitmap arrays appropriate for use
 * with CreateBitmap
 */
/* data file should be standard X bitmap file format, except that
 * height, width, and bits are used rather than file_height, file_width, 
 * file_bits
 */

#include "data" 

/* invert the order of the bits in a character */
swap(int c){
    int i, r = 0;
    for(i=0; i < 8; i++){
	r <<= 1;
	if(c&1) r |= 1;
	c >>= 1;
    }
    return r;
}

#include <stdio.h>
void main(){
    int w = (width+7)/8;		/* width of x bitmap in bytes */
    int w2 = ((width + 15)/16)*2;	/* width of windows one in bytes */
    int i, j, c;
    for(i = 0; i < height; i++){
	for(j = 0; j < w2; j++){
	    if(j < w2 - 1 || w == w2) c = bits[i*w+j];
	    else c = 0;
	    printf(" 0x%0.2x%s", swap(c),
		(j < w2-1 || i < height - 1) ? "," : "};");
	}
	putchar('\n');
    }
}
