amiga_imgv

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