Translation of libspng

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Translation of libspng

Post by j8w344c6 »

Please don't be confused by the name, it's completely different from libpng.

The home page of it is here: https://libspng.org/

Code: Select all

#pragma once

#include once "crt/stdlib.bi"
#include once "crt/stdint.bi"
#include once "crt/stdio.bi"

extern "C"

#define SPNG_CDECL
const SPNG_VERSION_MAJOR = 0
const SPNG_VERSION_MINOR = 7
const SPNG_VERSION_PATCH = 1

type spng_errno as long
enum
	SPNG_IO_ERROR = -2
	SPNG_IO_EOF = -1
	SPNG_OK = 0
	SPNG_EINVAL
	SPNG_EMEM
	SPNG_EOVERFLOW
	SPNG_ESIGNATURE
	SPNG_EWIDTH
	SPNG_EHEIGHT
	SPNG_EUSER_WIDTH
	SPNG_EUSER_HEIGHT
	SPNG_EBIT_DEPTH
	SPNG_ECOLOR_TYPE
	SPNG_ECOMPRESSION_METHOD
	SPNG_EFILTER_METHOD
	SPNG_EINTERLACE_METHOD
	SPNG_EIHDR_SIZE
	SPNG_ENOIHDR
	SPNG_ECHUNK_POS
	SPNG_ECHUNK_SIZE
	SPNG_ECHUNK_CRC
	SPNG_ECHUNK_TYPE
	SPNG_ECHUNK_UNKNOWN_CRITICAL
	SPNG_EDUP_PLTE
	SPNG_EDUP_CHRM
	SPNG_EDUP_GAMA
	SPNG_EDUP_ICCP
	SPNG_EDUP_SBIT
	SPNG_EDUP_SRGB
	SPNG_EDUP_BKGD
	SPNG_EDUP_HIST
	SPNG_EDUP_TRNS
	SPNG_EDUP_PHYS
	SPNG_EDUP_TIME
	SPNG_EDUP_OFFS
	SPNG_EDUP_EXIF
	SPNG_ECHRM
	SPNG_EPLTE_IDX
	SPNG_ETRNS_COLOR_TYPE
	SPNG_ETRNS_NO_PLTE
	SPNG_EGAMA
	SPNG_EICCP_NAME
	SPNG_EICCP_COMPRESSION_METHOD
	SPNG_ESBIT
	SPNG_ESRGB
	SPNG_ETEXT
	SPNG_ETEXT_KEYWORD
	SPNG_EZTXT
	SPNG_EZTXT_COMPRESSION_METHOD
	SPNG_EITXT
	SPNG_EITXT_COMPRESSION_FLAG
	SPNG_EITXT_COMPRESSION_METHOD
	SPNG_EITXT_LANG_TAG
	SPNG_EITXT_TRANSLATED_KEY
	SPNG_EBKGD_NO_PLTE
	SPNG_EBKGD_PLTE_IDX
	SPNG_EHIST_NO_PLTE
	SPNG_EPHYS
	SPNG_ESPLT_NAME
	SPNG_ESPLT_DUP_NAME
	SPNG_ESPLT_DEPTH
	SPNG_ETIME
	SPNG_EOFFS
	SPNG_EEXIF
	SPNG_EIDAT_TOO_SHORT
	SPNG_EIDAT_STREAM
	SPNG_EZLIB
	SPNG_EFILTER
	SPNG_EBUFSIZ
	SPNG_EIO
	SPNG_EOF
	SPNG_EBUF_SET
	SPNG_EBADSTATE
	SPNG_EFMT
	SPNG_EFLAGS
	SPNG_ECHUNKAVAIL
	SPNG_ENCODE_ONLY
	SPNG_EOI
	SPNG_ENOPLTE
	SPNG_ECHUNK_LIMITS
	SPNG_EZLIB_INIT
	SPNG_ECHUNK_STDLEN
	SPNG_EINTERNAL
	SPNG_ECTXTYPE
	SPNG_ENOSRC
	SPNG_ENODST
	SPNG_EOPSTATE
	SPNG_ENOTFINAL
end enum

type spng_text_type as long
enum
	SPNG_TEXT = 1
	SPNG_ZTXT = 2
	SPNG_ITXT = 3
end enum

type spng_color_type as long
enum
	SPNG_COLOR_TYPE_GRAYSCALE = 0
	SPNG_COLOR_TYPE_TRUECOLOR = 2
	SPNG_COLOR_TYPE_INDEXED = 3
	SPNG_COLOR_TYPE_GRAYSCALE_ALPHA = 4
	SPNG_COLOR_TYPE_TRUECOLOR_ALPHA = 6
end enum

type spng_filter as long
enum
	SPNG_FILTER_NONE = 0
	SPNG_FILTER_SUB = 1
	SPNG_FILTER_UP = 2
	SPNG_FILTER_AVERAGE = 3
	SPNG_FILTER_PAETH = 4
end enum

type spng_filter_choice as long
enum
	SPNG_DISABLE_FILTERING = 0
	SPNG_FILTER_CHOICE_NONE = 8
	SPNG_FILTER_CHOICE_SUB = 16
	SPNG_FILTER_CHOICE_UP = 32
	SPNG_FILTER_CHOICE_AVG = 64
	SPNG_FILTER_CHOICE_PAETH = 128
	SPNG_FILTER_CHOICE_ALL = (((8 or 16) or 32) or 64) or 128
end enum

type spng_interlace_method as long
enum
	SPNG_INTERLACE_NONE = 0
	SPNG_INTERLACE_ADAM7 = 1
end enum

type spng_format as long
enum
	SPNG_FMT_RGBA8 = 1
	SPNG_FMT_RGBA16 = 2
	SPNG_FMT_RGB8 = 4
	SPNG_FMT_GA8 = 16
	SPNG_FMT_GA16 = 32
	SPNG_FMT_G8 = 64
	SPNG_FMT_PNG = 256
	SPNG_FMT_RAW = 512
end enum

type spng_ctx_flags as long
enum
	SPNG_CTX_IGNORE_ADLER32 = 1
	SPNG_CTX_ENCODER = 2
end enum

type spng_decode_flags as long
enum
	SPNG_DECODE_USE_TRNS = 1
	SPNG_DECODE_USE_GAMA = 2
	SPNG_DECODE_USE_SBIT = 8
	SPNG_DECODE_TRNS = 1
	SPNG_DECODE_GAMMA = 2
	SPNG_DECODE_PROGRESSIVE = 256
end enum

type spng_crc_action as long
enum
	SPNG_CRC_ERROR = 0
	SPNG_CRC_DISCARD = 1
	SPNG_CRC_USE = 2
end enum

type spng_encode_flags as long
enum
	SPNG_ENCODE_PROGRESSIVE = 1
	SPNG_ENCODE_FINALIZE = 2
end enum

type spng_ihdr
	width as ulong
	height as ulong
	bit_depth as ubyte
	color_type as ubyte
	compression_method as ubyte
	filter_method as ubyte
	interlace_method as ubyte
end type

type spng_plte_entry
	red as ubyte
	green as ubyte
	blue as ubyte
	alpha as ubyte
end type

type spng_plte
	n_entries as ulong
	entries(0 to 255) as spng_plte_entry
end type

type spng_trns
	gray as ushort
	red as ushort
	green as ushort
	blue as ushort
	n_type3_entries as ulong
	type3_alpha(0 to 255) as ubyte
end type

