'
' GD definitions based on libgd 2.0.36 from http://www.libgd.org/ - their license below.
'
' API description here: http://www.libgd.org/Reference
'
' Ported to BaCon INCLUDE file by Peter van Eerten - GPL.
'
' Version 1.0: Initial release
' Version 1.1: Ignore symbol lookup error detection
' Version 1.2: Adapted for BaCon 3.0 and higher
'
' gd.h: declarations file for the graphic-draw module.
' Permission to use, copy, modify, and distribute this software and its
' documentation for any purpose and without fee is hereby granted, provided
' that the above copyright notice appear in all copies and that both that
' copyright notice and this permission notice appear in supporting
' documentation.  This software is provided "AS IS." Thomas Boutell and
' Boutell.Com, Inc. disclaim all warranties, either express or implied, 
' including but not limited to implied warranties of merchantability and 
' fitness for a particular purpose, with respect to this code and accompanying
' documentation.
'
CATCH GOTO gd_handle_error

gd_LIB$ = "libgd.so"
gd_seq = -1

LABEL gd_import_retry
    INCR gd_seq
    gd_retry = FALSE
    IMPORT "gdImageCreate(int,int)" FROM gd_LIB$ TYPE long
    IF gd_retry THEN GOTO gd_import_retry

GOTO gd_continue

LABEL gd_handle_error
    IF gd_seq = 0 THEN gd_LIB$ = "libgd.so.0"
    ELSE gd_LIB$ = CONCAT$(LEFT$(gd_LIB$, INSTRREV(gd_LIB$, ".")), STR$(gd_seq))
    IF gd_seq < 10 THEN
        gd_retry = TRUE
    ELSE
        PRINT "No GD library found!"
        END
    END IF
    RESUME

LABEL gd_continue

CATCH RESET

CONST gdMaxColors = 256
CONST gdAlphaMax = 127
CONST gdAlphaOpaque = 0
CONST gdAlphaTransparent = 127
CONST gdRedMax = 255
CONST gdGreenMax = 255
CONST gdBlueMax = 255
CONST gdDashSize = 4
CONST gdStyled = -2
CONST gdBrushed = -3
CONST gdStyledBrushed = -4
CONST gdTiled = -5
CONST gdTransparent = -6
CONST gdAntiAliased = -7
CONST gdFTEX_LINESPACE = 1
CONST gdFTEX_CHARMAP = 2
CONST gdFTEX_RESOLUTION = 4
CONST gdFTEX_DISABLE_KERNING = 8
CONST gdFTEX_XSHOW = 16
CONST gdFTEX_FONTPATHNAME = 32
CONST gdFTEX_FONTCONFIG = 64
CONST gdFTEX_RETURNFONTPATHNAME = 128
CONST gdFTEX_Unicode = 0
CONST gdFTEX_Shift_JIS = 1
CONST gdFTEX_Big5 = 2
CONST gdFTEX_Adobe_Custom = 3
CONST gdDisposalUnknown = 0
CONST gdDisposalNone = 1
CONST gdDisposalRestoreBackground = 2
CONST gdDisposalRestorePrevious = 3
CONST gdArc = 0
CONST gdPie = gdArc
CONST gdChord = 1
CONST gdNoFill = 2
CONST gdEdged = 4
CONST GD2_CHUNKSIZE = 128
CONST GD2_CHUNKSIZE_MIN = 64
CONST GD2_CHUNKSIZE_MAX = 4096
CONST GD2_VERS = 2
CONST GD2_ID = "gd2"
CONST GD2_FMT_RAW = 1
CONST GD2_FMT_COMPRESSED = 2
CONST GD_CMP_IMAGE = 1
CONST GD_CMP_NUM_COLORS = 2
CONST GD_CMP_COLOR = 4
CONST GD_CMP_SIZE_X = 8
CONST GD_CMP_SIZE_Y = 16
CONST GD_CMP_TRANSPARENT = 32
CONST GD_CMP_BACKGROUND = 64
CONST GD_CMP_INTERLACE = 128
CONST GD_CMP_TRUECOLOR = 256
CONST GD_RESOLUTION = 96

DEF FN gdTrueColorGetAlpha(c) = (((c) & 0x7F000000) >> 24)
DEF FN gdTrueColorGetRed(c) = (((c) & 0xFF0000) >> 16)
DEF FN gdTrueColorGetGreen(c) = (((c) & 0x00FF00) >> 8)
DEF FN gdTrueColorGetBlue(c) = ((c) & 0x0000FF)
DEF FN gdTrueColor(r, g, b) = (((r) << 16) + ((g) << 8) + (b))
DEF FN gdTrueColorAlpha(r, g, b, a) = (((a) << 24) + ((r) << 16) + ((g) << 8) + (b))

