December 03, 2020, 08:17:35 PM

Author Topic: [bmx] Bitmaps in DefData statements by matibee [ 1+ years ago ]  (Read 602 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Bitmaps in DefData statements
Author : matibee
Posted : 1+ years ago

Description : This contribution provides utility and code for converting bitmaps into DefData statements which you can embed into your forum posts.  This makes it possible to post your code as text-only without relying on external image hosting.

** DISCLAIMER ** This is only really suitable for small graphic files such as sprites and tiles due to the nature and size of the DefData statments.

The code below is for a drag and drop utility that creates the DefData statements from the target image.  Notice how the first line is a label that reflects the bitmap filename.  This is used to locate the correct data when using multiple embedded images.

Here is a quick sample from which you'll need to copy the DataToImage function.

Code: [Select]
SuperStrict
Graphics 200, 200

' Point to the image data...
RestoreData brick2_tga
' Load the image
Local b:TImage = DataToImage()

' Point to another image..
RestoreData circle_tga
' Load another image
Local c:TImage = DataToImage()

'------------------------------------------------------------------------------------
'
' Really simple demo..
'
Local tileoffset:Float = 0
While Not AppTerminate()
Cls
SetBlend( ALPHABLEND )
For Local i:Int = 0 To 8
For Local j:Int = 0 To 16
DrawImage( b, i * 32, (j * 16) - tileoffset )
Next
Next

DrawImage( c, MouseX() - 16, MouseY() - 16 )
Flip 1
tileoffset :- 0.5
If tileoffset < 0
tileoffset :+ 16
End If
Wend


'------------------------------------------------------------------------------------
'
' Use this function to "Load" an image once you have pointed RestoreData to your
' required data
'
Function DataToImage:TImage( flags:Int = -1 )
Local myhex$ = "0123456789ABCDEF"
Local w:Int, h:Int, line$
ReadData w
ReadData h
Local img:TImage = CreateImage( w, h, 1, flags )
Local tp:TPixmap = LockImage( img )
For Local y:Int = 0 To h - 1
ReadData line$
For Local x:Int = 0 To w - 1
Local word$ = Mid$( line$, x * 8 + 1, 8 )
Local pixel:Int = 0
Local shift:Int = 28
For Local i:Int = 1 To 8
pixel :+ (Instr( myhex$, Mid$(word$, i, 1) ) - 1) Shl shift
shift :- 4
Next
WritePixel( tp, x, y, pixel )
Next
Next
UnlockImage( img )
Return img
End Function


'------------------------------------------------------------------------------------
'
' Some "Image" data provided by the conversion utility
'
'
#brick2_tga
DefData 32, 16
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF3FDFECF899D9E9F799CEE3F499CCE1F499CCE1F499CCE1F499CBE1F499CCE1F499CDE2F499CDE2F499CCE1F499CDE2F499CDE2F499CDE2F499CDE2F499CCE2F499CCE1F499CCE1F499CCE2F499CCE2F499CDE2F499CDE2F499CCE2F499CBE1F499CBE1F499CAE0F499BDD9F15A9BC5E900FFFFFF00FFFFFF"
DefData "00FFFFFF1BC8DFF3F9D4E6F6FFE1EDF8FFD4E6F6FFD2E5F5FFD2E5F5FFD1E4F5FFD1E4F5FFD1E4F5FFD3E5F5FFD2E5F5FFD1E4F5FFD2E5F5FFD3E6F6FFD3E6F6FFD3E5F5FFD2E5F5FFD2E5F5FFD1E5F5FFD2E5F5FFD3E5F5FFD3E6F6FFD4E6F6FFD2E5F5FFD1E4F5FFD1E4F5FFCEE3F4FFB4D4EFFF6A87A1423A4B5900FFFFFF"
DefData "00FFFFFF4BABCFEDFFB4D4EFFFD7E8F6FFCCE2F4FFCAE0F4FFCAE0F4FFCAE0F4FFCAE0F4FFCCE1F4FFCDE2F4FFCBE1F4FFC9E0F3FFCCE1F4FFCEE3F4FFCEE3F4FFCDE2F4FFCCE1F4FFCBE1F4FFC9E0F3FFC9E0F3FFCBE1F4FFCBE1F4FFCCE1F4FFCAE0F4FFC9E0F3FFC9E0F3FFC8DFF3FF88AECFFF27323B8127323B00FFFFFF"
DefData "00FFFFFF4B9DC6EAFF9FC8EAFFAFD1EEFF9BC5E9FF9EC7EAFF9DC7EAFF9CC6EAFF9CC6EAFF9BC5EAFF99C4E9FF95BFE4FF94BEE2FF9AC5E9FFA0C8EBFFA2C9EBFFA3CAEBFFA0C8EAFF9CC6EAFF99C4E9FF97C2E6FF96C0E4FF96C0E4FF97C2E6FF98C2E7FF99C4E9FF99C4E9FF95BFE3FF445767FF27323B8727323B00FFFFFF"
DefData "00FFFFFF4B9BC5E9FF9EC7EAFFAFD1EEFFA0C8EAFFA3CAEBFFA0C8EAFF9DC6EAFF9BC5EAFF99C4E9FF93BCE0FF92BCDFFF94BDE1FF9BC5E9FFA1C8EBFFA3CAEBFFA5CBECFFA2C9EBFF9DC7EAFF99C4E9FF97C1E5FF95BFE3FF97C1E5FF98C3E8FF98C3E8FF97C1E5FF90B8DBFF88AECFFF3B4C5AFF27323B8727323B00FFFFFF"
DefData "00FFFFFF4B9AC5E9FF9DC6EAFFADD0EDFFA0C8EAFFA1C9EBFF9DC6EAFF9BC5E9FF9BC5E9FF9AC4E9FF97C1E5FF99C4E9FF9CC6EAFF9FC7EAFF9FC8EAFF9FC7EAFFA1C8EBFF9FC8EAFF9DC6EAFF99C4E9FF96C0E4FF95BFE3FF96C0E4FF97C1E5FF91BADDFF86ACCDFF7B9EBBFF7393AFFF303D49FF27323B8727323B00FFFFFF"
DefData "00FFFFFF4B9CC6EAFF9EC7EAFFAFD0EEFFA1C9EBFFA1C8EBFF9CC6EAFF9AC5E9FF9DC6EAFF9DC6EAFF9BC5E9FF9EC7EAFFA2C9EBFFA1C9EBFF9EC7EAFF9CC6EAFF9DC6EAFF9CC6EAFF9BC5E9FF98C3E8FF94BDE1FF93BCE0FF95BFE3FF98C2E7FF91BADDFF85ABCBFF7C9EBCFF7799B6FF34424FFF27323B8727323B00FFFFFF"
DefData "00FFFFFF4B9FC7EAFFA1C9EBFFB3D3EFFFA4CAEBFFA3CAEBFF9EC7EAFF9CC6EAFF9FC8EAFFA1C8EBFF9FC8EAFFA2C9EBFFA4CAEBFFA1C8EBFF9CC6EAFF9BC5EAFF9AC5E9FF98C3E8FF98C3E8FF94BEE2FF91B9DCFF91BADDFF95BFE4FF9BC5E9FF99C4E9FF94BEE2FF93BCE0FF94BDE1FF46596AFF27323B8727323B00FFFFFF"
DefData "00FFFFFF4B9FC7EAFFA2C9EBFFB4D4EFFFA2C9EBFF9FC8EAFF99C4E9FF97C1E5FF9BC5E9FF9BC5E9FF99C4E9FF9BC5EAFF9DC6EAFF9BC5E9FF98C3E8FF99C4E9FF99C4E9FF98C3E8FF97C2E6FF8FB8DAFF8BB2D3FF8EB6D9FF97C1E5FF9DC6EAFF9DC6EAFF99C4E9FF9AC4E9FF9BC5E9FF4C6173FF27323B8727323B00FFFFFF"
DefData "00FFFFFF4B9DC7EAFFA1C8EBFFB3D3EFFF9DC6EAFF98C3E8FF8EB6D9FF8CB3D5FF8EB6D9FF8CB3D5FF89B0D1FF8CB3D5FF8FB8DAFF8FB8DAFF92BBDEFF98C2E7FF9BC5E9FF9BC5E9FF97C2E6FF89B0D1FF85AACAFF8DB5D7FF98C3E8FF9FC7EAFF9DC6EAFF99C4E9FF98C3E8FF98C2E7FF495E6FFF27323B8727323B00FFFFFF"
DefData "00FFFFFF4B9CC6EAFF9FC8EAFFB3D3EFFF9DC6EAFF97C1E5FF8EB5D8FF8BB2D3FF8BB2D4FF8AB1D2FF8BB2D4FF8BB2D4FF8AB1D2FF89B0D1FF8CB3D5FF91BADDFF95BFE4FF97C2E6FF93BCE0FF85ABCBFF83A8C7FF8BB2D4FF96C0E4FF9DC6EAFF9CC6EAFF99C4E9FF98C2E7FF95BFE3FF405262FF27323B8727323B00FFFFFF"
DefData "00FFFFFF4B8DB5D7FF8AB1D2FF8AB1D2FF648098FF5E798FFF566F84FF536B7FFF546C80FF576F84FF5A7389FF566F84FF4F6579FF4C6274FF4D6275FF50677AFF556C81FF576F84FF546C80FF4B6072FF495E6FFF50677AFF597388FF648098FF66839BFF65819AFF617C93FF52697CFF27323BFF27323B8427323B00FFFFFF"
DefData "00FFFFFF2A5F7A91FF3E505FFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323BFF27323B5727323B00FFFFFF"
DefData "00FFFFFF00FFFFFF6C27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323BCC27323B8D27323B0327323B00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"


#circle_tga
DefData 32, 32
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF01E1B3BB01E1B3BB03E1B3BB03E1B3BB02E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF03E1B3BB04E1B3BB0CE1B3BB1EE1B3BB2FE1B3BB39E1B3BB33E1B3BB24E1B3BB15E1B3BB09E1B3BB04E1B3BB02E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB10E1B3BB36E1B3BB61E1B3BB88E1B3BBA3E1B3BBB3E1B3BBC0E1B3BBB8E1B3BBA8E1B3BB95E1B3BB70E1B3BB44E1B3BB1DE1B3BB07E1B3BB01E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF0CE1B3BB38E1B3BB7BE1B3BBBAE1B3BBE3E1B3BBFDE1B3BBF5E1B3BBEAE1B3BBE2E1B3BBE9E1B3BBEFE1B3BBF8E1B3BBEAE1B3BBC9E1B3BB92E1B3BB4DE1B3BB17E1B3BB04E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF03E1B3BB1EE1B3BB63E1B3BBB4E1B3BBEAE1B3BBE7E1B3BBC8E1B3BB9BE1B3BB7CE1B3BB6DE1B3BB64E1B3BB6AE1B3BB75E1B3BB92E1B3BBB8E1B3BBDBE1B3BBEBE1B3BBC8E1B3BB7FE1B3BB31E1B3BB09E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB22E1B3BB82E1B3BBD4E1B3BBE2E1B3BBBEE1B3BB7FE1B3BB46E1B3BB1BE1B3BB0AE1B3BB07E1B3BB05E1B3BB05E1B3BB07E1B3BB15E1B3BB37E1B3BB69E1B3BBABE1B3BBE0E1B3BBE1E1B3BBA4E1B3BB39E1B3BB07E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF01E1B3BB1AE1B3BB7BE1B3BBDDE1B3BBE1E1B3BB9AE1B3BB47E1B3BB12E1B3BB04E1B3BB01E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB0CE1B3BB2FE1B3BB79E1B3BBCBE1B3BBF0E1B3BBA2E1B3BB35E1B3BB07E1B3BB00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF0FE1B3BB68E1B3BBD8E1B3BBDFE1B3BB8BE1B3BB2AE1B3BB08E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF03E1B3BB15E1B3BB66E1B3BBD2E1B3BBE9E1B3BB97E1B3BB25E1B3BB02E1B3BB00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF06E1B3BB44E1B3BBC3E1B3BBEDE1B3BB9BE1B3BB28E1B3BB06E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB15E1B3BB70E1B3BBD3E1B3BBD9E1B3BB6AE1B3BB10E1B3BB00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF01E1B3BB18E1B3BB8EE1B3BBEAE1B3BBB9E1B3BB40E1B3BB07E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF01E1B3BB1FE1B3BB8EE1B3BBE2E1B3BBB6E1B3BB38E1B3BB02E1B3BB00FFFFFF"
DefData "00FFFFFF00FFFFFF02E1B3BB42E1B3BBC2E1B3BBDEE1B3BB6FE1B3BB0DE1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF07E1B3BB45E1B3BBC0E1B3BBE1E1B3BB6BE1B3BB0AE1B3BB00FFFFFF"
DefData "00FFFFFF00FFFFFF08E1B3BB6FE1B3BBE2E1B3BBB8E1B3BB35E1B3BB02E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB18E1B3BB8EE1B3BBE9E1B3BB9EE1B3BB21E1B3BB02E1B3BB"
DefData "00FFFFFF01E1B3BB18E1B3BB92E1B3BBEAE1B3BB8CE1B3BB14E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF08E1B3BB60E1B3BBDAE1B3BBC6E1B3BB43E1B3BB03E1B3BB"
DefData "00FFFFFF02E1B3BB2CE1B3BBACE1B3BBE3E1B3BB70E1B3BB07E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF04E1B3BB45E1B3BBC8E1B3BBD7E1B3BB5BE1B3BB04E1B3BB"
DefData "00FFFFFF02E1B3BB45E1B3BBC7E1B3BBDFE1B3BB69E1B3BB06E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB33E1B3BBB6E1B3BBE3E1B3BB66E1B3BB06E1B3BB"
DefData "00FFFFFF04E1B3BB57E1B3BBE2E1B3BBEAE1B3BB6FE1B3BB06E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB2DE1B3BBAFE1B3BBE8E1B3BB6CE1B3BB05E1B3BB"
DefData "00FFFFFF03E1B3BB42E1B3BBC9E1B3BBE5E1B3BB68E1B3BB07E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF01E1B3BB35E1B3BBB7E1B3BBE2E1B3BB65E1B3BB06E1B3BB"
DefData "00FFFFFF02E1B3BB2AE1B3BBB0E1B3BBEBE1B3BB75E1B3BB07E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF04E1B3BB45E1B3BBC8E1B3BBD6E1B3BB56E1B3BB04E1B3BB"
DefData "00FFFFFF00FFFFFF17E1B3BB95E1B3BBF4E1B3BB90E1B3BB18E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF05E1B3BB63E1B3BBE0E1B3BBC2E1B3BB3FE1B3BB02E1B3BB"
DefData "00FFFFFF00FFFFFF0AE1B3BB6CE1B3BBE5E1B3BBBFE1B3BB3FE1B3BB04E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF15E1B3BB92E1B3BBFAE1B3BB9AE1B3BB18E1B3BB01E1B3BB"
DefData "00FFFFFF00FFFFFF04E1B3BB3AE1B3BBBEE1B3BBE3E1B3BB7AE1B3BB10E1B3BB01E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF06E1B3BB4FE1B3BBCCE1B3BBE8E1B3BB6CE1B3BB08E1B3BB00FFFFFF"
DefData "00FFFFFF00FFFFFF01E1B3BB13E1B3BB81E1B3BBECE1B3BBBBE1B3BB41E1B3BB07E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB25E1B3BB9AE1B3BBEAE1B3BBB0E1B3BB30E1B3BB02E1B3BB00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF03E1B3BB39E1B3BBB7E1B3BBE4E1B3BB9CE1B3BB30E1B3BB06E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB18E1B3BB74E1B3BBD8E1B3BBD5E1B3BB5FE1B3BB0BE1B3BB00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF0EE1B3BB64E1B3BBD4E1B3BBE7E1B3BB96E1B3BB32E1B3BB09E1B3BB01E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB1BE1B3BB74E1B3BBCEE1B3BBE0E1B3BB8FE1B3BB1EE1B3BB01E1B3BB00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF01E1B3BB1DE1B3BB79E1B3BBD4E1B3BBDFE1B3BBA6E1B3BB50E1B3BB16E1B3BB04E1B3BB02E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF01E1B3BB04E1B3BB0EE1B3BB34E1B3BB89E1B3BBDCE1B3BBEAE1B3BBA0E1B3BB31E1B3BB05E1B3BB00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB1BE1B3BB70E1B3BBD0E1B3BBF9E1B3BBCCE1B3BB84E1B3BB4FE1B3BB26E1B3BB0DE1B3BB06E1B3BB06E1B3BB06E1B3BB0AE1B3BB1DE1B3BB3FE1B3BB71E1B3BBB2E1B3BBE9E1B3BBE7E1B3BB93E1B3BB31E1B3BB07E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB17E1B3BB57E1B3BBB0E1B3BBE3E1B3BBE9E1B3BBCCE1B3BBA5E1B3BB83E1B3BB73E1B3BB6DE1B3BB70E1B3BB7DE1B3BB99E1B3BBBEE1B3BBDEE1B3BBE4E1B3BBC3E1B3BB7BE1B3BB24E1B3BB03E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF01E1B3BB0AE1B3BB30E1B3BB74E1B3BBACE1B3BBD5E1B3BBE7E1B3BBEBE1B3BBE5E1B3BBE0E1B3BBE2E1B3BBEAE1B3BBEBE1B3BBDCE1B3BBBBE1B3BB87E1B3BB46E1B3BB16E1B3BB02E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB11E1B3BB2EE1B3BB58E1B3BB7AE1B3BB91E1B3BBA2E1B3BBABE1B3BBA6E1B3BB97E1B3BB83E1B3BB65E1B3BB3CE1B3BB1AE1B3BB06E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF02E1B3BB05E1B3BB0AE1B3BB13E1B3BB22E1B3BB29E1B3BB26E1B3BB19E1B3BB0DE1B3BB06E1B3BB03E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"
DefData "00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF01E1B3BB01E1B3BB01E1B3BB02E1B3BB00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF"


Code :
Code: BlitzMax
  1. SuperStrict
  2. Import MaxGui.Drivers
  3.  
  4. Global window:TGadget = CreateWindow:TGadget("Blitzmax image to data utility.  Drag file below...",60,60,320,320,Null,WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_CLIENTCOORDS|WINDOW_ACCEPTFILES)
  5. Global te:TGadget = CreateTextArea:TGadget( 10, 10, 300, 300, window:TGadget )
  6. SetGadgetLayout( te, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED )
  7.  
  8. Repeat
  9.         WaitEvent()
  10.         Select EventID()
  11.                 Case EVENT_WINDOWACCEPT
  12.                         Local file$ = EventExtra().tostring()
  13.                         Print file$
  14.                         Local image:TImage = LoadImage(file)
  15.                         If image <> Null
  16.                                 Local txt$ = StripDir( file$ )
  17.                                 txt$ = Replace( txt$, ".", "_" )
  18.                                 txt$ = Replace( txt$, " ", "_" )
  19.                                 txt$ = "#" + txt$ + "~n"
  20.                                 txt$ :+ "DefData " + ImageWidth( image ) + ", " + ImageHeight( image ) + "~n"
  21.                                 Local tp:TPixmap = LockImage( image )
  22.                                 For Local y:Int = 0 To ImageHeight( image ) - 1
  23.                                         Local rowstring$ = "DefData ~q"
  24.                                         For Local x:Int = 0 To ImageWidth( image ) - 1
  25.                                                 rowstring :+ Hex$( ReadPixel( tp, x, y ) )
  26.                                         Next
  27.                                         txt$ :+ rowstring + "~q~n"                                                                             
  28.                                 Next
  29.                                 UnlockImage( image )
  30.                                 te.SetText( txt$ )
  31.                         Else
  32.                                 Notify( "Invalid image file!" )
  33.                         End If                         
  34.                 Case EVENT_APPTERMINATE
  35.                         End
  36.                 Case EVENT_WINDOWCLOSE
  37.                         Select EventSource()
  38.                                 Case window End
  39.                         End Select
  40.                 End Select
  41. Forever


Comments :


dw817(Posted 1+ years ago)

 I'm always interested in looking at compression algorithms. Have to ask, in the first code, are you using a single hex-character (0-F) to represent a single pixel from a 16-color image ?


AdamStrange(Posted 1+ years ago)

 Simple answer - NOcomplex answer - look at the code data format:width, heightcolor data packed alpha x00 red xFF green xFF blue xFFSo there is no compression and no 16 colour image. its a 32 bit alphaInfant. if you look at the actual code it tells you in very simple terms what it is doing. Reading a line of data , then chunking it into 8 x width bytes (2 bytes per hex number) with is 0..255. it even uses word$ to further enforce what it is doing.:p


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal