Here's a link to PngLibcaseih wrote:So the result from this code is 4?lassar wrote:The freebasic 1.05 compiler I am using is 32-bit.It would probably help if you posted a complete, self-contained, compile-able example that illustrated this apparent bug. And a link to where the .bi and .a files are.Code: Select all
dim as integer ptr g print sizeof(g)
Showpng3.bas
Code: Select all
'
' This sample show work with PNGlib and FBGfx
' Bugs: Crash palette in palette's PNG images with more 128 colors...
' Dont work with 16-colors PNG...
' True color PNG images worked no problem...
'
' for work need PNGlib of course...
' take it here: http://antarman.nm.ru/files/FreeBASIC/PNGLIB.zip
'
' p.s. It all some green, green BETA...
'
#lang "fblite"
#include once "pnglib2.bi"
#include once "fbgfx.bi"
'$Dynamic
DECLARE FUNCTION LoadPNG(byval filename$)
DECLARE SUB ShowPng(Figure$)
DECLARE SUB LoadDirPng()
' Demo main part:
screenres 640,480,32,,&H01
PRINT "Press any key to see car"
SLEEP
ShowPNG "car.png"
DO:LOOP UNTIL INKEY$ = ""
DO:LOOP UNTIL INKEY$ <> ""
LoadDirPng
SLEEP
END
Option Nogosub
Function LoadPNG(byval Filename$)
' function load PNG and return pointer to image in FBGfx format...
dim png_image AS PNGINFO
dim as ubyte ptr PngSource,palete,VideoPtr
if PNG_Init(@png_image)=0 then return 0
if PNG_LoadFile(@png_image, Filename$)=0 then return 0
if PNG_Decode(@png_image)=0 then return 0
palete=png_image.pPNGPalette
PngSource=png_image.lpOutput
PNG_OutputRaw(@png_image,PngSource,0)
VideoPtr = SCREENPTR
' It may be made in one cycle, but it will be slowly...
NumberOfDwords% = 640 * 480
if Palete=0 then
SCREENLOCK
ASM
MOV EBX,[NumberOfDwords%]
MOV ESI,[PngSource]
MOV EDI,[VideoPtr]
MOV ECX,[NumberOfDwords%]
DoItAgain:
MOV EAX,0
LODSB
SHL EAX,8
LODSB
SHL EAX,8
LODSB
STOSD
LOOP DoItAgain
END ASM
SCREENUNLOCK
else
SCREENLOCK
ASM
MOV EBX,[NumberOfDwords%]
MOV ESI,[PngSource]
MOV EDI, [VideoPtr]
MOV ECX,[NumberOfDwords%]
DoItAgain2:
MOV EAX,0
LODSB
MOV EBX,EAX
ADD EAX,EBX
ADD EAX,EBX
PUSH ESI
MOV ESI,[palete]
ADD ESI, EAX
MOV EAX,0
LODSB
SHL EAX,8
LODSB
SHL EAX,8
LODSB
STOSD
POP ESI
LOOP DoItAgain2
END ASM
SCREENUNLOCK
end if
PNG_Cleanup(@png_image)
FUNCTION = sprite
end function
Option GoSub
SUB ShowPng(PngFile$)
LoadPNG PngFile$
END SUB
SUB LoadDirPng()
Fn$ = DIR$("DATA\*.PNG")
WHILE Fn$ <> ""
FilePath$ = CURDIR$ + "\DATA\" + Fn$
ShowPng FilePath$
Fn$ = DIR$
WEND
END SUB
pnglib2.bi
Code: Select all
'=============================================================================='
' +--\ |\ | +---- | | +---\ '
' | | | \ | | __ | | |___/ '
' +--/ | \| | \ | | | \ '
' | | | +---/ +--- ' +---/ '
'=============================================================================='
' PNGLIB v1.0 '
'
' Include file for use with FreeBasic
' '
' PNGlib version 1.0
' Written by Thomas Bleeker. (C) 2002. '
' Thomas@MadWizard.org '
' www.MadWizard.org '
'------------------------------------------------------------------------------'
' note: total size of PNGINFO structure has to be a multiple of 4 bytes
#ifndef __png_library__
#define __png_library__
#inclib "pnglib2"
type PNGINFO field=1
iWidth as integer ' Width of image
iHeight as integer ' Height of image
dwLastError as integer ' Last error code (PNGLIB_ERR_*)
nColors as integer ' Number of palette entries, if present
PNGColorType as byte ' Original PNG color type (PNG_CT_*)
PNGBitDepth as byte ' Original PNG bit depth (bits/sample)
PNGInterlaced as byte ' Interlace method (PNG_IM_*)
' The following structure members are used internally
' by PNGlib. You should not rely in any way on these values,
' nor assume they will be present in later versions.
' They are included *only* to reserve space for them.
lpPNGData as byte ptr ' pointer to data in PNG file
lnPNGData as integer ' length of data pointed to by lpPNGData
lpCurrent as byte ptr ' 'current pointer', used internally
lpOutput as byte ptr ' pointer to decompressed (unfiltered) output data, used internally
lnOutput as integer ' size of output data pointed to by lpOutput
pPNGPalette as byte ptr ' pointer to data in PLTE chunk
dwLoadType as integer ' type of data currently loaded (PNGI_LT_*)
pHeader as byte ptr ' pointer to raw IHDR chunk *data* (&chunk+8)
pIDAT as byte ptr ' pointer to start of first IDAT chunk
curState as integer ' PNGI_STATE_*
end type
'/******************************************************************************
' Function declararations
' ******************************************************************************/
declare function PNG_Init stdcall alias "PNG_Init" (byval pPNGInfo as PNGINFO ptr) as integer
declare function PNG_Cleanup stdcall alias "PNG_Cleanup" (byval pPNGInfo as PNGINFO ptr) as integer
declare function PNG_LoadFile stdcall alias "PNG_LoadFile" (byval pPNGInfo as PNGINFO ptr, byval lpFileName as string) as integer
declare function PNG_LoadResource stdcall alias "PNG_LoadResource" (byval pPNGInfo as PNGINFO ptr, byval hInstance as integer, byval lpResName as string) as integer
declare function PNG_LoadCustom stdcall alias "PNG_LoadCustom" (byval pPNGInfo as PNGINFO ptr, byval lpData as byte ptr, byval lnData as integer) as integer
declare function PNG_Decode stdcall alias "PNG_Decode" (byval pPNGInfo as PNGINFO ptr) as integer
declare function PNG_GetPalette stdcall alias "PNG_GetPalette" (byval pPNGInfo as PNGINFO ptr, byval lpOutput as any ptr, byval dwFormat as integer) as integer
declare function PNG_OutputRaw stdcall alias "PNG_OutputRaw" (byval pPNGInfo as PNGINFO ptr, byval lpDest as byte ptr, byval dwFormat as integer) as integer
declare function PNG_CreateBitmap stdcall alias "PNG_CreateBitmap" (byval pPNGInfo as PNGINFO ptr, byval hWndCompatible as integer, byval dwFormat as integer, bDDB as integer) as integer
'/******************************************************************************
' Copyproc types, used to build the PNG_OUTF_* values
' ******************************************************************************/
#define PNGCP_X_X 0
#define PNGCP_16_16 1
#define PNGCP_16_16_BGR 2
#define PNGCP_16_16_BGR_SA 3
#define PNGCP_16_16_BGRA 4
#define PNGCP_16_16_SA 5
#define PNGCP_16_8 6
#define PNGCP_16_8_BGR 7
#define PNGCP_16_8_BGR_SA 8
#define PNGCP_16_8_BGRA 9
#define PNGCP_16_8_SA 10
#define PNGCP_2_4 11
#define PNGCP_8_8_BGR 12
#define PNGCP_8_8_BGR_SA 13
#define PNGCP_8_8_BGRA 14
#define PNGCP_8_8_SA PNGCP_16_8
'/******************************************************************************
' Output formats
' ******************************************************************************/
#define PNG_OUTF_G1_G1 &h00010100+PNGCP_X_X
#define PNG_OUTF_G2_G2 &h00020000+PNGCP_X_X
#define PNG_OUTF_G2_G4 &h00020100+PNGCP_2_4
#define PNG_OUTF_G4_G4 &h00040100+PNGCP_X_X
#define PNG_OUTF_G8_G8 &h00080100+PNGCP_X_X
#define PNG_OUTF_G16_G16 &h00100000+PNGCP_16_16
#define PNG_OUTF_G16_G8 &h00100100+PNGCP_16_8
#define PNG_OUTF_T8_T8_BGR &h02080100+PNGCP_8_8_BGR
#define PNG_OUTF_T16_T16_BGR &h02100000+PNGCP_16_16_BGR
#define PNG_OUTF_T16_T8_BGR &h02100100+PNGCP_16_8_BGR
#define PNG_OUTF_P1_P1 &h03010100+PNGCP_X_X
#define PNG_OUTF_P2_P2 &h03020000+PNGCP_X_X
#define PNG_OUTF_P2_P4 &h03020100+PNGCP_2_4
#define PNG_OUTF_P4_P4 &h03040100+PNGCP_X_X
#define PNG_OUTF_P8_P8 &h03080100+PNGCP_X_X
#define PNG_OUTF_GA8_GA8 &h04080000+PNGCP_X_X
#define PNG_OUTF_GA8_G8 &h04080100+PNGCP_8_8_SA
#define PNG_OUTF_GA16_GA16 &h04100000+PNGCP_16_16
#define PNG_OUTF_GA16_G16 &h04100000+PNGCP_16_16_SA
#define PNG_OUTF_GA16_GA8 &h04100000+PNGCP_16_8
#define PNG_OUTF_GA16_G8 &h04100100+PNGCP_16_8_SA
#define PNG_OUTF_TA8_TA8_BGRA &h06080100+PNGCP_8_8_BGRA
#define PNG_OUTF_TA8_T8_BGR &h06080100+PNGCP_8_8_BGR_SA
#define PNG_OUTF_TA16_TA16_BGRA &h06100000+PNGCP_16_16_BGRA
#define PNG_OUTF_TA16_T16_BGR &h06100000+PNGCP_16_16_BGR_SA
#define PNG_OUTF_TA16_TA8_BGRA &h06100100+PNGCP_16_8_BGRA
#define PNG_OUTF_TA16_T8_BGR &h06100100+PNGCP_16_8_BGR_SA
#define PNG_OUTF_AUTO -1
'/******************************************************************************
' Error codes
' ******************************************************************************/
' Couldn't open file
#define PNGLIB_ERR_OPENFILE &h1000
#define PNGLIB_ERR_MEMALLOC &h1001 ' Couldn't allocate memory
#define PNGLIB_ERR_ALREADY_LOADED &h1002 ' Other data has already been loaded
#define PNGLIB_ERR_INVALIDPNG &h2000 ' Corrupt or invalid PNG
#define PNGLIB_ERR_UNSUPPORTED &h2001 ' PNG format not supported
#define PNGLIB_ERR_INVALIDFORMAT &h2002 ' User error (!): Invalid format specified
#define PNGLIB_ERR_WRONGSTATE &h2003 ' User error (!): Function call at the wrong time
#DEFINE PNGLIB_ERR_NOERROR 0 'No error has occurred
' (e.g. decoding before loading data)
#define PNGLIB_ERR_NOPALETTE &h2004 ' Palette requested for a non-paletted image
#define PNGLIB_ERR_INVALIDPARAMETER &h2005 ' Invalid parameter used for function
#define PNGLIB_ERR_CREATEBITMAP &h2006 ' Couldn't create bitmap
#define PNGLIB_ERR_FINDRESOURCE &h3001 ' Couldn't find resource
#define PNGLIB_ERR_LOADRESOURCE &h3002 ' Couldn't load resource
#DEFINE PNG_CT_GRAYSCALE 0
#DEFINE PNG_CT_RGB_TRIPLES 2
#DEFINE PNG_CT_PALETTE_INDEX 3
#DEFINE PNG_CT_GRAYSCALE_ALPHA 4
#DEFINE PNG_CT_RGB_ALPHA_QUADS 6
#DEFINE PNG_IM_NONE 0
#DEFINE PNG_IM_ADAM7 1
#define PNG_PF_RGB 0 ' output: red byte, green byte, blue byte
#define PNG_PF_BGRX 1 ' output: blue byte, green byte, red byte, zero byte
#endif