Undefined reference to `PNG_LoadFile@16'
Undefined reference to `PNG_LoadFile@16'
I am trying to get PngLib to work. (it's done in assembly)
If I remember right, I got it to work with no problem, on older versions of freebasic.
How do I fix this problem?
Here's a link to PngLib.
Could it be, that this version of freebasic 1.05 does not like PngLib2.a?
If I remember right, I got it to work with no problem, on older versions of freebasic.
How do I fix this problem?
Here's a link to PngLib.
Could it be, that this version of freebasic 1.05 does not like PngLib2.a?
Re: Undefined reference to `PNG_LoadFile@16'
Use D.J.Peter's, FBImage instead, its far more recent (2017).
See in Libraries: FBImage static Win/Lin 32/64-bit
Doing some searching on the forum, won't hurt (but prevents such useless posts).
(this is the last anwer, you'll get from me ... for such simple stuff)
See in Libraries: FBImage static Win/Lin 32/64-bit
Doing some searching on the forum, won't hurt (but prevents such useless posts).
(this is the last anwer, you'll get from me ... for such simple stuff)
Re: Undefined reference to `PNG_LoadFile@16'
please show code if possible or if it's an existing example then post the name of the example and where it can be found.
do you have libpnglib2.a in your FreeBASIC lib folder?
do you have libpnglib2.a in your FreeBASIC lib folder?
Re: Undefined reference to `PNG_LoadFile@16'
Get rid of the byvals in the include file by
#undef byval
#define byval
at the top of showpng3.bas above #lang "fblite"
But it runs with -gen gcc without changing anything.
#undef byval
#define byval
at the top of showpng3.bas above #lang "fblite"
But it runs with -gen gcc without changing anything.
Re: Undefined reference to `PNG_LoadFile@16'
It compiled, but did not show the pngdodicat wrote:Get rid of the byvals in the include file by
#undef byval
#define byval
at the top of showpng3.bas above #lang "fblite"
But it runs with -gen gcc without changing anything.
Last edited by lassar on Jul 17, 2018 19:55, edited 1 time in total.
Re: Undefined reference to `PNG_LoadFile@16'
Simple my foot.MrSwiss wrote:Use D.J.Peter's, FBImage instead, its far more recent (2017).
See in Libraries: FBImage static Win/Lin 32/64-bit
Doing some searching on the forum, won't hurt (but prevents such useless posts).
(this is the last anwer, you'll get from me ... for such simple stuff)
I did search forum, and did not find anything useful on this.
If it's so simple, tell me how to get this static library to work.
Last edited by lassar on Jul 17, 2018 19:55, edited 1 time in total.
Re: Undefined reference to `PNG_LoadFile@16'
Yes I got static library libpnglib2.a in my freebasic/win32 folder.srvaldez wrote:please show code if possible or if it's an existing example then post the name of the example and where it can be found.
do you have libpnglib2.a in your FreeBASIC lib folder?
The code is in Pnglib.zip: Link to download
This is about the only link on the web where you can still get the libpnglib2.a.
Re: Undefined reference to `PNG_LoadFile@16'
Here are .png file load/save using GDI.
Mainly coded by UEZ originally.
i cannot get it to work in 64 bits.
But the 32 bit compiler works OK.
If you have problems try pset on line 28
and
point on line 55
by uncommenting
Mainly coded by UEZ originally.
i cannot get it to work in 64 bits.
But the 32 bit compiler works OK.
If you have problems try pset on line 28
and
point on line 55
by uncommenting
Code: Select all
#if sizeof(integer)=8
#include "windows.bi"
''declare sub CLSIDFromString alias "CLSIDFromString"(as wstring,as _guid ptr) ''for 64 bits but doesn't work
#endif
#Include "win/gdiplus.bi"
#include "file.bi"
Function ImageLoad(Picture as String,byref i as any ptr) as long
#define putpixel(_x,_y,colour) *cptr(ulong ptr,row+ (_y)*pitch+ (_x) shl 2) =(colour)
static as integer pitch
static as any ptr row
Imageinfo i,,,,pitch,row
Dim As uinteger TMP
GDIPLUS.GdiplusStartup(@TMP,@type<GDIPLUS.GDIPLUSSTARTUPINPUT>(1),0)
Dim as any Ptr Img
if GDIPLUS.GdipLoadImageFromFile(Picture,@Img)>0 then return 0
Dim As Single w,h
GDIPLUS.GdipGetImageDimension(Img,@w,@h)
if w*h=0 then return 0
Dim As GDIPLUS.BitmapData Pdata
Dim As Rect R=Type(0,0,w-1,h-1)
GDIPLUS.GdipBitmapLockBits(Img,Cast(Any Ptr,@R),GDIPLUS.ImageLockModeRead,PixelFormat32bppARGB,@Pdata)
For y as long = 0 To h-1
For x as long = 0 To w-1
' pset i,(x,y),Cast(ulong Ptr,Pdata.Scan0)[y*w+x]
putpixel(x,y,(Cast(ulong Ptr,Pdata.Scan0)[y*w+x]))
Next
Next
return w*h
End Function
Function ImageSave( Filename as WString,Image As any Ptr, JPGQual as ULong = 80) as Boolean
#define _getpixel(_x,_y) *Cptr(Ulong Ptr,pixdata + (_y)*pitch + (_x) Shl 2)
Dim as Integer w, h, bypp, pitch
Dim pixdata As Any Ptr
If 0 <> ImageInfo(Image, w, h, bypp, pitch, pixdata) Then Return False
Dim GDIPlusStartupInput As GDIPLUS.GDIPLUSSTARTUPINPUT
Dim As ULONG_PTR GDIPlusToken
GDIPlusStartupInput.GdiplusVersion = 1
If (GDIPLUS.GdiplusStartup(@GDIPlusToken, @GDIPlusStartupInput, NULL) <> 0) Then Return 0
Dim as Uinteger x, y, RowOffset
Dim As Any Ptr hBitmap
Dim As GDIPLUS.BitmapData tBitmapData
Dim As Rect tRect = Type(0, 0, w - 1, h - 1)
GDIPLUS.GdipCreateBitmapFromScan0(w, h, 0, PixelFormat32bppARGB, 0, @hBitmap)
GDIPLUS.GdipBitmapLockBits(hBitmap, Cast(Any Ptr, @tRect), GDIPLUS.ImageLockModeWrite, PixelFormat32bppARGB, @tBitmapData)
For y = 0 to h - 1
RowOffset = y * w
for x = 0 to w - 1
Cast(Integer Ptr, tBitmapData.Scan0)[RowOffset + x] = &hFF000000 + _getpixel(x, y)
'Cast(Integer Ptr, tBitmapData.Scan0)[RowOffset + x] = &hFF000000 + point(x, y, Image)
Next
Next
GDIPLUS.GdipBitmapUnlockBits(hBitmap, @tBitmapData)
Dim as Byte iErr = 0
Dim as UInteger count, size
GDIPLUS.GdipGetImageEncodersSize(@count, @size)
Dim As GDIPLUS.ImageCodecInfo Ptr pImageCodecInfo, Clsid
pImageCodecInfo = Allocate(size)
GDIPLUS.GdipGetImageEncoders(count, size, pImageCodecInfo)
For i as ulong = 0 to count
If *cast(wstring ptr, pImageCodecInfo[i].MimeType) = "image/bmp" and Right(Filename, 4) = ".bmp" Then
If (GDIPLUS.GdipSaveImageToFile(hBitmap, WStr(Filename), @pImageCodecInfo[i].Clsid, NULL) <> 0) Then iErr += 1
Elseif *cast(wstring ptr, pImageCodecInfo[i].MimeType) = "image/jpeg" and (Right(Filename, 4) = ".jpg" or Right(Filename, 5) = ".jpeg") Then
'If (GdipSaveImageToFile(hBitmap, WStr(Filename), @pImageCodecInfo[i].Clsid, NULL) <> 0) Then iErr += 1
JPGQual = IIf(JPGQual < 0, 0, IIf(JPGQual > 100, 100, JPGQual))
Dim tParams As GDIPLUS.EncoderParameters
Dim EncoderQuality As String = "{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"
tParams.Count = 1
CLSIDFromString(Wstr(EncoderQuality), @tParams.Parameter(0).GUID) 'ERROR on 64 bits
With tParams.Parameter(0)
.NumberOfValues = 1
.Type = GDIPLUS.EncoderParameterValueTypeLong
.Value = VarPtr(JPGQual)
End With
If GDIPLUS.GdipSaveImageToFile(hBitmap, WStr(Filename), @pImageCodecInfo[i].Clsid, @tParams) <> 0 Then iErr += 1
ElseIf *cast(wstring ptr, pImageCodecInfo[i].MimeType) = "image/gif" and Right(Filename, 4) = ".gif" Then
If (GDIPLUS.GdipSaveImageToFile(hBitmap, WStr(Filename), @pImageCodecInfo[i].Clsid, NULL) <> 0) Then iErr += 1
ElseIf *cast(wstring ptr, pImageCodecInfo[i].MimeType) = "image/tiff" and (Right(Filename, 4) = ".tif" or Right(Filename, 5) = ".tiff") Then
If (GDIPLUS.GdipSaveImageToFile(hBitmap, WStr(Filename), @pImageCodecInfo[i].Clsid, NULL) <> 0) Then iErr += 1
ElseIf *cast(wstring ptr, pImageCodecInfo[i].MimeType) = "image/png" and Right(Filename, 4) = ".png" Then
If (GDIPLUS.GdipSaveImageToFile(hBitmap, WStr(Filename), @pImageCodecInfo[i].Clsid, NULL) <> 0) Then iErr += 1
Elseif *cast(wstring ptr, pImageCodecInfo[i].MimeType) = "image/ico" and Right(Filename, 4) = ".ico" Then
iErr += 1
End if
Next
Deallocate(pImageCodecInfo)
GDIPLUS.GdipDisposeImage(hBitmap)
GDIPLUS.GdiplusShutdown(GDIPlusToken)
If iErr > 0 Then Return False
Return True
End function
sub getsize(picture as string,byref w as single,byref h as single) 'unused
Dim As uinteger TMP
GDIPLUS.GdiplusStartup(@TMP,@type<GDIPLUS.GDIPLUSSTARTUPINPUT>(1),0)
Dim as any Ptr Img
if GDIPLUS.GdipLoadImageFromFile(Picture,@Img)>0 then exit sub
GDIPLUS.GdipGetImageDimension(Img,@w,@h)
end sub
screen 20,32
dim as any ptr im=imagecreate(500,500,rgb(0,0,150))
for n as long=0 to 100
circle im,(rnd*500,rnd*500),5+rnd*15,rgb(rnd*255,rnd*255,rnd*255),,,,f
next
imagesave("circles.png",im)
if fileexists("circles.png") then print "OK" else print "Failed to save .png file"
dim as single w,h
getsize("circles.png",w,h)
print "width","height"
print w,h
dim as any ptr im2=imagecreate(w,h)
ImageLoad("circles.png",im2)
put(100,100),im2
sleep
imagedestroy im
imagedestroy im2
Re: Undefined reference to `PNG_LoadFile@16'
Same for me. Besides, there was no car.png (here is one), but no luck even with the car.png in the exe path.lassar wrote:It compiled, but did not show the png
The screenres 640,480,32,,&H01 does horrible things on my machine, screenres 640,480,32,,GFX_WINDOWED is better but still no PNG.
Debugging shows that if PNG_Init(@png_image)=0 then return 0 does not return, it continues, but png_image is zero, and PNG_LoadFile fails. Seems a bug... or does it work for somebody?
Re: Undefined reference to `PNG_LoadFile@16'
All I know is that older versions of freebasic could compile it.
And those compiled versions worked.
And those compiled versions worked.
Bug in freebasic 1.05 compiler
There is a bug in the freebasic compiler.
There are 9 declare functions in pblib2.bi
And yet the compiler only complains about one of them.
The compiler says "undefined reference to `PNG_LoadFile@16' "
Think about it. the @16 says it needs 4 dwords for the parameters.(16 bytes)
And yet when you look at this function, It only need 2 dwords.(8 bytes)
I put pnglib2.a in notepad++, it mentions "_PNG_LoadFile@8": 2 dwords
This is a bug in freebasic 1.05 !
No wonder, I couldn't get it to work !
There are 9 declare functions in pblib2.bi
And yet the compiler only complains about one of them.
Code: Select all
declare function PNG_LoadFile stdcall alias "PNG_LoadFile" (byval pPNGInfo as PNGINFO ptr, byval lpFileName as string) as integer
Think about it. the @16 says it needs 4 dwords for the parameters.(16 bytes)
And yet when you look at this function, It only need 2 dwords.(8 bytes)
I put pnglib2.a in notepad++, it mentions "_PNG_LoadFile@8": 2 dwords
This is a bug in freebasic 1.05 !
No wonder, I couldn't get it to work !
Re: Undefined reference to `PNG_LoadFile@16'
Is the .a file and the compiler 32-bit? If the compiler was 64-bit that would make the pointers 8 bytes each.
Re: Undefined reference to `PNG_LoadFile@16'
Tried compiling one of my old programs using Pnglib on freebasic 20.0b
It compiles okay, and works.
Maybe I will make a dll of it.
It's a shame that freebasic 1.05 is so buggy.
For people that want a super fast png loader.
Here is my source code.
And here is pnglib.bi
It compiles okay, and works.
Maybe I will make a dll of it.
It's a shame that freebasic 1.05 is so buggy.
For people that want a super fast png loader.
Here is my source code.
Code: Select all
#lang "FBLITE"
#include once "pnglib.bi"
const as integer GFX_NULL = -1 , _
GFX_WINDOWED = &h00 , _
GFX_FULLSCREEN = &h01 , _
GFX_OPENGL = &h02 , _
GFX_NO_SWITCH = &h04 , _
GFX_NO_FRAME = &h08 , _
GFX_SHAPED_WINDOW = &h10 , _
GFX_ALWAYS_ON_TOP = &h20 , _
GFX_ALPHA_PRIMITIVES = &h40 , _
GFX_HIGH_PRIORITY = &h80
DECLARE FUNCTION ShowSplash(byval filename as string) as ubyte ptr
SCREENRES 640,480,24,,0 OR 4 OR 8 OR &h20 OR &h40'GFX_FULLSCREEN OR GFX_NO_SWITCH OR GFX_NO_FRAME OR GFX_ALWAYS_ON_TOP
ShowSplash "Dish32.png"
DO
LOOP UNTIL INKEY$ = CHR$(27)
END
Option Nogosub
Function ShowSplash(byval filename as string) as ubyte ptr
' function load PNG and return pointer to image in FBGfx format...
dim as PNGINFO png_image
dim as ubyte ptr SpritePtr, PngSource,sprite,palete
dim as ubyte r,g,b,IndexColor
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)
SpritePtr = SCREENPTR
' It may be made in one cycle, but it will be slowly...
NumberOfDwords% = png_image.iHeight * png_image.iWidth
if Palete=0 then
SCREENLOCK
ASM
MOV EBX,[NumberOfDwords%]
MOV ESI,[PngSource]
MOV EDI,[SpritePtr]
MOV ECX,[NumberOfDwords%]
DoItAgain:
MOV EAX,0
LODSD
BSWAP EAX
SHR EAX,8
STOSD
LOOP DoItAgain
END ASM
SCREENUNLOCK
else
SCREENLOCK
ASM
MOV EBX,[NumberOfDwords%]
MOV ESI,[PngSource]
MOV EDI, [SpritePtr]
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)
end function
Option GoSub
Code: Select all
'/******************************************************************************
' PNGlib version 1.0
' C/C++ header for Microsoft Visual C++
' (C) 2002 by Thomas Bleeker
' http://www.MadWizard.org
' ******************************************************************************/
#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
' ******************************************************************************/
#define PNGLIB_ERR_OPENFILE &h1000 ' Couldn't open file
#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
' (e.g. decoding before loading data)
#define PNGLIB_ERR_WRONGSTATE &h2003 ' User error (!): Function call at the wrong time
#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_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
Re: Undefined reference to `PNG_LoadFile@16'
The freebasic 1.05 compiler I am using is 32-bit.caseih wrote:Is the .a file and the compiler 32-bit? If the compiler was 64-bit that would make the pointers 8 bytes each.
Re: Undefined reference to `PNG_LoadFile@16'
So the result from this code is 4?lassar wrote:The freebasic 1.05 compiler I am using is 32-bit.
Code: Select all
dim as integer ptr g
print sizeof(g)