type spng_chrm_int
	white_point_x as ulong
	white_point_y as ulong
	red_x as ulong
	red_y as ulong
	green_x as ulong
	green_y as ulong
	blue_x as ulong
	blue_y as ulong
end type

type spng_chrm
	white_point_x as double
	white_point_y as double
	red_x as double
	red_y as double
	green_x as double
	green_y as double
	blue_x as double
	blue_y as double
end type

type spng_iccp
	profile_name as zstring * 80
	profile_len as uinteger
	profile as zstring ptr
end type

type spng_sbit
	grayscale_bits as ubyte
	red_bits as ubyte
	green_bits as ubyte
	blue_bits as ubyte
	alpha_bits as ubyte
end type

type spng_text
	keyword as zstring * 80
	as long type
	length as uinteger
	text as zstring ptr
	compression_flag as ubyte
	compression_method as ubyte
	language_tag as zstring ptr
	translated_keyword as zstring ptr
end type

type spng_bkgd
	gray as ushort
	red as ushort
	green as ushort
	blue as ushort
	plte_index as ushort
end type

type spng_hist
	frequency(0 to 255) as ushort
end type

type spng_phys
	ppu_x as ulong
	ppu_y as ulong
	unit_specifier as ubyte
end type

type spng_splt_entry
	red as ushort
	green as ushort
	blue as ushort
	alpha as ushort
	frequency as ushort
end type

type spng_splt
	name as zstring * 80
	sample_depth as ubyte
	n_entries as ulong
	entries as spng_splt_entry ptr
end type

type spng_time
	year as ushort
	month as ubyte
	day as ubyte
	hour as ubyte
	minute as ubyte
	second as ubyte
end type

type spng_offs
	x as long
	y as long
	unit_specifier as ubyte
end type

type spng_exif
	length as uinteger
	data as zstring ptr
end type

type spng_chunk
	offset as uinteger
	length as ulong
	as ubyte type(0 to 3)
	crc as ulong
end type

type spng_location as long
enum
	SPNG_AFTER_IHDR = 1
	SPNG_AFTER_PLTE = 2
	SPNG_AFTER_IDAT = 8
end enum

type spng_unknown_chunk
	as ubyte type(0 to 3)
	length as uinteger
	data as any ptr
	location as spng_location
end type

type spng_option as long
enum
	SPNG_KEEP_UNKNOWN_CHUNKS = 1
	SPNG_IMG_COMPRESSION_LEVEL
	SPNG_IMG_WINDOW_BITS
	SPNG_IMG_MEM_LEVEL
	SPNG_IMG_COMPRESSION_STRATEGY
	SPNG_TEXT_COMPRESSION_LEVEL
	SPNG_TEXT_WINDOW_BITS
	SPNG_TEXT_MEM_LEVEL
	SPNG_TEXT_COMPRESSION_STRATEGY
	SPNG_FILTER_CHOICE
	SPNG_CHUNK_COUNT_LIMIT
	SPNG_ENCODE_TO_BUFFER
end enum

type spng_alloc
	malloc_fn as function(byval size as uinteger) as any ptr
	realloc_fn as function(byval ptr as any ptr, byval size as uinteger) as any ptr
	calloc_fn as function(byval count as uinteger, byval size as uinteger) as any ptr
	free_fn as sub(byval ptr as any ptr)
end type

type spng_row_info
	scanline_idx as ulong
	row_num as ulong
	pass as long
	filter as ubyte
end type

declare function spng_ctx_new(byval flags as long) as spng_ctx ptr
declare function spng_ctx_new2(byval alloc as spng_alloc ptr, byval flags as long) as spng_ctx ptr
declare sub spng_ctx_free(byval ctx as spng_ctx ptr)
declare function spng_set_png_buffer(byval ctx as spng_ctx ptr, byval buf as const any ptr, byval size as uinteger) as long
declare function spng_set_png_stream(byval ctx as spng_ctx ptr, byval rw_func as function(byval ctx as spng_ctx ptr, byval user as any ptr, byval dst_src as any ptr, byval length as uinteger) as long, byval user as any ptr) as long
declare function spng_set_png_file(byval ctx as spng_ctx ptr, byval file as FILE ptr) as long
declare function spng_get_png_buffer(byval ctx as spng_ctx ptr, byval len as uinteger ptr, byval error as long ptr) as any ptr
declare function spng_set_image_limits(byval ctx as spng_ctx ptr, byval width as ulong, byval height as ulong) as long
declare function spng_get_image_limits(byval ctx as spng_ctx ptr, byval width as ulong ptr, byval height as ulong ptr) as long
declare function spng_set_chunk_limits(byval ctx as spng_ctx ptr, byval chunk_size as uinteger, byval cache_size as uinteger) as long
declare function spng_get_chunk_limits(byval ctx as spng_ctx ptr, byval chunk_size as uinteger ptr, byval cache_size as uinteger ptr) as long
declare function spng_set_crc_action(byval ctx as spng_ctx ptr, byval critical as long, byval ancillary as long) as long
declare function spng_set_option(byval ctx as spng_ctx ptr, byval option as spng_option, byval value as long) as long
declare function spng_get_option(byval ctx as spng_ctx ptr, byval option as spng_option, byval value as long ptr) as long
declare function spng_decoded_image_size(byval ctx as spng_ctx ptr, byval fmt as long, byval len as uinteger ptr) as long
declare function spng_decode_image(byval ctx as spng_ctx ptr, byval out as any ptr, byval len as uinteger, byval fmt as long, byval flags as long) as long
declare function spng_decode_scanline(byval ctx as spng_ctx ptr, byval out as any ptr, byval len as uinteger) as long
declare function spng_decode_row(byval ctx as spng_ctx ptr, byval out as any ptr, byval len as uinteger) as long
declare function spng_decode_chunks(byval ctx as spng_ctx ptr) as long
declare function spng_get_row_info(byval ctx as spng_ctx ptr, byval row_info as spng_row_info ptr) as long
declare function spng_encode_image(byval ctx as spng_ctx ptr, byval img as const any ptr, byval len as uinteger, byval fmt as long, byval flags as long) as long
declare function spng_encode_scanline(byval ctx as spng_ctx ptr, byval scanline as const any ptr, byval len as uinteger) as long
declare function spng_encode_row(byval ctx as spng_ctx ptr, byval row as const any ptr, byval len as uinteger) as long
declare function spng_encode_chunks(byval ctx as spng_ctx ptr) as long
declare function spng_get_ihdr(byval ctx as spng_ctx ptr, byval ihdr as spng_ihdr ptr) as long
declare function spng_get_plte(byval ctx as spng_ctx ptr, byval plte as spng_plte ptr) as long
declare function spng_get_trns(byval ctx as spng_ctx ptr, byval trns as spng_trns ptr) as long
declare function spng_get_chrm(byval ctx as spng_ctx ptr, byval chrm as spng_chrm ptr) as long
declare function spng_get_chrm_int(byval ctx as spng_ctx ptr, byval chrm_int as spng_chrm_int ptr) as long
declare function spng_get_gama(byval ctx as spng_ctx ptr, byval gamma as double ptr) as long
declare function spng_get_gama_int(byval ctx as spng_ctx ptr, byval gama_int as ulong ptr) as long
declare function spng_get_iccp(byval ctx as spng_ctx ptr, byval iccp as spng_iccp ptr) as long
declare function spng_get_sbit(byval ctx as spng_ctx ptr, byval sbit as spng_sbit ptr) as long
declare function spng_get_srgb(byval ctx as spng_ctx ptr, byval rendering_intent as ubyte ptr) as long
declare function spng_get_text(byval ctx as spng_ctx ptr, byval text as spng_text ptr, byval n_text as ulong ptr) as long
declare function spng_get_bkgd(byval ctx as spng_ctx ptr, byval bkgd as spng_bkgd ptr) as long
declare function spng_get_hist(byval ctx as spng_ctx ptr, byval hist as spng_hist ptr) as long
declare function spng_get_phys(byval ctx as spng_ctx ptr, byval phys as spng_phys ptr) as long
declare function spng_get_splt(byval ctx as spng_ctx ptr, byval splt as spng_splt ptr, byval n_splt as ulong ptr) as long
declare function spng_get_time(byval ctx as spng_ctx ptr, byval time as spng_time ptr) as long
declare function spng_get_unknown_chunks(byval ctx as spng_ctx ptr, byval chunks as spng_unknown_chunk ptr, byval n_chunks as ulong ptr) as long
declare function spng_get_offs(byval ctx as spng_ctx ptr, byval offs as spng_offs ptr) as long
declare function spng_get_exif(byval ctx as spng_ctx ptr, byval exif as spng_exif ptr) as long
declare function spng_set_ihdr(byval ctx as spng_ctx ptr, byval ihdr as spng_ihdr ptr) as long
declare function spng_set_plte(byval ctx as spng_ctx ptr, byval plte as spng_plte ptr) as long
declare function spng_set_trns(byval ctx as spng_ctx ptr, byval trns as spng_trns ptr) as long
declare function spng_set_chrm(byval ctx as spng_ctx ptr, byval chrm as spng_chrm ptr) as long
declare function spng_set_chrm_int(byval ctx as spng_ctx ptr, byval chrm_int as spng_chrm_int ptr) as long
declare function spng_set_gama(byval ctx as spng_ctx ptr, byval gamma as double) as long
declare function spng_set_gama_int(byval ctx as spng_ctx ptr, byval gamma as ulong) as long
declare function spng_set_iccp(byval ctx as spng_ctx ptr, byval iccp as spng_iccp ptr) as long
declare function spng_set_sbit(byval ctx as spng_ctx ptr, byval sbit as spng_sbit ptr) as long
declare function spng_set_srgb(byval ctx as spng_ctx ptr, byval rendering_intent as ubyte) as long
declare function spng_set_text(byval ctx as spng_ctx ptr, byval text as spng_text ptr, byval n_text as ulong) as long
declare function spng_set_bkgd(byval ctx as spng_ctx ptr, byval bkgd as spng_bkgd ptr) as long
declare function spng_set_hist(byval ctx as spng_ctx ptr, byval hist as spng_hist ptr) as long
declare function spng_set_phys(byval ctx as spng_ctx ptr, byval phys as spng_phys ptr) as long
declare function spng_set_splt(byval ctx as spng_ctx ptr, byval splt as spng_splt ptr, byval n_splt as ulong) as long
declare function spng_set_time(byval ctx as spng_ctx ptr, byval time as spng_time ptr) as long
declare function spng_set_unknown_chunks(byval ctx as spng_ctx ptr, byval chunks as spng_unknown_chunk ptr, byval n_chunks as ulong) as long
declare function spng_set_offs(byval ctx as spng_ctx ptr, byval offs as spng_offs ptr) as long
declare function spng_set_exif(byval ctx as spng_ctx ptr, byval exif as spng_exif ptr) as long
declare function spng_strerror(byval err as long) as const zstring ptr
declare function spng_version_string() as const zstring ptr

