Direct image overlap

have to preface this that direct bitmaps are an advanced feature and should probably not be used by any beginner.

there meant mostly for static images that do not have anything drawn below or ontop of them (splash screens, fmv, card game graphic, etc)
but if you do need them to overlap and there all rectangles here is an idea of how to do it using a “mask”

4 Likes

im actualy wondering about it now that i see it visualy
i was first thinking a 1bit buffer as mask, but it could aslo be an array of rects that you boundary check
i geuss the array will be faster and smaller

any opinions?

1 Like

I’m doing this with directBitmap, it’s nice even for board games :slight_smile:

I’ve just add a small option to allow for transparent color here

Right now the only way to use more than 4 colors at high res.

2 Likes

I opted for direct pixeling for my game… Although I’ll have to wait for my pikkito to see how slow it is and if anything can be done about it…

1 Like

I don’t know if that’s going to be possible in directbitmap since thats suposed to be a lcd comand to draw a rectangle with a string of 565rgb data

I might be wrong, have not seen the lcd data sheet

A mask would be super helpful!

1 Like

in my effort to make this happen i wanted to improve the way derect bitmap works since i think it can get a little more streamlined and less nested in the library

having trouble figuring out what ecactly im doing wrong


    void Pokitto::lcdBitmap(int16_t x0, int16_t y0,const uint16_t* colors, uint8_t * data){

	int16_t x1 = *data;
	int16_t y1 = *(data + 1);
	
	int16_t temp;
	if (x0>x1) {temp=x0;x0=x1;x1=temp;}
	if (y0>y1) {temp=y0;y0=y1;y1=temp;}
	if (x0 > POK_LCD_W) return;
	if (y0 > POK_LCD_H) return;
    if (x1 > POK_LCD_W) x1=POK_LCD_W;
	if (y1 > POK_LCD_H) y1=POK_LCD_W;
	if (x0 < 0) x0=0;
	if (y0 < 0) y0=0;

	int16_t x,y;
	int index = 2;
    for (x=x0; x<=x1;x++) {
        write_command(0x20);  // Horizontal DRAM Address (=y on pokitto screen)
        write_data(y0);
        write_command(0x21);  // Vertical DRAM Address (=x on pokitto screen)
        write_data(x);
        write_command(0x22); // write data to DRAM

        CLR_CS_SET_CD_RD_WR; // go to vram write mode

        
        //for (int s1=0; s1<scale;s1++){
        for (y=y0; y<y1;y++) {
                //for (int s=0; s<scale;s++){
        		setup_data_16(colors[data[index]>>4]);
                CLR_WR;SET_WR;
                //}for (int s=0; s<scale;s++){
                setup_data_16(colors[data[index]&0xF]);
                CLR_WR;SET_WR;
                //}
                index++;
        }
      //}
      }
    }


what kind of error/wrong outout you are getting?

detending on where the image is drawn im getting a diferent garbage image,
not sure where the error is and im not sure what derection im drawing in

all im trying to do is avoid derectpixel and write horizondal so you dont have to re evaluate where the pixel is

Sounds like your input data is wrong. Try writing a constant color value, for example 0xF000 and see how it behaves

hmm yea i can draw single color wen i dont add to the index

I’m having a similar issue. I’m sending a pointer to a 16bit pixel array. If I output only 0xFFF it works fine, but if I output my array I get one line of garbage and then it seems to crash everything…

I can;t give up though :stuck_out_tongue:

Are you sure your pointers to data are of the right type? int++ is 2 bytes

edit: forget that, its ok

found it:

colors[index>>4], NOT: colors[index]>>4

the latter will have you pointing in data outside the palette => garbage

edit: nope. im too tired to think. ill look at tjis tomorrow. my answer is wrong.

1 Like

I went a similar route, basically its a filled rectangle using a 16bit image array instead of a solid colour. It’s working fine for me, Sensitive is now working at a good speed on hardware, just a couple of sprites I need to take care of now.

void Pokitto::lcdTile(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t* gfx){

	if (x0 > POK_LCD_W) return;
	if (y0 > POK_LCD_H) return;
	if (x0 < 0) x0=0;
	if (y0 < 0) y0=0;

	int16_t x,y,z=0;
    for (x=x0; x<=x1-1;x++) {
        write_command(0x20);  // Horizontal DRAM Address (=y on pokitto screen)
        write_data(y0);
        write_command(0x21);  // Vertical DRAM Address (=x on pokitto screen)
        write_data(x);
        write_command(0x22); // write data to DRAM

        CLR_CS_SET_CD_RD_WR; // go to vram write mode

        for (y=y0; y<y1;y++) {
                setup_data_16(gfx[z++]); // setup the data (flat color = no change between pixels)
                CLR_WR;SET_WR; //CLR_WR;SET_WR;//toggle writeline, pokitto screen writes a column up to down
        }
    }

}
2 Likes

hang on a sec your passing a uint16 for gfx
that means its a full 565 rgb bitmap tile
idk how your creating gfx data but for larger images you going to hit memory isues

Currently at this point I’m only using 10x10 images tile style. Mostly this is just to prove the speed difference.

Also looking at the init LCD sequence, it seems to set a window on the LCD. I’m attempting to set a window of the tile size I am using at the position of the tile, so I can get rid of the position writing in the x loop, that might speed things up a little more, no luck so far though.

1 Like

OK, I think that this is about the fastest that this can get…

void Pokitto::setWindow(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
	write_command(0x37); write_data(x1);
	write_command(0x36); write_data(x2);
	write_command(0x39); write_data(y1);
	write_command(0x38); write_data(y2);
	write_command(0x20); write_data(x1);
	write_command(0x21); write_data(y1);
}

void Pokitto::lcdTile(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t* gfx){

	int width=x1-x0;
	int height=y1-y0;

	if (x0 > POK_LCD_W) return;
	if (y0 > POK_LCD_H) return;
	if (x0 < 0) x0=0;
	if (y0 < 0) y0=0;

	setWindow(y0, x0, y1-1, x1-1); // x and y are rotated
    write_command(0x22);

    for (int x=0; x<=width*height-1;x++) {
        write_data(gfx[x]);
    }
}

Yes, it’s sending the image in 16bit mode, so you might have to think about that from your code side rather than the core side. I’m not sure what the best practice would be in this case.

Although it doesn’t work for a single line, not sure why yet…

2 Likes

ad a case check for one line to do a +1 on the vertical in setwindow might fix it

i think we just have to give it also a reference to the pallet so it can run the current sprite format though we can keep this code for full color stuff wich might actual give you some nice transitional effects like gradients or as a compositor buffer for 2 overlapping color pallets