showbmp works but need help with it
Posted: Sun Aug 31, 2008 12:16 pm
this works but how do you get the data from the file
i want to read the pixles and palet
thank
**********code here****
'Show Bitmap 1.1 - by: Peter Swinkels, ***2005***
'These routines can be used to display RGB and RLE encoded Microsoft Windows bitmaps.
DEFINT A-Z
DECLARE SUB GeneratePalette ()
DECLARE SUB SetPalette (PaletteData AS STRING)
DECLARE SUB ShowBitmap (FileName AS STRING)
'Screen mode 12 can be used instead of mode 13 for 16 color (or monochrome) bitmaps.
SCREEN 13: CLS
'Insert the full path and filename for the bitmap to be displayed between the quotes.
ShowBitmap ""
SUB GeneratePalette
'This procedure generates a default palette.
DIM Blue AS INTEGER, Green AS INTEGER, Red AS INTEGER
DIM Brightness AS INTEGER, Entry AS INTEGER
Entry = 0
FOR Brightness = 0 TO 3
FOR Red = 0 TO 3
FOR Green = 0 TO 3
FOR Blue = 0 TO 3
PALETTE Entry, (CLNG((Blue + Brightness) * 10.5) * 65536) + (CLNG((Green + Brightness) * 10.5) * 256) + CLNG((Red + Brightness) * 10.5)
Entry = Entry + 1
NEXT Blue
NEXT Green
NEXT Red
NEXT Brightness
END SUB
SUB SetPalette (PaletteData AS STRING)
'This procedure sets the palette to match the bitmap's palette.
SHARED IndexCount
DIM Blue AS INTEGER, Green AS INTEGER, Red AS INTEGER
DIM Entry AS INTEGER, NewPalette(255) AS LONG
FOR Entry = 0 TO IndexCount - 1
Red = ASC(MID$(PaletteData, (Entry * 4) + 1, 1)) \ 4
Green = ASC(MID$(PaletteData, (Entry * 4) + 2, 1)) \ 4
Blue = ASC(MID$(PaletteData, (Entry * 4) + 3, 1)) \ 4
NewPalette(Entry) = (Red * 65536) + (Green * 256) + Blue
NEXT Entry
PALETTE USING NewPalette
END SUB
SUB ShowBitmap (FileName AS STRING)
'This procedure displays the specified bitmap.
SHARED IndexCount
DIM BitMask AS INTEGER, BitsPerPixel AS INTEGER, BytesPerPixel AS INTEGER, PixelsPerByte AS DOUBLE
DIM Blue AS INTEGER, Brightness AS INTEGER, Green AS INTEGER, Red AS INTEGER
DIM Byte AS LONG, Byte1 AS LONG, Byte2 AS LONG, Column AS LONG, Pixel AS INTEGER
DIM Compression AS INTEGER, Hght AS LONG, Padding AS LONG, PaletteData AS STRING, PixelData AS STRING, Wdth AS LONG
DIM x AS LONG, y AS LONG
'Checks if the specified file exists.
OPEN FileName FOR INPUT AS 1: CLOSE 1
'Loads and displays the specified bitmap.
OPEN "c:\5bmp.bmp" FOR BINARY AS 1
'Checks the file format.
SEEK #1, 1
IF INPUT$(2, 1) = "BM" THEN
'Gets the bitmap's compression type.
SEEK #1, 31
Compression = ASC(INPUT$(1, 1))
'Gets the width and height of the bitmap.
SEEK #1, 19
Wdth = CVL(INPUT$(4, 1))
Hght = CVL(INPUT$(4, 1))
'Gets the number of bits per pixel (color depth.)
SEEK #1, 29
BitsPerPixel = ASC(INPUT$(1, 1))
'Calculates the number of bytes per pixel.
BytesPerPixel = BitsPerPixel / 8
IF BytesPerPixel <1>= LOF(1)
Byte1 = ASC(INPUT$(1, 1))
Byte2 = ASC(INPUT$(1, 1))
IF Byte1 = 0 AND Byte2 <2> 2 THEN 'Checks whether absolute mode is used.
Byte2 = Byte2 / PixelsPerByte
PixelData = INPUT$(Byte2, 1)
FOR Byte = 1 TO Byte2 STEP PixelsPerByte
IF BitsPerPixel = 4 THEN BitMask = 240
IF BitsPerPixel = 8 THEN BitMask = 255
FOR Pixel = 0 TO PixelsPerByte - 1
IF Byte + Pixel = Byte2 THEN EXIT FOR
PSET ((x * PixelsPerByte) + Pixel, y), (ASC(MID$(PixelData, Byte + Pixel, 1)) AND BitMask) \ (BitMask \ (IndexCount - 1))
BitMask = BitMask \ IndexCount
NEXT Pixel
x = x + BytesPerPixel
NEXT Byte
''' x = x + 1
IF Byte2 MOD 2 > 0 THEN SEEK #1, SEEK(1) + 1
ELSEIF Byte1 > 0 THEN 'Checks whether encoded mode is used.
FOR Column = 1 TO Byte1 STEP PixelsPerByte
IF BitsPerPixel = 4 THEN BitMask = 240
IF BitsPerPixel = 8 THEN BitMask = 255
FOR Pixel = 0 TO PixelsPerByte - 1
IF Byte + Pixel = Byte1 THEN EXIT FOR
PSET ((x * PixelsPerByte) + Pixel, y), (Byte2 AND BitMask) \ (BitMask \ (IndexCount - 1))
BitMask = BitMask \ IndexCount
NEXT Pixel
x = x + BytesPerPixel
NEXT Column
END IF
LOOP
END IF
END IF
CLOSE 1
END SUB
i want to read the pixles and palet
thank
**********code here****
'Show Bitmap 1.1 - by: Peter Swinkels, ***2005***
'These routines can be used to display RGB and RLE encoded Microsoft Windows bitmaps.
DEFINT A-Z
DECLARE SUB GeneratePalette ()
DECLARE SUB SetPalette (PaletteData AS STRING)
DECLARE SUB ShowBitmap (FileName AS STRING)
'Screen mode 12 can be used instead of mode 13 for 16 color (or monochrome) bitmaps.
SCREEN 13: CLS
'Insert the full path and filename for the bitmap to be displayed between the quotes.
ShowBitmap ""
SUB GeneratePalette
'This procedure generates a default palette.
DIM Blue AS INTEGER, Green AS INTEGER, Red AS INTEGER
DIM Brightness AS INTEGER, Entry AS INTEGER
Entry = 0
FOR Brightness = 0 TO 3
FOR Red = 0 TO 3
FOR Green = 0 TO 3
FOR Blue = 0 TO 3
PALETTE Entry, (CLNG((Blue + Brightness) * 10.5) * 65536) + (CLNG((Green + Brightness) * 10.5) * 256) + CLNG((Red + Brightness) * 10.5)
Entry = Entry + 1
NEXT Blue
NEXT Green
NEXT Red
NEXT Brightness
END SUB
SUB SetPalette (PaletteData AS STRING)
'This procedure sets the palette to match the bitmap's palette.
SHARED IndexCount
DIM Blue AS INTEGER, Green AS INTEGER, Red AS INTEGER
DIM Entry AS INTEGER, NewPalette(255) AS LONG
FOR Entry = 0 TO IndexCount - 1
Red = ASC(MID$(PaletteData, (Entry * 4) + 1, 1)) \ 4
Green = ASC(MID$(PaletteData, (Entry * 4) + 2, 1)) \ 4
Blue = ASC(MID$(PaletteData, (Entry * 4) + 3, 1)) \ 4
NewPalette(Entry) = (Red * 65536) + (Green * 256) + Blue
NEXT Entry
PALETTE USING NewPalette
END SUB
SUB ShowBitmap (FileName AS STRING)
'This procedure displays the specified bitmap.
SHARED IndexCount
DIM BitMask AS INTEGER, BitsPerPixel AS INTEGER, BytesPerPixel AS INTEGER, PixelsPerByte AS DOUBLE
DIM Blue AS INTEGER, Brightness AS INTEGER, Green AS INTEGER, Red AS INTEGER
DIM Byte AS LONG, Byte1 AS LONG, Byte2 AS LONG, Column AS LONG, Pixel AS INTEGER
DIM Compression AS INTEGER, Hght AS LONG, Padding AS LONG, PaletteData AS STRING, PixelData AS STRING, Wdth AS LONG
DIM x AS LONG, y AS LONG
'Checks if the specified file exists.
OPEN FileName FOR INPUT AS 1: CLOSE 1
'Loads and displays the specified bitmap.
OPEN "c:\5bmp.bmp" FOR BINARY AS 1
'Checks the file format.
SEEK #1, 1
IF INPUT$(2, 1) = "BM" THEN
'Gets the bitmap's compression type.
SEEK #1, 31
Compression = ASC(INPUT$(1, 1))
'Gets the width and height of the bitmap.
SEEK #1, 19
Wdth = CVL(INPUT$(4, 1))
Hght = CVL(INPUT$(4, 1))
'Gets the number of bits per pixel (color depth.)
SEEK #1, 29
BitsPerPixel = ASC(INPUT$(1, 1))
'Calculates the number of bytes per pixel.
BytesPerPixel = BitsPerPixel / 8
IF BytesPerPixel <1>= LOF(1)
Byte1 = ASC(INPUT$(1, 1))
Byte2 = ASC(INPUT$(1, 1))
IF Byte1 = 0 AND Byte2 <2> 2 THEN 'Checks whether absolute mode is used.
Byte2 = Byte2 / PixelsPerByte
PixelData = INPUT$(Byte2, 1)
FOR Byte = 1 TO Byte2 STEP PixelsPerByte
IF BitsPerPixel = 4 THEN BitMask = 240
IF BitsPerPixel = 8 THEN BitMask = 255
FOR Pixel = 0 TO PixelsPerByte - 1
IF Byte + Pixel = Byte2 THEN EXIT FOR
PSET ((x * PixelsPerByte) + Pixel, y), (ASC(MID$(PixelData, Byte + Pixel, 1)) AND BitMask) \ (BitMask \ (IndexCount - 1))
BitMask = BitMask \ IndexCount
NEXT Pixel
x = x + BytesPerPixel
NEXT Byte
''' x = x + 1
IF Byte2 MOD 2 > 0 THEN SEEK #1, SEEK(1) + 1
ELSEIF Byte1 > 0 THEN 'Checks whether encoded mode is used.
FOR Column = 1 TO Byte1 STEP PixelsPerByte
IF BitsPerPixel = 4 THEN BitMask = 240
IF BitsPerPixel = 8 THEN BitMask = 255
FOR Pixel = 0 TO PixelsPerByte - 1
IF Byte + Pixel = Byte1 THEN EXIT FOR
PSET ((x * PixelsPerByte) + Pixel, y), (Byte2 AND BitMask) \ (BitMask \ (IndexCount - 1))
BitMask = BitMask \ IndexCount
NEXT Pixel
x = x + BytesPerPixel
NEXT Column
END IF
LOOP
END IF
END IF
CLOSE 1
END SUB