end extern
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Translation of libspng

Post by j8w344c6 »

Even though I translated it I have no idea how to use it. I found translated FreeBASIC headers usually have symbols renamed. I don't know if my translation is really correct or not. I'm just playing with fbfrog a bit.

Anyone with the needed knowledge please try converting this example in C to FreeBASIC to check if my translation really works. Thank you.

https://github.com/randy408/libspng/blo ... /example.c

(I don't understand anything of the code, so I'm unable to convert it to FreeBASIC and test it myself).
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Translation of libspng

Post by D.J.Peters »

Only as info: with lib fbimage you can load and save png files also and it's a static library no extra runtime are needen.

Joshy
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Translation of libspng

Post by j8w344c6 »

D.J.Peters wrote:Only as info: with lib fbimage you can load and save png files also and it's a static library no extra runtime are needen.

Joshy
Excuse me but where is this lib fbimage? I'm unable to find any headers with such name on my FreeBASIC.
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Translation of libspng

Post by Imortis »

j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Translation of libspng

Post by j8w344c6 »

Thanks.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Translation of libspng

Post by j8w344c6 »

My translation of libspng is currently not usable since there are many variable names conflict with FreeBASIC keywords. I only discovered this when open the .bi header in Geany which it highlights the FreeBASIC keywords. Might be fbfrog's -rename_ option will help. But I personally don't use this library so I can't test if my translation really works or not.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Translation of libspng

Post by srvaldez »

hello j8w344c6
this translation is for Windows
apparently fbfrog didn't translate this typedef struct spng_ctx spng_ctx; so all that was needed was to include type spng_ctx as spng_ctx, look at line 373 of the bi
spng.bi

Code: Select all

#pragma once

#include once "crt/stdlib.bi"
#include once "crt/stdint.bi"
#include once "crt/stdio.bi"

extern "C"

#define SPNG_H
#define SPNG_API __declspec(dllimport)
#define SPNG_CDECL
const SPNG_VERSION_MAJOR = 0
const SPNG_VERSION_MINOR = 7
const SPNG_VERSION_PATCH = 1

type spng_errno as long
enum
	SPNG_IO_ERROR = -2
	SPNG_IO_EOF = -1
	SPNG_OK = 0
	SPNG_EINVAL
	SPNG_EMEM
	SPNG_EOVERFLOW
	SPNG_ESIGNATURE
	SPNG_EWIDTH
	SPNG_EHEIGHT
	SPNG_EUSER_WIDTH
	SPNG_EUSER_HEIGHT
	SPNG_EBIT_DEPTH
	SPNG_ECOLOR_TYPE
	SPNG_ECOMPRESSION_METHOD
	SPNG_EFILTER_METHOD
	SPNG_EINTERLACE_METHOD
	SPNG_EIHDR_SIZE
	SPNG_ENOIHDR
	SPNG_ECHUNK_POS
	SPNG_ECHUNK_SIZE
	SPNG_ECHUNK_CRC
	SPNG_ECHUNK_TYPE
	SPNG_ECHUNK_UNKNOWN_CRITICAL
	SPNG_EDUP_PLTE
	SPNG_EDUP_CHRM
	SPNG_EDUP_GAMA
	SPNG_EDUP_ICCP
	SPNG_EDUP_SBIT
	SPNG_EDUP_SRGB
	SPNG_EDUP_BKGD
	SPNG_EDUP_HIST
	SPNG_EDUP_TRNS
	SPNG_EDUP_PHYS
	SPNG_EDUP_TIME
	SPNG_EDUP_OFFS
	SPNG_EDUP_EXIF
	SPNG_ECHRM
	SPNG_EPLTE_IDX
	SPNG_ETRNS_COLOR_TYPE
	SPNG_ETRNS_NO_PLTE
	SPNG_EGAMA
	SPNG_EICCP_NAME
	SPNG_EICCP_COMPRESSION_METHOD
	SPNG_ESBIT
	SPNG_ESRGB
	SPNG_ETEXT
	SPNG_ETEXT_KEYWORD
	SPNG_EZTXT
	SPNG_EZTXT_COMPRESSION_METHOD
	SPNG_EITXT
	SPNG_EITXT_COMPRESSION_FLAG
	SPNG_EITXT_COMPRESSION_METHOD
	SPNG_EITXT_LANG_TAG
	SPNG_EITXT_TRANSLATED_KEY
	SPNG_EBKGD_NO_PLTE
	SPNG_EBKGD_PLTE_IDX
	SPNG_EHIST_NO_PLTE
	SPNG_EPHYS
	SPNG_ESPLT_NAME
	SPNG_ESPLT_DUP_NAME
	SPNG_ESPLT_DEPTH
	SPNG_ETIME
	SPNG_EOFFS
	SPNG_EEXIF
	SPNG_EIDAT_TOO_SHORT
	SPNG_EIDAT_STREAM
	SPNG_EZLIB
	SPNG_EFILTER
	SPNG_EBUFSIZ
	SPNG_EIO
	SPNG_EOF
	SPNG_EBUF_SET
	SPNG_EBADSTATE
	SPNG_EFMT
	SPNG_EFLAGS
	SPNG_ECHUNKAVAIL
	SPNG_ENCODE_ONLY
	SPNG_EOI
	SPNG_ENOPLTE
	SPNG_ECHUNK_LIMITS
	SPNG_EZLIB_INIT
	SPNG_ECHUNK_STDLEN
	SPNG_EINTERNAL
	SPNG_ECTXTYPE
	SPNG_ENOSRC
	SPNG_ENODST
	SPNG_EOPSTATE
	SPNG_ENOTFINAL
