PDA

View Full Version : [Sources] PowerBASIC encryption and compression algorithms



ErosOlmi
14-07-2007, 07:22
http://www.pbcrypto.com/

PowerBASIC encryption and compression algorithms

kryton9
14-07-2007, 09:17
I feel like a spy visiting that site. Stuff over my head now, but at least I know where to go when and if the time arises. Thanks.

ErosOlmi
14-07-2007, 09:23
In this site you will find also an algo from ... imagine ...

Petr Schreiber

But which one? Father of Petr Schreiber Junior, our beloved Psch! :D

http://www.pbcrypto.com/view.php?algorithm=rle

kryton9
14-07-2007, 20:17
Ok, so that explains it. Petr is so smart and talented as he gets a lot from his father. Petr you are in trouble now.
You and your Dad should have had complete image format support for us already :) Just kidding of course.

On Jose Roca's site. He has freeimage converted over to powerBASIC Petr. Sure seems like the way to go to bring all formats
to tbgl. Take a look when you have some time.

Petr Schreiber
16-07-2007, 09:14
Ha!,

gang was unmasked ;D
Too bad dad has little time for coding now :(

Freeimage looks good, but if I remember correctly DLL was about 1 MB ... which is a lot :)


Bye,
Petr

kryton9
16-07-2007, 21:39
There is also code that uses the GDI+ to load png and jpg as textures. You might want to take a look. I couldn't find it but I know it is there somewhere.

José Roca
16-07-2007, 23:06
There is also code that uses the GDI+ to load png and jpg as textures. You might want to take a look. I couldn't find it but I know it is there somewhere.


I have a function that I'm using in the PowerBASIC OPENGL examples:



' =======================================================================================
' GL_BGRA structure
' =======================================================================================
TYPE GL_BGRA
blue AS BYTE
green AS BYTE
red AS BYTE
alpha AS BYTE
END TYPE
' =======================================================================================

' =======================================================================================
' GL_BGRA_UNION union
' =======================================================================================
UNION GL_BGRA_UNION
dwColor AS DWORD
GL_BGRA
END UNION
' =======================================================================================

' =======================================================================================
' GdiplusStartupInput structure
' =======================================================================================
TYPE GdiplusStartupInput
GdiplusVersion AS DWORD
DebugEventCallback AS DWORD
SuppressBackgroundThread AS LONG
SuppressExternalCodecs AS LONG
END TYPE
' =======================================================================================

' =======================================================================================
' GdiplusStartupOutput structure
' =======================================================================================
TYPE GdiplusStartupOutput
NotificationHook AS DWORD
NotificationUnhook AS DWORD
END TYPE
' =======================================================================================

' =======================================================================================
' GdiPlus functions used by GDIP_LoadTexture
' =======================================================================================

' =======================================================================================
DECLARE FUNCTION GdiplusStartup LIB "GDIPLUS.DLL" ALIAS "GdiplusStartup" ( _
BYREF token AS DWORD, _ ' *ULONG_PTR
BYREF pinput AS GdiplusStartupInput, _ ' *GdiplusStartupInput <record>
BYREF poutput AS GdiplusStartupOutput _ ' *GdiplusStartupOutput <record>
) AS LONG ' GpStatus <enum>
' =======================================================================================
DECLARE SUB GdiplusShutdown LIB "GDIPLUS.DLL" ALIAS "GdiplusShutdown" ( _
BYVAL token AS DWORD _ ' ULONG_PTR
) ' void
' =======================================================================================
DECLARE FUNCTION GdipLoadImageFromFile LIB "GDIPLUS.DLL" ALIAS "GdipLoadImageFromFile" ( _
BYVAL pFilename AS STRING, _ ' *GDIPCONST WCHAR
BYREF pImage AS DWORD _ ' *GpImage
) AS LONG ' GpStatus <enum>
' =======================================================================================
DECLARE FUNCTION GdipGetImageWidth LIB "GDIPLUS.DLL" ALIAS "GdipGetImageWidth" ( _
BYVAL pImage AS DWORD, _ ' *GpImage
BYREF nWidth AS DWORD _ ' *UINT
) AS LONG ' GpStatus <enum>
' =======================================================================================
DECLARE FUNCTION GdipGetImageHeight LIB "GDIPLUS.DLL" ALIAS "GdipGetImageHeight" ( _
BYVAL pImage AS DWORD, _ ' *GpImage
BYREF nHeight AS DWORD _ ' *UINT
) AS LONG ' GpStatus <enum>
' =======================================================================================
DECLARE FUNCTION GdipGetImageThumbnail LIB "GDIPLUS.DLL" ALIAS "GdipGetImageThumbnail" ( _
BYVAL pImage AS DWORD, _ ' *GpImage
BYVAL thumbWidth AS DWORD, _ ' UINT
BYVAL thumbHeight AS DWORD, _ ' UINT
BYREF thumbImage AS DWORD, _ ' **GpImage
BYVAL pcallback AS DWORD, _ ' GetThumbnailImageAbort
BYVAL callbackData AS DWORD _ ' *void
) AS LONG ' GpStatus <enum>
' =======================================================================================
DECLARE FUNCTION GdipImageRotateFlip LIB "GDIPLUS.DLL" ALIAS "GdipImageRotateFlip" ( _
BYVAL pImage AS DWORD, _ ' *GpImage
BYVAL rfType AS LONG _ ' RotateFlipType <enum>
) AS LONG ' GpStatus <enum>
' =======================================================================================
DECLARE FUNCTION GdipBitmapGetPixel LIB "GDIPLUS.DLL" ALIAS "GdipBitmapGetPixel" ( _
BYVAL pBitmap AS DWORD, _ ' *GpBitmap
BYVAL x AS LONG, _ ' INT
BYVAL y AS LONG, _ ' INT
BYREF pcolor AS DWORD _ ' ARGB
) AS LONG ' GpStatus <enum>
' =======================================================================================
DECLARE FUNCTION GdipDisposeImage LIB "GDIPLUS.DLL" ALIAS "GdipDisposeImage" ( _
BYVAL pImage AS DWORD _ ' *GpImage
) AS LONG ' GpStatus <enum>
' =======================================================================================

