dbf-udg

changeset 6:57ea4988a9f2

added code to dump the ditherblock image
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 18 Feb 2013 04:41:26 +0200
parents e09cbb2e9d4f
children 603656331514
files src/udg.cc
diffstat 1 files changed, 22 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/src/udg.cc	Mon Feb 18 03:46:52 2013 +0200
     1.2 +++ b/src/udg.cc	Mon Feb 18 04:41:26 2013 +0200
     1.3 @@ -70,8 +70,13 @@
     1.4  
     1.5  bool init()
     1.6  {
     1.7 -	float *img = new float[DITHER_SZ * DITHER_SZ * DITHER_LEVELS];
     1.8 -	float *ptr = img;
     1.9 +	FILE *fp = fopen("udg.ppm", "wb");
    1.10 +	if(fp) {
    1.11 +		fprintf(fp, "P6\n%d %d\n255\n", DITHER_SZ, DITHER_SZ * DITHER_LEVELS);
    1.12 +	}
    1.13 +
    1.14 +	unsigned char *img = new unsigned char[DITHER_SZ * DITHER_SZ * DITHER_LEVELS];
    1.15 +	unsigned char *ptr = img;
    1.16  
    1.17  	for(int i=0; i<DITHER_LEVELS; i++) {
    1.18  		float val = (float)i / (float)(DITHER_LEVELS - 1);
    1.19 @@ -79,11 +84,24 @@
    1.20  			for(int x=0; x<DITHER_SZ; x++) {
    1.21  				/* (1 + M) / (1 + MxN) */
    1.22  				float thres = (1.0 + dither_matrix[x][y]) / (1.0 + DITHER_SZ * DITHER_SZ);
    1.23 -				*ptr++ = val >= thres ? 1.0 : 0.0;
    1.24 +				*ptr++ = val >= thres ? 255 : 0;
    1.25 +
    1.26 +				if(fp) {
    1.27 +					int r = ptr[-1] ? 246 : 10;
    1.28 +					int g = ptr[-1] ? 198 : 72;
    1.29 +					int b = ptr[-1] ? 141 : 85;
    1.30 +					fputc(r, fp);
    1.31 +					fputc(g, fp);
    1.32 +					fputc(b, fp);
    1.33 +				}
    1.34  			}
    1.35  		}
    1.36  	}
    1.37  
    1.38 +	if(fp) {
    1.39 +		fclose(fp);
    1.40 +	}
    1.41 +
    1.42  	if(!(prog = create_program_load("sdr/dither.v.glsl", "sdr/dither.p.glsl"))) {
    1.43  		return false;
    1.44  	}
    1.45 @@ -94,7 +112,7 @@
    1.46  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    1.47  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    1.48  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    1.49 -	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, DITHER_SZ, DITHER_SZ * DITHER_LEVELS, 0, GL_LUMINANCE, GL_FLOAT, img);
    1.50 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, DITHER_SZ, DITHER_SZ * DITHER_LEVELS, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, img);
    1.51  
    1.52  	if(!init_scroller()) {
    1.53  		return false;