end enum

type spng_text_type as long
enum
	SPNG_TEXT = 1
	SPNG_ZTXT = 2
	SPNG_ITXT = 3
end enum

type spng_color_type as long
enum
	SPNG_COLOR_TYPE_GRAYSCALE = 0
	SPNG_COLOR_TYPE_TRUECOLOR = 2
	SPNG_COLOR_TYPE_INDEXED = 3
	SPNG_COLOR_TYPE_GRAYSCALE_ALPHA = 4
	SPNG_COLOR_TYPE_TRUECOLOR_ALPHA = 6
end enum

type spng_filter as long
enum
	SPNG_FILTER_NONE = 0
	SPNG_FILTER_SUB = 1
	SPNG_FILTER_UP = 2
	SPNG_FILTER_AVERAGE = 3
	SPNG_FILTER_PAETH = 4
end enum

type spng_filter_choice as long
enum
	SPNG_DISABLE_FILTERING = 0
	SPNG_FILTER_CHOICE_NONE = 8
	SPNG_FILTER_CHOICE_SUB = 16
	SPNG_FILTER_CHOICE_UP = 32
	SPNG_FILTER_CHOICE_AVG = 64
	SPNG_FILTER_CHOICE_PAETH = 128
	SPNG_FILTER_CHOICE_ALL = (((8 or 16) or 32) or 64) or 128
end enum

type spng_interlace_method as long
enum
	SPNG_INTERLACE_NONE = 0
	SPNG_INTERLACE_ADAM7 = 1
end enum

type spng_format as long
enum
	SPNG_FMT_RGBA8 = 1
	SPNG_FMT_RGBA16 = 2
	SPNG_FMT_RGB8 = 4
	SPNG_FMT_GA8 = 16
	SPNG_FMT_GA16 = 32
	SPNG_FMT_G8 = 64
	SPNG_FMT_PNG = 256
	SPNG_FMT_RAW = 512
end enum

type spng_ctx_flags as long
enum
	SPNG_CTX_IGNORE_ADLER32 = 1
	SPNG_CTX_ENCODER = 2
end enum

type spng_decode_flags as long
enum
	SPNG_DECODE_USE_TRNS = 1
	SPNG_DECODE_USE_GAMA = 2
	SPNG_DECODE_USE_SBIT = 8
	SPNG_DECODE_TRNS = 1
	SPNG_DECODE_GAMMA = 2
	SPNG_DECODE_PROGRESSIVE = 256
end enum

type spng_crc_action as long
enum
	SPNG_CRC_ERROR = 0
	SPNG_CRC_DISCARD = 1
	SPNG_CRC_USE = 2
end enum

type spng_encode_flags as long
enum
	SPNG_ENCODE_PROGRESSIVE = 1
	SPNG_ENCODE_FINALIZE = 2
end enum

type spng_ihdr
	width as ulong
	height as ulong
	bit_depth as ubyte
	color_type as ubyte
	compression_method as ubyte
	filter_method as ubyte
	interlace_method as ubyte
end type

type spng_plte_entry
	red as ubyte
	green as ubyte
	blue as ubyte
	alpha as ubyte
end type

type spng_plte
	n_entries as ulong
	entries(0 to 255) as spng_plte_entry
end type

type spng_trns
	gray as ushort
	red as ushort
	green as ushort
	blue as ushort
	n_type3_entries as ulong
	type3_alpha(0 to 255) as ubyte
end type

type spng_chrm_int
	white_point_x as ulong
	white_point_y as ulong
	red_x as ulong
	red_y as ulong
	green_x as ulong
	green_y as ulong
	blue_x as ulong
	blue_y as ulong
end type

type spng_chrm
	white_point_x as double
	white_point_y as double
	red_x as double
	red_y as double
	green_x as double
	green_y as double
	blue_x as double
	blue_y as double
end type

type spng_iccp
	profile_name as zstring * 80
	profile_len as uinteger
	profile as zstring ptr
end type

type spng_sbit
	grayscale_bits as ubyte
	red_bits as ubyte
	green_bits as ubyte
	blue_bits as ubyte
	alpha_bits as ubyte
end type

type spng_text
	keyword as zstring * 80
	as long type
	length as uinteger
	text as zstring ptr
	compression_flag as ubyte
	compression_method as ubyte
	language_tag as zstring ptr
	translated_keyword as zstring ptr
end type

type spng_bkgd
	gray as ushort
	red as ushort
	green as ushort
	blue as ushort
	plte_index as ushort
end type

type spng_hist
	frequency(0 to 255) as ushort
end type

type spng_phys
	ppu_x as ulong
	ppu_y as ulong
	unit_specifier as ubyte
end type

type spng_splt_entry
	red as ushort
	green as ushort
	blue as ushort
	alpha as ushort
	frequency as ushort
end type

type spng_splt
	name as zstring * 80
	sample_depth as ubyte
	n_entries as ulong
	entries as spng_splt_entry ptr
end type

type spng_time
	year as ushort
	month as ubyte
	day as ubyte
	hour as ubyte
	minute as ubyte
	second as ubyte
end type

type spng_offs
	x as long
	y as long
	unit_specifier as ubyte
end type

type spng_exif
	length as uinteger
	data as zstring ptr
end type

type spng_chunk
	offset as uinteger
	length as ulong
	as ubyte type(0 to 3)
	crc as ulong
end type

type spng_location as long
enum
	SPNG_AFTER_IHDR = 1
	SPNG_AFTER_PLTE = 2
	SPNG_AFTER_IDAT = 8
end enum

type spng_unknown_chunk
	as ubyte type(0 to 3)
	length as uinteger
	data as any ptr
	location as spng_location
end type

