libjpeg

Windows specific questions.
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

libjpeg

Post by Macq »

Hi guys,

I'm trying to compile
FreeBASIC-1.09.0-winlibs-gcc-9.3.0\examples\files\jpeglib\example.bas
but I don't have libjpeg.a

Where do I get it or how do I compile the source from http://ijg.org/ so that the result will work with my FB compiler?
I only care about the 64bit version.
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: libjpeg

Post by Macq »

I should have started this thread under Library Questions. My bad.

The 32bit library from
https://sourceforge.net/projects/fbc/fi ... Libraries/
works Ok, but I want 64bit.


When I build the library using
https://github.com/skeeto/w64devkit
I can "make test" and it builds and passes all tests.

When I compile example.bas as 64bit and it is linked to the 64bit libjpeg.a this happens:

\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\examples\files\jpeglib>example.exe
JPEG parameter struct mismatch: library thinks size is 664, caller expects 632

The message is in jerror.h

jpeglib.bi appears to be correct when compared to jpeglib.h

Is it some sort of compiler incompatibility and alignment problem?
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: libjpeg

Post by dodicat »

I get that also.
I compiled the source, unfortunately there is no jconfig to match the gcc compiler.
I had to test out a few (rename to jconfig.h).
jconfig.h for DJGPP seemed to be the closest.
jconfig.txt gives some clues, so I dare say an in depth look at this might come up trumps for gcc.
So I was left with a pile of warnings and some errors after compiling the *.c files to .o files.
I put this (library thinks size is 664, caller expects 632) down to these errors.
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: libjpeg

Post by Macq »

Hi dodicat,

Thanks for spending some time and effort on this.

Is there a way to persuade the gcc and other GNU tools in \FreeBASIC-1.09.0-winlibs-gcc-9.3.0\bin\win64 to make this library? I have the feeling that if the same compiler compiled the library and the test program then it would be able to produce a working executable. So far it's just a feeling :D


I don't get any errors or warnings.

Code: Select all

/* jconfig.h --- generated by ckconfig.c */
/* see jconfig.txt for explanations */

#define HAVE_PROTOTYPES
#define HAVE_UNSIGNED_CHAR
#define HAVE_UNSIGNED_SHORT
/* #define void char */
/* #define const */
#undef CHAR_IS_UNSIGNED
#define HAVE_STDDEF_H
#define HAVE_STDLIB_H
#undef NEED_BSD_STRINGS
#undef NEED_SYS_TYPES_H
#undef NEED_FAR_POINTERS
#undef NEED_SHORT_EXTERNAL_NAMES
#undef INCOMPLETE_TYPES_BROKEN

#ifdef JPEG_INTERNALS

#undef RIGHT_SHIFT_IS_UNSIGNED

#endif /* JPEG_INTERNALS */

#ifdef JPEG_CJPEG_DJPEG

#define BMP_SUPPORTED		/* BMP image file format */
#define GIF_SUPPORTED		/* GIF image file format */
#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
#undef RLE_SUPPORTED		/* Utah RLE image file format */
#define TARGA_SUPPORTED		/* Targa image file format */

#undef TWO_FILE_COMMANDLINE	/* You may need this on non-Unix systems */
#undef NEED_SIGNAL_CATCHER	/* Define this if you use jmemname.c */
#undef DONT_USE_B_MODE
/* #define PROGRESS_REPORT */	/* optional */

#endif /* JPEG_CJPEG_DJPEG */

Code: Select all

# Makefile for Independent JPEG Group's software

# This makefile is suitable for Unix-like systems with ANSI-capable compilers.
# If you have a non-ANSI compiler, makefile.unix is a better starting point.

# Read installation instructions before saying "make" !!

# The name of your C compiler:
CC= gcc

# You may need to adjust these cc options:
CFLAGS= -g -O6
# Generally, we recommend defining any configuration symbols in jconfig.h,
# NOT via -D switches here.

# Link-time cc options:
LDFLAGS= 

# To link any special libraries, add the necessary -l commands here.
LDLIBS= 

# Put here the object file name for the correct system-dependent memory
# manager file.  For Unix this is usually jmemnobs.o, but you may want
# to use jmemansi.o or jmemname.o if you have limited swap space.
SYSDEPMEM= jmemnobs.o

# miscellaneous OS-dependent stuff
# linker
LN= $(CC)
# file deletion command
RM= rm -f
# library (.a) file creation command
AR= ar rc
# second step in .a creation (use "touch" if not needed)
AR2= ranlib

# End of configurable options.

dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: libjpeg

Post by dodicat »

I have gcc from
https://winlibs.com/
I don't use it for fb, but I mess about with c and c++ sometimes.
I still get warnings/errors with your jconfig.h, perhaps because I use
gcc version 12.1.0 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders).

I didn't use a makefile, rather
gcc -c *.c
then
ar rcs -o libjpeg.a *.o
I'll test it all out again later on.
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: libjpeg

Post by Macq »

~ $ gcc --version
gcc (GCC) 12.1.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The gcc from w64devkit looks more generic.

I have managed to compile libjpeg using the tools in FreeBASIC-1.09.0-winlibs-gcc-9.3.0 except that I had to tell gcc to use include files from w64devkit because it doesn't appear to have any of its own.

