Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help :-(
#1
I've been racking my brains on this stupid conversion for months, everything I try to fix it fails. Qbasic code:

'$DYNAMIC
DEFINT A-Z
DIM Byte AS STRING * 1
SCREEN 13
OPEN p$ + ".bmp" FOR BINARY AS #1
GET #1, 1, ftype: GET #1, 29, bits
FOR attr = 0 TO 255
OUT &H3C8, attr
FOR rgb = 1 TO 3
GET #1, attr * 4 + 58 - rgb, Byte
OUT &H3C9, INT(ASC(Byte) * .2471)
NEXT
NEXT
GET #1, 19, xsz: GET #1, 23, ysz
FOR ypl& = 1 TO ysz
IF ypl& > 200 THEN EXIT FOR
FOR xpl& = 1 TO xsz
IF xpl& > 320 THEN EXIT FOR
bpl& = LOF(1) - (ypl& * (3 - (xsz + 3) MOD 4)) - ypl& * xsz + xpl&
GET #1, bpl&, attr
PSET (xpl& - 1, ypl& - 1), attr
NEXT
NEXT
CLOSE #1

This code works beautifully. Now here is the FB port, as far as I can tell it is a perfect conversion, but the image is upside down and has black streaks running through it:

SCREEN 13
open "c:\lefty.bmp" for binary as #1
dim xsz as short, ysz as short, ypl as integer, xpl as integer, bpl as integer, attr as short
dim ftype as short, bits as short, Bytes as String * 1, r as short, g as short, b as short
GET #1, 1, ftype: GET #1, 29, bits
FOR attr = 0 TO 255
OUT &H3C8, attr
GET #1, attr * 4 + 58 - 1, Bytes
r = int(ASC(Bytes) * .2471)
GET #1, attr * 4 + 58 - 2, Bytes
g = int(ASC(Bytes) * .2471)
GET #1, attr * 4 + 58 - 3, Bytes
b = int(ASC(Bytes) * .2471)
PALETTE attr,(b * 65536 + g * 256 + r)
NEXT
cGET #1, 19, xsz: GET #1, 23, ysz
FOR ypl = 1 TO ysz
IF ypl > 200 THEN EXIT FOR
FOR xpl = 1 TO xsz
IF xpl > 320 THEN EXIT FOR
bpl = LOF(1) - (ypl * (3 - (xsz + 3) MOD 4)) - ypl * xsz + xpl
GET #1, bpl, attr
PSET (xpl - 1, ypl - 1), attr
NEXT
NEXT
close #1
sleep

:???:
I have the newest version of FB and the image file is a basic 8 bit BMP. I don't want to have to use a library to do something as simple as load a bitmap. Could somebody please help me fix this, or at least send me a working bitmap loader?
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#2
both your port and this work fine for me:
Code:
'$DYNAMIC
DEFSHORT A-Z
DIM Byt AS STRING * 1
p$ = "c:/fb/flag"
SCREEN 13
OPEN p$ + ".bmp" FOR BINARY AS #1
GET #1, 1, ftype: GET #1, 29, bits
FOR attr = 0 TO 255
OUT &H3C8, attr
FOR _rgb = 1 TO 3
GET #1, attr * 4 + 58 - _rgb, Byt
OUT &H3C9, INT(ASC(Byt) * .2471)
NEXT
NEXT
GET #1, 19, xsz: GET #1, 23, ysz
FOR ypl& = 1 TO ysz
IF ypl& > 200 THEN EXIT FOR
FOR xpl& = 1 TO xsz
IF xpl& > 320 THEN EXIT FOR
bpl& = LOF(1) - (ypl& * (3 - (xsz + 3) MOD 4)) - ypl& * xsz + xpl&
GET #1, bpl&, attr
PSET (xpl& - 1, ypl& - 1), attr
NEXT
NEXT
CLOSE #1
sleep

care to post your bitmap somewhere?
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply
#3
Quote:r = int(ASC(Bytes) * .2471)
r = INT(ASC(Bytes) / 255.0 * 63.0)
Reply
#4
There are a bunch of bitmaps on my website that I have tried, take any of the 320x200 ones on my homepage

www.freewebs.com/wallacesoftware
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#5
Quote:I've been racking my brains on this stupid conversion for months, everything I try to fix it fails. Qbasic code:

'$DYNAMIC
DEFINT A-Z
DIM Byte AS STRING * 1
SCREEN 13
OPEN p$ + ".bmp" FOR BINARY AS #1
GET #1, 1, ftype: GET #1, 29, bits
FOR attr = 0 TO 255
OUT &H3C8, attr
FOR rgb = 1 TO 3
GET #1, attr * 4 + 58 - rgb, Byte
OUT &H3C9, INT(ASC(Byte) * .2471)
NEXT
NEXT
GET #1, 19, xsz: GET #1, 23, ysz
FOR ypl& = 1 TO ysz
IF ypl& > 200 THEN EXIT FOR
FOR xpl& = 1 TO xsz
IF xpl& > 320 THEN EXIT FOR
bpl& = LOF(1) - (ypl& * (3 - (xsz + 3) MOD 4)) - ypl& * xsz + xpl&
GET #1, bpl&, attr
PSET (xpl& - 1, ypl& - 1), attr
NEXT
NEXT
CLOSE #1

This code works beautifully. Now here is the FB port, as far as I can tell it is a perfect conversion, but the image is upside down and has black streaks running through it:

SCREEN 13
open "c:\lefty.bmp" for binary as #1
dim xsz as short, ysz as short, ypl as integer, xpl as integer, bpl as integer, attr as short
dim ftype as short, bits as short, Bytes as String * 1, r as short, g as short, b as short
GET #1, 1, ftype: GET #1, 29, bits
FOR attr = 0 TO 255
OUT &H3C8, attr
GET #1, attr * 4 + 58 - 1, Bytes
r = int(ASC(Bytes) * .2471)
GET #1, attr * 4 + 58 - 2, Bytes
g = int(ASC(Bytes) * .2471)
GET #1, attr * 4 + 58 - 3, Bytes
b = int(ASC(Bytes) * .2471)
PALETTE attr,(b * 65536 + g * 256 + r)
NEXT
cGET #1, 19, xsz: GET #1, 23, ysz
FOR ypl = 1 TO ysz
IF ypl > 200 THEN EXIT FOR
FOR xpl = 1 TO xsz
IF xpl > 320 THEN EXIT FOR
bpl = LOF(1) - (ypl * (3 - (xsz + 3) MOD 4)) - ypl * xsz + xpl
GET #1, bpl, attr
PSET (xpl - 1, ypl - 1), attr
NEXT
NEXT
close #1
sleep

:???:
I have the newest version of FB and the image file is a basic 8 bit BMP. I don't want to have to use a library to do something as simple as load a bitmap. Could somebody please help me fix this, or at least send me a working bitmap loader?

*pokes a newbie helper*



p.s. wallace, dont get me wrong, im not calling you a newbie. but i do believe that this is one of their jobs to put your code in tags.
Reply
#6
Quote:*pokes a newbie helper*
We don't have teh power yet. Wink (You didn't have to quote the entire post, either... Wink )