type spng_option as long
enum
	SPNG_KEEP_UNKNOWN_CHUNKS = 1
	SPNG_IMG_COMPRESSION_LEVEL
	SPNG_IMG_WINDOW_BITS
	SPNG_IMG_MEM_LEVEL
	SPNG_IMG_COMPRESSION_STRATEGY
	SPNG_TEXT_COMPRESSION_LEVEL
	SPNG_TEXT_WINDOW_BITS
	SPNG_TEXT_MEM_LEVEL
	SPNG_TEXT_COMPRESSION_STRATEGY
	SPNG_FILTER_CHOICE
	SPNG_CHUNK_COUNT_LIMIT
	SPNG_ENCODE_TO_BUFFER
end enum

type spng_alloc
	malloc_fn as function(byval size as uinteger) as any ptr
	realloc_fn as function(byval ptr as any ptr, byval size as uinteger) as any ptr
	calloc_fn as function(byval count as uinteger, byval size as uinteger) as any ptr
	free_fn as sub(byval ptr as any ptr)
end type

type spng_row_info
	scanline_idx as ulong
	row_num as ulong
	pass as long
	filter as ubyte
end type

type spng_ctx as spng_ctx

declare function spng_ctx_new(byval flags as long) as spng_ctx ptr
declare function spng_ctx_new2(byval alloc as spng_alloc ptr, byval flags as long) as spng_ctx ptr
declare sub spng_ctx_free(byval ctx as spng_ctx ptr)
declare function spng_set_png_buffer(byval ctx as spng_ctx ptr, byval buf as const any ptr, byval size as uinteger) as long
declare function spng_set_png_stream(byval ctx as spng_ctx ptr, byval rw_func as function(byval ctx as spng_ctx ptr, byval user as any ptr, byval dst_src as any ptr, byval length as uinteger) as long, byval user as any ptr) as long
declare function spng_set_png_file(byval ctx as spng_ctx ptr, byval file as FILE ptr) as long
declare function spng_get_png_buffer(byval ctx as spng_ctx ptr, byval len as uinteger ptr, byval error as long ptr) as any ptr
declare function spng_set_image_limits(byval ctx as spng_ctx ptr, byval width as ulong, byval height as ulong) as long
declare function spng_get_image_limits(byval ctx as spng_ctx ptr, byval width as ulong ptr, byval height as ulong ptr) as long
declare function spng_set_chunk_limits(byval ctx as spng_ctx ptr, byval chunk_size as uinteger, byval cache_size as uinteger) as long
declare function spng_get_chunk_limits(byval ctx as spng_ctx ptr, byval chunk_size as uinteger ptr, byval cache_size as uinteger ptr) as long
declare function spng_set_crc_action(byval ctx as spng_ctx ptr, byval critical as long, byval ancillary as long) as long
declare function spng_set_option(byval ctx as spng_ctx ptr, byval option as spng_option, byval value as long) as long
declare function spng_get_option(byval ctx as spng_ctx ptr, byval option as spng_option, byval value as long ptr) as long
declare function spng_decoded_image_size(byval ctx as spng_ctx ptr, byval fmt as long, byval len as uinteger ptr) as long
declare function spng_decode_image(byval ctx as spng_ctx ptr, byval out as any ptr, byval len as uinteger, byval fmt as long, byval flags as long) as long
declare function spng_decode_scanline(byval ctx as spng_ctx ptr, byval out as any ptr, byval len as uinteger) as long
declare function spng_decode_row(byval ctx as spng_ctx ptr, byval out as any ptr, byval len as uinteger) as long
declare function spng_decode_chunks(byval ctx as spng_ctx ptr) as long
declare function spng_get_row_info(byval ctx as spng_ctx ptr, byval row_info as spng_row_info ptr) as long
declare function spng_encode_image(byval ctx as spng_ctx ptr, byval img as const any ptr, byval len as uinteger, byval fmt as long, byval flags as long) as long
declare function spng_encode_scanline(byval ctx as spng_ctx ptr, byval scanline as const any ptr, byval len as uinteger) as long
declare function spng_encode_row(byval ctx as spng_ctx ptr, byval row as const any ptr, byval len as uinteger) as long
declare function spng_encode_chunks(byval ctx as spng_ctx ptr) as long
declare function spng_get_ihdr(byval ctx as spng_ctx ptr, byval ihdr as spng_ihdr ptr) as long
declare function spng_get_plte(byval ctx as spng_ctx ptr, byval plte as spng_plte ptr) as long
declare function spng_get_trns(byval ctx as spng_ctx ptr, byval trns as spng_trns ptr) as long
declare function spng_get_chrm(byval ctx as spng_ctx ptr, byval chrm as spng_chrm ptr) as long
declare function spng_get_chrm_int(byval ctx as spng_ctx ptr, byval chrm_int as spng_chrm_int ptr) as long
declare function spng_get_gama(byval ctx as spng_ctx ptr, byval gamma as double ptr) as long
declare function spng_get_gama_int(byval ctx as spng_ctx ptr, byval gama_int as ulong ptr) as long
declare function spng_get_iccp(byval ctx as spng_ctx ptr, byval iccp as spng_iccp ptr) as long
declare function spng_get_sbit(byval ctx as spng_ctx ptr, byval sbit as spng_sbit ptr) as long
declare function spng_get_srgb(byval ctx as spng_ctx ptr, byval rendering_intent as ubyte ptr) as long
declare function spng_get_text(byval ctx as spng_ctx ptr, byval text as spng_text ptr, byval n_text as ulong ptr) as long
declare function spng_get_bkgd(byval ctx as spng_ctx ptr, byval bkgd as spng_bkgd ptr) as long
declare function spng_get_hist(byval ctx as spng_ctx ptr, byval hist as spng_hist ptr) as long
declare function spng_get_phys(byval ctx as spng_ctx ptr, byval phys as spng_phys ptr) as long
declare function spng_get_splt(byval ctx as spng_ctx ptr, byval splt as spng_splt ptr, byval n_splt as ulong ptr) as long
declare function spng_get_time(byval ctx as spng_ctx ptr, byval time as spng_time ptr) as long
declare function spng_get_unknown_chunks(byval ctx as spng_ctx ptr, byval chunks as spng_unknown_chunk ptr, byval n_chunks as ulong ptr) as long
declare function spng_get_offs(byval ctx as spng_ctx ptr, byval offs as spng_offs ptr) as long
declare function spng_get_exif(byval ctx as spng_ctx ptr, byval exif as spng_exif ptr) as long
declare function spng_set_ihdr(byval ctx as spng_ctx ptr, byval ihdr as spng_ihdr ptr) as long
declare function spng_set_plte(byval ctx as spng_ctx ptr, byval plte as spng_plte ptr) as long
declare function spng_set_trns(byval ctx as spng_ctx ptr, byval trns as spng_trns ptr) as long
declare function spng_set_chrm(byval ctx as spng_ctx ptr, byval chrm as spng_chrm ptr) as long
declare function spng_set_chrm_int(byval ctx as spng_ctx ptr, byval chrm_int as spng_chrm_int ptr) as long
declare function spng_set_gama(byval ctx as spng_ctx ptr, byval gamma as double) as long
declare function spng_set_gama_int(byval ctx as spng_ctx ptr, byval gamma as ulong) as long
declare function spng_set_iccp(byval ctx as spng_ctx ptr, byval iccp as spng_iccp ptr) as long
declare function spng_set_sbit(byval ctx as spng_ctx ptr, byval sbit as spng_sbit ptr) as long
declare function spng_set_srgb(byval ctx as spng_ctx ptr, byval rendering_intent as ubyte) as long
declare function spng_set_text(byval ctx as spng_ctx ptr, byval text as spng_text ptr, byval n_text as ulong) as long
declare function spng_set_bkgd(byval ctx as spng_ctx ptr, byval bkgd as spng_bkgd ptr) as long
declare function spng_set_hist(byval ctx as spng_ctx ptr, byval hist as spng_hist ptr) as long
declare function spng_set_phys(byval ctx as spng_ctx ptr, byval phys as spng_phys ptr) as long
declare function spng_set_splt(byval ctx as spng_ctx ptr, byval splt as spng_splt ptr, byval n_splt as ulong) as long
declare function spng_set_time(byval ctx as spng_ctx ptr, byval time as spng_time ptr) as long
declare function spng_set_unknown_chunks(byval ctx as spng_ctx ptr, byval chunks as spng_unknown_chunk ptr, byval n_chunks as ulong) as long
declare function spng_set_offs(byval ctx as spng_ctx ptr, byval offs as spng_offs ptr) as long
declare function spng_set_exif(byval ctx as spng_ctx ptr, byval exif as spng_exif ptr) as long
declare function spng_strerror(byval err as long) as const zstring ptr
declare function spng_version_string() as const zstring ptr

