View Full Version : string to bitmap module
Michael Clease
30-09-2007, 01:21
Here is a module for converting 256 colour bitmaps to 24 bit bitmaps, its still very primitive at the moment so be gentle with it.
'----------------------------------------------------------------------------------------------------
' Usage: ReturnString = TBGF_String2Bitmap (stringbuffer, RGBformat)
' Stringbuffer is a string - which contains a valid bitmap file loaded into memory.
' RGBformat is
' %TBGF_BGRformat = &H00000001 which returns image data as B G R (valid bitmap file)
' %TBGF_RGBformat = &H00000002 which returns image data as R G B
' %TBGF_RGBAformat = &H00000004 which returns image data as R G B A
' %TBGF_File = &H00000008 Filebuffer is a filename to load.
' %TBGF_Buffer = &H00000010 FileBuffer is a bitmap file in a STRING
'
' ReturnString is a string - which contains a valid 24 bit bitmap file
' this is only for development when TBGL string is supported only the bitmap data will be returned.
'
' if stringbuffer does not contain a valid bitmap structure ReturnString = ""
'---------------------------------------------------------------------------------------------------
if you load a 24 bit bitmap it only returns the bitmap data (ie. not a valid file, headers stripped)
have fun.
Thanks Abraxas for the new module, but I am getting this error, forgive me if I am doing something stupid in getting this error.
It might be that the dll is not named thinBasic_name of dll, but not sure.
Ok, it was the naming... I changed the name of the dll to: thinBasic_TBGF.dll
in the script I changed the line: MODULE "TBGF_MODULEV0.1.0"
to: USES "TBGF"
It then works fine.
Michael Hartlef
30-09-2007, 09:35
Thanks for the module!
Kent, the error has to do with a bug that Eros just recently fixed and released a new Core.
Michael Clease
30-09-2007, 10:30
also didnt help I changed the module version numbering at the last minute and didnt post that version.
fixed now renamed module to thinBasic_TBGF.dll, you now need to copy to the mod directory inside thinbasic directory.
Petr Schreiber
30-09-2007, 11:07
Hi Abraxas,
thanks a lot. On my PC it works ok, I just added to script "USES "TBGF"" as I am more used to it.
Petr
ErosOlmi
30-09-2007, 12:30
Thanks a lot Abraxas.
Nice and useful module. If you want, I can create a dedicated forum for this module. I have the impression some other functionalities can be added to it ;)
Also, when you think will be the right time, I can include in standard thinBasic release adding help info too.
Just let me know.
Possible implementations:
load and save of the BMP files can be native TBGF module functions.
This will avoid the necessity to have FILE module loaded (I can show you FILE_LOAD/FILE_SAVE source code)
Change RGBFormat into more general options paremeter using HEX values. In this case more options acan be passed. Example:
TBGF_BGRformat = &H00000001
%TBGF_RGBformat = &H00000002
%TBGF_RGBAformat = &H00000004
%TBGF_File = &H00000008
%TBGF_Buffer = &H00000010
In this way, testing it, buffer can be either the name of a bitmap file or a real memory buffer and it can be used like:
TBGF_String2Bitmap (stringbuffer, %TBGF_File OR %TBGF_RGBformat)
or
TBGF_String2Bitmap (stringbuffer, %TBGF_Buffer OR %TBGF_RGBformat)
Just mad ideas, you know how we are ;D
In any case, thanks a lot for this idea.
Eros
@Ken,
here the bug Abraxas reported: http://community.thinbasic.com/index.php?topic=1226.msg8502#msg8502
It will be fixed in next release.
In any case just use USES "TBGF" and all should be ok.
Michael Clease
30-09-2007, 21:57
ok. look up ;D
Michael Clease
01-10-2007, 13:28
Eros i would be interested in seeing the File_load and save routines,as I know this will improve my simple routines that are in place now.
if you dont mind please email to my account address.
is my current version working OK.
thanks your help is as always much appreciated
Mike
ErosOlmi
01-10-2007, 14:04
Here they are PB source.
They can be improved maybe wrapping arounf TRY/CATCH/END TRY
FUNCTION File_Exists(BYVAL FullFileName AS STRING) AS LONG
FUNCTION = %FALSE
IF DIR$(FullFileName, %NORMAL OR %READONLY OR %HIDDEN OR %SYSTEM) = "" THEN EXIT FUNCTION
FUNCTION = %TRUE
END FUNCTION
FUNCTION FILE_Load(BYVAL lFileName AS STRING) AS STRING
LOCAL hFile AS LONG
LOCAL lBuffer AS STRING
ON ERROR RESUME NEXT
IF FILE_EXISTS(lFileName) THEN
hFile = FREEFILE
OPEN lFileName FOR BINARY ACCESS READ AS hFile
GET$ hFile, LOF(hFile), lBuffer
CLOSE hFile
FUNCTION = lBuffer
END IF
END FUNCTION
FUNCTION FILE_Save(BYVAL lFileName AS STRING, BYVAL sBuffer AS STRING) AS LONG
LOCAL hFile AS LONG
ON ERROR RESUME NEXT
IF FILE_EXISTS(lFileName) THEN
KILL lFileName
END IF
hFile = FREEFILE
OPEN lFileName FOR BINARY ACCESS READ WRITE AS hFile
PUT$ hFile, sBuffer
CLOSE hFile
FUNCTION = ERRCLEAR
END FUNCTION
Michael Clease
01-10-2007, 14:28
Here they are PB source.
They can be improved maybe wrapping arounf TRY/CATCH/END TRY
FUNCTION FILE_Load(BYVAL lFileName AS STRING) AS STRING
LOCAL hFile AS LONG
LOCAL lBuffer AS STRING
ON ERROR RESUME NEXT
IF FILE_EXISTS(lFileName) THEN
hFile = FREEFILE
OPEN lFileName FOR BINARY ACCESS READ AS hFile
SEEK hFile,1 ' Start of file
GET$ hFile, LOF(hFile), lBuffer
CLOSE hFile
FUNCTION = lBuffer
END IF
END FUNCTION
thanks
Is it better to add SEEK like above to guarantee that it points to the start of the file.
ErosOlmi
01-10-2007, 14:41
Do you have any evidence that after an OPEN ... BINARY ACCESS READ pointer is not at the beginning of the file?
Because file channel is a new one, even if file is already open in the same process, it should create a new file structure setting pointer to the beginning of the file.
I'm not aware of problems on that side but if you have good reason a will change.
Thanks
Eros
Michael Clease
01-10-2007, 14:52
no evidence. Me just not trusting that they wont change it in the future and just playing it safe.
thanks
Mike
ErosOlmi
01-10-2007, 15:04
OK, thanks.
Maybe time to improve a bit. Those functions are at least 4 years old :D
Michael Clease
09-12-2008, 00:06
I found my original code (from my old dead HDD) for this module, thought I would release it for people to play with.
Its as I left it last year so I dont know if its working or not.
Michael Hartlef
09-12-2008, 08:35
thanks Michael for sharing!
ErosOlmi
10-12-2008, 01:46
Thanks Michael (Clease) for posting the sources here.
Can you be so kind to see if you have your copy of "zlib.inc" file?
The versions I have are incompatible with your code. In particular "uncompress" function.
Thanks a lot
Eros
Michael Clease
10-12-2008, 20:02
I suspect that the uncompress function was the thing I was working on when I stopped work on it.
The zlib files I have will be added to my post with the code on.