gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > BMP to Raw > conv.exe (?)

#90909 - HtheB - Mon Jul 03, 2006 12:43 pm

Hi, I want to convert .bmp to .raw..
I tried many tools that I could find (yes.. even on gbadev)
It didnt work with any application.. (it wont work on the DS)

I had conv.exe.. (it was the best so far..) but.. does anyone has the conv.exe? b/c I think I have a corrupted version of it.. (the images works.. but its VERY weird..)


if someone know where to find it.. please tell me ^_^

tnq! :)

#90921 - silent_code - Mon Jul 03, 2006 2:19 pm

use usenti and/or (win)git (google for it ;) )... should solve your problems (except for 16bit images)...

#90930 - LiraNuna - Mon Jul 03, 2006 3:47 pm

what format you need the .raw as? 16col, 256col 32kcol ?
if it's one of those, gfx2gba is what you're looking for.

Code:
gfx2gba -c[16/256/32k] img.bmp

_________________
Private property.
Violators will be shot, survivors will be shot again.

#90938 - HtheB - Mon Jul 03, 2006 4:56 pm

silent_code wrote:
use usenti and/or (win)git (google for it ;) )... should solve your problems (except for 16bit images)...

Tried out allready ;)
didnt work..

LiraNuna wrote:
what format you need the .raw as? 16col, 256col 32kcol ?
if it's one of those, gfx2gba is what you're looking for.

Code:
gfx2gba -c[16/256/32k] img.bmp


Allready tried out.. didn't work eather..


its 24bit bmp format.. ^_^
so.... I really need that conv.exe its the only way :(

#90942 - silent_code - Mon Jul 03, 2006 5:11 pm

then just save it in 16 or 8 bit ;) that way you'll be able to use gfx2gba or the tools i mentioned... shouldn't be a problem ;)

#90943 - Cearn - Mon Jul 03, 2006 5:29 pm

HtheB wrote:
silent_code wrote:
use usenti and/or (win)git (google for it ;) )... should solve your problems (except for 16bit images)...

Tried out allready ;)
didnt work..

Could you define 'didn't work' here? Apart from the alpha bit, these tools should give the proper result even for 24bit images.

#91043 - HtheB - Tue Jul 04, 2006 6:41 am

Cearn wrote:
HtheB wrote:
silent_code wrote:
use usenti and/or (win)git (google for it ;) )... should solve your problems (except for 16bit images)...

Tried out allready ;)
didnt work..

Could you define 'didn't work' here? Apart from the alpha bit, these tools should give the proper result even for 24bit images.
Ok, I will make pictures and show them.. (really its horrible :( )

#91151 - silent_code - Tue Jul 04, 2006 10:27 pm

you better do ;)

it sounds like it's a code problem... i'm using 24bit .bmp files with usenti and (win)git and the only problem i have is the 24 to 16bit conversion of my raytraced images :( (look at the other thread about that problem).
but that's nothing to do with the tools.

#91217 - HtheB - Wed Jul 05, 2006 10:55 am

silent_code wrote:
you better do ;)

it sounds like it's a code problem... i'm using 24bit .bmp files with usenti and (win)git and the only problem i have is the 24 to 16bit conversion of my raytraced images :( (look at the other thread about that problem).
but that's nothing to do with the tools.
this is what it says in the conv.cpp

Code:
#include <stdio.h>

typedef unsigned short ushort;
typedef unsigned char byte;
typedef unsigned int uint;

#define RGB(r,g,b) ((1 << 15) | (r) | ((g) << 5) | ((b) << 10))
//#define RGB(r,g,b) ((b) | ((g) << 6) | ((r) << 11))


char *dumpFile(char* name) {
   char *font;
   int size;
   
   FILE *fd = fopen(name, "r");
   fseek(fd, 0, SEEK_END);
   size = ftell(fd);
   fseek(fd, 0, SEEK_SET);
   font = new char[size];
   fread(font, 1, size, fd);
   fclose(fd);
   
   return font;
}

int main(int argc, char** argv) {   
   byte rgb[3];
   ushort *dataOff;
   int off, pad;
   char *file = dumpFile(argv[1]);
   char *fileOff;
   uint width, height;
   int size;
   ushort * data;
   
   width = *(uint*)(file + 18);
   height = *(uint*)(file + 22);
   data = new ushort[width * height];
   size = width * height * 2;
      
   off = 0;
   pad = (3000 - width * 3) & 3;
   
   fileOff = file + 0x36;
   dataOff = data + (height - 1) * width;
   for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
         rgb[0] = (byte)(*fileOff++);
         rgb[1] = (byte)(*fileOff++);
         rgb[2] = (byte)(*fileOff++);
         dataOff[x] = RGB(rgb[2] >> 3,
               rgb[1] >> 3,
               rgb[0] >> 3);
      }
      dataOff -= width;
      fileOff += pad;
   }
   
   
   FILE *fd = fopen(argv[2], "w");
   rgb[0] = height;
   rgb[1] = width;
   fwrite(rgb, 1, 2, fd);
   fwrite(data, size, 1, fd);
   fclose(fd);
   
   delete[] (file);
}

#91239 - HtheB - Wed Jul 05, 2006 3:49 pm

when I compile it.. and use it (conv.exe) I still get corrupted pictures :(

#91246 - Cearn - Wed Jul 05, 2006 5:13 pm

That conv.exe works fine*, you're either not giving it the right kind of bitmap, or using the data it produces wrongly. Check your video mode settings.

* Though it's a minor miracle: no comments, magic numbers galore and no safety checks of any kind. The thing expects a 24bpp, version 3, bottom-up windows bitmap, where the width is a multiple of 4, but doesn't mention that anywhere. These conditions are probably met for your bitmap, but anything else will probably hang or crash the program, or worse: give incorrect output. The fact that the fopen() calls do not explicitly use binary mode is also slightly worrying; I'm not 100% sure, but that may give bad results if bytes are 0x0A ('\n') or 0x0D ('\r').
Also note that the first 2 bytes give the size of the bitmap. Again, not documented, and would be wrong for DS-screensized bitmaps or larger.

#91263 - HtheB - Wed Jul 05, 2006 7:12 pm

Cearn wrote:
That conv.exe works fine*, you're either not giving it the right kind of bitmap, or using the data it produces wrongly. Check your video mode settings.

* Though it's a minor miracle: no comments, magic numbers galore and no safety checks of any kind. The thing expects a 24bpp, version 3, bottom-up windows bitmap, where the width is a multiple of 4, but doesn't mention that anywhere. These conditions are probably met for your bitmap, but anything else will probably hang or crash the program, or worse: give incorrect output. The fact that the fopen() calls do not explicitly use binary mode is also slightly worrying; I'm not 100% sure, but that may give bad results if bytes are 0x0A ('\n') or 0x0D ('\r').
Also note that the first 2 bytes give the size of the bitmap. Again, not documented, and would be wrong for DS-screensized bitmaps or larger.
YES!!! I GOT IT TO WORK!!!

i changed:

Code:
FILE *fd = fopen(name, "r");

and
Code:
FILE *fd = fopen(argv[2], "w");


into:
Code:
FILE *fd = fopen(name, "rb");

and
Code:
FILE *fd = fopen(argv[2], "wb");


and it works! tnx for all help everyone! :)