end extern
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Translation of libspng

Post by j8w344c6 »

srvaldez wrote:hello j8w344c6
this translation is for Windows
apparently fbfrog didn't translate this typedef struct spng_ctx spng_ctx; so all that was needed was to include type spng_ctx as spng_ctx, look at line 373 of the bi
spng.bi

Code: Select all

#pragma once

#include once "crt/stdlib.bi"
#include once "crt/stdint.bi"
#include once "crt/stdio.bi"

extern "C"

#define SPNG_H
#define SPNG_API __declspec(dllimport)
#define SPNG_CDECL
const SPNG_VERSION_MAJOR = 0
const SPNG_VERSION_MINOR = 7
const SPNG_VERSION_PATCH = 1

type spng_errno as long
enum
	SPNG_IO_ERROR = -2
	SPNG_IO_EOF = -1
	SPNG_OK = 0
	SPNG_EINVAL
	SPNG_EMEM
	SPNG_EOVERFLOW
	SPNG_ESIGNATURE
	SPNG_EWIDTH
	SPNG_EHEIGHT
	SPNG_EUSER_WIDTH
	SPNG_EUSER_HEIGHT
	SPNG_EBIT_DEPTH
	SPNG_ECOLOR_TYPE
	SPNG_ECOMPRESSION_METHOD
	SPNG_EFILTER_METHOD
	SPNG_EINTERLACE_METHOD
	SPNG_EIHDR_SIZE
	SPNG_ENOIHDR
	SPNG_ECHUNK_POS
	SPNG_ECHUNK_SIZE
	SPNG_ECHUNK_CRC
	SPNG_ECHUNK_TYPE
	SPNG_ECHUNK_UNKNOWN_CRITICAL
	SPNG_EDUP_PLTE
	SPNG_EDUP_CHRM
	SPNG_EDUP_GAMA
	SPNG_EDUP_ICCP
	SPNG_EDUP_SBIT
	SPNG_EDUP_SRGB
	SPNG_EDUP_BKGD
	SPNG_EDUP_HIST
	SPNG_EDUP_TRNS
	SPNG_EDUP_PHYS
	SPNG_EDUP_TIME
	SPNG_EDUP_OFFS
	SPNG_EDUP_EXIF
	SPNG_ECHRM
	SPNG_EPLTE_IDX
	SPNG_ETRNS_COLOR_TYPE
	SPNG_ETRNS_NO_PLTE
	SPNG_EGAMA
	SPNG_EICCP_NAME
	SPNG_EICCP_COMPRESSION_METHOD
	SPNG_ESBIT
	SPNG_ESRGB
	SPNG_ETEXT
	SPNG_ETEXT_KEYWORD
	SPNG_EZTXT
	SPNG_EZTXT_COMPRESSION_METHOD
	SPNG_EITXT
	SPNG_EITXT_COMPRESSION_FLAG
	SPNG_EITXT_COMPRESSION_METHOD
	SPNG_EITXT_LANG_TAG
	SPNG_EITXT_TRANSLATED_KEY
	SPNG_EBKGD_NO_PLTE
	SPNG_EBKGD_PLTE_IDX
	SPNG_EHIST_NO_PLTE
	SPNG_EPHYS
	SPNG_ESPLT_NAME
	SPNG_ESPLT_DUP_NAME
	SPNG_ESPLT_DEPTH
	SPNG_ETIME
	SPNG_EOFFS
	SPNG_EEXIF
	SPNG_EIDAT_TOO_SHORT
	SPNG_EIDAT_STREAM
	SPNG_EZLIB
	SPNG_EFILTER
	SPNG_EBUFSIZ
	SPNG_EIO
	SPNG_EOF
	SPNG_EBUF_SET
	SPNG_EBADSTATE
	SPNG_EFMT
	SPNG_EFLAGS
	SPNG_ECHUNKAVAIL
	SPNG_ENCODE_ONLY
	SPNG_EOI
	SPNG_ENOPLTE
	SPNG_ECHUNK_LIMITS
	SPNG_EZLIB_INIT
	SPNG_ECHUNK_STDLEN
	SPNG_EINTERNAL
	SPNG_ECTXTYPE
	SPNG_ENOSRC
	SPNG_ENODST
	SPNG_EOPSTATE
	SPNG_ENOTFINAL
end enum

type spng_text_type as long
enum
	SPNG_TEXT = 1
	SPNG_ZTXT = 2
	SPNG_ITXT = 3
end enum

type spng_color_type as long
enum
	SPNG_COLOR_TYPE_GRAYSCALE = 0
	SPNG_COLOR_TYPE_TRUECOLOR = 2
	SPNG_COLOR_TYPE_INDEXED = 3
	SPNG_COLOR_TYPE_GRAYSCALE_ALPHA = 4
	SPNG_COLOR_TYPE_TRUECOLOR_ALPHA = 6
end enum

type spng_filter as long
enum
	SPNG_FILTER_NONE = 0
	SPNG_FILTER_SUB = 1
	SPNG_FILTER_UP = 2
	SPNG_FILTER_AVERAGE = 3
	SPNG_FILTER_PAETH = 4
end enum

type spng_filter_choice as long
enum
	SPNG_DISABLE_FILTERING = 0
	SPNG_FILTER_CHOICE_NONE = 8
	SPNG_FILTER_CHOICE_SUB = 16
	SPNG_FILTER_CHOICE_UP = 32
	SPNG_FILTER_CHOICE_AVG = 64
	SPNG_FILTER_CHOICE_PAETH = 128
	SPNG_FILTER_CHOICE_ALL = (((8 or 16) or 32) or 64) or 128
end enum

type spng_interlace_method as long
enum
	SPNG_INTERLACE_NONE = 0
	SPNG_INTERLACE_ADAM7 = 1
end enum

type spng_format as long
enum
	SPNG_FMT_RGBA8 = 1
	SPNG_FMT_RGBA16 = 2
	SPNG_FMT_RGB8 = 4
	SPNG_FMT_GA8 = 16
	SPNG_FMT_GA16 = 32
	SPNG_FMT_G8 = 64
	SPNG_FMT_PNG = 256
	SPNG_FMT_RAW = 512
end enum

type spng_ctx_flags as long
enum
	SPNG_CTX_IGNORE_ADLER32 = 1
	SPNG_CTX_ENCODER = 2