The result of using the library is the same error. jpeglib.bi must be not quite right. That 32 byte difference is a good clue.

Here is a bat file that gets the job done. It assumes that the root of your drive looks like this:
FreeBASIC-1.09.0-winlibs-gcc-9.3.0
jpeg-9e
w64devkit
@echo off

PATH=\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\bin\win64

set FB64=\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\fbc64.exe
set GCCINCLUDE=\w64devkit\x86_64-w64-mingw32\include
set GCCLIB=\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\lib\win64

set CFILES=jcapimin jcapistd jcarith jctrans jcparam jdatadst jcinit jcmaster jcmarker jcmainct jcprepct jccoefct jccolor jcsample jchuff jcdctmgr jfdctfst jfdctflt jfdctint jdapimin jdapistd jdarith jdtrans jdatasrc jdmaster jdinput jdmarker jdhuff jdmainct jdcoefct jdpostct jddctmgr jidctfst jidctflt jidctint jdsample jdcolor jquant1 jquant2 jdmerge jaricom jcomapi jutils jerror jmemmgr jmemnobs

if not exist %GCCINCLUDE%\mm_malloc.h echo /* I am a dummy */ > %GCCINCLUDE%\mm_malloc.h

echo From *.c to *.asm

for %%C in ( %CFILES% ) do GCC -I %GCCINCLUDE% -B %GCCLIB% -m64 -march=x86-64 -S -nostdlib -nostdinc -Wall -Wno-unused -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wno-format -masm=intel %%C.c -o %%C.asm

echo From *.asm to *.o

for %%C in ( %CFILES% ) do AS --64 --strip-local-absolute %%C.asm -o %%C.o

echo From *.o to libjpeg.a

%FB64% jcapimin.o jcapistd.o jcarith.o jctrans.o jcparam.o jdatadst.o jcinit.o jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o jcsample.o jchuff.o jcdctmgr.o jfdctfst.o jfdctflt.o jfdctint.o jdapimin.o jdapistd.o jdarith.o jdtrans.o jdatasrc.o jdmaster.o jdinput.o jdmarker.o jdhuff.o jdmainct.o jdcoefct.o jdpostct.o jddctmgr.o jidctfst.o jidctflt.o jidctint.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o jaricom.o jcomapi.o jutils.o jerror.o jmemmgr.o jmemnobs.o -v -lib -x libjpeg.a

dir libjpeg.a

echo ***** DONE!
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: libjpeg

Post by Macq »

It works :wink:

I don't think that jpeglib.bi was ever tested with a 64bit windows compiler. Perhaps it was tested with 64bit linux.
The conditionals are becoming convoluted, but it works now so I'm happy.

Code: Select all

 diff -b -a jpeglib\ -\ Copy.bi jpeglib.bi
--- jpeglib - Copy.bi
+++ jpeglib.bi
@@ -92,10 +92,14 @@
 type JDIMENSION as ulong
 const JPEG_MAX_DIMENSION = cast(clong, 65500)

+#if defined(__FB_WIN32__) and (__JPEGLIB_VER__ >= 8) and defined(__FB_64BIT__)
+       type jpeg_boolean as long
+#else
 #if defined(__FB_WIN32__) and (__JPEGLIB_VER__ >= 8)
        type jpeg_boolean as ubyte
 #else
        type jpeg_boolean as long
+#endif
 #endif

 #ifndef CTRUE

dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: libjpeg

Post by dodicat »

Yea, that's it now, even with my libjpeg.a conceived with all those warnings (and some errors)

For fun. Windows.
Put fblogo.jpg and color.jpg into a temp folder.
Put this code into the same folder and run it.
(call it whatever you like)

Code: Select all


Declare Function CryptBinaryToString Lib "Crypt32"Alias "CryptBinaryToStringA"(As zstring Ptr,As Long,As Long,As zstring Ptr,As Long Ptr) As Long

Declare Function CryptStringToBinary Lib "Crypt32"Alias "CryptStringToBinaryA"(As zstring Ptr,As Long,As Long,As Byte Ptr,As Long Ptr,As Long,As Long Ptr) As Long

