bitmap encoding

Libraries, utilities, bootloaders...

Re: bitmap encoding

Postby adekto » Sun Mar 23, 2014 3:21 pm

great, wait whats the rotation?
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium

Re: bitmap encoding

Postby hrangan » Sun Mar 23, 2014 3:25 pm

I see now what you mean about run length encoding not working. Raw encoding does seem like your only option for now.
User avatar
hrangan
 
Posts: 58
Joined: Thu Mar 20, 2014 9:35 pm
Location: Bangalore, India

Re: bitmap encoding

Postby rodot » Sun Mar 23, 2014 3:57 pm

Yep, rotation and flip.
Rotation and flip accept values from 0 to 3 (if it's larger, the program does a %4 to bring it back to the right value)
You can also use the predefined constants
Code: Select all
//rotations:
NOROT //0
ROTCCW //1 90° counter clock wise
ROT180 //2 180°
ROTCW //3 90° clock wise
//flip:
NOFLIP //0
FLIPH //1 horizontal mirror
FLIPV //2 vertical mirror
FLIPVH //3 both


I'm done with the bitmap converter, here it is.
Code: Select all
void setup() {
  size(200, 200);

  PrintWriter output;
  output = createWriter("output.txt");

  PImage img;
  img = loadImage("input.bmp");
  image(img, 0, 0);

  output.println("static unsigned char PROGMEM bitmapName[] =");
  output.println("{");
  output.print("  ");
  output.print(img.width);
  output.print(",");
  output.print(img.height);
  output.println(", //width and height");

  img.loadPixels();

  for (int y = 0; y<img.height; y++) {
    output.print("  ");
    for (int x = 0; x<img.width; x+=8) {
      output.print("B");
      for (int b = 0; b<8; b++) {
        color thisColor = img.get(x+b, y);
        if (brightness(thisColor) > 100) {
          output.print("0");
          img.set(x+b, y, color(255));
        }
        else {
          output.print("1");
          img.set(x+b, y, color(0));
        }
      }
      output.print(", ");
    }
    output.println();
    if ((y%8)==7) {
      output.println();
    }
  }

  img.updatePixels();
  image(img, 0, 100);

  output.print("};");
  output.flush();
  output.close();
}

void draw() {
}


It's a Processing program (the Java equivalent of Arduino), you'll find it here : http://www.processing.org/

It will read input.bmp and save the converted bitmap as output.txt. Then you just have to copy and past it into your code.

Edit: Processing bugs corrected
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: bitmap encoding

Postby Sot0 » Wed May 07, 2014 4:48 pm

Im trying to make a bigger bitmap, but it wont compile. 8x8 bitmaps like this work

Code: Select all
static unsigned char PROGMEM ghost[]=
{
  8,8,
  B00000000,
  B00111100,
  B01111110,
  B11011011,
  B11111111,
  B11111111,
  B11111111,
  B10100101,
};


But something like this doesnt.

Code: Select all
static unsigned char PROGMEM maze[]=
{
  16,1,
  B0000000111111110,

};


It gives this Error:

Code: Select all
In file included from /home/user/sketchbook/libraries/Gamebuino/Display.h:48,
                 from /home/user/sketchbook/libraries/Gamebuino/Gamebuino.h:16,
                 from Buino_Capnam_Serial.ino:2:
/home/user/sketchbook/libraries/Gamebuino/font3x5.c:8: warning: only initialized variables can be placed into program memory area
Buino_Capnam_Serial.ino:12: warning: only initialized variables can be placed into program memory area
Buino_Capnam_Serial.ino:25: warning: only initialized variables can be placed into program memory area
Buino_Capnam_Serial.ino:38: warning: only initialized variables can be placed into program memory area
Buino_Capnam_Serial.ino:51: warning: only initialized variables can be placed into program memory area
Buino_Capnam_Serial.ino:64: warning: only initialized variables can be placed into program memory area
Buino_Capnam_Serial.ino:77: warning: only initialized variables can be placed into program memory area
Buino_Capnam_Serial:80: error: ‘B0000000111111110’ was not declared in this scope
Buino_Capnam_Serial.ino: In function ‘void setup()’:
Buino_Capnam_Serial.ino:85: warning: only initialized variables can be placed into program memory area
Buino_Capnam_Serial.ino: In function ‘void loop()’:
Buino_Capnam_Serial.ino:145: warning: only initialized variables can be placed into program memory area


Why?

Regards
Sot0
Sot0
 
Posts: 31
Joined: Sat Apr 26, 2014 3:31 pm
Location: Germany

Re: bitmap encoding

Postby adekto » Wed May 07, 2014 4:58 pm

a byte is 8 bits
if u want a wider images u add a byte

Code: Select all
static unsigned char PROGMEM maze[]=
{
  16,1,
  B00000001,B11111110,

};
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium

Re: bitmap encoding

Postby Sot0 » Wed May 07, 2014 10:47 pm

Thanks, that makes Sense!
Sot0
 
Posts: 31
Joined: Sat Apr 26, 2014 3:31 pm
Location: Germany

Re: bitmap encoding

Postby DFX2KX » Thu May 08, 2014 12:44 am

adekto wrote:a byte is 8 bits
if u want a wider images u add a byte

Code: Select all
static unsigned char PROGMEM maze[]=
{
  16,1,
  B00000001,B11111110,

};

I assume you'd make multiple rows of multiple bits if you had to, right, for things like background images?
DFX2KX
 
Posts: 250
Joined: Mon Apr 14, 2014 3:48 am

Re: bitmap encoding

Postby adekto » Thu May 08, 2014 1:52 am

wel yea but i hope ur not planing to do that by hand ( i did it for the sd card and some other backgrounds)

but we got a program to convert BMP images to code
https://github.com/Rodot/Gamebuino/tree/master/Utilities/Bitmap_encoder

but just to clarify u cant have a byte that is smaller or bigger then 8 bits
so if say ur sprite is 17x1 px u you will end up using 3 bytes for that images
this is only for the width of your image hight is irrelevant
Code: Select all
static unsigned char PROGMEM maze[]=
{
//
  24,1,
  B11111111,B11111111,B10000000,

};
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium

Re: bitmap encoding

Postby Tony » Fri Jul 25, 2014 8:32 pm

Hi everyone, i have (simple?) questions about the "bitmap encoder" inside the toolkit, i want to test it but everytime i try, i get a " can't open the selected image" the files are .bmp files, but it doesn't work.

Do we need to rename the file : "input.bmp" as suggested in the code?

PImage img;
img = loadImage("input.bmp");
image(img, 0, 0);
(i don't think so because i tried this but it still doesn't work :( )

Do we have a maximum size for the .bmp file? (height, width)

Is it possible to get some "bmp.files" that have already been tested by someone?

Thanks for you answer :)
Tony
 
Posts: 7
Joined: Sat Jul 19, 2014 12:28 pm

Re: bitmap encoding

Postby adekto » Fri Jul 25, 2014 8:47 pm

i haven't used the toolkit yet but just to make sure did u make the image black and white (not greyscale)
also make sure its .bmp and not .BMP some programs tend to do that
size wise i assume the max size is 84x48 although i don't think there is a cap for the size
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium

PreviousNext

Return to Software Development

Who is online

Users browsing this forum: No registered users and 34 guests

cron