Haven't tested the code yet, but if dumbledore says it works, I'm inclined to believe him - are your bitmaps created with some special nonstandard bitmap writer, perhaps? I'll test in a bit if I get time...


EDIT: okay, tried your code with the first screenshot on the Contact page (screenshot.bmp) and it worked correctly. What version of FreeBASIC are you using? I compiled with an unmodified 0.14 win32 build.

EDIT2: tried Contact screenshot5.bmp (the BOOM one Smile ) and it also worked correctly.

What OS are you running on? (Win95/98/Me/NT/2000/XP)
Reply
#7
Strange. It seems to work fine for me.

But I don't like the way it's written. Here's what I wrote for you just now:

Code:
Option Explicit
Option Dynamic

Declare Function simpleLoadBMP8 (bmpFile As String) As UByte Ptr

#define UINT unsigned integer

Type tBitMapFileHeader Field = 1
   bfType As Unsigned Short
   bfTotalSize As UINT
   bfReservedI As Unsigned Short
   bfReservedII As Unsigned Short
   bfOffbits As UINT
   biSize As UINT
   biWidth As UINT
   biHeight As UINT
   biPlanes As Unsigned Short
   biBitCount As Unsigned Short
   biCompression As UINT
   biSizeImage As UINT
   biXpixelsPerMeter As UINT
   biYpixelsPerMeter As UINT
   biClrUsed As UINT
   biClrImportant As UINT
End Type

' example (this is how you have to use the code...) DON'T FORGET TO DEALLOCATE
Screen 13
Dim picture As UByte Ptr
picture = simpleLoadBMP8("bloodW.bmp")
Put (0, 0), picture, Pset
deallocate picture

Sleep
End

Private Function simpleLoadBMP8 (bmpFile As String) As UByte Ptr
    Dim head As tBitMapFileHeader, FF As Integer
    FF = FreeFile
    Open bmpFile For Binary As #FF
        ' header
        Get #FF, , head
        If head.bfType <> 19778 Then Return 0: Exit Function
        If head.biBitCount > 8 Then Return 0: Exit Function
        
        ' immediately set palette (UGH... palettes... why not convert it to 24/32 bit?)
        Dim colorIndex As Integer, colors(3) As UByte
        For colorIndex = 0 To (2 ^ head.biBitCount) - 1
            Get #FF, , colors()
            Palette colorIndex, 65536& * Int(colors(0) / 255.0 * 63.0) + _
                                256& * Int(colors(1) / 255.0 * 63.0) + _
                                Int(colors(2) / 255.0 * 63.0)
        Next colorIndex
        
        ' allocate space
        Dim returnPic As UByte Ptr, returnPicS As UShort Ptr
        returnPic = callocate( head.biWidth * head.biHeight + 4 )
        returnPicS = returnPic
        returnPicS[0] = 8 * head.biWidth
        returnPicS[1] = head.biHeight
        
        ' read data
        Dim bmpY As Integer, bmpX As Integer, bmpData As UByte
        For bmpY = head.biHeight - 1 To 0 Step -1
            For bmpX = 0 To head.biWidth - 1
                Get #FF, , bmpData
                returnPic[head.biWidth * bmpY + bmpX + 4] = bmpData
            Next bmpX            
        Next bmpY        
    Close #FF
    Return returnPic
End Function


Btw is converting to 24/32 bits an option? It would make it a lot easier...
Reply
#8
There must be something wrong with my computer or something. I'm on Windows XP Home SP2. Maybe it has something to do that I haven't expanded autoexec._nt. Some of the bitmaps were saved using FB code and some were created with MS Paint, that didn't seem to matter.

Neo, your code worked beautifully, thank you. I'm going to "borrow" it to convert bmps to sprite and texture files in Inspiration so I needed it to stay at 8bit, I hate palettes too.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#9
have you tried just bloading the bmps? in freebasic bload can load bsaved files or bmps Wink
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)