Ported jpgtest.cxx to pure C to avoid the need for a C++ compiler

This commit is contained in:
DRC
2011-02-07 08:06:16 +00:00
parent 023d8b367d
commit 1913d03c89
7 changed files with 30 additions and 109 deletions

View File

@@ -169,7 +169,7 @@ Build Recipes
Add Add
--host i686-pc-linux-gnu CFLAGS='-O3 -m32' CXXFLAGS='-O3 -m32' LDFLAGS=-m32 --host i686-pc-linux-gnu CFLAGS='-O3 -m32' LDFLAGS=-m32
to the configure command line. to the configure command line.
@@ -190,7 +190,7 @@ installed.
Add Add
CFLAGS='-O3 -m32' CXXFLAGS='-O3 -m32' LDFLAGS=-m32 CFLAGS='-O3 -m32' LDFLAGS=-m32
to the configure command line. to the configure command line.
@@ -202,8 +202,6 @@ Add
--host x86_64-apple-darwin NASM=/opt/local/bin/nasm \ --host x86_64-apple-darwin NASM=/opt/local/bin/nasm \
CFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ CFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \
-mmacosx-version-min=10.4 -O3' \
CXXFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \
-mmacosx-version-min=10.4 -O3' \ -mmacosx-version-min=10.4 -O3' \
LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \
-mmacosx-version-min=10.4' -mmacosx-version-min=10.4'
@@ -218,8 +216,6 @@ MacPorts, must be installed.
Add Add
CFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ CFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \
-mmacosx-version-min=10.4 -O3 -m32' \
CXXFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \
-mmacosx-version-min=10.4 -O3 -m32' \ -mmacosx-version-min=10.4 -O3 -m32' \
LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \
-mmacosx-version-min=10.4 -m32' -mmacosx-version-min=10.4 -m32'
@@ -232,7 +228,7 @@ to the configure command line. The OS X 10.4 SDK must be installed.
Add Add
--host x86_64-pc-solaris CFLAGS='-O3 -m64' CXXFLAGS='-O3 -m64' LDFLAGS=-m64 --host x86_64-pc-solaris CFLAGS='-O3 -m64' LDFLAGS=-m64
to the configure command line. to the configure command line.
@@ -242,8 +238,8 @@ to the configure command line.
Add Add
--host i386-unknown-freebsd CC='gcc -B /usr/lib32' CXX='g++ -B/usr/lib32' \ --host i386-unknown-freebsd CC='gcc -B /usr/lib32' CFLAGS='-O3 -m32' \
CFLAGS='-O3 -m32' CXXFLAGS='-O3 -m32' LDFLAGS='-B/usr/lib32' LDFLAGS='-B/usr/lib32'
to the configure command line. NASM 2.07 or later from FreeBSD ports must be to the configure command line. NASM 2.07 or later from FreeBSD ports must be
installed. installed.
@@ -254,15 +250,14 @@ Sun Studio
Add Add
CC=cc CXX=CC CC=cc
to the configure command line. libjpeg-turbo will automatically be built with to the configure command line. libjpeg-turbo will automatically be built with
the maximum optimization level (-xO5) unless you override CFLAGS and CXXFLAGS. the maximum optimization level (-xO5) unless you override CFLAGS.
To build a 64-bit version of libjpeg-turbo using Sun Studio, add To build a 64-bit version of libjpeg-turbo using Sun Studio, add
--host x86_64-pc-solaris CC=cc CXX=CC CFLAGS='-xO5 -m64' \ --host x86_64-pc-solaris CC=cc CFLAGS='-xO5 -m64' LDFLAGS=-m64
CXXFLAGS='-xO5 -m64' LDFLAGS=-m64
to the configure command line. to the configure command line.
@@ -502,7 +497,7 @@ Build Recipes
---------------------------- ----------------------------
cd {build_directory} cd {build_directory}
CC=/usr/bin/x86_64-w64-mingw32-gcc CXX=/usr/bin/x86_64-w64-mingw32-g++ \ CC=/usr/bin/x86_64-w64-mingw32-gcc \
cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \ cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_AR=/usr/bin/x86_64-w64-mingw32-ar \ -DCMAKE_AR=/usr/bin/x86_64-w64-mingw32-ar \
-DCMAKE_RANLIB=/usr/bin/x86_64-w64-mingw32-ranlib {source_directory} -DCMAKE_RANLIB=/usr/bin/x86_64-w64-mingw32-ranlib {source_directory}
@@ -517,7 +512,7 @@ mingw64-x86_64-gcc-g++ packages (and their dependencies) must be installed.
---------------------------- ----------------------------
cd {build_directory} cd {build_directory}
CC=/usr/bin/i686-w64-mingw32-gcc CXX=/usr/bin/i686-w64-mingw32-g++ \ CC=/usr/bin/i686-w64-mingw32-gcc \
cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \ cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
-DDCMAKE_AR=/usr/bin/i686-w64-mingw32-ar \ -DDCMAKE_AR=/usr/bin/i686-w64-mingw32-ar \
-DCMAKE_RANLIB=/usr/bin/i686-w64-mingw32-ranlib {source_directory} -DCMAKE_RANLIB=/usr/bin/i686-w64-mingw32-ranlib {source_directory}
@@ -536,7 +531,6 @@ toolchain (which is faster than the Cygwin version):
cd {build_directory} cd {build_directory}
CC={mingw-w64_binary_path}/x86_64-w64-mingw32-gcc \ CC={mingw-w64_binary_path}/x86_64-w64-mingw32-gcc \
CXX={mingw-w64_binary_path}/x86_64-w64-mingw32-g++ \
cmake -G "MSYS Makefiles" \ cmake -G "MSYS Makefiles" \
-DCMAKE_AR={mingw-w64_binary_path}/x86_64-w64-mingw32-ar \ -DCMAKE_AR={mingw-w64_binary_path}/x86_64-w64-mingw32-ar \
-DCMAKE_RANLIB={mingw-w64_binary_path}/x86_64-w64-mingw32-ranlib \ -DCMAKE_RANLIB={mingw-w64_binary_path}/x86_64-w64-mingw32-ranlib \
@@ -549,7 +543,6 @@ MinGW Build on Linux
cd {build_directory} cd {build_directory}
CC={mingw_binary_path}/i386-mingw32-gcc \ CC={mingw_binary_path}/i386-mingw32-gcc \
CXX={mingw_binary_path}/i386-mingw32-g++ \
cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \ cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_AR={mingw_binary_path}/i386-mingw32-ar \ -DCMAKE_AR={mingw_binary_path}/i386-mingw32-ar \
-DCMAKE_RANLIB={mingw_binary_path}/i386-mingw32-ranlib \ -DCMAKE_RANLIB={mingw_binary_path}/i386-mingw32-ranlib \

