PDA

View Full Version : TImage experimental



ErosOlmi
19-11-2009, 01:08
I'm testing a very simple module able to load BMP, ICO, JPG, TGA, PNG and TIFF images.
Target of the module is very precise and limited: the ability to load different images format other than just BMP and return a handle to windows bitmap of the image so functionalities are very few but I think enough to be very very useful for many activities.

Syntax of the new keywords inside the module are the following:

hBmp = TImage_Load(nIdx, ImageFileName)
lResult = TImage_Save(nIdx, ImageFileName, nType)
lResult = TImage_Unload(nIdx)
Width = TImage_Width(nIdx)
Height = TImage_Height(nIdx)
hBmp = TImage_Handle(nIdx)
Where:

nIdx is a user unique number used to identify the image and is assigned during TImage_Load. Just use a number like 1 or 2 or 3 or whatever number you like. nIdx is than used in all other functions to identify the image.
nType is one of the following equates: %TImage_BMP, %TImage_JPG, %TImage_PNG


I would like to have some feedback and tests. It should work on Win9x systems withoutthe need of GDI+ library but it needs Microsoft Visual C runtime (that should be present mainly on all Win9x systems)
If there will be no big problems I will deliver with official release.

Attached: module dll, module sources, example.

Thanks a lot
Eros

ps: TImage module takes advantages of PBIMAGE.DLL By Dean Hodgson I've found on another forum. PBIMAGE.DLL is loaded at module runtime from module resource directly into process memory.

Petr Schreiber
19-11-2009, 11:33
Hi Eros,

that looks very interesting. Does the library allow to get RGB(A) or BGR(A) raw data as well?

ErosOlmi
19-11-2009, 13:43
No. It allows just to resize the image and nothing more.

But ...

(I'm not an expert on the field)
it returns a handle to bmp. So maybe you can do something with that.

I will attach here TImage source code (late afternoon) so you can check.

Lionheart008
19-11-2009, 15:23
hi eros, I would like to test this module too. Looks interesting this thin image loader. perhaps it's also possible to set the images with x,y,width,height,style position or making some added controls, we will see. thanks for the nice little thing.


I will attach here TImage source code (late afternoon) so you can check.

I am curious, frank

ErosOlmi
19-11-2009, 18:23
Attached to first post of this message full TImage source code.

Consider you may have to change a bit include files in order to be able to compile it with Power Basic.

Petr Schreiber
19-11-2009, 19:22
Thanks Eros,

I will check it!

Petr Schreiber
19-11-2009, 20:05
The code is in LibertyBASIC, it confused me as I could not recognize the syntax for a while :)
The core of the functionality seems to be in image323.dll, which allows retrieving pixel colors by giving handle, x and y, but no pointer to data.

Michael Clease
19-11-2009, 20:35
I had a quick look around for more liberty stuff and found this jpeg.dll (24Kb ).

'This DLL loads an image and returns a handle
'to a 24-bit memory bitmap of the image.
'Supported types: .jpg, .bmp, .ico, .emf, .wmf, .gif
'= jpeg, bitmap, icon, enhanced metafile,
'windows metafile, and GIF

http://alycesrestaurant.com/dll.htm

ErosOlmi
19-11-2009, 21:09
TImage module takes advantages of PBIMAGE.DLL By Dean Hodgson and not the other dlls.
PBIMAGE.DLL has more image formats.

ErosOlmi
19-11-2009, 22:23
To get the BITMAP info from bitmap handle you can use the following code:


Declare Function GetObject Lib "GDI32.DLL" Alias "GetObjectA" (ByVal hObject As DWord, ByVal nCount As Long, ByVal lpObject As DWord) As Long
.
.
.
hImg = TImage_Load (%MyImage, sBITMAP)

Dim BI As tBITMAP
GetObject(hImg, SIZEOF(bi), VARPTR(bi))

