amiga_imgv

view 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 source
1 #include <stdlib.h>
2 #include <string.h>
3 #include "image.h"
5 struct ham_image *load_ham_image(const char *fname)
6 {
7 return 0; /* TODO */
8 }
10 struct ham_image *gen_ham_image(int w, int h, int nbpl)
11 {
12 int i, x, y;
13 struct ham_image *img;
14 unsigned char *pptr;
15 unsigned char pixval;
16 /*static const uint16_t defpal[] = {
17 0x000, 0xf00, 0xff0, 0x0f0, 0x0ff, 0x00f, 0xf0f, 0xfff,
18 0x444, 0x800, 0x880, 0x080, 0x088, 0x008, 0x808, 0x888
19 };*/
21 if(!(img = malloc(sizeof *img))) {
22 return 0;
23 }
24 if(!(img->pixels = calloc(w * h / 8 * nbpl, 1))) {
25 free(img);
26 return 0;
27 }
28 img->width = w;
29 img->height = h;
30 img->chglist = 0;
32 img->nbitplanes = nbpl;
33 /*memcpy(img->palette, defpal, sizeof defpal);*/
34 for(i=0; i<16; i++) {
35 img->palette[i] = i | (i << 4) | (i << 8);
36 }
38 pptr = img->pixels;
39 for(i=0; i<4; i++) {
40 pptr = img->pixels + i * w / 8;
41 for(y=0; y<h; y++) {
42 pixval = 0;
43 for(x=0; x<w; x++) {
44 pixval = (pixval >> 1) | ((((x ^ y) >> i) & 1) ? 0x80 : 0);
45 if((x & 7) == 7) {
46 *pptr++ = pixval;
47 pixval = 0;
48 }
49 }
50 pptr += w / 8 * (img->nbitplanes - 1);
51 }
52 }
54 return img;
55 }