end enum

type spng_decode_flags as long
enum
	SPNG_DECODE_USE_TRNS = 1
	SPNG_DECODE_USE_GAMA = 2
	SPNG_DECODE_USE_SBIT = 8
	SPNG_DECODE_TRNS = 1
	SPNG_DECODE_GAMMA = 2
	SPNG_DECODE_PROGRESSIVE = 256
end enum

type spng_crc_action as long
enum
	SPNG_CRC_ERROR = 0
	SPNG_CRC_DISCARD = 1
	SPNG_CRC_USE = 2
end enum

type spng_encode_flags as long
enum
	SPNG_ENCODE_PROGRESSIVE = 1
	SPNG_ENCODE_FINALIZE = 2
end enum

type spng_ihdr
	width as ulong
	height as ulong
	bit_depth as ubyte
	color_type as ubyte
	compression_method as ubyte
	filter_method as ubyte
	interlace_method as ubyte
end type

type spng_plte_entry
	red as ubyte
	green as ubyte
	blue as ubyte
	alpha as ubyte
end type

type spng_plte
	n_entries as ulong
	entries(0 to 255) as spng_plte_entry
end type

type spng_trns
	gray as ushort
	red as ushort
	green as ushort
	blue as ushort
	n_type3_entries as ulong
	type3_alpha(0 to 255) as ubyte
end type

type spng_chrm_int
	white_point_x as ulong
	white_point_y as ulong
	red_x as ulong
	red_y as ulong
	green_x as ulong
	green_y as ulong
	blue_x as ulong
	blue_y as ulong
end type

type spng_chrm
	white_point_x as double
	white_point_y as double
	red_x as double
	red_y as double
	green_x as double
	green_y as double
	blue_x as double
	blue_y as double
end type

type spng_iccp
	profile_name as zstring * 80
	profile_len as uinteger
	profile as zstring ptr
end type

type spng_sbit
	grayscale_bits as ubyte
	red_bits as ubyte
	green_bits as ubyte
	blue_bits as ubyte
	alpha_bits as ubyte
end type

type spng_text
	keyword as zstring * 80
	as long type
	length as uinteger
	text as zstring ptr
	compression_flag as ubyte
	compression_method as ubyte
	language_tag as zstring ptr
	translated_keyword as zstring ptr
end type

type spng_bkgd
	gray as ushort
	red as ushort
	green as ushort
	blue as ushort
	plte_index as ushort
end type

type spng_hist
	frequency(0 to 255) as ushort
end type

type spng_phys
	ppu_x as ulong
	ppu_y as ulong
	unit_specifier as ubyte
end type

type spng_splt_entry
	red as ushort
	green as ushort
	blue as ushort
	alpha as ushort
	frequency as ushort
end type

type spng_splt
	name as zstring * 80
	sample_depth as ubyte
	n_entries as ulong
	entries as spng_splt_entry ptr
end type

type spng_time
	year as ushort
	month as ubyte
	day as ubyte
	hour as ubyte
	minute as ubyte
	second as ubyte
end type

type spng_offs
	x as long
	y as long
	unit_specifier as ubyte
end type

type spng_exif
	length as uinteger
	data as zstring ptr
end type

type spng_chunk
	offset as uinteger
	length as ulong
	as ubyte type(0 to 3)
	crc as ulong
end type

type spng_location as long
enum
	SPNG_AFTER_IHDR = 1
	SPNG_AFTER_PLTE = 2
	SPNG_AFTER_IDAT = 8
end enum

type spng_unknown_chunk
	as ubyte type(0 to 3)
	length as uinteger
	data as any ptr
	location as spng_location
end type

type spng_option as long
enum
	SPNG_KEEP_UNKNOWN_CHUNKS = 1
	SPNG_IMG_COMPRESSION_LEVEL
	SPNG_IMG_WINDOW_BITS
	SPNG_IMG_MEM_LEVEL
	SPNG_IMG_COMPRESSION_STRATEGY
	SPNG_TEXT_COMPRESSION_LEVEL
	SPNG_TEXT_WINDOW_BITS
	SPNG_TEXT_MEM_LEVEL
	SPNG_TEXT_COMPRESSION_STRATEGY
	SPNG_FILTER_CHOICE
	SPNG_CHUNK_COUNT_LIMIT
	SPNG_ENCODE_TO_BUFFER
end enum

type spng_alloc
	malloc_fn as function(byval size as uinteger) as any ptr
	realloc_fn as function(byval ptr as any ptr, byval size as uinteger) as any ptr
	calloc_fn as function(byval count as uinteger, byval size as uinteger) as any ptr
	free_fn as sub(byval ptr as any ptr)
end type

type spng_row_info
	scanline_idx as ulong
	row_num as ulong
	pass as long
	filter as ubyte
end type

type spng_ctx as spng_ctx

