Images

Créations

archonik

NEW il y a 6 ans

archonik archonik

Using this exact code:

gb.display.drawImage(0, 50, img, 0, 50, 80, 14);

What I get:

What I expect:

It should draw the entire x axis from 0-80.

But it only draws the first 30~ pixels and just cuts off.

Sorunome

il y a 6 ans

Thank you, found the bug and fixed it......it was unbelievably stupid lol

Sorunome

NEW il y a 6 ans

archonik archonik

Thank you, found the bug and fixed it......it was unbelievably stupid lol

archonik

il y a 6 ans

Brilliant! Great news. Thank you for your help. Hope to see the fix pushed to Arduino IDE soon so I can finish polishing up my game!

archonik

NEW il y a 6 ans

Sorunome Sorunome

Brilliant! Great news. Thank you for your help. Hope to see the fix pushed to Arduino IDE soon so I can finish polishing up my game!

eriban

NEW il y a 6 ans

While implementing my first Gamebuino game I am running into some performance issues related to drawing images. The game features a 3D-like view which requires drawing images with a transparent color which partially overlap. This means it requires drawing more pixels than in a normal 2D game.

I did some benchmarking and get the following results:

  • A loop containing only a display.clear already uses 55% of CPU
    • Without a display.clear an empty loop still uses 49% of CPU
  • CPU usage goes up linearly with the number of images that are drawn (which is good, as it makes things predictable)
  • Drawing images with a transparent color is significantly slower than drawing a normal image: 
    • Without using a transparent color, 140 10x10 images can be drawn per frame before CPU load reaches 100%
    • When using a transparent color, 80 10x10 images can be drawn per frame before CPU load reaches 100%

So a couple of questions:

  • Is it normal that CPU usage is so high without any code in the loop?
  • Is it expected that drawing images with a transparent color is significantly slower?
  • Can I do anything in my code to improve performance?
  • Can anything be done in the Gamebuino library to improve performance?

Btw, I can share my benchmark code if that helps.

Sorunome

il y a 6 ans

Is it normal that CPU usage is so high without any code in the loop?

at 25 FPS you have 40ms time for each frame to calculate. the screen is 160x128 pixels, at 16 bits per pixel, making 327680 bits to send per frame. The SPI speed to send data to the screen at 24MHz, so sending the screen alone takes 14ms. That is 35% CPU time. Adding things like the sound interrupt (44.1kHz) etc. explains why a lank sketch has such a high CPU usage already.

Is it expected that drawing images with a transparent color is significantly slower?

Yes, as you can't just memcpy but have to check for every single pixel of the source image if they are the transparent color, and if so, skip them

Can I do anything in my code to improve performance?

No need to clear the screen if you do a full re-draw, try to avoid transparency, other things

Can anything be done in the Gamebuino library to improve performance?

Probably, and I'm happy for suggestions!

Sorunome

NEW il y a 6 ans

eriban eriban

Is it normal that CPU usage is so high without any code in the loop?

at 25 FPS you have 40ms time for each frame to calculate. the screen is 160x128 pixels, at 16 bits per pixel, making 327680 bits to send per frame. The SPI speed to send data to the screen at 24MHz, so sending the screen alone takes 14ms. That is 35% CPU time. Adding things like the sound interrupt (44.1kHz) etc. explains why a lank sketch has such a high CPU usage already.

Is it expected that drawing images with a transparent color is significantly slower?

Yes, as you can't just memcpy but have to check for every single pixel of the source image if they are the transparent color, and if so, skip them

Can I do anything in my code to improve performance?

No need to clear the screen if you do a full re-draw, try to avoid transparency, other things

Can anything be done in the Gamebuino library to improve performance?

Probably, and I'm happy for suggestions!

eriban

il y a 6 ans

Thanks for your (quick) reply. With your confirmation that this is the way it is and why, I refactored my drawing code to minimize the number and size of images with transparent pixels. The impact of this change is significant. At 15 FPS, CPU load went down from 86% to 63%. 20 FPS is now definitely feasible, and maybe even 25 FPS. :-)

I am not yet familiar enough with the Gamebuino library and programming for Arduino in general to suggest performance improvements to the library right now, but will definitely do so when/if I am able to.   

jicehel

NEW il y a 6 ans

I should make errors... I don't have success to use spritesheet