dim as string s
s+= "ITxhcmNoPgovICAgICAgICAgICAgICAgMTY2NjgyNzM1MiAgMCAgICAgMCAgICAg" +chr(13,10)
s+= "MCAgICAgICAzNiAgICAgICAgYAoAAAADAAADfgAAA34AAAN+UExPQUQAR0VUU0la" +chr(13,10)
s+= "RQBQU0FWRQBfX2ZiX2N0LmluZi8gICAgMTY2NjgyNzM1MiAgMCAgICAgMCAgICAg" +chr(13,10)
s+= "MTAwNjY2ICA3MzAgICAgICAgYApkhgUAAAAAAMwBAAANAAAAAAAFAC50ZXh0AAAA" +chr(13,10)
s+= "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAUGAuZGF0YQAAAAAAAAAAAAAA" +chr(13,10)
s+= "AAAAAAAAAAAAAAAAAAAAAAAAAABAAFDALmJzcwAAAAAAAAAAAAAAAAAAAAAAAAAA" +chr(13,10)
s+= "AAAAAAAAAAAAAAAAgABQwC5mYmN0aW5mAAAAAAAAAACgAAAA3AAAAAAAAAAAAAAA" +chr(13,10)
s+= "AAAAAEAAYEAvNAAAAAAAAAAAAAAAAAAAUAAAAHwBAAAAAAAAAAAAAAAAAABAAFBA" +chr(13,10)
s+= "LWwAa2VybmVsMzIALWwAZ2RpMzIALWwAbXNpbWczMgAtbAB1c2VyMzIALWwAdm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AAAAAAAAAAAAAAAAAAAAAAAIAAUMAucmRhdGEAAAAA" +chr(13,10)
s+= "AAAAAAAA8AAAAMwLAAAAAAAAAAAAAAAAAABAAFBALzQAAAAAAAAAAAAAAAAAAFAA" +chr(13,10)
s+= "AAC8DAAAAAAAAAAAAAAAAAAAQABQQFVIieVBVkFVQVRXVlNIictIg+wgSIPk8EiB" +chr(13,10)
s+= "7LAAAAAPKbQksAAAAA8pvCTAAAAASIsKSIXJD4SVAgAASI0FAAAAAEiNtCSQAAAA" +chr(13,10)
s+= "SMeEJJAAAAAAAAAASIlEJChIjQUIAAAATI1kJHBIiXQkME2J4UyNBRAAAABIjRUY" +chr(13,10)
s+= "AAAASIlEJCBIx0QkcAAAAADoAAAAAEUxwEyJ4kiNTCRQSIMtFwAAAAFIgy0PAAAA" +chr(13,10)
s+= "AUjHRCRQAAAAAMdEJHABAAAASMdEJHQAAAAASMdEJHwAAAAAx4QkhAAAAAAAAADo" +chr(13,10)
s+= "AAAAAEiLCzHbSMdEJFgAAAAA6AAAAABIjVQkWEiJwUmJxOgAAAAATInhhcAPn8P3" +chr(13,10)
s+= "2+gAAAAAhdt0JDHADyi0JLAAAAAPKLwkwAAAAEiNZdBbXl9BXEFdQV5dww8fAEiL" +chr(13,10)
s+= "TCRYSI1UJEhMjUQkTMdEJEgAAAAAx0QkTAAAAADoAAAAAPMPEEQkSPMPEHQkTA8o" +chr(13,10)
s+= "yPMPWc4PLg3gAAAAegJ0mvMPED3kAAAARTHkSMeEJJAAAAAAAAAASMeEJJgAAAAA" +chr(13,10)
s+= "AAAA8w9cx/MPXPdIx4QkoAAAAAAAAABIx4QkqAAAAAAAAABIx0QkYAAAAADoAAAA" +chr(13,10)
s+= "APMPLMAPKMaJRCRo6AAAAABIiXQkIEiLTCRYSI1UJGDzDyzAQbkKICYAQbgBAAAA" +chr(13,10)
s+= "iUQkbOgAAAAA6AAAAADzDxBEJEzzD1zH6AAAAADzDyz4hf8PiC0BAAAPH0QAAEGD" +chr(13,10)
s+= "xAFEOecPjBsBAABFheR+7k1j9Ew7NRAAAAB94vMPEEQkSDHb8w9cx+gAAAAA80QP" +chr(13,10)
s+= "LOhFhe14x4PDAUE53Xy/hdt+9Ehj80g7NRgAAAB96GYP78BmD+/J80EPKsTzD1lE" +chr(13,10)
s+= "JEjzDyrLg8MB8w9YwegAAAAASIuUJKAAAADzSA8swIsUgkiLBQgAAABJD6/GSAMF" +chr(13,10)
s+= "AAAAAIkUsEE53X2j6V3///8PH0QAADHSSI0NAAAAAEyNZCRw6AAAAABIjbQkkAAA" +chr(13,10)
s+= "AE2J4UyNRCRgSIlEJDBIjQUIAAAASI0VEAAAAEiJRCQgSI0NGAAAAEiJdCQoSMeE" +chr(13,10)
s+= "JJAAAAAAAAAASMdEJHAAAAAASMdEJGAAAAAA6AAAAADoAAAAAEiJBQAAAADpRf3/" +chr(13,10)
s+= "/w8fRAAAuv////+5/////+gAAAAASItMJFjoAAAAAPMPEEQkSPMPWUQkTOgAAAAA" +chr(13,10)
s+= "8w8swOmT/f//ZmYuDx+EAAAAAABmkFVIieVBVUmJ1UFUVkyJxkUxwFNIictIg+Tw" +chr(13,10)
s+= "SIPsUEiNVCQwSI1MJCBIx0QkIAAAAADHRCQwAQAAAEjHRCQ0AAAAAEjHRCQ8AAAA" +chr(13,10)
s+= "AMdEJEQAAAAA6AAAAABIiwtIx0QkKAAAAADoAAAAAEiNVCQoSInBSYnE6AAAAABM" +chr(13,10)
s+= "ieGJw+gAAAAAhdt+EUiNZeBbXkFcQV1dww8fRAAASItMJChJifBMieroAAAAAEiL" +chr(13,10)
s+= "TCQo6AAAAABIjWXgW15BXEFdXcNmkFVIieVBV0FWQVVBVFdWU0iJ00iD5PBIgexg" +chr(13,10)
s+= "AQAARIlFIEiNRCRwSI1UJHhIx0QkeAAAAABIiUQkMEiNhCSYAAAATI2MJIgAAABI" +chr(13,10)
s+= "iUQkKEiNhCSQAAAATI2EJIAAAABIiUQkIEjHhCSAAAAAAAAAAEjHhCSIAAAAAAAA" +chr(13,10)
s+= "AEjHhCSQAAAAAAAAAEjHhCSYAAAAAAAAAEjHRCRwAAAAAOgAAAAAhcB0GzHASI1l" +chr(13,10)
s+= "yFteX0FcQV1BXkFfXcMPH4QAAAAAAEUxwEiNlCTQAAAASI2MJKAAAABIx4Qk0AAA" +chr(13,10)
s+= "AAAAAABIx4Qk2AAAAAAAAABIx4Qk4AAAAAAAAABIx4QkoAAAAAAAAADHhCTQAAAA" +chr(13,10)
s+= "AQAAAOgAAAAAhcB1jkiLTCR4QbkKICYASIuUJIAAAABIx0QkIAAAAABFMcBMjaQk" +chr(13,10)
s+= "EAEAAEjHhCSoAAAAAAAAAEjHhCQQAQAAAAAAAI1B/4mEJLgAAACNQv+JhCS8AAAA" +chr(13,10)
s+= "SI2EJKgAAABIiUQkKEjHhCQYAQAAAAAAAEjHhCQgAQAAAAAAAEjHhCQoAQAAAAAA" +chr(13,10)
s+= "AEjHhCSwAAAAAAAAAOgAAAAATIlkJCBIi4wkqAAAAEG5CiAmAEiNlCSwAAAAQbgC" +chr(13,10)
s+= "AAAA6AAAAABIi4QkgAAAAEUxyUyNWP8PH4AAAAAASItMJHgxwEyNUf9JD6/JSMHh" +chr(13,10)
s+= "Ag8fRAAATIuEJJAAAABIjRSFAAAAAEgDlCSYAAAASIPAAU0Pr8FGiwQCSIuUJCAB" +chr(13,10)
s+= "AABEiQQKSIPBBEw50HbHSYPBAU052XamSIuMJKgAAABMieJFMf/oAAAAAEiNVCRs" +chr(13,10)
s+= "SI1MJGjHRCRoAAAAAMdEJGwAAAAA6AAAAACLTCRsSMeEJMAAAAAAAAAASMeEJMgA" +chr(13,10)
s+= "AAAAAAAASYnM6AAAAACLTCRoRIniRTHkSYnASYnG6AAAAACLRCRog+gBiUQkVEiN" +chr(13,10)
s+= "hCQwAQAASIlEJEjplgEAAGYPH0QAAEmLTQBIjRUCAAAA6AAAAAC6BAAAAEiJ2YlE" +chr(13,10)
s+= "JFDoAAAAAEiNFRgAAABIicFIiUQkQOgAAAAAugUAAABIidmJxugAAAAASI0VIgAA" +chr(13,10)
s+= "AEiJwUiJRCRY6AAAAACF9kSLTCRQSItMJFhAD5TGQA+29vfehcAPlMAPtsD32AnG" +chr(13,10)
s+= "McBFhckPlMD32CHG6AAAAABMi0QkQEyJwegAAAAAhfYPhMABAACDfSBkuGQAAAAP" +chr(13,10)
s+= "RkUgQbknAAAASI20JPAAAABMjQVQAAAASMfC/////4lFIEiLRCRISInxSMcAAAAA" +chr(13,10)
s+= "AEjHQAgAAAAASMdAEAAAAABIx0AYAAAAAEjHQCAAAAAAx0QkIAAAAADoAAAAAEiL" +chr(13,10)
s+= "jCTwAAAAx4QkMAEAAAEAAADoAAAAAEiNlCQ4AQAASYnFSInB6AAAAABMienoAAAA" +chr(13,10)
s+= "AEiNRSBNjQQ+SInaSLkBAAAABAAAAEyLTCRISImEJFABAABIiYwkSAEAAEiLjCSo" +chr(13,10)
s+= "AAAA6AAAAABIifGD+AFBgN//6AAAAABBg8QBRDlkJFQPgp4AAABEieBIjRRASI08" +chr(13,10)
s+= "kEiNFcIAAABIwecDTY1sPkBJi00A6AAAAAC6BAAAAEiJ2YnG6AAAAABIjRXWAAAA" +chr(13,10)
s+= "SInBSIlEJFjoAAAAAIX2SItMJFhAD5TGQA+29vfehcAPlMAPtsD32CHG6AAAAACF" +chr(13,10)
s+= "9g+E//3//0iLjCSoAAAARTHJTY0EPkiJ2ugAAAAAg/gBQYDf/0GDxAFEOWQkVA+D" +chr(13,10)
s+= "Yv///0yJ8egAAAAASIuMJKgAAADoAAAAAEiLjCSgAAAA6AAAAABFhP8PnsDpfPv/" +chr(13,10)
s+= "/w8fRAAASYtNAEiNFS4AAADoAAAAALoEAAAASInZicboAAAAAEiNFUIAAABIicFI" +chr(13,10)
s+= "iUQkWOgAAAAAhfZIi0wkWEAPlMZAD7b2996FwA+UwA+2wPfYIcboAAAAAIX2D4VE" +chr(13,10)
s+= "////SYtNAEiNFXgAAADoAAAAALoEAAAASIn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= "FQAAAAQA7QAAABYAAAAEAP0AAAAXAAAABAAMAQAAGAAAAAQAWAEAABkAAAAEAHIB" +chr(13,10)
s+= "AAAQAAAABAB+AQAAEAAAAAQAxwEAABoAAAAEANcBAAAaAAAABAD/AQAAGwAAAAQA" +chr(13,10)
s+= "BAIAABwAAAAEABMCAAAaAAAABABAAgAADgAAAAQAUwIAABoAAAAEAHMCAAAOAAAA" +chr(13,10)
s+= "BACYAgAAGgAAAAQArwIAAA4AAAAEALoCAAAOAAAABADVAgAAEAAAAAQA3wIAAB0A" +chr(13,10)
s+= "AAAEAPsCAAAOAAAABAACAwAADgAAAAQADgMAAA4AAAAEADYDAAAeAAAABAA7AwAA" +chr(13,10)
s+= "HwAAAAQAQgMAAA4AAAAEAFsDAAAgAAAABABlAwAAIQAAAAQAdgMAABoAAAAEAOQD" +chr(13,10)
s+= "AAAVAAAABAD1AwAAFgAAAAQABQQAABcAAAAEAA8EAAAYAAAABAA0BAAAGQAAAAQA" +chr(13,10)
s+= "PgQAACEAAAAEAO0EAAAUAAAABABfBQAAFQAAAAQA+AUAACIAAAAEAB4GAAAbAAAA" +chr(13,10)
s+= "BAChBgAAIwAAAAQAwAYAACQAAAAEAOQGAAAlAAAABAD5BgAAJgAAAAQAJwcAABAA" +chr(13,10)
s+= "AAAEACwHAAAnAAAABAA9BwAAKAAAAAQARAcAABAAAAAEAFEHAAAnAAAABABgBwAA" +chr(13,10)
s+= "KAAAAAQAZwcAABAAAAAEAHQHAAAnAAAABACnBwAAGAAAAAQAtAcAABgAAAAEAN4H" +chr(13,10)
s+= "AAAQAAAABAAkCAAAKQAAAAQAPAgAABYAAAAEAE8IAAAqAAAABABXCAAAGAAAAAQA" +chr(13,10)
s+= "jggAACsAAAAEAJ0IAAAsAAAABAC+CAAAEAAAAAQA0AgAACcAAAAEAN8IAAAoAAAA" +chr(13,10)
s+= "BADmCAAAEAAAAAQA8wgAACcAAAAEABUJAAAYAAAABAA0CQAAKwAAAAQAUgkAAC0A" +chr(13,10)
s+= "AAAEAF8JAAAhAAAABABsCQAALgAAAAQAhwkAABAAAAAEAIwJAAAnAAAABACbCQAA" +chr(13,10)
s+= "KAAAAAQAogkAABAAAAAEAK8JAAAnAAAABADRCQAAGAAAAAQA5AkAABAAAAAEAOkJ" +chr(13,10)
s+= "AAAnAAAABAD6CQAAKAAAAAQAAQoAABAAAAAEAA4KAAAnAAAABAAdCgAAKAAAAAQA" +chr(13,10)
s+= "JAoAABAAAAAEADEKAAAnAAAABABkCgAAGAAAAAQAcQoAABgAAAAEAIQKAAAQAAAA" +chr(13,10)
s+= "BACJCgAAJwAAAAQAmAoAACgAAAAEAJ8KAAAQAAAABACqCgAAJwAAAAQA0AoAABgA" +chr(13,10)
s+= "AAAEAC5maWxlAAAAAAAAAP7/AABnAWZha2UAAAAAAAAAAAAAAAAAAFBMT0FEAAAA" +chr(13,10)
s+= "AAAAAAEAIAACAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAAAAAAAAMAAAADAAAA" +chr(13,10)
s+= "AAAaAAAACAAAAAMAAAADAAAAAAAnAAAAEAAAAAMAAAADAAAAAAAxAAAAGAAAAAMA" +chr(13,10)
s+= "AAADAEdFVFNJWkUAkAMAAAEAIAACAFBTQVZFAAAAUAQAAAEAIAACAC50ZXh0AAAA" +chr(13,10)
s+= "AAAAAAEAAAADAeUKAABjAAAAAAAAAAAAAAAAAC5kYXRhAAAAAAAAAAIAAAADAQAA" +chr(13,10)
s+= "AAAAAAAAAAAAAAAAAAAAAC5ic3MAAAAAAAAAAAMAAAADASAAAAAAAAAAAAAAAAAA" +chr(13,10)
s+= "AAAAAC5yZGF0YQAAAAAAAAQAAAADAegAAAAAAAAAAAAAAAAAAAAAAAAAAAA7AAAA" +chr(13,10)
s+= "AAAAAAUAAAADAUIAAAAAAAAAAAAAAAAAAAAAAAAAAABGAAAAAAAAAAAAIAACAAAA" +chr(13,10)
s+= "AABYAAAAAAAAAAAAIAACAAAAAABnAAAAAAAAAAAAIAACAAAAAAB0AAAAAAAAAAAA" +chr(13,10)
s+= "IAACAAAAAACKAAAAAAAAAAAAIAACAAAAAACYAAAAAAAAAAAAIAACAAAAAACuAAAA" +chr(13,10)
s+= "AAAAAAAAIAACAAAAAAC5AAAAAAAAAAAAIAACAAAAAADMAAAAAAAAAAAAIAACAAAA" +chr(13,10)
s+= "AADXAAAAAAAAAAAAIAACAAAAAADuAAAAAAAAAAAAIAACAAAAAAABAQAAAAAAAAAA" +chr(13,10)
s+= "IAACAAAAAAARAQAAAAAAAAAAIAACAAAAAAAeAQAAAAAAAAAAIAACAAAAAAAvAQAA" +chr(13,10)
s+= "AAAAAAAAIAACAAAAAABJAQAAAAAAAAAAIAACAAAAAABeAQAAAAAAAAAAIAACAG1h" +chr(13,10)
s+= "bGxvYwAAAAAAAAAAIAACAAAAAAB3AQAAAAAAAAAAIAACAAAAAACMAQAAAAAAAAAA" +chr(13,10)
s+= "IAACAAAAAACbAQAAAAAAAAAAIAACAAAAAACoAQAAAAAAAAAAIAACAAAAAACzAQAA" +chr(13,10)
s+= "AAAAAAAAIAACAAAAAADDAQAAAAAAAAAAIAACAAAAAADXAQAAAAAAAAAAIAACAGZy" +chr(13,10)
s+= "ZWUAAAAAAAAAAAAAIAACAAAAAADkAQAAAAAAAAAAIAACAPQBAAAucmRhdGEkenp6" +chr(13,10)
s+= "AFJPVyQxLjIxMDAAUElUQ0gkMS4yMDk3AFlZJDEuMjA5OABYWCQxLjIwOTkALnJk" +chr(13,10)
s+= "YXRhJHp6egBmYl9HZnhJbWFnZUluZm82NABHZGlwbHVzU3RhcnR1cABmYl9TdHJU" +chr(13,10)
s+= "b1dzdHIAR2RpcExvYWRJbWFnZUZyb21GaWxlAGZiX1dzdHJEZWxldGUAR2RpcEdl" +chr(13,10)
s+= "dEltYWdlRGltZW5zaW9uAG5lYXJieWludGYAR2RpcEJpdG1hcExvY2tCaXRzAGZi" +chr(13,10)
s+= "X0dmeExvY2sAZmJfU3RyQWxsb2NUZW1wRGVzY1pFeABmYl9HZnhTY3JlZW5JbmZv" +chr(13,10)
s+= "NjQAZmJfR2Z4U2NyZWVuUHRyAGZiX0dmeFVubG9jawBHZGlwRGlzcG9zZUltYWdl" +chr(13,10)
s+= "AEdkaXBDcmVhdGVCaXRtYXBGcm9tU2NhbjAAR2RpcEJpdG1hcFVubG9ja0JpdHMA" +chr(13,10)
s+= "R2RpcEdldEltYWdlRW5jb2RlcnNTaXplAEdkaXBHZXRJbWFnZUVuY29kZXJzAGZi" +chr(13,10)
s+= "X1dzdHJDb21wYXJlAGZiX1dzdHJSaWdodABmYl9TdHJJbml0AENMU0lERnJvbVN0" +chr(13,10)
s+= "cmluZwBHZGlwU2F2ZUltYWdlVG9GaWxlAGZiX1N0ckRlbGV0ZQBHZGlwbHVzU2h1" +chr(13,10)
s+= "dGRvd24A" +chr(13,10)

 Function Base64Decode(s As String) As string 
    Dim As Long  Length = Len(s)
    static As ubyte b()
    redim b(length)
    CryptStringToBinary( (s),Length,1,@b(0),@Length,0, 0)
    dim as string result=string(length,0)'+1
    for n as long=0 to length
        result[n]=b(n)
        next
    Function=result