View File

@@ -86,9 +86,7 @@ endif(WITH_JPEG8)
if(MSVC) if(MSVC)
# Use the static C library for all build types # Use the static C library for all build types
foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${var} MATCHES "/MD") if(${var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}") string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
endif() endif()
@@ -203,10 +201,10 @@ target_link_libraries(jpegut turbojpeg)
add_executable(jpegut-static jpegut.c) add_executable(jpegut-static jpegut.c)
target_link_libraries(jpegut-static turbojpeg-static) target_link_libraries(jpegut-static turbojpeg-static)
add_executable(jpgtest jpgtest.cxx bmp.c) add_executable(jpgtest jpgtest.c bmp.c)
target_link_libraries(jpgtest turbojpeg) target_link_libraries(jpgtest turbojpeg)
add_executable(jpgtest-static jpgtest.cxx bmp.c) add_executable(jpgtest-static jpgtest.c bmp.c)
target_link_libraries(jpgtest-static turbojpeg-static) target_link_libraries(jpgtest-static turbojpeg-static)
add_executable(cjpeg-static cjpeg.c cdjpeg.c rdbmp.c rdgif.c rdppm.c rdswitch.c add_executable(cjpeg-static cjpeg.c cdjpeg.c rdbmp.c rdgif.c rdppm.c rdswitch.c

View File

@@ -3,6 +3,8 @@
[1] Added a JNI wrapper for TurboJPEG/OSS. See java/README for more details. [1] Added a JNI wrapper for TurboJPEG/OSS. See java/README for more details.
[2] Ported jpgtest.cxx to pure C to avoid the need for a C++ compiler.
1.1.0 1.1.0
===== =====

View File

@@ -79,7 +79,7 @@ TSTHDRS = rrutil.h rrtimer.h
bin_PROGRAMS = cjpeg djpeg jpegtran rdjpgcom wrjpgcom bin_PROGRAMS = cjpeg djpeg jpegtran rdjpgcom wrjpgcom
noinst_PROGRAMS = jpgtest jpegut noinst_PROGRAMS = jpgtest jpegut
jpgtest_SOURCES = $(TSTHDRS) jpgtest.cxx bmp.h bmp.c jpgtest_SOURCES = $(TSTHDRS) jpgtest.c bmp.h bmp.c
jpgtest_LDADD = libturbojpeg.la jpgtest_LDADD = libturbojpeg.la

View File

@@ -13,10 +13,8 @@ AC_DEFINE([HAVE_PROTOTYPES], 1, [Define if your compiler supports prototypes])
# Checks for programs. # Checks for programs.
SAVED_CFLAGS=${CFLAGS} SAVED_CFLAGS=${CFLAGS}
SAVED_CXXFLAGS=${CXXFLAGS}
AC_PROG_CPP AC_PROG_CPP
AC_PROG_CC AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL AC_PROG_INSTALL
AC_PROG_LIBTOOL AC_PROG_LIBTOOL
AC_PROG_LN_S AC_PROG_LN_S
@@ -32,9 +30,6 @@ if test "x${GCC}" = "xyes"; then
if test "x${SAVED_CFLAGS}" = "x"; then if test "x${SAVED_CFLAGS}" = "x"; then
CFLAGS=-O3 CFLAGS=-O3
fi fi
if test "x${SAVED_CXXFLAGS}" = "x"; then
CXXFLAGS=-O3
fi
fi fi
AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"]) AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
@@ -42,9 +37,6 @@ if test "x${SUNCC}" = "xyes"; then
if test "x${SAVED_CFLAGS}" = "x"; then if test "x${SAVED_CFLAGS}" = "x"; then
CFLAGS=-xO5 CFLAGS=-xO5
fi fi
if test "x${SAVED_CXXFLAGS}" = "x"; then
CXXFLAGS=-xO5
fi
fi fi
# Checks for libraries. # Checks for libraries.

View File

@@ -1,6 +1,6 @@
/* Copyright (C)2004 Landmark Graphics Corporation /* Copyright (C)2004 Landmark Graphics Corporation
* Copyright (C)2005, 2006 Sun Microsystems, Inc. * Copyright (C)2005, 2006 Sun Microsystems, Inc.
* Copyright (C)2009-2010 D. R. Commander * Copyright (C)2009-2011 D. R. Commander
* *
* This library is free software and may be redistributed and/or modified under * This library is free software and may be redistributed and/or modified under
* the terms of the wxWindows Library License, Version 3.1 or (at your option) * the terms of the wxWindows Library License, Version 3.1 or (at your option)
@@ -64,19 +64,19 @@ void printsigfig(double val, int figs)
printf(format, val); printf(format, val);
} }
void dotest(unsigned char *srcbuf, int w, int h, BMPPIXELFORMAT pf, int bu, void dotest(unsigned char *srcbuf, int w, int h, int pf, int bu,
int jpegsub, int qual, char *filename, int dotile, int useppm, int quiet) int jpegsub, int qual, char *filename, int dotile, int useppm, int quiet)
{ {
char tempstr[1024]; char tempstr[1024];
FILE *outfile=NULL; tjhandle hnd; FILE *outfile=NULL; tjhandle hnd;
unsigned char **jpegbuf=NULL, *rgbbuf=NULL; unsigned char **jpegbuf=NULL, *rgbbuf=NULL;
rrtimer timer; double elapsed; double start, elapsed;
int jpgbufsize=0, i, j, tilesizex, tilesizey, numtilesx, numtilesy, ITER; int jpgbufsize=0, i, j, tilesizex, tilesizey, numtilesx, numtilesy, ITER;
unsigned long *comptilesize=NULL; unsigned long *comptilesize=NULL;
int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0) int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0)
|(forcesse2?TJ_FORCESSE2:0)|(forcesse3?TJ_FORCESSE3:0) |(forcesse2?TJ_FORCESSE2:0)|(forcesse3?TJ_FORCESSE3:0)
|(fastupsample?TJ_FASTUPSAMPLE:0); |(fastupsample?TJ_FASTUPSAMPLE:0);
int ps=_ps[pf]; int ps=_ps[pf], tilen;
int pitch=w*ps, yuvsize; int pitch=w*ps, yuvsize;
int hsf=_hsf[jpegsub], vsf=_vsf[jpegsub]; int hsf=_hsf[jpegsub], vsf=_vsf[jpegsub];
int pw=PAD(w, hsf), ph=PAD(h, vsf); int pw=PAD(w, hsf), ph=PAD(h, vsf);
@@ -129,10 +129,10 @@ void dotest(unsigned char *srcbuf, int w, int h, BMPPIXELFORMAT pf, int bu,
jpegbuf[0], &comptilesize[0], jpegsub, qual, flags)==-1) jpegbuf[0], &comptilesize[0], jpegsub, qual, flags)==-1)
_throwtj("executing tjCompress()"); _throwtj("executing tjCompress()");
ITER=0; ITER=0;
timer.start(); start=rrtime();
do do
{ {
jpgbufsize=0; int tilen=0; jpgbufsize=0; tilen=0;
for(i=0; i<h; i+=tilesizey) for(i=0; i<h; i+=tilesizey)
{ {
for(j=0; j<w; j+=tilesizex) for(j=0; j<w; j+=tilesizex)
@@ -147,7 +147,7 @@ void dotest(unsigned char *srcbuf, int w, int h, BMPPIXELFORMAT pf, int bu,
} }
} }
ITER++; ITER++;
} while((elapsed=timer.elapsed())<5.); } while((elapsed=rrtime()-start)<5.);
if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()"); if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()");
hnd=NULL; hnd=NULL;
if(quiet) if(quiet)
@@ -196,7 +196,7 @@ void dotest(unsigned char *srcbuf, int w, int h, BMPPIXELFORMAT pf, int bu,
tilesizey, ps, flags)==-1) tilesizey, ps, flags)==-1)
_throwtj("executing tjDecompress()"); _throwtj("executing tjDecompress()");
ITER=0; ITER=0;
timer.start(); start=rrtime();
do do
{ {
int tilen=0; int tilen=0;
@@ -212,7 +212,7 @@ void dotest(unsigned char *srcbuf, int w, int h, BMPPIXELFORMAT pf, int bu,
} }
} }
ITER++; ITER++;
} while((elapsed=timer.elapsed())<5.); } while((elapsed=rrtime()-start)<5.);
if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()"); if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()");
hnd=NULL; hnd=NULL;
if(quiet) if(quiet)
@@ -301,13 +301,13 @@ void dotest(unsigned char *srcbuf, int w, int h, BMPPIXELFORMAT pf, int bu,
} }
void dodecomptest(char *filename, BMPPIXELFORMAT pf, int bu, int useppm, void dodecomptest(char *filename, int pf, int bu, int useppm,
int quiet) int quiet)
{ {
char tempstr[1024]; char tempstr[1024];
FILE *file=NULL; tjhandle hnd; FILE *file=NULL; tjhandle hnd;
unsigned char *jpegbuf=NULL, *rgbbuf=NULL; unsigned char *jpegbuf=NULL, *rgbbuf=NULL;
rrtimer timer; double elapsed; double start, elapsed;
int w, h, ITER; int w, h, ITER;
unsigned long jpgbufsize=0; unsigned long jpgbufsize=0;
int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0) int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0)
@@ -373,14 +373,14 @@ void dodecomptest(char *filename, BMPPIXELFORMAT pf, int bu, int useppm,
if(tjDecompress(hnd, jpegbuf, jpgbufsize, rgbbuf, w, pitch, h, ps, flags)==-1) if(tjDecompress(hnd, jpegbuf, jpgbufsize, rgbbuf, w, pitch, h, ps, flags)==-1)
_throwtj("executing tjDecompress()"); _throwtj("executing tjDecompress()");
ITER=0; ITER=0;
timer.start(); start=rrtime();
do do
{ {
if(tjDecompress(hnd, jpegbuf, jpgbufsize, rgbbuf, w, pitch, h, ps, flags) if(tjDecompress(hnd, jpegbuf, jpgbufsize, rgbbuf, w, pitch, h, ps, flags)
==-1) ==-1)
_throwtj("executing tjDecompress()"); _throwtj("executing tjDecompress()");
ITER++; ITER++;
} while((elapsed=timer.elapsed())<5.); } while((elapsed=rrtime()-start)<5.);
if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()"); if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()");
hnd=NULL; hnd=NULL;
if(quiet) if(quiet)
@@ -449,7 +449,7 @@ int main(int argc, char *argv[])
{ {
unsigned char *bmpbuf=NULL; int w, h, i, useppm=0; unsigned char *bmpbuf=NULL; int w, h, i, useppm=0;
int qual, dotile=0, quiet=0, hiqual=-1; char *temp; int qual, dotile=0, quiet=0, hiqual=-1; char *temp;
BMPPIXELFORMAT pf=BMP_BGR; int pf=BMP_BGR;
int bu=0, minarg=2; int bu=0, minarg=2;
printf("\n"); printf("\n");

View File

@@ -15,69 +15,6 @@
#ifndef __RRTIMER_H__ #ifndef __RRTIMER_H__
#define __RRTIMER_H__ #define __RRTIMER_H__
#ifdef __cplusplus
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/time.h>
#endif
class rrtimer
{
public:
rrtimer(void) : t1(0.0)
{
#ifdef _WIN32
highres=false; tick=0.001;
LARGE_INTEGER Frequency;
if(QueryPerformanceFrequency(&Frequency)!=0)
{
tick=(double)1.0/(double)(Frequency.QuadPart);
highres=true;
}
#endif
}
void start(void)
{
t1=time();
}
double time(void)
{
#ifdef _WIN32
if(highres)
{
LARGE_INTEGER Time;
QueryPerformanceCounter(&Time);
return((double)(Time.QuadPart)*tick);
}
else
return((double)GetTickCount()*tick);
#else
struct timeval __tv;
gettimeofday(&__tv, (struct timezone *)NULL);
return((double)(__tv.tv_sec)+(double)(__tv.tv_usec)*0.000001);
#endif
}
double elapsed(void)
{
return time()-t1;
}
private:
#ifdef _WIN32
bool highres; double tick;
#endif
double t1;
};
#endif // __cplusplus
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@@ -111,4 +48,3 @@ static __inline double rrtime(void)
#endif #endif
#endif #endif