Page 1 of 1

Posted: Tue Feb 26, 2002 2:21 am
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Hi,

I'm coding an Xpm image viewer/converter. It loads an Xpm image file, converts it to BMP format, saves it and loads the BMP image using LoadImage(). Well, it doesn't, and that is the problem, LoadImage() fails. It seems not to like the BMP header created, or something like that. The resulting BMP file is viewable in any viewer (not really true, only PicaView can load it). This is the BMP header created:

UPDATE: Never mind, there are errors everywhere, I'll keep working.

It would be nice if anybody could point me to the problem. If I don't find a solution, I'll code a converter only (not a viewer :wink:.

Thanks,



El_Choni

Edited by - El_Choni on 26 February 2002 03:40:52

Posted: Tue Feb 26, 2002 8:44 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

>UPDATE: Never mind, there are errors everywhere,
>I'll keep working.
>It would be nice if anybody could point me to the problem

Which Problem ??
Cant see source - cant see a problem.

If you still have some problems with fileformats,
look @ http://www.WotsIt.org

You´ll find useful infos about many FileFormats
on WotsIt, like this:
- There is a deficiency in the BMP file format
- specification from Microsoft.
- While they do point out in RLE encoding mode
- that lines must start on an even byte number,
- they have omitted the following:
-
- EVERY compression group must start on an even
- byte boundary.
-
- In RGB encoding (no compression), when using
- 8 bits per pixel, lines must start on a long-word
- boundary (i.e., low two bits zero).
-
- And, of course, they use 'int' in the spec when it
- should properly be 'short', and they use 'long' and
- 'DWORD' interchangeably. Should just be 'long'.

cya,
...Danilo
(registered PureBasic user)


Edited by - Danilo on 26 February 2002 08:50:57

Posted: Tue Feb 26, 2002 10:39 am
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Yes, I deleted it not to make people waste their time, because there were errors in other parts of the code.
In RGB encoding (no compression), when using
- 8 bits per pixel, lines must start on a long-word
- boundary (i.e., low two bits zero).
You mean Image data offset must be dword aligned (divisible by four)?
And, of course, they use 'int' in the spec when it
- should properly be 'short', and they use 'long' and
- 'DWORD' interchangeably. Should just be 'long'.
I thought that also. I don't know why they use all these names. Well, a dword could be a float (but not in a bmp structure).

Thanks, Danilo. Bye,

El_Choni

Posted: Tue Feb 26, 2002 11:32 am
by BackupUser
Restored from previous forum. Originally posted by fred.

Do you use the SaveImage() routine or you have build your own ?

Fred - AlphaSND

Posted: Tue Feb 26, 2002 11:57 am
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

What is SaveImage()? Some undocumented stuff?

Ok, found it in the PB function listing:

SaveImage(#Image, FileName)

(BTW, is it undocumented due to buggy behaviour or due to forgetting?)

Anyway I can't use it, because I don't have a way to load an image from memory instead of a file. So I need to save the data first as a bmp:

Code: Select all

If CreateFile(0, BmpFileName)
  WriteData(MemoryID(), BmpSize)
  CloseFile(0)
Endif
And load it after with LoadImage().

El_Choni

Edited by - El_Choni on 26 February 2002 14:11:42

Posted: Tue Feb 26, 2002 6:00 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Hi,

I'm coding an Xpm image viewer/converter. It loads an Xpm image file, converts it to BMP format, saves it and loads the BMP image using LoadImage(). Well, it doesn't, and that is the problem, LoadImage() fails. It seems not to like the BMP header created, or something like that. The resulting BMP file is viewable in any viewer (not really true, only PicaView can load it). This is the BMP header created:

UPDATE: Never mind, there are errors everywhere, I'll keep working.

It would be nice if anybody could point me to the problem. If I don't find a solution, I'll code a converter only (not a viewer :wink:.

Thanks,

El_Choni

Edited by - El_Choni on 26 February 2002 03:40:52
Hi, i've created bmp files in PB that is usable with the inbuild command LoadImage() i used the following Structure for the BMP header:

Code: Select all

;bitmap file header
  bfType.w          ; Identifier contains 'BM' for bitmapfiles
  bfSize.l          ; Total size of BMP file
  bfReserved1.w     ; ?
  bfReserved2.w     ; ?
  bfOffBits.l       ; Offset to RGB data? (or colortable if it exist?)
;bitmap info header
  biSize.l          ; Size of 'bitmap info header'
  biWidth.l         ; Width of picture
  biHeight.l        ; Height of picture
  biPlanes.w        ; Nr of planes in picture (use 1)
  biBitCount.w      ; Nr of bits per pixel 1,2,4,8,16,24,32 (use 24)
  biCompression.l   ; Which compression method 0=none (use 0)
  biSizeImage.l     ; Size of RGB data (=biWidth*biHeight*biBitcount>>3)
  biXPelsPerMeter.l ; ? (just set all below to 0)
  biYPelsPerMeter.l ; ?
  biClrUsed.l       ; ?
  biClrImportant.l  ; ?
EndStructure
After the header above the RGB data follows. The easiest format for a BMP file is the 24bit uncompressed kind, you can't go wrong with it. Also not that the top of the RGB-data is the bottom-left corner of your picture..

Posted: Wed Feb 27, 2002 4:45 am
by BackupUser
Restored from previous forum. Originally posted by WolfgangS.

HI !
for better understanding my (Blitzbasic :wink: Source snipped of my C64font2bmp converter. It is a 1 plane 2 color Bitmap.


Data $42 ,$4d ; ID = BM
Data 0 ,$00,$00,$00 ; Length of all data´s (whole Pic+Header)
Data $00 ,$00 ; n/u
Data $00 ,$00 ; n/u
Data 14+40+8,$00,$00,$00 ; Offset to the Picdata
; BitMapInfoHeader
Data 40 ,$00,$00,$00 ; Length of BitMapInfoHeader 40 = Type "Windows"
Data 0 ,$00,$00,$00 ; x size of of Pic
Data 0 ,$00,$00,$00 ; y size of Pic
Data 1 ,$00 ; Number of Planes
Data 1 ,$00 ; Numper of Bits/Pixel
Data 0 ,$00,$00,$00 ; 0 = no kompression
Data 0 ,$00,$00,$00 ; Size = (x/4*y) in pixel
Data 0 ,$00,$00,$00 ; x size
Data 8 ,$00,$00,$00 ; y size
Data 0 ,$00,$00,$00 ; all used colors 0 = all
Data 0 ,$00,$00,$00 ; all important colors 0 = all
; ab hier 54 $38
Data $00 ,$00,$00,$00 ; color 1 = RGB + 1 padding byte
Data $50 ,$00,$00,$00 ; color 2 = RGB + 1 padding byte

(BOF) here is the pic (don't forget the padding bytes !!!!!!!!!!!!!)
; data ...



MFG
Wolfi

Posted: Wed Feb 27, 2002 11:54 am
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Thanks a lot for your help!

It already works for 4 and 8 bit images, although it's very slow, maybe a library for conversion would be handy here, maybe I'll give it a try. Anyway, when I get this working, I'll post the 'standalone' and 'apiless' code regardless I do the lib or not.

El_Choni

Edited by - El_Choni on 27 February 2002 14:34:47

Posted: Wed Feb 27, 2002 5:50 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

Just post it, so we could try to optimize it a bit :)

Fred - AlphaSND

Posted: Thu Feb 28, 2002 3:12 am
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

1, 24 and 32 bpp working, 16 bpp is giving me a headache. Of course I'll post it when it's finished so you can optimize it, if you're so kind to do it. Or I'll post it when I'm desperate and can't make it work :wink: (well, I can always drop 16 bpp support XD).

UPDATE: 16 bpp working, I'll post human-readable code soon.

Many thanks, bye,

El_Choni

Edited by - El_Choni on 28 February 2002 18:03:01