MsgBox 0, "Bitmap Info: " & $CRLF & _
"bmType: " & $TAB & BI.bmType & $CRLF & _
"bmWidth: " & $TAB & BI.bmWidth & $CRLF & _
"bmHeight: " & $TAB & BI.bmHeight & $CRLF & _
"bmWidthBytes: " & $TAB & BI.bmWidthBytes & $CRLF & _
"bmPlanes: " & $TAB & BI.bmPlanes & $CRLF & _
"bmBitsPixel: " & $TAB & BI.bmBitsPixel & $CRLF & _
"bmBits: " & $TAB & BI.bmBits & $CRLF & _
""


BI.bmBits element is the BYTE PTR to location of the bit values for the bitmap
http://msdn.microsoft.com/en-us/library/dd183371(VS.85).aspx

Can this be of any help?

Michael Clease
19-11-2009, 23:49
thanks Eros

typo "bmHeight: " & $TAB & BI.bmWidth & $CRLF & _

I had a play and heres a quick stab at it with the jpeg.dll only one issue and thats the way bitmap files are constructed the bytes are in BGR rather than RGB its not difficult to fix its just slow.

Petr Schreiber
19-11-2009, 23:54
Thanks Eros, Michael!

Michael, BGR is no problem. Since the latest beta, TBGL supports %TBGL_DATA_BGR as well, so you can get the colors correct.


Petr

ErosOlmi
19-11-2009, 23:56
Thanks Michael, typo fixed.

My idea is not to work on a script level but to see if TImage module can be used to pass a valid BMP handle to other compiled functions (let's say TBGL) and still be able to get valid BMP info. So at the and all is compiled and thinBasic programmer should be transparent to all of the inside.

To me TImage (and internally PBIMAGE.DLL) is able to load different file formats producing valid BITMAP handle.
Than other module can get those handlers and do what they need.
Handle created is the same created with LoadImage API.

Another option is to embed PBIMAGE.DLL into other modules (like I did here in TImage) and use it as slave worker for loading images. Than use them internally as bitmaps.

That's the main mad ideas.
Maybe this is all superfluous when we will move to WinXP or above only thinBasic.

Petr Schreiber
20-11-2009, 00:01
Hi,

if PBIMAGE.DLL will work well, and it seems it does ok, I will consider embedding it to TBGL for Win9x systems.
This will allow M15 models to have JPG and PNG textures, and texture loading functions could adopt it as well.

Once we jump to XP, I will remove it and use GDI+ instead.

I am just not sure about the licence of PBIMAGE.

Lionheart008
20-11-2009, 00:01
hi all, petr, michael, eros.

I will try another way. It has taken over one and a half hour to check my codes and I have made one IMAGE.DLL with powerbasic. It has a lot of feature of "win32api.inc" and I don't know if I can use it for thinbasic too. I will try this one tomorrow and make it. I need time. I will include also one "open image" dialog button for *.jpg, *.bmp, *.png files.

testversion IMAGE.DLL and exe File I add here with one test-photo.

"PBIMAGE.DLL" and "pbimage.bas" I haven't seen some hours before (sorry), because I haven't studied the "resources" folder :shock:

best regards, Frank

ps: new update with "openFile" button (inkl. filter) I have done but I cannot yet load Images into new dialog. will come ;)

Michael Clease
20-11-2009, 01:27
Frank what does "myFunction1" do ? apart from a message box.

Lionheart008
20-11-2009, 01:31
good work michael with your jpeg dll test:)

I have seen the last posts just at this time and will post my new stuff to another place at board. I am thinking it's better not to confuse thinbasic user here with another DLL and tb examples.

best regards, frank

ps:
Frank what does "myFunction1" do ? apart from a message box.

It was only a first test for my "Image.DLL" example if this function runs too. has only a dummy sense. will delete it for next time ;)

ErosOlmi
21-11-2009, 12:54
An improved version of TImage module is now part of current thinBasic beta 1.7.10.0 distribution.
This thread is now closed.