amiga_imgv

changeset 4:0fd37effde29

progress
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 Oct 2017 11:36:18 +0300
parents 663471a80c21
children 0d3d7b020e6a
files src/amiga/gfx.c src/image.c src/sdl/gfx.c
diffstat 3 files changed, 77 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/src/amiga/gfx.c	Thu Oct 26 15:49:56 2017 +0300
     1.2 +++ b/src/amiga/gfx.c	Fri Oct 27 11:36:18 2017 +0300
     1.3 @@ -4,6 +4,7 @@
     1.4  #include "copper.h"
     1.5  #include "hwregs.h"
     1.6  #include "logger.h"
     1.7 +#include "image.h"
     1.8  
     1.9  static int scr_width, scr_height;
    1.10  static int fb_width, fb_height;
    1.11 @@ -124,7 +125,7 @@
    1.12  	bpladdr = (uint32_t)framebuf;
    1.13  	logmsg("bitplane address: %lx\n", (unsigned long)bpladdr);
    1.14  
    1.15 -	bplmod = (fb_width - scr_width) / 8 + fb_width / 8 * num_bitplanes;
    1.16 +	bplmod = (fb_width - scr_width) / 8 + fb_width / 8 * (num_bitplanes - 1);
    1.17  	REG_BPL1MOD = bplmod;
    1.18  	REG_BPL2MOD = bplmod;
    1.19  
    1.20 @@ -205,4 +206,36 @@
    1.21  
    1.22  void gfx_show_image(struct ham_image *img)
    1.23  {
    1.24 +	int i, j, k, fbwidth, fbheight, ncolors, prev_line;
    1.25 +	unsigned char *fbptr = gfx_get_framebuffer();
    1.26 +	struct palchange *chg = img->chglist;
    1.27 +
    1.28 +	fbwidth = gfx_framebuffer_width();
    1.29 +	fbheight = gfx_framebuffer_height();
    1.30 +
    1.31 +	logmsg("showing ham image %dx%d\n", fbwidth, fbheight);
    1.32 +
    1.33 +	memcpy(fbptr, img->pixels, fbwidth * fbheight / 8 * num_bitplanes);
    1.34 +
    1.35 +	/* create copper list that handles the palette */
    1.36 +	clear_copper();
    1.37 +	gfx_begin_copperlist();
    1.38 +	/* initial palette at the start of frame */
    1.39 +	for(i=0; i<16; i++) {
    1.40 +		add_copper(COPPER_MOVE(REGN_COLOR(i), img->palette[i]));
    1.41 +		logmsg("copper palette[%d]: %x\n", i, (unsigned int)img->palette[i]);
    1.42 +	}
    1.43 +#if 0
    1.44 +	/* add copper instructions for palette changes according to the image changelist */
    1.45 +	prev_line = -1;
    1.46 +	while(chg) {
    1.47 +		assert(chg->line >= prev_line);
    1.48 +		if(chg->line != prev_line) {
    1.49 +			prev_line = chg->line;
    1.50 +			add_copper(COPPER_VWAIT(chg->line));
    1.51 +		}
    1.52 +		add_copper(COPPER_MOVE(REGN_COLOR(chg->entry >> 12), chg->entry & 0xfff));
    1.53 +	}
    1.54 +#endif
    1.55 +	add_copper(COPPER_END);
    1.56  }
     2.1 --- a/src/image.c	Thu Oct 26 15:49:56 2017 +0300
     2.2 +++ b/src/image.c	Fri Oct 27 11:36:18 2017 +0300
     2.3 @@ -147,13 +147,15 @@
     2.4  		img->palette[i] = i | (i << 4) | (i << 8);
     2.5  	}
     2.6  
     2.7 -	pptr = img->pixels;
     2.8 -	for(i=0; i<4; i++) {
     2.9 +	for(i=0; i<nbpl; i++) {
    2.10  		pptr = img->pixels + i * w / 8;
    2.11  		for(y=0; y<h; y++) {
    2.12  			pixval = 0;
    2.13  			for(x=0; x<w; x++) {
    2.14 -				pixval = (pixval >> 1) | ((((x ^ y) >> i) & 1) ? 0x80 : 0);
    2.15 +				if(i < 4) {
    2.16 +					unsigned char val = (y & 1) ? 0 : 0xff;
    2.17 +					pixval = (pixval >> 1) | (((val >> i) & 1) ? 0x80 : 0);
    2.18 +				}
    2.19  				if((x & 7) == 7) {
    2.20  					*pptr++ = pixval;
    2.21  					pixval = 0;
     3.1 --- a/src/sdl/gfx.c	Thu Oct 26 15:49:56 2017 +0300
     3.2 +++ b/src/sdl/gfx.c	Fri Oct 27 11:36:18 2017 +0300
     3.3 @@ -24,6 +24,7 @@
     3.4  		SDL_Quit();
     3.5  		return -1;
     3.6  	}
     3.7 +	SDL_WM_SetCaption("imgv SDL version", 0);
     3.8  
     3.9  	return 0;
    3.10  }
    3.11 @@ -115,6 +116,13 @@
    3.12  #define AGREEN(x)	(((x) & 0xf0) | (((x) & 0xf0) >> 4))
    3.13  #define ABLUE(x)	((((x) & 0xf) << 4) | ((x) & 0xf))
    3.14  
    3.15 +#define RSHIFT		(fbsurf->format->Rshift)
    3.16 +#define GSHIFT		(fbsurf->format->Gshift)
    3.17 +#define BSHIFT		(fbsurf->format->Bshift)
    3.18 +#define RMASK		(fbsurf->format->Rmask)
    3.19 +#define GMASK		(fbsurf->format->Gmask)
    3.20 +#define BMASK		(fbsurf->format->Bmask)
    3.21 +
    3.22  void gfx_show_image(struct ham_image *img)
    3.23  {
    3.24  	int i, j, k;
    3.25 @@ -127,8 +135,8 @@
    3.26  		int red = ARED(pcol);
    3.27  		int green = AGREEN(pcol);
    3.28  		int blue = ABLUE(pcol);
    3.29 -		palette[i] = (red << fbsurf->format->Rshift) | (green << fbsurf->format->Gshift) |
    3.30 -			(blue << fbsurf->format->Bshift);
    3.31 +		palette[i] = (red << RSHIFT) | (green << GSHIFT) | (blue << BSHIFT);
    3.32 +		printf("palette[%d]: %d %d %d\n", i, red, green, blue);
    3.33  	}
    3.34  
    3.35  	if(SDL_MUSTLOCK(fbsurf)) {
    3.36 @@ -139,18 +147,43 @@
    3.37  	src = img->pixels;
    3.38  	for(i=0; i<img->height; i++) {
    3.39  		for(j=0; j<img->width; j++) {
    3.40 +			uint32_t color;
    3.41  			unsigned char idx = 0;
    3.42 -			int bit = j & 7;
    3.43 +			unsigned char ham;
    3.44 +			int bit = 7 - (j & 7);
    3.45 +
    3.46  			for(k=0; k<img->nbitplanes; k++) {
    3.47  				idx = (idx << 1) | ((*(src + k * img->width / 8) >> bit) & 1);
    3.48  			}
    3.49 -			*dest++ = palette[idx];
    3.50 -			if(bit == 7) {
    3.51 +
    3.52 +			printf("%d ", idx);
    3.53 +			color = palette[idx];
    3.54 +			/*ham = (idx >> 4) & 3;
    3.55 +			color = (i & j) ? dest[-1] : 0;
    3.56 +
    3.57 +			switch(ham) {
    3.58 +			case 0:
    3.59 +				color = palette[idx];
    3.60 +				break;
    3.61 +			case 1:
    3.62 +				color = (color & ~BMASK) | (((uint32_t)idx & 0xf) << BSHIFT);
    3.63 +				break;
    3.64 +			case 2:
    3.65 +				color = (color & ~RMASK) | (((uint32_t)idx & 0xf) << RSHIFT);
    3.66 +				break;
    3.67 +			case 3:
    3.68 +				color = (color & ~GMASK) | (((uint32_t)idx & 0xf) << GSHIFT);
    3.69 +			}
    3.70 +			*/
    3.71 +
    3.72 +			*dest++ = color;
    3.73 +			if(!bit) {
    3.74  				++src;
    3.75  			}
    3.76  		}
    3.77  		src += img->width / 8 * (img->nbitplanes - 1);
    3.78  	}
    3.79 +	putchar('\n');
    3.80  
    3.81  	if(SDL_MUSTLOCK(fbsurf)) {
    3.82  		SDL_UnlockSurface(fbsurf);