' =======================================================================================
' Loads textures from disk using GdiPlus.
' Based on code by Charles Pegge.
' Parameters:
' * strFileName = [in] The file name.
' * TextureWidth = [out] Width of the texture.
' * TextureHeight = [out] Height of the texture.
' * strTextureData = [out] The texture data.
' Return Value:
' * %E_POINTER = One of the parameters is null.
' * ERROR_FILE_NOT_FOUND = File not found.
' * ERROR_INVALID_DATA = Bad image size.
' * A GdiPlus status value.
' =======================================================================================
FUNCTION GL_LoadTexture (BYVAL strFileName AS STRING, BYREF TextureWidth AS LONG, BYREF TextureHeight AS LONG, BYREF strTextureData AS STRING) AS LONG

#REGISTER NONE
REGISTER x AS LONG
REGISTER y AS LONG

LOCAL hStatus AS LONG
LOCAL token AS DWORD
LOCAL StartupInput AS GdiplusStartupInput
LOCAL pImage AS DWORD
LOCAL pThumb AS DWORD
LOCAL pixColor AS GL_BGRA_UNION
LOCAL pTextureData AS DWORD PTR

IF VARPTR(TextureWidth) = %NULL OR VARPTR(TextureHeight) = %NULL OR VARPTR(strTextureData) = %NULL THEN
FUNCTION = %E_POINTER
EXIT FUNCTION
END IF

' Find the texture on disk
IF ISFALSE GL_FileExist(strFileName) THEN
FUNCTION = %ERROR_FILE_NOT_FOUND
EXIT FUNCTION
END IF

' Initialize GDI+
StartupInput.GdiplusVersion = 1
hStatus = GdiplusStartup(token, StartupInput, BYVAL %NULL)
IF hStatus THEN
FUNCTION = hStatus
EXIT FUNCTION
END IF

strFileName = UCODE$(strFileName)
hStatus = GdipLoadImageFromFile(strFileName, pImage)
IF hStatus = %S_OK THEN
hStatus = GdipGetImageWidth(pImage, TextureWidth)
hStatus = GdipGetImageHeight(pImage, TextureHeight)
IF TextureWidth <> TextureHeight THEN
hStatus = %ERROR_INVALID_DATA
ELSE
IF IIF&(TALLY(BIN$(TextureWidth), "1") = 1, 1, 0) = %FALSE THEN hStatus = %ERROR_INVALID_DATA
END IF
IF hStatus = %S_OK THEN
hStatus = GdipGetImageThumbnail(pImage, TextureWidth, TextureHeight, pThumb, %NULL, %NULL)
IF hStatus = %S_OK THEN
hStatus = GdipImageRotateFlip(pThumb, 6) ' 6 = %RotateNoneFlipY
IF hStatus = %S_OK THEN
strTextureData = NUL$(TextureWidth * TextureHeight * 4)
pTextureData = STRPTR(strTextureData)
FOR y = 0 TO TextureWidth - 1
FOR x = 0 TO TextureHeight - 1
GdipBitmapGetPixel(pThumb, x, y, pixColor.dwcolor)
SWAP pixColor.red, pixColor.blue
@pTextureData = pixColor.dwcolor
INCR pTextureData
NEXT
NEXT
END IF
END IF
END IF
END IF

IF pImage THEN GdipDisposeImage(pImage)
IF pThumb THEN GdipDisposeImage(pThumb)

' Shutdown GDI+
GdiplusShutdown token

FUNCTION = hStatus

END FUNCTION
' =======================================================================================

Michael Clease
16-07-2007, 23:10
how about an open source solution http://freeimage.sourceforge.net/index.html

kryton9
17-07-2007, 04:44
Thanks Jose, hopefully Petr can use it to make commands for tbgl to support those formats. Thanks again.

Petr Schreiber
17-07-2007, 10:34
Hi,

José function is perfect, only trouble I have with GDI+ solution is that it is not present on earlier versions of Windows.
It would be the best solution, thats sure.

I don't know how much rude it would be to make users of Win98 "BMP & TGA only".

Eros sent me some interesting materials regarding JPG, which I must check out too.


Bye,
Petr

Michael Hartlef
17-07-2007, 12:11
As long as you ship the GDI+ DLL with a script, the win98 users should be fine.

Petr Schreiber
17-07-2007, 21:58
You are right,

if it is possible to bundle GDIPLUS without any license violation, than it seems nice.
Not sure if it is evident from Microsoft info (http://msdn2.microsoft.com/en-us/library/ms533798.aspx).


Bye,
Petr

ErosOlmi
17-07-2007, 22:37
As far as I know GDI+ cannot be distributed.
We have to add a link to official Microsoft web site where Win9x/Win2K users can freely download it.

José Roca
17-07-2007, 23:14
There is a redistributable download:

http://www.microsoft.com/downloads/details.aspx?familyid=6A63AB9C-DF12-4D41-933C-BE590FEAA05A&displaylang=en