├── .gitignore ├── LICENSE ├── Makefile ├── Makefile.am ├── Makefile.in ├── README.md ├── ReadFile.c ├── ReadFile.h ├── aclocal.m4 ├── ansi2knr.1 ├── ansi2knr.c ├── ar-lib ├── autom4te.cache ├── output.0 ├── output.1 ├── output.2 ├── output.3 ├── output.4 ├── requests ├── traces.0 ├── traces.1 ├── traces.2 ├── traces.3 └── traces.4 ├── autoscan.log ├── bilinear_resize.cl ├── bilinear_resize.clc ├── cderror.h ├── cdjpeg.c ├── cdjpeg.h ├── cjpeg.1 ├── cjpeg.c ├── ckconfig.c ├── compile ├── config.guess ├── config.log ├── config.status ├── config.sub ├── configure ├── configure.ac ├── configure.scan ├── decode_idct.cl ├── decode_idct.clc ├── depcomp ├── djpeg.1 ├── djpeg.c ├── encode_dct.cl ├── encode_dct.clc ├── example.c ├── foo.bc ├── install-sh ├── jaricom.c ├── jcapimin.c ├── jcapistd.c ├── jcarith.c ├── jccoefct.c ├── jccolor.c ├── jcdctmgr.c ├── jchuff.c ├── jcinit.c ├── jcmainct.c ├── jcmarker.c ├── jcmaster.c ├── jcomapi.c ├── jconfig.cfg ├── jconfig.h ├── jcparam.c ├── jcprepct.c ├── jcsample.c ├── jctrans.c ├── jdapimin.c ├── jdapistd.c ├── jdarith.c ├── jdatadst.c ├── jdatasrc.c ├── jdcoefct.c ├── jdcolor.c ├── jdct.h ├── jddctmgr.c ├── jdhuff.c ├── jdinput.c ├── jdmainct.c ├── jdmarker.c ├── jdmaster.c ├── jdmerge.c ├── jdpostct.c ├── jdsample.c ├── jdtrans.c ├── jerror.c ├── jerror.h ├── jfdctflt.c ├── jfdctfst.c ├── jfdctint.c ├── jidctflt.c ├── jidctfst.c ├── jidctint.c ├── jinclude.h ├── jmemansi.c ├── jmemdos.c ├── jmemmac.c ├── jmemmgr.c ├── jmemname.c ├── jmemnobs.c ├── jmemsys.h ├── jmorecfg.h ├── jocl_env.c ├── jpegint.h ├── jpeglib.h ├── jpegresize ├── jpegresize.c ├── jpegtran.1 ├── jpegtran.c ├── jquant1.c ├── jquant2.c ├── jutils.c ├── jversion.h ├── libtool ├── ltmain.sh ├── m4 ├── libtool.m4 ├── ltoptions.m4 ├── ltsugar.m4 ├── ltversion.m4 └── lt~obsolete.m4 ├── main.c ├── missing ├── ocl_transupp.c ├── ocl_transupp.h ├── rdbmp.c ├── rdcolmap.c ├── rdgif.c ├── rdjpgcom.1 ├── rdjpgcom.c ├── rdppm.c ├── rdrle.c ├── rdswitch.c ├── rdtarga.c ├── stamp-h1 ├── testimg.jpg ├── testimgp.jpg ├── testorig.jpg ├── testprog.jpg ├── transupp.c ├── transupp.h ├── wrbmp.c ├── wrgif.c ├── wrjpgcom.1 ├── wrjpgcom.c ├── wrppm.c ├── wrrle.c └── wrtarga.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *~ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | # 3 | # Automake Makefile for the JPEG library 4 | # 5 | # This file is written by Bob Friesenhahn, Guido Vollbeding 6 | # 7 | 8 | # Sources to build library 9 | LIBSOURCES = jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \ 10 | jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \ 11 | jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \ 12 | jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \ 13 | jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \ 14 | jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \ 15 | jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \ 16 | jquant2.c jutils.c jmemmgr.c @MEMORYMGR@.c 17 | 18 | if OPENCL_SUPPORTED 19 | LIBSOURCES += ocl_transupp.c jocl_env.c 20 | endif 21 | 22 | ACLOCAL_AMFLAGS = -I m4 23 | 24 | # System dependent sources 25 | SYSDEPSOURCES = jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c 26 | 27 | # Headers which are installed to support the library 28 | INSTINCLUDES = jerror.h jmorecfg.h jpeglib.h 29 | 30 | # Headers which are not installed 31 | OTHERINCLUDES = cderror.h cdjpeg.h jdct.h jinclude.h jmemsys.h jpegint.h \ 32 | jversion.h transupp.h 33 | 34 | # Manual pages (Automake uses 'MANS' for itself) 35 | DISTMANS= cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 wrjpgcom.1 36 | 37 | # Other documentation files 38 | DOCS= README install.txt usage.txt wizard.txt example.c libjpeg.txt \ 39 | structure.txt coderules.txt filelist.txt change.log 40 | 41 | # Makefiles for various systems 42 | MKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.bcc \ 43 | makefile.mc6 makefile.dj makefile.wat makefile.vc makejdsw.vc6 \ 44 | makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 makecdep.vc6 \ 45 | makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 makedmak.vc6 \ 46 | maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 makerdsp.vc6 \ 47 | makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 makejsln.vc9 \ 48 | makeasln.vc9 makejvcp.vc9 makecvcp.vc9 makedvcp.vc9 maketvcp.vc9 \ 49 | makervcp.vc9 makewvcp.vc9 makeproj.mac makcjpeg.st makdjpeg.st \ 50 | makljpeg.st maktjpeg.st makefile.manx makefile.sas makefile.mms \ 51 | makefile.vms makvms.opt 52 | 53 | # Configuration files 54 | CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \ 55 | jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \ 56 | jconfig.vms 57 | 58 | # Support scripts for configure 59 | CONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp missing 60 | 61 | # Miscellaneous support files 62 | OTHERFILES= jconfig.txt ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm \ 63 | libjpeg.map 64 | 65 | # Test support files 66 | TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \ 67 | testimgp.jpg 68 | 69 | # libtool libraries to build 70 | lib_LTLIBRARIES = libjpeg.la 71 | 72 | # Library sources for libjpeg.la 73 | libjpeg_la_SOURCES = $(LIBSOURCES) 74 | 75 | # LDFLAGS for libjpeg.la 76 | libjpeg_la_LDFLAGS = -no-undefined \ 77 | -version-info $(JPEG_LIB_VERSION) 78 | 79 | if HAVE_LD_VERSION_SCRIPT 80 | libjpeg_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libjpeg.map 81 | endif 82 | 83 | # if OPENCL_SUPPORTED 84 | # LIBS += -framework OpenCL 85 | # LIBS += @OPENCL_LDFLAGS@ 86 | # endif 87 | 88 | # Executables to build 89 | if OPENCL_SUPPORTED 90 | bin_PROGRAMS = jpegresize 91 | else 92 | bin_PROGRAMS = cjpeg djpeg jpegtran rdjpgcom wrjpgcom 93 | endif 94 | 95 | # Executable sources & libs 96 | if OPENCL_SUPPORTED 97 | jpegresize_SOURCES = jpegresize.c 98 | jpegresize_LDADD = libjpeg.la 99 | else 100 | cjpeg_SOURCES = cjpeg.c rdppm.c rdgif.c rdtarga.c rdrle.c rdbmp.c \ 101 | rdswitch.c cdjpeg.c 102 | cjpeg_LDADD = libjpeg.la 103 | djpeg_SOURCES = djpeg.c wrppm.c wrgif.c wrtarga.c wrrle.c wrbmp.c \ 104 | rdcolmap.c cdjpeg.c 105 | djpeg_LDADD = libjpeg.la 106 | jpegtran_SOURCES = jpegtran.c rdswitch.c cdjpeg.c transupp.c 107 | jpegtran_LDADD = libjpeg.la 108 | rdjpgcom_SOURCES = rdjpgcom.c 109 | wrjpgcom_SOURCES = wrjpgcom.c 110 | endif 111 | 112 | # Manual pages to install 113 | man_MANS = $(DISTMANS) 114 | 115 | # Headers to install 116 | include_HEADERS = $(INSTINCLUDES) 117 | 118 | # Other distributed headers 119 | noinst_HEADERS = $(OTHERINCLUDES) 120 | 121 | # Other distributed files 122 | EXTRA_DIST = $(DOCS) $(DISTMANS) $(MKFILES) $(CONFIGFILES) $(SYSDEPSOURCES) \ 123 | $(OTHERFILES) $(TESTFILES) 124 | 125 | # Files to be cleaned 126 | CLEANFILES = testout.ppm testout.bmp testout.jpg testoutp.ppm testoutp.jpg \ 127 | testoutt.jpg 128 | 129 | # Install jconfig.h 130 | install-data-local: 131 | $(mkinstalldirs) $(DESTDIR)$(includedir) 132 | $(INSTALL_HEADER) jconfig.h $(DESTDIR)$(includedir)/jconfig.h 133 | 134 | # Uninstall jconfig.h 135 | uninstall-local: 136 | rm -f $(DESTDIR)$(includedir)/jconfig.h 137 | 138 | # Run tests 139 | if OPENCL_SUPPORTED 140 | else 141 | test: check-local 142 | check-local: 143 | $(RM) testout* 144 | ./djpeg -dct int -ppm -outfile testout.ppm $(srcdir)/testorig.jpg 145 | ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testorig.jpg 146 | ./cjpeg -dct int -outfile testout.jpg $(srcdir)/testimg.ppm 147 | ./djpeg -dct int -ppm -outfile testoutp.ppm $(srcdir)/testprog.jpg 148 | ./cjpeg -dct int -progressive -opt -outfile testoutp.jpg $(srcdir)/testimg.ppm 149 | ./jpegtran -outfile testoutt.jpg $(srcdir)/testprog.jpg 150 | cmp $(srcdir)/testimg.ppm testout.ppm 151 | cmp $(srcdir)/testimg.bmp testout.bmp 152 | cmp $(srcdir)/testimg.jpg testout.jpg 153 | cmp $(srcdir)/testimg.ppm testoutp.ppm 154 | cmp $(srcdir)/testimgp.jpg testoutp.jpg 155 | cmp $(srcdir)/testorig.jpg testoutt.jpg 156 | endif 157 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## OpenCL-JPEG(Beta) 2 | 3 | #### Intro 4 | 5 | Implement of JPEG codec with OpenCL fork from IJG libjpeg (v8) 6 | 7 | * Decode/Encode JPEG Image 8 | * Resize JPEG Image 9 | * Do not support libjpeg(v8) smart scale, because I do not understand the code :D 10 | * Do not support other transform now, such as rotate, crop, etc :D 11 | 12 | I recommend to use this lib with resize feature, because data transform between CPU and GPU is very expensive. 13 | 14 | #### Install 15 | 16 | * CPU Version 17 | 18 | ./configure && make && make install 19 | 20 | then you can find **cjpeg djpeg jpegtran rdjpgcom wrjpgcom** in the source directory 21 | 22 | * GPU Version 23 | 24 | * OSX 25 | 26 | ./configure --enable-opencl --enable-shared=no && make && make install 27 | 28 | 29 | then you can find **jpegresize** in the source directory. It will be some mistakes when compile shared library, so you need to disable shared library 30 | 31 | 32 | * Linux 33 | 34 | ./configure --enable-opencl --with-openclincludedir=xxx --with-opencllibdir=xxx 35 | 36 | because I do not have an Linux Computer supported OpenCL, so I do not test this branch, if you find any problem please let me know 37 | 38 | #### Usage 39 | 40 | ./jpegresize -w 500 -h 300 -q 80 -outfile han.jpg testimg.jpg 41 | 42 | The command will resize testimg.jpg to 500x300 image use your GPU device. 43 | 44 | #### TODO 45 | 46 | * Code & Performance 47 | * Benchmark 48 | * Http Server 49 | 50 | #### LICENSE 51 | 52 | MIT License 53 | -------------------------------------------------------------------------------- /ReadFile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | size_t read_all_bytes(const char * fileName,void ** mem) 6 | { 7 | FILE * file; 8 | struct stat mystat; 9 | void * content; 10 | 11 | *mem = NULL; 12 | 13 | if(0 != stat(fileName,&mystat)) 14 | { 15 | return 0; 16 | } 17 | 18 | file = fopen(fileName,"rb"); 19 | if(!file) 20 | { 21 | printf("Read file failed.\n"); 22 | return 0; 23 | } 24 | 25 | content = malloc(mystat.st_size + 1); 26 | if(content == NULL) 27 | { 28 | printf("Malloc failed.\n"); 29 | return 0; 30 | } 31 | ((char*)content)[mystat.st_size] = 0; 32 | 33 | 34 | if( mystat.st_size != fread(content,1,mystat.st_size,file)) 35 | { 36 | goto FREE_CONTENT; 37 | } 38 | *mem = content; 39 | return mystat.st_size; 40 | 41 | FREE_CONTENT: 42 | free(content); 43 | return 0; 44 | } 45 | 46 | void free_all_bytes(void * mem) 47 | { 48 | free(mem); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /ReadFile.h: -------------------------------------------------------------------------------- 1 | //#pragma once 2 | 3 | #include 4 | 5 | size_t read_all_bytes(const char * fileName,void ** mem); 6 | void free_all_bytes(void * mem); 7 | -------------------------------------------------------------------------------- /ansi2knr.1: -------------------------------------------------------------------------------- 1 | .TH ANSI2KNR 1 "19 Jan 1996" 2 | .SH NAME 3 | ansi2knr \- convert ANSI C to Kernighan & Ritchie C 4 | .SH SYNOPSIS 5 | .I ansi2knr 6 | [--varargs] input_file [output_file] 7 | .SH DESCRIPTION 8 | If no output_file is supplied, output goes to stdout. 9 | .br 10 | There are no error messages. 11 | .sp 12 | .I ansi2knr 13 | recognizes function definitions by seeing a non-keyword identifier at the left 14 | margin, followed by a left parenthesis, with a right parenthesis as the last 15 | character on the line, and with a left brace as the first token on the 16 | following line (ignoring possible intervening comments). It will recognize a 17 | multi-line header provided that no intervening line ends with a left or right 18 | brace or a semicolon. These algorithms ignore whitespace and comments, except 19 | that the function name must be the first thing on the line. 20 | .sp 21 | The following constructs will confuse it: 22 | .br 23 | - Any other construct that starts at the left margin and follows the 24 | above syntax (such as a macro or function call). 25 | .br 26 | - Some macros that tinker with the syntax of the function header. 27 | .sp 28 | The --varargs switch is obsolete, and is recognized only for 29 | backwards compatibility. The present version of 30 | .I ansi2knr 31 | will always attempt to convert a ... argument to va_alist and va_dcl. 32 | .SH AUTHOR 33 | L. Peter Deutsch wrote the original ansi2knr and 34 | continues to maintain the current version; most of the code in the current 35 | version is his work. ansi2knr also includes contributions by Francois 36 | Pinard and Jim Avera . 37 | -------------------------------------------------------------------------------- /ar-lib: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for Microsoft lib.exe 3 | 4 | me=ar-lib 5 | scriptversion=2012-03-01.08; # UTC 6 | 7 | # Copyright (C) 2010-2014 Free Software Foundation, Inc. 8 | # Written by Peter Rosin . 9 | # 10 | # This program is free software; you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation; either version 2, or (at your option) 13 | # any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | 33 | # func_error message 34 | func_error () 35 | { 36 | echo "$me: $1" 1>&2 37 | exit 1 38 | } 39 | 40 | file_conv= 41 | 42 | # func_file_conv build_file 43 | # Convert a $build file to $host form and store it in $file 44 | # Currently only supports Windows hosts. 45 | func_file_conv () 46 | { 47 | file=$1 48 | case $file in 49 | / | /[!/]*) # absolute file, and not a UNC file 50 | if test -z "$file_conv"; then 51 | # lazily determine how to convert abs files 52 | case `uname -s` in 53 | MINGW*) 54 | file_conv=mingw 55 | ;; 56 | CYGWIN*) 57 | file_conv=cygwin 58 | ;; 59 | *) 60 | file_conv=wine 61 | ;; 62 | esac 63 | fi 64 | case $file_conv in 65 | mingw) 66 | file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 67 | ;; 68 | cygwin) 69 | file=`cygpath -m "$file" || echo "$file"` 70 | ;; 71 | wine) 72 | file=`winepath -w "$file" || echo "$file"` 73 | ;; 74 | esac 75 | ;; 76 | esac 77 | } 78 | 79 | # func_at_file at_file operation archive 80 | # Iterate over all members in AT_FILE performing OPERATION on ARCHIVE 81 | # for each of them. 82 | # When interpreting the content of the @FILE, do NOT use func_file_conv, 83 | # since the user would need to supply preconverted file names to 84 | # binutils ar, at least for MinGW. 85 | func_at_file () 86 | { 87 | operation=$2 88 | archive=$3 89 | at_file_contents=`cat "$1"` 90 | eval set x "$at_file_contents" 91 | shift 92 | 93 | for member 94 | do 95 | $AR -NOLOGO $operation:"$member" "$archive" || exit $? 96 | done 97 | } 98 | 99 | case $1 in 100 | '') 101 | func_error "no command. Try '$0 --help' for more information." 102 | ;; 103 | -h | --h*) 104 | cat < (src_height - 1) ? (src_height - 1) : (src_y1 + 1); 29 | newX = dstXindex * ratioX; 30 | src_x1 = (int)newX; 31 | src_x2 = (newX + 1) > (src_width - 1) ? (src_width - 1) : (src_x1 + 1); 32 | 33 | t1 = fabs(src_x2 - newX); 34 | t2 = fabs(newX - src_x1); 35 | t3 = fabs(src_y2 - newY); 36 | t4 = fabs(newY - src_y1); 37 | 38 | /* 39 | t1 = src_x2 - newX; 40 | t2 = newX - src_x1; 41 | t3 = src_y2 - newY; 42 | t4 = newY - src_y1; 43 | */ 44 | /* Compute the in&out ptr */ 45 | __global JSAMPLE *out_ptr; 46 | 47 | /* Reserved pad samp 48 | * Org: dstWidth * dstHeight 49 | * Paded: resize_blks_in_row * resize_blks_in_height 50 | */ 51 | int pad_width, pad_height; 52 | 53 | pad_width = resize_blks_out_row * DCTSIZE; 54 | pad_height = resize_blks_out_height * DCTSIZE; 55 | 56 | out_ptr = samp_out + dstYindex * pad_width + dstXindex; 57 | /* Compute the input samp_ptr */ 58 | __global JSAMPLE *in_ptrA, *in_ptrB, *in_ptrC, *in_ptrD; 59 | in_ptrA = samp_in + src_y1 * resize_blks_in_row * DCTSIZE + src_x1; 60 | in_ptrB = samp_in + src_y1 * resize_blks_in_row * DCTSIZE + src_x2; 61 | in_ptrC = samp_in + src_y2 * resize_blks_in_row * DCTSIZE + src_x1; 62 | in_ptrD = samp_in + src_y2 * resize_blks_in_row * DCTSIZE + src_x2; 63 | 64 | JSAMPLE color_A, color_B, color_C, color_D; 65 | color_A = *in_ptrA; 66 | color_B = *in_ptrB; 67 | color_C = *in_ptrC; 68 | color_D = *in_ptrD; 69 | JSAMPLE result; 70 | result = t3 * t1 * color_A + t4 * t1 * color_B + t3 * t2 * color_C + t4 * t2 * color_D; 71 | // result = result == 0 ? (color_A + color_B + color_C + color_D)/4 : result; 72 | result = (result == 0 ? color_A : result); 73 | *out_ptr = 0; 74 | *out_ptr = result; 75 | barrier(CLK_GLOBAL_MEM_FENCE); 76 | if (add_it) 77 | { 78 | /* expand most right edge */ 79 | int add_width, add_height; 80 | add_width = pad_width - dstWidth; 81 | add_height = pad_height - dstHeight; 82 | if (dstXindex == (dstWidth -1)) 83 | { 84 | if (add_width) 85 | { 86 | int i; 87 | for(i = 1; i < add_width+1;i++) 88 | { 89 | *(out_ptr+i) = result; 90 | } 91 | } 92 | } 93 | if (dstYindex >= (dstHeight - add_height)) 94 | { 95 | if (add_height) 96 | { 97 | *(out_ptr + pad_width * add_height) = result; 98 | } 99 | } 100 | barrier(CLK_GLOBAL_MEM_FENCE); 101 | if (dstYindex >= (dstHeight-add_height) && dstXindex >= (dstWidth-add_width)) 102 | { 103 | if (add_height !=0 && add_width != 0 ) 104 | { 105 | *(out_ptr + pad_width*add_height+add_width) = result; 106 | } 107 | } 108 | 109 | /* 110 | if (dstYindex >= (dstHeight - add_height) && dstXindex == 0) 111 | { 112 | if (add_height) 113 | { 114 | int i; 115 | for(i = 0;i < pad_width;i++) 116 | { 117 | *(out_ptr + pad_width * add_height + i) = *(out_ptr + i); 118 | } 119 | } 120 | } 121 | */ 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /bilinear_resize.clc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anknown/opencl-jpeg/3ee64b66ed12c5374aa87322691731e3969e5e40/bilinear_resize.clc -------------------------------------------------------------------------------- /cderror.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cderror.h 3 | * 4 | * Copyright (C) 1994-1997, Thomas G. Lane. 5 | * Modified 2009 by Guido Vollbeding. 6 | * This file is part of the Independent JPEG Group's software. 7 | * For conditions of distribution and use, see the accompanying README file. 8 | * 9 | * This file defines the error and message codes for the cjpeg/djpeg 10 | * applications. These strings are not needed as part of the JPEG library 11 | * proper. 12 | * Edit this file to add new codes, or to translate the message strings to 13 | * some other language. 14 | */ 15 | 16 | /* 17 | * To define the enum list of message codes, include this file without 18 | * defining macro JMESSAGE. To create a message string table, include it 19 | * again with a suitable JMESSAGE definition (see jerror.c for an example). 20 | */ 21 | #ifndef JMESSAGE 22 | #ifndef CDERROR_H 23 | #define CDERROR_H 24 | /* First time through, define the enum list */ 25 | #define JMAKE_ENUM_LIST 26 | #else 27 | /* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ 28 | #define JMESSAGE(code,string) 29 | #endif /* CDERROR_H */ 30 | #endif /* JMESSAGE */ 31 | 32 | #ifdef JMAKE_ENUM_LIST 33 | 34 | typedef enum { 35 | 36 | #define JMESSAGE(code,string) code , 37 | 38 | #endif /* JMAKE_ENUM_LIST */ 39 | 40 | JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */ 41 | 42 | #ifdef BMP_SUPPORTED 43 | JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format") 44 | JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported") 45 | JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length") 46 | JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1") 47 | JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB") 48 | JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported") 49 | JMESSAGE(JERR_BMP_EMPTY, "Empty BMP image") 50 | JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM") 51 | JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image") 52 | JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image") 53 | JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image") 54 | JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image") 55 | #endif /* BMP_SUPPORTED */ 56 | 57 | #ifdef GIF_SUPPORTED 58 | JMESSAGE(JERR_GIF_BUG, "GIF output got confused") 59 | JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d") 60 | JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB") 61 | JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file") 62 | JMESSAGE(JERR_GIF_NOT, "Not a GIF file") 63 | JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image") 64 | JMESSAGE(JTRC_GIF_BADVERSION, 65 | "Warning: unexpected GIF version number '%c%c%c'") 66 | JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x") 67 | JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input") 68 | JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file") 69 | JMESSAGE(JWRN_GIF_CHAR, "Bogus char 0x%02x in GIF file, ignoring") 70 | JMESSAGE(JWRN_GIF_ENDCODE, "Premature end of GIF image") 71 | JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits") 72 | #endif /* GIF_SUPPORTED */ 73 | 74 | #ifdef PPM_SUPPORTED 75 | JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB") 76 | JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file") 77 | JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file") 78 | JMESSAGE(JTRC_PGM, "%ux%u PGM image") 79 | JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image") 80 | JMESSAGE(JTRC_PPM, "%ux%u PPM image") 81 | JMESSAGE(JTRC_PPM_TEXT, "%ux%u text PPM image") 82 | #endif /* PPM_SUPPORTED */ 83 | 84 | #ifdef RLE_SUPPORTED 85 | JMESSAGE(JERR_RLE_BADERROR, "Bogus error code from RLE library") 86 | JMESSAGE(JERR_RLE_COLORSPACE, "RLE output must be grayscale or RGB") 87 | JMESSAGE(JERR_RLE_DIMENSIONS, "Image dimensions (%ux%u) too large for RLE") 88 | JMESSAGE(JERR_RLE_EMPTY, "Empty RLE file") 89 | JMESSAGE(JERR_RLE_EOF, "Premature EOF in RLE header") 90 | JMESSAGE(JERR_RLE_MEM, "Insufficient memory for RLE header") 91 | JMESSAGE(JERR_RLE_NOT, "Not an RLE file") 92 | JMESSAGE(JERR_RLE_TOOMANYCHANNELS, "Cannot handle %d output channels for RLE") 93 | JMESSAGE(JERR_RLE_UNSUPPORTED, "Cannot handle this RLE setup") 94 | JMESSAGE(JTRC_RLE, "%ux%u full-color RLE file") 95 | JMESSAGE(JTRC_RLE_FULLMAP, "%ux%u full-color RLE file with map of length %d") 96 | JMESSAGE(JTRC_RLE_GRAY, "%ux%u grayscale RLE file") 97 | JMESSAGE(JTRC_RLE_MAPGRAY, "%ux%u grayscale RLE file with map of length %d") 98 | JMESSAGE(JTRC_RLE_MAPPED, "%ux%u colormapped RLE file with map of length %d") 99 | #endif /* RLE_SUPPORTED */ 100 | 101 | #ifdef TARGA_SUPPORTED 102 | JMESSAGE(JERR_TGA_BADCMAP, "Unsupported Targa colormap format") 103 | JMESSAGE(JERR_TGA_BADPARMS, "Invalid or unsupported Targa file") 104 | JMESSAGE(JERR_TGA_COLORSPACE, "Targa output must be grayscale or RGB") 105 | JMESSAGE(JTRC_TGA, "%ux%u RGB Targa image") 106 | JMESSAGE(JTRC_TGA_GRAY, "%ux%u grayscale Targa image") 107 | JMESSAGE(JTRC_TGA_MAPPED, "%ux%u colormapped Targa image") 108 | #else 109 | JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled") 110 | #endif /* TARGA_SUPPORTED */ 111 | 112 | JMESSAGE(JERR_BAD_CMAP_FILE, 113 | "Color map file is invalid or of unsupported format") 114 | JMESSAGE(JERR_TOO_MANY_COLORS, 115 | "Output file format cannot handle %d colormap entries") 116 | JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed") 117 | #ifdef TARGA_SUPPORTED 118 | JMESSAGE(JERR_UNKNOWN_FORMAT, 119 | "Unrecognized input file format --- perhaps you need -targa") 120 | #else 121 | JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format") 122 | #endif 123 | JMESSAGE(JERR_UNSUPPORTED_FORMAT, "Unsupported output file format") 124 | 125 | #ifdef JMAKE_ENUM_LIST 126 | 127 | JMSG_LASTADDONCODE 128 | } ADDON_MESSAGE_CODE; 129 | 130 | #undef JMAKE_ENUM_LIST 131 | #endif /* JMAKE_ENUM_LIST */ 132 | 133 | /* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ 134 | #undef JMESSAGE 135 | -------------------------------------------------------------------------------- /cdjpeg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cdjpeg.c 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains common support routines used by the IJG application 9 | * programs (cjpeg, djpeg, jpegtran). 10 | */ 11 | 12 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ 13 | #include /* to declare isupper(), tolower() */ 14 | #ifdef NEED_SIGNAL_CATCHER 15 | #include /* to declare signal() */ 16 | #endif 17 | #ifdef USE_SETMODE 18 | #include /* to declare setmode()'s parameter macros */ 19 | /* If you have setmode() but not , just delete this line: */ 20 | #include /* to declare setmode() */ 21 | #endif 22 | 23 | 24 | /* 25 | * Signal catcher to ensure that temporary files are removed before aborting. 26 | * NB: for Amiga Manx C this is actually a global routine named _abort(); 27 | * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus... 28 | */ 29 | 30 | #ifdef NEED_SIGNAL_CATCHER 31 | 32 | static j_common_ptr sig_cinfo; 33 | 34 | void /* must be global for Manx C */ 35 | signal_catcher (int signum) 36 | { 37 | if (sig_cinfo != NULL) { 38 | if (sig_cinfo->err != NULL) /* turn off trace output */ 39 | sig_cinfo->err->trace_level = 0; 40 | jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */ 41 | } 42 | exit(EXIT_FAILURE); 43 | } 44 | 45 | 46 | GLOBAL(void) 47 | enable_signal_catcher (j_common_ptr cinfo) 48 | { 49 | sig_cinfo = cinfo; 50 | #ifdef SIGINT /* not all systems have SIGINT */ 51 | signal(SIGINT, signal_catcher); 52 | #endif 53 | #ifdef SIGTERM /* not all systems have SIGTERM */ 54 | signal(SIGTERM, signal_catcher); 55 | #endif 56 | } 57 | 58 | #endif 59 | 60 | 61 | /* 62 | * Optional progress monitor: display a percent-done figure on stderr. 63 | */ 64 | 65 | #ifdef PROGRESS_REPORT 66 | 67 | METHODDEF(void) 68 | progress_monitor (j_common_ptr cinfo) 69 | { 70 | cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress; 71 | int total_passes = prog->pub.total_passes + prog->total_extra_passes; 72 | int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit); 73 | 74 | if (percent_done != prog->percent_done) { 75 | prog->percent_done = percent_done; 76 | if (total_passes > 1) { 77 | fprintf(stderr, "\rPass %d/%d: %3d%% ", 78 | prog->pub.completed_passes + prog->completed_extra_passes + 1, 79 | total_passes, percent_done); 80 | } else { 81 | fprintf(stderr, "\r %3d%% ", percent_done); 82 | } 83 | fflush(stderr); 84 | } 85 | } 86 | 87 | 88 | GLOBAL(void) 89 | start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress) 90 | { 91 | /* Enable progress display, unless trace output is on */ 92 | if (cinfo->err->trace_level == 0) { 93 | progress->pub.progress_monitor = progress_monitor; 94 | progress->completed_extra_passes = 0; 95 | progress->total_extra_passes = 0; 96 | progress->percent_done = -1; 97 | cinfo->progress = &progress->pub; 98 | } 99 | } 100 | 101 | 102 | GLOBAL(void) 103 | end_progress_monitor (j_common_ptr cinfo) 104 | { 105 | /* Clear away progress display */ 106 | if (cinfo->err->trace_level == 0) { 107 | fprintf(stderr, "\r \r"); 108 | fflush(stderr); 109 | } 110 | } 111 | 112 | #endif 113 | 114 | 115 | /* 116 | * Case-insensitive matching of possibly-abbreviated keyword switches. 117 | * keyword is the constant keyword (must be lower case already), 118 | * minchars is length of minimum legal abbreviation. 119 | */ 120 | 121 | GLOBAL(boolean) 122 | keymatch (char * arg, const char * keyword, int minchars) 123 | { 124 | register int ca, ck; 125 | register int nmatched = 0; 126 | 127 | while ((ca = *arg++) != '\0') { 128 | if ((ck = *keyword++) == '\0') 129 | return FALSE; /* arg longer than keyword, no good */ 130 | if (isupper(ca)) /* force arg to lcase (assume ck is already) */ 131 | ca = tolower(ca); 132 | if (ca != ck) 133 | return FALSE; /* no good */ 134 | nmatched++; /* count matched characters */ 135 | } 136 | /* reached end of argument; fail if it's too short for unique abbrev */ 137 | if (nmatched < minchars) 138 | return FALSE; 139 | return TRUE; /* A-OK */ 140 | } 141 | 142 | 143 | /* 144 | * Routines to establish binary I/O mode for stdin and stdout. 145 | * Non-Unix systems often require some hacking to get out of text mode. 146 | */ 147 | 148 | GLOBAL(FILE *) 149 | read_stdin (void) 150 | { 151 | FILE * input_file = stdin; 152 | 153 | #ifdef USE_SETMODE /* need to hack file mode? */ 154 | setmode(fileno(stdin), O_BINARY); 155 | #endif 156 | #ifdef USE_FDOPEN /* need to re-open in binary mode? */ 157 | if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) { 158 | fprintf(stderr, "Cannot reopen stdin\n"); 159 | exit(EXIT_FAILURE); 160 | } 161 | #endif 162 | return input_file; 163 | } 164 | 165 | 166 | GLOBAL(FILE *) 167 | write_stdout (void) 168 | { 169 | FILE * output_file = stdout; 170 | 171 | #ifdef USE_SETMODE /* need to hack file mode? */ 172 | setmode(fileno(stdout), O_BINARY); 173 | #endif 174 | #ifdef USE_FDOPEN /* need to re-open in binary mode? */ 175 | if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { 176 | fprintf(stderr, "Cannot reopen stdout\n"); 177 | exit(EXIT_FAILURE); 178 | } 179 | #endif 180 | return output_file; 181 | } 182 | -------------------------------------------------------------------------------- /cdjpeg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cdjpeg.h 3 | * 4 | * Copyright (C) 1994-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains common declarations for the sample applications 9 | * cjpeg and djpeg. It is NOT used by the core JPEG library. 10 | */ 11 | 12 | #define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */ 13 | #define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */ 14 | #include "jinclude.h" 15 | #include "jpeglib.h" 16 | #include "jerror.h" /* get library error codes too */ 17 | #include "cderror.h" /* get application-specific error codes */ 18 | 19 | 20 | /* 21 | * Object interface for cjpeg's source file decoding modules 22 | */ 23 | 24 | typedef struct cjpeg_source_struct * cjpeg_source_ptr; 25 | 26 | struct cjpeg_source_struct { 27 | JMETHOD(void, start_input, (j_compress_ptr cinfo, 28 | cjpeg_source_ptr sinfo)); 29 | JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, 30 | cjpeg_source_ptr sinfo)); 31 | JMETHOD(void, finish_input, (j_compress_ptr cinfo, 32 | cjpeg_source_ptr sinfo)); 33 | 34 | FILE *input_file; 35 | 36 | JSAMPARRAY buffer; 37 | JDIMENSION buffer_height; 38 | }; 39 | 40 | 41 | /* 42 | * Object interface for djpeg's output file encoding modules 43 | */ 44 | 45 | typedef struct djpeg_dest_struct * djpeg_dest_ptr; 46 | 47 | struct djpeg_dest_struct { 48 | /* start_output is called after jpeg_start_decompress finishes. 49 | * The color map will be ready at this time, if one is needed. 50 | */ 51 | JMETHOD(void, start_output, (j_decompress_ptr cinfo, 52 | djpeg_dest_ptr dinfo)); 53 | /* Emit the specified number of pixel rows from the buffer. */ 54 | JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo, 55 | djpeg_dest_ptr dinfo, 56 | JDIMENSION rows_supplied)); 57 | /* Finish up at the end of the image. */ 58 | JMETHOD(void, finish_output, (j_decompress_ptr cinfo, 59 | djpeg_dest_ptr dinfo)); 60 | 61 | /* Target file spec; filled in by djpeg.c after object is created. */ 62 | FILE * output_file; 63 | 64 | /* Output pixel-row buffer. Created by module init or start_output. 65 | * Width is cinfo->output_width * cinfo->output_components; 66 | * height is buffer_height. 67 | */ 68 | JSAMPARRAY buffer; 69 | JDIMENSION buffer_height; 70 | }; 71 | 72 | 73 | /* 74 | * cjpeg/djpeg may need to perform extra passes to convert to or from 75 | * the source/destination file format. The JPEG library does not know 76 | * about these passes, but we'd like them to be counted by the progress 77 | * monitor. We use an expanded progress monitor object to hold the 78 | * additional pass count. 79 | */ 80 | 81 | struct cdjpeg_progress_mgr { 82 | struct jpeg_progress_mgr pub; /* fields known to JPEG library */ 83 | int completed_extra_passes; /* extra passes completed */ 84 | int total_extra_passes; /* total extra */ 85 | /* last printed percentage stored here to avoid multiple printouts */ 86 | int percent_done; 87 | }; 88 | 89 | typedef struct cdjpeg_progress_mgr * cd_progress_ptr; 90 | 91 | 92 | /* Short forms of external names for systems with brain-damaged linkers. */ 93 | 94 | #ifdef NEED_SHORT_EXTERNAL_NAMES 95 | #define jinit_read_bmp jIRdBMP 96 | #define jinit_write_bmp jIWrBMP 97 | #define jinit_read_gif jIRdGIF 98 | #define jinit_write_gif jIWrGIF 99 | #define jinit_read_ppm jIRdPPM 100 | #define jinit_write_ppm jIWrPPM 101 | #define jinit_read_rle jIRdRLE 102 | #define jinit_write_rle jIWrRLE 103 | #define jinit_read_targa jIRdTarga 104 | #define jinit_write_targa jIWrTarga 105 | #define read_quant_tables RdQTables 106 | #define read_scan_script RdScnScript 107 | #define set_quality_ratings SetQRates 108 | #define set_quant_slots SetQSlots 109 | #define set_sample_factors SetSFacts 110 | #define read_color_map RdCMap 111 | #define enable_signal_catcher EnSigCatcher 112 | #define start_progress_monitor StProgMon 113 | #define end_progress_monitor EnProgMon 114 | #define read_stdin RdStdin 115 | #define write_stdout WrStdout 116 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 117 | 118 | /* Module selection routines for I/O modules. */ 119 | 120 | EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo)); 121 | EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo, 122 | boolean is_os2)); 123 | EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo)); 124 | EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo)); 125 | EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo)); 126 | EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo)); 127 | EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo)); 128 | EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo)); 129 | EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo)); 130 | EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo)); 131 | 132 | /* cjpeg support routines (in rdswitch.c) */ 133 | 134 | EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename, 135 | boolean force_baseline)); 136 | EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename)); 137 | EXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg, 138 | boolean force_baseline)); 139 | EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg)); 140 | EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg)); 141 | 142 | /* djpeg support routines (in rdcolmap.c) */ 143 | 144 | EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile)); 145 | 146 | /* common support routines (in cdjpeg.c) */ 147 | 148 | EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo)); 149 | EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo, 150 | cd_progress_ptr progress)); 151 | EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo)); 152 | EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars)); 153 | EXTERN(FILE *) read_stdin JPP((void)); 154 | EXTERN(FILE *) write_stdout JPP((void)); 155 | 156 | /* miscellaneous useful macros */ 157 | 158 | #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ 159 | #define READ_BINARY "r" 160 | #define WRITE_BINARY "w" 161 | #else 162 | #ifdef VMS /* VMS is very nonstandard */ 163 | #define READ_BINARY "rb", "ctx=stm" 164 | #define WRITE_BINARY "wb", "ctx=stm" 165 | #else /* standard ANSI-compliant case */ 166 | #define READ_BINARY "rb" 167 | #define WRITE_BINARY "wb" 168 | #endif 169 | #endif 170 | 171 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */ 172 | #define EXIT_FAILURE 1 173 | #endif 174 | #ifndef EXIT_SUCCESS 175 | #ifdef VMS 176 | #define EXIT_SUCCESS 1 /* VMS is very nonstandard */ 177 | #else 178 | #define EXIT_SUCCESS 0 179 | #endif 180 | #endif 181 | #ifndef EXIT_WARNING 182 | #ifdef VMS 183 | #define EXIT_WARNING 1 /* VMS is very nonstandard */ 184 | #else 185 | #define EXIT_WARNING 2 186 | #endif 187 | #endif 188 | -------------------------------------------------------------------------------- /compile: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for compilers which do not understand '-c -o'. 3 | 4 | scriptversion=2012-10-14.11; # UTC 5 | 6 | # Copyright (C) 1999-2014 Free Software Foundation, Inc. 7 | # Written by Tom Tromey . 8 | # 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | # This file is maintained in Automake, please report 28 | # bugs to or send patches to 29 | # . 30 | 31 | nl=' 32 | ' 33 | 34 | # We need space, tab and new line, in precisely that order. Quoting is 35 | # there to prevent tools from complaining about whitespace usage. 36 | IFS=" "" $nl" 37 | 38 | file_conv= 39 | 40 | # func_file_conv build_file lazy 41 | # Convert a $build file to $host form and store it in $file 42 | # Currently only supports Windows hosts. If the determined conversion 43 | # type is listed in (the comma separated) LAZY, no conversion will 44 | # take place. 45 | func_file_conv () 46 | { 47 | file=$1 48 | case $file in 49 | / | /[!/]*) # absolute file, and not a UNC file 50 | if test -z "$file_conv"; then 51 | # lazily determine how to convert abs files 52 | case `uname -s` in 53 | MINGW*) 54 | file_conv=mingw 55 | ;; 56 | CYGWIN*) 57 | file_conv=cygwin 58 | ;; 59 | *) 60 | file_conv=wine 61 | ;; 62 | esac 63 | fi 64 | case $file_conv/,$2, in 65 | *,$file_conv,*) 66 | ;; 67 | mingw/*) 68 | file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69 | ;; 70 | cygwin/*) 71 | file=`cygpath -m "$file" || echo "$file"` 72 | ;; 73 | wine/*) 74 | file=`winepath -w "$file" || echo "$file"` 75 | ;; 76 | esac 77 | ;; 78 | esac 79 | } 80 | 81 | # func_cl_dashL linkdir 82 | # Make cl look for libraries in LINKDIR 83 | func_cl_dashL () 84 | { 85 | func_file_conv "$1" 86 | if test -z "$lib_path"; then 87 | lib_path=$file 88 | else 89 | lib_path="$lib_path;$file" 90 | fi 91 | linker_opts="$linker_opts -LIBPATH:$file" 92 | } 93 | 94 | # func_cl_dashl library 95 | # Do a library search-path lookup for cl 96 | func_cl_dashl () 97 | { 98 | lib=$1 99 | found=no 100 | save_IFS=$IFS 101 | IFS=';' 102 | for dir in $lib_path $LIB 103 | do 104 | IFS=$save_IFS 105 | if $shared && test -f "$dir/$lib.dll.lib"; then 106 | found=yes 107 | lib=$dir/$lib.dll.lib 108 | break 109 | fi 110 | if test -f "$dir/$lib.lib"; then 111 | found=yes 112 | lib=$dir/$lib.lib 113 | break 114 | fi 115 | if test -f "$dir/lib$lib.a"; then 116 | found=yes 117 | lib=$dir/lib$lib.a 118 | break 119 | fi 120 | done 121 | IFS=$save_IFS 122 | 123 | if test "$found" != yes; then 124 | lib=$lib.lib 125 | fi 126 | } 127 | 128 | # func_cl_wrapper cl arg... 129 | # Adjust compile command to suit cl 130 | func_cl_wrapper () 131 | { 132 | # Assume a capable shell 133 | lib_path= 134 | shared=: 135 | linker_opts= 136 | for arg 137 | do 138 | if test -n "$eat"; then 139 | eat= 140 | else 141 | case $1 in 142 | -o) 143 | # configure might choose to run compile as 'compile cc -o foo foo.c'. 144 | eat=1 145 | case $2 in 146 | *.o | *.[oO][bB][jJ]) 147 | func_file_conv "$2" 148 | set x "$@" -Fo"$file" 149 | shift 150 | ;; 151 | *) 152 | func_file_conv "$2" 153 | set x "$@" -Fe"$file" 154 | shift 155 | ;; 156 | esac 157 | ;; 158 | -I) 159 | eat=1 160 | func_file_conv "$2" mingw 161 | set x "$@" -I"$file" 162 | shift 163 | ;; 164 | -I*) 165 | func_file_conv "${1#-I}" mingw 166 | set x "$@" -I"$file" 167 | shift 168 | ;; 169 | -l) 170 | eat=1 171 | func_cl_dashl "$2" 172 | set x "$@" "$lib" 173 | shift 174 | ;; 175 | -l*) 176 | func_cl_dashl "${1#-l}" 177 | set x "$@" "$lib" 178 | shift 179 | ;; 180 | -L) 181 | eat=1 182 | func_cl_dashL "$2" 183 | ;; 184 | -L*) 185 | func_cl_dashL "${1#-L}" 186 | ;; 187 | -static) 188 | shared=false 189 | ;; 190 | -Wl,*) 191 | arg=${1#-Wl,} 192 | save_ifs="$IFS"; IFS=',' 193 | for flag in $arg; do 194 | IFS="$save_ifs" 195 | linker_opts="$linker_opts $flag" 196 | done 197 | IFS="$save_ifs" 198 | ;; 199 | -Xlinker) 200 | eat=1 201 | linker_opts="$linker_opts $2" 202 | ;; 203 | -*) 204 | set x "$@" "$1" 205 | shift 206 | ;; 207 | *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208 | func_file_conv "$1" 209 | set x "$@" -Tp"$file" 210 | shift 211 | ;; 212 | *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213 | func_file_conv "$1" mingw 214 | set x "$@" "$file" 215 | shift 216 | ;; 217 | *) 218 | set x "$@" "$1" 219 | shift 220 | ;; 221 | esac 222 | fi 223 | shift 224 | done 225 | if test -n "$linker_opts"; then 226 | linker_opts="-link$linker_opts" 227 | fi 228 | exec "$@" $linker_opts 229 | exit 1 230 | } 231 | 232 | eat= 233 | 234 | case $1 in 235 | '') 236 | echo "$0: No command. Try '$0 --help' for more information." 1>&2 237 | exit 1; 238 | ;; 239 | -h | --h*) 240 | cat <<\EOF 241 | Usage: compile [--help] [--version] PROGRAM [ARGS] 242 | 243 | Wrapper for compilers which do not understand '-c -o'. 244 | Remove '-o dest.o' from ARGS, run PROGRAM with the remaining 245 | arguments, and rename the output as expected. 246 | 247 | If you are trying to build a whole package this is not the 248 | right script to run: please start by reading the file 'INSTALL'. 249 | 250 | Report bugs to . 251 | EOF 252 | exit $? 253 | ;; 254 | -v | --v*) 255 | echo "compile $scriptversion" 256 | exit $? 257 | ;; 258 | cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 259 | func_cl_wrapper "$@" # Doesn't return... 260 | ;; 261 | esac 262 | 263 | ofile= 264 | cfile= 265 | 266 | for arg 267 | do 268 | if test -n "$eat"; then 269 | eat= 270 | else 271 | case $1 in 272 | -o) 273 | # configure might choose to run compile as 'compile cc -o foo foo.c'. 274 | # So we strip '-o arg' only if arg is an object. 275 | eat=1 276 | case $2 in 277 | *.o | *.obj) 278 | ofile=$2 279 | ;; 280 | *) 281 | set x "$@" -o "$2" 282 | shift 283 | ;; 284 | esac 285 | ;; 286 | *.c) 287 | cfile=$1 288 | set x "$@" "$1" 289 | shift 290 | ;; 291 | *) 292 | set x "$@" "$1" 293 | shift 294 | ;; 295 | esac 296 | fi 297 | shift 298 | done 299 | 300 | if test -z "$ofile" || test -z "$cfile"; then 301 | # If no '-o' option was seen then we might have been invoked from a 302 | # pattern rule where we don't need one. That is ok -- this is a 303 | # normal compilation that the losing compiler can handle. If no 304 | # '.c' file was seen then we are probably linking. That is also 305 | # ok. 306 | exec "$@" 307 | fi 308 | 309 | # Name of file we expect compiler to create. 310 | cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 311 | 312 | # Create the lock directory. 313 | # Note: use '[/\\:.-]' here to ensure that we don't use the same name 314 | # that we are using for the .o file. Also, base the name on the expected 315 | # object file name, since that is what matters with a parallel build. 316 | lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 317 | while true; do 318 | if mkdir "$lockdir" >/dev/null 2>&1; then 319 | break 320 | fi 321 | sleep 1 322 | done 323 | # FIXME: race condition here if user kills between mkdir and trap. 324 | trap "rmdir '$lockdir'; exit 1" 1 2 15 325 | 326 | # Run the compile. 327 | "$@" 328 | ret=$? 329 | 330 | if test -f "$cofile"; then 331 | test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 332 | elif test -f "${cofile}bj"; then 333 | test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 334 | fi 335 | 336 | rmdir "$lockdir" 337 | exit $ret 338 | 339 | # Local Variables: 340 | # mode: shell-script 341 | # sh-indentation: 2 342 | # eval: (add-hook 'write-file-hooks 'time-stamp) 343 | # time-stamp-start: "scriptversion=" 344 | # time-stamp-format: "%:y-%02m-%02d.%02H" 345 | # time-stamp-time-zone: "UTC" 346 | # time-stamp-end: "; # UTC" 347 | # End: 348 | -------------------------------------------------------------------------------- /configure.scan: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) 6 | AC_CONFIG_SRCDIR([ansi2knr.c]) 7 | AC_CONFIG_HEADERS([config.h]) 8 | 9 | # Checks for programs. 10 | AC_PROG_CXX 11 | AC_PROG_AWK 12 | AC_PROG_CC 13 | AC_PROG_CPP 14 | AC_PROG_INSTALL 15 | AC_PROG_LN_S 16 | AC_PROG_MAKE_SET 17 | AC_PROG_RANLIB 18 | 19 | # Checks for libraries. 20 | # FIXME: Replace `main' with a function in `-lpthread': 21 | AC_CHECK_LIB([pthread], [main]) 22 | 23 | # Checks for header files. 24 | AC_CHECK_HEADERS([fcntl.h limits.h locale.h malloc.h stddef.h stdint.h stdlib.h string.h strings.h unistd.h]) 25 | 26 | # Checks for typedefs, structures, and compiler characteristics. 27 | AC_TYPE_SIZE_T 28 | AC_TYPE_UINT32_T 29 | 30 | # Checks for library functions. 31 | AC_FUNC_MALLOC 32 | AC_CHECK_FUNCS([gettimeofday mkdir setlocale strerror]) 33 | 34 | AC_CONFIG_FILES([Makefile 35 | bak/Makefile]) 36 | AC_OUTPUT 37 | -------------------------------------------------------------------------------- /decode_idct.clc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anknown/opencl-jpeg/3ee64b66ed12c5374aa87322691731e3969e5e40/decode_idct.clc -------------------------------------------------------------------------------- /djpeg.1: -------------------------------------------------------------------------------- 1 | .TH DJPEG 1 "3 October 2009" 2 | .SH NAME 3 | djpeg \- decompress a JPEG file to an image file 4 | .SH SYNOPSIS 5 | .B djpeg 6 | [ 7 | .I options 8 | ] 9 | [ 10 | .I filename 11 | ] 12 | .LP 13 | .SH DESCRIPTION 14 | .LP 15 | .B djpeg 16 | decompresses the named JPEG file, or the standard input if no file is named, 17 | and produces an image file on the standard output. PBMPLUS (PPM/PGM), BMP, 18 | GIF, Targa, or RLE (Utah Raster Toolkit) output format can be selected. 19 | (RLE is supported only if the URT library is available.) 20 | .SH OPTIONS 21 | All switch names may be abbreviated; for example, 22 | .B \-grayscale 23 | may be written 24 | .B \-gray 25 | or 26 | .BR \-gr . 27 | Most of the "basic" switches can be abbreviated to as little as one letter. 28 | Upper and lower case are equivalent (thus 29 | .B \-BMP 30 | is the same as 31 | .BR \-bmp ). 32 | British spellings are also accepted (e.g., 33 | .BR \-greyscale ), 34 | though for brevity these are not mentioned below. 35 | .PP 36 | The basic switches are: 37 | .TP 38 | .BI \-colors " N" 39 | Reduce image to at most N colors. This reduces the number of colors used in 40 | the output image, so that it can be displayed on a colormapped display or 41 | stored in a colormapped file format. For example, if you have an 8-bit 42 | display, you'd need to reduce to 256 or fewer colors. 43 | .TP 44 | .BI \-quantize " N" 45 | Same as 46 | .BR \-colors . 47 | .B \-colors 48 | is the recommended name, 49 | .B \-quantize 50 | is provided only for backwards compatibility. 51 | .TP 52 | .B \-fast 53 | Select recommended processing options for fast, low quality output. (The 54 | default options are chosen for highest quality output.) Currently, this is 55 | equivalent to \fB\-dct fast \-nosmooth \-onepass \-dither ordered\fR. 56 | .TP 57 | .B \-grayscale 58 | Force gray-scale output even if JPEG file is color. Useful for viewing on 59 | monochrome displays; also, 60 | .B djpeg 61 | runs noticeably faster in this mode. 62 | .TP 63 | .BI \-scale " M/N" 64 | Scale the output image by a factor M/N. Currently supported scale factors are 65 | M/N with all M from 1 to 16, where N is the source DCT size, which is 8 for 66 | baseline JPEG. If the /N part is omitted, then M specifies the DCT scaled 67 | size to be applied on the given input. For baseline JPEG this is equivalent 68 | to M/8 scaling, since the source DCT size for baseline JPEG is 8. 69 | Scaling is handy if the image is larger than your screen; also, 70 | .B djpeg 71 | runs much faster when scaling down the output. 72 | .TP 73 | .B \-bmp 74 | Select BMP output format (Windows flavor). 8-bit colormapped format is 75 | emitted if 76 | .B \-colors 77 | or 78 | .B \-grayscale 79 | is specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color 80 | format is emitted. 81 | .TP 82 | .B \-gif 83 | Select GIF output format. Since GIF does not support more than 256 colors, 84 | .B \-colors 256 85 | is assumed (unless you specify a smaller number of colors). 86 | .TP 87 | .B \-os2 88 | Select BMP output format (OS/2 1.x flavor). 8-bit colormapped format is 89 | emitted if 90 | .B \-colors 91 | or 92 | .B \-grayscale 93 | is specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color 94 | format is emitted. 95 | .TP 96 | .B \-pnm 97 | Select PBMPLUS (PPM/PGM) output format (this is the default format). 98 | PGM is emitted if the JPEG file is gray-scale or if 99 | .B \-grayscale 100 | is specified; otherwise PPM is emitted. 101 | .TP 102 | .B \-rle 103 | Select RLE output format. (Requires URT library.) 104 | .TP 105 | .B \-targa 106 | Select Targa output format. Gray-scale format is emitted if the JPEG file is 107 | gray-scale or if 108 | .B \-grayscale 109 | is specified; otherwise, colormapped format is emitted if 110 | .B \-colors 111 | is specified; otherwise, 24-bit full-color format is emitted. 112 | .PP 113 | Switches for advanced users: 114 | .TP 115 | .B \-dct int 116 | Use integer DCT method (default). 117 | .TP 118 | .B \-dct fast 119 | Use fast integer DCT (less accurate). 120 | .TP 121 | .B \-dct float 122 | Use floating-point DCT method. 123 | The float method is very slightly more accurate than the int method, but is 124 | much slower unless your machine has very fast floating-point hardware. Also 125 | note that results of the floating-point method may vary slightly across 126 | machines, while the integer methods should give the same results everywhere. 127 | The fast integer method is much less accurate than the other two. 128 | .TP 129 | .B \-dither fs 130 | Use Floyd-Steinberg dithering in color quantization. 131 | .TP 132 | .B \-dither ordered 133 | Use ordered dithering in color quantization. 134 | .TP 135 | .B \-dither none 136 | Do not use dithering in color quantization. 137 | By default, Floyd-Steinberg dithering is applied when quantizing colors; this 138 | is slow but usually produces the best results. Ordered dither is a compromise 139 | between speed and quality; no dithering is fast but usually looks awful. Note 140 | that these switches have no effect unless color quantization is being done. 141 | Ordered dither is only available in 142 | .B \-onepass 143 | mode. 144 | .TP 145 | .BI \-map " file" 146 | Quantize to the colors used in the specified image file. This is useful for 147 | producing multiple files with identical color maps, or for forcing a 148 | predefined set of colors to be used. The 149 | .I file 150 | must be a GIF or PPM file. This option overrides 151 | .B \-colors 152 | and 153 | .BR \-onepass . 154 | .TP 155 | .B \-nosmooth 156 | Don't use high-quality upsampling. 157 | .TP 158 | .B \-onepass 159 | Use one-pass instead of two-pass color quantization. The one-pass method is 160 | faster and needs less memory, but it produces a lower-quality image. 161 | .B \-onepass 162 | is ignored unless you also say 163 | .B \-colors 164 | .IR N . 165 | Also, the one-pass method is always used for gray-scale output (the two-pass 166 | method is no improvement then). 167 | .TP 168 | .BI \-maxmemory " N" 169 | Set limit for amount of memory to use in processing large images. Value is 170 | in thousands of bytes, or millions of bytes if "M" is attached to the 171 | number. For example, 172 | .B \-max 4m 173 | selects 4000000 bytes. If more space is needed, temporary files will be used. 174 | .TP 175 | .BI \-outfile " name" 176 | Send output image to the named file, not to standard output. 177 | .TP 178 | .B \-verbose 179 | Enable debug printout. More 180 | .BR \-v 's 181 | give more output. Also, version information is printed at startup. 182 | .TP 183 | .B \-debug 184 | Same as 185 | .BR \-verbose . 186 | .SH EXAMPLES 187 | .LP 188 | This example decompresses the JPEG file foo.jpg, quantizes it to 189 | 256 colors, and saves the output in 8-bit BMP format in foo.bmp: 190 | .IP 191 | .B djpeg \-colors 256 \-bmp 192 | .I foo.jpg 193 | .B > 194 | .I foo.bmp 195 | .SH HINTS 196 | To get a quick preview of an image, use the 197 | .B \-grayscale 198 | and/or 199 | .B \-scale 200 | switches. 201 | .B \-grayscale \-scale 1/8 202 | is the fastest case. 203 | .PP 204 | Several options are available that trade off image quality to gain speed. 205 | .B \-fast 206 | turns on the recommended settings. 207 | .PP 208 | .B \-dct fast 209 | and/or 210 | .B \-nosmooth 211 | gain speed at a small sacrifice in quality. 212 | When producing a color-quantized image, 213 | .B \-onepass \-dither ordered 214 | is fast but much lower quality than the default behavior. 215 | .B \-dither none 216 | may give acceptable results in two-pass mode, but is seldom tolerable in 217 | one-pass mode. 218 | .PP 219 | If you are fortunate enough to have very fast floating point hardware, 220 | \fB\-dct float\fR may be even faster than \fB\-dct fast\fR. But on most 221 | machines \fB\-dct float\fR is slower than \fB\-dct int\fR; in this case it is 222 | not worth using, because its theoretical accuracy advantage is too small to be 223 | significant in practice. 224 | .SH ENVIRONMENT 225 | .TP 226 | .B JPEGMEM 227 | If this environment variable is set, its value is the default memory limit. 228 | The value is specified as described for the 229 | .B \-maxmemory 230 | switch. 231 | .B JPEGMEM 232 | overrides the default value specified when the program was compiled, and 233 | itself is overridden by an explicit 234 | .BR \-maxmemory . 235 | .SH SEE ALSO 236 | .BR cjpeg (1), 237 | .BR jpegtran (1), 238 | .BR rdjpgcom (1), 239 | .BR wrjpgcom (1) 240 | .br 241 | .BR ppm (5), 242 | .BR pgm (5) 243 | .br 244 | Wallace, Gregory K. "The JPEG Still Picture Compression Standard", 245 | Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44. 246 | .SH AUTHOR 247 | Independent JPEG Group 248 | .SH BUGS 249 | To avoid the Unisys LZW patent, 250 | .B djpeg 251 | produces uncompressed GIF files. These are larger than they should be, but 252 | are readable by standard GIF decoders. 253 | -------------------------------------------------------------------------------- /encode_dct.clc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anknown/opencl-jpeg/3ee64b66ed12c5374aa87322691731e3969e5e40/encode_dct.clc -------------------------------------------------------------------------------- /foo.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anknown/opencl-jpeg/3ee64b66ed12c5374aa87322691731e3969e5e40/foo.bc -------------------------------------------------------------------------------- /jaricom.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jaricom.c 3 | * 4 | * Developed 1997-2009 by Guido Vollbeding. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains probability estimation tables for common use in 9 | * arithmetic entropy encoding and decoding routines. 10 | * 11 | * This data represents Table D.2 in the JPEG spec (ISO/IEC IS 10918-1 12 | * and CCITT Recommendation ITU-T T.81) and Table 24 in the JBIG spec 13 | * (ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82). 14 | */ 15 | 16 | #define JPEG_INTERNALS 17 | #include "jinclude.h" 18 | #include "jpeglib.h" 19 | 20 | /* The following #define specifies the packing of the four components 21 | * into the compact INT32 representation. 22 | * Note that this formula must match the actual arithmetic encoder 23 | * and decoder implementation. The implementation has to be changed 24 | * if this formula is changed. 25 | * The current organization is leaned on Markus Kuhn's JBIG 26 | * implementation (jbig_tab.c). 27 | */ 28 | 29 | #define V(i,a,b,c,d) (((INT32)a << 16) | ((INT32)c << 8) | ((INT32)d << 7) | b) 30 | 31 | const INT32 jpeg_aritab[113+1] = { 32 | /* 33 | * Index, Qe_Value, Next_Index_LPS, Next_Index_MPS, Switch_MPS 34 | */ 35 | V( 0, 0x5a1d, 1, 1, 1 ), 36 | V( 1, 0x2586, 14, 2, 0 ), 37 | V( 2, 0x1114, 16, 3, 0 ), 38 | V( 3, 0x080b, 18, 4, 0 ), 39 | V( 4, 0x03d8, 20, 5, 0 ), 40 | V( 5, 0x01da, 23, 6, 0 ), 41 | V( 6, 0x00e5, 25, 7, 0 ), 42 | V( 7, 0x006f, 28, 8, 0 ), 43 | V( 8, 0x0036, 30, 9, 0 ), 44 | V( 9, 0x001a, 33, 10, 0 ), 45 | V( 10, 0x000d, 35, 11, 0 ), 46 | V( 11, 0x0006, 9, 12, 0 ), 47 | V( 12, 0x0003, 10, 13, 0 ), 48 | V( 13, 0x0001, 12, 13, 0 ), 49 | V( 14, 0x5a7f, 15, 15, 1 ), 50 | V( 15, 0x3f25, 36, 16, 0 ), 51 | V( 16, 0x2cf2, 38, 17, 0 ), 52 | V( 17, 0x207c, 39, 18, 0 ), 53 | V( 18, 0x17b9, 40, 19, 0 ), 54 | V( 19, 0x1182, 42, 20, 0 ), 55 | V( 20, 0x0cef, 43, 21, 0 ), 56 | V( 21, 0x09a1, 45, 22, 0 ), 57 | V( 22, 0x072f, 46, 23, 0 ), 58 | V( 23, 0x055c, 48, 24, 0 ), 59 | V( 24, 0x0406, 49, 25, 0 ), 60 | V( 25, 0x0303, 51, 26, 0 ), 61 | V( 26, 0x0240, 52, 27, 0 ), 62 | V( 27, 0x01b1, 54, 28, 0 ), 63 | V( 28, 0x0144, 56, 29, 0 ), 64 | V( 29, 0x00f5, 57, 30, 0 ), 65 | V( 30, 0x00b7, 59, 31, 0 ), 66 | V( 31, 0x008a, 60, 32, 0 ), 67 | V( 32, 0x0068, 62, 33, 0 ), 68 | V( 33, 0x004e, 63, 34, 0 ), 69 | V( 34, 0x003b, 32, 35, 0 ), 70 | V( 35, 0x002c, 33, 9, 0 ), 71 | V( 36, 0x5ae1, 37, 37, 1 ), 72 | V( 37, 0x484c, 64, 38, 0 ), 73 | V( 38, 0x3a0d, 65, 39, 0 ), 74 | V( 39, 0x2ef1, 67, 40, 0 ), 75 | V( 40, 0x261f, 68, 41, 0 ), 76 | V( 41, 0x1f33, 69, 42, 0 ), 77 | V( 42, 0x19a8, 70, 43, 0 ), 78 | V( 43, 0x1518, 72, 44, 0 ), 79 | V( 44, 0x1177, 73, 45, 0 ), 80 | V( 45, 0x0e74, 74, 46, 0 ), 81 | V( 46, 0x0bfb, 75, 47, 0 ), 82 | V( 47, 0x09f8, 77, 48, 0 ), 83 | V( 48, 0x0861, 78, 49, 0 ), 84 | V( 49, 0x0706, 79, 50, 0 ), 85 | V( 50, 0x05cd, 48, 51, 0 ), 86 | V( 51, 0x04de, 50, 52, 0 ), 87 | V( 52, 0x040f, 50, 53, 0 ), 88 | V( 53, 0x0363, 51, 54, 0 ), 89 | V( 54, 0x02d4, 52, 55, 0 ), 90 | V( 55, 0x025c, 53, 56, 0 ), 91 | V( 56, 0x01f8, 54, 57, 0 ), 92 | V( 57, 0x01a4, 55, 58, 0 ), 93 | V( 58, 0x0160, 56, 59, 0 ), 94 | V( 59, 0x0125, 57, 60, 0 ), 95 | V( 60, 0x00f6, 58, 61, 0 ), 96 | V( 61, 0x00cb, 59, 62, 0 ), 97 | V( 62, 0x00ab, 61, 63, 0 ), 98 | V( 63, 0x008f, 61, 32, 0 ), 99 | V( 64, 0x5b12, 65, 65, 1 ), 100 | V( 65, 0x4d04, 80, 66, 0 ), 101 | V( 66, 0x412c, 81, 67, 0 ), 102 | V( 67, 0x37d8, 82, 68, 0 ), 103 | V( 68, 0x2fe8, 83, 69, 0 ), 104 | V( 69, 0x293c, 84, 70, 0 ), 105 | V( 70, 0x2379, 86, 71, 0 ), 106 | V( 71, 0x1edf, 87, 72, 0 ), 107 | V( 72, 0x1aa9, 87, 73, 0 ), 108 | V( 73, 0x174e, 72, 74, 0 ), 109 | V( 74, 0x1424, 72, 75, 0 ), 110 | V( 75, 0x119c, 74, 76, 0 ), 111 | V( 76, 0x0f6b, 74, 77, 0 ), 112 | V( 77, 0x0d51, 75, 78, 0 ), 113 | V( 78, 0x0bb6, 77, 79, 0 ), 114 | V( 79, 0x0a40, 77, 48, 0 ), 115 | V( 80, 0x5832, 80, 81, 1 ), 116 | V( 81, 0x4d1c, 88, 82, 0 ), 117 | V( 82, 0x438e, 89, 83, 0 ), 118 | V( 83, 0x3bdd, 90, 84, 0 ), 119 | V( 84, 0x34ee, 91, 85, 0 ), 120 | V( 85, 0x2eae, 92, 86, 0 ), 121 | V( 86, 0x299a, 93, 87, 0 ), 122 | V( 87, 0x2516, 86, 71, 0 ), 123 | V( 88, 0x5570, 88, 89, 1 ), 124 | V( 89, 0x4ca9, 95, 90, 0 ), 125 | V( 90, 0x44d9, 96, 91, 0 ), 126 | V( 91, 0x3e22, 97, 92, 0 ), 127 | V( 92, 0x3824, 99, 93, 0 ), 128 | V( 93, 0x32b4, 99, 94, 0 ), 129 | V( 94, 0x2e17, 93, 86, 0 ), 130 | V( 95, 0x56a8, 95, 96, 1 ), 131 | V( 96, 0x4f46, 101, 97, 0 ), 132 | V( 97, 0x47e5, 102, 98, 0 ), 133 | V( 98, 0x41cf, 103, 99, 0 ), 134 | V( 99, 0x3c3d, 104, 100, 0 ), 135 | V( 100, 0x375e, 99, 93, 0 ), 136 | V( 101, 0x5231, 105, 102, 0 ), 137 | V( 102, 0x4c0f, 106, 103, 0 ), 138 | V( 103, 0x4639, 107, 104, 0 ), 139 | V( 104, 0x415e, 103, 99, 0 ), 140 | V( 105, 0x5627, 105, 106, 1 ), 141 | V( 106, 0x50e7, 108, 107, 0 ), 142 | V( 107, 0x4b85, 109, 103, 0 ), 143 | V( 108, 0x5597, 110, 109, 0 ), 144 | V( 109, 0x504f, 111, 107, 0 ), 145 | V( 110, 0x5a10, 110, 111, 1 ), 146 | V( 111, 0x5522, 112, 109, 0 ), 147 | V( 112, 0x59eb, 112, 111, 1 ), 148 | /* 149 | * This last entry is used for fixed probability estimate of 0.5 150 | * as recommended in Section 10.3 Table 5 of ITU-T Rec. T.851. 151 | */ 152 | V( 113, 0x5a1d, 113, 113, 0 ) 153 | }; 154 | -------------------------------------------------------------------------------- /jcapistd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jcapistd.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains application interface code for the compression half 9 | * of the JPEG library. These are the "standard" API routines that are 10 | * used in the normal full-compression case. They are not used by a 11 | * transcoding-only application. Note that if an application links in 12 | * jpeg_start_compress, it will end up linking in the entire compressor. 13 | * We thus must separate this file from jcapimin.c to avoid linking the 14 | * whole compression library into a transcoder. 15 | */ 16 | 17 | #define JPEG_INTERNALS 18 | #include "jinclude.h" 19 | #include "jpeglib.h" 20 | 21 | 22 | /* 23 | * Compression initialization. 24 | * Before calling this, all parameters and a data destination must be set up. 25 | * 26 | * We require a write_all_tables parameter as a failsafe check when writing 27 | * multiple datastreams from the same compression object. Since prior runs 28 | * will have left all the tables marked sent_table=TRUE, a subsequent run 29 | * would emit an abbreviated stream (no tables) by default. This may be what 30 | * is wanted, but for safety's sake it should not be the default behavior: 31 | * programmers should have to make a deliberate choice to emit abbreviated 32 | * images. Therefore the documentation and examples should encourage people 33 | * to pass write_all_tables=TRUE; then it will take active thought to do the 34 | * wrong thing. 35 | */ 36 | 37 | GLOBAL(void) 38 | jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables) 39 | { 40 | if (cinfo->global_state != CSTATE_START) 41 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 42 | 43 | if (write_all_tables) 44 | jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */ 45 | 46 | /* (Re)initialize error mgr and destination modules */ 47 | (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); 48 | (*cinfo->dest->init_destination) (cinfo); 49 | /* Perform master selection of active modules */ 50 | jinit_compress_master(cinfo); 51 | /* Set up for the first pass */ 52 | (*cinfo->master->prepare_for_pass) (cinfo); 53 | /* Ready for application to drive first pass through jpeg_write_scanlines 54 | * or jpeg_write_raw_data. 55 | */ 56 | cinfo->next_scanline = 0; 57 | cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING); 58 | } 59 | 60 | 61 | /* 62 | * Write some scanlines of data to the JPEG compressor. 63 | * 64 | * The return value will be the number of lines actually written. 65 | * This should be less than the supplied num_lines only in case that 66 | * the data destination module has requested suspension of the compressor, 67 | * or if more than image_height scanlines are passed in. 68 | * 69 | * Note: we warn about excess calls to jpeg_write_scanlines() since 70 | * this likely signals an application programmer error. However, 71 | * excess scanlines passed in the last valid call are *silently* ignored, 72 | * so that the application need not adjust num_lines for end-of-image 73 | * when using a multiple-scanline buffer. 74 | */ 75 | 76 | GLOBAL(JDIMENSION) 77 | jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, 78 | JDIMENSION num_lines) 79 | { 80 | JDIMENSION row_ctr, rows_left; 81 | 82 | if (cinfo->global_state != CSTATE_SCANNING) 83 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 84 | if (cinfo->next_scanline >= cinfo->image_height) 85 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); 86 | 87 | /* Call progress monitor hook if present */ 88 | if (cinfo->progress != NULL) { 89 | cinfo->progress->pass_counter = (long) cinfo->next_scanline; 90 | cinfo->progress->pass_limit = (long) cinfo->image_height; 91 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 92 | } 93 | 94 | /* Give master control module another chance if this is first call to 95 | * jpeg_write_scanlines. This lets output of the frame/scan headers be 96 | * delayed so that application can write COM, etc, markers between 97 | * jpeg_start_compress and jpeg_write_scanlines. 98 | */ 99 | if (cinfo->master->call_pass_startup) 100 | (*cinfo->master->pass_startup) (cinfo); 101 | 102 | /* Ignore any extra scanlines at bottom of image. */ 103 | rows_left = cinfo->image_height - cinfo->next_scanline; 104 | if (num_lines > rows_left) 105 | num_lines = rows_left; 106 | 107 | row_ctr = 0; 108 | (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines); 109 | cinfo->next_scanline += row_ctr; 110 | return row_ctr; 111 | } 112 | 113 | 114 | /* 115 | * Alternate entry point to write raw data. 116 | * Processes exactly one iMCU row per call, unless suspended. 117 | */ 118 | 119 | GLOBAL(JDIMENSION) 120 | jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, 121 | JDIMENSION num_lines) 122 | { 123 | JDIMENSION lines_per_iMCU_row; 124 | 125 | if (cinfo->global_state != CSTATE_RAW_OK) 126 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 127 | if (cinfo->next_scanline >= cinfo->image_height) { 128 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); 129 | return 0; 130 | } 131 | 132 | /* Call progress monitor hook if present */ 133 | if (cinfo->progress != NULL) { 134 | cinfo->progress->pass_counter = (long) cinfo->next_scanline; 135 | cinfo->progress->pass_limit = (long) cinfo->image_height; 136 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 137 | } 138 | 139 | /* Give master control module another chance if this is first call to 140 | * jpeg_write_raw_data. This lets output of the frame/scan headers be 141 | * delayed so that application can write COM, etc, markers between 142 | * jpeg_start_compress and jpeg_write_raw_data. 143 | */ 144 | if (cinfo->master->call_pass_startup) 145 | (*cinfo->master->pass_startup) (cinfo); 146 | 147 | /* Verify that at least one iMCU row has been passed. */ 148 | lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE; 149 | if (num_lines < lines_per_iMCU_row) 150 | ERREXIT(cinfo, JERR_BUFFER_SIZE); 151 | 152 | /* Directly compress the row. */ 153 | if (! (*cinfo->coef->compress_data) (cinfo, data)) { 154 | /* If compressor did not consume the whole row, suspend processing. */ 155 | return 0; 156 | } 157 | 158 | /* OK, we processed one iMCU row. */ 159 | cinfo->next_scanline += lines_per_iMCU_row; 160 | return lines_per_iMCU_row; 161 | } 162 | -------------------------------------------------------------------------------- /jcinit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jcinit.c 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains initialization logic for the JPEG compressor. 9 | * This routine is in charge of selecting the modules to be executed and 10 | * making an initialization call to each one. 11 | * 12 | * Logically, this code belongs in jcmaster.c. It's split out because 13 | * linking this routine implies linking the entire compression library. 14 | * For a transcoding-only application, we want to be able to use jcmaster.c 15 | * without linking in the whole library. 16 | */ 17 | 18 | #define JPEG_INTERNALS 19 | #include "jinclude.h" 20 | #include "jpeglib.h" 21 | 22 | 23 | /* 24 | * Master selection of compression modules. 25 | * This is done once at the start of processing an image. We determine 26 | * which modules will be used and give them appropriate initialization calls. 27 | */ 28 | 29 | GLOBAL(void) 30 | jinit_compress_master (j_compress_ptr cinfo) 31 | { 32 | /* Initialize master control (includes parameter checking/processing) */ 33 | jinit_c_master_control(cinfo, FALSE /* full compression */); 34 | 35 | /* Preprocessing */ 36 | if (! cinfo->raw_data_in) { 37 | jinit_color_converter(cinfo); 38 | jinit_downsampler(cinfo); 39 | jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */); 40 | } 41 | /* Forward DCT */ 42 | jinit_forward_dct(cinfo); 43 | /* Entropy encoding: either Huffman or arithmetic coding. */ 44 | if (cinfo->arith_code) 45 | jinit_arith_encoder(cinfo); 46 | else { 47 | jinit_huff_encoder(cinfo); 48 | } 49 | 50 | /* Need a full-image coefficient buffer in any multi-pass mode. */ 51 | jinit_c_coef_controller(cinfo, 52 | (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding)); 53 | jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); 54 | 55 | jinit_marker_writer(cinfo); 56 | 57 | /* We can now tell the memory manager to allocate virtual arrays. */ 58 | (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); 59 | 60 | /* Write the datastream header (SOI) immediately. 61 | * Frame and scan headers are postponed till later. 62 | * This lets application insert special markers after the SOI. 63 | */ 64 | (*cinfo->marker->write_file_header) (cinfo); 65 | } 66 | -------------------------------------------------------------------------------- /jcomapi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jcomapi.c 3 | * 4 | * Copyright (C) 1994-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains application interface routines that are used for both 9 | * compression and decompression. 10 | */ 11 | 12 | #define JPEG_INTERNALS 13 | #include "jinclude.h" 14 | #include "jpeglib.h" 15 | 16 | 17 | /* 18 | * Abort processing of a JPEG compression or decompression operation, 19 | * but don't destroy the object itself. 20 | * 21 | * For this, we merely clean up all the nonpermanent memory pools. 22 | * Note that temp files (virtual arrays) are not allowed to belong to 23 | * the permanent pool, so we will be able to close all temp files here. 24 | * Closing a data source or destination, if necessary, is the application's 25 | * responsibility. 26 | */ 27 | 28 | GLOBAL(void) 29 | jpeg_abort (j_common_ptr cinfo) 30 | { 31 | int pool; 32 | 33 | /* Do nothing if called on a not-initialized or destroyed JPEG object. */ 34 | if (cinfo->mem == NULL) 35 | return; 36 | 37 | /* Releasing pools in reverse order might help avoid fragmentation 38 | * with some (brain-damaged) malloc libraries. 39 | */ 40 | for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) { 41 | (*cinfo->mem->free_pool) (cinfo, pool); 42 | } 43 | 44 | /* Reset overall state for possible reuse of object */ 45 | if (cinfo->is_decompressor) { 46 | cinfo->global_state = DSTATE_START; 47 | /* Try to keep application from accessing now-deleted marker list. 48 | * A bit kludgy to do it here, but this is the most central place. 49 | */ 50 | ((j_decompress_ptr) cinfo)->marker_list = NULL; 51 | } else { 52 | cinfo->global_state = CSTATE_START; 53 | } 54 | } 55 | 56 | 57 | /* 58 | * Destruction of a JPEG object. 59 | * 60 | * Everything gets deallocated except the master jpeg_compress_struct itself 61 | * and the error manager struct. Both of these are supplied by the application 62 | * and must be freed, if necessary, by the application. (Often they are on 63 | * the stack and so don't need to be freed anyway.) 64 | * Closing a data source or destination, if necessary, is the application's 65 | * responsibility. 66 | */ 67 | 68 | GLOBAL(void) 69 | jpeg_destroy (j_common_ptr cinfo) 70 | { 71 | /* We need only tell the memory manager to release everything. */ 72 | /* NB: mem pointer is NULL if memory mgr failed to initialize. */ 73 | if (cinfo->mem != NULL) 74 | (*cinfo->mem->self_destruct) (cinfo); 75 | cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */ 76 | cinfo->global_state = 0; /* mark it destroyed */ 77 | } 78 | 79 | 80 | /* 81 | * Convenience routines for allocating quantization and Huffman tables. 82 | * (Would jutils.c be a more reasonable place to put these?) 83 | */ 84 | 85 | GLOBAL(JQUANT_TBL *) 86 | jpeg_alloc_quant_table (j_common_ptr cinfo) 87 | { 88 | JQUANT_TBL *tbl; 89 | 90 | tbl = (JQUANT_TBL *) 91 | (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL)); 92 | tbl->sent_table = FALSE; /* make sure this is false in any new table */ 93 | return tbl; 94 | } 95 | 96 | 97 | GLOBAL(JHUFF_TBL *) 98 | jpeg_alloc_huff_table (j_common_ptr cinfo) 99 | { 100 | JHUFF_TBL *tbl; 101 | 102 | tbl = (JHUFF_TBL *) 103 | (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL)); 104 | tbl->sent_table = FALSE; /* make sure this is false in any new table */ 105 | return tbl; 106 | } 107 | -------------------------------------------------------------------------------- /jconfig.cfg: -------------------------------------------------------------------------------- 1 | /* jconfig.cfg. Generated from configure.ac by autoheader. */ 2 | 3 | /* Characters are unsigned */ 4 | #undef CHAR_IS_UNSIGNED 5 | 6 | /* Maximum data space library will allocate. */ 7 | #undef DEFAULT_MAX_MEM 8 | 9 | /* Don't open files in binary mode. */ 10 | #undef DONT_USE_B_MODE 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_DLFCN_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_INTTYPES_H 17 | 18 | /* Define to 1 if you have the `OpenCL' library (-lOpenCL). */ 19 | #undef HAVE_LIBOPENCL 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_LOCALE_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_MEMORY_H 26 | 27 | /* Compiler supports function prototypes. */ 28 | #undef HAVE_PROTOTYPES 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_STDDEF_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_STDINT_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_STDLIB_H 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #undef HAVE_STRINGS_H 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_STRING_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_SYS_STAT_H 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #undef HAVE_SYS_TYPES_H 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_UNISTD_H 53 | 54 | /* Compiler supports 'unsigned char'. */ 55 | #undef HAVE_UNSIGNED_CHAR 56 | 57 | /* Compiler supports 'unsigned short'. */ 58 | #undef HAVE_UNSIGNED_SHORT 59 | 60 | /* Compiler does not support pointers to unspecified structures. */ 61 | #undef INCOMPLETE_TYPES_BROKEN 62 | 63 | /* How to obtain function inlining. */ 64 | #undef INLINE 65 | 66 | /* Define to the sub-directory where libtool stores uninstalled libraries. */ 67 | #undef LT_OBJDIR 68 | 69 | /* Compiler has rather than standard . */ 70 | #undef NEED_BSD_STRINGS 71 | 72 | /* Linker requires that global names be unique in first 15 characters. */ 73 | #undef NEED_SHORT_EXTERNAL_NAMES 74 | 75 | /* Need signal handler to clean up temporary files. */ 76 | #undef NEED_SIGNAL_CATCHER 77 | 78 | /* Need to include in order to obtain size_t. */ 79 | #undef NEED_SYS_TYPES_H 80 | 81 | /* The mktemp() function is not available. */ 82 | #undef NO_MKTEMP 83 | 84 | /* Name of package */ 85 | #undef PACKAGE 86 | 87 | /* Define to the address where bug reports for this package should be sent. */ 88 | #undef PACKAGE_BUGREPORT 89 | 90 | /* Define to the full name of this package. */ 91 | #undef PACKAGE_NAME 92 | 93 | /* Define to the full name and version of this package. */ 94 | #undef PACKAGE_STRING 95 | 96 | /* Define to the one symbol short name of this package. */ 97 | #undef PACKAGE_TARNAME 98 | 99 | /* Define to the home page for this package. */ 100 | #undef PACKAGE_URL 101 | 102 | /* Define to the version of this package. */ 103 | #undef PACKAGE_VERSION 104 | 105 | /* Broken compiler shifts signed values as an unsigned shift. */ 106 | #undef RIGHT_SHIFT_IS_UNSIGNED 107 | 108 | /* Define to 1 if you have the ANSI C header files. */ 109 | #undef STDC_HEADERS 110 | 111 | /* Version number of package */ 112 | #undef VERSION 113 | 114 | /* Define to empty if `const' does not conform to ANSI C. */ 115 | #undef const 116 | 117 | /* Define 'void' as 'char' for archaic compilers that don't understand it. */ 118 | #undef void 119 | -------------------------------------------------------------------------------- /jconfig.h: -------------------------------------------------------------------------------- 1 | /* jconfig.h. Generated from jconfig.cfg by configure. */ 2 | /* jconfig.cfg. Generated from configure.ac by autoheader. */ 3 | 4 | /* Characters are unsigned */ 5 | /* #undef CHAR_IS_UNSIGNED */ 6 | 7 | /* Maximum data space library will allocate. */ 8 | /* #undef DEFAULT_MAX_MEM */ 9 | 10 | /* Don't open files in binary mode. */ 11 | /* #undef DONT_USE_B_MODE */ 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_DLFCN_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_INTTYPES_H 1 18 | 19 | /* Define to 1 if you have the `OpenCL' library (-lOpenCL). */ 20 | /* #undef HAVE_LIBOPENCL */ 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_LOCALE_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_MEMORY_H 1 27 | 28 | /* Compiler supports function prototypes. */ 29 | #define HAVE_PROTOTYPES 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDDEF_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STDINT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_STDLIB_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_STRINGS_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_STRING_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SYS_STAT_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_SYS_TYPES_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_UNISTD_H 1 54 | 55 | /* Compiler supports 'unsigned char'. */ 56 | #define HAVE_UNSIGNED_CHAR 1 57 | 58 | /* Compiler supports 'unsigned short'. */ 59 | #define HAVE_UNSIGNED_SHORT 1 60 | 61 | /* Compiler does not support pointers to unspecified structures. */ 62 | /* #undef INCOMPLETE_TYPES_BROKEN */ 63 | 64 | /* How to obtain function inlining. */ 65 | #define INLINE __inline__ 66 | 67 | /* Define to the sub-directory where libtool stores uninstalled libraries. */ 68 | #define LT_OBJDIR ".libs/" 69 | 70 | /* Compiler has rather than standard . */ 71 | /* #undef NEED_BSD_STRINGS */ 72 | 73 | /* Linker requires that global names be unique in first 15 characters. */ 74 | /* #undef NEED_SHORT_EXTERNAL_NAMES */ 75 | 76 | /* Need signal handler to clean up temporary files. */ 77 | /* #undef NEED_SIGNAL_CATCHER */ 78 | 79 | /* Need to include in order to obtain size_t. */ 80 | /* #undef NEED_SYS_TYPES_H */ 81 | 82 | /* The mktemp() function is not available. */ 83 | /* #undef NO_MKTEMP */ 84 | 85 | /* Name of package */ 86 | #define PACKAGE "libjpeg" 87 | 88 | /* Define to the address where bug reports for this package should be sent. */ 89 | #define PACKAGE_BUGREPORT "" 90 | 91 | /* Define to the full name of this package. */ 92 | #define PACKAGE_NAME "libjpeg" 93 | 94 | /* Define to the full name and version of this package. */ 95 | #define PACKAGE_STRING "libjpeg 8.0" 96 | 97 | /* Define to the one symbol short name of this package. */ 98 | #define PACKAGE_TARNAME "libjpeg" 99 | 100 | /* Define to the home page for this package. */ 101 | #define PACKAGE_URL "" 102 | 103 | /* Define to the version of this package. */ 104 | #define PACKAGE_VERSION "8.0" 105 | 106 | /* Broken compiler shifts signed values as an unsigned shift. */ 107 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */ 108 | 109 | /* Define to 1 if you have the ANSI C header files. */ 110 | #define STDC_HEADERS 1 111 | 112 | /* Version number of package */ 113 | #define VERSION "8.0" 114 | 115 | /* Define to empty if `const' does not conform to ANSI C. */ 116 | /* #undef const */ 117 | 118 | /* Define 'void' as 'char' for archaic compilers that don't understand it. */ 119 | /* #undef void */ 120 | -------------------------------------------------------------------------------- /jerror.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jerror.c 3 | * 4 | * Copyright (C) 1991-1998, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains simple error-reporting and trace-message routines. 9 | * These are suitable for Unix-like systems and others where writing to 10 | * stderr is the right thing to do. Many applications will want to replace 11 | * some or all of these routines. 12 | * 13 | * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile, 14 | * you get a Windows-specific hack to display error messages in a dialog box. 15 | * It ain't much, but it beats dropping error messages into the bit bucket, 16 | * which is what happens to output to stderr under most Windows C compilers. 17 | * 18 | * These routines are used by both the compression and decompression code. 19 | */ 20 | 21 | /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ 22 | #include "jinclude.h" 23 | #include "jpeglib.h" 24 | #include "jversion.h" 25 | #include "jerror.h" 26 | 27 | #ifdef USE_WINDOWS_MESSAGEBOX 28 | #include 29 | #endif 30 | 31 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */ 32 | #define EXIT_FAILURE 1 33 | #endif 34 | 35 | 36 | /* 37 | * Create the message string table. 38 | * We do this from the master message list in jerror.h by re-reading 39 | * jerror.h with a suitable definition for macro JMESSAGE. 40 | * The message table is made an external symbol just in case any applications 41 | * want to refer to it directly. 42 | */ 43 | 44 | #ifdef NEED_SHORT_EXTERNAL_NAMES 45 | #define jpeg_std_message_table jMsgTable 46 | #endif 47 | 48 | #define JMESSAGE(code,string) string , 49 | 50 | const char * const jpeg_std_message_table[] = { 51 | #include "jerror.h" 52 | NULL 53 | }; 54 | 55 | 56 | /* 57 | * Error exit handler: must not return to caller. 58 | * 59 | * Applications may override this if they want to get control back after 60 | * an error. Typically one would longjmp somewhere instead of exiting. 61 | * The setjmp buffer can be made a private field within an expanded error 62 | * handler object. Note that the info needed to generate an error message 63 | * is stored in the error object, so you can generate the message now or 64 | * later, at your convenience. 65 | * You should make sure that the JPEG object is cleaned up (with jpeg_abort 66 | * or jpeg_destroy) at some point. 67 | */ 68 | 69 | METHODDEF(void) 70 | error_exit (j_common_ptr cinfo) 71 | { 72 | /* Always display the message */ 73 | (*cinfo->err->output_message) (cinfo); 74 | 75 | /* Let the memory manager delete any temp files before we die */ 76 | jpeg_destroy(cinfo); 77 | 78 | exit(EXIT_FAILURE); 79 | } 80 | 81 | 82 | /* 83 | * Actual output of an error or trace message. 84 | * Applications may override this method to send JPEG messages somewhere 85 | * other than stderr. 86 | * 87 | * On Windows, printing to stderr is generally completely useless, 88 | * so we provide optional code to produce an error-dialog popup. 89 | * Most Windows applications will still prefer to override this routine, 90 | * but if they don't, it'll do something at least marginally useful. 91 | * 92 | * NOTE: to use the library in an environment that doesn't support the 93 | * C stdio library, you may have to delete the call to fprintf() entirely, 94 | * not just not use this routine. 95 | */ 96 | 97 | METHODDEF(void) 98 | output_message (j_common_ptr cinfo) 99 | { 100 | char buffer[JMSG_LENGTH_MAX]; 101 | 102 | /* Create the message */ 103 | (*cinfo->err->format_message) (cinfo, buffer); 104 | 105 | #ifdef USE_WINDOWS_MESSAGEBOX 106 | /* Display it in a message dialog box */ 107 | MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", 108 | MB_OK | MB_ICONERROR); 109 | #else 110 | /* Send it to stderr, adding a newline */ 111 | fprintf(stderr, "%s\n", buffer); 112 | #endif 113 | } 114 | 115 | 116 | /* 117 | * Decide whether to emit a trace or warning message. 118 | * msg_level is one of: 119 | * -1: recoverable corrupt-data warning, may want to abort. 120 | * 0: important advisory messages (always display to user). 121 | * 1: first level of tracing detail. 122 | * 2,3,...: successively more detailed tracing messages. 123 | * An application might override this method if it wanted to abort on warnings 124 | * or change the policy about which messages to display. 125 | */ 126 | 127 | METHODDEF(void) 128 | emit_message (j_common_ptr cinfo, int msg_level) 129 | { 130 | struct jpeg_error_mgr * err = cinfo->err; 131 | 132 | if (msg_level < 0) { 133 | /* It's a warning message. Since corrupt files may generate many warnings, 134 | * the policy implemented here is to show only the first warning, 135 | * unless trace_level >= 3. 136 | */ 137 | if (err->num_warnings == 0 || err->trace_level >= 3) 138 | (*err->output_message) (cinfo); 139 | /* Always count warnings in num_warnings. */ 140 | err->num_warnings++; 141 | } else { 142 | /* It's a trace message. Show it if trace_level >= msg_level. */ 143 | if (err->trace_level >= msg_level) 144 | (*err->output_message) (cinfo); 145 | } 146 | } 147 | 148 | 149 | /* 150 | * Format a message string for the most recent JPEG error or message. 151 | * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX 152 | * characters. Note that no '\n' character is added to the string. 153 | * Few applications should need to override this method. 154 | */ 155 | 156 | METHODDEF(void) 157 | format_message (j_common_ptr cinfo, char * buffer) 158 | { 159 | struct jpeg_error_mgr * err = cinfo->err; 160 | int msg_code = err->msg_code; 161 | const char * msgtext = NULL; 162 | const char * msgptr; 163 | char ch; 164 | boolean isstring; 165 | 166 | /* Look up message string in proper table */ 167 | if (msg_code > 0 && msg_code <= err->last_jpeg_message) { 168 | msgtext = err->jpeg_message_table[msg_code]; 169 | } else if (err->addon_message_table != NULL && 170 | msg_code >= err->first_addon_message && 171 | msg_code <= err->last_addon_message) { 172 | msgtext = err->addon_message_table[msg_code - err->first_addon_message]; 173 | } 174 | 175 | /* Defend against bogus message number */ 176 | if (msgtext == NULL) { 177 | err->msg_parm.i[0] = msg_code; 178 | msgtext = err->jpeg_message_table[0]; 179 | } 180 | 181 | /* Check for string parameter, as indicated by %s in the message text */ 182 | isstring = FALSE; 183 | msgptr = msgtext; 184 | while ((ch = *msgptr++) != '\0') { 185 | if (ch == '%') { 186 | if (*msgptr == 's') isstring = TRUE; 187 | break; 188 | } 189 | } 190 | 191 | /* Format the message into the passed buffer */ 192 | if (isstring) 193 | sprintf(buffer, msgtext, err->msg_parm.s); 194 | else 195 | sprintf(buffer, msgtext, 196 | err->msg_parm.i[0], err->msg_parm.i[1], 197 | err->msg_parm.i[2], err->msg_parm.i[3], 198 | err->msg_parm.i[4], err->msg_parm.i[5], 199 | err->msg_parm.i[6], err->msg_parm.i[7]); 200 | } 201 | 202 | 203 | /* 204 | * Reset error state variables at start of a new image. 205 | * This is called during compression startup to reset trace/error 206 | * processing to default state, without losing any application-specific 207 | * method pointers. An application might possibly want to override 208 | * this method if it has additional error processing state. 209 | */ 210 | 211 | METHODDEF(void) 212 | reset_error_mgr (j_common_ptr cinfo) 213 | { 214 | cinfo->err->num_warnings = 0; 215 | /* trace_level is not reset since it is an application-supplied parameter */ 216 | cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */ 217 | } 218 | 219 | 220 | /* 221 | * Fill in the standard error-handling methods in a jpeg_error_mgr object. 222 | * Typical call is: 223 | * struct jpeg_compress_struct cinfo; 224 | * struct jpeg_error_mgr err; 225 | * 226 | * cinfo.err = jpeg_std_error(&err); 227 | * after which the application may override some of the methods. 228 | */ 229 | 230 | GLOBAL(struct jpeg_error_mgr *) 231 | jpeg_std_error (struct jpeg_error_mgr * err) 232 | { 233 | err->error_exit = error_exit; 234 | err->emit_message = emit_message; 235 | err->output_message = output_message; 236 | err->format_message = format_message; 237 | err->reset_error_mgr = reset_error_mgr; 238 | 239 | err->trace_level = 0; /* default = no tracing */ 240 | err->num_warnings = 0; /* no warnings emitted yet */ 241 | err->msg_code = 0; /* may be useful as a flag for "no error" */ 242 | 243 | /* Initialize message table pointers */ 244 | err->jpeg_message_table = jpeg_std_message_table; 245 | err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; 246 | 247 | err->addon_message_table = NULL; 248 | err->first_addon_message = 0; /* for safety */ 249 | err->last_addon_message = 0; 250 | 251 | return err; 252 | } 253 | -------------------------------------------------------------------------------- /jfdctflt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jfdctflt.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * Modified 2003-2009 by Guido Vollbeding. 6 | * This file is part of the Independent JPEG Group's software. 7 | * For conditions of distribution and use, see the accompanying README file. 8 | * 9 | * This file contains a floating-point implementation of the 10 | * forward DCT (Discrete Cosine Transform). 11 | * 12 | * This implementation should be more accurate than either of the integer 13 | * DCT implementations. However, it may not give the same results on all 14 | * machines because of differences in roundoff behavior. Speed will depend 15 | * on the hardware's floating point capacity. 16 | * 17 | * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT 18 | * on each column. Direct algorithms are also available, but they are 19 | * much more complex and seem not to be any faster when reduced to code. 20 | * 21 | * This implementation is based on Arai, Agui, and Nakajima's algorithm for 22 | * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 23 | * Japanese, but the algorithm is described in the Pennebaker & Mitchell 24 | * JPEG textbook (see REFERENCES section in file README). The following code 25 | * is based directly on figure 4-8 in P&M. 26 | * While an 8-point DCT cannot be done in less than 11 multiplies, it is 27 | * possible to arrange the computation so that many of the multiplies are 28 | * simple scalings of the final outputs. These multiplies can then be 29 | * folded into the multiplications or divisions by the JPEG quantization 30 | * table entries. The AA&N method leaves only 5 multiplies and 29 adds 31 | * to be done in the DCT itself. 32 | * The primary disadvantage of this method is that with a fixed-point 33 | * implementation, accuracy is lost due to imprecise representation of the 34 | * scaled quantization values. However, that problem does not arise if 35 | * we use floating point arithmetic. 36 | */ 37 | 38 | #define JPEG_INTERNALS 39 | #include "jinclude.h" 40 | #include "jpeglib.h" 41 | #include "jdct.h" /* Private declarations for DCT subsystem */ 42 | 43 | #ifdef DCT_FLOAT_SUPPORTED 44 | 45 | 46 | /* 47 | * This module is specialized to the case DCTSIZE = 8. 48 | */ 49 | 50 | #if DCTSIZE != 8 51 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 52 | #endif 53 | 54 | 55 | /* 56 | * Perform the forward DCT on one block of samples. 57 | */ 58 | 59 | GLOBAL(void) 60 | jpeg_fdct_float (FAST_FLOAT * data, JSAMPARRAY sample_data, JDIMENSION start_col) 61 | { 62 | FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 63 | FAST_FLOAT tmp10, tmp11, tmp12, tmp13; 64 | FAST_FLOAT z1, z2, z3, z4, z5, z11, z13; 65 | FAST_FLOAT *dataptr; 66 | JSAMPROW elemptr; 67 | int ctr; 68 | 69 | /* Pass 1: process rows. */ 70 | 71 | dataptr = data; 72 | for (ctr = 0; ctr < DCTSIZE; ctr++) { 73 | elemptr = sample_data[ctr] + start_col; 74 | 75 | /* Load data into workspace */ 76 | tmp0 = (FAST_FLOAT) (GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7])); 77 | tmp7 = (FAST_FLOAT) (GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7])); 78 | tmp1 = (FAST_FLOAT) (GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6])); 79 | tmp6 = (FAST_FLOAT) (GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6])); 80 | tmp2 = (FAST_FLOAT) (GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5])); 81 | tmp5 = (FAST_FLOAT) (GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5])); 82 | tmp3 = (FAST_FLOAT) (GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4])); 83 | tmp4 = (FAST_FLOAT) (GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4])); 84 | 85 | /* Even part */ 86 | 87 | tmp10 = tmp0 + tmp3; /* phase 2 */ 88 | tmp13 = tmp0 - tmp3; 89 | tmp11 = tmp1 + tmp2; 90 | tmp12 = tmp1 - tmp2; 91 | 92 | /* Apply unsigned->signed conversion */ 93 | dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */ 94 | dataptr[4] = tmp10 - tmp11; 95 | 96 | z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ 97 | dataptr[2] = tmp13 + z1; /* phase 5 */ 98 | dataptr[6] = tmp13 - z1; 99 | 100 | /* Odd part */ 101 | 102 | tmp10 = tmp4 + tmp5; /* phase 2 */ 103 | tmp11 = tmp5 + tmp6; 104 | tmp12 = tmp6 + tmp7; 105 | 106 | /* The rotator is modified from fig 4-8 to avoid extra negations. */ 107 | z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ 108 | z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ 109 | z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ 110 | z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ 111 | 112 | z11 = tmp7 + z3; /* phase 5 */ 113 | z13 = tmp7 - z3; 114 | 115 | dataptr[5] = z13 + z2; /* phase 6 */ 116 | dataptr[3] = z13 - z2; 117 | dataptr[1] = z11 + z4; 118 | dataptr[7] = z11 - z4; 119 | 120 | dataptr += DCTSIZE; /* advance pointer to next row */ 121 | } 122 | 123 | /* Pass 2: process columns. */ 124 | 125 | dataptr = data; 126 | for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { 127 | tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; 128 | tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; 129 | tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; 130 | tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; 131 | tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; 132 | tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; 133 | tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; 134 | tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; 135 | 136 | /* Even part */ 137 | 138 | tmp10 = tmp0 + tmp3; /* phase 2 */ 139 | tmp13 = tmp0 - tmp3; 140 | tmp11 = tmp1 + tmp2; 141 | tmp12 = tmp1 - tmp2; 142 | 143 | dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ 144 | dataptr[DCTSIZE*4] = tmp10 - tmp11; 145 | 146 | z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ 147 | dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ 148 | dataptr[DCTSIZE*6] = tmp13 - z1; 149 | 150 | /* Odd part */ 151 | 152 | tmp10 = tmp4 + tmp5; /* phase 2 */ 153 | tmp11 = tmp5 + tmp6; 154 | tmp12 = tmp6 + tmp7; 155 | 156 | /* The rotator is modified from fig 4-8 to avoid extra negations. */ 157 | z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ 158 | z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ 159 | z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ 160 | z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ 161 | 162 | z11 = tmp7 + z3; /* phase 5 */ 163 | z13 = tmp7 - z3; 164 | 165 | dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ 166 | dataptr[DCTSIZE*3] = z13 - z2; 167 | dataptr[DCTSIZE*1] = z11 + z4; 168 | dataptr[DCTSIZE*7] = z11 - z4; 169 | 170 | dataptr++; /* advance pointer to next column */ 171 | } 172 | } 173 | 174 | #endif /* DCT_FLOAT_SUPPORTED */ 175 | -------------------------------------------------------------------------------- /jfdctfst.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jfdctfst.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * Modified 2003-2009 by Guido Vollbeding. 6 | * This file is part of the Independent JPEG Group's software. 7 | * For conditions of distribution and use, see the accompanying README file. 8 | * 9 | * This file contains a fast, not so accurate integer implementation of the 10 | * forward DCT (Discrete Cosine Transform). 11 | * 12 | * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT 13 | * on each column. Direct algorithms are also available, but they are 14 | * much more complex and seem not to be any faster when reduced to code. 15 | * 16 | * This implementation is based on Arai, Agui, and Nakajima's algorithm for 17 | * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 18 | * Japanese, but the algorithm is described in the Pennebaker & Mitchell 19 | * JPEG textbook (see REFERENCES section in file README). The following code 20 | * is based directly on figure 4-8 in P&M. 21 | * While an 8-point DCT cannot be done in less than 11 multiplies, it is 22 | * possible to arrange the computation so that many of the multiplies are 23 | * simple scalings of the final outputs. These multiplies can then be 24 | * folded into the multiplications or divisions by the JPEG quantization 25 | * table entries. The AA&N method leaves only 5 multiplies and 29 adds 26 | * to be done in the DCT itself. 27 | * The primary disadvantage of this method is that with fixed-point math, 28 | * accuracy is lost due to imprecise representation of the scaled 29 | * quantization values. The smaller the quantization table entry, the less 30 | * precise the scaled value, so this implementation does worse with high- 31 | * quality-setting files than with low-quality ones. 32 | */ 33 | 34 | #define JPEG_INTERNALS 35 | #include "jinclude.h" 36 | #include "jpeglib.h" 37 | #include "jdct.h" /* Private declarations for DCT subsystem */ 38 | 39 | #ifdef DCT_IFAST_SUPPORTED 40 | 41 | 42 | /* 43 | * This module is specialized to the case DCTSIZE = 8. 44 | */ 45 | 46 | #if DCTSIZE != 8 47 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 48 | #endif 49 | 50 | 51 | /* Scaling decisions are generally the same as in the LL&M algorithm; 52 | * see jfdctint.c for more details. However, we choose to descale 53 | * (right shift) multiplication products as soon as they are formed, 54 | * rather than carrying additional fractional bits into subsequent additions. 55 | * This compromises accuracy slightly, but it lets us save a few shifts. 56 | * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) 57 | * everywhere except in the multiplications proper; this saves a good deal 58 | * of work on 16-bit-int machines. 59 | * 60 | * Again to save a few shifts, the intermediate results between pass 1 and 61 | * pass 2 are not upscaled, but are represented only to integral precision. 62 | * 63 | * A final compromise is to represent the multiplicative constants to only 64 | * 8 fractional bits, rather than 13. This saves some shifting work on some 65 | * machines, and may also reduce the cost of multiplication (since there 66 | * are fewer one-bits in the constants). 67 | */ 68 | 69 | #define CONST_BITS 8 70 | 71 | 72 | /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus 73 | * causing a lot of useless floating-point operations at run time. 74 | * To get around this we use the following pre-calculated constants. 75 | * If you change CONST_BITS you may want to add appropriate values. 76 | * (With a reasonable C compiler, you can just rely on the FIX() macro...) 77 | */ 78 | 79 | #if CONST_BITS == 8 80 | #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */ 81 | #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */ 82 | #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */ 83 | #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */ 84 | #else 85 | #define FIX_0_382683433 FIX(0.382683433) 86 | #define FIX_0_541196100 FIX(0.541196100) 87 | #define FIX_0_707106781 FIX(0.707106781) 88 | #define FIX_1_306562965 FIX(1.306562965) 89 | #endif 90 | 91 | 92 | /* We can gain a little more speed, with a further compromise in accuracy, 93 | * by omitting the addition in a descaling shift. This yields an incorrectly 94 | * rounded result half the time... 95 | */ 96 | 97 | #ifndef USE_ACCURATE_ROUNDING 98 | #undef DESCALE 99 | #define DESCALE(x,n) RIGHT_SHIFT(x, n) 100 | #endif 101 | 102 | 103 | /* Multiply a DCTELEM variable by an INT32 constant, and immediately 104 | * descale to yield a DCTELEM result. 105 | */ 106 | 107 | #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) 108 | 109 | 110 | /* 111 | * Perform the forward DCT on one block of samples. 112 | */ 113 | 114 | GLOBAL(void) 115 | jpeg_fdct_ifast (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col) 116 | { 117 | DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 118 | DCTELEM tmp10, tmp11, tmp12, tmp13; 119 | DCTELEM z1, z2, z3, z4, z5, z11, z13; 120 | DCTELEM *dataptr; 121 | JSAMPROW elemptr; 122 | int ctr; 123 | SHIFT_TEMPS 124 | 125 | /* Pass 1: process rows. */ 126 | 127 | dataptr = data; 128 | for (ctr = 0; ctr < DCTSIZE; ctr++) { 129 | elemptr = sample_data[ctr] + start_col; 130 | 131 | /* Load data into workspace */ 132 | tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]); 133 | tmp7 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]); 134 | tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]); 135 | tmp6 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]); 136 | tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]); 137 | tmp5 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]); 138 | tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]); 139 | tmp4 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]); 140 | 141 | /* Even part */ 142 | 143 | tmp10 = tmp0 + tmp3; /* phase 2 */ 144 | tmp13 = tmp0 - tmp3; 145 | tmp11 = tmp1 + tmp2; 146 | tmp12 = tmp1 - tmp2; 147 | 148 | /* Apply unsigned->signed conversion */ 149 | dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */ 150 | dataptr[4] = tmp10 - tmp11; 151 | 152 | z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ 153 | dataptr[2] = tmp13 + z1; /* phase 5 */ 154 | dataptr[6] = tmp13 - z1; 155 | 156 | /* Odd part */ 157 | 158 | tmp10 = tmp4 + tmp5; /* phase 2 */ 159 | tmp11 = tmp5 + tmp6; 160 | tmp12 = tmp6 + tmp7; 161 | 162 | /* The rotator is modified from fig 4-8 to avoid extra negations. */ 163 | z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */ 164 | z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */ 165 | z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ 166 | z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ 167 | 168 | z11 = tmp7 + z3; /* phase 5 */ 169 | z13 = tmp7 - z3; 170 | 171 | dataptr[5] = z13 + z2; /* phase 6 */ 172 | dataptr[3] = z13 - z2; 173 | dataptr[1] = z11 + z4; 174 | dataptr[7] = z11 - z4; 175 | 176 | dataptr += DCTSIZE; /* advance pointer to next row */ 177 | } 178 | 179 | /* Pass 2: process columns. */ 180 | 181 | dataptr = data; 182 | for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { 183 | tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; 184 | tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; 185 | tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; 186 | tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; 187 | tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; 188 | tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; 189 | tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; 190 | tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; 191 | 192 | /* Even part */ 193 | 194 | tmp10 = tmp0 + tmp3; /* phase 2 */ 195 | tmp13 = tmp0 - tmp3; 196 | tmp11 = tmp1 + tmp2; 197 | tmp12 = tmp1 - tmp2; 198 | 199 | dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ 200 | dataptr[DCTSIZE*4] = tmp10 - tmp11; 201 | 202 | z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ 203 | dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ 204 | dataptr[DCTSIZE*6] = tmp13 - z1; 205 | 206 | /* Odd part */ 207 | 208 | tmp10 = tmp4 + tmp5; /* phase 2 */ 209 | tmp11 = tmp5 + tmp6; 210 | tmp12 = tmp6 + tmp7; 211 | 212 | /* The rotator is modified from fig 4-8 to avoid extra negations. */ 213 | z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */ 214 | z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */ 215 | z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ 216 | z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ 217 | 218 | z11 = tmp7 + z3; /* phase 5 */ 219 | z13 = tmp7 - z3; 220 | 221 | dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ 222 | dataptr[DCTSIZE*3] = z13 - z2; 223 | dataptr[DCTSIZE*1] = z11 + z4; 224 | dataptr[DCTSIZE*7] = z11 - z4; 225 | 226 | dataptr++; /* advance pointer to next column */ 227 | } 228 | } 229 | 230 | #endif /* DCT_IFAST_SUPPORTED */ 231 | -------------------------------------------------------------------------------- /jidctflt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jidctflt.c 3 | * 4 | * Copyright (C) 1994-1998, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains a floating-point implementation of the 9 | * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine 10 | * must also perform dequantization of the input coefficients. 11 | * 12 | * This implementation should be more accurate than either of the integer 13 | * IDCT implementations. However, it may not give the same results on all 14 | * machines because of differences in roundoff behavior. Speed will depend 15 | * on the hardware's floating point capacity. 16 | * 17 | * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT 18 | * on each row (or vice versa, but it's more convenient to emit a row at 19 | * a time). Direct algorithms are also available, but they are much more 20 | * complex and seem not to be any faster when reduced to code. 21 | * 22 | * This implementation is based on Arai, Agui, and Nakajima's algorithm for 23 | * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 24 | * Japanese, but the algorithm is described in the Pennebaker & Mitchell 25 | * JPEG textbook (see REFERENCES section in file README). The following code 26 | * is based directly on figure 4-8 in P&M. 27 | * While an 8-point DCT cannot be done in less than 11 multiplies, it is 28 | * possible to arrange the computation so that many of the multiplies are 29 | * simple scalings of the final outputs. These multiplies can then be 30 | * folded into the multiplications or divisions by the JPEG quantization 31 | * table entries. The AA&N method leaves only 5 multiplies and 29 adds 32 | * to be done in the DCT itself. 33 | * The primary disadvantage of this method is that with a fixed-point 34 | * implementation, accuracy is lost due to imprecise representation of the 35 | * scaled quantization values. However, that problem does not arise if 36 | * we use floating point arithmetic. 37 | */ 38 | 39 | #define JPEG_INTERNALS 40 | #include "jinclude.h" 41 | #include "jpeglib.h" 42 | #include "jdct.h" /* Private declarations for DCT subsystem */ 43 | 44 | #ifdef DCT_FLOAT_SUPPORTED 45 | 46 | 47 | /* 48 | * This module is specialized to the case DCTSIZE = 8. 49 | */ 50 | 51 | #if DCTSIZE != 8 52 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 53 | #endif 54 | 55 | 56 | /* Dequantize a coefficient by multiplying it by the multiplier-table 57 | * entry; produce a float result. 58 | */ 59 | 60 | #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval)) 61 | 62 | 63 | /* 64 | * Perform dequantization and inverse DCT on one block of coefficients. 65 | */ 66 | 67 | GLOBAL(void) 68 | jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, 69 | JCOEFPTR coef_block, 70 | JSAMPARRAY output_buf, JDIMENSION output_col) 71 | { 72 | FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 73 | FAST_FLOAT tmp10, tmp11, tmp12, tmp13; 74 | FAST_FLOAT z5, z10, z11, z12, z13; 75 | JCOEFPTR inptr; 76 | FLOAT_MULT_TYPE * quantptr; 77 | FAST_FLOAT * wsptr; 78 | JSAMPROW outptr; 79 | JSAMPLE *range_limit = IDCT_range_limit(cinfo); 80 | int ctr; 81 | FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */ 82 | SHIFT_TEMPS 83 | 84 | /* Pass 1: process columns from input, store into work array. */ 85 | 86 | inptr = coef_block; 87 | quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table; 88 | wsptr = workspace; 89 | for (ctr = DCTSIZE; ctr > 0; ctr--) { 90 | /* Due to quantization, we will usually find that many of the input 91 | * coefficients are zero, especially the AC terms. We can exploit this 92 | * by short-circuiting the IDCT calculation for any column in which all 93 | * the AC terms are zero. In that case each output is equal to the 94 | * DC coefficient (with scale factor as needed). 95 | * With typical images and quantization tables, half or more of the 96 | * column DCT calculations can be simplified this way. 97 | */ 98 | 99 | if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && 100 | inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && 101 | inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && 102 | inptr[DCTSIZE*7] == 0) { 103 | /* AC terms all zero */ 104 | FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 105 | 106 | wsptr[DCTSIZE*0] = dcval; 107 | wsptr[DCTSIZE*1] = dcval; 108 | wsptr[DCTSIZE*2] = dcval; 109 | wsptr[DCTSIZE*3] = dcval; 110 | wsptr[DCTSIZE*4] = dcval; 111 | wsptr[DCTSIZE*5] = dcval; 112 | wsptr[DCTSIZE*6] = dcval; 113 | wsptr[DCTSIZE*7] = dcval; 114 | 115 | inptr++; /* advance pointers to next column */ 116 | quantptr++; 117 | wsptr++; 118 | continue; 119 | } 120 | 121 | /* Even part */ 122 | 123 | tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 124 | tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); 125 | tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); 126 | tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); 127 | 128 | tmp10 = tmp0 + tmp2; /* phase 3 */ 129 | tmp11 = tmp0 - tmp2; 130 | 131 | tmp13 = tmp1 + tmp3; /* phases 5-3 */ 132 | tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */ 133 | 134 | tmp0 = tmp10 + tmp13; /* phase 2 */ 135 | tmp3 = tmp10 - tmp13; 136 | tmp1 = tmp11 + tmp12; 137 | tmp2 = tmp11 - tmp12; 138 | 139 | /* Odd part */ 140 | 141 | tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); 142 | tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); 143 | tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); 144 | tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); 145 | 146 | z13 = tmp6 + tmp5; /* phase 6 */ 147 | z10 = tmp6 - tmp5; 148 | z11 = tmp4 + tmp7; 149 | z12 = tmp4 - tmp7; 150 | 151 | tmp7 = z11 + z13; /* phase 5 */ 152 | tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */ 153 | 154 | z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ 155 | tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ 156 | tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ 157 | 158 | tmp6 = tmp12 - tmp7; /* phase 2 */ 159 | tmp5 = tmp11 - tmp6; 160 | tmp4 = tmp10 + tmp5; 161 | 162 | wsptr[DCTSIZE*0] = tmp0 + tmp7; 163 | wsptr[DCTSIZE*7] = tmp0 - tmp7; 164 | wsptr[DCTSIZE*1] = tmp1 + tmp6; 165 | wsptr[DCTSIZE*6] = tmp1 - tmp6; 166 | wsptr[DCTSIZE*2] = tmp2 + tmp5; 167 | wsptr[DCTSIZE*5] = tmp2 - tmp5; 168 | wsptr[DCTSIZE*4] = tmp3 + tmp4; 169 | wsptr[DCTSIZE*3] = tmp3 - tmp4; 170 | 171 | inptr++; /* advance pointers to next column */ 172 | quantptr++; 173 | wsptr++; 174 | } 175 | 176 | /* Pass 2: process rows from work array, store into output array. */ 177 | /* Note that we must descale the results by a factor of 8 == 2**3. */ 178 | 179 | wsptr = workspace; 180 | for (ctr = 0; ctr < DCTSIZE; ctr++) { 181 | outptr = output_buf[ctr] + output_col; 182 | /* Rows of zeroes can be exploited in the same way as we did with columns. 183 | * However, the column calculation has created many nonzero AC terms, so 184 | * the simplification applies less often (typically 5% to 10% of the time). 185 | * And testing floats for zero is relatively expensive, so we don't bother. 186 | */ 187 | 188 | /* Even part */ 189 | 190 | tmp10 = wsptr[0] + wsptr[4]; 191 | tmp11 = wsptr[0] - wsptr[4]; 192 | 193 | tmp13 = wsptr[2] + wsptr[6]; 194 | tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13; 195 | 196 | tmp0 = tmp10 + tmp13; 197 | tmp3 = tmp10 - tmp13; 198 | tmp1 = tmp11 + tmp12; 199 | tmp2 = tmp11 - tmp12; 200 | 201 | /* Odd part */ 202 | 203 | z13 = wsptr[5] + wsptr[3]; 204 | z10 = wsptr[5] - wsptr[3]; 205 | z11 = wsptr[1] + wsptr[7]; 206 | z12 = wsptr[1] - wsptr[7]; 207 | 208 | tmp7 = z11 + z13; 209 | tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); 210 | 211 | z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ 212 | tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ 213 | tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ 214 | 215 | tmp6 = tmp12 - tmp7; 216 | tmp5 = tmp11 - tmp6; 217 | tmp4 = tmp10 + tmp5; 218 | 219 | /* Final output stage: scale down by a factor of 8 and range-limit */ 220 | 221 | outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3) 222 | & RANGE_MASK]; 223 | outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3) 224 | & RANGE_MASK]; 225 | outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3) 226 | & RANGE_MASK]; 227 | outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3) 228 | & RANGE_MASK]; 229 | outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3) 230 | & RANGE_MASK]; 231 | outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3) 232 | & RANGE_MASK]; 233 | outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3) 234 | & RANGE_MASK]; 235 | outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3) 236 | & RANGE_MASK]; 237 | 238 | wsptr += DCTSIZE; /* advance pointer to next row */ 239 | } 240 | } 241 | 242 | #endif /* DCT_FLOAT_SUPPORTED */ 243 | -------------------------------------------------------------------------------- /jinclude.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jinclude.h 3 | * 4 | * Copyright (C) 1991-1994, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file exists to provide a single place to fix any problems with 9 | * including the wrong system include files. (Common problems are taken 10 | * care of by the standard jconfig symbols, but on really weird systems 11 | * you may have to edit this file.) 12 | * 13 | * NOTE: this file is NOT intended to be included by applications using the 14 | * JPEG library. Most applications need only include jpeglib.h. 15 | */ 16 | 17 | 18 | /* Include auto-config file to find out which system include files we need. */ 19 | 20 | #include "jconfig.h" /* auto configuration options */ 21 | #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ 22 | 23 | /* 24 | * We need the NULL macro and size_t typedef. 25 | * On an ANSI-conforming system it is sufficient to include . 26 | * Otherwise, we get them from or ; we may have to 27 | * pull in as well. 28 | * Note that the core JPEG library does not require ; 29 | * only the default error handler and data source/destination modules do. 30 | * But we must pull it in because of the references to FILE in jpeglib.h. 31 | * You can remove those references if you want to compile without . 32 | */ 33 | 34 | #ifdef HAVE_STDDEF_H 35 | #include 36 | #endif 37 | 38 | #ifdef HAVE_STDLIB_H 39 | #include 40 | #endif 41 | 42 | #ifdef NEED_SYS_TYPES_H 43 | #include 44 | #endif 45 | 46 | #include 47 | 48 | /* 49 | * We need memory copying and zeroing functions, plus strncpy(). 50 | * ANSI and System V implementations declare these in . 51 | * BSD doesn't have the mem() functions, but it does have bcopy()/bzero(). 52 | * Some systems may declare memset and memcpy in . 53 | * 54 | * NOTE: we assume the size parameters to these functions are of type size_t. 55 | * Change the casts in these macros if not! 56 | */ 57 | 58 | #ifdef NEED_BSD_STRINGS 59 | 60 | #include 61 | #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) 62 | #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) 63 | 64 | #else /* not BSD, assume ANSI/SysV string lib */ 65 | 66 | #include 67 | #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) 68 | #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) 69 | 70 | #endif 71 | 72 | /* 73 | * In ANSI C, and indeed any rational implementation, size_t is also the 74 | * type returned by sizeof(). However, it seems there are some irrational 75 | * implementations out there, in which sizeof() returns an int even though 76 | * size_t is defined as long or unsigned long. To ensure consistent results 77 | * we always use this SIZEOF() macro in place of using sizeof() directly. 78 | */ 79 | 80 | #define SIZEOF(object) ((size_t) sizeof(object)) 81 | 82 | /* 83 | * The modules that use fread() and fwrite() always invoke them through 84 | * these macros. On some systems you may need to twiddle the argument casts. 85 | * CAUTION: argument order is different from underlying functions! 86 | */ 87 | 88 | #define JFREAD(file,buf,sizeofbuf) \ 89 | ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) 90 | 91 | #if 0 92 | #define JFWRITE(file,buf,sizeofbuf) (sizeofbuf) 93 | #else 94 | #define JFWRITE(file,buf,sizeofbuf) \ 95 | ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) 96 | #endif 97 | 98 | -------------------------------------------------------------------------------- /jmemansi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jmemansi.c 3 | * 4 | * Copyright (C) 1992-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file provides a simple generic implementation of the system- 9 | * dependent portion of the JPEG memory manager. This implementation 10 | * assumes that you have the ANSI-standard library routine tmpfile(). 11 | * Also, the problem of determining the amount of memory available 12 | * is shoved onto the user. 13 | */ 14 | 15 | #define JPEG_INTERNALS 16 | #include "jinclude.h" 17 | #include "jpeglib.h" 18 | #include "jmemsys.h" /* import the system-dependent declarations */ 19 | 20 | #ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ 21 | extern void * malloc JPP((size_t size)); 22 | extern void free JPP((void *ptr)); 23 | #endif 24 | 25 | #ifndef SEEK_SET /* pre-ANSI systems may not define this; */ 26 | #define SEEK_SET 0 /* if not, assume 0 is correct */ 27 | #endif 28 | 29 | 30 | /* 31 | * Memory allocation and freeing are controlled by the regular library 32 | * routines malloc() and free(). 33 | */ 34 | 35 | GLOBAL(void *) 36 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) 37 | { 38 | return (void *) malloc(sizeofobject); 39 | } 40 | 41 | GLOBAL(void) 42 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) 43 | { 44 | free(object); 45 | } 46 | 47 | 48 | /* 49 | * "Large" objects are treated the same as "small" ones. 50 | * NB: although we include FAR keywords in the routine declarations, 51 | * this file won't actually work in 80x86 small/medium model; at least, 52 | * you probably won't be able to process useful-size images in only 64KB. 53 | */ 54 | 55 | GLOBAL(void FAR *) 56 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) 57 | { 58 | return (void FAR *) malloc(sizeofobject); 59 | } 60 | 61 | GLOBAL(void) 62 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) 63 | { 64 | free(object); 65 | } 66 | 67 | 68 | /* 69 | * This routine computes the total memory space available for allocation. 70 | * It's impossible to do this in a portable way; our current solution is 71 | * to make the user tell us (with a default value set at compile time). 72 | * If you can actually get the available space, it's a good idea to subtract 73 | * a slop factor of 5% or so. 74 | */ 75 | 76 | #ifndef DEFAULT_MAX_MEM /* so can override from makefile */ 77 | #define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */ 78 | #endif 79 | 80 | GLOBAL(long) 81 | jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, 82 | long max_bytes_needed, long already_allocated) 83 | { 84 | return cinfo->mem->max_memory_to_use - already_allocated; 85 | } 86 | 87 | 88 | /* 89 | * Backing store (temporary file) management. 90 | * Backing store objects are only used when the value returned by 91 | * jpeg_mem_available is less than the total space needed. You can dispense 92 | * with these routines if you have plenty of virtual memory; see jmemnobs.c. 93 | */ 94 | 95 | 96 | METHODDEF(void) 97 | read_backing_store (j_common_ptr cinfo, backing_store_ptr info, 98 | void FAR * buffer_address, 99 | long file_offset, long byte_count) 100 | { 101 | if (fseek(info->temp_file, file_offset, SEEK_SET)) 102 | ERREXIT(cinfo, JERR_TFILE_SEEK); 103 | if (JFREAD(info->temp_file, buffer_address, byte_count) 104 | != (size_t) byte_count) 105 | ERREXIT(cinfo, JERR_TFILE_READ); 106 | } 107 | 108 | 109 | METHODDEF(void) 110 | write_backing_store (j_common_ptr cinfo, backing_store_ptr info, 111 | void FAR * buffer_address, 112 | long file_offset, long byte_count) 113 | { 114 | if (fseek(info->temp_file, file_offset, SEEK_SET)) 115 | ERREXIT(cinfo, JERR_TFILE_SEEK); 116 | if (JFWRITE(info->temp_file, buffer_address, byte_count) 117 | != (size_t) byte_count) 118 | ERREXIT(cinfo, JERR_TFILE_WRITE); 119 | } 120 | 121 | 122 | METHODDEF(void) 123 | close_backing_store (j_common_ptr cinfo, backing_store_ptr info) 124 | { 125 | fclose(info->temp_file); 126 | /* Since this implementation uses tmpfile() to create the file, 127 | * no explicit file deletion is needed. 128 | */ 129 | } 130 | 131 | 132 | /* 133 | * Initial opening of a backing-store object. 134 | * 135 | * This version uses tmpfile(), which constructs a suitable file name 136 | * behind the scenes. We don't have to use info->temp_name[] at all; 137 | * indeed, we can't even find out the actual name of the temp file. 138 | */ 139 | 140 | GLOBAL(void) 141 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, 142 | long total_bytes_needed) 143 | { 144 | if ((info->temp_file = tmpfile()) == NULL) 145 | ERREXITS(cinfo, JERR_TFILE_CREATE, ""); 146 | info->read_backing_store = read_backing_store; 147 | info->write_backing_store = write_backing_store; 148 | info->close_backing_store = close_backing_store; 149 | } 150 | 151 | 152 | /* 153 | * These routines take care of any system-dependent initialization and 154 | * cleanup required. 155 | */ 156 | 157 | GLOBAL(long) 158 | jpeg_mem_init (j_common_ptr cinfo) 159 | { 160 | return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ 161 | } 162 | 163 | GLOBAL(void) 164 | jpeg_mem_term (j_common_ptr cinfo) 165 | { 166 | /* no work */ 167 | } 168 | -------------------------------------------------------------------------------- /jmemname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jmemname.c 3 | * 4 | * Copyright (C) 1992-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file provides a generic implementation of the system-dependent 9 | * portion of the JPEG memory manager. This implementation assumes that 10 | * you must explicitly construct a name for each temp file. 11 | * Also, the problem of determining the amount of memory available 12 | * is shoved onto the user. 13 | */ 14 | 15 | #define JPEG_INTERNALS 16 | #include "jinclude.h" 17 | #include "jpeglib.h" 18 | #include "jmemsys.h" /* import the system-dependent declarations */ 19 | 20 | #ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ 21 | extern void * malloc JPP((size_t size)); 22 | extern void free JPP((void *ptr)); 23 | #endif 24 | 25 | #ifndef SEEK_SET /* pre-ANSI systems may not define this; */ 26 | #define SEEK_SET 0 /* if not, assume 0 is correct */ 27 | #endif 28 | 29 | #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ 30 | #define READ_BINARY "r" 31 | #define RW_BINARY "w+" 32 | #else 33 | #ifdef VMS /* VMS is very nonstandard */ 34 | #define READ_BINARY "rb", "ctx=stm" 35 | #define RW_BINARY "w+b", "ctx=stm" 36 | #else /* standard ANSI-compliant case */ 37 | #define READ_BINARY "rb" 38 | #define RW_BINARY "w+b" 39 | #endif 40 | #endif 41 | 42 | 43 | /* 44 | * Selection of a file name for a temporary file. 45 | * This is system-dependent! 46 | * 47 | * The code as given is suitable for most Unix systems, and it is easily 48 | * modified for most non-Unix systems. Some notes: 49 | * 1. The temp file is created in the directory named by TEMP_DIRECTORY. 50 | * The default value is /usr/tmp, which is the conventional place for 51 | * creating large temp files on Unix. On other systems you'll probably 52 | * want to change the file location. You can do this by editing the 53 | * #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h. 54 | * 55 | * 2. If you need to change the file name as well as its location, 56 | * you can override the TEMP_FILE_NAME macro. (Note that this is 57 | * actually a printf format string; it must contain %s and %d.) 58 | * Few people should need to do this. 59 | * 60 | * 3. mktemp() is used to ensure that multiple processes running 61 | * simultaneously won't select the same file names. If your system 62 | * doesn't have mktemp(), define NO_MKTEMP to do it the hard way. 63 | * (If you don't have , also define NO_ERRNO_H.) 64 | * 65 | * 4. You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c 66 | * will cause the temp files to be removed if you stop the program early. 67 | */ 68 | 69 | #ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */ 70 | #define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */ 71 | #endif 72 | 73 | static int next_file_num; /* to distinguish among several temp files */ 74 | 75 | #ifdef NO_MKTEMP 76 | 77 | #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ 78 | #define TEMP_FILE_NAME "%sJPG%03d.TMP" 79 | #endif 80 | 81 | #ifndef NO_ERRNO_H 82 | #include /* to define ENOENT */ 83 | #endif 84 | 85 | /* ANSI C specifies that errno is a macro, but on older systems it's more 86 | * likely to be a plain int variable. And not all versions of errno.h 87 | * bother to declare it, so we have to in order to be most portable. Thus: 88 | */ 89 | #ifndef errno 90 | extern int errno; 91 | #endif 92 | 93 | 94 | LOCAL(void) 95 | select_file_name (char * fname) 96 | { 97 | FILE * tfile; 98 | 99 | /* Keep generating file names till we find one that's not in use */ 100 | for (;;) { 101 | next_file_num++; /* advance counter */ 102 | sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); 103 | if ((tfile = fopen(fname, READ_BINARY)) == NULL) { 104 | /* fopen could have failed for a reason other than the file not 105 | * being there; for example, file there but unreadable. 106 | * If isn't available, then we cannot test the cause. 107 | */ 108 | #ifdef ENOENT 109 | if (errno != ENOENT) 110 | continue; 111 | #endif 112 | break; 113 | } 114 | fclose(tfile); /* oops, it's there; close tfile & try again */ 115 | } 116 | } 117 | 118 | #else /* ! NO_MKTEMP */ 119 | 120 | /* Note that mktemp() requires the initial filename to end in six X's */ 121 | #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ 122 | #define TEMP_FILE_NAME "%sJPG%dXXXXXX" 123 | #endif 124 | 125 | LOCAL(void) 126 | select_file_name (char * fname) 127 | { 128 | next_file_num++; /* advance counter */ 129 | sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); 130 | mktemp(fname); /* make sure file name is unique */ 131 | /* mktemp replaces the trailing XXXXXX with a unique string of characters */ 132 | } 133 | 134 | #endif /* NO_MKTEMP */ 135 | 136 | 137 | /* 138 | * Memory allocation and freeing are controlled by the regular library 139 | * routines malloc() and free(). 140 | */ 141 | 142 | GLOBAL(void *) 143 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) 144 | { 145 | return (void *) malloc(sizeofobject); 146 | } 147 | 148 | GLOBAL(void) 149 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) 150 | { 151 | free(object); 152 | } 153 | 154 | 155 | /* 156 | * "Large" objects are treated the same as "small" ones. 157 | * NB: although we include FAR keywords in the routine declarations, 158 | * this file won't actually work in 80x86 small/medium model; at least, 159 | * you probably won't be able to process useful-size images in only 64KB. 160 | */ 161 | 162 | GLOBAL(void FAR *) 163 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) 164 | { 165 | return (void FAR *) malloc(sizeofobject); 166 | } 167 | 168 | GLOBAL(void) 169 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) 170 | { 171 | free(object); 172 | } 173 | 174 | 175 | /* 176 | * This routine computes the total memory space available for allocation. 177 | * It's impossible to do this in a portable way; our current solution is 178 | * to make the user tell us (with a default value set at compile time). 179 | * If you can actually get the available space, it's a good idea to subtract 180 | * a slop factor of 5% or so. 181 | */ 182 | 183 | #ifndef DEFAULT_MAX_MEM /* so can override from makefile */ 184 | #define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */ 185 | #endif 186 | 187 | GLOBAL(long) 188 | jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, 189 | long max_bytes_needed, long already_allocated) 190 | { 191 | return cinfo->mem->max_memory_to_use - already_allocated; 192 | } 193 | 194 | 195 | /* 196 | * Backing store (temporary file) management. 197 | * Backing store objects are only used when the value returned by 198 | * jpeg_mem_available is less than the total space needed. You can dispense 199 | * with these routines if you have plenty of virtual memory; see jmemnobs.c. 200 | */ 201 | 202 | 203 | METHODDEF(void) 204 | read_backing_store (j_common_ptr cinfo, backing_store_ptr info, 205 | void FAR * buffer_address, 206 | long file_offset, long byte_count) 207 | { 208 | if (fseek(info->temp_file, file_offset, SEEK_SET)) 209 | ERREXIT(cinfo, JERR_TFILE_SEEK); 210 | if (JFREAD(info->temp_file, buffer_address, byte_count) 211 | != (size_t) byte_count) 212 | ERREXIT(cinfo, JERR_TFILE_READ); 213 | } 214 | 215 | 216 | METHODDEF(void) 217 | write_backing_store (j_common_ptr cinfo, backing_store_ptr info, 218 | void FAR * buffer_address, 219 | long file_offset, long byte_count) 220 | { 221 | if (fseek(info->temp_file, file_offset, SEEK_SET)) 222 | ERREXIT(cinfo, JERR_TFILE_SEEK); 223 | if (JFWRITE(info->temp_file, buffer_address, byte_count) 224 | != (size_t) byte_count) 225 | ERREXIT(cinfo, JERR_TFILE_WRITE); 226 | } 227 | 228 | 229 | METHODDEF(void) 230 | close_backing_store (j_common_ptr cinfo, backing_store_ptr info) 231 | { 232 | fclose(info->temp_file); /* close the file */ 233 | unlink(info->temp_name); /* delete the file */ 234 | /* If your system doesn't have unlink(), use remove() instead. 235 | * remove() is the ANSI-standard name for this function, but if 236 | * your system was ANSI you'd be using jmemansi.c, right? 237 | */ 238 | TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); 239 | } 240 | 241 | 242 | /* 243 | * Initial opening of a backing-store object. 244 | */ 245 | 246 | GLOBAL(void) 247 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, 248 | long total_bytes_needed) 249 | { 250 | select_file_name(info->temp_name); 251 | if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL) 252 | ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); 253 | info->read_backing_store = read_backing_store; 254 | info->write_backing_store = write_backing_store; 255 | info->close_backing_store = close_backing_store; 256 | TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); 257 | } 258 | 259 | 260 | /* 261 | * These routines take care of any system-dependent initialization and 262 | * cleanup required. 263 | */ 264 | 265 | GLOBAL(long) 266 | jpeg_mem_init (j_common_ptr cinfo) 267 | { 268 | next_file_num = 0; /* initialize temp file name generator */ 269 | return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ 270 | } 271 | 272 | GLOBAL(void) 273 | jpeg_mem_term (j_common_ptr cinfo) 274 | { 275 | /* no work */ 276 | } 277 | -------------------------------------------------------------------------------- /jmemnobs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jmemnobs.c 3 | * 4 | * Copyright (C) 1992-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file provides a really simple implementation of the system- 9 | * dependent portion of the JPEG memory manager. This implementation 10 | * assumes that no backing-store files are needed: all required space 11 | * can be obtained from malloc(). 12 | * This is very portable in the sense that it'll compile on almost anything, 13 | * but you'd better have lots of main memory (or virtual memory) if you want 14 | * to process big images. 15 | * Note that the max_memory_to_use option is ignored by this implementation. 16 | */ 17 | 18 | #define JPEG_INTERNALS 19 | #include "jinclude.h" 20 | #include "jpeglib.h" 21 | #include "jmemsys.h" /* import the system-dependent declarations */ 22 | 23 | #ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ 24 | extern void * malloc JPP((size_t size)); 25 | extern void free JPP((void *ptr)); 26 | #endif 27 | 28 | 29 | /* 30 | * Memory allocation and freeing are controlled by the regular library 31 | * routines malloc() and free(). 32 | */ 33 | 34 | GLOBAL(void *) 35 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) 36 | { 37 | return (void *) malloc(sizeofobject); 38 | } 39 | 40 | GLOBAL(void) 41 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) 42 | { 43 | free(object); 44 | } 45 | 46 | 47 | /* 48 | * "Large" objects are treated the same as "small" ones. 49 | * NB: although we include FAR keywords in the routine declarations, 50 | * this file won't actually work in 80x86 small/medium model; at least, 51 | * you probably won't be able to process useful-size images in only 64KB. 52 | */ 53 | 54 | GLOBAL(void FAR *) 55 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) 56 | { 57 | return (void FAR *) malloc(sizeofobject); 58 | } 59 | 60 | GLOBAL(void) 61 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) 62 | { 63 | free(object); 64 | } 65 | 66 | 67 | /* 68 | * This routine computes the total memory space available for allocation. 69 | * Here we always say, "we got all you want bud!" 70 | */ 71 | 72 | GLOBAL(long) 73 | jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, 74 | long max_bytes_needed, long already_allocated) 75 | { 76 | return max_bytes_needed; 77 | } 78 | 79 | 80 | /* 81 | * Backing store (temporary file) management. 82 | * Since jpeg_mem_available always promised the moon, 83 | * this should never be called and we can just error out. 84 | */ 85 | 86 | GLOBAL(void) 87 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, 88 | long total_bytes_needed) 89 | { 90 | ERREXIT(cinfo, JERR_NO_BACKING_STORE); 91 | } 92 | 93 | 94 | /* 95 | * These routines take care of any system-dependent initialization and 96 | * cleanup required. Here, there isn't any. 97 | */ 98 | 99 | GLOBAL(long) 100 | jpeg_mem_init (j_common_ptr cinfo) 101 | { 102 | return 0; /* just set max_memory_to_use to 0 */ 103 | } 104 | 105 | GLOBAL(void) 106 | jpeg_mem_term (j_common_ptr cinfo) 107 | { 108 | /* no work */ 109 | } 110 | -------------------------------------------------------------------------------- /jmemsys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jmemsys.h 3 | * 4 | * Copyright (C) 1992-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This include file defines the interface between the system-independent 9 | * and system-dependent portions of the JPEG memory manager. No other 10 | * modules need include it. (The system-independent portion is jmemmgr.c; 11 | * there are several different versions of the system-dependent portion.) 12 | * 13 | * This file works as-is for the system-dependent memory managers supplied 14 | * in the IJG distribution. You may need to modify it if you write a 15 | * custom memory manager. If system-dependent changes are needed in 16 | * this file, the best method is to #ifdef them based on a configuration 17 | * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR 18 | * and USE_MAC_MEMMGR. 19 | */ 20 | 21 | 22 | /* Short forms of external names for systems with brain-damaged linkers. */ 23 | 24 | #ifdef NEED_SHORT_EXTERNAL_NAMES 25 | #define jpeg_get_small jGetSmall 26 | #define jpeg_free_small jFreeSmall 27 | #define jpeg_get_large jGetLarge 28 | #define jpeg_free_large jFreeLarge 29 | #define jpeg_mem_available jMemAvail 30 | #define jpeg_open_backing_store jOpenBackStore 31 | #define jpeg_mem_init jMemInit 32 | #define jpeg_mem_term jMemTerm 33 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 34 | 35 | 36 | /* 37 | * These two functions are used to allocate and release small chunks of 38 | * memory. (Typically the total amount requested through jpeg_get_small is 39 | * no more than 20K or so; this will be requested in chunks of a few K each.) 40 | * Behavior should be the same as for the standard library functions malloc 41 | * and free; in particular, jpeg_get_small must return NULL on failure. 42 | * On most systems, these ARE malloc and free. jpeg_free_small is passed the 43 | * size of the object being freed, just in case it's needed. 44 | * On an 80x86 machine using small-data memory model, these manage near heap. 45 | */ 46 | 47 | EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject)); 48 | EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object, 49 | size_t sizeofobject)); 50 | 51 | /* 52 | * These two functions are used to allocate and release large chunks of 53 | * memory (up to the total free space designated by jpeg_mem_available). 54 | * The interface is the same as above, except that on an 80x86 machine, 55 | * far pointers are used. On most other machines these are identical to 56 | * the jpeg_get/free_small routines; but we keep them separate anyway, 57 | * in case a different allocation strategy is desirable for large chunks. 58 | */ 59 | 60 | EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo, 61 | size_t sizeofobject)); 62 | EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object, 63 | size_t sizeofobject)); 64 | 65 | /* 66 | * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may 67 | * be requested in a single call to jpeg_get_large (and jpeg_get_small for that 68 | * matter, but that case should never come into play). This macro is needed 69 | * to model the 64Kb-segment-size limit of far addressing on 80x86 machines. 70 | * On those machines, we expect that jconfig.h will provide a proper value. 71 | * On machines with 32-bit flat address spaces, any large constant may be used. 72 | * 73 | * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type 74 | * size_t and will be a multiple of sizeof(align_type). 75 | */ 76 | 77 | #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */ 78 | #define MAX_ALLOC_CHUNK 1000000000L 79 | #endif 80 | 81 | /* 82 | * This routine computes the total space still available for allocation by 83 | * jpeg_get_large. If more space than this is needed, backing store will be 84 | * used. NOTE: any memory already allocated must not be counted. 85 | * 86 | * There is a minimum space requirement, corresponding to the minimum 87 | * feasible buffer sizes; jmemmgr.c will request that much space even if 88 | * jpeg_mem_available returns zero. The maximum space needed, enough to hold 89 | * all working storage in memory, is also passed in case it is useful. 90 | * Finally, the total space already allocated is passed. If no better 91 | * method is available, cinfo->mem->max_memory_to_use - already_allocated 92 | * is often a suitable calculation. 93 | * 94 | * It is OK for jpeg_mem_available to underestimate the space available 95 | * (that'll just lead to more backing-store access than is really necessary). 96 | * However, an overestimate will lead to failure. Hence it's wise to subtract 97 | * a slop factor from the true available space. 5% should be enough. 98 | * 99 | * On machines with lots of virtual memory, any large constant may be returned. 100 | * Conversely, zero may be returned to always use the minimum amount of memory. 101 | */ 102 | 103 | EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo, 104 | long min_bytes_needed, 105 | long max_bytes_needed, 106 | long already_allocated)); 107 | 108 | 109 | /* 110 | * This structure holds whatever state is needed to access a single 111 | * backing-store object. The read/write/close method pointers are called 112 | * by jmemmgr.c to manipulate the backing-store object; all other fields 113 | * are private to the system-dependent backing store routines. 114 | */ 115 | 116 | #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */ 117 | 118 | 119 | #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */ 120 | 121 | typedef unsigned short XMSH; /* type of extended-memory handles */ 122 | typedef unsigned short EMSH; /* type of expanded-memory handles */ 123 | 124 | typedef union { 125 | short file_handle; /* DOS file handle if it's a temp file */ 126 | XMSH xms_handle; /* handle if it's a chunk of XMS */ 127 | EMSH ems_handle; /* handle if it's a chunk of EMS */ 128 | } handle_union; 129 | 130 | #endif /* USE_MSDOS_MEMMGR */ 131 | 132 | #ifdef USE_MAC_MEMMGR /* Mac-specific junk */ 133 | #include 134 | #endif /* USE_MAC_MEMMGR */ 135 | 136 | 137 | typedef struct backing_store_struct * backing_store_ptr; 138 | 139 | typedef struct backing_store_struct { 140 | /* Methods for reading/writing/closing this backing-store object */ 141 | JMETHOD(void, read_backing_store, (j_common_ptr cinfo, 142 | backing_store_ptr info, 143 | void FAR * buffer_address, 144 | long file_offset, long byte_count)); 145 | JMETHOD(void, write_backing_store, (j_common_ptr cinfo, 146 | backing_store_ptr info, 147 | void FAR * buffer_address, 148 | long file_offset, long byte_count)); 149 | JMETHOD(void, close_backing_store, (j_common_ptr cinfo, 150 | backing_store_ptr info)); 151 | 152 | /* Private fields for system-dependent backing-store management */ 153 | #ifdef USE_MSDOS_MEMMGR 154 | /* For the MS-DOS manager (jmemdos.c), we need: */ 155 | handle_union handle; /* reference to backing-store storage object */ 156 | char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ 157 | #else 158 | #ifdef USE_MAC_MEMMGR 159 | /* For the Mac manager (jmemmac.c), we need: */ 160 | short temp_file; /* file reference number to temp file */ 161 | FSSpec tempSpec; /* the FSSpec for the temp file */ 162 | char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ 163 | #else 164 | /* For a typical implementation with temp files, we need: */ 165 | FILE * temp_file; /* stdio reference to temp file */ 166 | char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */ 167 | #endif 168 | #endif 169 | } backing_store_info; 170 | 171 | 172 | /* 173 | * Initial opening of a backing-store object. This must fill in the 174 | * read/write/close pointers in the object. The read/write routines 175 | * may take an error exit if the specified maximum file size is exceeded. 176 | * (If jpeg_mem_available always returns a large value, this routine can 177 | * just take an error exit.) 178 | */ 179 | 180 | EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo, 181 | backing_store_ptr info, 182 | long total_bytes_needed)); 183 | 184 | 185 | /* 186 | * These routines take care of any system-dependent initialization and 187 | * cleanup required. jpeg_mem_init will be called before anything is 188 | * allocated (and, therefore, nothing in cinfo is of use except the error 189 | * manager pointer). It should return a suitable default value for 190 | * max_memory_to_use; this may subsequently be overridden by the surrounding 191 | * application. (Note that max_memory_to_use is only important if 192 | * jpeg_mem_available chooses to consult it ... no one else will.) 193 | * jpeg_mem_term may assume that all requested memory has been freed and that 194 | * all opened backing-store objects have been closed. 195 | */ 196 | 197 | EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo)); 198 | EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo)); 199 | -------------------------------------------------------------------------------- /jpegresize: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anknown/opencl-jpeg/3ee64b66ed12c5374aa87322691731e3969e5e40/jpegresize -------------------------------------------------------------------------------- /jutils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jutils.c 3 | * 4 | * Copyright (C) 1991-1996, Thomas G. Lane. 5 | * Modified 2009 by Guido Vollbeding. 6 | * This file is part of the Independent JPEG Group's software. 7 | * For conditions of distribution and use, see the accompanying README file. 8 | * 9 | * This file contains tables and miscellaneous utility routines needed 10 | * for both compression and decompression. 11 | * Note we prefix all global names with "j" to minimize conflicts with 12 | * a surrounding application. 13 | */ 14 | 15 | #define JPEG_INTERNALS 16 | #include "jinclude.h" 17 | #include "jpeglib.h" 18 | 19 | 20 | /* 21 | * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element 22 | * of a DCT block read in natural order (left to right, top to bottom). 23 | */ 24 | 25 | #if 0 /* This table is not actually needed in v6a */ 26 | 27 | const int jpeg_zigzag_order[DCTSIZE2] = { 28 | 0, 1, 5, 6, 14, 15, 27, 28, 29 | 2, 4, 7, 13, 16, 26, 29, 42, 30 | 3, 8, 12, 17, 25, 30, 41, 43, 31 | 9, 11, 18, 24, 31, 40, 44, 53, 32 | 10, 19, 23, 32, 39, 45, 52, 54, 33 | 20, 22, 33, 38, 46, 51, 55, 60, 34 | 21, 34, 37, 47, 50, 56, 59, 61, 35 | 35, 36, 48, 49, 57, 58, 62, 63 36 | }; 37 | 38 | #endif 39 | 40 | /* 41 | * jpeg_natural_order[i] is the natural-order position of the i'th element 42 | * of zigzag order. 43 | * 44 | * When reading corrupted data, the Huffman decoders could attempt 45 | * to reference an entry beyond the end of this array (if the decoded 46 | * zero run length reaches past the end of the block). To prevent 47 | * wild stores without adding an inner-loop test, we put some extra 48 | * "63"s after the real entries. This will cause the extra coefficient 49 | * to be stored in location 63 of the block, not somewhere random. 50 | * The worst case would be a run-length of 15, which means we need 16 51 | * fake entries. 52 | */ 53 | 54 | const int jpeg_natural_order[DCTSIZE2+16] = { 55 | 0, 1, 8, 16, 9, 2, 3, 10, 56 | 17, 24, 32, 25, 18, 11, 4, 5, 57 | 12, 19, 26, 33, 40, 48, 41, 34, 58 | 27, 20, 13, 6, 7, 14, 21, 28, 59 | 35, 42, 49, 56, 57, 50, 43, 36, 60 | 29, 22, 15, 23, 30, 37, 44, 51, 61 | 58, 59, 52, 45, 38, 31, 39, 46, 62 | 53, 60, 61, 54, 47, 55, 62, 63, 63 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 64 | 63, 63, 63, 63, 63, 63, 63, 63 65 | }; 66 | 67 | const int jpeg_natural_order7[7*7+16] = { 68 | 0, 1, 8, 16, 9, 2, 3, 10, 69 | 17, 24, 32, 25, 18, 11, 4, 5, 70 | 12, 19, 26, 33, 40, 48, 41, 34, 71 | 27, 20, 13, 6, 14, 21, 28, 35, 72 | 42, 49, 50, 43, 36, 29, 22, 30, 73 | 37, 44, 51, 52, 45, 38, 46, 53, 74 | 54, 75 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 76 | 63, 63, 63, 63, 63, 63, 63, 63 77 | }; 78 | 79 | const int jpeg_natural_order6[6*6+16] = { 80 | 0, 1, 8, 16, 9, 2, 3, 10, 81 | 17, 24, 32, 25, 18, 11, 4, 5, 82 | 12, 19, 26, 33, 40, 41, 34, 27, 83 | 20, 13, 21, 28, 35, 42, 43, 36, 84 | 29, 37, 44, 45, 85 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 86 | 63, 63, 63, 63, 63, 63, 63, 63 87 | }; 88 | 89 | const int jpeg_natural_order5[5*5+16] = { 90 | 0, 1, 8, 16, 9, 2, 3, 10, 91 | 17, 24, 32, 25, 18, 11, 4, 12, 92 | 19, 26, 33, 34, 27, 20, 28, 35, 93 | 36, 94 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 95 | 63, 63, 63, 63, 63, 63, 63, 63 96 | }; 97 | 98 | const int jpeg_natural_order4[4*4+16] = { 99 | 0, 1, 8, 16, 9, 2, 3, 10, 100 | 17, 24, 25, 18, 11, 19, 26, 27, 101 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 102 | 63, 63, 63, 63, 63, 63, 63, 63 103 | }; 104 | 105 | const int jpeg_natural_order3[3*3+16] = { 106 | 0, 1, 8, 16, 9, 2, 10, 17, 107 | 18, 108 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 109 | 63, 63, 63, 63, 63, 63, 63, 63 110 | }; 111 | 112 | const int jpeg_natural_order2[2*2+16] = { 113 | 0, 1, 8, 9, 114 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 115 | 63, 63, 63, 63, 63, 63, 63, 63 116 | }; 117 | 118 | 119 | /* 120 | * Arithmetic utilities 121 | */ 122 | 123 | GLOBAL(long) 124 | jdiv_round_up (long a, long b) 125 | /* Compute a/b rounded up to next integer, ie, ceil(a/b) */ 126 | /* Assumes a >= 0, b > 0 */ 127 | { 128 | return (a + b - 1L) / b; 129 | } 130 | 131 | 132 | GLOBAL(long) 133 | jround_up (long a, long b) 134 | /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ 135 | /* Assumes a >= 0, b > 0 */ 136 | { 137 | a += b - 1L; 138 | return a - (a % b); 139 | } 140 | 141 | 142 | /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays 143 | * and coefficient-block arrays. This won't work on 80x86 because the arrays 144 | * are FAR and we're assuming a small-pointer memory model. However, some 145 | * DOS compilers provide far-pointer versions of memcpy() and memset() even 146 | * in the small-model libraries. These will be used if USE_FMEM is defined. 147 | * Otherwise, the routines below do it the hard way. (The performance cost 148 | * is not all that great, because these routines aren't very heavily used.) 149 | */ 150 | 151 | #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */ 152 | #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size) 153 | #define FMEMZERO(target,size) MEMZERO(target,size) 154 | #else /* 80x86 case, define if we can */ 155 | #ifdef USE_FMEM 156 | #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size)) 157 | #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size)) 158 | #endif 159 | #endif 160 | 161 | 162 | GLOBAL(void) 163 | jcopy_sample_rows (JSAMPARRAY input_array, int source_row, 164 | JSAMPARRAY output_array, int dest_row, 165 | int num_rows, JDIMENSION num_cols) 166 | /* Copy some rows of samples from one place to another. 167 | * num_rows rows are copied from input_array[source_row++] 168 | * to output_array[dest_row++]; these areas may overlap for duplication. 169 | * The source and destination arrays must be at least as wide as num_cols. 170 | */ 171 | { 172 | register JSAMPROW inptr, outptr; 173 | #ifdef FMEMCOPY 174 | register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE)); 175 | #else 176 | register JDIMENSION count; 177 | #endif 178 | register int row; 179 | 180 | input_array += source_row; 181 | output_array += dest_row; 182 | 183 | for (row = num_rows; row > 0; row--) { 184 | inptr = *input_array++; 185 | outptr = *output_array++; 186 | #ifdef FMEMCOPY 187 | FMEMCOPY(outptr, inptr, count); 188 | #else 189 | for (count = num_cols; count > 0; count--) 190 | *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */ 191 | #endif 192 | } 193 | } 194 | 195 | 196 | GLOBAL(void) 197 | jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, 198 | JDIMENSION num_blocks) 199 | /* Copy a row of coefficient blocks from one place to another. */ 200 | { 201 | #ifdef FMEMCOPY 202 | FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))); 203 | #else 204 | register JCOEFPTR inptr, outptr; 205 | register long count; 206 | 207 | inptr = (JCOEFPTR) input_row; 208 | outptr = (JCOEFPTR) output_row; 209 | for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) { 210 | *outptr++ = *inptr++; 211 | } 212 | #endif 213 | } 214 | 215 | 216 | GLOBAL(void) 217 | jzero_far (void FAR * target, size_t bytestozero) 218 | /* Zero out a chunk of FAR memory. */ 219 | /* This might be sample-array data, block-array data, or alloc_large data. */ 220 | { 221 | #ifdef FMEMZERO 222 | FMEMZERO(target, bytestozero); 223 | #else 224 | register char FAR * ptr = (char FAR *) target; 225 | register size_t count; 226 | 227 | for (count = bytestozero; count > 0; count--) { 228 | *ptr++ = 0; 229 | } 230 | #endif 231 | } 232 | -------------------------------------------------------------------------------- /jversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jversion.h 3 | * 4 | * Copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains software version identification. 9 | */ 10 | 11 | 12 | #define JVERSION "8 10-Jan-2010" 13 | 14 | #define JCOPYRIGHT "Copyright (C) 2010, Thomas G. Lane, Guido Vollbeding" 15 | -------------------------------------------------------------------------------- /m4/ltsugar.m4: -------------------------------------------------------------------------------- 1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software 4 | # Foundation, Inc. 5 | # Written by Gary V. Vaughan, 2004 6 | # 7 | # This file is free software; the Free Software Foundation gives 8 | # unlimited permission to copy and/or distribute it, with or without 9 | # modifications, as long as this notice is preserved. 10 | 11 | # serial 6 ltsugar.m4 12 | 13 | # This is to help aclocal find these macros, as it can't see m4_define. 14 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) 15 | 16 | 17 | # lt_join(SEP, ARG1, [ARG2...]) 18 | # ----------------------------- 19 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their 20 | # associated separator. 21 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier 22 | # versions in m4sugar had bugs. 23 | m4_define([lt_join], 24 | [m4_if([$#], [1], [], 25 | [$#], [2], [[$2]], 26 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) 27 | m4_define([_lt_join], 28 | [m4_if([$#$2], [2], [], 29 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) 30 | 31 | 32 | # lt_car(LIST) 33 | # lt_cdr(LIST) 34 | # ------------ 35 | # Manipulate m4 lists. 36 | # These macros are necessary as long as will still need to support 37 | # Autoconf-2.59, which quotes differently. 38 | m4_define([lt_car], [[$1]]) 39 | m4_define([lt_cdr], 40 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], 41 | [$#], 1, [], 42 | [m4_dquote(m4_shift($@))])]) 43 | m4_define([lt_unquote], $1) 44 | 45 | 46 | # lt_append(MACRO-NAME, STRING, [SEPARATOR]) 47 | # ------------------------------------------ 48 | # Redefine MACRO-NAME to hold its former content plus 'SEPARATOR''STRING'. 49 | # Note that neither SEPARATOR nor STRING are expanded; they are appended 50 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). 51 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different 52 | # than defined and empty). 53 | # 54 | # This macro is needed until we can rely on Autoconf 2.62, since earlier 55 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. 56 | m4_define([lt_append], 57 | [m4_define([$1], 58 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) 59 | 60 | 61 | 62 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) 63 | # ---------------------------------------------------------- 64 | # Produce a SEP delimited list of all paired combinations of elements of 65 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list 66 | # has the form PREFIXmINFIXSUFFIXn. 67 | # Needed until we can rely on m4_combine added in Autoconf 2.62. 68 | m4_define([lt_combine], 69 | [m4_if(m4_eval([$# > 3]), [1], 70 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl 71 | [[m4_foreach([_Lt_prefix], [$2], 72 | [m4_foreach([_Lt_suffix], 73 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, 74 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) 75 | 76 | 77 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) 78 | # ----------------------------------------------------------------------- 79 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited 80 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. 81 | m4_define([lt_if_append_uniq], 82 | [m4_ifdef([$1], 83 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], 84 | [lt_append([$1], [$2], [$3])$4], 85 | [$5])], 86 | [lt_append([$1], [$2], [$3])$4])]) 87 | 88 | 89 | # lt_dict_add(DICT, KEY, VALUE) 90 | # ----------------------------- 91 | m4_define([lt_dict_add], 92 | [m4_define([$1($2)], [$3])]) 93 | 94 | 95 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) 96 | # -------------------------------------------- 97 | m4_define([lt_dict_add_subkey], 98 | [m4_define([$1($2:$3)], [$4])]) 99 | 100 | 101 | # lt_dict_fetch(DICT, KEY, [SUBKEY]) 102 | # ---------------------------------- 103 | m4_define([lt_dict_fetch], 104 | [m4_ifval([$3], 105 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), 106 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) 107 | 108 | 109 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) 110 | # ----------------------------------------------------------------- 111 | m4_define([lt_if_dict_fetch], 112 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], 113 | [$5], 114 | [$6])]) 115 | 116 | 117 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) 118 | # -------------------------------------------------------------- 119 | m4_define([lt_dict_filter], 120 | [m4_if([$5], [], [], 121 | [lt_join(m4_quote(m4_default([$4], [[, ]])), 122 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), 123 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl 124 | ]) 125 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 4179 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.6]) 16 | m4_define([LT_PACKAGE_REVISION], [2.4.6]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.6' 20 | macro_revision='2.4.6' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /m4/lt~obsolete.m4: -------------------------------------------------------------------------------- 1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004-2005, 2007, 2009, 2011-2015 Free Software 4 | # Foundation, Inc. 5 | # Written by Scott James Remnant, 2004. 6 | # 7 | # This file is free software; the Free Software Foundation gives 8 | # unlimited permission to copy and/or distribute it, with or without 9 | # modifications, as long as this notice is preserved. 10 | 11 | # serial 5 lt~obsolete.m4 12 | 13 | # These exist entirely to fool aclocal when bootstrapping libtool. 14 | # 15 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN), 16 | # which have later been changed to m4_define as they aren't part of the 17 | # exported API, or moved to Autoconf or Automake where they belong. 18 | # 19 | # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN 20 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us 21 | # using a macro with the same name in our local m4/libtool.m4 it'll 22 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define 23 | # and doesn't know about Autoconf macros at all.) 24 | # 25 | # So we provide this file, which has a silly filename so it's always 26 | # included after everything else. This provides aclocal with the 27 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything 28 | # because those macros already exist, or will be overwritten later. 29 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 30 | # 31 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. 32 | # Yes, that means every name once taken will need to remain here until 33 | # we give up compatibility with versions before 1.7, at which point 34 | # we need to keep only those names which we still refer to. 35 | 36 | # This is to help aclocal find these macros, as it can't see m4_define. 37 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) 38 | 39 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) 40 | m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) 41 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) 42 | m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) 43 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) 44 | m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) 45 | m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) 46 | m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) 47 | m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) 48 | m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) 49 | m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) 50 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) 51 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) 52 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) 53 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) 54 | m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) 55 | m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) 56 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) 57 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) 58 | m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) 59 | m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) 60 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) 61 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) 62 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) 63 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) 64 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) 65 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) 66 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) 67 | m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) 68 | m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) 69 | m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) 70 | m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) 71 | m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) 72 | m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) 73 | m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) 74 | m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) 75 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) 76 | m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) 77 | m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) 78 | m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) 79 | m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) 80 | m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) 81 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) 82 | m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) 83 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) 84 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) 85 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) 86 | m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) 87 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) 88 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) 89 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) 90 | m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) 91 | m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) 92 | m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) 93 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) 94 | m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) 95 | m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) 96 | m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) 97 | m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) 98 | m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) 99 | m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) 100 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jpegtran.c 3 | */ 4 | 5 | //#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ 6 | //#include "ocl_transupp.h" /* Support routines for jpegtran */ 7 | #include "jpeglib.h" 8 | #include 9 | //#include 10 | #include "jinclude.h" 11 | //#include 12 | #include "jversion.h" 13 | #include "jpegint.h" 14 | //#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ 15 | //#ifdef __MWERKS__ 16 | //#include /* Metrowerks needs this */ 17 | //#include /* ... and this */ 18 | //#endif 19 | //#ifdef THINK_C 20 | //#include /* Think declares it here */ 21 | //#endif 22 | //#endif 23 | //#include 24 | //#include 25 | //#include 26 | //#include 27 | //#include 28 | /* 29 | * Argument-parsing code. 30 | * The switch parser is designed to be useful with DOS-style command line 31 | * syntax, ie, intermixed switches and file names, where only the switches 32 | * to the left of a given file name affect processing of that file. 33 | * The main program in this file doesn't actually use this capability... 34 | */ 35 | //__thread const char * progname; /* program name for error messages */ 36 | //__thread char * outfilename; /* for -outfile switch */ 37 | //__thread char * scaleoption; /* -scale switch */ 38 | //__thread JCOPY_OPTION copyoption; /* -copy switch */ 39 | int main(int argc, char **argv) 40 | { 41 | /* pub_env should be global variable */ 42 | ocl_pub_env_struct* pub_env; 43 | pub_env = (ocl_pub_env_struct*)malloc(sizeof(ocl_pub_env_struct)); 44 | ocl_pub_env_init(pub_env); 45 | /* pri_env should be thread own */ 46 | ocl_pri_env_struct* pri_env; 47 | pri_env = (ocl_pri_env_struct*)malloc(sizeof(ocl_pri_env_struct)); 48 | ocl_pri_env_init(pub_env, pri_env); 49 | 50 | FILE* fp; 51 | unsigned char* srcdata; 52 | unsigned char* dstdata = NULL; 53 | int outsize,insize; 54 | fp = fopen("./input_images/448_298_90_-256126272.jpg","r"); 55 | if (fp == NULL) 56 | { 57 | printf("Couldn't open src_image_file\n"); 58 | exit(1); 59 | } 60 | fseek(fp,0,SEEK_END); 61 | insize = ftell(fp); 62 | srcdata = (unsigned char*)malloc(insize+1); 63 | /* should malloc dstdata as big as enough */ 64 | dstdata = (unsigned char*)malloc(2*insize+1); 65 | fseek(fp,0,SEEK_SET); 66 | fread(srcdata, insize+1, 1, fp); 67 | outsize = resize_pic(srcdata,insize,dstdata,500,300,90,pub_env,pri_env); 68 | printf("Outsize = %d\n",outsize); 69 | if (dstdata == NULL) 70 | exit(1); 71 | fclose(fp); 72 | fp = fopen("./dst_images/test.jpg","w"); 73 | fwrite(dstdata,outsize,1,fp); 74 | fclose(fp); 75 | /* srcdata/dstdata/pri_env/pub_env should be free by application */ 76 | free(srcdata); 77 | free(dstdata); 78 | ocl_pri_env_release(pri_env); 79 | free(pri_env); 80 | ocl_pub_env_release(pub_env); 81 | free(pub_env); 82 | 83 | return 0; 84 | } 85 | 86 | 87 | -------------------------------------------------------------------------------- /missing: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Common wrapper for a few potentially missing GNU programs. 3 | 4 | scriptversion=2013-10-28.13; # UTC 5 | 6 | # Copyright (C) 1996-2014 Free Software Foundation, Inc. 7 | # Originally written by Fran,cois Pinard , 1996. 8 | 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | if test $# -eq 0; then 28 | echo 1>&2 "Try '$0 --help' for more information" 29 | exit 1 30 | fi 31 | 32 | case $1 in 33 | 34 | --is-lightweight) 35 | # Used by our autoconf macros to check whether the available missing 36 | # script is modern enough. 37 | exit 0 38 | ;; 39 | 40 | --run) 41 | # Back-compat with the calling convention used by older automake. 42 | shift 43 | ;; 44 | 45 | -h|--h|--he|--hel|--help) 46 | echo "\ 47 | $0 [OPTION]... PROGRAM [ARGUMENT]... 48 | 49 | Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due 50 | to PROGRAM being missing or too old. 51 | 52 | Options: 53 | -h, --help display this help and exit 54 | -v, --version output version information and exit 55 | 56 | Supported PROGRAM values: 57 | aclocal autoconf autoheader autom4te automake makeinfo 58 | bison yacc flex lex help2man 59 | 60 | Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and 61 | 'g' are ignored when checking the name. 62 | 63 | Send bug reports to ." 64 | exit $? 65 | ;; 66 | 67 | -v|--v|--ve|--ver|--vers|--versi|--versio|--version) 68 | echo "missing $scriptversion (GNU Automake)" 69 | exit $? 70 | ;; 71 | 72 | -*) 73 | echo 1>&2 "$0: unknown '$1' option" 74 | echo 1>&2 "Try '$0 --help' for more information" 75 | exit 1 76 | ;; 77 | 78 | esac 79 | 80 | # Run the given program, remember its exit status. 81 | "$@"; st=$? 82 | 83 | # If it succeeded, we are done. 84 | test $st -eq 0 && exit 0 85 | 86 | # Also exit now if we it failed (or wasn't found), and '--version' was 87 | # passed; such an option is passed most likely to detect whether the 88 | # program is present and works. 89 | case $2 in --version|--help) exit $st;; esac 90 | 91 | # Exit code 63 means version mismatch. This often happens when the user 92 | # tries to use an ancient version of a tool on a file that requires a 93 | # minimum version. 94 | if test $st -eq 63; then 95 | msg="probably too old" 96 | elif test $st -eq 127; then 97 | # Program was missing. 98 | msg="missing on your system" 99 | else 100 | # Program was found and executed, but failed. Give up. 101 | exit $st 102 | fi 103 | 104 | perl_URL=http://www.perl.org/ 105 | flex_URL=http://flex.sourceforge.net/ 106 | gnu_software_URL=http://www.gnu.org/software 107 | 108 | program_details () 109 | { 110 | case $1 in 111 | aclocal|automake) 112 | echo "The '$1' program is part of the GNU Automake package:" 113 | echo "<$gnu_software_URL/automake>" 114 | echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" 115 | echo "<$gnu_software_URL/autoconf>" 116 | echo "<$gnu_software_URL/m4/>" 117 | echo "<$perl_URL>" 118 | ;; 119 | autoconf|autom4te|autoheader) 120 | echo "The '$1' program is part of the GNU Autoconf package:" 121 | echo "<$gnu_software_URL/autoconf/>" 122 | echo "It also requires GNU m4 and Perl in order to run:" 123 | echo "<$gnu_software_URL/m4/>" 124 | echo "<$perl_URL>" 125 | ;; 126 | esac 127 | } 128 | 129 | give_advice () 130 | { 131 | # Normalize program name to check for. 132 | normalized_program=`echo "$1" | sed ' 133 | s/^gnu-//; t 134 | s/^gnu//; t 135 | s/^g//; t'` 136 | 137 | printf '%s\n' "'$1' is $msg." 138 | 139 | configure_deps="'configure.ac' or m4 files included by 'configure.ac'" 140 | case $normalized_program in 141 | autoconf*) 142 | echo "You should only need it if you modified 'configure.ac'," 143 | echo "or m4 files included by it." 144 | program_details 'autoconf' 145 | ;; 146 | autoheader*) 147 | echo "You should only need it if you modified 'acconfig.h' or" 148 | echo "$configure_deps." 149 | program_details 'autoheader' 150 | ;; 151 | automake*) 152 | echo "You should only need it if you modified 'Makefile.am' or" 153 | echo "$configure_deps." 154 | program_details 'automake' 155 | ;; 156 | aclocal*) 157 | echo "You should only need it if you modified 'acinclude.m4' or" 158 | echo "$configure_deps." 159 | program_details 'aclocal' 160 | ;; 161 | autom4te*) 162 | echo "You might have modified some maintainer files that require" 163 | echo "the 'autom4te' program to be rebuilt." 164 | program_details 'autom4te' 165 | ;; 166 | bison*|yacc*) 167 | echo "You should only need it if you modified a '.y' file." 168 | echo "You may want to install the GNU Bison package:" 169 | echo "<$gnu_software_URL/bison/>" 170 | ;; 171 | lex*|flex*) 172 | echo "You should only need it if you modified a '.l' file." 173 | echo "You may want to install the Fast Lexical Analyzer package:" 174 | echo "<$flex_URL>" 175 | ;; 176 | help2man*) 177 | echo "You should only need it if you modified a dependency" \ 178 | "of a man page." 179 | echo "You may want to install the GNU Help2man package:" 180 | echo "<$gnu_software_URL/help2man/>" 181 | ;; 182 | makeinfo*) 183 | echo "You should only need it if you modified a '.texi' file, or" 184 | echo "any other file indirectly affecting the aspect of the manual." 185 | echo "You might want to install the Texinfo package:" 186 | echo "<$gnu_software_URL/texinfo/>" 187 | echo "The spurious makeinfo call might also be the consequence of" 188 | echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" 189 | echo "want to install GNU make:" 190 | echo "<$gnu_software_URL/make/>" 191 | ;; 192 | *) 193 | echo "You might have modified some files without having the proper" 194 | echo "tools for further handling them. Check the 'README' file, it" 195 | echo "often tells you about the needed prerequisites for installing" 196 | echo "this package. You may also peek at any GNU archive site, in" 197 | echo "case some other package contains this missing '$1' program." 198 | ;; 199 | esac 200 | } 201 | 202 | give_advice "$1" | sed -e '1s/^/WARNING: /' \ 203 | -e '2,$s/^/ /' >&2 204 | 205 | # Propagate the correct exit status (expected to be 127 for a program 206 | # not found, 63 for a program that failed due to version mismatch). 207 | exit $st 208 | 209 | # Local variables: 210 | # eval: (add-hook 'write-file-hooks 'time-stamp) 211 | # time-stamp-start: "scriptversion=" 212 | # time-stamp-format: "%:y-%02m-%02d.%02H" 213 | # time-stamp-time-zone: "UTC" 214 | # time-stamp-end: "; # UTC" 215 | # End: 216 | -------------------------------------------------------------------------------- /rdcolmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rdcolmap.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file implements djpeg's "-map file" switch. It reads a source image 9 | * and constructs a colormap to be supplied to the JPEG decompressor. 10 | * 11 | * Currently, these file formats are supported for the map file: 12 | * GIF: the contents of the GIF's global colormap are used. 13 | * PPM (either text or raw flavor): the entire file is read and 14 | * each unique pixel value is entered in the map. 15 | * Note that reading a large PPM file will be horrendously slow. 16 | * Typically, a PPM-format map file should contain just one pixel 17 | * of each desired color. Such a file can be extracted from an 18 | * ordinary image PPM file with ppmtomap(1). 19 | * 20 | * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not 21 | * currently implemented. 22 | */ 23 | 24 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ 25 | 26 | #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ 27 | 28 | /* Portions of this code are based on the PBMPLUS library, which is: 29 | ** 30 | ** Copyright (C) 1988 by Jef Poskanzer. 31 | ** 32 | ** Permission to use, copy, modify, and distribute this software and its 33 | ** documentation for any purpose and without fee is hereby granted, provided 34 | ** that the above copyright notice appear in all copies and that both that 35 | ** copyright notice and this permission notice appear in supporting 36 | ** documentation. This software is provided "as is" without express or 37 | ** implied warranty. 38 | */ 39 | 40 | 41 | /* 42 | * Add a (potentially) new color to the color map. 43 | */ 44 | 45 | LOCAL(void) 46 | add_map_entry (j_decompress_ptr cinfo, int R, int G, int B) 47 | { 48 | JSAMPROW colormap0 = cinfo->colormap[0]; 49 | JSAMPROW colormap1 = cinfo->colormap[1]; 50 | JSAMPROW colormap2 = cinfo->colormap[2]; 51 | int ncolors = cinfo->actual_number_of_colors; 52 | int index; 53 | 54 | /* Check for duplicate color. */ 55 | for (index = 0; index < ncolors; index++) { 56 | if (GETJSAMPLE(colormap0[index]) == R && 57 | GETJSAMPLE(colormap1[index]) == G && 58 | GETJSAMPLE(colormap2[index]) == B) 59 | return; /* color is already in map */ 60 | } 61 | 62 | /* Check for map overflow. */ 63 | if (ncolors >= (MAXJSAMPLE+1)) 64 | ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1)); 65 | 66 | /* OK, add color to map. */ 67 | colormap0[ncolors] = (JSAMPLE) R; 68 | colormap1[ncolors] = (JSAMPLE) G; 69 | colormap2[ncolors] = (JSAMPLE) B; 70 | cinfo->actual_number_of_colors++; 71 | } 72 | 73 | 74 | /* 75 | * Extract color map from a GIF file. 76 | */ 77 | 78 | LOCAL(void) 79 | read_gif_map (j_decompress_ptr cinfo, FILE * infile) 80 | { 81 | int header[13]; 82 | int i, colormaplen; 83 | int R, G, B; 84 | 85 | /* Initial 'G' has already been read by read_color_map */ 86 | /* Read the rest of the GIF header and logical screen descriptor */ 87 | for (i = 1; i < 13; i++) { 88 | if ((header[i] = getc(infile)) == EOF) 89 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 90 | } 91 | 92 | /* Verify GIF Header */ 93 | if (header[1] != 'I' || header[2] != 'F') 94 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 95 | 96 | /* There must be a global color map. */ 97 | if ((header[10] & 0x80) == 0) 98 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 99 | 100 | /* OK, fetch it. */ 101 | colormaplen = 2 << (header[10] & 0x07); 102 | 103 | for (i = 0; i < colormaplen; i++) { 104 | R = getc(infile); 105 | G = getc(infile); 106 | B = getc(infile); 107 | if (R == EOF || G == EOF || B == EOF) 108 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 109 | add_map_entry(cinfo, 110 | R << (BITS_IN_JSAMPLE-8), 111 | G << (BITS_IN_JSAMPLE-8), 112 | B << (BITS_IN_JSAMPLE-8)); 113 | } 114 | } 115 | 116 | 117 | /* Support routines for reading PPM */ 118 | 119 | 120 | LOCAL(int) 121 | pbm_getc (FILE * infile) 122 | /* Read next char, skipping over any comments */ 123 | /* A comment/newline sequence is returned as a newline */ 124 | { 125 | register int ch; 126 | 127 | ch = getc(infile); 128 | if (ch == '#') { 129 | do { 130 | ch = getc(infile); 131 | } while (ch != '\n' && ch != EOF); 132 | } 133 | return ch; 134 | } 135 | 136 | 137 | LOCAL(unsigned int) 138 | read_pbm_integer (j_decompress_ptr cinfo, FILE * infile) 139 | /* Read an unsigned decimal integer from the PPM file */ 140 | /* Swallows one trailing character after the integer */ 141 | /* Note that on a 16-bit-int machine, only values up to 64k can be read. */ 142 | /* This should not be a problem in practice. */ 143 | { 144 | register int ch; 145 | register unsigned int val; 146 | 147 | /* Skip any leading whitespace */ 148 | do { 149 | ch = pbm_getc(infile); 150 | if (ch == EOF) 151 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 152 | } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); 153 | 154 | if (ch < '0' || ch > '9') 155 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 156 | 157 | val = ch - '0'; 158 | while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { 159 | val *= 10; 160 | val += ch - '0'; 161 | } 162 | return val; 163 | } 164 | 165 | 166 | /* 167 | * Extract color map from a PPM file. 168 | */ 169 | 170 | LOCAL(void) 171 | read_ppm_map (j_decompress_ptr cinfo, FILE * infile) 172 | { 173 | int c; 174 | unsigned int w, h, maxval, row, col; 175 | int R, G, B; 176 | 177 | /* Initial 'P' has already been read by read_color_map */ 178 | c = getc(infile); /* save format discriminator for a sec */ 179 | 180 | /* while we fetch the remaining header info */ 181 | w = read_pbm_integer(cinfo, infile); 182 | h = read_pbm_integer(cinfo, infile); 183 | maxval = read_pbm_integer(cinfo, infile); 184 | 185 | if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ 186 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 187 | 188 | /* For now, we don't support rescaling from an unusual maxval. */ 189 | if (maxval != (unsigned int) MAXJSAMPLE) 190 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 191 | 192 | switch (c) { 193 | case '3': /* it's a text-format PPM file */ 194 | for (row = 0; row < h; row++) { 195 | for (col = 0; col < w; col++) { 196 | R = read_pbm_integer(cinfo, infile); 197 | G = read_pbm_integer(cinfo, infile); 198 | B = read_pbm_integer(cinfo, infile); 199 | add_map_entry(cinfo, R, G, B); 200 | } 201 | } 202 | break; 203 | 204 | case '6': /* it's a raw-format PPM file */ 205 | for (row = 0; row < h; row++) { 206 | for (col = 0; col < w; col++) { 207 | R = getc(infile); 208 | G = getc(infile); 209 | B = getc(infile); 210 | if (R == EOF || G == EOF || B == EOF) 211 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 212 | add_map_entry(cinfo, R, G, B); 213 | } 214 | } 215 | break; 216 | 217 | default: 218 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 219 | break; 220 | } 221 | } 222 | 223 | 224 | /* 225 | * Main entry point from djpeg.c. 226 | * Input: opened input file (from file name argument on command line). 227 | * Output: colormap and actual_number_of_colors fields are set in cinfo. 228 | */ 229 | 230 | GLOBAL(void) 231 | read_color_map (j_decompress_ptr cinfo, FILE * infile) 232 | { 233 | /* Allocate space for a color map of maximum supported size. */ 234 | cinfo->colormap = (*cinfo->mem->alloc_sarray) 235 | ((j_common_ptr) cinfo, JPOOL_IMAGE, 236 | (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3); 237 | cinfo->actual_number_of_colors = 0; /* initialize map to empty */ 238 | 239 | /* Read first byte to determine file format */ 240 | switch (getc(infile)) { 241 | case 'G': 242 | read_gif_map(cinfo, infile); 243 | break; 244 | case 'P': 245 | read_ppm_map(cinfo, infile); 246 | break; 247 | default: 248 | ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 249 | break; 250 | } 251 | } 252 | 253 | #endif /* QUANT_2PASS_SUPPORTED */ 254 | -------------------------------------------------------------------------------- /rdgif.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rdgif.c 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains routines to read input images in GIF format. 9 | * 10 | ***************************************************************************** 11 | * NOTE: to avoid entanglements with Unisys' patent on LZW compression, * 12 | * the ability to read GIF files has been removed from the IJG distribution. * 13 | * Sorry about that. * 14 | ***************************************************************************** 15 | * 16 | * We are required to state that 17 | * "The Graphics Interchange Format(c) is the Copyright property of 18 | * CompuServe Incorporated. GIF(sm) is a Service Mark property of 19 | * CompuServe Incorporated." 20 | */ 21 | 22 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ 23 | 24 | #ifdef GIF_SUPPORTED 25 | 26 | /* 27 | * The module selection routine for GIF format input. 28 | */ 29 | 30 | GLOBAL(cjpeg_source_ptr) 31 | jinit_read_gif (j_compress_ptr cinfo) 32 | { 33 | fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n"); 34 | exit(EXIT_FAILURE); 35 | return NULL; /* keep compiler happy */ 36 | } 37 | 38 | #endif /* GIF_SUPPORTED */ 39 | -------------------------------------------------------------------------------- /rdjpgcom.1: -------------------------------------------------------------------------------- 1 | .TH RDJPGCOM 1 "02 April 2009" 2 | .SH NAME 3 | rdjpgcom \- display text comments from a JPEG file 4 | .SH SYNOPSIS 5 | .B rdjpgcom 6 | [ 7 | .B \-raw 8 | ] 9 | [ 10 | .B \-verbose 11 | ] 12 | [ 13 | .I filename 14 | ] 15 | .LP 16 | .SH DESCRIPTION 17 | .LP 18 | .B rdjpgcom 19 | reads the named JPEG/JFIF file, or the standard input if no file is named, 20 | and prints any text comments found in the file on the standard output. 21 | .PP 22 | The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. 23 | Although the standard doesn't actually define what COM blocks are for, they 24 | are widely used to hold user-supplied text strings. This lets you add 25 | annotations, titles, index terms, etc to your JPEG files, and later retrieve 26 | them as text. COM blocks do not interfere with the image stored in the JPEG 27 | file. The maximum size of a COM block is 64K, but you can have as many of 28 | them as you like in one JPEG file. 29 | .SH OPTIONS 30 | .TP 31 | .B \-raw 32 | Normally 33 | .B rdjpgcom 34 | escapes non-printable characters in comments, for security reasons. 35 | This option avoids that. 36 | .PP 37 | .B \-verbose 38 | Causes 39 | .B rdjpgcom 40 | to also display the JPEG image dimensions. 41 | .PP 42 | Switch names may be abbreviated, and are not case sensitive. 43 | .SH HINTS 44 | .B rdjpgcom 45 | does not depend on the IJG JPEG library. Its source code is intended as an 46 | illustration of the minimum amount of code required to parse a JPEG file 47 | header correctly. 48 | .PP 49 | In 50 | .B \-verbose 51 | mode, 52 | .B rdjpgcom 53 | will also attempt to print the contents of any "APP12" markers as text. 54 | Some digital cameras produce APP12 markers containing useful textual 55 | information. If you like, you can modify the source code to print 56 | other APPn marker types as well. 57 | .SH SEE ALSO 58 | .BR cjpeg (1), 59 | .BR djpeg (1), 60 | .BR jpegtran (1), 61 | .BR wrjpgcom (1) 62 | .SH AUTHOR 63 | Independent JPEG Group 64 | -------------------------------------------------------------------------------- /stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for jconfig.h 2 | -------------------------------------------------------------------------------- /testimg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anknown/opencl-jpeg/3ee64b66ed12c5374aa87322691731e3969e5e40/testimg.jpg -------------------------------------------------------------------------------- /testimgp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anknown/opencl-jpeg/3ee64b66ed12c5374aa87322691731e3969e5e40/testimgp.jpg -------------------------------------------------------------------------------- /testorig.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anknown/opencl-jpeg/3ee64b66ed12c5374aa87322691731e3969e5e40/testorig.jpg -------------------------------------------------------------------------------- /testprog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anknown/opencl-jpeg/3ee64b66ed12c5374aa87322691731e3969e5e40/testprog.jpg -------------------------------------------------------------------------------- /wrjpgcom.1: -------------------------------------------------------------------------------- 1 | .TH WRJPGCOM 1 "15 June 1995" 2 | .SH NAME 3 | wrjpgcom \- insert text comments into a JPEG file 4 | .SH SYNOPSIS 5 | .B wrjpgcom 6 | [ 7 | .B \-replace 8 | ] 9 | [ 10 | .BI \-comment " text" 11 | ] 12 | [ 13 | .BI \-cfile " name" 14 | ] 15 | [ 16 | .I filename 17 | ] 18 | .LP 19 | .SH DESCRIPTION 20 | .LP 21 | .B wrjpgcom 22 | reads the named JPEG/JFIF file, or the standard input if no file is named, 23 | and generates a new JPEG/JFIF file on standard output. A comment block is 24 | added to the file. 25 | .PP 26 | The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. 27 | Although the standard doesn't actually define what COM blocks are for, they 28 | are widely used to hold user-supplied text strings. This lets you add 29 | annotations, titles, index terms, etc to your JPEG files, and later retrieve 30 | them as text. COM blocks do not interfere with the image stored in the JPEG 31 | file. The maximum size of a COM block is 64K, but you can have as many of 32 | them as you like in one JPEG file. 33 | .PP 34 | .B wrjpgcom 35 | adds a COM block, containing text you provide, to a JPEG file. 36 | Ordinarily, the COM block is added after any existing COM blocks; but you 37 | can delete the old COM blocks if you wish. 38 | .SH OPTIONS 39 | Switch names may be abbreviated, and are not case sensitive. 40 | .TP 41 | .B \-replace 42 | Delete any existing COM blocks from the file. 43 | .TP 44 | .BI \-comment " text" 45 | Supply text for new COM block on command line. 46 | .TP 47 | .BI \-cfile " name" 48 | Read text for new COM block from named file. 49 | .PP 50 | If you have only one line of comment text to add, you can provide it on the 51 | command line with 52 | .BR \-comment . 53 | The comment text must be surrounded with quotes so that it is treated as a 54 | single argument. Longer comments can be read from a text file. 55 | .PP 56 | If you give neither 57 | .B \-comment 58 | nor 59 | .BR \-cfile , 60 | then 61 | .B wrjpgcom 62 | will read the comment text from standard input. (In this case an input image 63 | file name MUST be supplied, so that the source JPEG file comes from somewhere 64 | else.) You can enter multiple lines, up to 64KB worth. Type an end-of-file 65 | indicator (usually control-D) to terminate the comment text entry. 66 | .PP 67 | .B wrjpgcom 68 | will not add a COM block if the provided comment string is empty. Therefore 69 | \fB\-replace \-comment ""\fR can be used to delete all COM blocks from a file. 70 | .SH EXAMPLES 71 | .LP 72 | Add a short comment to in.jpg, producing out.jpg: 73 | .IP 74 | .B wrjpgcom \-c 75 | \fI"View of my back yard" in.jpg 76 | .B > 77 | .I out.jpg 78 | .PP 79 | Attach a long comment previously stored in comment.txt: 80 | .IP 81 | .B wrjpgcom 82 | .I in.jpg 83 | .B < 84 | .I comment.txt 85 | .B > 86 | .I out.jpg 87 | .PP 88 | or equivalently 89 | .IP 90 | .B wrjpgcom 91 | .B -cfile 92 | .I comment.txt 93 | .B < 94 | .I in.jpg 95 | .B > 96 | .I out.jpg 97 | .SH SEE ALSO 98 | .BR cjpeg (1), 99 | .BR djpeg (1), 100 | .BR jpegtran (1), 101 | .BR rdjpgcom (1) 102 | .SH AUTHOR 103 | Independent JPEG Group 104 | -------------------------------------------------------------------------------- /wrppm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * wrppm.c 3 | * 4 | * Copyright (C) 1991-1996, Thomas G. Lane. 5 | * Modified 2009 by Guido Vollbeding. 6 | * This file is part of the Independent JPEG Group's software. 7 | * For conditions of distribution and use, see the accompanying README file. 8 | * 9 | * This file contains routines to write output images in PPM/PGM format. 10 | * The extended 2-byte-per-sample raw PPM/PGM formats are supported. 11 | * The PBMPLUS library is NOT required to compile this software 12 | * (but it is highly useful as a set of PPM image manipulation programs). 13 | * 14 | * These routines may need modification for non-Unix environments or 15 | * specialized applications. As they stand, they assume output to 16 | * an ordinary stdio stream. 17 | */ 18 | 19 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ 20 | 21 | #ifdef PPM_SUPPORTED 22 | 23 | 24 | /* 25 | * For 12-bit JPEG data, we either downscale the values to 8 bits 26 | * (to write standard byte-per-sample PPM/PGM files), or output 27 | * nonstandard word-per-sample PPM/PGM files. Downscaling is done 28 | * if PPM_NORAWWORD is defined (this can be done in the Makefile 29 | * or in jconfig.h). 30 | * (When the core library supports data precision reduction, a cleaner 31 | * implementation will be to ask for that instead.) 32 | */ 33 | 34 | #if BITS_IN_JSAMPLE == 8 35 | #define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) (v) 36 | #define BYTESPERSAMPLE 1 37 | #define PPM_MAXVAL 255 38 | #else 39 | #ifdef PPM_NORAWWORD 40 | #define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) ((v) >> (BITS_IN_JSAMPLE-8)) 41 | #define BYTESPERSAMPLE 1 42 | #define PPM_MAXVAL 255 43 | #else 44 | /* The word-per-sample format always puts the MSB first. */ 45 | #define PUTPPMSAMPLE(ptr,v) \ 46 | { register int val_ = v; \ 47 | *ptr++ = (char) ((val_ >> 8) & 0xFF); \ 48 | *ptr++ = (char) (val_ & 0xFF); \ 49 | } 50 | #define BYTESPERSAMPLE 2 51 | #define PPM_MAXVAL ((1<pub.output_file, dest->iobuffer, dest->buffer_width); 97 | } 98 | 99 | 100 | /* 101 | * This code is used when we have to copy the data and apply a pixel 102 | * format translation. Typically this only happens in 12-bit mode. 103 | */ 104 | 105 | METHODDEF(void) 106 | copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, 107 | JDIMENSION rows_supplied) 108 | { 109 | ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; 110 | register char * bufferptr; 111 | register JSAMPROW ptr; 112 | register JDIMENSION col; 113 | 114 | ptr = dest->pub.buffer[0]; 115 | bufferptr = dest->iobuffer; 116 | for (col = dest->samples_per_row; col > 0; col--) { 117 | PUTPPMSAMPLE(bufferptr, GETJSAMPLE(*ptr++)); 118 | } 119 | (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); 120 | } 121 | 122 | 123 | /* 124 | * Write some pixel data when color quantization is in effect. 125 | * We have to demap the color index values to straight data. 126 | */ 127 | 128 | METHODDEF(void) 129 | put_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, 130 | JDIMENSION rows_supplied) 131 | { 132 | ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; 133 | register char * bufferptr; 134 | register int pixval; 135 | register JSAMPROW ptr; 136 | register JSAMPROW color_map0 = cinfo->colormap[0]; 137 | register JSAMPROW color_map1 = cinfo->colormap[1]; 138 | register JSAMPROW color_map2 = cinfo->colormap[2]; 139 | register JDIMENSION col; 140 | 141 | ptr = dest->pub.buffer[0]; 142 | bufferptr = dest->iobuffer; 143 | for (col = cinfo->output_width; col > 0; col--) { 144 | pixval = GETJSAMPLE(*ptr++); 145 | PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map0[pixval])); 146 | PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1[pixval])); 147 | PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2[pixval])); 148 | } 149 | (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); 150 | } 151 | 152 | 153 | METHODDEF(void) 154 | put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, 155 | JDIMENSION rows_supplied) 156 | { 157 | ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; 158 | register char * bufferptr; 159 | register JSAMPROW ptr; 160 | register JSAMPROW color_map = cinfo->colormap[0]; 161 | register JDIMENSION col; 162 | 163 | ptr = dest->pub.buffer[0]; 164 | bufferptr = dest->iobuffer; 165 | for (col = cinfo->output_width; col > 0; col--) { 166 | PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)])); 167 | } 168 | (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); 169 | } 170 | 171 | 172 | /* 173 | * Startup: write the file header. 174 | */ 175 | 176 | METHODDEF(void) 177 | start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) 178 | { 179 | ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; 180 | 181 | /* Emit file header */ 182 | switch (cinfo->out_color_space) { 183 | case JCS_GRAYSCALE: 184 | /* emit header for raw PGM format */ 185 | fprintf(dest->pub.output_file, "P5\n%ld %ld\n%d\n", 186 | (long) cinfo->output_width, (long) cinfo->output_height, 187 | PPM_MAXVAL); 188 | break; 189 | case JCS_RGB: 190 | /* emit header for raw PPM format */ 191 | fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n", 192 | (long) cinfo->output_width, (long) cinfo->output_height, 193 | PPM_MAXVAL); 194 | break; 195 | default: 196 | ERREXIT(cinfo, JERR_PPM_COLORSPACE); 197 | } 198 | } 199 | 200 | 201 | /* 202 | * Finish up at the end of the file. 203 | */ 204 | 205 | METHODDEF(void) 206 | finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) 207 | { 208 | /* Make sure we wrote the output file OK */ 209 | fflush(dinfo->output_file); 210 | if (ferror(dinfo->output_file)) 211 | ERREXIT(cinfo, JERR_FILE_WRITE); 212 | } 213 | 214 | 215 | /* 216 | * The module selection routine for PPM format output. 217 | */ 218 | 219 | GLOBAL(djpeg_dest_ptr) 220 | jinit_write_ppm (j_decompress_ptr cinfo) 221 | { 222 | ppm_dest_ptr dest; 223 | 224 | /* Create module interface object, fill in method pointers */ 225 | dest = (ppm_dest_ptr) 226 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 227 | SIZEOF(ppm_dest_struct)); 228 | dest->pub.start_output = start_output_ppm; 229 | dest->pub.finish_output = finish_output_ppm; 230 | 231 | /* Calculate output image dimensions so we can allocate space */ 232 | jpeg_calc_output_dimensions(cinfo); 233 | 234 | /* Create physical I/O buffer. Note we make this near on a PC. */ 235 | dest->samples_per_row = cinfo->output_width * cinfo->out_color_components; 236 | dest->buffer_width = dest->samples_per_row * (BYTESPERSAMPLE * SIZEOF(char)); 237 | dest->iobuffer = (char *) (*cinfo->mem->alloc_small) 238 | ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width); 239 | 240 | if (cinfo->quantize_colors || BITS_IN_JSAMPLE != 8 || 241 | SIZEOF(JSAMPLE) != SIZEOF(char)) { 242 | /* When quantizing, we need an output buffer for colormap indexes 243 | * that's separate from the physical I/O buffer. We also need a 244 | * separate buffer if pixel format translation must take place. 245 | */ 246 | dest->pub.buffer = (*cinfo->mem->alloc_sarray) 247 | ((j_common_ptr) cinfo, JPOOL_IMAGE, 248 | cinfo->output_width * cinfo->output_components, (JDIMENSION) 1); 249 | dest->pub.buffer_height = 1; 250 | if (! cinfo->quantize_colors) 251 | dest->pub.put_pixel_rows = copy_pixel_rows; 252 | else if (cinfo->out_color_space == JCS_GRAYSCALE) 253 | dest->pub.put_pixel_rows = put_demapped_gray; 254 | else 255 | dest->pub.put_pixel_rows = put_demapped_rgb; 256 | } else { 257 | /* We will fwrite() directly from decompressor output buffer. */ 258 | /* Synthesize a JSAMPARRAY pointer structure */ 259 | /* Cast here implies near->far pointer conversion on PCs */ 260 | dest->pixrow = (JSAMPROW) dest->iobuffer; 261 | dest->pub.buffer = & dest->pixrow; 262 | dest->pub.buffer_height = 1; 263 | dest->pub.put_pixel_rows = put_pixel_rows; 264 | } 265 | 266 | return (djpeg_dest_ptr) dest; 267 | } 268 | 269 | #endif /* PPM_SUPPORTED */ 270 | -------------------------------------------------------------------------------- /wrtarga.c: -------------------------------------------------------------------------------- 1 | /* 2 | * wrtarga.c 3 | * 4 | * Copyright (C) 1991-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains routines to write output images in Targa format. 9 | * 10 | * These routines may need modification for non-Unix environments or 11 | * specialized applications. As they stand, they assume output to 12 | * an ordinary stdio stream. 13 | * 14 | * Based on code contributed by Lee Daniel Crocker. 15 | */ 16 | 17 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ 18 | 19 | #ifdef TARGA_SUPPORTED 20 | 21 | 22 | /* 23 | * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. 24 | * This is not yet implemented. 25 | */ 26 | 27 | #if BITS_IN_JSAMPLE != 8 28 | Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ 29 | #endif 30 | 31 | /* 32 | * The output buffer needs to be writable by fwrite(). On PCs, we must 33 | * allocate the buffer in near data space, because we are assuming small-data 34 | * memory model, wherein fwrite() can't reach far memory. If you need to 35 | * process very wide images on a PC, you might have to compile in large-memory 36 | * model, or else replace fwrite() with a putc() loop --- which will be much 37 | * slower. 38 | */ 39 | 40 | 41 | /* Private version of data destination object */ 42 | 43 | typedef struct { 44 | struct djpeg_dest_struct pub; /* public fields */ 45 | 46 | char *iobuffer; /* physical I/O buffer */ 47 | JDIMENSION buffer_width; /* width of one row */ 48 | } tga_dest_struct; 49 | 50 | typedef tga_dest_struct * tga_dest_ptr; 51 | 52 | 53 | LOCAL(void) 54 | write_header (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors) 55 | /* Create and write a Targa header */ 56 | { 57 | char targaheader[18]; 58 | 59 | /* Set unused fields of header to 0 */ 60 | MEMZERO(targaheader, SIZEOF(targaheader)); 61 | 62 | if (num_colors > 0) { 63 | targaheader[1] = 1; /* color map type 1 */ 64 | targaheader[5] = (char) (num_colors & 0xFF); 65 | targaheader[6] = (char) (num_colors >> 8); 66 | targaheader[7] = 24; /* 24 bits per cmap entry */ 67 | } 68 | 69 | targaheader[12] = (char) (cinfo->output_width & 0xFF); 70 | targaheader[13] = (char) (cinfo->output_width >> 8); 71 | targaheader[14] = (char) (cinfo->output_height & 0xFF); 72 | targaheader[15] = (char) (cinfo->output_height >> 8); 73 | targaheader[17] = 0x20; /* Top-down, non-interlaced */ 74 | 75 | if (cinfo->out_color_space == JCS_GRAYSCALE) { 76 | targaheader[2] = 3; /* image type = uncompressed gray-scale */ 77 | targaheader[16] = 8; /* bits per pixel */ 78 | } else { /* must be RGB */ 79 | if (num_colors > 0) { 80 | targaheader[2] = 1; /* image type = colormapped RGB */ 81 | targaheader[16] = 8; 82 | } else { 83 | targaheader[2] = 2; /* image type = uncompressed RGB */ 84 | targaheader[16] = 24; 85 | } 86 | } 87 | 88 | if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t) 18) 89 | ERREXIT(cinfo, JERR_FILE_WRITE); 90 | } 91 | 92 | 93 | /* 94 | * Write some pixel data. 95 | * In this module rows_supplied will always be 1. 96 | */ 97 | 98 | METHODDEF(void) 99 | put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, 100 | JDIMENSION rows_supplied) 101 | /* used for unquantized full-color output */ 102 | { 103 | tga_dest_ptr dest = (tga_dest_ptr) dinfo; 104 | register JSAMPROW inptr; 105 | register char * outptr; 106 | register JDIMENSION col; 107 | 108 | inptr = dest->pub.buffer[0]; 109 | outptr = dest->iobuffer; 110 | for (col = cinfo->output_width; col > 0; col--) { 111 | outptr[0] = (char) GETJSAMPLE(inptr[2]); /* RGB to BGR order */ 112 | outptr[1] = (char) GETJSAMPLE(inptr[1]); 113 | outptr[2] = (char) GETJSAMPLE(inptr[0]); 114 | inptr += 3, outptr += 3; 115 | } 116 | (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); 117 | } 118 | 119 | METHODDEF(void) 120 | put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, 121 | JDIMENSION rows_supplied) 122 | /* used for grayscale OR quantized color output */ 123 | { 124 | tga_dest_ptr dest = (tga_dest_ptr) dinfo; 125 | register JSAMPROW inptr; 126 | register char * outptr; 127 | register JDIMENSION col; 128 | 129 | inptr = dest->pub.buffer[0]; 130 | outptr = dest->iobuffer; 131 | for (col = cinfo->output_width; col > 0; col--) { 132 | *outptr++ = (char) GETJSAMPLE(*inptr++); 133 | } 134 | (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); 135 | } 136 | 137 | 138 | /* 139 | * Write some demapped pixel data when color quantization is in effect. 140 | * For Targa, this is only applied to grayscale data. 141 | */ 142 | 143 | METHODDEF(void) 144 | put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, 145 | JDIMENSION rows_supplied) 146 | { 147 | tga_dest_ptr dest = (tga_dest_ptr) dinfo; 148 | register JSAMPROW inptr; 149 | register char * outptr; 150 | register JSAMPROW color_map0 = cinfo->colormap[0]; 151 | register JDIMENSION col; 152 | 153 | inptr = dest->pub.buffer[0]; 154 | outptr = dest->iobuffer; 155 | for (col = cinfo->output_width; col > 0; col--) { 156 | *outptr++ = (char) GETJSAMPLE(color_map0[GETJSAMPLE(*inptr++)]); 157 | } 158 | (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); 159 | } 160 | 161 | 162 | /* 163 | * Startup: write the file header. 164 | */ 165 | 166 | METHODDEF(void) 167 | start_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) 168 | { 169 | tga_dest_ptr dest = (tga_dest_ptr) dinfo; 170 | int num_colors, i; 171 | FILE *outfile; 172 | 173 | if (cinfo->out_color_space == JCS_GRAYSCALE) { 174 | /* Targa doesn't have a mapped grayscale format, so we will */ 175 | /* demap quantized gray output. Never emit a colormap. */ 176 | write_header(cinfo, dinfo, 0); 177 | if (cinfo->quantize_colors) 178 | dest->pub.put_pixel_rows = put_demapped_gray; 179 | else 180 | dest->pub.put_pixel_rows = put_gray_rows; 181 | } else if (cinfo->out_color_space == JCS_RGB) { 182 | if (cinfo->quantize_colors) { 183 | /* We only support 8-bit colormap indexes, so only 256 colors */ 184 | num_colors = cinfo->actual_number_of_colors; 185 | if (num_colors > 256) 186 | ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, num_colors); 187 | write_header(cinfo, dinfo, num_colors); 188 | /* Write the colormap. Note Targa uses BGR byte order */ 189 | outfile = dest->pub.output_file; 190 | for (i = 0; i < num_colors; i++) { 191 | putc(GETJSAMPLE(cinfo->colormap[2][i]), outfile); 192 | putc(GETJSAMPLE(cinfo->colormap[1][i]), outfile); 193 | putc(GETJSAMPLE(cinfo->colormap[0][i]), outfile); 194 | } 195 | dest->pub.put_pixel_rows = put_gray_rows; 196 | } else { 197 | write_header(cinfo, dinfo, 0); 198 | dest->pub.put_pixel_rows = put_pixel_rows; 199 | } 200 | } else { 201 | ERREXIT(cinfo, JERR_TGA_COLORSPACE); 202 | } 203 | } 204 | 205 | 206 | /* 207 | * Finish up at the end of the file. 208 | */ 209 | 210 | METHODDEF(void) 211 | finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) 212 | { 213 | /* Make sure we wrote the output file OK */ 214 | fflush(dinfo->output_file); 215 | if (ferror(dinfo->output_file)) 216 | ERREXIT(cinfo, JERR_FILE_WRITE); 217 | } 218 | 219 | 220 | /* 221 | * The module selection routine for Targa format output. 222 | */ 223 | 224 | GLOBAL(djpeg_dest_ptr) 225 | jinit_write_targa (j_decompress_ptr cinfo) 226 | { 227 | tga_dest_ptr dest; 228 | 229 | /* Create module interface object, fill in method pointers */ 230 | dest = (tga_dest_ptr) 231 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 232 | SIZEOF(tga_dest_struct)); 233 | dest->pub.start_output = start_output_tga; 234 | dest->pub.finish_output = finish_output_tga; 235 | 236 | /* Calculate output image dimensions so we can allocate space */ 237 | jpeg_calc_output_dimensions(cinfo); 238 | 239 | /* Create I/O buffer. Note we make this near on a PC. */ 240 | dest->buffer_width = cinfo->output_width * cinfo->output_components; 241 | dest->iobuffer = (char *) 242 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 243 | (size_t) (dest->buffer_width * SIZEOF(char))); 244 | 245 | /* Create decompressor output buffer. */ 246 | dest->pub.buffer = (*cinfo->mem->alloc_sarray) 247 | ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width, (JDIMENSION) 1); 248 | dest->pub.buffer_height = 1; 249 | 250 | return (djpeg_dest_ptr) dest; 251 | } 252 | 253 | #endif /* TARGA_SUPPORTED */ 254 | --------------------------------------------------------------------------------