amiga_imgv

diff src/image.c @ 0:a4788c959918

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 25 Oct 2017 19:34:53 +0300
parents
children 663471a80c21
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/image.c	Wed Oct 25 19:34:53 2017 +0300
     1.3 @@ -0,0 +1,55 @@
     1.4 +#include <stdlib.h>
     1.5 +#include <string.h>
     1.6 +#include "image.h"
     1.7 +
     1.8 +struct ham_image *load_ham_image(const char *fname)
     1.9 +{
    1.10 +	return 0;	/* TODO */
    1.11 +}
    1.12 +
    1.13 +struct ham_image *gen_ham_image(int w, int h, int nbpl)
    1.14 +{
    1.15 +	int i, x, y;
    1.16 +	struct ham_image *img;
    1.17 +	unsigned char *pptr;
    1.18 +	unsigned char pixval;
    1.19 +	/*static const uint16_t defpal[] = {
    1.20 +		0x000, 0xf00, 0xff0, 0x0f0, 0x0ff, 0x00f, 0xf0f, 0xfff,
    1.21 +		0x444, 0x800, 0x880, 0x080, 0x088, 0x008, 0x808, 0x888
    1.22 +	};*/
    1.23 +
    1.24 +	if(!(img = malloc(sizeof *img))) {
    1.25 +		return 0;
    1.26 +	}
    1.27 +	if(!(img->pixels = calloc(w * h / 8 * nbpl, 1))) {
    1.28 +		free(img);
    1.29 +		return 0;
    1.30 +	}
    1.31 +	img->width = w;
    1.32 +	img->height = h;
    1.33 +	img->chglist = 0;
    1.34 +
    1.35 +	img->nbitplanes = nbpl;
    1.36 +	/*memcpy(img->palette, defpal, sizeof defpal);*/
    1.37 +	for(i=0; i<16; i++) {
    1.38 +		img->palette[i] = i | (i << 4) | (i << 8);
    1.39 +	}
    1.40 +
    1.41 +	pptr = img->pixels;
    1.42 +	for(i=0; i<4; i++) {
    1.43 +		pptr = img->pixels + i * w / 8;
    1.44 +		for(y=0; y<h; y++) {
    1.45 +			pixval = 0;
    1.46 +			for(x=0; x<w; x++) {
    1.47 +				pixval = (pixval >> 1) | ((((x ^ y) >> i) & 1) ? 0x80 : 0);
    1.48 +				if((x & 7) == 7) {
    1.49 +					*pptr++ = pixval;
    1.50 +					pixval = 0;
    1.51 +				}
    1.52 +			}
    1.53 +			pptr += w / 8 * (img->nbitplanes - 1);
    1.54 +		}
    1.55 +	}
    1.56 +
    1.57 +	return img;
    1.58 +}