declare function spng_ctx_new(byval flags as long) as spng_ctx ptr
declare function spng_ctx_new2(byval alloc as spng_alloc ptr, byval flags as long) as spng_ctx ptr
declare sub spng_ctx_free(byval ctx as spng_ctx ptr)
declare function spng_set_png_buffer(byval ctx as spng_ctx ptr, byval buf as const any ptr, byval size as uinteger) as long
declare function spng_set_png_stream(byval ctx as spng_ctx ptr, byval rw_func as function(byval ctx as spng_ctx ptr, byval user as any ptr, byval dst_src as any ptr, byval length as uinteger) as long, byval user as any ptr) as long
declare function spng_set_png_file(byval ctx as spng_ctx ptr, byval file as FILE ptr) as long
declare function spng_get_png_buffer(byval ctx as spng_ctx ptr, byval len as uinteger ptr, byval error as long ptr) as any ptr
declare function spng_set_image_limits(byval ctx as spng_ctx ptr, byval width as ulong, byval height as ulong) as long
declare function spng_get_image_limits(byval ctx as spng_ctx ptr, byval width as ulong ptr, byval height as ulong ptr) as long
declare function spng_set_chunk_limits(byval ctx as spng_ctx ptr, byval chunk_size as uinteger, byval cache_size as uinteger) as long
declare function spng_get_chunk_limits(byval ctx as spng_ctx ptr, byval chunk_size as uinteger ptr, byval cache_size as uinteger ptr) as long
declare function spng_set_crc_action(byval ctx as spng_ctx ptr, byval critical as long, byval ancillary as long) as long
declare function spng_set_option(byval ctx as spng_ctx ptr, byval option as spng_option, byval value as long) as long
declare function spng_get_option(byval ctx as spng_ctx ptr, byval option as spng_option, byval value as long ptr) as long
declare function spng_decoded_image_size(byval ctx as spng_ctx ptr, byval fmt as long, byval len as uinteger ptr) as long
declare function spng_decode_image(byval ctx as spng_ctx ptr, byval out as any ptr, byval len as uinteger, byval fmt as long, byval flags as long) as long
declare function spng_decode_scanline(byval ctx as spng_ctx ptr, byval out as any ptr, byval len as uinteger) as long
declare function spng_decode_row(byval ctx as spng_ctx ptr, byval out as any ptr, byval len as uinteger) as long
declare function spng_decode_chunks(byval ctx as spng_ctx ptr) as long
declare function spng_get_row_info(byval ctx as spng_ctx ptr, byval row_info as spng_row_info ptr) as long
declare function spng_encode_image(byval ctx as spng_ctx ptr, byval img as const any ptr, byval len as uinteger, byval fmt as long, byval flags as long) as long
declare function spng_encode_scanline(byval ctx as spng_ctx ptr, byval scanline as const any ptr, byval len as uinteger) as long
declare function spng_encode_row(byval ctx as spng_ctx ptr, byval row as const any ptr, byval len as uinteger) as long
declare function spng_encode_chunks(byval ctx as spng_ctx ptr) as long
declare function spng_get_ihdr(byval ctx as spng_ctx ptr, byval ihdr as spng_ihdr ptr) as long
declare function spng_get_plte(byval ctx as spng_ctx ptr, byval plte as spng_plte ptr) as long
declare function spng_get_trns(byval ctx as spng_ctx ptr, byval trns as spng_trns ptr) as long
declare function spng_get_chrm(byval ctx as spng_ctx ptr, byval chrm as spng_chrm ptr) as long
declare function spng_get_chrm_int(byval ctx as spng_ctx ptr, byval chrm_int as spng_chrm_int ptr) as long
declare function spng_get_gama(byval ctx as spng_ctx ptr, byval gamma as double ptr) as long
declare function spng_get_gama_int(byval ctx as spng_ctx ptr, byval gama_int as ulong ptr) as long
declare function spng_get_iccp(byval ctx as spng_ctx ptr, byval iccp as spng_iccp ptr) as long
declare function spng_get_sbit(byval ctx as spng_ctx ptr, byval sbit as spng_sbit ptr) as long
declare function spng_get_srgb(byval ctx as spng_ctx ptr, byval rendering_intent as ubyte ptr) as long
declare function spng_get_text(byval ctx as spng_ctx ptr, byval text as spng_text ptr, byval n_text as ulong ptr) as long
declare function spng_get_bkgd(byval ctx as spng_ctx ptr, byval bkgd as spng_bkgd ptr) as long
declare function spng_get_hist(byval ctx as spng_ctx ptr, byval hist as spng_hist ptr) as long
declare function spng_get_phys(byval ctx as spng_ctx ptr, byval phys as spng_phys ptr) as long
declare function spng_get_splt(byval ctx as spng_ctx ptr, byval splt as spng_splt ptr, byval n_splt as ulong ptr) as long
declare function spng_get_time(byval ctx as spng_ctx ptr, byval time as spng_time ptr) as long
declare function spng_get_unknown_chunks(byval ctx as spng_ctx ptr, byval chunks as spng_unknown_chunk ptr, byval n_chunks as ulong ptr) as long
declare function spng_get_offs(byval ctx as spng_ctx ptr, byval offs as spng_offs ptr) as long
declare function spng_get_exif(byval ctx as spng_ctx ptr, byval exif as spng_exif ptr) as long
declare function spng_set_ihdr(byval ctx as spng_ctx ptr, byval ihdr as spng_ihdr ptr) as long
declare function spng_set_plte(byval ctx as spng_ctx ptr, byval plte as spng_plte ptr) as long
declare function spng_set_trns(byval ctx as spng_ctx ptr, byval trns as spng_trns ptr) as long
declare function spng_set_chrm(byval ctx as spng_ctx ptr, byval chrm as spng_chrm ptr) as long
declare function spng_set_chrm_int(byval ctx as spng_ctx ptr, byval chrm_int as spng_chrm_int ptr) as long
declare function spng_set_gama(byval ctx as spng_ctx ptr, byval gamma as double) as long
declare function spng_set_gama_int(byval ctx as spng_ctx ptr, byval gamma as ulong) as long
declare function spng_set_iccp(byval ctx as spng_ctx ptr, byval iccp as spng_iccp ptr) as long
declare function spng_set_sbit(byval ctx as spng_ctx ptr, byval sbit as spng_sbit ptr) as long
declare function spng_set_srgb(byval ctx as spng_ctx ptr, byval rendering_intent as ubyte) as long
declare function spng_set_text(byval ctx as spng_ctx ptr, byval text as spng_text ptr, byval n_text as ulong) as long
declare function spng_set_bkgd(byval ctx as spng_ctx ptr, byval bkgd as spng_bkgd ptr) as long
declare function spng_set_hist(byval ctx as spng_ctx ptr, byval hist as spng_hist ptr) as long
declare function spng_set_phys(byval ctx as spng_ctx ptr, byval phys as spng_phys ptr) as long
declare function spng_set_splt(byval ctx as spng_ctx ptr, byval splt as spng_splt ptr, byval n_splt as ulong) as long
declare function spng_set_time(byval ctx as spng_ctx ptr, byval time as spng_time ptr) as long
declare function spng_set_unknown_chunks(byval ctx as spng_ctx ptr, byval chunks as spng_unknown_chunk ptr, byval n_chunks as ulong) as long
declare function spng_set_offs(byval ctx as spng_ctx ptr, byval offs as spng_offs ptr) as long
declare function spng_set_exif(byval ctx as spng_ctx ptr, byval exif as spng_exif ptr) as long
declare function spng_strerror(byval err as long) as const zstring ptr
declare function spng_version_string() as const zstring ptr

end extern
There are many variable names conflict with FreeBASIC keywords, like apha, type,... In your translation you forgot to rename them, too. BTW, how could you find the missing typedef that fbfrog not translated? Even though it's a short header but comparing the generated .bi with the original .h manually is almost impossible for me.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Translation of libspng

Post by j8w344c6 »

How could we know if there are variable names conflict with FreeBASIC keywords to replace them from the first place? FreeBASIC keywords are simply too many. Only when I opened the translated .bi header in Geany I found those variable names being highlighted so I know they are FreeBASIC keywords. But this is not guaranteed to work, though. Sometimes I just miss some of them. Regardless of how good your eyes could be, you can't catch all of the variable names conflicted with and highlighted as keywords. It seems there is no reliable way to check it and you have to do trial and error by actually including the generated .bi header into test application and try to compile it.
adeyblue
Posts: 299
Joined: Nov 07, 2019 20:08

Re: Translation of libspng

Post by adeyblue »

Image
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Translation of libspng

Post by j8w344c6 »

adeyblue wrote:Image
???
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Translation of libspng

Post by Imortis »

adeyblue wrote:Image
That is incredibly rude. Moderation just had it out with another user over this exact kind of behavior. Why would you think it is okay here?
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Translation of libspng

Post by fxm »

admins and the others,

Referring to the srvaldez' translation:

Code: Select all

Type weird As weird
#print typeof(weird)    '' ANY
Dim As weird Ptr pw
#print typeof(pw)       '' ANY PTR
Type weird As String    '' error 4: Duplicated definition in 'Type weird As String'
#print typeof(weird)    '' ANY

Type normal As _normal
#print typeof(normal)   '' error 71: Incomplete type ...
                        '' ANY PTR
Dim As normal Ptr pn
#print typeof(pn)       '' _NORMAL PTR
Type _normal As String
#print typeof(pn)       '' STRING PTR
Is the above behavior wanted (lines #1 to #6) ?
I expected an error message on line #1 (where type-name and alias-name are the same)
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Translation of libspng

Post by paul doe »

fxm wrote:...
Is the above behavior wanted (lines #1 to #6) ?
I expected an error message on line #1 (where type-name and alias-name are the same)
Weird but valid. Any was used in QB to express 'disable type checking', to allow calling procedures written in other languages. This doesn't work in the 'Fb' dialect:

Code: Select all

declare sub foo( as any )
but it does in the 'Qb' dialect:

Code: Select all

#lang "qb"

declare sub foo( as any )
So, it's probably default behavior in such a case.
Post Reply