I would use crop seems easy but i always have this error:

exit status 1
no matching function for call to 'Gamebuino_Meta::Image::drawImage(int, int, Gamebuino_Meta::Image&, int, int, int, int)'


The code line is: gb.display.drawImage(7, 2, ParaCol1, 0, 0, 10, 12);

Seems like the code of example... no idea, it's will be enough for today but i don't success... I'll finish to make unique image as i success to manage it ...

Sorunome

il y a 6 ans

I should make errors... I don't have success to use spritesheet

Where are you stick?

I would use crop seems easy but i always have this error:

Crop is currently only in the git repo, it hasn't made its way to the one released via the Arduino IDE yet

Sorunome

NEW il y a 6 ans

jicehel jicehel

I should make errors... I don't have success to use spritesheet

Where are you stick?

I would use crop seems easy but i always have this error:

Crop is currently only in the git repo, it hasn't made its way to the one released via the Arduino IDE yet

jicehel

NEW il y a 6 ans

OK, thanks Sorunome. Spritesheet make no error but the fram was invisible, so as it was not more easy as a simple crop, i would use it.

Have i an easy way to use librairy from the repo instead of actual ?

Sorunome

il y a 6 ans

Have i an easy way to use librairy from the repo instead of actual ?

On linux you clone the repo into `~/Arduino/libraries/` folder....on windows and mac there should be equivalent folders somewhere

eriban

NEW il y a 6 ans

Sorunome Sorunome

Thanks for your (quick) reply. With your confirmation that this is the way it is and why, I refactored my drawing code to minimize the number and size of images with transparent pixels. The impact of this change is significant. At 15 FPS, CPU load went down from 86% to 63%. 20 FPS is now definitely feasible, and maybe even 25 FPS. :-)

I am not yet familiar enough with the Gamebuino library and programming for Arduino in general to suggest performance improvements to the library right now, but will definitely do so when/if I am able to.   

Sorunome

NEW il y a 6 ans

jicehel jicehel

Have i an easy way to use librairy from the repo instead of actual ?

On linux you clone the repo into `~/Arduino/libraries/` folder....on windows and mac there should be equivalent folders somewhere

geed

NEW il y a 6 ans

Hi every one !

Someone to explain me how work the transparency in indexed mode ? For exemple, i want the everything in magenta are transparence, how i do that ?

i tried many thing but nothing work properly :(

Thanks !!

eriban

il y a 6 ans

It is easy. Use setTransparentColor on the image.

For example:

Image myImage = ...;

void setup() {
  gb.begin();
  myImage.setTransparentColor(INDEX_PURPLE);
}

void loop() {
  while(!gb.update());
  gb.display.drawImage(0, 0, myImage);
}

eriban

NEW il y a 6 ans

geed geed

It is easy. Use setTransparentColor on the image.

For example:

Image myImage = ...;

void setup() {
  gb.begin();
  myImage.setTransparentColor(INDEX_PURPLE);
}

void loop() {
  while(!gb.update());
  gb.display.drawImage(0, 0, myImage);
}

Sorunome

il y a 6 ans

There is no need to use setTransparentColor(), as you should set it in the header of the image data!

Sorunome

NEW il y a 6 ans

eriban eriban

There is no need to use setTransparentColor(), as you should set it in the header of the image data!

geed

il y a 6 ans

Yes but how ? :)

I "converted" my pictures with the "image converter" on this site. I created them with piskel and they use only color of the GB palette.

What i must write in the header to do this ? for exemple, if i write 0xCA30 or MAGENTA, it doesn't work. Magenta's pixels aren't transparent.

Thanks

jicehel

NEW il y a 6 ans

Sorunome correct me if i make a mistake but you can't do it with a file picture loaded and not binary written in code. As i said i begin so i have maybe missed something with it.

Sorunome

il y a 6 ans

That is indeed correct, indexed BMPs can't have transparency, thus you have to use setTransparentColor() for them.

You can, however, load 32 bit depth BMPs and it'll automatically convert to rgb565 with setting the transparent color

Sorunome

NEW il y a 6 ans

jicehel jicehel

That is indeed correct, indexed BMPs can't have transparency, thus you have to use setTransparentColor() for them.

You can, however, load 32 bit depth BMPs and it'll automatically convert to rgb565 with setting the transparent color