End Function   

Sub savefile(filename As String,p As String)
    Dim As Integer n
    n=Freefile
    If Open (filename For Binary Access Write As #n)=0 Then
        Put #n,,p
        Close
    Else
        Print "Unable to save " + filename
    End If
End Sub
kill "libotherjpeg.a"
savefile("libotherjpeg.a",Base64Decode(s))
print "Press any key to finish . . ."
sleep

 
 
Then test it all out with this

Code: Select all

#inclib "otherjpeg"
declare Function Pload(Picture as String,byref i as any ptr=0) as long
declare sub getsize(picture as string,byref w as single,byref h as single) 
declare Function pSave(Image As Any Ptr, Filename As wstring, JPGQual As Ulong = 80) As Boolean
screen 19,32

dim as single w,h

pload("fblogo.jpg")

draw string(10,250),"fblogo.jpg"
getsize("color.jpg",w,h)

dim as any ptr i=imagecreate(w,h,0)
pload("color.jpg",i)

put(300,300),i,pset

draw string(330,520),"color.jpg"
get(300,300)-(300+w-1,300+h-1),i
psave(i,"color.bmp")
bload("color.bmp",i)
put(400,50),i,pset
draw string(450,30),"color.bmp"
sleep 
Last edited by dodicat on Oct 26, 2022 23:50, edited 1 time in total.
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: libjpeg

Post by Macq »

That library is impressive for its size. Only 10k! It must be calling windows routines to get most of the work done.

I decided to compare the decompress speeds of the two libraries. My results are that libjpeg is about 3 times faster. My CPU takes 2.4 seconds for 5000 reads of color.jpg via libjpeg (gcc -O3) and 8.3 seconds with libotherjpeg. libotherjpeg also hangs on to the memory so that after 5000 loops the process is getting very big.

Code: Select all


' Compare the decompress speeds of libjpeg and libotherjpeg

#include once "fbgfx.bi"
#include once "jpeglib.bi"
#include once "crt.bi"

#inclib "otherjpeg"
declare Function Pload(Picture as String,byref i as any ptr=0) as long
declare sub getsize(picture as string,byref w as single,byref h as single) 
declare Function pSave(Image As Any Ptr, Filename As wstring, JPGQual As Ulong = 80) As Boolean

Const loop_count = 5000
Const picture = "color.jpg"

declare function imageread_jpg _
	( _
		byref filename as string, _
		byval bpp as integer _
	) as any ptr



dim as any ptr img1
dim as double   StartTime, Runtime1, Runtime2
dim as integer i
dim as Single w,h

getsize(exepath( ) & "/" & picture,w,h)
Screenres w, h, 32

img1 = imageread_jpg( exepath() & "/" & picture, 32 ) ' Warm up
put (0,0), img1, pset
imagedestroy(img1)

StartTime = Timer
for i = 1 to loop_count
    img1 = imageread_jpg( exepath() & "/" & picture, 32 ) ' use libjpeg
    imagedestroy(img1) ' Avoid big memory leak
next i
Runtime1 = Timer - StartTime
beep()
img1 = imagecreate(w,h,0)
pload(exepath( ) & "/" & picture,img1) ' Warm up
imagedestroy(img1)
StartTime = Timer
for i = 1 to loop_count
    img1 = imagecreate(w,h,0)
    pload(exepath( ) & "/" & picture,img1) ' Use the "libotherjpeg" library
    imagedestroy(img1) ' Can't avoid big memory leak!
next i
Runtime2 = Timer - StartTime

print:print using "  libjpeg Runtime = ##.####";Runtime1
print:print using "otherjpeg Runtime = ##.####";Runtime2
beep:sleep
imagedestroy(img1)
end 0

function imageread_jpg (byref filename as string, byval bpp as integer) as any ptr

	dim as FILE ptr fp = fopen( filename, "rb" )
	if( fp = NULL ) then
		print:print "could not open image file " & filename
		return NULL
	end if

	dim jinfo as jpeg_decompress_struct
	dim jerr as jpeg_error_mgr

	jinfo.err = jpeg_std_error( @jerr )
	jpeg_create_decompress( @jinfo )

	jpeg_stdio_src( @jinfo, fp )
	jpeg_read_header( @jinfo, 1 )
	jpeg_start_decompress( @jinfo )

	select case( jinfo.out_color_space )
	case JCS_GRAYSCALE
		if( (jinfo.output_components <> 1) or (jinfo.out_color_components <> 1) ) then
			'' grayscale, but not 1 byte per pixel (will this ever happen?)
			return NULL
		end if
	case JCS_RGB
		if( (jinfo.output_components <> 3) or (jinfo.out_color_components <> 3) ) then
			'' RGB, but not 3 bytes per pixel (will this ever happen?)
			return NULL
		end if
	case JCS_YCbCr
		print "jpeg image uses YCbCr color space, not implemented"
		return NULL
	case JCS_CMYK
		print "jpeg image uses CMYK color space, not implemented"
		return NULL
	case JCS_YCCK
		print "jpeg image uses YCCK color space, not implemented"
		return NULL
	case else
		print "jpeg image uses unknown color space"
		return NULL
	end select

	dim rowbytes as integer
	rowbytes = jinfo.output_width * jinfo.output_components

	'' Allocate an array of rows (but with only 1 row, since we're going to
	'' read only one at a time)
	dim rows as JSAMPARRAY
	dim src as ubyte ptr
	rows = callocate( sizeof( ubyte ptr ) )
	rows[0] = callocate( rowbytes )
	src = rows[0]

	dim img as FB.IMAGE ptr
	img = imagecreate( jinfo.output_width, jinfo.output_height )

	dim pitch as integer = img->pitch
	dim as ubyte ptr dst = cast( ubyte ptr, img + 1 )

	while( jinfo.output_scanline < jinfo.output_height )
		jpeg_read_scanlines( @jinfo, rows, 1 )

		select case( jinfo.out_color_space )
		case JCS_GRAYSCALE
			dim i as integer
			select case( bpp )
			case 24, 32
				for i = 0 to rowbytes-1
					*cptr( ulong ptr, dst ) = rgb( src[i], src[i], src[i] )
					dst += 4
				next
			case 15, 16
				for i = 0 to rowbytes-1
					pset img, (i, jinfo.output_scanline-1), rgb( src[i], src[i], src[i] )
				next
			case else
				'' 8 bpp and less require a proper global palette,
				'' which contains the colors used in the image
				'for i = 0 to rowbytes-1
				'	pset img, (i, jinfo.output_scanline-1), src[i]
				'next
				memcpy( dst, src, rowbytes )
				dst += pitch
			end select

		case JCS_RGB
			imageconvertrow( src, 24, dst, bpp, jinfo.output_width )
			dst += pitch
		end select
	wend

	deallocate( rows[0] )
	deallocate( rows )

	jpeg_finish_decompress( @jinfo )
	jpeg_destroy_decompress( @jinfo )
	fclose( fp )

	function = img
end function

dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: libjpeg

Post by dodicat »

I have got rid of the leak, and tried a little optimisation.
(Above code edited, the one that makes the lib)
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: libjpeg

Post by Macq »

Yes, the leak is gone. I now get:
libjpeg Runtime = 2.1991
otherjpeg Runtime = 8.4322

I'm concerned with speed because I'm going to be scanning thousands of pictures.
Here's a little colour and silliness :lol:

Code: Select all

' Some Jpeg fun and games
' Compile as 64bit console with libotherjpeg.a in the same directory as this
#inclib "otherjpeg"
declare Function Pload(Picture as String,byref i as any ptr=0) as long
declare sub getsize(picture as string,byref w as single,byref h as single) 
declare Function pSave(Image As Any Ptr, Filename As wstring, JPGQual As Ulong = 80) As Boolean

dim as single w,h,ww,hh
screen 21,32 : ww = 1280 : hh = 1024

getsize("color.jpg",w,h)
dim as any ptr i = imagecreate(w,h,0)
pload("color.jpg",i)

dim as integer j,k
for j = 0 to (hh-h) step 10
    put(ww-w-j,hh-h-j),i,pset
next j
getsize("fblogo.jpg",w,h)
dim as any ptr logo = imagecreate(w,h,0)
pload("fblogo.jpg",logo)
for j = 0 to (hh-h) step 10
    put(j+100,hh-h-j),logo,pset
next j
sleep

Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: libjpeg

Post by Macq »

I decided to recompile libjpeg (with w64devkit) with error messages sent to a windows message box rather than STDOUT, and when I did, I had to revert to the original jpeglib.bi file.

Here's the new version of jconfig.h

Code: Select all

/* jconfig.h --- generated by ckconfig.c */
/* see jconfig.txt for explanations */

#include <windows.h>
#define USE_WINDOWS_MESSAGEBOX
#define HAVE_BOOLEAN

#define HAVE_PROTOTYPES
#define HAVE_UNSIGNED_CHAR
#define HAVE_UNSIGNED_SHORT
/* #define void char */
/* #define const */
#undef CHAR_IS_UNSIGNED
#define HAVE_STDDEF_H
#define HAVE_STDLIB_H
#undef NEED_BSD_STRINGS
#undef NEED_SYS_TYPES_H
#undef NEED_FAR_POINTERS
#undef NEED_SHORT_EXTERNAL_NAMES
#undef INCOMPLETE_TYPES_BROKEN

#ifdef JPEG_INTERNALS

#undef RIGHT_SHIFT_IS_UNSIGNED

#endif /* JPEG_INTERNALS */

#ifdef JPEG_CJPEG_DJPEG

#define BMP_SUPPORTED		/* BMP image file format */
#define GIF_SUPPORTED		/* GIF image file format */
#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
#undef RLE_SUPPORTED		/* Utah RLE image file format */
#define TARGA_SUPPORTED		/* Targa image file format */

#undef TWO_FILE_COMMANDLINE	/* You may need this on non-Unix systems */
#undef NEED_SIGNAL_CATCHER	/* Define this if you use jmemname.c */
#undef DONT_USE_B_MODE
/* #define PROGRESS_REPORT */	/* optional */

#endif /* JPEG_CJPEG_DJPEG */

srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: libjpeg

Post by srvaldez »

if you run ./configure from the msys2 shell it will create a make file as well as jconfig.h and running make will compile everything without warnings or errors
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: libjpeg

Post by srvaldez »

@Macq
how did you get w64devkit to compile jpeglib ?
were any warnings or errors generated ?
I tried w64devkit but could not get it to work, when issuing the command ./configure first it could not determine what target to build for, after passing --build=mingw64 it would then complain that it couldn't find any suitable C compiler, after passing --build=mingw64 CC=gcc it complained that it couldn't find grep in PATH:/usr/xpn4/bin or similar, after numerous attempts of setting the PATH to various values I gave up
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: libjpeg

Post by dodicat »

What exactly is this w64devkit?
I downloaded the. windows version and it says
-----------------------------
First build the image, then run it to produce a distribution .zip file:

docker build -t w64devkit .
docker run --rm w64devkit >w64devkit.zip

This takes about half an hour on modern systems. You will need an
internet connection during the first couple minutes of the build.
------------------------------------------------------------
Then later on:
---------------------------------------------------------
set PATH=c:\path\to\w64devkit\bin;%PATH%

Then to start an interactive unix shell:

sh -l
---------------------------------------------------------------
I don't want to take half an hour to build, what does this do to my system and registry?

I already have gcc 12 on my path (mingw), what does devkit do that my mingw does not do?
I already have a good ide (devcpp) which uses my mingw, and I can use a little command line editor which I made up myself.
I seem to remember the vim editor from Linux, which I disliked at the time and never used.
Thanks for your demo Macq.
Post Reply