' BaCon cannot access pointers to structures
'DEF FN gdImageTrueColor(im) = ((im)->trueColor)
'DEF FN gdImageSX(im) = ((im)->sx)
'DEF FN gdImageSY(im) = ((im)->sy)
'DEF FN gdImageColorsTotal(im) = ((im)->colorsTotal)
'DEF FN gdImageRed(im, c) = ((im)->trueColor ? gdTrueColorGetRed(c) : (im)->red[(c)])
'DEF FN gdImageGreen(im, c) = ((im)->trueColor ? gdTrueColorGetGreen(c) : (im)->green[(c)])
'DEF FN gdImageBlue(im, c) = ((im)->trueColor ? gdTrueColorGetBlue(c) : (im)->blue[(c)])
'DEF FN gdImageAlpha(im, c) = ((im)->trueColor ? gdTrueColorGetAlpha(c) : (im)->alpha[(c)])
'DEF FN gdImageGetTransparent(im) = ((im)->transparent)
'DEF FN gdImageGetInterlaced(im) = ((im)->interlace)
'DEF FN gdImagePalettePixel(im, x, y) = (im)->pixels[(y)][(x)]
'DEF FN gdImageTrueColorPixel(im, x, y) = (im)->tpixels[(y)][(x)]

IMPORT "gdImageCreateTrueColor(int,int)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromPng(FILE*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromPngCtx(long)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromPngPtr(int,void*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGif(FILE*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGifCtx(long)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGifPtr(int,void*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromWBMP(FILE*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromWBMPCtx(void*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromWBMPPtr(int,void*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromJpeg(FILE*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromJpegCtx(void*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromJpegPtr(int,void*)" FROM gd_LIB$ TYPE long
IMPORT "gdAlphaBlend(int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageCreateFromPngSource(long)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGd(FILE*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGdCtx(long)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGdPtr(int,void*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGd2(FILE*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGd2Ctx(long)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGd2Ptr(int,void*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGd2Part(FILE*,int,int,int,int)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGd2PartCtx(long,int,int,int,int)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromGd2PartPtr(int,void*,int,int,int,int)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromXbm(FILE*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageCreateFromXpm(char*)" FROM gd_LIB$ TYPE long
IMPORT "gdImageDestroy(long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageSetPixel(long,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGetPixel(long,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageGetTrueColorPixel(long,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageAABlend(long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageLine(long,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageDashedLine(long,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageRectangle(long,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageFilledRectangle(long,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageSetClip(long,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGetClip(long,int*,int*,int*,int*)" FROM gd_LIB$ TYPE void
IMPORT "gdImageBoundsSafe(long,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageChar(long,long,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageCharUp(long,long,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageString(long,long,int,int,char*,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageStringUp(long,long,int,int,char*,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageString16(long,long,int,int,short*,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageStringUp16(long,long,int,int,short*,int)" FROM gd_LIB$ TYPE void
IMPORT "gdFontCacheSetup(void)" FROM gd_LIB$ TYPE int
IMPORT "gdFontCacheShutdown(void)" FROM gd_LIB$ TYPE void
IMPORT "gdFreeFontCache(void)" FROM gd_LIB$ TYPE void
IMPORT "gdImageStringTTF(long,int*,int,char*,double,double,int,int,char*)" FROM gd_LIB$ TYPE char*
IMPORT "gdImageStringFT(long,int*,int,char*,double,double,int,int,char*)" FROM gd_LIB$ TYPE char*
IMPORT "gdFTUseFontConfig(int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageStringFTEx(long,int*,int,char*,double,double,int,int,char*,long)" FROM gd_LIB$ TYPE char*
IMPORT "gdImagePolygon(long,long,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageOpenPolygon(long,long,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageFilledPolygon(long,long,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageColorAllocate(long,int,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageColorAllocateAlpha(long,int,int,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageColorClosest(long,int,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageColorClosestAlpha(long,int,int,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageColorClosestHWB(long,int,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageColorExact(long,int,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageColorExactAlpha(long,int,int,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageColorResolve(long,int,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageColorResolveAlpha(long,int,int,int,int)" FROM gd_LIB$ TYPE int
IMPORT "gdImageColorDeallocate(long,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageCreatePaletteFromTrueColor(long,int,int)" FROM gd_LIB$ TYPE long
IMPORT "gdImageTrueColorToPalette(long,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageColorTransparent(long,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImagePaletteCopy(long,long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGif(long,FILE*)" FROM gd_LIB$ TYPE void
IMPORT "gdImagePng(long,FILE*)" FROM gd_LIB$ TYPE void
IMPORT "gdImagePngCtx(long,long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGifCtx(long,long)" FROM gd_LIB$ TYPE void
IMPORT "gdImagePngEx(long,FILE*,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImagePngCtxEx(long,long,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageWBMP(long,int,FILE*)" FROM gd_LIB$ TYPE void
IMPORT "gdImageWBMPCtx(long,int,long)" FROM gd_LIB$ TYPE void
IMPORT "gdFree(void*)" FROM gd_LIB$ TYPE void
IMPORT "gdImageWBMPPtr(long,int*,int)" FROM gd_LIB$ TYPE void*
IMPORT "gdImageJpeg(long,FILE*,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageJpegCtx(long,long,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageJpegPtr(long,int*,int)" FROM gd_LIB$ TYPE void*
IMPORT "gdImageGifAnimBegin(long,FILE*,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGifAnimAdd(long,FILE*,int,int,int,int,int,long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGifAnimEnd(FILE*)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGifAnimBeginCtx(long,long,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGifAnimAddCtx(long,long,int,int,int,int,int,long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGifAnimEndCtx(long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGifAnimBeginPtr(long,int*,int,int)" FROM gd_LIB$ TYPE void*
IMPORT "gdImageGifAnimAddPtr(long,int*,int,int,int,int,int,long)" FROM gd_LIB$ TYPE void*
IMPORT "gdImageGifAnimEndPtr(int*)" FROM gd_LIB$ TYPE void*
IMPORT "gdImagePngToSink(long,long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGd(long,FILE*)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGd2(long,FILE*,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageGifPtr(long,int*)" FROM gd_LIB$ TYPE void*
IMPORT "gdImagePngPtr(long,int*)" FROM gd_LIB$ TYPE void*
IMPORT "gdImagePngPtrEx(long,int*,int)" FROM gd_LIB$ TYPE void*
IMPORT "gdImageGdPtr(long,int*)" FROM gd_LIB$ TYPE void*
IMPORT "gdImageGd2Ptr(long,int,int,int*)" FROM gd_LIB$ TYPE void*
'IMPORT "gdImageEllipse(long,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageFilledArc(long,int,int,int,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageArc(long,int,int,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageFilledEllipse(long,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageFillToBorder(long,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageFill(long,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageCopy(long,long,int,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageCopyMerge(long,long,int,int,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageCopyMergeGray(long,long,int,int,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageCopyResized(long,long,int,int,int,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageCopyResampled(long,long,int,int,int,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageCopyRotated(long,long,double,double,int,int,int,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageSetBrush(long,long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageSetTile(long,long)" FROM gd_LIB$ TYPE void
IMPORT "gdImageSetAntiAliased(long,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageSetAntiAliasedDontBlend(long,int,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageSetStyle(long,int*,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageSetThickness(long,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageInterlace(long,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageAlphaBlending(long,int)" FROM gd_LIB$ TYPE void
IMPORT "gdImageSaveAlpha(long,int)" FROM gd_LIB$ TYPE void
IMPORT "gdNewFileCtx(FILE*)" FROM gd_LIB$ TYPE long
IMPORT "gdNewDynamicCtx(int,void*)" FROM gd_LIB$ TYPE long
IMPORT "gdNewDynamicCtxEx(int,void*,int)" FROM gd_LIB$ TYPE long
IMPORT "gdNewSSCtx(long,long)" FROM gd_LIB$ TYPE long
IMPORT "gdDPExtractData(long,int*)" FROM gd_LIB$ TYPE void*
IMPORT "gdImageCompare(long,long)" FROM gd_LIB$ TYPE int
IMPORT "gdFontGetSmall(void)" FROM gd_LIB$ TYPE long
IMPORT "gdFontGetTiny(void)" FROM gd_LIB$ TYPE long
IMPORT "gdFontGetMediumBold(void)" FROM gd_LIB$ TYPE long
IMPORT "gdFontGetLarge(void)" FROM gd_LIB$ TYPE long
IMPORT "gdFontGetGiant(void)" FROM gd_LIB$ TYPE long
IMPORT "gdImageSquareToCircle(long,int)" FROM gd_LIB$ TYPE long
IMPORT "gdImageStringFTCircle(long,int,int,double,double,double,char*,double,char*,char*,int)" FROM gd_LIB$ TYPE char*
IMPORT "gdImageSharpen(long,int)" FROM gd_LIB$ TYPE void

CONST gdImageCreatePalette = gdImageCreate