Attachment #522445: Patch v2.0. Part 1: Upgrade to libjpeg-turbo v1.1.0 for bug #573948

View | Details | Raw Unified | Return to bug 573948
Collapse All | Expand All

(-)a/config/autoconf.mk.in (+4 lines)
Line     Link Here 
 Lines 163-178   MOZ_TREMOR = @MOZ_TREMOR@ Link Here 
163
MOZ_WEBM = @MOZ_WEBM@
163
MOZ_WEBM = @MOZ_WEBM@
164
VPX_AS = @VPX_AS@
164
VPX_AS = @VPX_AS@
165
VPX_ASFLAGS = @VPX_ASFLAGS@
165
VPX_ASFLAGS = @VPX_ASFLAGS@
166
VPX_DASH_C_FLAG = @VPX_DASH_C_FLAG@
166
VPX_DASH_C_FLAG = @VPX_DASH_C_FLAG@
167
VPX_AS_CONVERSION = @VPX_AS_CONVERSION@
167
VPX_AS_CONVERSION = @VPX_AS_CONVERSION@
168
VPX_ASM_SUFFIX = @VPX_ASM_SUFFIX@
168
VPX_ASM_SUFFIX = @VPX_ASM_SUFFIX@
169
VPX_X86_ASM = @VPX_X86_ASM@
169
VPX_X86_ASM = @VPX_X86_ASM@
170
VPX_ARM_ASM = @VPX_ARM_ASM@
170
VPX_ARM_ASM = @VPX_ARM_ASM@
171
LIBJPEG_TURBO_AS = @LIBJPEG_TURBO_AS@
172
LIBJPEG_TURBO_ASFLAGS = @LIBJPEG_TURBO_ASFLAGS@
173
LIBJPEG_TURBO_X86_ASM = @LIBJPEG_TURBO_X86_ASM@
174
LIBJPEG_TURBO_X64_ASM = @LIBJPEG_TURBO_X64_ASM@
171
NS_PRINTING = @NS_PRINTING@
175
NS_PRINTING = @NS_PRINTING@
172
MOZ_PDF_PRINTING = @MOZ_PDF_PRINTING@
176
MOZ_PDF_PRINTING = @MOZ_PDF_PRINTING@
173
MOZ_CRASHREPORTER = @MOZ_CRASHREPORTER@
177
MOZ_CRASHREPORTER = @MOZ_CRASHREPORTER@
174
MOZ_HELP_VIEWER = @MOZ_HELP_VIEWER@
178
MOZ_HELP_VIEWER = @MOZ_HELP_VIEWER@
175
MOC= @MOC@
179
MOC= @MOC@
176
MOZ_NSS_PATCH = @MOZ_NSS_PATCH@
180
MOZ_NSS_PATCH = @MOZ_NSS_PATCH@
177
MOZ_WEBGL = @MOZ_WEBGL@
181
MOZ_WEBGL = @MOZ_WEBGL@
178
MOZ_ANGLE = @MOZ_ANGLE@
182
MOZ_ANGLE = @MOZ_ANGLE@
(-)a/configure.in (+69 lines)
Line     Link Here 
 Lines 4944-4959   MOZ_MEDIA= Link Here 
4944
MOZ_WEBM=1
4944
MOZ_WEBM=1
4945
VPX_AS=
4945
VPX_AS=
4946
VPX_ASFLAGS=
4946
VPX_ASFLAGS=
4947
VPX_AS_DASH_C_FLAG=
4947
VPX_AS_DASH_C_FLAG=
4948
VPX_AS_CONVERSION=
4948
VPX_AS_CONVERSION=
4949
VPX_ASM_SUFFIX=
4949
VPX_ASM_SUFFIX=
4950
VPX_X86_ASM=
4950
VPX_X86_ASM=
4951
VPX_ARM_ASM=
4951
VPX_ARM_ASM=
4952
LIBJPEG_TURBO_AS=
4953
LIBJPEG_TURBO_ASFLAGS=
4954
LIBJPEG_TURBO_X86_ASM=
4955
LIBJPEG_TURBO_X64_ASM=
4952
MOZ_PANGO=1
4956
MOZ_PANGO=1
4953
MOZ_PERMISSIONS=1
4957
MOZ_PERMISSIONS=1
4954
MOZ_PLACES=1
4958
MOZ_PLACES=1
4955
MOZ_PLUGINS=1
4959
MOZ_PLUGINS=1
4956
MOZ_PREF_EXTENSIONS=1
4960
MOZ_PREF_EXTENSIONS=1
4957
MOZ_PROFILELOCKING=1
4961
MOZ_PROFILELOCKING=1
4958
MOZ_PSM=1
4962
MOZ_PSM=1
4959
MOZ_RDF=1
4963
MOZ_RDF=1
 Lines 6410-6425   MOZ_ARG_WITH_STRING(crashreporter-enable Link Here 
6410
    MOZ_CRASHREPORTER_ENABLE_PERCENT="$val"])
6414
    MOZ_CRASHREPORTER_ENABLE_PERCENT="$val"])
6411
6415
6412
if test -z "$MOZ_CRASHREPORTER_ENABLE_PERCENT"; then
6416
if test -z "$MOZ_CRASHREPORTER_ENABLE_PERCENT"; then
6413
   MOZ_CRASHREPORTER_ENABLE_PERCENT=100
6417
   MOZ_CRASHREPORTER_ENABLE_PERCENT=100
6414
fi
6418
fi
6415
AC_DEFINE_UNQUOTED(MOZ_CRASHREPORTER_ENABLE_PERCENT, $MOZ_CRASHREPORTER_ENABLE_PERCENT)
6419
AC_DEFINE_UNQUOTED(MOZ_CRASHREPORTER_ENABLE_PERCENT, $MOZ_CRASHREPORTER_ENABLE_PERCENT)
6416
6420
6417
dnl ========================================================
6421
dnl ========================================================
6422
dnl = libjpeg-turbo configuration
6423
dnl ========================================================
6424
6425
dnl Detect if we can use yasm to compile libjpeg-turbo's optimized assembly
6426
dnl files.
6427
AC_MSG_CHECKING([for YASM assembler])
6428
AC_CHECK_PROGS(LIBJPEG_TURBO_AS, yasm, "")
6429
6430
dnl XXX jlebar -- need a yasm version check here.
6431
6432
if test -n "LIBJPEG_TURBO_AS"; then
6433
6434
  LIBJPEG_TURBO_AS="yasm"
6435
6436
  dnl We have YASM; see if we support it on this platform.
6437
  case "$OS_ARCH:$OS_TEST" in
6438
  Linux:x86|Linux:i?86)
6439
    LIBJPEG_TURBO_ASFLAGS="-f elf32 -rnasm -pnasm -DPIC -DELF"
6440
    LIBJPEG_TURBO_X86_ASM=1
6441
  ;;
6442
  Linux:x86_64)
6443
    LIBJPEG_TURBO_ASFLAGS="-f elf64 -rnasm -pnasm -D__x86_64__ -DPIC -DELF"
6444
    LIBJPEG_TURBO_X64_ASM=1
6445
  ;;
6446
  SunOS:i?86)
6447
    LIBJPEG_TURBO_ASFLAGS="-f elf32 -rnasm -pnasm -DPIC -DELF"
6448
    LIBJPEG_TURBO_X86_ASM=1
6449
  ;;
6450
  SunOS:x86_64)
6451
    LIBJPEG_TURBO_ASFLAGS="-f elf64 -rnasm -pnasm -D__x86_64__ -DPIC -DELF"
6452
    LIBJPEG_TURBO_X64_ASM=1
6453
  ;;
6454
  Darwin:i?86)
6455
    LIBJPEG_TURBO_ASFLAGS="-f macho32 -rnasm -pnasm -DPIC -DMACHO"
6456
    LIBJPEG_TURBO_X86_ASM=1
6457
  ;;
6458
  Darwin:x86_64)
6459
    LIBJPEG_TURBO_ASFLAGS="-f macho64 -rnasm -pnasm -D__x86_64__ -DPIC -DMACHO"
6460
    LIBJPEG_TURBO_X64_ASM=1
6461
  ;;
6462
  WINNT:x86|WINNT:i?86)
6463
    LIBJPEG_TURBO_ASFLAGS="-f win32 -rnasm -pnasm -DPIC -DWIN32"
6464
    LIBJPEG_TURBO_X86_ASM=1
6465
  ;;
6466
  WINNT:x86_64)
6467
    LIBJPEG_TURBO_ASFLAGS="-f win64 -rnasm -pnasm -D__x86_64__ -DPIC -DWIN64"
6468
    LIBJPEG_TURBO_X64_ASM=1
6469
  ;;
6470
  esac
6471
6472
fi # end have YASM
6473
6474
if test -n "$LIBJPEG_TURBO_X86_ASM"; then
6475
  AC_DEFINE(LIBJPEG_TURBO_X86_ASM)
6476
elif test -n "$LIBJPEG_TURBO_X64_ASM"; then
6477
  AC_DEFINE(LIBJPEG_TURBO_X64_ASM)
6478
else
6479
  AC_MSG_WARN([No assembler or assembly support for libjpeg-turbo.  Using unoptimized C routines.])
6480
fi
6481
6482
dnl ========================================================
6418
dnl = Enable compilation of specific extension modules
6483
dnl = Enable compilation of specific extension modules
6419
dnl ========================================================
6484
dnl ========================================================
6420
6485
6421
MOZ_ARG_ENABLE_STRING(extensions,
6486
MOZ_ARG_ENABLE_STRING(extensions,
6422
[  --enable-extensions     Enable extensions],
6487
[  --enable-extensions     Enable extensions],
6423
[ for option in `echo $enableval | sed 's/,/ /g'`; do
6488
[ for option in `echo $enableval | sed 's/,/ /g'`; do
6424
    if test "$option" = "yes" -o "$option" = "all"; then
6489
    if test "$option" = "yes" -o "$option" = "all"; then
6425
        AC_MSG_ERROR([--enable-extensions=$option is no longer supported.])
6490
        AC_MSG_ERROR([--enable-extensions=$option is no longer supported.])
 Lines 9177-9192   AC_SUBST(MOZ_OGG) Link Here 
9177
AC_SUBST(MOZ_ALSA_LIBS)
9242
AC_SUBST(MOZ_ALSA_LIBS)
9178
AC_SUBST(VPX_AS)
9243
AC_SUBST(VPX_AS)
9179
AC_SUBST(VPX_ASFLAGS)
9244
AC_SUBST(VPX_ASFLAGS)
9180
AC_SUBST(VPX_DASH_C_FLAG)
9245
AC_SUBST(VPX_DASH_C_FLAG)
9181
AC_SUBST(VPX_AS_CONVERSION)
9246
AC_SUBST(VPX_AS_CONVERSION)
9182
AC_SUBST(VPX_ASM_SUFFIX)
9247
AC_SUBST(VPX_ASM_SUFFIX)
9183
AC_SUBST(VPX_X86_ASM)
9248
AC_SUBST(VPX_X86_ASM)
9184
AC_SUBST(VPX_ARM_ASM)
9249
AC_SUBST(VPX_ARM_ASM)
9250
AC_SUBST(LIBJPEG_TURBO_AS)
9251
AC_SUBST(LIBJPEG_TURBO_ASFLAGS)
9252
AC_SUBST(LIBJPEG_TURBO_X86_ASM)
9253
AC_SUBST(LIBJPEG_TURBO_X64_ASM)
9185
9254
9186
if test "$USING_HCC"; then
9255
if test "$USING_HCC"; then
9187
   CC='${topsrcdir}/build/hcc'
9256
   CC='${topsrcdir}/build/hcc'
9188
   CC="$CC '$_OLDCC'"
9257
   CC="$CC '$_OLDCC'"
9189
   CXX='${topsrcdir}/build/hcpp'
9258
   CXX='${topsrcdir}/build/hcpp'
9190
   CXX="$CXX '$_OLDCXX'"
9259
   CXX="$CXX '$_OLDCXX'"
9191
   AC_SUBST(CC)
9260
   AC_SUBST(CC)
9192
   AC_SUBST(CXX)
9261
   AC_SUBST(CXX)
(-)a/jpeg/MOZCHANGES (-10 / +67 lines)
Line     Link Here 
 Lines 1-10    Link Here 
1
1
To upgrade to a new revision of libjpeg-turbo, do the following:
2
Changes made to pristine jpeg source by mozilla.org developers.
2
3
3
* Check out libjpeg-turbo from SVN:
4
2003/08/18 -- change default mapping for METHODDEF, LOCAL, GLOBAL, EXTERN to better match NSPR
4
5
5
    $ svn co https://libjpeg-turbo.svn.sourceforge.net/svnroot/libjpeg-turbo/trunk libjpeg-turbo
6
2003/03/14  -- mingw bustage fix. w32api uses different header guard define
6
7
               for <basestd.h> than msvc.
7
* In a clean clone of mozilla-central, run the following commands
8
8
9
????/??/??  -- Lots of undocumented changes. :(
9
    $ rm -rf jpeg
10
10
    $ svn export --ignore-externals /path/to/libjpeg-turbo jpeg
11
    $ cd jpeg
12
13
* Now look through the new files and rm any which are npotb.  When I upgraded
14
  to libjpeg-turbo 1.1.0, the only files I kept which didn't match
15
16
    *.c  *.h *.asm *.inc
17
18
  were README and README-turbo.
19
20
  You can easily look for all non *.c, *.h, *.asm, and *.inc files by running
21
22
    $ hg status -nu | grep -v '\(c\|h\|asm\|inc\)$'
23
24
  Once you're comfortable that you're only deleting files you want to delete
25
  (and you've hg add'ed the files you want to keep), you can nuke the remaining
26
  files with
27
28
    $ hg status -nu | grep -v '\(c\|h\|asm\|inc\)$' | xargs rm
29
30
  A helpful command for finding the *.c files which aren't *currently* part of
31
  the build is
32
33
    diff <(ls *.c | sort) <(grep -o '\w*\.c' Makefile.in | sort)
34
35
  of course, libjpeg-turbo might have added some new source files, so you'll
36
  have to look though and figure out which of these files to keep.
37
38
* Restore files modified in the Mozilla repository.
39
40
    $ hg revert --no-backup Makefile.in jconfig.h jmorecfg.h simd/Makefile.in \
41
      simd/jsimdcfg.inc jchuff.c jdhuff.c jdhuff.h MOZCHANGES
42
43
* Update Makefile.in to build any new files.
44
45
* Finally, tell hg that we've added or removed some files:
46
47
    $ hg addremove
48
49
50
== March 28, 2011 (initial commit, libjpeg-turbo v1.1.0 r469 2011-02-27) ==
51
52
* Modified jmorecfg.h to define UINT8, UINT16, INT16, and INT32 in terms of
53
  prtypes to fix a build error on Windows.
54
55
* Removed the following files which are licensed under the wxWindows license:
56
57
    bmp.c, bmp.h, jpegut.c, jpgtest.cxx, rrtimer.h, rrutil.h, turbojpeg.h,
58
    turbojpegl.c
59
60
* Reverted the following files to what was previously in Mozilla's tree
61
  (nominally libjpeg 6.2):
62
63
    jchuff.c, jdhuff.c, jdhuff.h
64
65
  since the versions of these files in libjpeg-turbo are also under the
66
  wxWindows license.  (It would have been nicer to revert them to the new
67
  libjpeg-8b code, but that doesn't easily integrate with libjpeg-turbo.)
(-)a/jpeg/Makefile.in (-41 / +115 lines)
Line     Link Here 
 Lines 10-30    Link Here 
10
# Software distributed under the License is distributed on an "AS IS" basis,
10
# Software distributed under the License is distributed on an "AS IS" basis,
11
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
# for the specific language governing rights and limitations under the
12
# for the specific language governing rights and limitations under the
13
# License.
13
# License.
14
#
14
#
15
# The Original Code is mozilla.org code.
15
# The Original Code is mozilla.org code.
16
#
16
#
17
# The Initial Developer of the Original Code is
17
# The Initial Developer of the Original Code is
18
# Netscape Communications Corporation.
18
# Mozilla Corporation
19
# Portions created by the Initial Developer are Copyright (C) 1998
19
# Portions created by the Initial Developer are Copyright (C) 2010
20
# the Initial Developer. All Rights Reserved.
20
# the Initial Developer. All Rights Reserved.
21
#
21
#
22
# Contributor(s):
22
# Contributor(s):
23
#  Justin Lebar <justin.lebar@gmail.com>
23
#
24
#
24
# Alternatively, the contents of this file may be used under the terms of
25
# Alternatively, the contents of this file may be used under the terms of
25
# either the GNU General Public License Version 2 or later (the "GPL"), or
26
# either the GNU General Public License Version 2 or later (the "GPL"), or
26
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
# in which case the provisions of the GPL or the LGPL are applicable instead
28
# in which case the provisions of the GPL or the LGPL are applicable instead
28
# of those above. If you wish to allow use of your version of this file only
29
# of those above. If you wish to allow use of your version of this file only
29
# under the terms of either the GPL or the LGPL, and not to allow others to
30
# under the terms of either the GPL or the LGPL, and not to allow others to
30
# use your version of this file under the terms of the MPL, indicate your
31
# use your version of this file under the terms of the MPL, indicate your
 Lines 37-124    Link Here 
37
38
38
DEPTH		= ..
39
DEPTH		= ..
39
topsrcdir	= @top_srcdir@
40
topsrcdir	= @top_srcdir@
40
srcdir		= @srcdir@
41
srcdir		= @srcdir@
41
VPATH		= @srcdir@
42
VPATH		= @srcdir@
42
43
43
include $(DEPTH)/config/autoconf.mk
44
include $(DEPTH)/config/autoconf.mk
44
45
46
DIRS		= simd
45
MODULE		= jpeg
47
MODULE		= jpeg
46
LIBRARY_NAME	= mozjpeg
48
LIBRARY_NAME	= mozjpeg
47
49
48
ifeq ($(OS_ARCH),WINNT)
50
ifeq ($(OS_ARCH),WINNT)
49
LIBRARY_NAME	= jpeg32$(VERSION_NUMBER)
51
LIBRARY_NAME	= jpeg32$(VERSION_NUMBER)
50
ifneq ($(OS_TEST),x86_64)
52
ifneq ($(OS_TEST),x86_64)
51
# FIXME: bug 413019
53
# FIXME: bug 413019
52
ifndef GNU_CC
54
ifndef GNU_CC
53
OS_COMPILE_CFLAGS += -GL-
55
OS_COMPILE_CFLAGS += -GL-
54
endif
56
endif
55
endif
57
endif
56
endif
58
endif
57
59
58
GRE_MODULE	= 1
60
GRE_MODULE	= 1
59
61
60
CSRCS		= \
62
CSRCS		= \
63
		jcomapi.c \
61
		jdapimin.c \
64
		jdapimin.c \
62
		jdapistd.c \
65
		jdapistd.c \
66
		jdatadst.c \
63
		jdatasrc.c \
67
		jdatasrc.c \
64
		jdatadst.c \
68
		jdcoefct.c \
69
		jdcolor.c \
70
		jddctmgr.c \
71
		jdhuff.c \
72
		jdinput.c \
73
		jdmainct.c \
74
		jdmarker.c \
65
		jdmaster.c \
75
		jdmaster.c \
66
		jdinput.c \
76
		jdmerge.c \
67
		jdmarker.c \
68
		jdhuff.c \
69
		jdphuff.c \
77
		jdphuff.c \
70
		jdmainct.c \
71
		jdcoefct.c \
72
		jdpostct.c \
78
		jdpostct.c \
73
		jddctmgr.c \
74
		jidctfst.c \
75
		jidctflt.c \
76
		jidctint.c \
77
		jdsample.c \
79
		jdsample.c \
78
		jdcolor.c \
80
		jdtrans.c \
79
		jquant1.c \
80
		jquant2.c \
81
		jdmerge.c \
82
		jcomapi.c \
83
		jutils.c \
84
		jerror.c \
81
		jerror.c \
85
		jmemmgr.c \
86
		jmemnobs.c \
87
		jfdctflt.c \
82
		jfdctflt.c \
88
		jfdctfst.c \
83
		jfdctfst.c \
89
		jfdctint.c \
84
		jfdctint.c \
85
		jidctflt.c \
86
		jidctfst.c \
87
		jidctint.c \
88
		jidctred.c \
89
		jmemmgr.c \
90
		jmemnobs.c \
91
		jquant1.c \
92
		jquant2.c \
93
		jutils.c \
90
		$(NULL)
94
		$(NULL)
91
95
96
# These files enable support for writing JPEGs
97
CSRCS		+= \
98
		jcapimin.c \
99
		jcapistd.c \
100
		jccoefct.c \
101
		jccolor.c \
102
		jcdctmgr.c \
103
		jchuff.c \
104
		jcinit.c \
105
		jcmainct.c \
106
		jcmarker.c \
107
		jcmaster.c \
108
		jcparam.c \
109
		jcphuff.c \
110
		jcprepct.c \
111
		jcsample.c \
112
		$(NULL)
113
114
AS=$(LIBJPEG_TURBO_AS)
115
ASM_SUFFIX=asm
116
ASFLAGS=$(LIBJPEG_TURBO_ASFLAGS) -I$(topsrcdir)/modules/libjpeg-turbo/simd/
117
118
ifeq ($(AS),yasm)
119
  # yasm doesn't like -c
120
  AS_DASH_C_FLAG=
121
endif
122
123
# No SIMD support?
124
ifeq (,$(LIBJPEG_TURBO_X86_ASM)$(LIBJPEG_TURBO_X64_ASM))
125
  CSRCS += jsimd_none.c
126
endif
127
128
ifeq (1,$(LIBJPEG_TURBO_X64_ASM))
129
  CSRCS   += simd/jsimd_x86_64.c
130
  ASFILES += \
131
	simd/jccolss2-64.asm \
132
	simd/jcqnts2f-64.asm \
133
	simd/jcqnts2i-64.asm \
134
	simd/jcsamss2-64.asm \
135
	simd/jdcolss2-64.asm \
136
	simd/jdmerss2-64.asm \
137
	simd/jdsamss2-64.asm \
138
	simd/jfss2fst-64.asm \
139
	simd/jfss2int-64.asm \
140
	simd/jfsseflt-64.asm \
141
	simd/jiss2flt-64.asm \
142
	simd/jiss2fst-64.asm \
143
	simd/jiss2int-64.asm \
144
	simd/jiss2red-64.asm \
145
	$(NULL)
146
endif
147
148
ifeq (1,$(LIBJPEG_TURBO_X86_ASM))
149
  CSRCS   +=simd/jsimd_i386.c
150
  ASFILES += \
151
	simd/jccolmmx.asm \
152
	simd/jccolss2.asm \
153
	simd/jcqnt3dn.asm \
154
	simd/jcqntmmx.asm \
155
	simd/jcqnts2f.asm \
156
	simd/jcqnts2i.asm \
157
	simd/jcqntsse.asm \
158
	simd/jcsammmx.asm \
159
	simd/jcsamss2.asm \
160
	simd/jdcolmmx.asm \
161
	simd/jdcolss2.asm \
162
	simd/jdmermmx.asm \
163
	simd/jdmerss2.asm \
164
	simd/jdsammmx.asm \
165
	simd/jdsamss2.asm \
166
	simd/jf3dnflt.asm \
167
	simd/jfmmxfst.asm \
168
	simd/jfmmxint.asm \
169
	simd/jfss2fst.asm \
170
	simd/jfss2int.asm \
171
	simd/jfsseflt.asm \
172
	simd/ji3dnflt.asm \
173
	simd/jimmxfst.asm \
174
	simd/jimmxint.asm \
175
	simd/jimmxred.asm \
176
	simd/jiss2flt.asm \
177
	simd/jiss2fst.asm \
178
	simd/jiss2int.asm \
179
	simd/jiss2red.asm \
180
	simd/jisseflt.asm \
181
	simd/jsimdcpu.asm \
182
	$(NULL)
183
endif
184
185
# jwinfig.h, jos2fig.h  ? XXX
92
EXPORTS		= \
186
EXPORTS		= \
93
		jconfig.h \
187
		jconfig.h \
94
		jerror.h \
188
		jerror.h \
95
		jinclude.h \
189
		jinclude.h \
96
		jmorecfg.h \
190
		jmorecfg.h \
191
		jpegint.h \
97
		jpeglib.h \
192
		jpeglib.h \
98
		jpegint.h \
99
		jwinfig.h \
100
		jos2fig.h \
101
		$(NULL)
193
		$(NULL)
102
194
103
# These files enable support for writing JPEGs
104
CSRCS		+= \
105
		jcapimin.c \
106
		jcparam.c \
107
		jcapistd.c \
108
		jcmarker.c \
109
		jcinit.c \
110
		jcmainct.c \
111
		jchuff.c \
112
		jcsample.c \
113
		jcmaster.c \
114
		jccoefct.c \
115
		jccolor.c \
116
		jcphuff.c \
117
		jcdctmgr.c \
118
		jcprepct.c \
119
		$(NULL)
120
121
# need static lib for some of the libimg componentry to link properly
195
# need static lib for some of the libimg componentry to link properly
122
FORCE_STATIC_LIB = 1
196
FORCE_STATIC_LIB = 1
123
197
124
include $(topsrcdir)/config/rules.mk
198
include $(topsrcdir)/config/rules.mk
(-)a/jpeg/README (-182 / +86 lines)
Line     Link Here 
 Lines 1-105    Link Here 
1
libjpeg-turbo note:  This file is mostly taken from the libjpeg v8b README
2
file, and it is included only for reference.  Some parts of it may not apply to
3
libjpeg-turbo.  Please see README-turbo.txt for information specific to the
4
turbo version.
5
6
1
The Independent JPEG Group's JPEG software
7
The Independent JPEG Group's JPEG software
2
==========================================
8
==========================================
3
9
4
README for release 6b of 27-Mar-1998
10
This distribution contains a release of the Independent JPEG Group's free JPEG
5
====================================
11
software.  You are welcome to redistribute this software and to use it for any
6
12
purpose, subject to the conditions under LEGAL ISSUES, below.
7
This distribution contains the sixth public release of the Independent JPEG
13
8
Group's free JPEG software.  You are welcome to redistribute this software and
14
This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone,
9
to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
15
Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson,
10
16
Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers,
11
Serious users of this software (particularly those incorporating it into
17
and other members of the Independent JPEG Group.
12
larger programs) should contact IJG at jpeg-info@uunet.uu.net to be added to
13
our electronic mailing list.  Mailing list members are notified of updates
14
and have a chance to participate in technical discussions, etc.
15
16
This software is the work of Tom Lane, Philip Gladstone, Jim Boucher,
17
Lee Crocker, Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi,
18
Guido Vollbeding, Ge' Weijers, and other members of the Independent JPEG
19
Group.
20
18
21
IJG is not affiliated with the official ISO JPEG standards committee.
19
IJG is not affiliated with the official ISO JPEG standards committee.
22
20
23
21
24
DOCUMENTATION ROADMAP
22
DOCUMENTATION ROADMAP
25
=====================
23
=====================
26
24
27
This file contains the following sections:
25
This file contains the following sections:
28
26
29
OVERVIEW            General description of JPEG and the IJG software.
27
OVERVIEW            General description of JPEG and the IJG software.
30
LEGAL ISSUES        Copyright, lack of warranty, terms of distribution.
28
LEGAL ISSUES        Copyright, lack of warranty, terms of distribution.
31
REFERENCES          Where to learn more about JPEG.
29
REFERENCES          Where to learn more about JPEG.
32
ARCHIVE LOCATIONS   Where to find newer versions of this software.
30
ARCHIVE LOCATIONS   Where to find newer versions of this software.
33
RELATED SOFTWARE    Other stuff you should get.
34
FILE FORMAT WARS    Software *not* to get.
31
FILE FORMAT WARS    Software *not* to get.
35
TO DO               Plans for future IJG releases.
32
TO DO               Plans for future IJG releases.
36
33
37
Other documentation files in the distribution are:
34
Other documentation files in the distribution are:
38
35
39
User documentation:
36
User documentation:
40
  install.doc       How to configure and install the IJG software.
37
  install.txt       How to configure and install the IJG software.
41
  usage.doc         Usage instructions for cjpeg, djpeg, jpegtran,
38
  usage.txt         Usage instructions for cjpeg, djpeg, jpegtran,
42
                    rdjpgcom, and wrjpgcom.
39
                    rdjpgcom, and wrjpgcom.
43
  *.1               Unix-style man pages for programs (same info as usage.doc).
40
  *.1               Unix-style man pages for programs (same info as usage.txt).
44
  wizard.doc        Advanced usage instructions for JPEG wizards only.
41
  wizard.txt        Advanced usage instructions for JPEG wizards only.
45
  change.log        Version-to-version change highlights.
42
  change.log        Version-to-version change highlights.
46
Programmer and internal documentation:
43
Programmer and internal documentation:
47
  libjpeg.doc       How to use the JPEG library in your own programs.
44
  libjpeg.txt       How to use the JPEG library in your own programs.
48
  example.c         Sample code for calling the JPEG library.
45
  example.c         Sample code for calling the JPEG library.
49
  structure.doc     Overview of the JPEG library's internal structure.
46
  structure.txt     Overview of the JPEG library's internal structure.
50
  filelist.doc      Road map of IJG files.
47
  filelist.txt      Road map of IJG files.
51
  coderules.doc     Coding style rules --- please read if you contribute code.
48
  coderules.txt     Coding style rules --- please read if you contribute code.
52
49
53
Please read at least the files install.doc and usage.doc.  Useful information
50
Please read at least the files install.txt and usage.txt.  Some information
54
can also be found in the JPEG FAQ (Frequently Asked Questions) article.  See
51
can also be found in the JPEG FAQ (Frequently Asked Questions) article.  See
55
ARCHIVE LOCATIONS below to find out where to obtain the FAQ article.
52
ARCHIVE LOCATIONS below to find out where to obtain the FAQ article.
56
53
57
If you want to understand how the JPEG code works, we suggest reading one or
54
If you want to understand how the JPEG code works, we suggest reading one or
58
more of the REFERENCES, then looking at the documentation files (in roughly
55
more of the REFERENCES, then looking at the documentation files (in roughly
59
the order listed) before diving into the code.
56
the order listed) before diving into the code.
60
57
61
58
62
OVERVIEW
59
OVERVIEW
63
========
60
========
64
61
65
This package contains C software to implement JPEG image compression and
62
This package contains C software to implement JPEG image encoding, decoding,
66
decompression.  JPEG (pronounced "jay-peg") is a standardized compression
63
and transcoding.  JPEG (pronounced "jay-peg") is a standardized compression
67
method for full-color and gray-scale images.  JPEG is intended for compressing
64
method for full-color and gray-scale images.  JPEG's strong suit is compressing
68
"real-world" scenes; line drawings, cartoons and other non-realistic images
65
photographic images or other types of images which have smooth color and
69
are not its strong suit.  JPEG is lossy, meaning that the output image is not
66
brightness transitions between neighboring pixels.  Images with sharp lines or
70
exactly identical to the input image.  Hence you must not use JPEG if you
67
other abrupt features may not compress well with JPEG, and a higher JPEG
71
have to have identical output bits.  However, on typical photographic images,
68
quality may have to be used to avoid visible compression artifacts with such
72
very good compression levels can be obtained with no visible change, and
69
images.
73
remarkably high compression levels are possible if you can tolerate a
70
74
low-quality image.  For more details, see the references, or just experiment
71
JPEG is lossy, meaning that the output pixels are not necessarily identical to
75
with various compression settings.
72
the input pixels.  However, on photographic content and other "smooth" images,
73
very good compression ratios can be obtained with no visible compression
74
artifacts, and extremely high compression ratios are possible if you are
75
willing to sacrifice image quality (by reducing the "quality" setting in the
76
compressor.)
76
77
77
This software implements JPEG baseline, extended-sequential, and progressive
78
This software implements JPEG baseline, extended-sequential, and progressive
78
compression processes.  Provision is made for supporting all variants of these
79
compression processes.  Provision is made for supporting all variants of these
79
processes, although some uncommon parameter settings aren't implemented yet.
80
processes, although some uncommon parameter settings aren't implemented yet.
80
For legal reasons, we are not distributing code for the arithmetic-coding
81
We have made no provision for supporting the hierarchical or lossless
81
variants of JPEG; see LEGAL ISSUES.  We have made no provision for supporting
82
processes defined in the standard.
82
the hierarchical or lossless processes defined in the standard.
83
83
84
We provide a set of library routines for reading and writing JPEG image files,
84
We provide a set of library routines for reading and writing JPEG image files,
85
plus two sample applications "cjpeg" and "djpeg", which use the library to
85
plus two sample applications "cjpeg" and "djpeg", which use the library to
86
perform conversion between JPEG and some other popular image file formats.
86
perform conversion between JPEG and some other popular image file formats.
87
The library is intended to be reused in other applications.
87
The library is intended to be reused in other applications.
88
88
89
In order to support file conversion and viewing software, we have included
89
In order to support file conversion and viewing software, we have included
90
considerable functionality beyond the bare JPEG coding/decoding capability;
90
considerable functionality beyond the bare JPEG coding/decoding capability;
91
for example, the color quantization modules are not strictly part of JPEG
91
for example, the color quantization modules are not strictly part of JPEG
92
decoding, but they are essential for output to colormapped file formats or
92
decoding, but they are essential for output to colormapped file formats or
93
colormapped displays.  These extra functions can be compiled out of the
93
colormapped displays.  These extra functions can be compiled out of the
94
library if not required for a particular application.  We have also included
94
library if not required for a particular application.
95
"jpegtran", a utility for lossless transcoding between different JPEG
95
96
processes, and "rdjpgcom" and "wrjpgcom", two simple applications for
96
We have also included "jpegtran", a utility for lossless transcoding between
97
inserting and extracting textual comments in JFIF files.
97
different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple
98
applications for inserting and extracting textual comments in JFIF files.
98
99
99
The emphasis in designing this software has been on achieving portability and
100
The emphasis in designing this software has been on achieving portability and
100
flexibility, while also making it fast enough to be useful.  In particular,
101
flexibility, while also making it fast enough to be useful.  In particular,
101
the software is not intended to be read as a tutorial on JPEG.  (See the
102
the software is not intended to be read as a tutorial on JPEG.  (See the
102
REFERENCES section for introductory material.)  Rather, it is intended to
103
REFERENCES section for introductory material.)  Rather, it is intended to
103
be reliable, portable, industrial-strength code.  We do not claim to have
104
be reliable, portable, industrial-strength code.  We do not claim to have
104
achieved that goal in every aspect of the software, but we strive for it.
105
achieved that goal in every aspect of the software, but we strive for it.
105
106
 Lines 122-138   3. You may not pretend that you wrote th Link Here 
122
123
123
In legalese:
124
In legalese:
124
125
125
The authors make NO WARRANTY or representation, either express or implied,
126
The authors make NO WARRANTY or representation, either express or implied,
126
with respect to this software, its quality, accuracy, merchantability, or
127
with respect to this software, its quality, accuracy, merchantability, or
127
fitness for a particular purpose.  This software is provided "AS IS", and you,
128
fitness for a particular purpose.  This software is provided "AS IS", and you,
128
its user, assume the entire risk as to its quality and accuracy.
129
its user, assume the entire risk as to its quality and accuracy.
129
130
130
This software is copyright (C) 1991-1998, Thomas G. Lane.
131
This software is copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding.
131
All Rights Reserved except as specified below.
132
All Rights Reserved except as specified below.
132
133
133
Permission is hereby granted to use, copy, modify, and distribute this
134
Permission is hereby granted to use, copy, modify, and distribute this
134
software (or portions thereof) for any purpose, without fee, subject to these
135
software (or portions thereof) for any purpose, without fee, subject to these
135
conditions:
136
conditions:
136
(1) If any part of the source code for this software is distributed, then this
137
(1) If any part of the source code for this software is distributed, then this
137
README file must be included, with this copyright and no-warranty notice
138
README file must be included, with this copyright and no-warranty notice
138
unaltered; and any additions, deletions, or changes to the original files
139
unaltered; and any additions, deletions, or changes to the original files
 Lines 165-191   by the usual distribution terms of the F Link Here 
165
that you must include source code if you redistribute it.  (See the file
166
that you must include source code if you redistribute it.  (See the file
166
ansi2knr.c for full details.)  However, since ansi2knr.c is not needed as part
167
ansi2knr.c for full details.)  However, since ansi2knr.c is not needed as part
167
of any program generated from the IJG code, this does not limit you more than
168
of any program generated from the IJG code, this does not limit you more than
168
the foregoing paragraphs do.
169
the foregoing paragraphs do.
169
170
170
The Unix configuration script "configure" was produced with GNU Autoconf.
171
The Unix configuration script "configure" was produced with GNU Autoconf.
171
It is copyright by the Free Software Foundation but is freely distributable.
172
It is copyright by the Free Software Foundation but is freely distributable.
172
The same holds for its supporting scripts (config.guess, config.sub,
173
The same holds for its supporting scripts (config.guess, config.sub,
173
ltconfig, ltmain.sh).  Another support script, install-sh, is copyright
174
ltmain.sh).  Another support script, install-sh, is copyright by X Consortium
174
by M.I.T. but is also freely distributable.
175
but is also freely distributable.
175
176
It appears that the arithmetic coding option of the JPEG spec is covered by
177
patents owned by IBM, AT&T, and Mitsubishi.  Hence arithmetic coding cannot
178
legally be used without obtaining one or more licenses.  For this reason,
179
support for arithmetic coding has been removed from the free JPEG software.
180
(Since arithmetic coding provides only a marginal gain over the unpatented
181
Huffman mode, it is unlikely that very many implementations will support it.)
182
So far as we are aware, there are no patent restrictions on the remaining
183
code.
184
176
185
The IJG distribution formerly included code to read and write GIF files.
177
The IJG distribution formerly included code to read and write GIF files.
186
To avoid entanglement with the Unisys LZW patent, GIF reading support has
178
To avoid entanglement with the Unisys LZW patent, GIF reading support has
187
been removed altogether, and the GIF writer has been simplified to produce
179
been removed altogether, and the GIF writer has been simplified to produce
188
"uncompressed GIFs".  This technique does not use the LZW algorithm; the
180
"uncompressed GIFs".  This technique does not use the LZW algorithm; the
189
resulting GIF files are larger than usual, but are readable by all standard
181
resulting GIF files are larger than usual, but are readable by all standard
190
GIF decoders.
182
GIF decoders.
191
183
 Lines 193-385   We are required to state that Link Here 
193
    "The Graphics Interchange Format(c) is the Copyright property of
185
    "The Graphics Interchange Format(c) is the Copyright property of
194
    CompuServe Incorporated.  GIF(sm) is a Service Mark property of
186
    CompuServe Incorporated.  GIF(sm) is a Service Mark property of
195
    CompuServe Incorporated."
187
    CompuServe Incorporated."
196
188
197
189
198
REFERENCES
190
REFERENCES
199
==========
191
==========
200
192
201
We highly recommend reading one or more of these references before trying to
193
We recommend reading one or more of these references before trying to
202
understand the innards of the JPEG software.
194
understand the innards of the JPEG software.
203
195
204
The best short technical introduction to the JPEG compression algorithm is
196
The best short technical introduction to the JPEG compression algorithm is
205
	Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
197
	Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
206
	Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
198
	Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
207
(Adjacent articles in that issue discuss MPEG motion picture compression,
199
(Adjacent articles in that issue discuss MPEG motion picture compression,
208
applications of JPEG, and related topics.)  If you don't have the CACM issue
200
applications of JPEG, and related topics.)  If you don't have the CACM issue
209
handy, a PostScript file containing a revised version of Wallace's article is
201
handy, a PostScript file containing a revised version of Wallace's article is
210
available at ftp://ftp.uu.net/graphics/jpeg/wallace.ps.gz.  The file (actually
202
available at http://www.ijg.org/files/wallace.ps.gz.  The file (actually
211
a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
203
a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
212
omits the sample images that appeared in CACM, but it includes corrections
204
omits the sample images that appeared in CACM, but it includes corrections
213
and some added material.  Note: the Wallace article is copyright ACM and IEEE,
205
and some added material.  Note: the Wallace article is copyright ACM and IEEE,
214
and it may not be used for commercial purposes.
206
and it may not be used for commercial purposes.
215
207
216
A somewhat less technical, more leisurely introduction to JPEG can be found in
208
A somewhat less technical, more leisurely introduction to JPEG can be found in
217
"The Data Compression Book" by Mark Nelson and Jean-loup Gailly, published by
209
"The Data Compression Book" by Mark Nelson and Jean-loup Gailly, published by
218
M&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1.  This book provides
210
M&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1.  This book provides
219
good explanations and example C code for a multitude of compression methods
211
good explanations and example C code for a multitude of compression methods
220
including JPEG.  It is an excellent source if you are comfortable reading C
212
including JPEG.  It is an excellent source if you are comfortable reading C
221
code but don't know much about data compression in general.  The book's JPEG
213
code but don't know much about data compression in general.  The book's JPEG
222
sample code is far from industrial-strength, but when you are ready to look
214
sample code is far from industrial-strength, but when you are ready to look
223
at a full implementation, you've got one here...
215
at a full implementation, you've got one here...
224
216
225
The best full description of JPEG is the textbook "JPEG Still Image Data
217
The best currently available description of JPEG is the textbook "JPEG Still
226
Compression Standard" by William B. Pennebaker and Joan L. Mitchell, published
218
Image Data Compression Standard" by William B. Pennebaker and Joan L.
227
by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1.  Price US$59.95, 638 pp.
219
Mitchell, published by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1.
228
The book includes the complete text of the ISO JPEG standards (DIS 10918-1
220
Price US$59.95, 638 pp.  The book includes the complete text of the ISO JPEG
229
and draft DIS 10918-2).  This is by far the most complete exposition of JPEG
221
standards (DIS 10918-1 and draft DIS 10918-2).
230
in existence, and we highly recommend it.
222
231
223
The original JPEG standard is divided into two parts, Part 1 being the actual
232
The JPEG standard itself is not available electronically; you must order a
224
specification, while Part 2 covers compliance testing methods.  Part 1 is
233
paper copy through ISO or ITU.  (Unless you feel a need to own a certified
225
titled "Digital Compression and Coding of Continuous-tone Still Images,
234
official copy, we recommend buying the Pennebaker and Mitchell book instead;
235
it's much cheaper and includes a great deal of useful explanatory material.)
236
In the USA, copies of the standard may be ordered from ANSI Sales at (212)
237
642-4900, or from Global Engineering Documents at (800) 854-7179.  (ANSI
238
doesn't take credit card orders, but Global does.)  It's not cheap: as of
239
1992, ANSI was charging $95 for Part 1 and $47 for Part 2, plus 7%
240
shipping/handling.  The standard is divided into two parts, Part 1 being the
241
actual specification, while Part 2 covers compliance testing methods.  Part 1
242
is titled "Digital Compression and Coding of Continuous-tone Still Images,
243
Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS
226
Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS
244
10918-1, ITU-T T.81.  Part 2 is titled "Digital Compression and Coding of
227
10918-1, ITU-T T.81.  Part 2 is titled "Digital Compression and Coding of
245
Continuous-tone Still Images, Part 2: Compliance testing" and has document
228
Continuous-tone Still Images, Part 2: Compliance testing" and has document
246
numbers ISO/IEC IS 10918-2, ITU-T T.83.
229
numbers ISO/IEC IS 10918-2, ITU-T T.83.
247
230
248
Some extensions to the original JPEG standard are defined in JPEG Part 3,
249
a newer ISO standard numbered ISO/IEC IS 10918-3 and ITU-T T.84.  IJG
250
currently does not support any Part 3 extensions.
251
252
The JPEG standard does not specify all details of an interchangeable file
231
The JPEG standard does not specify all details of an interchangeable file
253
format.  For the omitted details we follow the "JFIF" conventions, revision
232
format.  For the omitted details we follow the "JFIF" conventions, revision
254
1.02.  A copy of the JFIF spec is available from:
233
1.02.  JFIF 1.02 has been adopted as an Ecma International Technical Report
255
	Literature Department
234
and thus received a formal publication status.  It is available as a free
256
	C-Cube Microsystems, Inc.
235
download in PDF format from
257
	1778 McCarthy Blvd.
236
http://www.ecma-international.org/publications/techreports/E-TR-098.htm.
258
	Milpitas, CA 95035
237
A PostScript version of the JFIF document is available at
259
	phone (408) 944-6300,  fax (408) 944-6314
238
http://www.ijg.org/files/jfif.ps.gz.  There is also a plain text version at
260
A PostScript version of this document is available by FTP at
239
http://www.ijg.org/files/jfif.txt.gz, but it is missing the figures.
261
ftp://ftp.uu.net/graphics/jpeg/jfif.ps.gz.  There is also a plain text
262
version at ftp://ftp.uu.net/graphics/jpeg/jfif.txt.gz, but it is missing
263
the figures.
264
240
265
The TIFF 6.0 file format specification can be obtained by FTP from
241
The TIFF 6.0 file format specification can be obtained by FTP from
266
ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz.  The JPEG incorporation scheme
242
ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz.  The JPEG incorporation scheme
267
found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.
243
found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.
268
IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
244
IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
269
Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
245
Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
270
(Compression tag 7).  Copies of this Note can be obtained from ftp.sgi.com or
246
(Compression tag 7).  Copies of this Note can be obtained from
271
from ftp://ftp.uu.net/graphics/jpeg/.  It is expected that the next revision
247
http://www.ijg.org/files/.  It is expected that the next revision
272
of the TIFF spec will replace the 6.0 JPEG design with the Note's design.
248
of the TIFF spec will replace the 6.0 JPEG design with the Note's design.
273
Although IJG's own code does not support TIFF/JPEG, the free libtiff library
249
Although IJG's own code does not support TIFF/JPEG, the free libtiff library
274
uses our library to implement TIFF/JPEG per the Note.  libtiff is available
250
uses our library to implement TIFF/JPEG per the Note.
275
from ftp://ftp.sgi.com/graphics/tiff/.
276
251
277
252
278
ARCHIVE LOCATIONS
253
ARCHIVE LOCATIONS
279
=================
254
=================
280
255
281
The "official" archive site for this software is ftp.uu.net (Internet
256
The "official" archive site for this software is www.ijg.org.
282
address 192.48.96.9).  The most recent released version can always be found
257
The most recent released version can always be found there in
283
there in directory graphics/jpeg.  This particular version will be archived
258
directory "files".  This particular version will be archived as
284
as ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz.  If you don't have
259
http://www.ijg.org/files/jpegsrc.v8b.tar.gz, and in Windows-compatible
285
direct Internet access, UUNET's archives are also available via UUCP; contact
260
"zip" archive format as http://www.ijg.org/files/jpegsr8b.zip.
286
help@uunet.uu.net for information on retrieving files that way.
261
287
262
The JPEG FAQ (Frequently Asked Questions) article is a source of some
288
Numerous Internet sites maintain copies of the UUNET files.  However, only
263
general information about JPEG.
289
ftp.uu.net is guaranteed to have the latest official version.
290
291
You can also obtain this software in DOS-compatible "zip" archive format from
292
the SimTel archives (ftp://ftp.simtel.net/pub/simtelnet/msdos/graphics/), or
293
on CompuServe in the Graphics Support forum (GO CIS:GRAPHSUP), library 12
294
"JPEG Tools".  Again, these versions may sometimes lag behind the ftp.uu.net
295
release.
296
297
The JPEG FAQ (Frequently Asked Questions) article is a useful source of
298
general information about JPEG.  It is updated constantly and therefore is
299
not included in this distribution.  The FAQ is posted every two weeks to
300
Usenet newsgroups comp.graphics.misc, news.answers, and other groups.
301
It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/
264
It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/
302
and other news.answers archive sites, including the official news.answers
265
and other news.answers archive sites, including the official news.answers
303
archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/.
266
archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/.
304
If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu
267
If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu
305
with body
268
with body
306
	send usenet/news.answers/jpeg-faq/part1
269
	send usenet/news.answers/jpeg-faq/part1
307
	send usenet/news.answers/jpeg-faq/part2
270
	send usenet/news.answers/jpeg-faq/part2
308
271
309
272
310
RELATED SOFTWARE
311
================
312
313
Numerous viewing and image manipulation programs now support JPEG.  (Quite a
314
few of them use this library to do so.)  The JPEG FAQ described above lists
315
some of the more popular free and shareware viewers, and tells where to
316
obtain them on Internet.
317
318
If you are on a Unix machine, we highly recommend Jef Poskanzer's free
319
PBMPLUS software, which provides many useful operations on PPM-format image
320
files.  In particular, it can convert PPM images to and from a wide range of
321
other formats, thus making cjpeg/djpeg considerably more useful.  The latest
322
version is distributed by the NetPBM group, and is available from numerous
323
sites, notably ftp://wuarchive.wustl.edu/graphics/graphics/packages/NetPBM/.
324
Unfortunately PBMPLUS/NETPBM is not nearly as portable as the IJG software is;
325
you are likely to have difficulty making it work on any non-Unix machine.
326
327
A different free JPEG implementation, written by the PVRG group at Stanford,
328
is available from ftp://havefun.stanford.edu/pub/jpeg/.  This program
329
is designed for research and experimentation rather than production use;
330
it is slower, harder to use, and less portable than the IJG code, but it
331
is easier to read and modify.  Also, the PVRG code supports lossless JPEG,
332
which we do not.  (On the other hand, it doesn't do progressive JPEG.)
333
334
335
FILE FORMAT WARS
273
FILE FORMAT WARS
336
================
274
================
337
275
338
Some JPEG programs produce files that are not compatible with our library.
276
The ISO JPEG standards committee actually promotes different formats like
339
The root of the problem is that the ISO JPEG committee failed to specify a
277
"JPEG 2000" or "JPEG XR" which are incompatible with original DCT-based
340
concrete file format.  Some vendors "filled in the blanks" on their own,
278
JPEG.  IJG therefore does not support these formats (see REFERENCES).  Indeed,
341
creating proprietary formats that no one else could read.  (For example, none
342
of the early commercial JPEG implementations for the Macintosh were able to
343
exchange compressed files.)
344
345
The file format we have adopted is called JFIF (see REFERENCES).  This format
346
has been agreed to by a number of major commercial JPEG vendors, and it has
347
become the de facto standard.  JFIF is a minimal or "low end" representation.
348
We recommend the use of TIFF/JPEG (TIFF revision 6.0 as modified by TIFF
349
Technical Note #2) for "high end" applications that need to record a lot of
350
additional data about an image.  TIFF/JPEG is fairly new and not yet widely
351
supported, unfortunately.
352
353
The upcoming JPEG Part 3 standard defines a file format called SPIFF.
354
SPIFF is interoperable with JFIF, in the sense that most JFIF decoders should
355
be able to read the most common variant of SPIFF.  SPIFF has some technical
356
advantages over JFIF, but its major claim to fame is simply that it is an
357
official standard rather than an informal one.  At this point it is unclear
358
whether SPIFF will supersede JFIF or whether JFIF will remain the de-facto
359
standard.  IJG intends to support SPIFF once the standard is frozen, but we
360
have not decided whether it should become our default output format or not.
361
(In any case, our decoder will remain capable of reading JFIF indefinitely.)
362
363
Various proprietary file formats incorporating JPEG compression also exist.
364
We have little or no sympathy for the existence of these formats.  Indeed,
365
one of the original reasons for developing this free software was to help
279
one of the original reasons for developing this free software was to help
366
force convergence on common, open format standards for JPEG files.  Don't
280
force convergence on common, interoperable format standards for JPEG files.
367
use a proprietary file format!
281
Don't use an incompatible file format!
282
(In any case, our decoder will remain capable of reading existing JPEG
283
image files indefinitely.)
368
284
369
285
370
TO DO
286
TO DO
371
=====
287
=====
372
288
373
The major thrust for v7 will probably be improvement of visual quality.
289
Please send bug reports, offers of help, etc. to jpeg-info@uc.ag.
374
The current method for scaling the quantization tables is known not to be
375
very good at low Q values.  We also intend to investigate block boundary
376
smoothing, "poor man's variable quantization", and other means of improving
377
quality-vs-file-size performance without sacrificing compatibility.
378
379
In future versions, we are considering supporting some of the upcoming JPEG
380
Part 3 extensions --- principally, variable quantization and the SPIFF file
381
format.
382
383
As always, speeding things up is of great interest.
384
385
Please send bug reports, offers of help, etc. to jpeg-info@uunet.uu.net.
(-)a/jpeg/README-turbo.txt (+304 lines)
Line     Link Here 
Line 0    Link Here 
1
*******************************************************************************
2
**     Background
3
*******************************************************************************
4
5
libjpeg-turbo is a derivative of libjpeg which uses SIMD instructions (MMX,
6
SSE2, etc.) to accelerate baseline JPEG compression and decompression on x86
7
and x86-64 systems.  On such systems, libjpeg-turbo is generally 2-4x as fast
8
as the unmodified version of libjpeg, all else being equal.
9
10
libjpeg-turbo was originally based on libjpeg/SIMD by Miyasaka Masaru, but
11
the TigerVNC and VirtualGL projects made numerous enhancements to the codec in
12
2009, including improved support for Mac OS X, 64-bit support, support for
13
32-bit and big endian pixel formats (RGBX, XBGR, etc.), accelerated Huffman
14
encoding/decoding, and various bug fixes.  The goal was to produce a fully open
15
source codec that could replace the partially closed source TurboJPEG/IPP codec
16
used by VirtualGL and TurboVNC.  libjpeg-turbo generally performs in the range
17
of 80-120% of TurboJPEG/IPP.  It is faster in some areas but slower in others.
18
19
In early 2010, libjpeg-turbo spun off into its own independent project, with
20
the goal of making high-speed JPEG compression/decompression technology
21
available to a broader range of users and developers.  The libjpeg-turbo shared
22
libraries can be used as drop-in replacements for libjpeg on most systems.
23
24
25
*******************************************************************************
26
**     License
27
*******************************************************************************
28
29
The TurboJPEG/OSS wrapper, as well as some of the optimizations to the Huffman
30
encoder (jchuff.c) and decoder (jdhuff.c), were borrowed from VirtualGL, and
31
thus any distribution of libjpeg-turbo which includes those files must, as a
32
whole, be subject to the terms of the wxWindows Library Licence, Version 3.1.
33
A copy of this license can be found in this directory under LICENSE.txt.  The
34
wxWindows Library License is based on the LGPL but includes provisions which
35
allow the Library to be statically linked into proprietary libraries and
36
applications without requiring the resulting binaries to be distributed under
37
the terms of the LGPL.
38
39
The rest of the source code, apart from TurboJPEG/OSS and the Huffman codec
40
optimizations, falls under a less restrictive, BSD-style license (see README.)
41
You can choose to distribute libjpeg-turbo, as a whole, under this BSD-style
42
license by simply removing TurboJPEG/OSS and replacing the optimized jchuff.c
43
and jdhuff.c with their unoptimized counterparts from the libjpeg v6b source.
44
45
46
*******************************************************************************
47
**     Using libjpeg-turbo
48
*******************************************************************************
49
50
=============================
51
Replacing libjpeg at Run Time
52
=============================
53
54
If a Unix application is dynamically linked with libjpeg, then you can replace
55
libjpeg with libjpeg-turbo at run time by manipulating LD_LIBRARY_PATH.
56
For instance:
57
58
  [Using libjpeg]
59
  > time cjpeg <vgl_5674_0098.ppm >vgl_5674_0098.jpg
60
  real  0m0.392s
61
  user  0m0.074s
62
  sys   0m0.020s
63
64
  [Using libjpeg-turbo]
65
  > export LD_LIBRARY_PATH=/opt/libjpeg-turbo/{lib}:$LD_LIBRARY_PATH
66
  > time cjpeg <vgl_5674_0098.ppm >vgl_5674_0098.jpg
67
  real  0m0.109s
68
  user  0m0.029s
69
  sys   0m0.010s
70
71
NOTE: {lib} can be lib, lib32, lib64, or lib/64, depending on the O/S and
72
architecture.
73
74
System administrators can also replace the libjpeg sym links in /usr/{lib} with
75
links to the libjpeg dynamic library located in /opt/libjpeg-turbo/{lib}.  This
76
will effectively accelerate every dynamically linked libjpeg application on the
77
system.
78
79
The libjpeg-turbo SDK for Visual C++ installs the libjpeg-turbo DLL
80
(jpeg62.dll, jpeg7.dll, or jpeg8.dll, depending on whether libjpeg v6b, v7, or
81
v8 emulation is enabled) into c:\libjpeg-turbo[64]\bin, and the PATH
82
environment variable can be modified such that this directory is searched
83
before any others that might contain a libjpeg DLL.  However, if a libjpeg
84
DLL exists in an application's install directory, then Windows will load this
85
DLL first whenever the application is launched.  Thus, if an application ships
86
with jpeg62.dll, jpeg7.dll, or jpeg8.dll, then back up the application's
87
version of this DLL and copy c:\libjpeg-turbo[64]\bin\jpeg*.dll into the
88
application's install directory to accelerate it.
89
90
The version of the libjpeg-turbo DLL distributed in the libjpeg-turbo SDK for
91
Visual C++ requires the Visual C++ 2008 C run time DLL (msvcr90.dll).
92
msvcr90.dll ships with more recent versions of Windows, but users of older
93
Windows releases can obtain it from the Visual C++ 2008 Redistributable
94
Package, which is available as a free download from Microsoft's web site.
95
96
NOTE:  Features of libjpeg which require passing a C run time structure, such
97
as a file handle, from an application to libjpeg will probably not work with
98
the version of the libjpeg-turbo DLL distributed in the libjpeg-turbo SDK for
99
Visual C++, unless the application is also built to use the Visual C++ 2008 C
100
run time DLL.  In particular, this affects jpeg_stdio_dest() and
101
jpeg_stdio_src().
102
103
Mac applications typically embed their own copies of the libjpeg dylib inside
104
the (hidden) application bundle, so it is not possible to globally replace
105
libjpeg on OS X systems.  If an application uses a shared library version of
106
libjpeg, then it may be possible to replace the application's version of it.
107
This would generally involve copying libjpeg.*.dylib from libjpeg-turbo into
108
the appropriate place in the application bundle and using install_name_tool to
109
repoint the dylib to the new directory.  This requires an advanced knowledge of
110
OS X and would not survive an upgrade or a re-install of the application.
111
Thus, it is not recommended for most users.
112
113
=======================
114
Replacing TurboJPEG/IPP
115
=======================
116
117
libjpeg-turbo is a drop-in replacement for the TurboJPEG/IPP SDK used by
118
VirtualGL 2.1.x and TurboVNC 0.6 (and prior.)  libjpeg-turbo contains a wrapper
119
library (TurboJPEG/OSS) that emulates the TurboJPEG API using libjpeg-turbo
120
instead of the closed source Intel Performance Primitives.  You can replace the
121
TurboJPEG/IPP package on Linux systems with the libjpeg-turbo package in order
122
to make existing releases of VirtualGL 2.1.x and TurboVNC 0.x use the new codec
123
at run time.  Note that the 64-bit libjpeg-turbo packages contain only 64-bit
124
binaries, whereas the TurboJPEG/IPP 64-bit packages contained both 64-bit and
125
32-bit binaries.  Thus, to replace a TurboJPEG/IPP 64-bit package, install
126
both the 64-bit and 32-bit versions of libjpeg-turbo.
127
128
You can also build the VirtualGL 2.1.x and TurboVNC 0.6 source code with
129
the libjpeg-turbo SDK instead of TurboJPEG/IPP.  It should work identically.
130
libjpeg-turbo also includes static library versions of TurboJPEG/OSS, which
131
are used to build TurboVNC 1.0 and later.
132
133
========================================
134
Using libjpeg-turbo in Your Own Programs
135
========================================
136
137
For the most part, libjpeg-turbo should work identically to libjpeg, so in
138
most cases, an application can be built against libjpeg and then run against
139
libjpeg-turbo.  On Unix systems (including Cygwin), you can build against
140
libjpeg-turbo instead of libjpeg by setting
141
142
  CPATH=/opt/libjpeg-turbo/include
143
  and
144
  LIBRARY_PATH=/opt/libjpeg-turbo/{lib}
145
146
({lib} = lib32 or lib64, depending on whether you are building a 32-bit or a
147
64-bit application.)
148
149
If using MinGW, then set
150
151
  CPATH=/c/libjpeg-turbo-gcc[64]/include
152
  and
153
  LIBRARY_PATH=/c/libjpeg-turbo-gcc[64]/lib
154
155
Building against libjpeg-turbo is useful, for instance, if you want to build an
156
application that leverages the libjpeg-turbo colorspace extensions (see below.)
157
On Linux and Solaris systems, you would still need to manipulate
158
LD_LIBRARY_PATH or create appropriate sym links to use libjpeg-turbo at run
159
time.  On such systems, you can pass -R /opt/libjpeg-turbo/{lib} to the linker
160
to force the use of libjpeg-turbo at run time rather than libjpeg (also useful
161
if you want to leverage the colorspace extensions), or you can link against the
162
libjpeg-turbo static library.
163
164
To force a Linux, Solaris, or MinGW application to link against the static
165
version of libjpeg-turbo, you can use the following linker options:
166
167
  -Wl,-Bstatic -ljpeg -Wl,-Bdynamic
168
169
On OS X, simply add /opt/libjpeg-turbo/lib/libjpeg.a to the linker command
170
line (this also works on Linux and Solaris.)
171
172
To build Visual C++ applications using libjpeg-turbo, add
173
c:\libjpeg-turbo[64]\include to the system or user INCLUDE environment
174
variable and c:\libjpeg-turbo[64]\lib to the system or user LIB environment
175
variable, and then link against either jpeg.lib (to use the DLL version of
176
libjpeg-turbo) or jpeg-static.lib (to use the static version of libjpeg-turbo.)
177
178
=====================
179
Colorspace Extensions
180
=====================
181
182
libjpeg-turbo includes extensions which allow JPEG images to be compressed
183
directly from (and decompressed directly to) buffers which use BGR, BGRX,
184
RGBX, XBGR, and XRGB pixel ordering.  This is implemented with six new
185
colorspace constants:
186
187
  JCS_EXT_RGB   /* red/green/blue */
188
  JCS_EXT_RGBX  /* red/green/blue/x */
189
  JCS_EXT_BGR   /* blue/green/red */
190
  JCS_EXT_BGRX  /* blue/green/red/x */
191
  JCS_EXT_XBGR  /* x/blue/green/red */
192
  JCS_EXT_XRGB  /* x/red/green/blue */
193
194
Setting cinfo.in_color_space (compression) or cinfo.out_color_space
195
(decompression) to one of these values will cause libjpeg-turbo to read the
196
red, green, and blue values from (or write them to) the appropriate position in
197
the pixel when YUV conversion is performed.
198
199
Your application can check for the existence of these extensions at compile
200
time with:
201
202
  #ifdef JCS_EXTENSIONS
203
204
At run time, attempting to use these extensions with a version of libjpeg
205
that doesn't support them will result in a "Bogus input colorspace" error.
206
207
=================================
208
libjpeg v7 and v8 API/ABI support
209
=================================
210
211
libjpeg v7 and v8 added new features to the API/ABI, and, unfortunately, the
212
compression and decompression structures were extended in a backward-
213
incompatible manner to accommodate these features.  Thus, programs which are
214
built to use libjpeg v7 or v8 did not work with libjpeg-turbo, since it is
215
based on the libjpeg v6b code base.  Although libjpeg v7 and v8 are still not
216
as widely used as v6b, enough programs (including a few Linux distros) have
217
made the switch that it was desirable to provide support for the libjpeg v7/v8
218
API/ABI in libjpeg-turbo.
219
220
Some of the libjpeg v7 and v8 features -- DCT scaling, to name one -- involve
221
deep modifications to the code which cannot be accommodated by libjpeg-turbo
222
without either breaking compatibility with libjpeg v6b or producing an
223
unsupportable mess.  In order to fully support libjpeg v8 with all of its
224
features, we would have to essentially port the SIMD extensions to the libjpeg
225
v8 code base and maintain two separate code trees.  We are hesitant to do this
226
until/unless the newer libjpeg code bases garner more community support and
227
involvement and until/unless we have some notion of whether future libjpeg
228
releases will also be backward-incompatible.
229
230
By passing an argument of --with-jpeg7 or --with-jpeg8 to configure, or an
231
argument of -DWITH_JPEG7=1 or -DWITH_JPEG8=1 to cmake, you can build a version
232
of libjpeg-turbo which emulates the libjpeg v7 or v8 API/ABI, so that programs
233
which are built against libjpeg v7 or v8 can be run with libjpeg-turbo.  The
234
following section describes which libjpeg v7+ features are supported and which
235
aren't.
236
237
libjpeg v7 and v8 Features:
238
---------------------------
239
240
Fully supported:
241
242
-- cjpeg: Separate quality settings for luminance and chrominance
243
   Note that the libpjeg v7+ API was extended to accommodate this feature only
244
   for convenience purposes.  It has always been possible to implement this
245
   feature with libjpeg v6b (see rdswitch.c for an example.)
246
247
-- cjpeg: 32-bit BMP support
248
249
-- jpegtran: lossless cropping
250
251
-- jpegtran: -perfect option
252
253
-- rdjpgcom: -raw option
254
255
-- rdjpgcom: locale awareness
256
257
258
Fully supported when using libjpeg v7/v8 emulation:
259
260
-- libjpeg: In-memory source and destination managers
261
262
263
Not supported:
264
265
-- libjpeg: DCT scaling in compressor
266
   cinfo.scale_num and cinfo.scale_denom are silently ignored.
267
268
-- libjpeg: IDCT scaling extensions in decompressor
269
   libjpeg-turbo still supports IDCT scaling with scaling factors of 1/2, 1/4,
270
   and 1/8 (same as libjpeg v6b.)
271
272
-- libjpeg: Fancy downsampling in compressor
273
   cinfo.do_fancy_downsampling is silently ignored.
274
275
-- jpegtran: Scaling
276
   Seems to depend on the DCT scaling feature, which isn't supported.
277
278
279
*******************************************************************************
280
**     Performance pitfalls
281
*******************************************************************************
282
283
===============
284
Restart Markers
285
===============
286
287
The optimized Huffman decoder in libjpeg-turbo does not handle restart markers
288
in a way that makes libjpeg happy, so it is necessary to use the slow Huffman
289
decoder when decompressing a JPEG image that has restart markers.  This can
290
cause the decompression performance to drop by as much as 20%, but the
291
performance will still be much much greater than that of libjpeg v6b.  Many
292
consumer packages, such as PhotoShop, use restart markers when generating JPEG
293
images, so images generated by those programs will experience this issue.
294
295
===============================================
296
Fast Integer Forward DCT at High Quality Levels
297
===============================================
298
299
The algorithm used by the SIMD-accelerated quantization function cannot produce
300
correct results whenever the fast integer forward DCT is used along with a JPEG
301
quality of 98-100.  Thus, libjpeg-turbo must use the non-SIMD quantization
302
function in those cases.  This causes performance to drop by as much as 40%.
303
It is therefore strongly advised that you use the slow integer forward DCT
304
whenever encoding images with a JPEG quality of 98 or higher.
(-)a/jpeg/cderror.h (+2 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * cderror.h
2
 * cderror.h
3
 *
3
 *
4
 * Copyright (C) 1994-1997, Thomas G. Lane.
4
 * Copyright (C) 1994-1997, Thomas G. Lane.
5
 * Modified 2009 by Guido Vollbeding.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file defines the error and message codes for the cjpeg/djpeg
9
 * This file defines the error and message codes for the cjpeg/djpeg
9
 * applications.  These strings are not needed as part of the JPEG library
10
 * applications.  These strings are not needed as part of the JPEG library
10
 * proper.
11
 * proper.
11
 * Edit this file to add new codes, or to translate the message strings to
12
 * Edit this file to add new codes, or to translate the message strings to
12
 * some other language.
13
 * some other language.
 Lines 40-55   JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) Link Here 
40
41
41
#ifdef BMP_SUPPORTED
42
#ifdef BMP_SUPPORTED
42
JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
43
JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
43
JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported")
44
JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported")
44
JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
45
JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
45
JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
46
JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
46
JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
47
JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
47
JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
48
JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
49
JMESSAGE(JERR_BMP_EMPTY, "Empty BMP image")
48
JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
50
JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
49
JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image")
51
JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image")
50
JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
52
JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
51
JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image")
53
JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image")
52
JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
54
JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
53
#endif /* BMP_SUPPORTED */
55
#endif /* BMP_SUPPORTED */
54
56
55
#ifdef GIF_SUPPORTED
57
#ifdef GIF_SUPPORTED
(-)a/jpeg/cdjpeg.c (-181 lines)
Line     Link Here 
 Lines 1-181    Link Here 
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 <ctype.h>		/* to declare isupper(), tolower() */
14
#ifdef NEED_SIGNAL_CATCHER
15
#include <signal.h>		/* to declare signal() */
16
#endif
17
#ifdef USE_SETMODE
18
#include <fcntl.h>		/* to declare setmode()'s parameter macros */
19
/* If you have setmode() but not <io.h>, just delete this line: */
20
#include <io.h>			/* 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
}
(-)a/jpeg/cdjpeg.h (-1 / +4 lines)
Line     Link Here 
 Lines 99-114   typedef struct cdjpeg_progress_mgr * cd_ Link Here 
99
#define jinit_read_ppm		jIRdPPM
99
#define jinit_read_ppm		jIRdPPM
100
#define jinit_write_ppm		jIWrPPM
100
#define jinit_write_ppm		jIWrPPM
101
#define jinit_read_rle		jIRdRLE
101
#define jinit_read_rle		jIRdRLE
102
#define jinit_write_rle		jIWrRLE
102
#define jinit_write_rle		jIWrRLE
103
#define jinit_read_targa	jIRdTarga
103
#define jinit_read_targa	jIRdTarga
104
#define jinit_write_targa	jIWrTarga
104
#define jinit_write_targa	jIWrTarga
105
#define read_quant_tables	RdQTables
105
#define read_quant_tables	RdQTables
106
#define read_scan_script	RdScnScript
106
#define read_scan_script	RdScnScript
107
#define set_quality_ratings     SetQRates
107
#define set_quant_slots		SetQSlots
108
#define set_quant_slots		SetQSlots
108
#define set_sample_factors	SetSFacts
109
#define set_sample_factors	SetSFacts
109
#define read_color_map		RdCMap
110
#define read_color_map		RdCMap
110
#define enable_signal_catcher	EnSigCatcher
111
#define enable_signal_catcher	EnSigCatcher
111
#define start_progress_monitor	StProgMon
112
#define start_progress_monitor	StProgMon
112
#define end_progress_monitor	EnProgMon
113
#define end_progress_monitor	EnProgMon
113
#define read_stdin		RdStdin
114
#define read_stdin		RdStdin
114
#define write_stdout		WrStdout
115
#define write_stdout		WrStdout
 Lines 126-143   EXTERN(djpeg_dest_ptr) jinit_write_ppm J Link Here 
126
EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
127
EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
127
EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));
128
EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));
128
EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));
129
EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));
129
EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
130
EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
130
131
131
/* cjpeg support routines (in rdswitch.c) */
132
/* cjpeg support routines (in rdswitch.c) */
132
133
133
EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
134
EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
134
				    int scale_factor, boolean force_baseline));
135
				       boolean force_baseline));
135
EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));
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));
136
EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
139
EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
137
EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
140
EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
138
141
139
/* djpeg support routines (in rdcolmap.c) */
142
/* djpeg support routines (in rdcolmap.c) */
140
143
141
EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
144
EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
142
145
143
/* common support routines (in cdjpeg.c) */
146
/* common support routines (in cdjpeg.c) */
(-)a/jpeg/change.log (-217 lines)
Line     Link Here 
 Lines 1-217    Link Here 
1
CHANGE LOG for Independent JPEG Group's JPEG software
2
3
4
Version 6b  27-Mar-1998
5
-----------------------
6
7
jpegtran has new features for lossless image transformations (rotation
8
and flipping) as well as "lossless" reduction to grayscale.
9
10
jpegtran now copies comments by default; it has a -copy switch to enable
11
copying all APPn blocks as well, or to suppress comments.  (Formerly it
12
always suppressed comments and APPn blocks.)  jpegtran now also preserves
13
JFIF version and resolution information.
14
15
New decompressor library feature: COM and APPn markers found in the input
16
file can be saved in memory for later use by the application.  (Before,
17
you had to code this up yourself with a custom marker processor.)
18
19
There is an unused field "void * client_data" now in compress and decompress
20
parameter structs; this may be useful in some applications.
21
22
JFIF version number information is now saved by the decoder and accepted by
23
the encoder.  jpegtran uses this to copy the source file's version number,
24
to ensure "jpegtran -copy all" won't create bogus files that contain JFXX
25
extensions but claim to be version 1.01.  Applications that generate their
26
own JFXX extension markers also (finally) have a supported way to cause the
27
encoder to emit JFIF version number 1.02.
28
29
djpeg's trace mode reports JFIF 1.02 thumbnail images as such, rather
30
than as unknown APP0 markers.
31
32
In -verbose mode, djpeg and rdjpgcom will try to print the contents of
33
APP12 markers as text.  Some digital cameras store useful text information
34
in APP12 markers.
35
36
Handling of truncated data streams is more robust: blocks beyond the one in
37
which the error occurs will be output as uniform gray, or left unchanged
38
if decoding a progressive JPEG.  The appearance no longer depends on the
39
Huffman tables being used.
40
41
Huffman tables are checked for validity much more carefully than before.
42
43
To avoid the Unisys LZW patent, djpeg's GIF output capability has been
44
changed to produce "uncompressed GIFs", and cjpeg's GIF input capability
45
has been removed altogether.  We're not happy about it either, but there
46
seems to be no good alternative.
47
48
The configure script now supports building libjpeg as a shared library
49
on many flavors of Unix (all the ones that GNU libtool knows how to
50
build shared libraries for).  Use "./configure --enable-shared" to
51
try this out.
52
53
New jconfig file and makefiles for Microsoft Visual C++ and Developer Studio.
54
Also, a jconfig file and a build script for Metrowerks CodeWarrior
55
on Apple Macintosh.  makefile.dj has been updated for DJGPP v2, and there
56
are miscellaneous other minor improvements in the makefiles.
57
58
jmemmac.c now knows how to create temporary files following Mac System 7
59
conventions.
60
61
djpeg's -map switch is now able to read raw-format PPM files reliably.
62
63
cjpeg -progressive -restart no longer generates any unnecessary DRI markers.
64
65
Multiple calls to jpeg_simple_progression for a single JPEG object
66
no longer leak memory.
67
68
69
Version 6a  7-Feb-96
70
--------------------
71
72
Library initialization sequence modified to detect version mismatches
73
and struct field packing mismatches between library and calling application.
74
This change requires applications to be recompiled, but does not require
75
any application source code change.
76
77
All routine declarations changed to the style "GLOBAL(type) name ...",
78
that is, GLOBAL, LOCAL, METHODDEF, EXTERN are now macros taking the
79
routine's return type as an argument.  This makes it possible to add
80
Microsoft-style linkage keywords to all the routines by changing just
81
these macros.  Note that any application code that was using these macros
82
will have to be changed.
83
84
DCT coefficient quantization tables are now stored in normal array order
85
rather than zigzag order.  Application code that calls jpeg_add_quant_table,
86
or otherwise manipulates quantization tables directly, will need to be
87
changed.  If you need to make such code work with either older or newer
88
versions of the library, a test like "#if JPEG_LIB_VERSION >= 61" is
89
recommended.
90
91
djpeg's trace capability now dumps DQT tables in natural order, not zigzag
92
order.  This allows the trace output to be made into a "-qtables" file
93
more easily.
94
95
New system-dependent memory manager module for use on Apple Macintosh.
96
97
Fix bug in cjpeg's -smooth option: last one or two scanlines would be
98
duplicates of the prior line unless the image height mod 16 was 1 or 2.
99
100
Repair minor problems in VMS, BCC, MC6 makefiles.
101
102
New configure script based on latest GNU Autoconf.
103
104
Correct the list of include files needed by MetroWerks C for ccommand().
105
106
Numerous small documentation updates.
107
108
109
Version 6  2-Aug-95
110
-------------------
111
112
Progressive JPEG support: library can read and write full progressive JPEG
113
files.  A "buffered image" mode supports incremental decoding for on-the-fly
114
display of progressive images.  Simply recompiling an existing IJG-v5-based
115
decoder with v6 should allow it to read progressive files, though of course
116
without any special progressive display.
117
118
New "jpegtran" application performs lossless transcoding between different
119
JPEG formats; primarily, it can be used to convert baseline to progressive
120
JPEG and vice versa.  In support of jpegtran, the library now allows lossless
121
reading and writing of JPEG files as DCT coefficient arrays.  This ability
122
may be of use in other applications.
123
124
Notes for programmers:
125
* We changed jpeg_start_decompress() to be able to suspend; this makes all
126
decoding modes available to suspending-input applications.  However,
127
existing applications that use suspending input will need to be changed
128
to check the return value from jpeg_start_decompress().  You don't need to
129
do anything if you don't use a suspending data source.
130
* We changed the interface to the virtual array routines: access_virt_array
131
routines now take a count of the number of rows to access this time.  The
132
last parameter to request_virt_array routines is now interpreted as the
133
maximum number of rows that may be accessed at once, but not necessarily
134
the height of every access.
135
136
137
Version 5b  15-Mar-95
138
---------------------
139
140
Correct bugs with grayscale images having v_samp_factor > 1.
141
142
jpeg_write_raw_data() now supports output suspension.
143
144
Correct bugs in "configure" script for case of compiling in
145
a directory other than the one containing the source files.
146
147
Repair bug in jquant1.c: sometimes didn't use as many colors as it could.
148
149
Borland C makefile and jconfig file work under either MS-DOS or OS/2.
150
151
Miscellaneous improvements to documentation.
152
153
154
Version 5a  7-Dec-94
155
--------------------
156
157
Changed color conversion roundoff behavior so that grayscale values are
158
represented exactly.  (This causes test image files to change.)
159
160
Make ordered dither use 16x16 instead of 4x4 pattern for a small quality
161
improvement.
162
163
New configure script based on latest GNU Autoconf.
164
Fix configure script to handle CFLAGS correctly.
165
Rename *.auto files to *.cfg, so that configure script still works if
166
file names have been truncated for DOS.
167
168
Fix bug in rdbmp.c: didn't allow for extra data between header and image.
169
170
Modify rdppm.c/wrppm.c to handle 2-byte raw PPM/PGM formats for 12-bit data.
171
172
Fix several bugs in rdrle.c.
173
174
NEED_SHORT_EXTERNAL_NAMES option was broken.
175
176
Revise jerror.h/jerror.c for more flexibility in message table.
177
178
Repair oversight in jmemname.c NO_MKTEMP case: file could be there
179
but unreadable.
180
181
182
Version 5  24-Sep-94
183
--------------------
184
185
Version 5 represents a nearly complete redesign and rewrite of the IJG
186
software.  Major user-visible changes include:
187
  * Automatic configuration simplifies installation for most Unix systems.
188
  * A range of speed vs. image quality tradeoffs are supported.
189
    This includes resizing of an image during decompression: scaling down
190
    by a factor of 1/2, 1/4, or 1/8 is handled very efficiently.
191
  * New programs rdjpgcom and wrjpgcom allow insertion and extraction
192
    of text comments in a JPEG file.
193
194
The application programmer's interface to the library has changed completely.
195
Notable improvements include:
196
  * We have eliminated the use of callback routines for handling the
197
    uncompressed image data.  The application now sees the library as a
198
    set of routines that it calls to read or write image data on a
199
    scanline-by-scanline basis.
200
  * The application image data is represented in a conventional interleaved-
201
    pixel format, rather than as a separate array for each color channel.
202
    This can save a copying step in many programs.
203
  * The handling of compressed data has been cleaned up: the application can
204
    supply routines to source or sink the compressed data.  It is possible to
205
    suspend processing on source/sink buffer overrun, although this is not
206
    supported in all operating modes.
207
  * All static state has been eliminated from the library, so that multiple
208
    instances of compression or decompression can be active concurrently.
209
  * JPEG abbreviated datastream formats are supported, ie, quantization and
210
    Huffman tables can be stored separately from the image data.
211
  * And not only that, but the documentation of the library has improved
212
    considerably!
213
214
215
The last widely used release before the version 5 rewrite was version 4A of
216
18-Feb-93.  Change logs before that point have been discarded, since they
217
are not of much interest after the rewrite.
(-)a/jpeg/cjpeg.c (-606 lines)
Line     Link Here 
 Lines 1-606    Link Here 
1
/*
2
 * cjpeg.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 a command-line user interface for the JPEG compressor.
9
 * It should work on any system with Unix- or MS-DOS-style command lines.
10
 *
11
 * Two different command line styles are permitted, depending on the
12
 * compile-time switch TWO_FILE_COMMANDLINE:
13
 *	cjpeg [options]  inputfile outputfile
14
 *	cjpeg [options]  [inputfile]
15
 * In the second style, output is always to standard output, which you'd
16
 * normally redirect to a file or pipe to some other program.  Input is
17
 * either from a named file or from standard input (typically redirected).
18
 * The second style is convenient on Unix but is unhelpful on systems that
19
 * don't support pipes.  Also, you MUST use the first style if your system
20
 * doesn't do binary I/O to stdin/stdout.
21
 * To simplify script writing, the "-outfile" switch is provided.  The syntax
22
 *	cjpeg [options]  -outfile outputfile  inputfile
23
 * works regardless of which command line style is used.
24
 */
25
26
#include "cdjpeg.h"		/* Common decls for cjpeg/djpeg applications */
27
#include "jversion.h"		/* for version message */
28
29
#ifdef USE_CCOMMAND		/* command-line reader for Macintosh */
30
#ifdef __MWERKS__
31
#include <SIOUX.h>              /* Metrowerks needs this */
32
#include <console.h>		/* ... and this */
33
#endif
34
#ifdef THINK_C
35
#include <console.h>		/* Think declares it here */
36
#endif
37
#endif
38
39
40
/* Create the add-on message string table. */
41
42
#define JMESSAGE(code,string)	string ,
43
44
static const char * const cdjpeg_message_table[] = {
45
#include "cderror.h"
46
  NULL
47
};
48
49
50
/*
51
 * This routine determines what format the input file is,
52
 * and selects the appropriate input-reading module.
53
 *
54
 * To determine which family of input formats the file belongs to,
55
 * we may look only at the first byte of the file, since C does not
56
 * guarantee that more than one character can be pushed back with ungetc.
57
 * Looking at additional bytes would require one of these approaches:
58
 *     1) assume we can fseek() the input file (fails for piped input);
59
 *     2) assume we can push back more than one character (works in
60
 *        some C implementations, but unportable);
61
 *     3) provide our own buffering (breaks input readers that want to use
62
 *        stdio directly, such as the RLE library);
63
 * or  4) don't put back the data, and modify the input_init methods to assume
64
 *        they start reading after the start of file (also breaks RLE library).
65
 * #1 is attractive for MS-DOS but is untenable on Unix.
66
 *
67
 * The most portable solution for file types that can't be identified by their
68
 * first byte is to make the user tell us what they are.  This is also the
69
 * only approach for "raw" file types that contain only arbitrary values.
70
 * We presently apply this method for Targa files.  Most of the time Targa
71
 * files start with 0x00, so we recognize that case.  Potentially, however,
72
 * a Targa file could start with any byte value (byte 0 is the length of the
73
 * seldom-used ID field), so we provide a switch to force Targa input mode.
74
 */
75
76
static boolean is_targa;	/* records user -targa switch */
77
78
79
LOCAL(cjpeg_source_ptr)
80
select_file_type (j_compress_ptr cinfo, FILE * infile)
81
{
82
  int c;
83
84
  if (is_targa) {
85
#ifdef TARGA_SUPPORTED
86
    return jinit_read_targa(cinfo);
87
#else
88
    ERREXIT(cinfo, JERR_TGA_NOTCOMP);
89
#endif
90
  }
91
92
  if ((c = getc(infile)) == EOF)
93
    ERREXIT(cinfo, JERR_INPUT_EMPTY);
94
  if (ungetc(c, infile) == EOF)
95
    ERREXIT(cinfo, JERR_UNGETC_FAILED);
96
97
  switch (c) {
98
#ifdef BMP_SUPPORTED
99
  case 'B':
100
    return jinit_read_bmp(cinfo);
101
#endif
102
#ifdef GIF_SUPPORTED
103
  case 'G':
104
    return jinit_read_gif(cinfo);
105
#endif
106
#ifdef PPM_SUPPORTED
107
  case 'P':
108
    return jinit_read_ppm(cinfo);
109
#endif
110
#ifdef RLE_SUPPORTED
111
  case 'R':
112
    return jinit_read_rle(cinfo);
113
#endif
114
#ifdef TARGA_SUPPORTED
115
  case 0x00:
116
    return jinit_read_targa(cinfo);
117
#endif
118
  default:
119
    ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
120
    break;
121
  }
122
123
  return NULL;			/* suppress compiler warnings */
124
}
125
126
127
/*
128
 * Argument-parsing code.
129
 * The switch parser is designed to be useful with DOS-style command line
130
 * syntax, ie, intermixed switches and file names, where only the switches
131
 * to the left of a given file name affect processing of that file.
132
 * The main program in this file doesn't actually use this capability...
133
 */
134
135
136
static const char * progname;	/* program name for error messages */
137
static char * outfilename;	/* for -outfile switch */
138
139
140
LOCAL(void)
141
usage (void)
142
/* complain about bad command line */
143
{
144
  fprintf(stderr, "usage: %s [switches] ", progname);
145
#ifdef TWO_FILE_COMMANDLINE
146
  fprintf(stderr, "inputfile outputfile\n");
147
#else
148
  fprintf(stderr, "[inputfile]\n");
149
#endif
150
151
  fprintf(stderr, "Switches (names may be abbreviated):\n");
152
  fprintf(stderr, "  -quality N     Compression quality (0..100; 5-95 is useful range)\n");
153
  fprintf(stderr, "  -grayscale     Create monochrome JPEG file\n");
154
#ifdef ENTROPY_OPT_SUPPORTED
155
  fprintf(stderr, "  -optimize      Optimize Huffman table (smaller file, but slow compression)\n");
156
#endif
157
#ifdef C_PROGRESSIVE_SUPPORTED
158
  fprintf(stderr, "  -progressive   Create progressive JPEG file\n");
159
#endif
160
#ifdef TARGA_SUPPORTED
161
  fprintf(stderr, "  -targa         Input file is Targa format (usually not needed)\n");
162
#endif
163
  fprintf(stderr, "Switches for advanced users:\n");
164
#ifdef DCT_ISLOW_SUPPORTED
165
  fprintf(stderr, "  -dct int       Use integer DCT method%s\n",
166
	  (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
167
#endif
168
#ifdef DCT_IFAST_SUPPORTED
169
  fprintf(stderr, "  -dct fast      Use fast integer DCT (less accurate)%s\n",
170
	  (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
171
#endif
172
#ifdef DCT_FLOAT_SUPPORTED
173
  fprintf(stderr, "  -dct float     Use floating-point DCT method%s\n",
174
	  (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
175
#endif
176
  fprintf(stderr, "  -restart N     Set restart interval in rows, or in blocks with B\n");
177
#ifdef INPUT_SMOOTHING_SUPPORTED
178
  fprintf(stderr, "  -smooth N      Smooth dithered input (N=1..100 is strength)\n");
179
#endif
180
  fprintf(stderr, "  -maxmemory N   Maximum memory to use (in kbytes)\n");
181
  fprintf(stderr, "  -outfile name  Specify name for output file\n");
182
  fprintf(stderr, "  -verbose  or  -debug   Emit debug output\n");
183
  fprintf(stderr, "Switches for wizards:\n");
184
#ifdef C_ARITH_CODING_SUPPORTED
185
  fprintf(stderr, "  -arithmetic    Use arithmetic coding\n");
186
#endif
187
  fprintf(stderr, "  -baseline      Force baseline quantization tables\n");
188
  fprintf(stderr, "  -qtables file  Use quantization tables given in file\n");
189
  fprintf(stderr, "  -qslots N[,...]    Set component quantization tables\n");
190
  fprintf(stderr, "  -sample HxV[,...]  Set component sampling factors\n");
191
#ifdef C_MULTISCAN_FILES_SUPPORTED
192
  fprintf(stderr, "  -scans file    Create multi-scan JPEG per script file\n");
193
#endif
194
  exit(EXIT_FAILURE);
195
}
196
197
198
LOCAL(int)
199
parse_switches (j_compress_ptr cinfo, int argc, char **argv,
200
		int last_file_arg_seen, boolean for_real)
201
/* Parse optional switches.
202
 * Returns argv[] index of first file-name argument (== argc if none).
203
 * Any file names with indexes <= last_file_arg_seen are ignored;
204
 * they have presumably been processed in a previous iteration.
205
 * (Pass 0 for last_file_arg_seen on the first or only iteration.)
206
 * for_real is FALSE on the first (dummy) pass; we may skip any expensive
207
 * processing.
208
 */
209
{
210
  int argn;
211
  char * arg;
212
  int quality;			/* -quality parameter */
213
  int q_scale_factor;		/* scaling percentage for -qtables */
214
  boolean force_baseline;
215
  boolean simple_progressive;
216
  char * qtablefile = NULL;	/* saves -qtables filename if any */
217
  char * qslotsarg = NULL;	/* saves -qslots parm if any */
218
  char * samplearg = NULL;	/* saves -sample parm if any */
219
  char * scansarg = NULL;	/* saves -scans parm if any */
220
221
  /* Set up default JPEG parameters. */
222
  /* Note that default -quality level need not, and does not,
223
   * match the default scaling for an explicit -qtables argument.
224
   */
225
  quality = 75;			/* default -quality value */
226
  q_scale_factor = 100;		/* default to no scaling for -qtables */
227
  force_baseline = FALSE;	/* by default, allow 16-bit quantizers */
228
  simple_progressive = FALSE;
229
  is_targa = FALSE;
230
  outfilename = NULL;
231
  cinfo->err->trace_level = 0;
232
233
  /* Scan command line options, adjust parameters */
234
235
  for (argn = 1; argn < argc; argn++) {
236
    arg = argv[argn];
237
    if (*arg != '-') {
238
      /* Not a switch, must be a file name argument */
239
      if (argn <= last_file_arg_seen) {
240
	outfilename = NULL;	/* -outfile applies to just one input file */
241
	continue;		/* ignore this name if previously processed */
242
      }
243
      break;			/* else done parsing switches */
244
    }
245
    arg++;			/* advance past switch marker character */
246
247
    if (keymatch(arg, "arithmetic", 1)) {
248
      /* Use arithmetic coding. */
249
#ifdef C_ARITH_CODING_SUPPORTED
250
      cinfo->arith_code = TRUE;
251
#else
252
      fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
253
	      progname);
254
      exit(EXIT_FAILURE);
255
#endif
256
257
    } else if (keymatch(arg, "baseline", 1)) {
258
      /* Force baseline-compatible output (8-bit quantizer values). */
259
      force_baseline = TRUE;
260
261
    } else if (keymatch(arg, "dct", 2)) {
262
      /* Select DCT algorithm. */
263
      if (++argn >= argc)	/* advance to next argument */
264
	usage();
265
      if (keymatch(argv[argn], "int", 1)) {
266
	cinfo->dct_method = JDCT_ISLOW;
267
      } else if (keymatch(argv[argn], "fast", 2)) {
268
	cinfo->dct_method = JDCT_IFAST;
269
      } else if (keymatch(argv[argn], "float", 2)) {
270
	cinfo->dct_method = JDCT_FLOAT;
271
      } else
272
	usage();
273
274
    } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
275
      /* Enable debug printouts. */
276
      /* On first -d, print version identification */
277
      static boolean printed_version = FALSE;
278
279
      if (! printed_version) {
280
	fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n",
281
		JVERSION, JCOPYRIGHT);
282
	printed_version = TRUE;
283
      }
284
      cinfo->err->trace_level++;
285
286
    } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
287
      /* Force a monochrome JPEG file to be generated. */
288
      jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
289
290
    } else if (keymatch(arg, "maxmemory", 3)) {
291
      /* Maximum memory in Kb (or Mb with 'm'). */
292
      long lval;
293
      char ch = 'x';
294
295
      if (++argn >= argc)	/* advance to next argument */
296
	usage();
297
      if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
298
	usage();
299
      if (ch == 'm' || ch == 'M')
300
	lval *= 1000L;
301
      cinfo->mem->max_memory_to_use = lval * 1000L;
302
303
    } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
304
      /* Enable entropy parm optimization. */
305
#ifdef ENTROPY_OPT_SUPPORTED
306
      cinfo->optimize_coding = TRUE;
307
#else
308
      fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
309
	      progname);
310
      exit(EXIT_FAILURE);
311
#endif
312
313
    } else if (keymatch(arg, "outfile", 4)) {
314
      /* Set output file name. */
315
      if (++argn >= argc)	/* advance to next argument */
316
	usage();
317
      outfilename = argv[argn];	/* save it away for later use */
318
319
    } else if (keymatch(arg, "progressive", 1)) {
320
      /* Select simple progressive mode. */
321
#ifdef C_PROGRESSIVE_SUPPORTED
322
      simple_progressive = TRUE;
323
      /* We must postpone execution until num_components is known. */
324
#else
325
      fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
326
	      progname);
327
      exit(EXIT_FAILURE);
328
#endif
329
330
    } else if (keymatch(arg, "quality", 1)) {
331
      /* Quality factor (quantization table scaling factor). */
332
      if (++argn >= argc)	/* advance to next argument */
333
	usage();
334
      if (sscanf(argv[argn], "%d", &quality) != 1)
335
	usage();
336
      /* Change scale factor in case -qtables is present. */
337
      q_scale_factor = jpeg_quality_scaling(quality);
338
339
    } else if (keymatch(arg, "qslots", 2)) {
340
      /* Quantization table slot numbers. */
341
      if (++argn >= argc)	/* advance to next argument */
342
	usage();
343
      qslotsarg = argv[argn];
344
      /* Must delay setting qslots until after we have processed any
345
       * colorspace-determining switches, since jpeg_set_colorspace sets
346
       * default quant table numbers.
347
       */
348
349
    } else if (keymatch(arg, "qtables", 2)) {
350
      /* Quantization tables fetched from file. */
351
      if (++argn >= argc)	/* advance to next argument */
352
	usage();
353
      qtablefile = argv[argn];
354
      /* We postpone actually reading the file in case -quality comes later. */
355
356
    } else if (keymatch(arg, "restart", 1)) {
357
      /* Restart interval in MCU rows (or in MCUs with 'b'). */
358
      long lval;
359
      char ch = 'x';
360
361
      if (++argn >= argc)	/* advance to next argument */
362
	usage();
363
      if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
364
	usage();
365
      if (lval < 0 || lval > 65535L)
366
	usage();
367
      if (ch == 'b' || ch == 'B') {
368
	cinfo->restart_interval = (unsigned int) lval;
369
	cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
370
      } else {
371
	cinfo->restart_in_rows = (int) lval;
372
	/* restart_interval will be computed during startup */
373
      }
374
375
    } else if (keymatch(arg, "sample", 2)) {
376
      /* Set sampling factors. */
377
      if (++argn >= argc)	/* advance to next argument */
378
	usage();
379
      samplearg = argv[argn];
380
      /* Must delay setting sample factors until after we have processed any
381
       * colorspace-determining switches, since jpeg_set_colorspace sets
382
       * default sampling factors.
383
       */
384
385
    } else if (keymatch(arg, "scans", 2)) {
386
      /* Set scan script. */
387
#ifdef C_MULTISCAN_FILES_SUPPORTED
388
      if (++argn >= argc)	/* advance to next argument */
389
	usage();
390
      scansarg = argv[argn];
391
      /* We must postpone reading the file in case -progressive appears. */
392
#else
393
      fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
394
	      progname);
395
      exit(EXIT_FAILURE);
396
#endif
397
398
    } else if (keymatch(arg, "smooth", 2)) {
399
      /* Set input smoothing factor. */
400
      int val;
401
402
      if (++argn >= argc)	/* advance to next argument */
403
	usage();
404
      if (sscanf(argv[argn], "%d", &val) != 1)
405
	usage();
406
      if (val < 0 || val > 100)
407
	usage();
408
      cinfo->smoothing_factor = val;
409
410
    } else if (keymatch(arg, "targa", 1)) {
411
      /* Input file is Targa format. */
412
      is_targa = TRUE;
413
414
    } else {
415
      usage();			/* bogus switch */
416
    }
417
  }
418
419
  /* Post-switch-scanning cleanup */
420
421
  if (for_real) {
422
423
    /* Set quantization tables for selected quality. */
424
    /* Some or all may be overridden if -qtables is present. */
425
    jpeg_set_quality(cinfo, quality, force_baseline);
426
427
    if (qtablefile != NULL)	/* process -qtables if it was present */
428
      if (! read_quant_tables(cinfo, qtablefile,
429
			      q_scale_factor, force_baseline))
430
	usage();
431
432
    if (qslotsarg != NULL)	/* process -qslots if it was present */
433
      if (! set_quant_slots(cinfo, qslotsarg))
434
	usage();
435
436
    if (samplearg != NULL)	/* process -sample if it was present */
437
      if (! set_sample_factors(cinfo, samplearg))
438
	usage();
439
440
#ifdef C_PROGRESSIVE_SUPPORTED
441
    if (simple_progressive)	/* process -progressive; -scans can override */
442
      jpeg_simple_progression(cinfo);
443
#endif
444
445
#ifdef C_MULTISCAN_FILES_SUPPORTED
446
    if (scansarg != NULL)	/* process -scans if it was present */
447
      if (! read_scan_script(cinfo, scansarg))
448
	usage();
449
#endif
450
  }
451
452
  return argn;			/* return index of next arg (file name) */
453
}
454
455
456
/*
457
 * The main program.
458
 */
459
460
int
461
main (int argc, char **argv)
462
{
463
  struct jpeg_compress_struct cinfo;
464
  struct jpeg_error_mgr jerr;
465
#ifdef PROGRESS_REPORT
466
  struct cdjpeg_progress_mgr progress;
467
#endif
468
  int file_index;
469
  cjpeg_source_ptr src_mgr;
470
  FILE * input_file;
471
  FILE * output_file;
472
  JDIMENSION num_scanlines;
473
474
  /* On Mac, fetch a command line. */
475
#ifdef USE_CCOMMAND
476
  argc = ccommand(&argv);
477
#endif
478
479
  progname = argv[0];
480
  if (progname == NULL || progname[0] == 0)
481
    progname = "cjpeg";		/* in case C library doesn't provide it */
482
483
  /* Initialize the JPEG compression object with default error handling. */
484
  cinfo.err = jpeg_std_error(&jerr);
485
  jpeg_create_compress(&cinfo);
486
  /* Add some application-specific error messages (from cderror.h) */
487
  jerr.addon_message_table = cdjpeg_message_table;
488
  jerr.first_addon_message = JMSG_FIRSTADDONCODE;
489
  jerr.last_addon_message = JMSG_LASTADDONCODE;
490
491
  /* Now safe to enable signal catcher. */
492
#ifdef NEED_SIGNAL_CATCHER
493
  enable_signal_catcher((j_common_ptr) &cinfo);
494
#endif
495
496
  /* Initialize JPEG parameters.
497
   * Much of this may be overridden later.
498
   * In particular, we don't yet know the input file's color space,
499
   * but we need to provide some value for jpeg_set_defaults() to work.
500
   */
501
502
  cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
503
  jpeg_set_defaults(&cinfo);
504
505
  /* Scan command line to find file names.
506
   * It is convenient to use just one switch-parsing routine, but the switch
507
   * values read here are ignored; we will rescan the switches after opening
508
   * the input file.
509
   */
510
511
  file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
512
513
#ifdef TWO_FILE_COMMANDLINE
514
  /* Must have either -outfile switch or explicit output file name */
515
  if (outfilename == NULL) {
516
    if (file_index != argc-2) {
517
      fprintf(stderr, "%s: must name one input and one output file\n",
518
	      progname);
519
      usage();
520
    }
521
    outfilename = argv[file_index+1];
522
  } else {
523
    if (file_index != argc-1) {
524
      fprintf(stderr, "%s: must name one input and one output file\n",
525
	      progname);
526
      usage();
527
    }
528
  }
529
#else
530
  /* Unix style: expect zero or one file name */
531
  if (file_index < argc-1) {
532
    fprintf(stderr, "%s: only one input file\n", progname);
533
    usage();
534
  }
535
#endif /* TWO_FILE_COMMANDLINE */
536
537
  /* Open the input file. */
538
  if (file_index < argc) {
539
    if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
540
      fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
541
      exit(EXIT_FAILURE);
542
    }
543
  } else {
544
    /* default input file is stdin */
545
    input_file = read_stdin();
546
  }
547
548
  /* Open the output file. */
549
  if (outfilename != NULL) {
550
    if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
551
      fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
552
      exit(EXIT_FAILURE);
553
    }
554
  } else {
555
    /* default output file is stdout */
556
    output_file = write_stdout();
557
  }
558
559
#ifdef PROGRESS_REPORT
560
  start_progress_monitor((j_common_ptr) &cinfo, &progress);
561
#endif
562
563
  /* Figure out the input file format, and set up to read it. */
564
  src_mgr = select_file_type(&cinfo, input_file);
565
  src_mgr->input_file = input_file;
566
567
  /* Read the input file header to obtain file size & colorspace. */
568
  (*src_mgr->start_input) (&cinfo, src_mgr);
569
570
  /* Now that we know input colorspace, fix colorspace-dependent defaults */
571
  jpeg_default_colorspace(&cinfo);
572
573
  /* Adjust default compression parameters by re-parsing the options */
574
  file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
575
576
  /* Specify data destination for compression */
577
  jpeg_stdio_dest(&cinfo, output_file);
578
579
  /* Start compressor */
580
  jpeg_start_compress(&cinfo, TRUE);
581
582
  /* Process data */
583
  while (cinfo.next_scanline < cinfo.image_height) {
584
    num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
585
    (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
586
  }
587
588
  /* Finish compression and release memory */
589
  (*src_mgr->finish_input) (&cinfo, src_mgr);
590
  jpeg_finish_compress(&cinfo);
591
  jpeg_destroy_compress(&cinfo);
592
593
  /* Close files, if we opened them */
594
  if (input_file != stdin)
595
    fclose(input_file);
596
  if (output_file != stdout)
597
    fclose(output_file);
598
599
#ifdef PROGRESS_REPORT
600
  end_progress_monitor((j_common_ptr) &cinfo);
601
#endif
602
603
  /* All done. */
604
  exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
605
  return 0;			/* suppress no-return-value warnings */
606
}
(-)a/jpeg/ckconfig.c (-402 lines)
Line     Link Here 
 Lines 1-402    Link Here 
1
/*
2
 * ckconfig.c
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
9
/*
10
 * This program is intended to help you determine how to configure the JPEG
11
 * software for installation on a particular system.  The idea is to try to
12
 * compile and execute this program.  If your compiler fails to compile the
13
 * program, make changes as indicated in the comments below.  Once you can
14
 * compile the program, run it, and it will produce a "jconfig.h" file for
15
 * your system.
16
 *
17
 * As a general rule, each time you try to compile this program,
18
 * pay attention only to the *first* error message you get from the compiler.
19
 * Many C compilers will issue lots of spurious error messages once they
20
 * have gotten confused.  Go to the line indicated in the first error message,
21
 * and read the comments preceding that line to see what to change.
22
 *
23
 * Almost all of the edits you may need to make to this program consist of
24
 * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL",
25
 * or vice versa.  This is called defining or undefining that symbol.
26
 */
27
28
29
/* First we must see if your system has the include files we need.
30
 * We start out with the assumption that your system has all the ANSI-standard
31
 * include files.  If you get any error trying to include one of these files,
32
 * undefine the corresponding HAVE_xxx symbol.
33
 */
34
35
#define HAVE_STDDEF_H		/* replace 'define' by 'undef' if error here */
36
#ifdef HAVE_STDDEF_H		/* next line will be skipped if you undef... */
37
#include <stddef.h>
38
#endif
39
40
#define HAVE_STDLIB_H		/* same thing for stdlib.h */
41
#ifdef HAVE_STDLIB_H
42
#include <stdlib.h>
43
#endif
44
45
#include <stdio.h>		/* If you ain't got this, you ain't got C. */
46
47
/* We have to see if your string functions are defined by
48
 * strings.h (old BSD convention) or string.h (everybody else).
49
 * We try the non-BSD convention first; define NEED_BSD_STRINGS
50
 * if the compiler says it can't find string.h.
51
 */
52
53
#undef NEED_BSD_STRINGS
54
55
#ifdef NEED_BSD_STRINGS
56
#include <strings.h>
57
#else
58
#include <string.h>
59
#endif
60
61
/* On some systems (especially older Unix machines), type size_t is
62
 * defined only in the include file <sys/types.h>.  If you get a failure
63
 * on the size_t test below, try defining NEED_SYS_TYPES_H.
64
 */
65
66
#undef NEED_SYS_TYPES_H		/* start by assuming we don't need it */
67
#ifdef NEED_SYS_TYPES_H
68
#include <sys/types.h>
69
#endif
70
71
72
/* Usually type size_t is defined in one of the include files we've included
73
 * above.  If not, you'll get an error on the "typedef size_t my_size_t;" line.
74
 * In that case, first try defining NEED_SYS_TYPES_H just above.
75
 * If that doesn't work, you'll have to search through your system library
76
 * to figure out which include file defines "size_t".  Look for a line that
77
 * says "typedef something-or-other size_t;".  Then, change the line below
78
 * that says "#include <someincludefile.h>" to instead include the file
79
 * you found size_t in, and define NEED_SPECIAL_INCLUDE.  If you can't find
80
 * type size_t anywhere, try replacing "#include <someincludefile.h>" with
81
 * "typedef unsigned int size_t;".
82
 */
83
84
#undef NEED_SPECIAL_INCLUDE	/* assume we DON'T need it, for starters */
85
86
#ifdef NEED_SPECIAL_INCLUDE
87
#include <someincludefile.h>
88
#endif
89
90
typedef size_t my_size_t;	/* The payoff: do we have size_t now? */
91
92
93
/* The next question is whether your compiler supports ANSI-style function
94
 * prototypes.  You need to know this in order to choose between using
95
 * makefile.ansi and using makefile.unix.
96
 * The #define line below is set to assume you have ANSI function prototypes.
97
 * If you get an error in this group of lines, undefine HAVE_PROTOTYPES.
98
 */
99
100
#define HAVE_PROTOTYPES
101
102
#ifdef HAVE_PROTOTYPES
103
int testfunction (int arg1, int * arg2); /* check prototypes */
104
105
struct methods_struct {		/* check method-pointer declarations */
106
  int (*error_exit) (char *msgtext);
107
  int (*trace_message) (char *msgtext);
108
  int (*another_method) (void);
109
};
110
111
int testfunction (int arg1, int * arg2) /* check definitions */
112
{
113
  return arg2[arg1];
114
}
115
116
int test2function (void)	/* check void arg list */
117
{
118
  return 0;
119
}
120
#endif
121
122
123
/* Now we want to find out if your compiler knows what "unsigned char" means.
124
 * If you get an error on the "unsigned char un_char;" line,
125
 * then undefine HAVE_UNSIGNED_CHAR.
126
 */
127
128
#define HAVE_UNSIGNED_CHAR
129
130
#ifdef HAVE_UNSIGNED_CHAR
131
unsigned char un_char;
132
#endif
133
134
135
/* Now we want to find out if your compiler knows what "unsigned short" means.
136
 * If you get an error on the "unsigned short un_short;" line,
137
 * then undefine HAVE_UNSIGNED_SHORT.
138
 */
139
140
#define HAVE_UNSIGNED_SHORT
141
142
#ifdef HAVE_UNSIGNED_SHORT
143
unsigned short un_short;
144
#endif
145
146
147
/* Now we want to find out if your compiler understands type "void".
148
 * If you get an error anywhere in here, undefine HAVE_VOID.
149
 */
150
151
#define HAVE_VOID
152
153
#ifdef HAVE_VOID
154
/* Caution: a C++ compiler will insist on complete prototypes */
155
typedef void * void_ptr;	/* check void * */
156
#ifdef HAVE_PROTOTYPES		/* check ptr to function returning void */
157
typedef void (*void_func) (int a, int b);
158
#else
159
typedef void (*void_func) ();
160
#endif
161
162
#ifdef HAVE_PROTOTYPES		/* check void function result */
163
void test3function (void_ptr arg1, void_func arg2)
164
#else
165
void test3function (arg1, arg2)
166
     void_ptr arg1;
167
     void_func arg2;
168
#endif
169
{
170
  char * locptr = (char *) arg1; /* check casting to and from void * */
171
  arg1 = (void *) locptr;
172
  (*arg2) (1, 2);		/* check call of fcn returning void */
173
}
174
#endif
175
176
177
/* Now we want to find out if your compiler knows what "const" means.
178
 * If you get an error here, undefine HAVE_CONST.
179
 */
180
181
#define HAVE_CONST
182
183
#ifdef HAVE_CONST
184
static const int carray[3] = {1, 2, 3};
185
186
#ifdef HAVE_PROTOTYPES
187
int test4function (const int arg1)
188
#else
189
int test4function (arg1)
190
     const int arg1;
191
#endif
192
{
193
  return carray[arg1];
194
}
195
#endif
196
197
198
/* If you get an error or warning about this structure definition,
199
 * define INCOMPLETE_TYPES_BROKEN.
200
 */
201
202
#undef INCOMPLETE_TYPES_BROKEN
203
204
#ifndef INCOMPLETE_TYPES_BROKEN
205
typedef struct undefined_structure * undef_struct_ptr;
206
#endif
207
208
209
/* If you get an error about duplicate names,
210
 * define NEED_SHORT_EXTERNAL_NAMES.
211
 */
212
213
#undef NEED_SHORT_EXTERNAL_NAMES
214
215
#ifndef NEED_SHORT_EXTERNAL_NAMES
216
217
int possibly_duplicate_function ()
218
{
219
  return 0;
220
}
221
222
int possibly_dupli_function ()
223
{
224
  return 1;
225
}
226
227
#endif
228
229
230
231
/************************************************************************
232
 *  OK, that's it.  You should not have to change anything beyond this
233
 *  point in order to compile and execute this program.  (You might get
234
 *  some warnings, but you can ignore them.)
235
 *  When you run the program, it will make a couple more tests that it
236
 *  can do automatically, and then it will create jconfig.h and print out
237
 *  any additional suggestions it has.
238
 ************************************************************************
239
 */
240
241
242
#ifdef HAVE_PROTOTYPES
243
int is_char_signed (int arg)
244
#else
245
int is_char_signed (arg)
246
     int arg;
247
#endif
248
{
249
  if (arg == 189) {		/* expected result for unsigned char */
250
    return 0;			/* type char is unsigned */
251
  }
252
  else if (arg != -67) {	/* expected result for signed char */
253
    printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
254
    printf("I fear the JPEG software will not work at all.\n\n");
255
  }
256
  return 1;			/* assume char is signed otherwise */
257
}
258
259
260
#ifdef HAVE_PROTOTYPES
261
int is_shifting_signed (long arg)
262
#else
263
int is_shifting_signed (arg)
264
     long arg;
265
#endif
266
/* See whether right-shift on a long is signed or not. */
267
{
268
  long res = arg >> 4;
269
270
  if (res == -0x7F7E80CL) {	/* expected result for signed shift */
271
    return 1;			/* right shift is signed */
272
  }
273
  /* see if unsigned-shift hack will fix it. */
274
  /* we can't just test exact value since it depends on width of long... */
275
  res |= (~0L) << (32-4);
276
  if (res == -0x7F7E80CL) {	/* expected result now? */
277
    return 0;			/* right shift is unsigned */
278
  }
279
  printf("Right shift isn't acting as I expect it to.\n");
280
  printf("I fear the JPEG software will not work at all.\n\n");
281
  return 0;			/* try it with unsigned anyway */
282
}
283
284
285
#ifdef HAVE_PROTOTYPES
286
int main (int argc, char ** argv)
287
#else
288
int main (argc, argv)
289
     int argc;
290
     char ** argv;
291
#endif
292
{
293
  char signed_char_check = (char) (-67);
294
  FILE *outfile;
295
296
  /* Attempt to write jconfig.h */
297
  if ((outfile = fopen("jconfig.h", "w")) == NULL) {
298
    printf("Failed to write jconfig.h\n");
299
    return 1;
300
  }
301
302
  /* Write out all the info */
303
  fprintf(outfile, "/* jconfig.h --- generated by ckconfig.c */\n");
304
  fprintf(outfile, "/* see jconfig.doc for explanations */\n\n");
305
#ifdef HAVE_PROTOTYPES
306
  fprintf(outfile, "#define HAVE_PROTOTYPES\n");
307
#else
308
  fprintf(outfile, "#undef HAVE_PROTOTYPES\n");
309
#endif
310
#ifdef HAVE_UNSIGNED_CHAR
311
  fprintf(outfile, "#define HAVE_UNSIGNED_CHAR\n");
312
#else
313
  fprintf(outfile, "#undef HAVE_UNSIGNED_CHAR\n");
314
#endif
315
#ifdef HAVE_UNSIGNED_SHORT
316
  fprintf(outfile, "#define HAVE_UNSIGNED_SHORT\n");
317
#else
318
  fprintf(outfile, "#undef HAVE_UNSIGNED_SHORT\n");
319
#endif
320
#ifdef HAVE_VOID
321
  fprintf(outfile, "/* #define void char */\n");
322
#else
323
  fprintf(outfile, "#define void char\n");
324
#endif
325
#ifdef HAVE_CONST
326
  fprintf(outfile, "/* #define const */\n");
327
#else
328
  fprintf(outfile, "#define const\n");
329
#endif
330
  if (is_char_signed((int) signed_char_check))
331
    fprintf(outfile, "#undef CHAR_IS_UNSIGNED\n");
332
  else
333
    fprintf(outfile, "#define CHAR_IS_UNSIGNED\n");
334
#ifdef HAVE_STDDEF_H
335
  fprintf(outfile, "#define HAVE_STDDEF_H\n");
336
#else
337
  fprintf(outfile, "#undef HAVE_STDDEF_H\n");
338
#endif
339
#ifdef HAVE_STDLIB_H
340
  fprintf(outfile, "#define HAVE_STDLIB_H\n");
341
#else
342
  fprintf(outfile, "#undef HAVE_STDLIB_H\n");
343
#endif
344
#ifdef NEED_BSD_STRINGS
345
  fprintf(outfile, "#define NEED_BSD_STRINGS\n");
346
#else
347
  fprintf(outfile, "#undef NEED_BSD_STRINGS\n");
348
#endif
349
#ifdef NEED_SYS_TYPES_H
350
  fprintf(outfile, "#define NEED_SYS_TYPES_H\n");
351
#else
352
  fprintf(outfile, "#undef NEED_SYS_TYPES_H\n");
353
#endif
354
  fprintf(outfile, "#undef NEED_FAR_POINTERS\n");
355
#ifdef NEED_SHORT_EXTERNAL_NAMES
356
  fprintf(outfile, "#define NEED_SHORT_EXTERNAL_NAMES\n");
357
#else
358
  fprintf(outfile, "#undef NEED_SHORT_EXTERNAL_NAMES\n");
359
#endif
360
#ifdef INCOMPLETE_TYPES_BROKEN
361
  fprintf(outfile, "#define INCOMPLETE_TYPES_BROKEN\n");
362
#else
363
  fprintf(outfile, "#undef INCOMPLETE_TYPES_BROKEN\n");
364
#endif
365
  fprintf(outfile, "\n#ifdef JPEG_INTERNALS\n\n");
366
  if (is_shifting_signed(-0x7F7E80B1L))
367
    fprintf(outfile, "#undef RIGHT_SHIFT_IS_UNSIGNED\n");
368
  else
369
    fprintf(outfile, "#define RIGHT_SHIFT_IS_UNSIGNED\n");
370
  fprintf(outfile, "\n#endif /* JPEG_INTERNALS */\n");
371
  fprintf(outfile, "\n#ifdef JPEG_CJPEG_DJPEG\n\n");
372
  fprintf(outfile, "#define BMP_SUPPORTED		/* BMP image file format */\n");
373
  fprintf(outfile, "#define GIF_SUPPORTED		/* GIF image file format */\n");
374
  fprintf(outfile, "#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */\n");
375
  fprintf(outfile, "#undef RLE_SUPPORTED		/* Utah RLE image file format */\n");
376
  fprintf(outfile, "#define TARGA_SUPPORTED		/* Targa image file format */\n\n");
377
  fprintf(outfile, "#undef TWO_FILE_COMMANDLINE	/* You may need this on non-Unix systems */\n");
378
  fprintf(outfile, "#undef NEED_SIGNAL_CATCHER	/* Define this if you use jmemname.c */\n");
379
  fprintf(outfile, "#undef DONT_USE_B_MODE\n");
380
  fprintf(outfile, "/* #define PROGRESS_REPORT */	/* optional */\n");
381
  fprintf(outfile, "\n#endif /* JPEG_CJPEG_DJPEG */\n");
382
383
  /* Close the jconfig.h file */
384
  fclose(outfile);
385
386
  /* User report */
387
  printf("Configuration check for Independent JPEG Group's software done.\n");
388
  printf("\nI have written the jconfig.h file for you.\n\n");
389
#ifdef HAVE_PROTOTYPES
390
  printf("You should use makefile.ansi as the starting point for your Makefile.\n");
391
#else
392
  printf("You should use makefile.unix as the starting point for your Makefile.\n");
393
#endif
394
395
#ifdef NEED_SPECIAL_INCLUDE
396
  printf("\nYou'll need to change jconfig.h to include the system include file\n");
397
  printf("that you found type size_t in, or add a direct definition of type\n");
398
  printf("size_t if that's what you used.  Just add it to the end.\n");
399
#endif
400
401
  return 0;
402
}
(-)a/jpeg/coderules.doc (-118 lines)
Line     Link Here 
 Lines 1-118    Link Here 
1
IJG JPEG LIBRARY:  CODING RULES
2
3
Copyright (C) 1991-1996, Thomas G. Lane.
4
This file is part of the Independent JPEG Group's software.
5
For conditions of distribution and use, see the accompanying README file.
6
7
8
Since numerous people will be contributing code and bug fixes, it's important
9
to establish a common coding style.  The goal of using similar coding styles
10
is much more important than the details of just what that style is.
11
12
In general we follow the recommendations of "Recommended C Style and Coding
13
Standards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and
14
Brader).  This document is available in the IJG FTP archive (see
15
jpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl).
16
17
Block comments should be laid out thusly:
18
19
/*
20
 *  Block comments in this style.
21
 */
22
23
We indent statements in K&R style, e.g.,
24
	if (test) {
25
	  then-part;
26
	} else {
27
	  else-part;
28
	}
29
with two spaces per indentation level.  (This indentation convention is
30
handled automatically by GNU Emacs and many other text editors.)
31
32
Multi-word names should be written in lower case with underscores, e.g.,
33
multi_word_name (not multiWordName).  Preprocessor symbols and enum constants
34
are similar but upper case (MULTI_WORD_NAME).  Names should be unique within
35
the first fifteen characters.  (On some older systems, global names must be
36
unique within six characters.  We accommodate this without cluttering the
37
source code by using macros to substitute shorter names.)
38
39
We use function prototypes everywhere; we rely on automatic source code
40
transformation to feed prototype-less C compilers.  Transformation is done
41
by the simple and portable tool 'ansi2knr.c' (courtesy of Ghostscript).
42
ansi2knr is not very bright, so it imposes a format requirement on function
43
declarations: the function name MUST BEGIN IN COLUMN 1.  Thus all functions
44
should be written in the following style:
45
46
LOCAL(int *)
47
function_name (int a, char *b)
48
{
49
    code...
50
}
51
52
Note that each function definition must begin with GLOBAL(type), LOCAL(type),
53
or METHODDEF(type).  These macros expand to "static type" or just "type" as
54
appropriate.  They provide a readable indication of the routine's usage and
55
can readily be changed for special needs.  (For instance, special linkage
56
keywords can be inserted for use in Windows DLLs.)
57
58
ansi2knr does not transform method declarations (function pointers in
59
structs).  We handle these with a macro JMETHOD, defined as
60
	#ifdef HAVE_PROTOTYPES
61
	#define JMETHOD(type,methodname,arglist)  type (*methodname) arglist
62
	#else
63
	#define JMETHOD(type,methodname,arglist)  type (*methodname) ()
64
	#endif
65
which is used like this:
66
	struct function_pointers {
67
	  JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp));
68
	  JMETHOD(void, term_entropy_encoder, (void));
69
	};
70
Note the set of parentheses surrounding the parameter list.
71
72
A similar solution is used for forward and external function declarations
73
(see the EXTERN and JPP macros).
74
75
If the code is to work on non-ANSI compilers, we cannot rely on a prototype
76
declaration to coerce actual parameters into the right types.  Therefore, use
77
explicit casts on actual parameters whenever the actual parameter type is not
78
identical to the formal parameter.  Beware of implicit conversions to "int".
79
80
It seems there are some non-ANSI compilers in which the sizeof() operator
81
is defined to return int, yet size_t is defined as long.  Needless to say,
82
this is brain-damaged.  Always use the SIZEOF() macro in place of sizeof(),
83
so that the result is guaranteed to be of type size_t.
84
85
86
The JPEG library is intended to be used within larger programs.  Furthermore,
87
we want it to be reentrant so that it can be used by applications that process
88
multiple images concurrently.  The following rules support these requirements:
89
90
1. Avoid direct use of file I/O, "malloc", error report printouts, etc;
91
pass these through the common routines provided.
92
93
2. Minimize global namespace pollution.  Functions should be declared static
94
wherever possible.  (Note that our method-based calling conventions help this
95
a lot: in many modules only the initialization function will ever need to be
96
called directly, so only that function need be externally visible.)  All
97
global function names should begin with "jpeg_", and should have an
98
abbreviated name (unique in the first six characters) substituted by macro
99
when NEED_SHORT_EXTERNAL_NAMES is set.
100
101
3. Don't use global variables; anything that must be used in another module
102
should be in the common data structures.
103
104
4. Don't use static variables except for read-only constant tables.  Variables
105
that should be private to a module can be placed into private structures (see
106
the system architecture document, structure.doc).
107
108
5. Source file names should begin with "j" for files that are part of the
109
library proper; source files that are not part of the library, such as cjpeg.c
110
and djpeg.c, do not begin with "j".  Keep source file names to eight
111
characters (plus ".c" or ".h", etc) to make life easy for MS-DOSers.  Keep
112
compression and decompression code in separate source files --- some
113
applications may want only one half of the library.
114
115
Note: these rules (particularly #4) are not followed religiously in the
116
modules that are used in cjpeg/djpeg but are not part of the JPEG library
117
proper.  Those modules are not really intended to be used in other
118
applications.
(-)a/jpeg/djpeg.c (-616 lines)
Line     Link Here 
 Lines 1-616    Link Here 
1
/*
2
 * djpeg.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 a command-line user interface for the JPEG decompressor.
9
 * It should work on any system with Unix- or MS-DOS-style command lines.
10
 *
11
 * Two different command line styles are permitted, depending on the
12
 * compile-time switch TWO_FILE_COMMANDLINE:
13
 *	djpeg [options]  inputfile outputfile
14
 *	djpeg [options]  [inputfile]
15
 * In the second style, output is always to standard output, which you'd
16
 * normally redirect to a file or pipe to some other program.  Input is
17
 * either from a named file or from standard input (typically redirected).
18
 * The second style is convenient on Unix but is unhelpful on systems that
19
 * don't support pipes.  Also, you MUST use the first style if your system
20
 * doesn't do binary I/O to stdin/stdout.
21
 * To simplify script writing, the "-outfile" switch is provided.  The syntax
22
 *	djpeg [options]  -outfile outputfile  inputfile
23
 * works regardless of which command line style is used.
24
 */
25
26
#include "cdjpeg.h"		/* Common decls for cjpeg/djpeg applications */
27
#include "jversion.h"		/* for version message */
28
29
#include <ctype.h>		/* to declare isprint() */
30
31
#ifdef USE_CCOMMAND		/* command-line reader for Macintosh */
32
#ifdef __MWERKS__
33
#include <SIOUX.h>              /* Metrowerks needs this */
34
#include <console.h>		/* ... and this */
35
#endif
36
#ifdef THINK_C
37
#include <console.h>		/* Think declares it here */
38
#endif
39
#endif
40
41
42
/* Create the add-on message string table. */
43
44
#define JMESSAGE(code,string)	string ,
45
46
static const char * const cdjpeg_message_table[] = {
47
#include "cderror.h"
48
  NULL
49
};
50
51
52
/*
53
 * This list defines the known output image formats
54
 * (not all of which need be supported by a given version).
55
 * You can change the default output format by defining DEFAULT_FMT;
56
 * indeed, you had better do so if you undefine PPM_SUPPORTED.
57
 */
58
59
typedef enum {
60
	FMT_BMP,		/* BMP format (Windows flavor) */
61
	FMT_GIF,		/* GIF format */
62
	FMT_OS2,		/* BMP format (OS/2 flavor) */
63
	FMT_PPM,		/* PPM/PGM (PBMPLUS formats) */
64
	FMT_RLE,		/* RLE format */
65
	FMT_TARGA,		/* Targa format */
66
	FMT_TIFF		/* TIFF format */
67
} IMAGE_FORMATS;
68
69
#ifndef DEFAULT_FMT		/* so can override from CFLAGS in Makefile */
70
#define DEFAULT_FMT	FMT_PPM
71
#endif
72
73
static IMAGE_FORMATS requested_fmt;
74
75
76
/*
77
 * Argument-parsing code.
78
 * The switch parser is designed to be useful with DOS-style command line
79
 * syntax, ie, intermixed switches and file names, where only the switches
80
 * to the left of a given file name affect processing of that file.
81
 * The main program in this file doesn't actually use this capability...
82
 */
83
84
85
static const char * progname;	/* program name for error messages */
86
static char * outfilename;	/* for -outfile switch */
87
88
89
LOCAL(void)
90
usage (void)
91
/* complain about bad command line */
92
{
93
  fprintf(stderr, "usage: %s [switches] ", progname);
94
#ifdef TWO_FILE_COMMANDLINE
95
  fprintf(stderr, "inputfile outputfile\n");
96
#else
97
  fprintf(stderr, "[inputfile]\n");
98
#endif
99
100
  fprintf(stderr, "Switches (names may be abbreviated):\n");
101
  fprintf(stderr, "  -colors N      Reduce image to no more than N colors\n");
102
  fprintf(stderr, "  -fast          Fast, low-quality processing\n");
103
  fprintf(stderr, "  -grayscale     Force grayscale output\n");
104
#ifdef IDCT_SCALING_SUPPORTED
105
  fprintf(stderr, "  -scale M/N     Scale output image by fraction M/N, eg, 1/8\n");
106
#endif
107
#ifdef BMP_SUPPORTED
108
  fprintf(stderr, "  -bmp           Select BMP output format (Windows style)%s\n",
109
	  (DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
110
#endif
111
#ifdef GIF_SUPPORTED
112
  fprintf(stderr, "  -gif           Select GIF output format%s\n",
113
	  (DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
114
#endif
115
#ifdef BMP_SUPPORTED
116
  fprintf(stderr, "  -os2           Select BMP output format (OS/2 style)%s\n",
117
	  (DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
118
#endif
119
#ifdef PPM_SUPPORTED
120
  fprintf(stderr, "  -pnm           Select PBMPLUS (PPM/PGM) output format%s\n",
121
	  (DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
122
#endif
123
#ifdef RLE_SUPPORTED
124
  fprintf(stderr, "  -rle           Select Utah RLE output format%s\n",
125
	  (DEFAULT_FMT == FMT_RLE ? " (default)" : ""));
126
#endif
127
#ifdef TARGA_SUPPORTED
128
  fprintf(stderr, "  -targa         Select Targa output format%s\n",
129
	  (DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));
130
#endif
131
  fprintf(stderr, "Switches for advanced users:\n");
132
#ifdef DCT_ISLOW_SUPPORTED
133
  fprintf(stderr, "  -dct int       Use integer DCT method%s\n",
134
	  (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
135
#endif
136
#ifdef DCT_IFAST_SUPPORTED
137
  fprintf(stderr, "  -dct fast      Use fast integer DCT (less accurate)%s\n",
138
	  (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
139
#endif
140
#ifdef DCT_FLOAT_SUPPORTED
141
  fprintf(stderr, "  -dct float     Use floating-point DCT method%s\n",
142
	  (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
143
#endif
144
  fprintf(stderr, "  -dither fs     Use F-S dithering (default)\n");
145
  fprintf(stderr, "  -dither none   Don't use dithering in quantization\n");
146
  fprintf(stderr, "  -dither ordered  Use ordered dither (medium speed, quality)\n");
147
#ifdef QUANT_2PASS_SUPPORTED
148
  fprintf(stderr, "  -map FILE      Map to colors used in named image file\n");
149
#endif
150
  fprintf(stderr, "  -nosmooth      Don't use high-quality upsampling\n");
151
#ifdef QUANT_1PASS_SUPPORTED
152
  fprintf(stderr, "  -onepass       Use 1-pass quantization (fast, low quality)\n");
153
#endif
154
  fprintf(stderr, "  -maxmemory N   Maximum memory to use (in kbytes)\n");
155
  fprintf(stderr, "  -outfile name  Specify name for output file\n");
156
  fprintf(stderr, "  -verbose  or  -debug   Emit debug output\n");
157
  exit(EXIT_FAILURE);
158
}
159
160
161
LOCAL(int)
162
parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
163
		int last_file_arg_seen, boolean for_real)
164
/* Parse optional switches.
165
 * Returns argv[] index of first file-name argument (== argc if none).
166
 * Any file names with indexes <= last_file_arg_seen are ignored;
167
 * they have presumably been processed in a previous iteration.
168
 * (Pass 0 for last_file_arg_seen on the first or only iteration.)
169
 * for_real is FALSE on the first (dummy) pass; we may skip any expensive
170
 * processing.
171
 */
172
{
173
  int argn;
174
  char * arg;
175
176
  /* Set up default JPEG parameters. */
177
  requested_fmt = DEFAULT_FMT;	/* set default output file format */
178
  outfilename = NULL;
179
  cinfo->err->trace_level = 0;
180
181
  /* Scan command line options, adjust parameters */
182
183
  for (argn = 1; argn < argc; argn++) {
184
    arg = argv[argn];
185
    if (*arg != '-') {
186
      /* Not a switch, must be a file name argument */
187
      if (argn <= last_file_arg_seen) {
188
	outfilename = NULL;	/* -outfile applies to just one input file */
189
	continue;		/* ignore this name if previously processed */
190
      }
191
      break;			/* else done parsing switches */
192
    }
193
    arg++;			/* advance past switch marker character */
194
195
    if (keymatch(arg, "bmp", 1)) {
196
      /* BMP output format. */
197
      requested_fmt = FMT_BMP;
198
199
    } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
200
	       keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
201
      /* Do color quantization. */
202
      int val;
203
204
      if (++argn >= argc)	/* advance to next argument */
205
	usage();
206
      if (sscanf(argv[argn], "%d", &val) != 1)
207
	usage();
208
      cinfo->desired_number_of_colors = val;
209
      cinfo->quantize_colors = TRUE;
210
211
    } else if (keymatch(arg, "dct", 2)) {
212
      /* Select IDCT algorithm. */
213
      if (++argn >= argc)	/* advance to next argument */
214
	usage();
215
      if (keymatch(argv[argn], "int", 1)) {
216
	cinfo->dct_method = JDCT_ISLOW;
217
      } else if (keymatch(argv[argn], "fast", 2)) {
218
	cinfo->dct_method = JDCT_IFAST;
219
      } else if (keymatch(argv[argn], "float", 2)) {
220
	cinfo->dct_method = JDCT_FLOAT;
221
      } else
222
	usage();
223
224
    } else if (keymatch(arg, "dither", 2)) {
225
      /* Select dithering algorithm. */
226
      if (++argn >= argc)	/* advance to next argument */
227
	usage();
228
      if (keymatch(argv[argn], "fs", 2)) {
229
	cinfo->dither_mode = JDITHER_FS;
230
      } else if (keymatch(argv[argn], "none", 2)) {
231
	cinfo->dither_mode = JDITHER_NONE;
232
      } else if (keymatch(argv[argn], "ordered", 2)) {
233
	cinfo->dither_mode = JDITHER_ORDERED;
234
      } else
235
	usage();
236
237
    } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
238
      /* Enable debug printouts. */
239
      /* On first -d, print version identification */
240
      static boolean printed_version = FALSE;
241
242
      if (! printed_version) {
243
	fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n",
244
		JVERSION, JCOPYRIGHT);
245
	printed_version = TRUE;
246
      }
247
      cinfo->err->trace_level++;
248
249
    } else if (keymatch(arg, "fast", 1)) {
250
      /* Select recommended processing options for quick-and-dirty output. */
251
      cinfo->two_pass_quantize = FALSE;
252
      cinfo->dither_mode = JDITHER_ORDERED;
253
      if (! cinfo->quantize_colors) /* don't override an earlier -colors */
254
	cinfo->desired_number_of_colors = 216;
255
      cinfo->dct_method = JDCT_FASTEST;
256
      cinfo->do_fancy_upsampling = FALSE;
257
258
    } else if (keymatch(arg, "gif", 1)) {
259
      /* GIF output format. */
260
      requested_fmt = FMT_GIF;
261
262
    } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
263
      /* Force monochrome output. */
264
      cinfo->out_color_space = JCS_GRAYSCALE;
265
266
    } else if (keymatch(arg, "map", 3)) {
267
      /* Quantize to a color map taken from an input file. */
268
      if (++argn >= argc)	/* advance to next argument */
269
	usage();
270
      if (for_real) {		/* too expensive to do twice! */
271
#ifdef QUANT_2PASS_SUPPORTED	/* otherwise can't quantize to supplied map */
272
	FILE * mapfile;
273
274
	if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
275
	  fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
276
	  exit(EXIT_FAILURE);
277
	}
278
	read_color_map(cinfo, mapfile);
279
	fclose(mapfile);
280
	cinfo->quantize_colors = TRUE;
281
#else
282
	ERREXIT(cinfo, JERR_NOT_COMPILED);
283
#endif
284
      }
285
286
    } else if (keymatch(arg, "maxmemory", 3)) {
287
      /* Maximum memory in Kb (or Mb with 'm'). */
288
      long lval;
289
      char ch = 'x';
290
291
      if (++argn >= argc)	/* advance to next argument */
292
	usage();
293
      if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
294
	usage();
295
      if (ch == 'm' || ch == 'M')
296
	lval *= 1000L;
297
      cinfo->mem->max_memory_to_use = lval * 1000L;
298
299
    } else if (keymatch(arg, "nosmooth", 3)) {
300
      /* Suppress fancy upsampling */
301
      cinfo->do_fancy_upsampling = FALSE;
302
303
    } else if (keymatch(arg, "onepass", 3)) {
304
      /* Use fast one-pass quantization. */
305
      cinfo->two_pass_quantize = FALSE;
306
307
    } else if (keymatch(arg, "os2", 3)) {
308
      /* BMP output format (OS/2 flavor). */
309
      requested_fmt = FMT_OS2;
310
311
    } else if (keymatch(arg, "outfile", 4)) {
312
      /* Set output file name. */
313
      if (++argn >= argc)	/* advance to next argument */
314
	usage();
315
      outfilename = argv[argn];	/* save it away for later use */
316
317
    } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
318
      /* PPM/PGM output format. */
319
      requested_fmt = FMT_PPM;
320
321
    } else if (keymatch(arg, "rle", 1)) {
322
      /* RLE output format. */
323
      requested_fmt = FMT_RLE;
324
325
    } else if (keymatch(arg, "scale", 1)) {
326
      /* Scale the output image by a fraction M/N. */
327
      if (++argn >= argc)	/* advance to next argument */
328
	usage();
329
      if (sscanf(argv[argn], "%d/%d",
330
		 &cinfo->scale_num, &cinfo->scale_denom) != 2)
331
	usage();
332
333
    } else if (keymatch(arg, "targa", 1)) {
334
      /* Targa output format. */
335
      requested_fmt = FMT_TARGA;
336
337
    } else {
338
      usage();			/* bogus switch */
339
    }
340
  }
341
342
  return argn;			/* return index of next arg (file name) */
343
}
344
345
346
/*
347
 * Marker processor for COM and interesting APPn markers.
348
 * This replaces the library's built-in processor, which just skips the marker.
349
 * We want to print out the marker as text, to the extent possible.
350
 * Note this code relies on a non-suspending data source.
351
 */
352
353
LOCAL(unsigned int)
354
jpeg_getc (j_decompress_ptr cinfo)
355
/* Read next byte */
356
{
357
  struct jpeg_source_mgr * datasrc = cinfo->src;
358
359
  if (datasrc->bytes_in_buffer == 0) {
360
    if (! (*datasrc->fill_input_buffer) (cinfo))
361
      ERREXIT(cinfo, JERR_CANT_SUSPEND);
362
  }
363
  datasrc->bytes_in_buffer--;
364
  return GETJOCTET(*datasrc->next_input_byte++);
365
}
366
367
368
METHODDEF(boolean)
369
print_text_marker (j_decompress_ptr cinfo)
370
{
371
  boolean traceit = (cinfo->err->trace_level >= 1);
372
  INT32 length;
373
  unsigned int ch;
374
  unsigned int lastch = 0;
375
376
  length = jpeg_getc(cinfo) << 8;
377
  length += jpeg_getc(cinfo);
378
  length -= 2;			/* discount the length word itself */
379
380
  if (traceit) {
381
    if (cinfo->unread_marker == JPEG_COM)
382
      fprintf(stderr, "Comment, length %ld:\n", (long) length);
383
    else			/* assume it is an APPn otherwise */
384
      fprintf(stderr, "APP%d, length %ld:\n",
385
	      cinfo->unread_marker - JPEG_APP0, (long) length);
386
  }
387
388
  while (--length >= 0) {
389
    ch = jpeg_getc(cinfo);
390
    if (traceit) {
391
      /* Emit the character in a readable form.
392
       * Nonprintables are converted to \nnn form,
393
       * while \ is converted to \\.
394
       * Newlines in CR, CR/LF, or LF form will be printed as one newline.
395
       */
396
      if (ch == '\r') {
397
	fprintf(stderr, "\n");
398
      } else if (ch == '\n') {
399
	if (lastch != '\r')
400
	  fprintf(stderr, "\n");
401
      } else if (ch == '\\') {
402
	fprintf(stderr, "\\\\");
403
      } else if (isprint(ch)) {
404
	putc(ch, stderr);
405
      } else {
406
	fprintf(stderr, "\\%03o", ch);
407
      }
408
      lastch = ch;
409
    }
410
  }
411
412
  if (traceit)
413
    fprintf(stderr, "\n");
414
415
  return TRUE;
416
}
417
418
419
/*
420
 * The main program.
421
 */
422
423
int
424
main (int argc, char **argv)
425
{
426
  struct jpeg_decompress_struct cinfo;
427
  struct jpeg_error_mgr jerr;
428
#ifdef PROGRESS_REPORT
429
  struct cdjpeg_progress_mgr progress;
430
#endif
431
  int file_index;
432
  djpeg_dest_ptr dest_mgr = NULL;
433
  FILE * input_file;
434
  FILE * output_file;
435
  JDIMENSION num_scanlines;
436
437
  /* On Mac, fetch a command line. */
438
#ifdef USE_CCOMMAND
439
  argc = ccommand(&argv);
440
#endif
441
442
  progname = argv[0];
443
  if (progname == NULL || progname[0] == 0)
444
    progname = "djpeg";		/* in case C library doesn't provide it */
445
446
  /* Initialize the JPEG decompression object with default error handling. */
447
  cinfo.err = jpeg_std_error(&jerr);
448
  jpeg_create_decompress(&cinfo);
449
  /* Add some application-specific error messages (from cderror.h) */
450
  jerr.addon_message_table = cdjpeg_message_table;
451
  jerr.first_addon_message = JMSG_FIRSTADDONCODE;
452
  jerr.last_addon_message = JMSG_LASTADDONCODE;
453
454
  /* Insert custom marker processor for COM and APP12.
455
   * APP12 is used by some digital camera makers for textual info,
456
   * so we provide the ability to display it as text.
457
   * If you like, additional APPn marker types can be selected for display,
458
   * but don't try to override APP0 or APP14 this way (see libjpeg.doc).
459
   */
460
  jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
461
  jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
462
463
  /* Now safe to enable signal catcher. */
464
#ifdef NEED_SIGNAL_CATCHER
465
  enable_signal_catcher((j_common_ptr) &cinfo);
466
#endif
467
468
  /* Scan command line to find file names. */
469
  /* It is convenient to use just one switch-parsing routine, but the switch
470
   * values read here are ignored; we will rescan the switches after opening
471
   * the input file.
472
   * (Exception: tracing level set here controls verbosity for COM markers
473
   * found during jpeg_read_header...)
474
   */
475
476
  file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
477
478
#ifdef TWO_FILE_COMMANDLINE
479
  /* Must have either -outfile switch or explicit output file name */
480
  if (outfilename == NULL) {
481
    if (file_index != argc-2) {
482
      fprintf(stderr, "%s: must name one input and one output file\n",
483
	      progname);
484
      usage();
485
    }
486
    outfilename = argv[file_index+1];
487
  } else {
488
    if (file_index != argc-1) {
489
      fprintf(stderr, "%s: must name one input and one output file\n",
490
	      progname);
491
      usage();
492
    }
493
  }
494
#else
495
  /* Unix style: expect zero or one file name */
496
  if (file_index < argc-1) {
497
    fprintf(stderr, "%s: only one input file\n", progname);
498
    usage();
499
  }
500
#endif /* TWO_FILE_COMMANDLINE */
501
502
  /* Open the input file. */
503
  if (file_index < argc) {
504
    if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
505
      fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
506
      exit(EXIT_FAILURE);
507
    }
508
  } else {
509
    /* default input file is stdin */
510
    input_file = read_stdin();
511
  }
512
513
  /* Open the output file. */
514
  if (outfilename != NULL) {
515
    if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
516
      fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
517
      exit(EXIT_FAILURE);
518
    }
519
  } else {
520
    /* default output file is stdout */
521
    output_file = write_stdout();
522
  }
523
524
#ifdef PROGRESS_REPORT
525
  start_progress_monitor((j_common_ptr) &cinfo, &progress);
526
#endif
527
528
  /* Specify data source for decompression */
529
  jpeg_stdio_src(&cinfo, input_file);
530
531
  /* Read file header, set default decompression parameters */
532
  (void) jpeg_read_header(&cinfo, TRUE);
533
534
  /* Adjust default decompression parameters by re-parsing the options */
535
  file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
536
537
  /* Initialize the output module now to let it override any crucial
538
   * option settings (for instance, GIF wants to force color quantization).
539
   */
540
  switch (requested_fmt) {
541
#ifdef BMP_SUPPORTED
542
  case FMT_BMP:
543
    dest_mgr = jinit_write_bmp(&cinfo, FALSE);
544
    break;
545
  case FMT_OS2:
546
    dest_mgr = jinit_write_bmp(&cinfo, TRUE);
547
    break;
548
#endif
549
#ifdef GIF_SUPPORTED
550
  case FMT_GIF:
551
    dest_mgr = jinit_write_gif(&cinfo);
552
    break;
553
#endif
554
#ifdef PPM_SUPPORTED
555
  case FMT_PPM:
556
    dest_mgr = jinit_write_ppm(&cinfo);
557
    break;
558
#endif
559
#ifdef RLE_SUPPORTED
560
  case FMT_RLE:
561
    dest_mgr = jinit_write_rle(&cinfo);
562
    break;
563
#endif
564
#ifdef TARGA_SUPPORTED
565
  case FMT_TARGA:
566
    dest_mgr = jinit_write_targa(&cinfo);
567
    break;
568
#endif
569
  default:
570
    ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
571
    break;
572
  }
573
  dest_mgr->output_file = output_file;
574
575
  /* Start decompressor */
576
  (void) jpeg_start_decompress(&cinfo);
577
578
  /* Write output file header */
579
  (*dest_mgr->start_output) (&cinfo, dest_mgr);
580
581
  /* Process data */
582
  while (cinfo.output_scanline < cinfo.output_height) {
583
    num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
584
					dest_mgr->buffer_height);
585
    (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
586
  }
587
588
#ifdef PROGRESS_REPORT
589
  /* Hack: count final pass as done in case finish_output does an extra pass.
590
   * The library won't have updated completed_passes.
591
   */
592
  progress.pub.completed_passes = progress.pub.total_passes;
593
#endif
594
595
  /* Finish decompression and release memory.
596
   * I must do it in this order because output module has allocated memory
597
   * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
598
   */
599
  (*dest_mgr->finish_output) (&cinfo, dest_mgr);
600
  (void) jpeg_finish_decompress(&cinfo);
601
  jpeg_destroy_decompress(&cinfo);
602
603
  /* Close files, if we opened them */
604
  if (input_file != stdin)
605
    fclose(input_file);
606
  if (output_file != stdout)
607
    fclose(output_file);
608
609
#ifdef PROGRESS_REPORT
610
  end_progress_monitor((j_common_ptr) &cinfo);
611
#endif
612
613
  /* All done. */
614
  exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
615
  return 0;			/* suppress no-return-value warnings */
616
}
(-)a/jpeg/example.c (-433 lines)
Line     Link Here 
 Lines 1-433    Link Here 
1
/*
2
 * example.c
3
 *
4
 * This file illustrates how to use the IJG code as a subroutine library
5
 * to read or write JPEG image files.  You should look at this code in
6
 * conjunction with the documentation file libjpeg.doc.
7
 *
8
 * This code will not do anything useful as-is, but it may be helpful as a
9
 * skeleton for constructing routines that call the JPEG library.  
10
 *
11
 * We present these routines in the same coding style used in the JPEG code
12
 * (ANSI function definitions, etc); but you are of course free to code your
13
 * routines in a different style if you prefer.
14
 */
15
16
#include <stdio.h>
17
18
/*
19
 * Include file for users of JPEG library.
20
 * You will need to have included system headers that define at least
21
 * the typedefs FILE and size_t before you can include jpeglib.h.
22
 * (stdio.h is sufficient on ANSI-conforming systems.)
23
 * You may also wish to include "jerror.h".
24
 */
25
26
#include "jpeglib.h"
27
28
/*
29
 * <setjmp.h> is used for the optional error recovery mechanism shown in
30
 * the second part of the example.
31
 */
32
33
#include <setjmp.h>
34
35
36
37
/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/
38
39
/* This half of the example shows how to feed data into the JPEG compressor.
40
 * We present a minimal version that does not worry about refinements such
41
 * as error recovery (the JPEG code will just exit() if it gets an error).
42
 */
43
44
45
/*
46
 * IMAGE DATA FORMATS:
47
 *
48
 * The standard input image format is a rectangular array of pixels, with
49
 * each pixel having the same number of "component" values (color channels).
50
 * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars).
51
 * If you are working with color data, then the color values for each pixel
52
 * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit
53
 * RGB color.
54
 *
55
 * For this example, we'll assume that this data structure matches the way
56
 * our application has stored the image in memory, so we can just pass a
57
 * pointer to our image buffer.  In particular, let's say that the image is
58
 * RGB color and is described by:
59
 */
60
61
extern JSAMPLE * image_buffer;	/* Points to large array of R,G,B-order data */
62
extern int image_height;	/* Number of rows in image */
63
extern int image_width;		/* Number of columns in image */
64
65
66
/*
67
 * Sample routine for JPEG compression.  We assume that the target file name
68
 * and a compression quality factor are passed in.
69
 */
70
71
GLOBAL(void)
72
write_JPEG_file (char * filename, int quality)
73
{
74
  /* This struct contains the JPEG compression parameters and pointers to
75
   * working space (which is allocated as needed by the JPEG library).
76
   * It is possible to have several such structures, representing multiple
77
   * compression/decompression processes, in existence at once.  We refer
78
   * to any one struct (and its associated working data) as a "JPEG object".
79
   */
80
  struct jpeg_compress_struct cinfo;
81
  /* This struct represents a JPEG error handler.  It is declared separately
82
   * because applications often want to supply a specialized error handler
83
   * (see the second half of this file for an example).  But here we just
84
   * take the easy way out and use the standard error handler, which will
85
   * print a message on stderr and call exit() if compression fails.
86
   * Note that this struct must live as long as the main JPEG parameter
87
   * struct, to avoid dangling-pointer problems.
88
   */
89
  struct jpeg_error_mgr jerr;
90
  /* More stuff */
91
  FILE * outfile;		/* target file */
92
  JSAMPROW row_pointer[1];	/* pointer to JSAMPLE row[s] */
93
  int row_stride;		/* physical row width in image buffer */
94
95
  /* Step 1: allocate and initialize JPEG compression object */
96
97
  /* We have to set up the error handler first, in case the initialization
98
   * step fails.  (Unlikely, but it could happen if you are out of memory.)
99
   * This routine fills in the contents of struct jerr, and returns jerr's
100
   * address which we place into the link field in cinfo.
101
   */
102
  cinfo.err = jpeg_std_error(&jerr);
103
  /* Now we can initialize the JPEG compression object. */
104
  jpeg_create_compress(&cinfo);
105
106
  /* Step 2: specify data destination (eg, a file) */
107
  /* Note: steps 2 and 3 can be done in either order. */
108
109
  /* Here we use the library-supplied code to send compressed data to a
110
   * stdio stream.  You can also write your own code to do something else.
111
   * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
112
   * requires it in order to write binary files.
113
   */
114
  if ((outfile = fopen(filename, "wb")) == NULL) {
115
    fprintf(stderr, "can't open %s\n", filename);
116
    exit(1);
117
  }
118
  jpeg_stdio_dest(&cinfo, outfile);
119
120
  /* Step 3: set parameters for compression */
121
122
  /* First we supply a description of the input image.
123
   * Four fields of the cinfo struct must be filled in:
124
   */
125
  cinfo.image_width = image_width; 	/* image width and height, in pixels */
126
  cinfo.image_height = image_height;
127
  cinfo.input_components = 3;		/* # of color components per pixel */
128
  cinfo.in_color_space = JCS_RGB; 	/* colorspace of input image */
129
  /* Now use the library's routine to set default compression parameters.
130
   * (You must set at least cinfo.in_color_space before calling this,
131
   * since the defaults depend on the source color space.)
132
   */
133
  jpeg_set_defaults(&cinfo);
134
  /* Now you can set any non-default parameters you wish to.
135
   * Here we just illustrate the use of quality (quantization table) scaling:
136
   */
137
  jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
138
139
  /* Step 4: Start compressor */
140
141
  /* TRUE ensures that we will write a complete interchange-JPEG file.
142
   * Pass TRUE unless you are very sure of what you're doing.
143
   */
144
  jpeg_start_compress(&cinfo, TRUE);
145
146
  /* Step 5: while (scan lines remain to be written) */
147
  /*           jpeg_write_scanlines(...); */
148
149
  /* Here we use the library's state variable cinfo.next_scanline as the
150
   * loop counter, so that we don't have to keep track ourselves.
151
   * To keep things simple, we pass one scanline per call; you can pass
152
   * more if you wish, though.
153
   */
154
  row_stride = image_width * 3;	/* JSAMPLEs per row in image_buffer */
155
156
  while (cinfo.next_scanline < cinfo.image_height) {
157
    /* jpeg_write_scanlines expects an array of pointers to scanlines.
158
     * Here the array is only one element long, but you could pass
159
     * more than one scanline at a time if that's more convenient.
160
     */
161
    row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
162
    (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
163
  }
164
165
  /* Step 6: Finish compression */
166
167
  jpeg_finish_compress(&cinfo);
168
  /* After finish_compress, we can close the output file. */
169
  fclose(outfile);
170
171
  /* Step 7: release JPEG compression object */
172
173
  /* This is an important step since it will release a good deal of memory. */
174
  jpeg_destroy_compress(&cinfo);
175
176
  /* And we're done! */
177
}
178
179
180
/*
181
 * SOME FINE POINTS:
182
 *
183
 * In the above loop, we ignored the return value of jpeg_write_scanlines,
184
 * which is the number of scanlines actually written.  We could get away
185
 * with this because we were only relying on the value of cinfo.next_scanline,
186
 * which will be incremented correctly.  If you maintain additional loop
187
 * variables then you should be careful to increment them properly.
188
 * Actually, for output to a stdio stream you needn't worry, because
189
 * then jpeg_write_scanlines will write all the lines passed (or else exit
190
 * with a fatal error).  Partial writes can only occur if you use a data
191
 * destination module that can demand suspension of the compressor.
192
 * (If you don't know what that's for, you don't need it.)
193
 *
194
 * If the compressor requires full-image buffers (for entropy-coding
195
 * optimization or a multi-scan JPEG file), it will create temporary
196
 * files for anything that doesn't fit within the maximum-memory setting.
197
 * (Note that temp files are NOT needed if you use the default parameters.)
198
 * On some systems you may need to set up a signal handler to ensure that
199
 * temporary files are deleted if the program is interrupted.  See libjpeg.doc.
200
 *
201
 * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG
202
 * files to be compatible with everyone else's.  If you cannot readily read
203
 * your data in that order, you'll need an intermediate array to hold the
204
 * image.  See rdtarga.c or rdbmp.c for examples of handling bottom-to-top
205
 * source data using the JPEG code's internal virtual-array mechanisms.
206
 */
207
208
209
210
/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/
211
212
/* This half of the example shows how to read data from the JPEG decompressor.
213
 * It's a bit more refined than the above, in that we show:
214
 *   (a) how to modify the JPEG library's standard error-reporting behavior;
215
 *   (b) how to allocate workspace using the library's memory manager.
216
 *
217
 * Just to make this example a little different from the first one, we'll
218
 * assume that we do not intend to put the whole image into an in-memory
219
 * buffer, but to send it line-by-line someplace else.  We need a one-
220
 * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG
221
 * memory manager allocate it for us.  This approach is actually quite useful
222
 * because we don't need to remember to deallocate the buffer separately: it
223
 * will go away automatically when the JPEG object is cleaned up.
224
 */
225
226
227
/*
228
 * ERROR HANDLING:
229
 *
230
 * The JPEG library's standard error handler (jerror.c) is divided into
231
 * several "methods" which you can override individually.  This lets you
232
 * adjust the behavior without duplicating a lot of code, which you might
233
 * have to update with each future release.
234
 *
235
 * Our example here shows how to override the "error_exit" method so that
236
 * control is returned to the library's caller when a fatal error occurs,
237
 * rather than calling exit() as the standard error_exit method does.
238
 *
239
 * We use C's setjmp/longjmp facility to return control.  This means that the
240
 * routine which calls the JPEG library must first execute a setjmp() call to
241
 * establish the return point.  We want the replacement error_exit to do a
242
 * longjmp().  But we need to make the setjmp buffer accessible to the
243
 * error_exit routine.  To do this, we make a private extension of the
244
 * standard JPEG error handler object.  (If we were using C++, we'd say we
245
 * were making a subclass of the regular error handler.)
246
 *
247
 * Here's the extended error handler struct:
248
 */
249
250
struct my_error_mgr {
251
  struct jpeg_error_mgr pub;	/* "public" fields */
252
253
  jmp_buf setjmp_buffer;	/* for return to caller */
254
};
255
256
typedef struct my_error_mgr * my_error_ptr;
257
258
/*
259
 * Here's the routine that will replace the standard error_exit method:
260
 */
261
262
METHODDEF(void)
263
my_error_exit (j_common_ptr cinfo)
264
{
265
  /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
266
  my_error_ptr myerr = (my_error_ptr) cinfo->err;
267
268
  /* Always display the message. */
269
  /* We could postpone this until after returning, if we chose. */
270
  (*cinfo->err->output_message) (cinfo);
271
272
  /* Return control to the setjmp point */
273
  longjmp(myerr->setjmp_buffer, 1);
274
}
275
276
277
/*
278
 * Sample routine for JPEG decompression.  We assume that the source file name
279
 * is passed in.  We want to return 1 on success, 0 on error.
280
 */
281
282
283
GLOBAL(int)
284
read_JPEG_file (char * filename)
285
{
286
  /* This struct contains the JPEG decompression parameters and pointers to
287
   * working space (which is allocated as needed by the JPEG library).
288
   */
289
  struct jpeg_decompress_struct cinfo;
290
  /* We use our private extension JPEG error handler.
291
   * Note that this struct must live as long as the main JPEG parameter
292
   * struct, to avoid dangling-pointer problems.
293
   */
294
  struct my_error_mgr jerr;
295
  /* More stuff */
296
  FILE * infile;		/* source file */
297
  JSAMPARRAY buffer;		/* Output row buffer */
298
  int row_stride;		/* physical row width in output buffer */
299
300
  /* In this example we want to open the input file before doing anything else,
301
   * so that the setjmp() error recovery below can assume the file is open.
302
   * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
303
   * requires it in order to read binary files.
304
   */
305
306
  if ((infile = fopen(filename, "rb")) == NULL) {
307
    fprintf(stderr, "can't open %s\n", filename);
308
    return 0;
309
  }
310
311
  /* Step 1: allocate and initialize JPEG decompression object */
312
313
  /* We set up the normal JPEG error routines, then override error_exit. */
314
  cinfo.err = jpeg_std_error(&jerr.pub);
315
  jerr.pub.error_exit = my_error_exit;
316
  /* Establish the setjmp return context for my_error_exit to use. */
317
  if (setjmp(jerr.setjmp_buffer)) {
318
    /* If we get here, the JPEG code has signaled an error.
319
     * We need to clean up the JPEG object, close the input file, and return.
320
     */
321
    jpeg_destroy_decompress(&cinfo);
322
    fclose(infile);
323
    return 0;
324
  }
325
  /* Now we can initialize the JPEG decompression object. */
326
  jpeg_create_decompress(&cinfo);
327
328
  /* Step 2: specify data source (eg, a file) */
329
330
  jpeg_stdio_src(&cinfo, infile);
331
332
  /* Step 3: read file parameters with jpeg_read_header() */
333
334
  (void) jpeg_read_header(&cinfo, TRUE);
335
  /* We can ignore the return value from jpeg_read_header since
336
   *   (a) suspension is not possible with the stdio data source, and
337
   *   (b) we passed TRUE to reject a tables-only JPEG file as an error.
338
   * See libjpeg.doc for more info.
339
   */
340
341
  /* Step 4: set parameters for decompression */
342
343
  /* In this example, we don't need to change any of the defaults set by
344
   * jpeg_read_header(), so we do nothing here.
345
   */
346
347
  /* Step 5: Start decompressor */
348
349
  (void) jpeg_start_decompress(&cinfo);
350
  /* We can ignore the return value since suspension is not possible
351
   * with the stdio data source.
352
   */
353
354
  /* We may need to do some setup of our own at this point before reading
355
   * the data.  After jpeg_start_decompress() we have the correct scaled
356
   * output image dimensions available, as well as the output colormap
357
   * if we asked for color quantization.
358
   * In this example, we need to make an output work buffer of the right size.
359
   */ 
360
  /* JSAMPLEs per row in output buffer */
361
  row_stride = cinfo.output_width * cinfo.output_components;
362
  /* Make a one-row-high sample array that will go away when done with image */
363
  buffer = (*cinfo.mem->alloc_sarray)
364
		((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
365
366
  /* Step 6: while (scan lines remain to be read) */
367
  /*           jpeg_read_scanlines(...); */
368
369
  /* Here we use the library's state variable cinfo.output_scanline as the
370
   * loop counter, so that we don't have to keep track ourselves.
371
   */
372
  while (cinfo.output_scanline < cinfo.output_height) {
373
    /* jpeg_read_scanlines expects an array of pointers to scanlines.
374
     * Here the array is only one element long, but you could ask for
375
     * more than one scanline at a time if that's more convenient.
376
     */
377
    (void) jpeg_read_scanlines(&cinfo, buffer, 1);
378
    /* Assume put_scanline_someplace wants a pointer and sample count. */
379
    put_scanline_someplace(buffer[0], row_stride);
380
  }
381
382
  /* Step 7: Finish decompression */
383
384
  (void) jpeg_finish_decompress(&cinfo);
385
  /* We can ignore the return value since suspension is not possible
386
   * with the stdio data source.
387
   */
388
389
  /* Step 8: Release JPEG decompression object */
390
391
  /* This is an important step since it will release a good deal of memory. */
392
  jpeg_destroy_decompress(&cinfo);
393
394
  /* After finish_decompress, we can close the input file.
395
   * Here we postpone it until after no more JPEG errors are possible,
396
   * so as to simplify the setjmp error logic above.  (Actually, I don't
397
   * think that jpeg_destroy can do an error exit, but why assume anything...)
398
   */
399
  fclose(infile);
400
401
  /* At this point you may want to check to see whether any corrupt-data
402
   * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
403
   */
404
405
  /* And we're done! */
406
  return 1;
407
}
408
409
410
/*
411
 * SOME FINE POINTS:
412
 *
413
 * In the above code, we ignored the return value of jpeg_read_scanlines,
414
 * which is the number of scanlines actually read.  We could get away with
415
 * this because we asked for only one line at a time and we weren't using
416
 * a suspending data source.  See libjpeg.doc for more info.
417
 *
418
 * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress();
419
 * we should have done it beforehand to ensure that the space would be
420
 * counted against the JPEG max_memory setting.  In some systems the above
421
 * code would risk an out-of-memory error.  However, in general we don't
422
 * know the output image dimensions before jpeg_start_decompress(), unless we
423
 * call jpeg_calc_output_dimensions().  See libjpeg.doc for more about this.
424
 *
425
 * Scanlines are returned in the same order as they appear in the JPEG file,
426
 * which is standardly top-to-bottom.  If you must emit data bottom-to-top,
427
 * you can use one of the virtual arrays provided by the JPEG memory manager
428
 * to invert the data.  See wrbmp.c for an example.
429
 *
430
 * As with compression, some operating modes may require temporary files.
431
 * On some systems you may need to set up a signal handler to ensure that
432
 * temporary files are deleted if the program is interrupted.  See libjpeg.doc.
433
 */
(-)a/jpeg/filelist.doc (-210 lines)
Line     Link Here 
 Lines 1-210    Link Here 
1
IJG JPEG LIBRARY:  FILE LIST
2
3
Copyright (C) 1994-1998, Thomas G. Lane.
4
This file is part of the Independent JPEG Group's software.
5
For conditions of distribution and use, see the accompanying README file.
6
7
8
Here is a road map to the files in the IJG JPEG distribution.  The
9
distribution includes the JPEG library proper, plus two application
10
programs ("cjpeg" and "djpeg") which use the library to convert JPEG
11
files to and from some other popular image formats.  A third application
12
"jpegtran" uses the library to do lossless conversion between different
13
variants of JPEG.  There are also two stand-alone applications,
14
"rdjpgcom" and "wrjpgcom".
15
16
17
THE JPEG LIBRARY
18
================
19
20
Include files:
21
22
jpeglib.h	JPEG library's exported data and function declarations.
23
jconfig.h	Configuration declarations.  Note: this file is not present
24
		in the distribution; it is generated during installation.
25
jmorecfg.h	Additional configuration declarations; need not be changed
26
		for a standard installation.
27
jerror.h	Declares JPEG library's error and trace message codes.
28
jinclude.h	Central include file used by all IJG .c files to reference
29
		system include files.
30
jpegint.h	JPEG library's internal data structures.
31
jchuff.h	Private declarations for Huffman encoder modules.
32
jdhuff.h	Private declarations for Huffman decoder modules.
33
jdct.h		Private declarations for forward & reverse DCT subsystems.
34
jmemsys.h	Private declarations for memory management subsystem.
35
jversion.h	Version information.
36
37
Applications using the library should include jpeglib.h (which in turn
38
includes jconfig.h and jmorecfg.h).  Optionally, jerror.h may be included
39
if the application needs to reference individual JPEG error codes.  The
40
other include files are intended for internal use and would not normally
41
be included by an application program.  (cjpeg/djpeg/etc do use jinclude.h,
42
since its function is to improve portability of the whole IJG distribution.
43
Most other applications will directly include the system include files they
44
want, and hence won't need jinclude.h.)
45
46
47
C source code files:
48
49
These files contain most of the functions intended to be called directly by
50
an application program:
51
52
jcapimin.c	Application program interface: core routines for compression.
53
jcapistd.c	Application program interface: standard compression.
54
jdapimin.c	Application program interface: core routines for decompression.
55
jdapistd.c	Application program interface: standard decompression.
56
jcomapi.c	Application program interface routines common to compression
57
		and decompression.
58
jcparam.c	Compression parameter setting helper routines.
59
jctrans.c	API and library routines for transcoding compression.
60
jdtrans.c	API and library routines for transcoding decompression.
61
62
Compression side of the library:
63
64
jcinit.c	Initialization: determines which other modules to use.
65
jcmaster.c	Master control: setup and inter-pass sequencing logic.
66
jcmainct.c	Main buffer controller (preprocessor => JPEG compressor).
67
jcprepct.c	Preprocessor buffer controller.
68
jccoefct.c	Buffer controller for DCT coefficient buffer.
69
jccolor.c	Color space conversion.
70
jcsample.c	Downsampling.
71
jcdctmgr.c	DCT manager (DCT implementation selection & control).
72
jfdctint.c	Forward DCT using slow-but-accurate integer method.
73
jfdctfst.c	Forward DCT using faster, less accurate integer method.
74
jfdctflt.c	Forward DCT using floating-point arithmetic.
75
jchuff.c	Huffman entropy coding for sequential JPEG.
76
jcphuff.c	Huffman entropy coding for progressive JPEG.
77
jcmarker.c	JPEG marker writing.
78
jdatadst.c	Data destination manager for stdio output.
79
80
Decompression side of the library:
81
82
jdmaster.c	Master control: determines which other modules to use.
83
jdinput.c	Input controller: controls input processing modules.
84
jdmainct.c	Main buffer controller (JPEG decompressor => postprocessor).
85
jdcoefct.c	Buffer controller for DCT coefficient buffer.
86
jdpostct.c	Postprocessor buffer controller.
87
jdmarker.c	JPEG marker reading.
88
jdhuff.c	Huffman entropy decoding for sequential JPEG.
89
jdphuff.c	Huffman entropy decoding for progressive JPEG.
90
jddctmgr.c	IDCT manager (IDCT implementation selection & control).
91
jidctint.c	Inverse DCT using slow-but-accurate integer method.
92
jidctfst.c	Inverse DCT using faster, less accurate integer method.
93
jidctflt.c	Inverse DCT using floating-point arithmetic.
94
jidctred.c	Inverse DCTs with reduced-size outputs.
95
jdsample.c	Upsampling.
96
jdcolor.c	Color space conversion.
97
jdmerge.c	Merged upsampling/color conversion (faster, lower quality).
98
jquant1.c	One-pass color quantization using a fixed-spacing colormap.
99
jquant2.c	Two-pass color quantization using a custom-generated colormap.
100
		Also handles one-pass quantization to an externally given map.
101
jdatasrc.c	Data source manager for stdio input.
102
103
Support files for both compression and decompression:
104
105
jerror.c	Standard error handling routines (application replaceable).
106
jmemmgr.c	System-independent (more or less) memory management code.
107
jutils.c	Miscellaneous utility routines.
108
109
jmemmgr.c relies on a system-dependent memory management module.  The IJG
110
distribution includes the following implementations of the system-dependent
111
module:
112
113
jmemnobs.c	"No backing store": assumes adequate virtual memory exists.
114
jmemansi.c	Makes temporary files with ANSI-standard routine tmpfile().
115
jmemname.c	Makes temporary files with program-generated file names.
116
jmemdos.c	Custom implementation for MS-DOS (16-bit environment only):
117
		can use extended and expanded memory as well as temp files.
118
jmemmac.c	Custom implementation for Apple Macintosh.
119
120
Exactly one of the system-dependent modules should be configured into an
121
installed JPEG library (see install.doc for hints about which one to use).
122
On unusual systems you may find it worthwhile to make a special
123
system-dependent memory manager.
124
125
126
Non-C source code files:
127
128
jmemdosa.asm	80x86 assembly code support for jmemdos.c; used only in
129
		MS-DOS-specific configurations of the JPEG library.
130
131
132
CJPEG/DJPEG/JPEGTRAN
133
====================
134
135
Include files:
136
137
cdjpeg.h	Declarations shared by cjpeg/djpeg/jpegtran modules.
138
cderror.h	Additional error and trace message codes for cjpeg et al.
139
transupp.h	Declarations for jpegtran support routines in transupp.c.
140
141
C source code files:
142
143
cjpeg.c		Main program for cjpeg.
144
djpeg.c		Main program for djpeg.
145
jpegtran.c	Main program for jpegtran.
146
cdjpeg.c	Utility routines used by all three programs.
147
rdcolmap.c	Code to read a colormap file for djpeg's "-map" switch.
148
rdswitch.c	Code to process some of cjpeg's more complex switches.
149
		Also used by jpegtran.
150
transupp.c	Support code for jpegtran: lossless image manipulations.
151
152
Image file reader modules for cjpeg:
153
154
rdbmp.c		BMP file input.
155
rdgif.c		GIF file input (now just a stub).
156
rdppm.c		PPM/PGM file input.
157
rdrle.c		Utah RLE file input.
158
rdtarga.c	Targa file input.
159
160
Image file writer modules for djpeg:
161
162
wrbmp.c		BMP file output.
163
wrgif.c		GIF file output (a mere shadow of its former self).
164
wrppm.c		PPM/PGM file output.
165
wrrle.c		Utah RLE file output.
166
wrtarga.c	Targa file output.
167
168
169
RDJPGCOM/WRJPGCOM
170
=================
171
172
C source code files:
173
174
rdjpgcom.c	Stand-alone rdjpgcom application.
175
wrjpgcom.c	Stand-alone wrjpgcom application.
176
177
These programs do not depend on the IJG library.  They do use
178
jconfig.h and jinclude.h, only to improve portability.
179
180
181
ADDITIONAL FILES
182
================
183
184
Documentation (see README for a guide to the documentation files):
185
186
README		Master documentation file.
187
*.doc		Other documentation files.
188
*.1		Documentation in Unix man page format.
189
change.log	Version-to-version change highlights.
190
example.c	Sample code for calling JPEG library.
191
192
Configuration/installation files and programs (see install.doc for more info):
193
194
configure	Unix shell script to perform automatic configuration.
195
ltconfig	Support scripts for configure (from GNU libtool).
196
ltmain.sh
197
config.guess
198
config.sub
199
install-sh	Install shell script for those Unix systems lacking one.
200
ckconfig.c	Program to generate jconfig.h on non-Unix systems.
201
jconfig.doc	Template for making jconfig.h by hand.
202
makefile.*	Sample makefiles for particular systems.
203
jconfig.*	Sample jconfig.h for particular systems.
204
ansi2knr.c	De-ANSIfier for pre-ANSI C compilers (courtesy of
205
		L. Peter Deutsch and Aladdin Enterprises).
206
207
Test files (see install.doc for test procedure):
208
209
test*.*		Source and comparison files for confidence test.
210
		These are binary image files, NOT text files.
(-)a/jpeg/install.doc (-1063 lines)
Line     Link Here 
 Lines 1-1063    Link Here 
1
INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software
2
3
Copyright (C) 1991-1998, Thomas G. Lane.
4
This file is part of the Independent JPEG Group's software.
5
For conditions of distribution and use, see the accompanying README file.
6
7
8
This file explains how to configure and install the IJG software.  We have
9
tried to make this software extremely portable and flexible, so that it can be
10
adapted to almost any environment.  The downside of this decision is that the
11
installation process is complicated.  We have provided shortcuts to simplify
12
the task on common systems.  But in any case, you will need at least a little
13
familiarity with C programming and program build procedures for your system.
14
15
If you are only using this software as part of a larger program, the larger
16
program's installation procedure may take care of configuring the IJG code.
17
For example, Ghostscript's installation script will configure the IJG code.
18
You don't need to read this file if you just want to compile Ghostscript.
19
20
If you are on a Unix machine, you may not need to read this file at all.
21
Try doing
22
	./configure
23
	make
24
	make test
25
If that doesn't complain, do
26
	make install
27
(better do "make -n install" first to see if the makefile will put the files
28
where you want them).  Read further if you run into snags or want to customize
29
the code for your system.
30
31
32
TABLE OF CONTENTS
33
-----------------
34
35
Before you start
36
Configuring the software:
37
	using the automatic "configure" script
38
	using one of the supplied jconfig and makefile files
39
	by hand
40
Building the software
41
Testing the software
42
Installing the software
43
Optional stuff
44
Optimization
45
Hints for specific systems
46
47
48
BEFORE YOU START
49
================
50
51
Before installing the software you must unpack the distributed source code.
52
Since you are reading this file, you have probably already succeeded in this
53
task.  However, there is a potential for error if you needed to convert the
54
files to the local standard text file format (for example, if you are on
55
MS-DOS you may have converted LF end-of-line to CR/LF).  You must apply
56
such conversion to all the files EXCEPT those whose names begin with "test".
57
The test files contain binary data; if you change them in any way then the
58
self-test will give bad results.
59
60
Please check the last section of this file to see if there are hints for the
61
specific machine or compiler you are using.
62
63
64
CONFIGURING THE SOFTWARE
65
========================
66
67
To configure the IJG code for your system, you need to create two files:
68
  * jconfig.h: contains values for system-dependent #define symbols.
69
  * Makefile: controls the compilation process.
70
(On a non-Unix machine, you may create "project files" or some other
71
substitute for a Makefile.  jconfig.h is needed in any environment.)
72
73
We provide three different ways to generate these files:
74
  * On a Unix system, you can just run the "configure" script.
75
  * We provide sample jconfig files and makefiles for popular machines;
76
    if your machine matches one of the samples, just copy the right sample
77
    files to jconfig.h and Makefile.
78
  * If all else fails, read the instructions below and make your own files.
79
80
81
Configuring the software using the automatic "configure" script
82
---------------------------------------------------------------
83
84
If you are on a Unix machine, you can just type
85
	./configure
86
and let the configure script construct appropriate configuration files.
87
If you're using "csh" on an old version of System V, you might need to type
88
	sh configure
89
instead to prevent csh from trying to execute configure itself.
90
Expect configure to run for a few minutes, particularly on slower machines;
91
it works by compiling a series of test programs.
92
93
Configure was created with GNU Autoconf and it follows the usual conventions
94
for GNU configure scripts.  It makes a few assumptions that you may want to
95
override.  You can do this by providing optional switches to configure:
96
97
* If you want to build libjpeg as a shared library, say
98
	./configure --enable-shared
99
To get both shared and static libraries, say
100
	./configure --enable-shared --enable-static
101
Note that these switches invoke GNU libtool to take care of system-dependent
102
shared library building methods.  If things don't work this way, please try
103
running configure without either switch; that should build a static library
104
without using libtool.  If that works, your problem is probably with libtool
105
not with the IJG code.  libtool is fairly new and doesn't support all flavors
106
of Unix yet.  (You might be able to find a newer version of libtool than the
107
one included with libjpeg; see ftp.gnu.org.  Report libtool problems to
108
bug-libtool@gnu.org.)
109
110
* Configure will use gcc (GNU C compiler) if it's available, otherwise cc.
111
To force a particular compiler to be selected, use the CC option, for example
112
	./configure CC='cc'
113
The same method can be used to include any unusual compiler switches.
114
For example, on HP-UX you probably want to say
115
	./configure CC='cc -Aa'
116
to get HP's compiler to run in ANSI mode.
117
118
* The default CFLAGS setting is "-O" for non-gcc compilers, "-O2" for gcc.
119
You can override this by saying, for example,
120
	./configure CFLAGS='-g'
121
if you want to compile with debugging support.
122
123
* Configure will set up the makefile so that "make install" will install files
124
into /usr/local/bin, /usr/local/man, etc.  You can specify an installation
125
prefix other than "/usr/local" by giving configure the option "--prefix=PATH".
126
127
* If you don't have a lot of swap space, you may need to enable the IJG
128
software's internal virtual memory mechanism.  To do this, give the option
129
"--enable-maxmem=N" where N is the default maxmemory limit in megabytes.
130
This is discussed in more detail under "Selecting a memory manager", below.
131
You probably don't need to worry about this on reasonably-sized Unix machines,
132
unless you plan to process very large images.
133
134
Configure has some other features that are useful if you are cross-compiling
135
or working in a network of multiple machine types; but if you need those
136
features, you probably already know how to use them.
137
138
139
Configuring the software using one of the supplied jconfig and makefile files
140
-----------------------------------------------------------------------------
141
142
If you have one of these systems, you can just use the provided configuration
143
files:
144
145
Makefile	jconfig file	System and/or compiler
146
147
makefile.manx	jconfig.manx	Amiga, Manx Aztec C
148
makefile.sas	jconfig.sas	Amiga, SAS C
149
makeproj.mac	jconfig.mac	Apple Macintosh, Metrowerks CodeWarrior
150
mak*jpeg.st	jconfig.st	Atari ST/STE/TT, Pure C or Turbo C
151
makefile.bcc	jconfig.bcc	MS-DOS or OS/2, Borland C
152
makefile.dj	jconfig.dj	MS-DOS, DJGPP (Delorie's port of GNU C)
153
makefile.mc6	jconfig.mc6	MS-DOS, Microsoft C (16-bit only)
154
makefile.wat	jconfig.wat	MS-DOS, OS/2, or Windows NT, Watcom C
155
makefile.vc	jconfig.vc	Windows NT/95, MS Visual C++
156
make*.ds	jconfig.vc	Windows NT/95, MS Developer Studio
157
makefile.mms	jconfig.vms	Digital VMS, with MMS software
158
makefile.vms	jconfig.vms	Digital VMS, without MMS software
159
160
Copy the proper jconfig file to jconfig.h and the makefile to Makefile (or
161
whatever your system uses as the standard makefile name).  For more info see
162
the appropriate system-specific hints section near the end of this file.
163
164
165
Configuring the software by hand
166
--------------------------------
167
168
First, generate a jconfig.h file.  If you are moderately familiar with C,
169
the comments in jconfig.doc should be enough information to do this; just
170
copy jconfig.doc to jconfig.h and edit it appropriately.  Otherwise, you may
171
prefer to use the ckconfig.c program.  You will need to compile and execute
172
ckconfig.c by hand --- we hope you know at least enough to do that.
173
ckconfig.c may not compile the first try (in fact, the whole idea is for it
174
to fail if anything is going to).  If you get compile errors, fix them by
175
editing ckconfig.c according to the directions given in ckconfig.c.  Once
176
you get it to run, it will write a suitable jconfig.h file, and will also
177
print out some advice about which makefile to use.
178
179
You may also want to look at the canned jconfig files, if there is one for a
180
system similar to yours.
181
182
Second, select a makefile and copy it to Makefile (or whatever your system
183
uses as the standard makefile name).  The most generic makefiles we provide
184
are
185
	makefile.ansi:	if your C compiler supports function prototypes
186
	makefile.unix:	if not.
187
(You have function prototypes if ckconfig.c put "#define HAVE_PROTOTYPES"
188
in jconfig.h.)  You may want to start from one of the other makefiles if
189
there is one for a system similar to yours.
190
191
Look over the selected Makefile and adjust options as needed.  In particular
192
you may want to change the CC and CFLAGS definitions.  For instance, if you
193
are using GCC, set CC=gcc.  If you had to use any compiler switches to get
194
ckconfig.c to work, make sure the same switches are in CFLAGS.
195
196
If you are on a system that doesn't use makefiles, you'll need to set up
197
project files (or whatever you do use) to compile all the source files and
198
link them into executable files cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom.
199
See the file lists in any of the makefiles to find out which files go into
200
each program.  Note that the provided makefiles all make a "library" file
201
libjpeg first, but you don't have to do that if you don't want to; the file
202
lists identify which source files are actually needed for compression,
203
decompression, or both.  As a last resort, you can make a batch script that
204
just compiles everything and links it all together; makefile.vms is an example
205
of this (it's for VMS systems that have no make-like utility).
206
207
Here are comments about some specific configuration decisions you'll
208
need to make:
209
210
Command line style
211
------------------
212
213
These programs can use a Unix-like command line style which supports
214
redirection and piping, like this:
215
	cjpeg inputfile >outputfile
216
	cjpeg <inputfile >outputfile
217
	source program | cjpeg >outputfile
218
The simpler "two file" command line style is just
219
	cjpeg inputfile outputfile
220
You may prefer the two-file style, particularly if you don't have pipes.
221
222
You MUST use two-file style on any system that doesn't cope well with binary
223
data fed through stdin/stdout; this is true for some MS-DOS compilers, for
224
example.  If you're not on a Unix system, it's safest to assume you need
225
two-file style.  (But if your compiler provides either the Posix-standard
226
fdopen() library routine or a Microsoft-compatible setmode() routine, you
227
can safely use the Unix command line style, by defining USE_FDOPEN or
228
USE_SETMODE respectively.)
229
230
To use the two-file style, make jconfig.h say "#define TWO_FILE_COMMANDLINE".
231
232
Selecting a memory manager
233
--------------------------
234
235
The IJG code is capable of working on images that are too big to fit in main
236
memory; data is swapped out to temporary files as necessary.  However, the
237
code to do this is rather system-dependent.  We provide five different
238
memory managers:
239
240
* jmemansi.c	This version uses the ANSI-standard library routine tmpfile(),
241
		which not all non-ANSI systems have.  On some systems
242
		tmpfile() may put the temporary file in a non-optimal
243
		location; if you don't like what it does, use jmemname.c.
244
245
* jmemname.c	This version creates named temporary files.  For anything
246
		except a Unix machine, you'll need to configure the
247
		select_file_name() routine appropriately; see the comments
248
		near the head of jmemname.c.  If you use this version, define
249
		NEED_SIGNAL_CATCHER in jconfig.h to make sure the temp files
250
		are removed if the program is aborted.
251
252
* jmemnobs.c	(That stands for No Backing Store :-).)  This will compile on
253
		almost any system, but it assumes you have enough main memory
254
		or virtual memory to hold the biggest images you work with.
255
256
* jmemdos.c	This should be used with most 16-bit MS-DOS compilers.
257
		See the system-specific notes about MS-DOS for more info.
258
		IMPORTANT: if you use this, define USE_MSDOS_MEMMGR in
259
		jconfig.h, and include the assembly file jmemdosa.asm in the
260
		programs.  The supplied makefiles and jconfig files for
261
		16-bit MS-DOS compilers already do both.
262
263
* jmemmac.c	Custom version for Apple Macintosh; see the system-specific
264
		notes for Macintosh for more info.
265
266
To use a particular memory manager, change the SYSDEPMEM variable in your
267
makefile to equal the corresponding object file name (for example, jmemansi.o
268
or jmemansi.obj for jmemansi.c).
269
270
If you have plenty of (real or virtual) main memory, just use jmemnobs.c.
271
"Plenty" means about ten bytes for every pixel in the largest images
272
you plan to process, so a lot of systems don't meet this criterion.
273
If yours doesn't, try jmemansi.c first.  If that doesn't compile, you'll have
274
to use jmemname.c; be sure to adjust select_file_name() for local conditions.
275
You may also need to change unlink() to remove() in close_backing_store().
276
277
Except with jmemnobs.c or jmemmac.c, you need to adjust the DEFAULT_MAX_MEM
278
setting to a reasonable value for your system (either by adding a #define for
279
DEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile).
280
This value limits the amount of data space the program will attempt to
281
allocate.  Code and static data space isn't counted, so the actual memory
282
needs for cjpeg or djpeg are typically 100 to 150Kb more than the max-memory
283
setting.  Larger max-memory settings reduce the amount of I/O needed to
284
process a large image, but too large a value can result in "insufficient
285
memory" failures.  On most Unix machines (and other systems with virtual
286
memory), just set DEFAULT_MAX_MEM to several million and forget it.  At the
287
other end of the spectrum, for MS-DOS machines you probably can't go much
288
above 300K to 400K.  (On MS-DOS the value refers to conventional memory only.
289
Extended/expanded memory is handled separately by jmemdos.c.)
290
291
292
BUILDING THE SOFTWARE
293
=====================
294
295
Now you should be able to compile the software.  Just say "make" (or
296
whatever's necessary to start the compilation).  Have a cup of coffee.
297
298
Here are some things that could go wrong:
299
300
If your compiler complains about undefined structures, you should be able to
301
shut it up by putting "#define INCOMPLETE_TYPES_BROKEN" in jconfig.h.
302
303
If you have trouble with missing system include files or inclusion of the
304
wrong ones, read jinclude.h.  This shouldn't happen if you used configure
305
or ckconfig.c to set up jconfig.h.
306
307
There are a fair number of routines that do not use all of their parameters;
308
some compilers will issue warnings about this, which you can ignore.  There
309
are also a few configuration checks that may give "unreachable code" warnings.
310
Any other warning deserves investigation.
311
312
If you don't have a getenv() library routine, define NO_GETENV.
313
314
Also see the system-specific hints, below.
315
316
317
TESTING THE SOFTWARE
318
====================
319
320
As a quick test of functionality we've included a small sample image in
321
several forms:
322
	testorig.jpg	Starting point for the djpeg tests.
323
	testimg.ppm	The output of djpeg testorig.jpg
324
	testimg.bmp	The output of djpeg -bmp -colors 256 testorig.jpg
325
	testimg.jpg	The output of cjpeg testimg.ppm
326
	testprog.jpg	Progressive-mode equivalent of testorig.jpg.
327
	testimgp.jpg	The output of cjpeg -progressive -optimize testimg.ppm
328
(The first- and second-generation .jpg files aren't identical since JPEG is
329
lossy.)  If you can generate duplicates of the testimg* files then you
330
probably have working programs.
331
332
With most of the makefiles, "make test" will perform the necessary
333
comparisons.
334
335
If you're using a makefile that doesn't provide the test option, run djpeg
336
and cjpeg by hand and compare the output files to testimg* with whatever
337
binary file comparison tool you have.  The files should be bit-for-bit
338
identical.
339
340
If the programs complain "MAX_ALLOC_CHUNK is wrong, please fix", then you
341
need to reduce MAX_ALLOC_CHUNK to a value that fits in type size_t.
342
Try adding "#define MAX_ALLOC_CHUNK 65520L" to jconfig.h.  A less likely
343
configuration error is "ALIGN_TYPE is wrong, please fix": defining ALIGN_TYPE
344
as long should take care of that one.
345
346
If the cjpeg test run fails with "Missing Huffman code table entry", it's a
347
good bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED.  Go back to the
348
configuration step and run ckconfig.c.  (This is a good plan for any other
349
test failure, too.)
350
351
If you are using Unix (one-file) command line style on a non-Unix system,
352
it's a good idea to check that binary I/O through stdin/stdout actually
353
works.  You should get the same results from "djpeg <testorig.jpg >out.ppm"
354
as from "djpeg -outfile out.ppm testorig.jpg".  Note that the makefiles all
355
use the latter style and therefore do not exercise stdin/stdout!  If this
356
check fails, try recompiling with USE_SETMODE or USE_FDOPEN defined.
357
If it still doesn't work, better use two-file style.
358
359
If you chose a memory manager other than jmemnobs.c, you should test that
360
temporary-file usage works.  Try "djpeg -bmp -colors 256 -max 0 testorig.jpg"
361
and make sure its output matches testimg.bmp.  If you have any really large
362
images handy, try compressing them with -optimize and/or decompressing with
363
-colors 256 to make sure your DEFAULT_MAX_MEM setting is not too large.
364
365
NOTE: this is far from an exhaustive test of the JPEG software; some modules,
366
such as 1-pass color quantization, are not exercised at all.  It's just a
367
quick test to give you some confidence that you haven't missed something
368
major.
369
370
371
INSTALLING THE SOFTWARE
372
=======================
373
374
Once you're done with the above steps, you can install the software by
375
copying the executable files (cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom)
376
to wherever you normally install programs.  On Unix systems, you'll also want
377
to put the man pages (cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1)
378
in the man-page directory.  The pre-fab makefiles don't support this step
379
since there's such a wide variety of installation procedures on different
380
systems.
381
382
If you generated a Makefile with the "configure" script, you can just say
383
	make install
384
to install the programs and their man pages into the standard places.
385
(You'll probably need to be root to do this.)  We recommend first saying
386
	make -n install
387
to see where configure thought the files should go.  You may need to edit
388
the Makefile, particularly if your system's conventions for man page
389
filenames don't match what configure expects.
390
391
If you want to install the IJG library itself, for use in compiling other
392
programs besides ours, then you need to put the four include files
393
	jpeglib.h jerror.h jconfig.h jmorecfg.h
394
into your include-file directory, and put the library file libjpeg.a
395
(extension may vary depending on system) wherever library files go.
396
If you generated a Makefile with "configure", it will do what it thinks
397
is the right thing if you say
398
	make install-lib
399
400
401
OPTIONAL STUFF
402
==============
403
404
Progress monitor:
405
406
If you like, you can #define PROGRESS_REPORT (in jconfig.h) to enable display
407
of percent-done progress reports.  The routine provided in cdjpeg.c merely
408
prints percentages to stderr, but you can customize it to do something
409
fancier.
410
411
Utah RLE file format support:
412
413
We distribute the software with support for RLE image files (Utah Raster
414
Toolkit format) disabled, because the RLE support won't compile without the
415
Utah library.  If you have URT version 3.1 or later, you can enable RLE
416
support as follows:
417
	1.  #define RLE_SUPPORTED in jconfig.h.
418
	2.  Add a -I option to CFLAGS in the Makefile for the directory
419
	    containing the URT .h files (typically the "include"
420
	    subdirectory of the URT distribution).
421
	3.  Add -L... -lrle to LDLIBS in the Makefile, where ... specifies
422
	    the directory containing the URT "librle.a" file (typically the
423
	    "lib" subdirectory of the URT distribution).
424
425
Support for 12-bit-deep pixel data:
426
427
The JPEG standard allows either 8-bit or 12-bit data precision.  (For color,
428
this means 8 or 12 bits per channel, of course.)  If you need to work with
429
deeper than 8-bit data, you can compile the IJG code for 12-bit operation.
430
To do so:
431
  1. In jmorecfg.h, define BITS_IN_JSAMPLE as 12 rather than 8.
432
  2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED,
433
     because the code for those formats doesn't handle 12-bit data and won't
434
     even compile.  (The PPM code does work, as explained below.  The GIF
435
     code works too; it scales 8-bit GIF data to and from 12-bit depth
436
     automatically.)
437
  3. Compile.  Don't expect "make test" to pass, since the supplied test
438
     files are for 8-bit data.
439
440
Currently, 12-bit support does not work on 16-bit-int machines.
441
442
Note that a 12-bit version will not read 8-bit JPEG files, nor vice versa;
443
so you'll want to keep around a regular 8-bit compilation as well.
444
(Run-time selection of data depth, to allow a single copy that does both,
445
is possible but would probably slow things down considerably; it's very low
446
on our to-do list.)
447
448
The PPM reader (rdppm.c) can read 12-bit data from either text-format or
449
binary-format PPM and PGM files.  Binary-format PPM/PGM files which have a
450
maxval greater than 255 are assumed to use 2 bytes per sample, LSB first
451
(little-endian order).  As of early 1995, 2-byte binary format is not
452
officially supported by the PBMPLUS library, but it is expected that a
453
future release of PBMPLUS will support it.  Note that the PPM reader will
454
read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming
455
data is automatically rescaled to either maxval=255 or maxval=4095 as
456
appropriate for the cjpeg bit depth.
457
458
The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM
459
format, maxval 4095, when compiled with BITS_IN_JSAMPLE=12.  Since this
460
format is not yet widely supported, you can disable it by compiling wrppm.c
461
with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a
462
standard 1-byte/sample PPM or PGM file.  (Yes, this means still another copy
463
of djpeg to keep around.  But hopefully you won't need it for very long.
464
Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.)
465
466
Of course, if you are working with 12-bit data, you probably have it stored
467
in some other, nonstandard format.  In that case you'll probably want to
468
write your own I/O modules to read and write your format.
469
470
Note that a 12-bit version of cjpeg always runs in "-optimize" mode, in
471
order to generate valid Huffman tables.  This is necessary because our
472
default Huffman tables only cover 8-bit data.
473
474
Removing code:
475
476
If you need to make a smaller version of the JPEG software, some optional
477
functions can be removed at compile time.  See the xxx_SUPPORTED #defines in
478
jconfig.h and jmorecfg.h.  If at all possible, we recommend that you leave in
479
decoder support for all valid JPEG files, to ensure that you can read anyone's
480
output.  Taking out support for image file formats that you don't use is the
481
most painless way to make the programs smaller.  Another possibility is to
482
remove some of the DCT methods: in particular, the "IFAST" method may not be
483
enough faster than the others to be worth keeping on your machine.  (If you
484
do remove ISLOW or IFAST, be sure to redefine JDCT_DEFAULT or JDCT_FASTEST
485
to a supported method, by adding a #define in jconfig.h.)
486
487
488
OPTIMIZATION
489
============
490
491
Unless you own a Cray, you'll probably be interested in making the JPEG
492
software go as fast as possible.  This section covers some machine-dependent
493
optimizations you may want to try.  We suggest that before trying any of
494
this, you first get the basic installation to pass the self-test step.
495
Repeat the self-test after any optimization to make sure that you haven't
496
broken anything.
497
498
The integer DCT routines perform a lot of multiplications.  These
499
multiplications must yield 32-bit results, but none of their input values
500
are more than 16 bits wide.  On many machines, notably the 680x0 and 80x86
501
CPUs, a 16x16=>32 bit multiply instruction is faster than a full 32x32=>32
502
bit multiply.  Unfortunately there is no portable way to specify such a
503
multiplication in C, but some compilers can generate one when you use the
504
right combination of casts.  See the MULTIPLYxxx macro definitions in
505
jdct.h.  If your compiler makes "int" be 32 bits and "short" be 16 bits,
506
defining SHORTxSHORT_32 is fairly likely to work.  When experimenting with
507
alternate definitions, be sure to test not only whether the code still works
508
(use the self-test), but also whether it is actually faster --- on some
509
compilers, alternate definitions may compute the right answer, yet be slower
510
than the default.  Timing cjpeg on a large PGM (grayscale) input file is the
511
best way to check this, as the DCT will be the largest fraction of the runtime
512
in that mode.  (Note: some of the distributed compiler-specific jconfig files
513
already contain #define switches to select appropriate MULTIPLYxxx
514
definitions.)
515
516
If your machine has sufficiently fast floating point hardware, you may find
517
that the float DCT method is faster than the integer DCT methods, even
518
after tweaking the integer multiply macros.  In that case you may want to
519
make the float DCT be the default method.  (The only objection to this is
520
that float DCT results may vary slightly across machines.)  To do that, add
521
"#define JDCT_DEFAULT JDCT_FLOAT" to jconfig.h.  Even if you don't change
522
the default, you should redefine JDCT_FASTEST, which is the method selected
523
by djpeg's -fast switch.  Don't forget to update the documentation files
524
(usage.doc and/or cjpeg.1, djpeg.1) to agree with what you've done.
525
526
If access to "short" arrays is slow on your machine, it may be a win to
527
define type JCOEF as int rather than short.  This will cost a good deal of
528
memory though, particularly in some multi-pass modes, so don't do it unless
529
you have memory to burn and short is REALLY slow.
530
531
If your compiler can compile function calls in-line, make sure the INLINE
532
macro in jmorecfg.h is defined as the keyword that marks a function
533
inline-able.  Some compilers have a switch that tells the compiler to inline
534
any function it thinks is profitable (e.g., -finline-functions for gcc).
535
Enabling such a switch is likely to make the compiled code bigger but faster.
536
537
In general, it's worth trying the maximum optimization level of your compiler,
538
and experimenting with any optional optimizations such as loop unrolling.
539
(Unfortunately, far too many compilers have optimizer bugs ... be prepared to
540
back off if the code fails self-test.)  If you do any experimentation along
541
these lines, please report the optimal settings to jpeg-info@uunet.uu.net so
542
we can mention them in future releases.  Be sure to specify your machine and
543
compiler version.
544
545
546
HINTS FOR SPECIFIC SYSTEMS
547
==========================
548
549
We welcome reports on changes needed for systems not mentioned here.  Submit
550
'em to jpeg-info@uunet.uu.net.  Also, if configure or ckconfig.c is wrong
551
about how to configure the JPEG software for your system, please let us know.
552
553
554
Acorn RISC OS:
555
556
(Thanks to Simon Middleton for these hints on compiling with Desktop C.)
557
After renaming the files according to Acorn conventions, take a copy of
558
makefile.ansi, change all occurrences of 'libjpeg.a' to 'libjpeg.o' and
559
change these definitions as indicated:
560
561
CFLAGS= -throwback -IC: -Wn
562
LDLIBS=C:o.Stubs
563
SYSDEPMEM=jmemansi.o
564
LN=Link
565
AR=LibFile -c -o
566
567
Also add a new line '.c.o:; $(cc) $< $(cflags) -c -o $@'.  Remove the
568
lines '$(RM) libjpeg.o' and '$(AR2) libjpeg.o' and the 'jconfig.h'
569
dependency section.
570
571
Copy jconfig.doc to jconfig.h.  Edit jconfig.h to define TWO_FILE_COMMANDLINE
572
and CHAR_IS_UNSIGNED.
573
574
Run the makefile using !AMU not !Make.  If you want to use the 'clean' and
575
'test' makefile entries then you will have to fiddle with the syntax a bit
576
and rename the test files.
577
578
579
Amiga:
580
581
SAS C 6.50 reportedly is too buggy to compile the IJG code properly.
582
A patch to update to 6.51 is available from SAS or AmiNet FTP sites.
583
584
The supplied config files are set up to use jmemname.c as the memory
585
manager, with temporary files being created on the device named by
586
"JPEGTMP:".
587
588
589
Atari ST/STE/TT:
590
 
591
Copy the project files makcjpeg.st, makdjpeg.st, maktjpeg.st, and makljpeg.st
592
to cjpeg.prj, djpeg.prj, jpegtran.prj, and libjpeg.prj respectively.  The
593
project files should work as-is with Pure C.  For Turbo C, change library
594
filenames "pc..." to "tc..." in each project file.  Note that libjpeg.prj
595
selects jmemansi.c as the recommended memory manager.  You'll probably want to
596
adjust the DEFAULT_MAX_MEM setting --- you want it to be a couple hundred K
597
less than your normal free memory.  Put "#define DEFAULT_MAX_MEM nnnn" into
598
jconfig.h to do this.
599
600
To use the 68881/68882 coprocessor for the floating point DCT, add the
601
compiler option "-8" to the project files and replace pcfltlib.lib with
602
pc881lib.lib in cjpeg.prj and djpeg.prj.  Or if you don't have a
603
coprocessor, you may prefer to remove the float DCT code by undefining
604
DCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float
605
code will be too slow to be useful).  In that case, you can delete
606
pcfltlib.lib from the project files.
607
608
Note that you must make libjpeg.lib before making cjpeg.ttp, djpeg.ttp,
609
or jpegtran.ttp.  You'll have to perform the self-test by hand.
610
611
We haven't bothered to include project files for rdjpgcom and wrjpgcom.
612
Those source files should just be compiled by themselves; they don't
613
depend on the JPEG library.
614
615
There is a bug in some older versions of the Turbo C library which causes the
616
space used by temporary files created with "tmpfile()" not to be freed after
617
an abnormal program exit.  If you check your disk afterwards, you will find
618
cluster chains that are allocated but not used by a file.  This should not
619
happen in cjpeg/djpeg/jpegtran, since we enable a signal catcher to explicitly
620
close temp files before exiting.  But if you use the JPEG library with your
621
own code, be sure to supply a signal catcher, or else use a different
622
system-dependent memory manager.
623
624
625
Cray:
626
627
Should you be so fortunate as to be running JPEG on a Cray YMP, there is a
628
compiler bug in old versions of Cray's Standard C (prior to 3.1).  If you
629
still have an old compiler, you'll need to insert a line reading
630
"#pragma novector" just before the loop	
631
    for (i = 1; i <= (int) htbl->bits[l]; i++)
632
      huffsize[p++] = (char) l;
633
in fix_huff_tbl (in V5beta1, line 204 of jchuff.c and line 176 of jdhuff.c).
634
[This bug may or may not still occur with the current IJG code, but it's
635
probably a dead issue anyway...]
636
637
638
HP-UX:
639
640
If you have HP-UX 7.05 or later with the "software development" C compiler,
641
you should run the compiler in ANSI mode.  If using the configure script,
642
say
643
	./configure CC='cc -Aa'
644
(or -Ae if you prefer).  If configuring by hand, use makefile.ansi and add
645
"-Aa" to the CFLAGS line in the makefile.
646
647
If you have a pre-7.05 system, or if you are using the non-ANSI C compiler
648
delivered with a minimum HP-UX system, then you must use makefile.unix
649
(and do NOT add -Aa); or just run configure without the CC option.
650
651
On HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior
652
to A.08.07.  If you get complaints about "not a typedef name", you'll have to
653
use makefile.unix, or run configure without the CC option.
654
655
656
Macintosh, generic comments:
657
658
The supplied user-interface files (cjpeg.c, djpeg.c, etc) are set up to
659
provide a Unix-style command line interface.  You can use this interface on
660
the Mac by means of the ccommand() library routine provided by Metrowerks
661
CodeWarrior or Think C.  This is only appropriate for testing the library,
662
however; to make a user-friendly equivalent of cjpeg/djpeg you'd really want
663
to develop a Mac-style user interface.  There isn't a complete example
664
available at the moment, but there are some helpful starting points:
665
1. Sam Bushell's free "To JPEG" applet provides drag-and-drop conversion to
666
JPEG under System 7 and later.  This only illustrates how to use the
667
compression half of the library, but it does a very nice job of that part.
668
The CodeWarrior source code is available from http://www.pobox.com/~jsam.
669
2. Jim Brunner prepared a Mac-style user interface for both compression and
670
decompression.  Unfortunately, it hasn't been updated since IJG v4, and
671
the library's API has changed considerably since then.  Still it may be of
672
some help, particularly as a guide to compiling the IJG code under Think C.
673
Jim's code is available from the Info-Mac archives, at sumex-aim.stanford.edu
674
or mirrors thereof; see file /info-mac/dev/src/jpeg-convert-c.hqx.
675
676
jmemmac.c is the recommended memory manager back end for Macintosh.  It uses
677
NewPtr/DisposePtr instead of malloc/free, and has a Mac-specific
678
implementation of jpeg_mem_available().  It also creates temporary files that
679
follow Mac conventions.  (That part of the code relies on System-7-or-later OS
680
functions.  See the comments in jmemmac.c if you need to run it on System 6.)
681
NOTE that USE_MAC_MEMMGR must be defined in jconfig.h to use jmemmac.c.
682
683
You can also use jmemnobs.c, if you don't care about handling images larger
684
than available memory.  If you use any memory manager back end other than
685
jmemmac.c, we recommend replacing "malloc" and "free" by "NewPtr" and
686
"DisposePtr", because Mac C libraries often have peculiar implementations of
687
malloc/free.  (For instance, free() may not return the freed space to the
688
Mac Memory Manager.  This is undesirable for the IJG code because jmemmgr.c
689
already clumps space requests.)
690
691
692
Macintosh, Metrowerks CodeWarrior:
693
694
The Unix-command-line-style interface can be used by defining USE_CCOMMAND.
695
You'll also need to define TWO_FILE_COMMANDLINE to avoid stdin/stdout.
696
This means that when using the cjpeg/djpeg programs, you'll have to type the
697
input and output file names in the "Arguments" text-edit box, rather than
698
using the file radio buttons.  (Perhaps USE_FDOPEN or USE_SETMODE would
699
eliminate the problem, but I haven't heard from anyone who's tried it.)
700
701
On 680x0 Macs, Metrowerks defines type "double" as a 10-byte IEEE extended
702
float.  jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power
703
of 2.  Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
704
705
The supplied configuration file jconfig.mac can be used for your jconfig.h;
706
it includes all the recommended symbol definitions.  If you have AppleScript
707
installed, you can run the supplied script makeproj.mac to create CodeWarrior
708
project files for the library and the testbed applications, then build the
709
library and applications.  (Thanks to Dan Sears and Don Agro for this nifty
710
hack, which saves us from trying to maintain CodeWarrior project files as part
711
of the IJG distribution...)
712
713
714
Macintosh, Think C:
715
716
The documentation in Jim Brunner's "JPEG Convert" source code (see above)
717
includes detailed build instructions for Think C; it's probably somewhat
718
out of date for the current release, but may be helpful.
719
720
If you want to build the minimal command line version, proceed as follows.
721
You'll have to prepare project files for the programs; we don't include any
722
in the distribution since they are not text files.  Use the file lists in
723
any of the supplied makefiles as a guide.  Also add the ANSI and Unix C
724
libraries in a separate segment.  You may need to divide the JPEG files into
725
more than one segment; we recommend dividing compression and decompression
726
modules.  Define USE_CCOMMAND in jconfig.h so that the ccommand() routine is
727
called.  You must also define TWO_FILE_COMMANDLINE because stdin/stdout
728
don't handle binary data correctly.
729
730
On 680x0 Macs, Think C defines type "double" as a 12-byte IEEE extended float.
731
jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2.
732
Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
733
734
jconfig.mac should work as a jconfig.h configuration file for Think C,
735
but the makeproj.mac AppleScript script is specific to CodeWarrior.  Sorry.
736
737
738
MIPS R3000:
739
740
MIPS's cc version 1.31 has a rather nasty optimization bug.  Don't use -O
741
if you have that compiler version.  (Use "cc -V" to check the version.)
742
Note that the R3000 chip is found in workstations from DEC and others.
743
744
745
MS-DOS, generic comments for 16-bit compilers:
746
747
The IJG code is designed to work well in 80x86 "small" or "medium" memory
748
models (i.e., data pointers are 16 bits unless explicitly declared "far";
749
code pointers can be either size).  You may be able to use small model to
750
compile cjpeg or djpeg by itself, but you will probably have to use medium
751
model for any larger application.  This won't make much difference in
752
performance.  You *will* take a noticeable performance hit if you use a
753
large-data memory model, and you should avoid "huge" model if at all
754
possible.  Be sure that NEED_FAR_POINTERS is defined in jconfig.h if you use
755
a small-data memory model; be sure it is NOT defined if you use a large-data
756
model.  (The supplied makefiles and jconfig files for Borland and Microsoft C
757
compile in medium model and define NEED_FAR_POINTERS.)
758
759
The DOS-specific memory manager, jmemdos.c, should be used if possible.
760
It needs some assembly-code routines which are in jmemdosa.asm; make sure
761
your makefile assembles that file and includes it in the library.  If you
762
don't have a suitable assembler, you can get pre-assembled object files for
763
jmemdosa by FTP from ftp.uu.net:/graphics/jpeg/jdosaobj.zip.  (DOS-oriented
764
distributions of the IJG source code often include these object files.)
765
766
When using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set
767
MAX_ALLOC_CHUNK to less than 64K (65520L is a typical value).  If your
768
C library's far-heap malloc() can't allocate blocks that large, reduce
769
MAX_ALLOC_CHUNK to whatever it can handle.
770
771
If you can't use jmemdos.c for some reason --- for example, because you
772
don't have an assembler to assemble jmemdosa.asm --- you'll have to fall
773
back to jmemansi.c or jmemname.c.  You'll probably still need to set
774
MAX_ALLOC_CHUNK in jconfig.h, because most DOS C libraries won't malloc()
775
more than 64K at a time.  IMPORTANT: if you use jmemansi.c or jmemname.c,
776
you will have to compile in a large-data memory model in order to get the
777
right stdio library.  Too bad.
778
779
wrjpgcom needs to be compiled in large model, because it malloc()s a 64KB
780
work area to hold the comment text.  If your C library's malloc can't
781
handle that, reduce MAX_COM_LENGTH as necessary in wrjpgcom.c.
782
783
Most MS-DOS compilers treat stdin/stdout as text files, so you must use
784
two-file command line style.  But if your compiler has either fdopen() or
785
setmode(), you can use one-file style if you like.  To do this, define
786
USE_SETMODE or USE_FDOPEN so that stdin/stdout will be set to binary mode.
787
(USE_SETMODE seems to work with more DOS compilers than USE_FDOPEN.)  You
788
should test that I/O through stdin/stdout produces the same results as I/O
789
to explicitly named files... the "make test" procedures in the supplied
790
makefiles do NOT use stdin/stdout.
791
792
793
MS-DOS, generic comments for 32-bit compilers:
794
795
None of the above comments about memory models apply if you are using a
796
32-bit flat-memory-space environment, such as DJGPP or Watcom C.  (And you
797
should use one if you have it, as performance will be much better than
798
8086-compatible code!)  For flat-memory-space compilers, do NOT define
799
NEED_FAR_POINTERS, and do NOT use jmemdos.c.  Use jmemnobs.c if the
800
environment supplies adequate virtual memory, otherwise use jmemansi.c or
801
jmemname.c.
802
803
You'll still need to be careful about binary I/O through stdin/stdout.
804
See the last paragraph of the previous section.
805
806
807
MS-DOS, Borland C:
808
809
Be sure to convert all the source files to DOS text format (CR/LF newlines).
810
Although Borland C will often work OK with unmodified Unix (LF newlines)
811
source files, sometimes it will give bogus compile errors.
812
"Illegal character '#'" is the most common such error.  (This is true with
813
Borland C 3.1, but perhaps is fixed in newer releases.)
814
815
If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.
816
jconfig.bcc already includes #define USE_SETMODE to make this work.
817
(fdopen does not work correctly.)
818
819
820
MS-DOS, Microsoft C:
821
822
makefile.mc6 works with Microsoft C, DOS Visual C++, etc.  It should only
823
be used if you want to build a 16-bit (small or medium memory model) program.
824
825
If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.
826
jconfig.mc6 already includes #define USE_SETMODE to make this work.
827
(fdopen does not work correctly.)
828
829
Note that this makefile assumes that the working copy of itself is called
830
"makefile".  If you want to call it something else, say "makefile.mak",
831
be sure to adjust the dependency line that reads "$(RFILE) : makefile".
832
Otherwise the make will fail because it doesn't know how to create "makefile".
833
Worse, some releases of Microsoft's make utilities give an incorrect error
834
message in this situation.
835
836
Old versions of MS C fail with an "out of macro expansion space" error
837
because they can't cope with the macro TRACEMS8 (defined in jerror.h).
838
If this happens to you, the easiest solution is to change TRACEMS8 to
839
expand to nothing.  You'll lose the ability to dump out JPEG coefficient
840
tables with djpeg -debug -debug, but at least you can compile.
841
842
Original MS C 6.0 is very buggy; it compiles incorrect code unless you turn
843
off optimization entirely (remove -O from CFLAGS).  6.00A is better, but it
844
still generates bad code if you enable loop optimizations (-Ol or -Ox).
845
846
MS C 8.0 crashes when compiling jquant1.c with optimization switch /Oo ...
847
which is on by default.  To work around this bug, compile that one file
848
with /Oo-.
849
850
851
Microsoft Windows (all versions), generic comments:
852
853
Some Windows system include files define typedef boolean as "unsigned char".
854
The IJG code also defines typedef boolean, but we make it "int" by default.
855
This doesn't affect the IJG programs because we don't import those Windows
856
include files.  But if you use the JPEG library in your own program, and some
857
of your program's files import one definition of boolean while some import the
858
other, you can get all sorts of mysterious problems.  A good preventive step
859
is to make the IJG library use "unsigned char" for boolean.  To do that,
860
add something like this to your jconfig.h file:
861
	/* Define "boolean" as unsigned char, not int, per Windows custom */
862
	#ifndef __RPCNDR_H__	/* don't conflict if rpcndr.h already read */
863
	typedef unsigned char boolean;
864
	#endif
865
	#define HAVE_BOOLEAN	/* prevent jmorecfg.h from redefining it */
866
(This is already in jconfig.vc, by the way.)
867
868
windef.h contains the declarations
869
	#define far
870
	#define FAR far
871
Since jmorecfg.h tries to define FAR as empty, you may get a compiler
872
warning if you include both jpeglib.h and windef.h (which windows.h
873
includes).  To suppress the warning, you can put "#ifndef FAR"/"#endif"
874
around the line "#define FAR" in jmorecfg.h.
875
876
When using the library in a Windows application, you will almost certainly
877
want to modify or replace the error handler module jerror.c, since our
878
default error handler does a couple of inappropriate things:
879
  1. it tries to write error and warning messages on stderr;
880
  2. in event of a fatal error, it exits by calling exit().
881
882
A simple stopgap solution for problem 1 is to replace the line
883
	fprintf(stderr, "%s\n", buffer);
884
(in output_message in jerror.c) with
885
	MessageBox(GetActiveWindow(),buffer,"JPEG Error",MB_OK|MB_ICONERROR);
886
It's highly recommended that you at least do that much, since otherwise
887
error messages will disappear into nowhere.  (Beginning with IJG v6b, this
888
code is already present in jerror.c; just define USE_WINDOWS_MESSAGEBOX in
889
jconfig.h to enable it.)
890
891
The proper solution for problem 2 is to return control to your calling
892
application after a library error.  This can be done with the setjmp/longjmp
893
technique discussed in libjpeg.doc and illustrated in example.c.  (NOTE:
894
some older Windows C compilers provide versions of setjmp/longjmp that
895
don't actually work under Windows.  You may need to use the Windows system
896
functions Catch and Throw instead.)
897
898
The recommended memory manager under Windows is jmemnobs.c; in other words,
899
let Windows do any virtual memory management needed.  You should NOT use
900
jmemdos.c nor jmemdosa.asm under Windows.
901
902
For Windows 3.1, we recommend compiling in medium or large memory model;
903
for newer Windows versions, use a 32-bit flat memory model.  (See the MS-DOS
904
sections above for more info about memory models.)  In the 16-bit memory
905
models only, you'll need to put
906
	#define MAX_ALLOC_CHUNK 65520L	/* Maximum request to malloc() */
907
into jconfig.h to limit allocation chunks to 64Kb.  (Without that, you'd
908
have to use huge memory model, which slows things down unnecessarily.)
909
jmemnobs.c works without modification in large or flat memory models, but to
910
use medium model, you need to modify its jpeg_get_large and jpeg_free_large
911
routines to allocate far memory.  In any case, you might like to replace
912
its calls to malloc and free with direct calls on Windows memory allocation
913
functions.
914
915
You may also want to modify jdatasrc.c and jdatadst.c to use Windows file
916
operations rather than fread/fwrite.  This is only necessary if your C
917
compiler doesn't provide a competent implementation of C stdio functions.
918
919
You might want to tweak the RGB_xxx macros in jmorecfg.h so that the library
920
will accept or deliver color pixels in BGR sample order, not RGB; BGR order
921
is usually more convenient under Windows.  Note that this change will break
922
the sample applications cjpeg/djpeg, but the library itself works fine.
923
924
925
Many people want to convert the IJG library into a DLL.  This is reasonably
926
straightforward, but watch out for the following:
927
928
  1. Don't try to compile as a DLL in small or medium memory model; use
929
large model, or even better, 32-bit flat model.  Many places in the IJG code
930
assume the address of a local variable is an ordinary (not FAR) pointer;
931
that isn't true in a medium-model DLL.
932
933
  2. Microsoft C cannot pass file pointers between applications and DLLs.
934
(See Microsoft Knowledge Base, PSS ID Number Q50336.)  So jdatasrc.c and
935
jdatadst.c don't work if you open a file in your application and then pass
936
the pointer to the DLL.  One workaround is to make jdatasrc.c/jdatadst.c
937
part of your main application rather than part of the DLL.
938
939
  3. You'll probably need to modify the macros GLOBAL() and EXTERN() to
940
attach suitable linkage keywords to the exported routine names.  Similarly,
941
you'll want to modify METHODDEF() and JMETHOD() to ensure function pointers
942
are declared in a way that lets application routines be called back through
943
the function pointers.  These macros are in jmorecfg.h.  Typical definitions
944
for a 16-bit DLL are:
945
	#define GLOBAL(type)		type _far _pascal _loadds _export
946
	#define EXTERN(type)		extern type _far _pascal _loadds
947
	#define METHODDEF(type)		static type _far _pascal
948
	#define JMETHOD(type,methodname,arglist)  \
949
		type (_far _pascal *methodname) arglist
950
For a 32-bit DLL you may want something like
951
	#define GLOBAL(type)		__declspec(dllexport) type
952
	#define EXTERN(type)		extern __declspec(dllexport) type
953
Although not all the GLOBAL routines are actually intended to be called by
954
the application, the performance cost of making them all DLL entry points is
955
negligible.
956
957
The unmodified IJG library presents a very C-specific application interface,
958
so the resulting DLL is only usable from C or C++ applications.  There has
959
been some talk of writing wrapper code that would present a simpler interface
960
usable from other languages, such as Visual Basic.  This is on our to-do list
961
but hasn't been very high priority --- any volunteers out there?
962
963
964
Microsoft Windows, Borland C:
965
966
The provided jconfig.bcc should work OK in a 32-bit Windows environment,
967
but you'll need to tweak it in a 16-bit environment (you'd need to define
968
NEED_FAR_POINTERS and MAX_ALLOC_CHUNK).  Beware that makefile.bcc will need
969
alteration if you want to use it for Windows --- in particular, you should
970
use jmemnobs.c not jmemdos.c under Windows.
971
972
Borland C++ 4.5 fails with an internal compiler error when trying to compile
973
jdmerge.c in 32-bit mode.  If enough people complain, perhaps Borland will fix
974
it.  In the meantime, the simplest known workaround is to add a redundant
975
definition of the variable range_limit in h2v1_merged_upsample(), at the head
976
of the block that handles odd image width (about line 268 in v6 jdmerge.c):
977
  /* If image width is odd, do the last output column separately */
978
  if (cinfo->output_width & 1) {
979
    register JSAMPLE * range_limit = cinfo->sample_range_limit; /* ADD THIS */
980
    cb = GETJSAMPLE(*inptr1);
981
Pretty bizarre, especially since the very similar routine h2v2_merged_upsample
982
doesn't trigger the bug.
983
Recent reports suggest that this bug does not occur with "bcc32a" (the
984
Pentium-optimized version of the compiler).
985
986
Another report from a user of Borland C 4.5 was that incorrect code (leading
987
to a color shift in processed images) was produced if any of the following
988
optimization switch combinations were used: 
989
	-Ot -Og
990
	-Ot -Op
991
	-Ot -Om
992
So try backing off on optimization if you see such a problem.  (Are there
993
several different releases all numbered "4.5"??)
994
995
996
Microsoft Windows, Microsoft Visual C++:
997
998
jconfig.vc should work OK with any Microsoft compiler for a 32-bit memory
999
model.  makefile.vc is intended for command-line use.  (If you are using
1000
the Developer Studio environment, you may prefer the DevStudio project
1001
files; see below.)
1002
1003
Some users feel that it's easier to call the library from C++ code if you
1004
force VC++ to treat the library as C++ code, which you can do by renaming
1005
all the *.c files to *.cpp (and adjusting the makefile to match).  This
1006
avoids the need to put extern "C" { ... } around #include "jpeglib.h" in
1007
your C++ application.
1008
1009
1010
Microsoft Windows, Microsoft Developer Studio:
1011
1012
We include makefiles that should work as project files in DevStudio 4.2 or
1013
later.  There is a library makefile that builds the IJG library as a static
1014
Win32 library, and an application makefile that builds the sample applications
1015
as Win32 console applications.  (Even if you only want the library, we
1016
recommend building the applications so that you can run the self-test.)
1017
1018
To use:
1019
1. Copy jconfig.vc to jconfig.h, makelib.ds to jpeg.mak, and
1020
   makeapps.ds to apps.mak.  (Note that the renaming is critical!)
1021
2. Click on the .mak files to construct project workspaces.
1022
   (If you are using DevStudio more recent than 4.2, you'll probably
1023
   get a message saying that the makefiles are being updated.)
1024
3. Build the library project, then the applications project.
1025
4. Move the application .exe files from `app`\Release to an
1026
   appropriate location on your path.
1027
5. To perform the self-test, execute the command line
1028
	NMAKE /f makefile.vc  test
1029
1030
1031
OS/2, Borland C++:
1032
1033
Watch out for optimization bugs in older Borland compilers; you may need
1034
to back off the optimization switch settings.  See the comments in
1035
makefile.bcc.
1036
1037
1038
SGI:
1039
1040
On some SGI systems, you may need to set "AR2= ar -ts" in the Makefile.
1041
If you are using configure, you can do this by saying
1042
	./configure RANLIB='ar -ts'
1043
This change is not needed on all SGIs.  Use it only if the make fails at the
1044
stage of linking the completed programs.
1045
1046
On the MIPS R4000 architecture (Indy, etc.), the compiler option "-mips2"
1047
reportedly speeds up the float DCT method substantially, enough to make it
1048
faster than the default int method (but still slower than the fast int
1049
method).  If you use -mips2, you may want to alter the default DCT method to
1050
be float.  To do this, put "#define JDCT_DEFAULT JDCT_FLOAT" in jconfig.h.
1051
1052
1053
VMS:
1054
1055
On an Alpha/VMS system with MMS, be sure to use the "/Marco=Alpha=1"
1056
qualifier with MMS when building the JPEG package.
1057
1058
VAX/VMS v5.5-1 may have problems with the test step of the build procedure
1059
reporting differences when it compares the original and test images.  If the
1060
error points to the last block of the files, it is most likely bogus and may
1061
be safely ignored.  It seems to be because the files are Stream_LF and
1062
Backup/Compare has difficulty with the (presumably) null padded files.
1063
This problem was not observed on VAX/VMS v6.1 or AXP/VMS v6.1.
(-)a/jpeg/jaricom.c (+152 lines)
Line     Link Here 
Line 0    Link Here 
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 )
(-)a/jpeg/jcapimin.c (-1 / +13 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jcapimin.c
2
 * jcapimin.c
3
 *
3
 *
4
 * Copyright (C) 1994-1998, Thomas G. Lane.
4
 * Copyright (C) 1994-1998, Thomas G. Lane.
5
 * Modified 2003-2010 by Guido Vollbeding.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains application interface code for the compression half
9
 * This file contains application interface code for the compression half
9
 * of the JPEG library.  These are the "minimum" API routines that may be
10
 * of the JPEG library.  These are the "minimum" API routines that may be
10
 * needed in either the normal full-compression case or the transcoding-only
11
 * needed in either the normal full-compression case or the transcoding-only
11
 * case.
12
 * case.
12
 *
13
 *
 Lines 58-81   jpeg_CreateCompress (j_compress_ptr cinf Link Here 
58
  jinit_memory_mgr((j_common_ptr) cinfo);
59
  jinit_memory_mgr((j_common_ptr) cinfo);
59
60
60
  /* Zero out pointers to permanent structures. */
61
  /* Zero out pointers to permanent structures. */
61
  cinfo->progress = NULL;
62
  cinfo->progress = NULL;
62
  cinfo->dest = NULL;
63
  cinfo->dest = NULL;
63
64
64
  cinfo->comp_info = NULL;
65
  cinfo->comp_info = NULL;
65
66
66
  for (i = 0; i < NUM_QUANT_TBLS; i++)
67
  for (i = 0; i < NUM_QUANT_TBLS; i++) {
67
    cinfo->quant_tbl_ptrs[i] = NULL;
68
    cinfo->quant_tbl_ptrs[i] = NULL;
69
#if JPEG_LIB_VERSION >= 70
70
    cinfo->q_scale_factor[i] = 100;
71
#endif
72
  }
68
73
69
  for (i = 0; i < NUM_HUFF_TBLS; i++) {
74
  for (i = 0; i < NUM_HUFF_TBLS; i++) {
70
    cinfo->dc_huff_tbl_ptrs[i] = NULL;
75
    cinfo->dc_huff_tbl_ptrs[i] = NULL;
71
    cinfo->ac_huff_tbl_ptrs[i] = NULL;
76
    cinfo->ac_huff_tbl_ptrs[i] = NULL;
72
  }
77
  }
73
78
79
#if JPEG_LIB_VERSION >= 80
80
  /* Must do it here for emit_dqt in case jpeg_write_tables is used */
81
  cinfo->block_size = DCTSIZE;
82
  cinfo->natural_order = jpeg_natural_order;
83
  cinfo->lim_Se = DCTSIZE2-1;
84
#endif
85
74
  cinfo->script_space = NULL;
86
  cinfo->script_space = NULL;
75
87
76
  cinfo->input_gamma = 1.0;	/* in case application forgets */
88
  cinfo->input_gamma = 1.0;	/* in case application forgets */
77
89
78
  /* OK, I'm ready */
90
  /* OK, I'm ready */
79
  cinfo->global_state = CSTATE_START;
91
  cinfo->global_state = CSTATE_START;
80
}
92
}
81
93
(-)a/jpeg/jcarith.c (+925 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * jcarith.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 portable arithmetic entropy encoding routines for JPEG
9
 * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81).
10
 *
11
 * Both sequential and progressive modes are supported in this single module.
12
 *
13
 * Suspension is not currently supported in this module.
14
 */
15
16
#define JPEG_INTERNALS
17
#include "jinclude.h"
18
#include "jpeglib.h"
19
20
21
/* Expanded entropy encoder object for arithmetic encoding. */
22
23
typedef struct {
24
  struct jpeg_entropy_encoder pub; /* public fields */
25
26
  INT32 c; /* C register, base of coding interval, layout as in sec. D.1.3 */
27
  INT32 a;               /* A register, normalized size of coding interval */
28
  INT32 sc;        /* counter for stacked 0xFF values which might overflow */
29
  INT32 zc;          /* counter for pending 0x00 output values which might *
30
                          * be discarded at the end ("Pacman" termination) */
31
  int ct;  /* bit shift counter, determines when next byte will be written */
32
  int buffer;                /* buffer for most recent output byte != 0xFF */
33
34
  int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
35
  int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
36
37
  unsigned int restarts_to_go;	/* MCUs left in this restart interval */
38
  int next_restart_num;		/* next restart number to write (0-7) */
39
40
  /* Pointers to statistics areas (these workspaces have image lifespan) */
41
  unsigned char * dc_stats[NUM_ARITH_TBLS];
42
  unsigned char * ac_stats[NUM_ARITH_TBLS];
43
44
  /* Statistics bin for coding with fixed probability 0.5 */
45
  unsigned char fixed_bin[4];
46
} arith_entropy_encoder;
47
48
typedef arith_entropy_encoder * arith_entropy_ptr;
49
50
/* The following two definitions specify the allocation chunk size
51
 * for the statistics area.
52
 * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least
53
 * 49 statistics bins for DC, and 245 statistics bins for AC coding.
54
 *
55
 * We use a compact representation with 1 byte per statistics bin,
56
 * thus the numbers directly represent byte sizes.
57
 * This 1 byte per statistics bin contains the meaning of the MPS
58
 * (more probable symbol) in the highest bit (mask 0x80), and the
59
 * index into the probability estimation state machine table
60
 * in the lower bits (mask 0x7F).
61
 */
62
63
#define DC_STAT_BINS 64
64
#define AC_STAT_BINS 256
65
66
/* NOTE: Uncomment the following #define if you want to use the
67
 * given formula for calculating the AC conditioning parameter Kx
68
 * for spectral selection progressive coding in section G.1.3.2
69
 * of the spec (Kx = Kmin + SRL (8 + Se - Kmin) 4).
70
 * Although the spec and P&M authors claim that this "has proven
71
 * to give good results for 8 bit precision samples", I'm not
72
 * convinced yet that this is really beneficial.
73
 * Early tests gave only very marginal compression enhancements
74
 * (a few - around 5 or so - bytes even for very large files),
75
 * which would turn out rather negative if we'd suppress the
76
 * DAC (Define Arithmetic Conditioning) marker segments for
77
 * the default parameters in the future.
78
 * Note that currently the marker writing module emits 12-byte
79
 * DAC segments for a full-component scan in a color image.
80
 * This is not worth worrying about IMHO. However, since the
81
 * spec defines the default values to be used if the tables
82
 * are omitted (unlike Huffman tables, which are required
83
 * anyway), one might optimize this behaviour in the future,
84
 * and then it would be disadvantageous to use custom tables if
85
 * they don't provide sufficient gain to exceed the DAC size.
86
 *
87
 * On the other hand, I'd consider it as a reasonable result
88
 * that the conditioning has no significant influence on the
89
 * compression performance. This means that the basic
90
 * statistical model is already rather stable.
91
 *
92
 * Thus, at the moment, we use the default conditioning values
93
 * anyway, and do not use the custom formula.
94
 *
95
#define CALCULATE_SPECTRAL_CONDITIONING
96
 */
97
98
/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32.
99
 * We assume that int right shift is unsigned if INT32 right shift is,
100
 * which should be safe.
101
 */
102
103
#ifdef RIGHT_SHIFT_IS_UNSIGNED
104
#define ISHIFT_TEMPS	int ishift_temp;
105
#define IRIGHT_SHIFT(x,shft)  \
106
	((ishift_temp = (x)) < 0 ? \
107
	 (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
108
	 (ishift_temp >> (shft)))
109
#else
110
#define ISHIFT_TEMPS
111
#define IRIGHT_SHIFT(x,shft)	((x) >> (shft))
112
#endif
113
114
115
LOCAL(void)
116
emit_byte (int val, j_compress_ptr cinfo)
117
/* Write next output byte; we do not support suspension in this module. */
118
{
119
  struct jpeg_destination_mgr * dest = cinfo->dest;
120
121
  *dest->next_output_byte++ = (JOCTET) val;
122
  if (--dest->free_in_buffer == 0)
123
    if (! (*dest->empty_output_buffer) (cinfo))
124
      ERREXIT(cinfo, JERR_CANT_SUSPEND);
125
}
126
127
128
/*
129
 * Finish up at the end of an arithmetic-compressed scan.
130
 */
131
132
METHODDEF(void)
133
finish_pass (j_compress_ptr cinfo)
134
{
135
  arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
136
  INT32 temp;
137
138
  /* Section D.1.8: Termination of encoding */
139
140
  /* Find the e->c in the coding interval with the largest
141
   * number of trailing zero bits */
142
  if ((temp = (e->a - 1 + e->c) & 0xFFFF0000L) < e->c)
143
    e->c = temp + 0x8000L;
144
  else
145
    e->c = temp;
146
  /* Send remaining bytes to output */
147
  e->c <<= e->ct;
148
  if (e->c & 0xF8000000L) {
149
    /* One final overflow has to be handled */
150
    if (e->buffer >= 0) {
151
      if (e->zc)
152
	do emit_byte(0x00, cinfo);
153
	while (--e->zc);
154
      emit_byte(e->buffer + 1, cinfo);
155
      if (e->buffer + 1 == 0xFF)
156
	emit_byte(0x00, cinfo);
157
    }
158
    e->zc += e->sc;  /* carry-over converts stacked 0xFF bytes to 0x00 */
159
    e->sc = 0;
160
  } else {
161
    if (e->buffer == 0)
162
      ++e->zc;
163
    else if (e->buffer >= 0) {
164
      if (e->zc)
165
	do emit_byte(0x00, cinfo);
166
	while (--e->zc);
167
      emit_byte(e->buffer, cinfo);
168
    }
169
    if (e->sc) {
170
      if (e->zc)
171
	do emit_byte(0x00, cinfo);
172
	while (--e->zc);
173
      do {
174
	emit_byte(0xFF, cinfo);
175
	emit_byte(0x00, cinfo);
176
      } while (--e->sc);
177
    }
178
  }
179
  /* Output final bytes only if they are not 0x00 */
180
  if (e->c & 0x7FFF800L) {
181
    if (e->zc)  /* output final pending zero bytes */
182
      do emit_byte(0x00, cinfo);
183
      while (--e->zc);
184
    emit_byte((e->c >> 19) & 0xFF, cinfo);
185
    if (((e->c >> 19) & 0xFF) == 0xFF)
186
      emit_byte(0x00, cinfo);
187
    if (e->c & 0x7F800L) {
188
      emit_byte((e->c >> 11) & 0xFF, cinfo);
189
      if (((e->c >> 11) & 0xFF) == 0xFF)
190
	emit_byte(0x00, cinfo);
191
    }
192
  }
193
}
194
195
196
/*
197
 * The core arithmetic encoding routine (common in JPEG and JBIG).
198
 * This needs to go as fast as possible.
199
 * Machine-dependent optimization facilities
200
 * are not utilized in this portable implementation.
201
 * However, this code should be fairly efficient and
202
 * may be a good base for further optimizations anyway.
203
 *
204
 * Parameter 'val' to be encoded may be 0 or 1 (binary decision).
205
 *
206
 * Note: I've added full "Pacman" termination support to the
207
 * byte output routines, which is equivalent to the optional
208
 * Discard_final_zeros procedure (Figure D.15) in the spec.
209
 * Thus, we always produce the shortest possible output
210
 * stream compliant to the spec (no trailing zero bytes,
211
 * except for FF stuffing).
212
 *
213
 * I've also introduced a new scheme for accessing
214
 * the probability estimation state machine table,
215
 * derived from Markus Kuhn's JBIG implementation.
216
 */
217
218
LOCAL(void)
219
arith_encode (j_compress_ptr cinfo, unsigned char *st, int val) 
220
{
221
  register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
222
  register unsigned char nl, nm;
223
  register INT32 qe, temp;
224
  register int sv;
225
226
  /* Fetch values from our compact representation of Table D.2:
227
   * Qe values and probability estimation state machine
228
   */
229
  sv = *st;
230
  qe = jpeg_aritab[sv & 0x7F];	/* => Qe_Value */
231
  nl = qe & 0xFF; qe >>= 8;	/* Next_Index_LPS + Switch_MPS */
232
  nm = qe & 0xFF; qe >>= 8;	/* Next_Index_MPS */
233
234
  /* Encode & estimation procedures per sections D.1.4 & D.1.5 */
235
  e->a -= qe;
236
  if (val != (sv >> 7)) {
237
    /* Encode the less probable symbol */
238
    if (e->a >= qe) {
239
      /* If the interval size (qe) for the less probable symbol (LPS)
240
       * is larger than the interval size for the MPS, then exchange
241
       * the two symbols for coding efficiency, otherwise code the LPS
242
       * as usual: */
243
      e->c += e->a;
244
      e->a = qe;
245
    }
246
    *st = (sv & 0x80) ^ nl;	/* Estimate_after_LPS */
247
  } else {
248
    /* Encode the more probable symbol */
249
    if (e->a >= 0x8000L)
250
      return;  /* A >= 0x8000 -> ready, no renormalization required */
251
    if (e->a < qe) {
252
      /* If the interval size (qe) for the less probable symbol (LPS)
253
       * is larger than the interval size for the MPS, then exchange
254
       * the two symbols for coding efficiency: */
255
      e->c += e->a;
256
      e->a = qe;
257
    }
258
    *st = (sv & 0x80) ^ nm;	/* Estimate_after_MPS */
259
  }
260
261
  /* Renormalization & data output per section D.1.6 */
262
  do {
263
    e->a <<= 1;
264
    e->c <<= 1;
265
    if (--e->ct == 0) {
266
      /* Another byte is ready for output */
267
      temp = e->c >> 19;
268
      if (temp > 0xFF) {
269
	/* Handle overflow over all stacked 0xFF bytes */
270
	if (e->buffer >= 0) {
271
	  if (e->zc)
272
	    do emit_byte(0x00, cinfo);
273
	    while (--e->zc);
274
	  emit_byte(e->buffer + 1, cinfo);
275
	  if (e->buffer + 1 == 0xFF)
276
	    emit_byte(0x00, cinfo);
277
	}
278
	e->zc += e->sc;  /* carry-over converts stacked 0xFF bytes to 0x00 */
279
	e->sc = 0;
280
	/* Note: The 3 spacer bits in the C register guarantee
281
	 * that the new buffer byte can't be 0xFF here
282
	 * (see page 160 in the P&M JPEG book). */
283
	e->buffer = temp & 0xFF;  /* new output byte, might overflow later */
284
      } else if (temp == 0xFF) {
285
	++e->sc;  /* stack 0xFF byte (which might overflow later) */
286
      } else {
287
	/* Output all stacked 0xFF bytes, they will not overflow any more */
288
	if (e->buffer == 0)
289
	  ++e->zc;
290
	else if (e->buffer >= 0) {
291
	  if (e->zc)
292
	    do emit_byte(0x00, cinfo);
293
	    while (--e->zc);
294
	  emit_byte(e->buffer, cinfo);
295
	}
296
	if (e->sc) {
297
	  if (e->zc)
298
	    do emit_byte(0x00, cinfo);
299
	    while (--e->zc);
300
	  do {
301
	    emit_byte(0xFF, cinfo);
302
	    emit_byte(0x00, cinfo);
303
	  } while (--e->sc);
304
	}
305
	e->buffer = temp & 0xFF;  /* new output byte (can still overflow) */
306
      }
307
      e->c &= 0x7FFFFL;
308
      e->ct += 8;
309
    }
310
  } while (e->a < 0x8000L);
311
}
312
313
314
/*
315
 * Emit a restart marker & resynchronize predictions.
316
 */
317
318
LOCAL(void)
319
emit_restart (j_compress_ptr cinfo, int restart_num)
320
{
321
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
322
  int ci;
323
  jpeg_component_info * compptr;
324
325
  finish_pass(cinfo);
326
327
  emit_byte(0xFF, cinfo);
328
  emit_byte(JPEG_RST0 + restart_num, cinfo);
329
330
  /* Re-initialize statistics areas */
331
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
332
    compptr = cinfo->cur_comp_info[ci];
333
    /* DC needs no table for refinement scan */
334
    if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
335
      MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);
336
      /* Reset DC predictions to 0 */
337
      entropy->last_dc_val[ci] = 0;
338
      entropy->dc_context[ci] = 0;
339
    }
340
    /* AC needs no table when not present */
341
    if (cinfo->progressive_mode == 0 || cinfo->Se) {
342
      MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);
343
    }
344
  }
345
346
  /* Reset arithmetic encoding variables */
347
  entropy->c = 0;
348
  entropy->a = 0x10000L;
349
  entropy->sc = 0;
350
  entropy->zc = 0;
351
  entropy->ct = 11;
352
  entropy->buffer = -1;  /* empty */
353
}
354
355
356
/*
357
 * MCU encoding for DC initial scan (either spectral selection,
358
 * or first pass of successive approximation).
359
 */
360
361
METHODDEF(boolean)
362
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
363
{
364
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
365
  JBLOCKROW block;
366
  unsigned char *st;
367
  int blkn, ci, tbl;
368
  int v, v2, m;
369
  ISHIFT_TEMPS
370
371
  /* Emit restart marker if needed */
372
  if (cinfo->restart_interval) {
373
    if (entropy->restarts_to_go == 0) {
374
      emit_restart(cinfo, entropy->next_restart_num);
375
      entropy->restarts_to_go = cinfo->restart_interval;
376
      entropy->next_restart_num++;
377
      entropy->next_restart_num &= 7;
378
    }
379
    entropy->restarts_to_go--;
380
  }
381
382
  /* Encode the MCU data blocks */
383
  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
384
    block = MCU_data[blkn];
385
    ci = cinfo->MCU_membership[blkn];
386
    tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
387
388
    /* Compute the DC value after the required point transform by Al.
389
     * This is simply an arithmetic right shift.
390
     */
391
    m = IRIGHT_SHIFT((int) ((*block)[0]), cinfo->Al);
392
393
    /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */
394
395
    /* Table F.4: Point to statistics bin S0 for DC coefficient coding */
396
    st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
397
398
    /* Figure F.4: Encode_DC_DIFF */
399
    if ((v = m - entropy->last_dc_val[ci]) == 0) {
400
      arith_encode(cinfo, st, 0);
401
      entropy->dc_context[ci] = 0;	/* zero diff category */
402
    } else {
403
      entropy->last_dc_val[ci] = m;
404
      arith_encode(cinfo, st, 1);
405
      /* Figure F.6: Encoding nonzero value v */
406
      /* Figure F.7: Encoding the sign of v */
407
      if (v > 0) {
408
	arith_encode(cinfo, st + 1, 0);	/* Table F.4: SS = S0 + 1 */
409
	st += 2;			/* Table F.4: SP = S0 + 2 */
410
	entropy->dc_context[ci] = 4;	/* small positive diff category */
411
      } else {
412
	v = -v;
413
	arith_encode(cinfo, st + 1, 1);	/* Table F.4: SS = S0 + 1 */
414
	st += 3;			/* Table F.4: SN = S0 + 3 */
415
	entropy->dc_context[ci] = 8;	/* small negative diff category */
416
      }
417
      /* Figure F.8: Encoding the magnitude category of v */
418
      m = 0;
419
      if (v -= 1) {
420
	arith_encode(cinfo, st, 1);
421
	m = 1;
422
	v2 = v;
423
	st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
424
	while (v2 >>= 1) {
425
	  arith_encode(cinfo, st, 1);
426
	  m <<= 1;
427
	  st += 1;
428
	}
429
      }
430
      arith_encode(cinfo, st, 0);
431
      /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
432
      if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
433
	entropy->dc_context[ci] = 0;	/* zero diff category */
434
      else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
435
	entropy->dc_context[ci] += 8;	/* large diff category */
436
      /* Figure F.9: Encoding the magnitude bit pattern of v */
437
      st += 14;
438
      while (m >>= 1)
439
	arith_encode(cinfo, st, (m & v) ? 1 : 0);
440
    }
441
  }
442
443
  return TRUE;
444
}
445
446
447
/*
448
 * MCU encoding for AC initial scan (either spectral selection,
449
 * or first pass of successive approximation).
450
 */
451
452
METHODDEF(boolean)
453
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
454
{
455
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
456
  JBLOCKROW block;
457
  unsigned char *st;
458
  int tbl, k, ke;
459
  int v, v2, m;
460
461
  /* Emit restart marker if needed */
462
  if (cinfo->restart_interval) {
463
    if (entropy->restarts_to_go == 0) {
464
      emit_restart(cinfo, entropy->next_restart_num);
465
      entropy->restarts_to_go = cinfo->restart_interval;
466
      entropy->next_restart_num++;
467
      entropy->next_restart_num &= 7;
468
    }
469
    entropy->restarts_to_go--;
470
  }
471
472
  /* Encode the MCU data block */
473
  block = MCU_data[0];
474
  tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
475
476
  /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
477
478
  /* Establish EOB (end-of-block) index */
479
  for (ke = cinfo->Se; ke > 0; ke--)
480
    /* We must apply the point transform by Al.  For AC coefficients this
481
     * is an integer division with rounding towards 0.  To do this portably
482
     * in C, we shift after obtaining the absolute value.
483
     */
484
    if ((v = (*block)[jpeg_natural_order[ke]]) >= 0) {
485
      if (v >>= cinfo->Al) break;
486
    } else {
487
      v = -v;
488
      if (v >>= cinfo->Al) break;
489
    }
490
491
  /* Figure F.5: Encode_AC_Coefficients */
492
  for (k = cinfo->Ss; k <= ke; k++) {
493
    st = entropy->ac_stats[tbl] + 3 * (k - 1);
494
    arith_encode(cinfo, st, 0);		/* EOB decision */
495
    for (;;) {
496
      if ((v = (*block)[jpeg_natural_order[k]]) >= 0) {
497
	if (v >>= cinfo->Al) {
498
	  arith_encode(cinfo, st + 1, 1);
499
	  arith_encode(cinfo, entropy->fixed_bin, 0);
500
	  break;
501
	}
502
      } else {
503
	v = -v;
504
	if (v >>= cinfo->Al) {
505
	  arith_encode(cinfo, st + 1, 1);
506
	  arith_encode(cinfo, entropy->fixed_bin, 1);
507
	  break;
508
	}
509
      }
510
      arith_encode(cinfo, st + 1, 0); st += 3; k++;
511
    }
512
    st += 2;
513
    /* Figure F.8: Encoding the magnitude category of v */
514
    m = 0;
515
    if (v -= 1) {
516
      arith_encode(cinfo, st, 1);
517
      m = 1;
518
      v2 = v;
519
      if (v2 >>= 1) {
520
	arith_encode(cinfo, st, 1);
521
	m <<= 1;
522
	st = entropy->ac_stats[tbl] +
523
	     (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
524
	while (v2 >>= 1) {
525
	  arith_encode(cinfo, st, 1);
526
	  m <<= 1;
527
	  st += 1;
528
	}
529
      }
530
    }
531
    arith_encode(cinfo, st, 0);
532
    /* Figure F.9: Encoding the magnitude bit pattern of v */
533
    st += 14;
534
    while (m >>= 1)
535
      arith_encode(cinfo, st, (m & v) ? 1 : 0);
536
  }
537
  /* Encode EOB decision only if k <= cinfo->Se */
538
  if (k <= cinfo->Se) {
539
    st = entropy->ac_stats[tbl] + 3 * (k - 1);
540
    arith_encode(cinfo, st, 1);
541
  }
542
543
  return TRUE;
544
}
545
546
547
/*
548
 * MCU encoding for DC successive approximation refinement scan.
549
 */
550
551
METHODDEF(boolean)
552
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
553
{
554
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
555
  unsigned char *st;
556
  int Al, blkn;
557
558
  /* Emit restart marker if needed */
559
  if (cinfo->restart_interval) {
560
    if (entropy->restarts_to_go == 0) {
561
      emit_restart(cinfo, entropy->next_restart_num);
562
      entropy->restarts_to_go = cinfo->restart_interval;
563
      entropy->next_restart_num++;
564
      entropy->next_restart_num &= 7;
565
    }
566
    entropy->restarts_to_go--;
567
  }
568
569
  st = entropy->fixed_bin;	/* use fixed probability estimation */
570
  Al = cinfo->Al;
571
572
  /* Encode the MCU data blocks */
573
  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
574
    /* We simply emit the Al'th bit of the DC coefficient value. */
575
    arith_encode(cinfo, st, (MCU_data[blkn][0][0] >> Al) & 1);
576
  }
577
578
  return TRUE;
579
}
580
581
582
/*
583
 * MCU encoding for AC successive approximation refinement scan.
584
 */
585
586
METHODDEF(boolean)
587
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
588
{
589
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
590
  JBLOCKROW block;
591
  unsigned char *st;
592
  int tbl, k, ke, kex;
593
  int v;
594
595
  /* Emit restart marker if needed */
596
  if (cinfo->restart_interval) {
597
    if (entropy->restarts_to_go == 0) {
598
      emit_restart(cinfo, entropy->next_restart_num);
599
      entropy->restarts_to_go = cinfo->restart_interval;
600
      entropy->next_restart_num++;
601
      entropy->next_restart_num &= 7;
602
    }
603
    entropy->restarts_to_go--;
604
  }
605
606
  /* Encode the MCU data block */
607
  block = MCU_data[0];
608
  tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
609
610
  /* Section G.1.3.3: Encoding of AC coefficients */
611
612
  /* Establish EOB (end-of-block) index */
613
  for (ke = cinfo->Se; ke > 0; ke--)
614
    /* We must apply the point transform by Al.  For AC coefficients this
615
     * is an integer division with rounding towards 0.  To do this portably
616
     * in C, we shift after obtaining the absolute value.
617
     */
618
    if ((v = (*block)[jpeg_natural_order[ke]]) >= 0) {
619
      if (v >>= cinfo->Al) break;
620
    } else {
621
      v = -v;
622
      if (v >>= cinfo->Al) break;
623
    }
624
625
  /* Establish EOBx (previous stage end-of-block) index */
626
  for (kex = ke; kex > 0; kex--)
627
    if ((v = (*block)[jpeg_natural_order[kex]]) >= 0) {
628
      if (v >>= cinfo->Ah) break;
629
    } else {
630
      v = -v;
631
      if (v >>= cinfo->Ah) break;
632
    }
633
634
  /* Figure G.10: Encode_AC_Coefficients_SA */
635
  for (k = cinfo->Ss; k <= ke; k++) {
636
    st = entropy->ac_stats[tbl] + 3 * (k - 1);
637
    if (k > kex)
638
      arith_encode(cinfo, st, 0);	/* EOB decision */
639
    for (;;) {
640
      if ((v = (*block)[jpeg_natural_order[k]]) >= 0) {
641
	if (v >>= cinfo->Al) {
642
	  if (v >> 1)			/* previously nonzero coef */
643
	    arith_encode(cinfo, st + 2, (v & 1));
644
	  else {			/* newly nonzero coef */
645
	    arith_encode(cinfo, st + 1, 1);
646
	    arith_encode(cinfo, entropy->fixed_bin, 0);
647
	  }
648
	  break;
649
	}
650
      } else {
651
	v = -v;
652
	if (v >>= cinfo->Al) {
653
	  if (v >> 1)			/* previously nonzero coef */
654
	    arith_encode(cinfo, st + 2, (v & 1));
655
	  else {			/* newly nonzero coef */
656
	    arith_encode(cinfo, st + 1, 1);
657
	    arith_encode(cinfo, entropy->fixed_bin, 1);
658
	  }
659
	  break;
660
	}
661
      }
662
      arith_encode(cinfo, st + 1, 0); st += 3; k++;
663
    }
664
  }
665
  /* Encode EOB decision only if k <= cinfo->Se */
666
  if (k <= cinfo->Se) {
667
    st = entropy->ac_stats[tbl] + 3 * (k - 1);
668
    arith_encode(cinfo, st, 1);
669
  }
670
671
  return TRUE;
672
}
673
674
675
/*
676
 * Encode and output one MCU's worth of arithmetic-compressed coefficients.
677
 */
678
679
METHODDEF(boolean)
680
encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
681
{
682
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
683
  jpeg_component_info * compptr;
684
  JBLOCKROW block;
685
  unsigned char *st;
686
  int blkn, ci, tbl, k, ke;
687
  int v, v2, m;
688
689
  /* Emit restart marker if needed */
690
  if (cinfo->restart_interval) {
691
    if (entropy->restarts_to_go == 0) {
692
      emit_restart(cinfo, entropy->next_restart_num);
693
      entropy->restarts_to_go = cinfo->restart_interval;
694
      entropy->next_restart_num++;
695
      entropy->next_restart_num &= 7;
696
    }
697
    entropy->restarts_to_go--;
698
  }
699
700
  /* Encode the MCU data blocks */
701
  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
702
    block = MCU_data[blkn];
703
    ci = cinfo->MCU_membership[blkn];
704
    compptr = cinfo->cur_comp_info[ci];
705
706
    /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */
707
708
    tbl = compptr->dc_tbl_no;
709
710
    /* Table F.4: Point to statistics bin S0 for DC coefficient coding */
711
    st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
712
713
    /* Figure F.4: Encode_DC_DIFF */
714
    if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) {
715
      arith_encode(cinfo, st, 0);
716
      entropy->dc_context[ci] = 0;	/* zero diff category */
717
    } else {
718
      entropy->last_dc_val[ci] = (*block)[0];
719
      arith_encode(cinfo, st, 1);
720
      /* Figure F.6: Encoding nonzero value v */
721
      /* Figure F.7: Encoding the sign of v */
722
      if (v > 0) {
723
	arith_encode(cinfo, st + 1, 0);	/* Table F.4: SS = S0 + 1 */
724
	st += 2;			/* Table F.4: SP = S0 + 2 */
725
	entropy->dc_context[ci] = 4;	/* small positive diff category */
726
      } else {
727
	v = -v;
728
	arith_encode(cinfo, st + 1, 1);	/* Table F.4: SS = S0 + 1 */
729
	st += 3;			/* Table F.4: SN = S0 + 3 */
730
	entropy->dc_context[ci] = 8;	/* small negative diff category */
731
      }
732
      /* Figure F.8: Encoding the magnitude category of v */
733
      m = 0;
734
      if (v -= 1) {
735
	arith_encode(cinfo, st, 1);
736
	m = 1;
737
	v2 = v;
738
	st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
739
	while (v2 >>= 1) {
740
	  arith_encode(cinfo, st, 1);
741
	  m <<= 1;
742
	  st += 1;
743
	}
744
      }
745
      arith_encode(cinfo, st, 0);
746
      /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
747
      if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
748
	entropy->dc_context[ci] = 0;	/* zero diff category */
749
      else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
750
	entropy->dc_context[ci] += 8;	/* large diff category */
751
      /* Figure F.9: Encoding the magnitude bit pattern of v */
752
      st += 14;
753
      while (m >>= 1)
754
	arith_encode(cinfo, st, (m & v) ? 1 : 0);
755
    }
756
757
    /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
758
759
    tbl = compptr->ac_tbl_no;
760
761
    /* Establish EOB (end-of-block) index */
762
    for (ke = DCTSIZE2 - 1; ke > 0; ke--)
763
      if ((*block)[jpeg_natural_order[ke]]) break;
764
765
    /* Figure F.5: Encode_AC_Coefficients */
766
    for (k = 1; k <= ke; k++) {
767
      st = entropy->ac_stats[tbl] + 3 * (k - 1);
768
      arith_encode(cinfo, st, 0);	/* EOB decision */
769
      while ((v = (*block)[jpeg_natural_order[k]]) == 0) {
770
	arith_encode(cinfo, st + 1, 0); st += 3; k++;
771
      }
772
      arith_encode(cinfo, st + 1, 1);
773
      /* Figure F.6: Encoding nonzero value v */
774
      /* Figure F.7: Encoding the sign of v */
775
      if (v > 0) {
776
	arith_encode(cinfo, entropy->fixed_bin, 0);
777
      } else {
778
	v = -v;
779
	arith_encode(cinfo, entropy->fixed_bin, 1);
780
      }
781
      st += 2;
782
      /* Figure F.8: Encoding the magnitude category of v */
783
      m = 0;
784
      if (v -= 1) {
785
	arith_encode(cinfo, st, 1);
786
	m = 1;
787
	v2 = v;
788
	if (v2 >>= 1) {
789
	  arith_encode(cinfo, st, 1);
790
	  m <<= 1;
791
	  st = entropy->ac_stats[tbl] +
792
	       (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
793
	  while (v2 >>= 1) {
794
	    arith_encode(cinfo, st, 1);
795
	    m <<= 1;
796
	    st += 1;
797
	  }
798
	}
799
      }
800
      arith_encode(cinfo, st, 0);
801
      /* Figure F.9: Encoding the magnitude bit pattern of v */
802
      st += 14;
803
      while (m >>= 1)
804
	arith_encode(cinfo, st, (m & v) ? 1 : 0);
805
    }
806
    /* Encode EOB decision only if k <= DCTSIZE2 - 1 */
807
    if (k <= DCTSIZE2 - 1) {
808
      st = entropy->ac_stats[tbl] + 3 * (k - 1);
809
      arith_encode(cinfo, st, 1);
810
    }
811
  }
812
813
  return TRUE;
814
}
815
816
817
/*
818
 * Initialize for an arithmetic-compressed scan.
819
 */
820
821
METHODDEF(void)
822
start_pass (j_compress_ptr cinfo, boolean gather_statistics)
823
{
824
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
825
  int ci, tbl;
826
  jpeg_component_info * compptr;
827
828
  if (gather_statistics)
829
    /* Make sure to avoid that in the master control logic!
830
     * We are fully adaptive here and need no extra
831
     * statistics gathering pass!
832
     */
833
    ERREXIT(cinfo, JERR_NOT_COMPILED);
834
835
  /* We assume jcmaster.c already validated the progressive scan parameters. */
836
837
  /* Select execution routines */
838
  if (cinfo->progressive_mode) {
839
    if (cinfo->Ah == 0) {
840
      if (cinfo->Ss == 0)
841
	entropy->pub.encode_mcu = encode_mcu_DC_first;
842
      else
843
	entropy->pub.encode_mcu = encode_mcu_AC_first;
844
    } else {
845
      if (cinfo->Ss == 0)
846
	entropy->pub.encode_mcu = encode_mcu_DC_refine;
847
      else
848
	entropy->pub.encode_mcu = encode_mcu_AC_refine;
849
    }
850
  } else
851
    entropy->pub.encode_mcu = encode_mcu;
852
853
  /* Allocate & initialize requested statistics areas */
854
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
855
    compptr = cinfo->cur_comp_info[ci];
856
    /* DC needs no table for refinement scan */
857
    if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
858
      tbl = compptr->dc_tbl_no;
859
      if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
860
	ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
861
      if (entropy->dc_stats[tbl] == NULL)
862
	entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
863
	  ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);
864
      MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
865
      /* Initialize DC predictions to 0 */
866
      entropy->last_dc_val[ci] = 0;
867
      entropy->dc_context[ci] = 0;
868
    }
869
    /* AC needs no table when not present */
870
    if (cinfo->progressive_mode == 0 || cinfo->Se) {
871
      tbl = compptr->ac_tbl_no;
872
      if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
873
	ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
874
      if (entropy->ac_stats[tbl] == NULL)
875
	entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
876
	  ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);
877
      MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
878
#ifdef CALCULATE_SPECTRAL_CONDITIONING
879
      if (cinfo->progressive_mode)
880
	/* Section G.1.3.2: Set appropriate arithmetic conditioning value Kx */
881
	cinfo->arith_ac_K[tbl] = cinfo->Ss + ((8 + cinfo->Se - cinfo->Ss) >> 4);
882
#endif
883
    }
884
  }
885
886
  /* Initialize arithmetic encoding variables */
887
  entropy->c = 0;
888
  entropy->a = 0x10000L;
889
  entropy->sc = 0;
890
  entropy->zc = 0;
891
  entropy->ct = 11;
892
  entropy->buffer = -1;  /* empty */
893
894
  /* Initialize restart stuff */
895
  entropy->restarts_to_go = cinfo->restart_interval;
896
  entropy->next_restart_num = 0;
897
}
898
899
900
/*
901
 * Module initialization routine for arithmetic entropy encoding.
902
 */
903
904
GLOBAL(void)
905
jinit_arith_encoder (j_compress_ptr cinfo)
906
{
907
  arith_entropy_ptr entropy;
908
  int i;
909
910
  entropy = (arith_entropy_ptr)
911
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
912
				SIZEOF(arith_entropy_encoder));
913
  cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
914
  entropy->pub.start_pass = start_pass;
915
  entropy->pub.finish_pass = finish_pass;
916
917
  /* Mark tables unallocated */
918
  for (i = 0; i < NUM_ARITH_TBLS; i++) {
919
    entropy->dc_stats[i] = NULL;
920
    entropy->ac_stats[i] = NULL;
921
  }
922
923
  /* Initialize index for fixed probability estimation */
924
  entropy->fixed_bin[0] = 113;
925
}
(-)a/jpeg/jccolor.c (-23 / +129 lines)
Line     Link Here 
 Lines 1-21    Link Here 
1
/*
1
/*
2
 * jccolor.c
2
 * jccolor.c
3
 *
3
 *
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
5
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
 * Copyright 2009 D. R. Commander
5
 * This file is part of the Independent JPEG Group's software.
7
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
8
 * For conditions of distribution and use, see the accompanying README file.
7
 *
9
 *
8
 * This file contains input colorspace conversion routines.
10
 * This file contains input colorspace conversion routines.
9
 */
11
 */
10
12
11
#define JPEG_INTERNALS
13
#define JPEG_INTERNALS
12
#include "jinclude.h"
14
#include "jinclude.h"
13
#include "jpeglib.h"
15
#include "jpeglib.h"
16
#include "jsimd.h"
14
17
15
18
16
/* Private subobject */
19
/* Private subobject */
17
20
18
typedef struct {
21
typedef struct {
19
  struct jpeg_color_converter pub; /* public fields */
22
  struct jpeg_color_converter pub; /* public fields */
20
23
21
  /* Private state for RGB->YCC conversion */
24
  /* Private state for RGB->YCC conversion */
 Lines 73-88   typedef my_color_converter * my_cconvert Link Here 
73
#define G_CB_OFF	(4*(MAXJSAMPLE+1))
76
#define G_CB_OFF	(4*(MAXJSAMPLE+1))
74
#define B_CB_OFF	(5*(MAXJSAMPLE+1))
77
#define B_CB_OFF	(5*(MAXJSAMPLE+1))
75
#define R_CR_OFF	B_CB_OFF		/* B=>Cb, R=>Cr are the same */
78
#define R_CR_OFF	B_CB_OFF		/* B=>Cb, R=>Cr are the same */
76
#define G_CR_OFF	(6*(MAXJSAMPLE+1))
79
#define G_CR_OFF	(6*(MAXJSAMPLE+1))
77
#define B_CR_OFF	(7*(MAXJSAMPLE+1))
80
#define B_CR_OFF	(7*(MAXJSAMPLE+1))
78
#define TABLE_SIZE	(8*(MAXJSAMPLE+1))
81
#define TABLE_SIZE	(8*(MAXJSAMPLE+1))
79
82
80
83
84
#if BITS_IN_JSAMPLE == 8
85
86
static const unsigned char red_lut[256] = {
87
  0 , 0 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 , 4 , 4 , 4 , 4 ,
88
  5 , 5 , 5 , 6 , 6 , 6 , 7 , 7 , 7 , 7 , 8 , 8 , 8 , 9 , 9 , 9 ,
89
  10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14,
90
  14, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19,
91
  19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 24,
92
  24, 24, 25, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 28,
93
  29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33,
94
  33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 36, 37, 37, 37, 38, 38,
95
  38, 39, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42, 42, 43,
96
  43, 43, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 47, 47, 47, 48,
97
  48, 48, 48, 49, 49, 49, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52,
98
  53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57,
99
  57, 58, 58, 58, 59, 59, 59, 60, 60, 60, 60, 61, 61, 61, 62, 62,
100
  62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 65, 66, 66, 66, 67,
101
  67, 67, 68, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 71,
102
  72, 72, 72, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 76, 76, 76
103
};
104
105
static const unsigned char green_lut[256] = {
106
  0  , 1  , 1  , 2  , 2  , 3  , 4  , 4  , 5  , 5  , 6  , 6  ,
107
  7  , 8  , 8  , 9  , 9  , 10 , 11 , 11 , 12 , 12 , 13 , 14 ,
108
  14 , 15 , 15 , 16 , 16 , 17 , 18 , 18 , 19 , 19 , 20 , 21 ,
109
  21 , 22 , 22 , 23 , 23 , 24 , 25 , 25 , 26 , 26 , 27 , 28 ,
110
  28 , 29 , 29 , 30 , 31 , 31 , 32 , 32 , 33 , 33 , 34 , 35 ,
111
  35 , 36 , 36 , 37 , 38 , 38 , 39 , 39 , 40 , 41 , 41 , 42 ,
112
  42 , 43 , 43 , 44 , 45 , 45 , 46 , 46 , 47 , 48 , 48 , 49 ,
113
  49 , 50 , 50 , 51 , 52 , 52 , 53 , 53 , 54 , 55 , 55 , 56 ,
114
  56 , 57 , 58 , 58 , 59 , 59 , 60 , 60 , 61 , 62 , 62 , 63 ,
115
  63 , 64 , 65 , 65 , 66 , 66 , 67 , 68 , 68 , 69 , 69 , 70 ,
116
  70 , 71 , 72 , 72 , 73 , 73 , 74 , 75 , 75 , 76 , 76 , 77 ,
117
  77 , 78 , 79 , 79 , 80 , 80 , 81 , 82 , 82 , 83 , 83 , 84 ,
118
  85 , 85 , 86 , 86 , 87 , 87 , 88 , 89 , 89 , 90 , 90 , 91 ,
119
  92 , 92 , 93 , 93 , 94 , 95 , 95 , 96 , 96 , 97 , 97 , 98 ,
120
  99 , 99 , 100, 100, 101, 102, 102, 103, 103, 104, 104, 105,
121
  106, 106, 107, 107, 108, 109, 109, 110, 110, 111, 112, 112,
122
  113, 113, 114, 114, 115, 116, 116, 117, 117, 118, 119, 119,
123
  120, 120, 121, 122, 122, 123, 123, 124, 124, 125, 126, 126,
124
  127, 127, 128, 129, 129, 130, 130, 131, 131, 132, 133, 133,
125
  134, 134, 135, 136, 136, 137, 137, 138, 139, 139, 140, 140,
126
  141, 141, 142, 143, 143, 144, 144, 145, 146, 146, 147, 147,
127
  148, 149, 149, 150
128
};
129
130
static const unsigned char blue_lut[256] = {
131
  0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 ,
132
  2 , 2 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 4 ,
133
  4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ,
134
  5 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 7 , 7 , 7 , 7 , 7 , 7 ,
135
  7 , 7 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 9 , 9 , 9 , 9 , 9 ,
136
  9 , 9 , 9 , 9 , 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11,
137
  11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13,
138
  13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14,
139
  15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
140
  16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18,
141
  18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20,
142
  20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22,
143
  22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24,
144
  24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25,
145
  26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27,
146
  27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29
147
};
148
149
#endif
150
151
81
/*
152
/*
82
 * Initialize for RGB->YCC colorspace conversion.
153
 * Initialize for RGB->YCC colorspace conversion.
83
 */
154
 */
84
155
85
METHODDEF(void)
156
METHODDEF(void)
86
rgb_ycc_start (j_compress_ptr cinfo)
157
rgb_ycc_start (j_compress_ptr cinfo)
87
{
158
{
88
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
159
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
 Lines 141-160   rgb_ycc_convert (j_compress_ptr cinfo, Link Here 
141
212
142
  while (--num_rows >= 0) {
213
  while (--num_rows >= 0) {
143
    inptr = *input_buf++;
214
    inptr = *input_buf++;
144
    outptr0 = output_buf[0][output_row];
215
    outptr0 = output_buf[0][output_row];
145
    outptr1 = output_buf[1][output_row];
216
    outptr1 = output_buf[1][output_row];
146
    outptr2 = output_buf[2][output_row];
217
    outptr2 = output_buf[2][output_row];
147
    output_row++;
218
    output_row++;
148
    for (col = 0; col < num_cols; col++) {
219
    for (col = 0; col < num_cols; col++) {
149
      r = GETJSAMPLE(inptr[RGB_RED]);
220
      r = GETJSAMPLE(inptr[rgb_red[cinfo->in_color_space]]);
150
      g = GETJSAMPLE(inptr[RGB_GREEN]);
221
      g = GETJSAMPLE(inptr[rgb_green[cinfo->in_color_space]]);
151
      b = GETJSAMPLE(inptr[RGB_BLUE]);
222
      b = GETJSAMPLE(inptr[rgb_blue[cinfo->in_color_space]]);
152
      inptr += RGB_PIXELSIZE;
223
      inptr += rgb_pixelsize[cinfo->in_color_space];
153
      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
224
      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
154
       * must be too; we do not need an explicit range-limiting operation.
225
       * must be too; we do not need an explicit range-limiting operation.
155
       * Hence the value being shifted is never negative, and we don't
226
       * Hence the value being shifted is never negative, and we don't
156
       * need the general RIGHT_SHIFT macro.
227
       * need the general RIGHT_SHIFT macro.
157
       */
228
       */
158
      /* Y */
229
      /* Y */
159
      outptr0[col] = (JSAMPLE)
230
      outptr0[col] = (JSAMPLE)
160
		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
231
		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
 Lines 182-218   rgb_ycc_convert (j_compress_ptr cinfo, Link Here 
182
 * We assume rgb_ycc_start has been called (we only use the Y tables).
253
 * We assume rgb_ycc_start has been called (we only use the Y tables).
183
 */
254
 */
184
255
185
METHODDEF(void)
256
METHODDEF(void)
186
rgb_gray_convert (j_compress_ptr cinfo,
257
rgb_gray_convert (j_compress_ptr cinfo,
187
		  JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
258
		  JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
188
		  JDIMENSION output_row, int num_rows)
259
		  JDIMENSION output_row, int num_rows)
189
{
260
{
190
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
261
  #if BITS_IN_JSAMPLE != 8
191
  register int r, g, b;
192
  register INT32 * ctab = cconvert->rgb_ycc_tab;
262
  register INT32 * ctab = cconvert->rgb_ycc_tab;
263
  #endif
193
  register JSAMPROW inptr;
264
  register JSAMPROW inptr;
194
  register JSAMPROW outptr;
265
  register JSAMPROW outptr;
195
  register JDIMENSION col;
266
  JSAMPLE *maxoutptr;
196
  JDIMENSION num_cols = cinfo->image_width;
267
  JDIMENSION num_cols = cinfo->image_width;
268
  int rindex = rgb_red[cinfo->in_color_space];
269
  int gindex = rgb_green[cinfo->in_color_space];
270
  int bindex = rgb_blue[cinfo->in_color_space];
271
  int rgbstride = rgb_pixelsize[cinfo->in_color_space];
197
272
198
  while (--num_rows >= 0) {
273
  while (--num_rows >= 0) {
199
    inptr = *input_buf++;
274
    inptr = *input_buf++;
200
    outptr = output_buf[0][output_row];
275
    outptr = output_buf[0][output_row];
276
    maxoutptr = &outptr[num_cols];
201
    output_row++;
277
    output_row++;
202
    for (col = 0; col < num_cols; col++) {
278
    for (; outptr < maxoutptr; outptr++, inptr += rgbstride) {
203
      r = GETJSAMPLE(inptr[RGB_RED]);
204
      g = GETJSAMPLE(inptr[RGB_GREEN]);
205
      b = GETJSAMPLE(inptr[RGB_BLUE]);
206
      inptr += RGB_PIXELSIZE;
207
      /* Y */
279
      /* Y */
208
      outptr[col] = (JSAMPLE)
280
      #if BITS_IN_JSAMPLE == 8
209
		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
281
      *outptr = red_lut[inptr[rindex]] + green_lut[inptr[gindex]]
210
		 >> SCALEBITS);
282
	    + blue_lut[inptr[bindex]];
283
      #else
284
      *outptr = (JSAMPLE)
285
	    ((ctab[GETJSAMPLE(inptr[rindex])+R_Y_OFF]
286
	     + ctab[GETJSAMPLE(inptr[gindex])+G_Y_OFF]
287
	     + ctab[GETJSAMPLE(inptr[bindex])+B_Y_OFF])
288
	     >> SCALEBITS);
289
      #endif
211
    }
290
    }
212
  }
291
  }
213
}
292
}
214
293
215
294
216
/*
295
/*
217
 * Convert some rows of samples to the JPEG colorspace.
296
 * Convert some rows of samples to the JPEG colorspace.
218
 * This version handles Adobe-style CMYK->YCCK conversion,
297
 * This version handles Adobe-style CMYK->YCCK conversion,
 Lines 363-383   jinit_color_converter (j_compress_ptr ci Link Here 
363
  /* Make sure input_components agrees with in_color_space */
442
  /* Make sure input_components agrees with in_color_space */
364
  switch (cinfo->in_color_space) {
443
  switch (cinfo->in_color_space) {
365
  case JCS_GRAYSCALE:
444
  case JCS_GRAYSCALE:
366
    if (cinfo->input_components != 1)
445
    if (cinfo->input_components != 1)
367
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
446
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
368
    break;
447
    break;
369
448
370
  case JCS_RGB:
449
  case JCS_RGB:
371
#if RGB_PIXELSIZE != 3
450
  case JCS_EXT_RGB:
372
    if (cinfo->input_components != RGB_PIXELSIZE)
451
  case JCS_EXT_RGBX:
452
  case JCS_EXT_BGR:
453
  case JCS_EXT_BGRX:
454
  case JCS_EXT_XBGR:
455
  case JCS_EXT_XRGB:
456
    if (cinfo->input_components != rgb_pixelsize[cinfo->in_color_space])
373
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
457
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
374
    break;
458
    break;
375
#endif /* else share code with YCbCr */
376
459
377
  case JCS_YCbCr:
460
  case JCS_YCbCr:
378
    if (cinfo->input_components != 3)
461
    if (cinfo->input_components != 3)
379
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
462
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
380
    break;
463
    break;
381
464
382
  case JCS_CMYK:
465
  case JCS_CMYK:
383
  case JCS_YCCK:
466
  case JCS_YCCK:
 Lines 393-432   jinit_color_converter (j_compress_ptr ci Link Here 
393
476
394
  /* Check num_components, set conversion method based on requested space */
477
  /* Check num_components, set conversion method based on requested space */
395
  switch (cinfo->jpeg_color_space) {
478
  switch (cinfo->jpeg_color_space) {
396
  case JCS_GRAYSCALE:
479
  case JCS_GRAYSCALE:
397
    if (cinfo->num_components != 1)
480
    if (cinfo->num_components != 1)
398
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
481
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
399
    if (cinfo->in_color_space == JCS_GRAYSCALE)
482
    if (cinfo->in_color_space == JCS_GRAYSCALE)
400
      cconvert->pub.color_convert = grayscale_convert;
483
      cconvert->pub.color_convert = grayscale_convert;
401
    else if (cinfo->in_color_space == JCS_RGB) {
484
    else if (cinfo->in_color_space == JCS_RGB ||
485
             cinfo->in_color_space == JCS_EXT_RGB ||
486
             cinfo->in_color_space == JCS_EXT_RGBX ||
487
             cinfo->in_color_space == JCS_EXT_BGR ||
488
             cinfo->in_color_space == JCS_EXT_BGRX ||
489
             cinfo->in_color_space == JCS_EXT_XBGR ||
490
             cinfo->in_color_space == JCS_EXT_XRGB) {
402
      cconvert->pub.start_pass = rgb_ycc_start;
491
      cconvert->pub.start_pass = rgb_ycc_start;
403
      cconvert->pub.color_convert = rgb_gray_convert;
492
      cconvert->pub.color_convert = rgb_gray_convert;
404
    } else if (cinfo->in_color_space == JCS_YCbCr)
493
    } else if (cinfo->in_color_space == JCS_YCbCr)
405
      cconvert->pub.color_convert = grayscale_convert;
494
      cconvert->pub.color_convert = grayscale_convert;
406
    else
495
    else
407
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
496
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
408
    break;
497
    break;
409
498
410
  case JCS_RGB:
499
  case JCS_RGB:
500
  case JCS_EXT_RGB:
501
  case JCS_EXT_RGBX:
502
  case JCS_EXT_BGR:
503
  case JCS_EXT_BGRX:
504
  case JCS_EXT_XBGR:
505
  case JCS_EXT_XRGB:
411
    if (cinfo->num_components != 3)
506
    if (cinfo->num_components != 3)
412
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
507
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
413
    if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
508
    if (cinfo->in_color_space == cinfo->jpeg_color_space &&
509
      rgb_pixelsize[cinfo->in_color_space] == 3)
414
      cconvert->pub.color_convert = null_convert;
510
      cconvert->pub.color_convert = null_convert;
415
    else
511
    else
416
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
512
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
417
    break;
513
    break;
418
514
419
  case JCS_YCbCr:
515
  case JCS_YCbCr:
420
    if (cinfo->num_components != 3)
516
    if (cinfo->num_components != 3)
421
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
517
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
422
    if (cinfo->in_color_space == JCS_RGB) {
518
    if (cinfo->in_color_space == JCS_RGB ||
423
      cconvert->pub.start_pass = rgb_ycc_start;
519
        cinfo->in_color_space == JCS_EXT_RGB ||
424
      cconvert->pub.color_convert = rgb_ycc_convert;
520
        cinfo->in_color_space == JCS_EXT_RGBX ||
521
        cinfo->in_color_space == JCS_EXT_BGR ||
522
        cinfo->in_color_space == JCS_EXT_BGRX ||
523
        cinfo->in_color_space == JCS_EXT_XBGR ||
524
        cinfo->in_color_space == JCS_EXT_XRGB) {
525
      if (jsimd_can_rgb_ycc())
526
        cconvert->pub.color_convert = jsimd_rgb_ycc_convert;
527
      else {
528
        cconvert->pub.start_pass = rgb_ycc_start;
529
        cconvert->pub.color_convert = rgb_ycc_convert;
530
      }
425
    } else if (cinfo->in_color_space == JCS_YCbCr)
531
    } else if (cinfo->in_color_space == JCS_YCbCr)
426
      cconvert->pub.color_convert = null_convert;
532
      cconvert->pub.color_convert = null_convert;
427
    else
533
    else
428
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
534
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
429
    break;
535
    break;
430
536
431
  case JCS_CMYK:
537
  case JCS_CMYK:
432
    if (cinfo->num_components != 4)
538
    if (cinfo->num_components != 4)
(-)a/jpeg/jcdctmgr.c (-122 / +377 lines)
Line     Link Here 
 Lines 1-52    Link Here 
1
/*
1
/*
2
 * jcdctmgr.c
2
 * jcdctmgr.c
3
 *
3
 *
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
5
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
6
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
7
 * Copyright (C) 2011 D. R. Commander
5
 * This file is part of the Independent JPEG Group's software.
8
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
9
 * For conditions of distribution and use, see the accompanying README file.
7
 *
10
 *
8
 * This file contains the forward-DCT management logic.
11
 * This file contains the forward-DCT management logic.
9
 * This code selects a particular DCT implementation to be used,
12
 * This code selects a particular DCT implementation to be used,
10
 * and it performs related housekeeping chores including coefficient
13
 * and it performs related housekeeping chores including coefficient
11
 * quantization.
14
 * quantization.
12
 */
15
 */
13
16
14
#define JPEG_INTERNALS
17
#define JPEG_INTERNALS
15
#include "jinclude.h"
18
#include "jinclude.h"
16
#include "jpeglib.h"
19
#include "jpeglib.h"
17
#include "jdct.h"		/* Private declarations for DCT subsystem */
20
#include "jdct.h"		/* Private declarations for DCT subsystem */
21
#include "jsimddct.h"
18
22
19
23
20
/* Private subobject for this module */
24
/* Private subobject for this module */
21
25
26
typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
27
typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
28
29
typedef JMETHOD(void, convsamp_method_ptr,
30
                (JSAMPARRAY sample_data, JDIMENSION start_col,
31
                 DCTELEM * workspace));
32
typedef JMETHOD(void, float_convsamp_method_ptr,
33
                (JSAMPARRAY sample_data, JDIMENSION start_col,
34
                 FAST_FLOAT *workspace));
35
36
typedef JMETHOD(void, quantize_method_ptr,
37
                (JCOEFPTR coef_block, DCTELEM * divisors,
38
                 DCTELEM * workspace));
39
typedef JMETHOD(void, float_quantize_method_ptr,
40
                (JCOEFPTR coef_block, FAST_FLOAT * divisors,
41
                 FAST_FLOAT * workspace));
42
43
METHODDEF(void) quantize (JCOEFPTR, DCTELEM *, DCTELEM *);
44
22
typedef struct {
45
typedef struct {
23
  struct jpeg_forward_dct pub;	/* public fields */
46
  struct jpeg_forward_dct pub;	/* public fields */
24
47
25
  /* Pointer to the DCT routine actually in use */
48
  /* Pointer to the DCT routine actually in use */
26
  forward_DCT_method_ptr do_dct;
49
  forward_DCT_method_ptr dct;
50
  convsamp_method_ptr convsamp;
51
  quantize_method_ptr quantize;
27
52
28
  /* The actual post-DCT divisors --- not identical to the quant table
53
  /* The actual post-DCT divisors --- not identical to the quant table
29
   * entries, because of scaling (especially for an unnormalized DCT).
54
   * entries, because of scaling (especially for an unnormalized DCT).
30
   * Each table is given in normal array order.
55
   * Each table is given in normal array order.
31
   */
56
   */
32
  DCTELEM * divisors[NUM_QUANT_TBLS];
57
  DCTELEM * divisors[NUM_QUANT_TBLS];
33
58
59
  /* work area for FDCT subroutine */
60
  DCTELEM * workspace;
61
34
#ifdef DCT_FLOAT_SUPPORTED
62
#ifdef DCT_FLOAT_SUPPORTED
35
  /* Same as above for the floating-point case. */
63
  /* Same as above for the floating-point case. */
36
  float_DCT_method_ptr do_float_dct;
64
  float_DCT_method_ptr float_dct;
65
  float_convsamp_method_ptr float_convsamp;
66
  float_quantize_method_ptr float_quantize;
37
  FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
67
  FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
68
  FAST_FLOAT * float_workspace;
38
#endif
69
#endif
39
} my_fdct_controller;
70
} my_fdct_controller;
40
71
41
typedef my_fdct_controller * my_fdct_ptr;
72
typedef my_fdct_controller * my_fdct_ptr;
42
73
43
74
44
/*
75
/*
76
 * Find the highest bit in an integer through binary search.
77
 */
78
LOCAL(int)
79
flss (UINT16 val)
80
{
81
  int bit;
82
83
  bit = 16;
84
85
  if (!val)
86
    return 0;
87
88
  if (!(val & 0xff00)) {
89
    bit -= 8;
90
    val <<= 8;
91
  }
92
  if (!(val & 0xf000)) {
93
    bit -= 4;
94
    val <<= 4;
95
  }
96
  if (!(val & 0xc000)) {
97
    bit -= 2;
98
    val <<= 2;
99
  }
100
  if (!(val & 0x8000)) {
101
    bit -= 1;
102
    val <<= 1;
103
  }
104
105
  return bit;
106
}
107
108
/*
109
 * Compute values to do a division using reciprocal.
110
 *
111
 * This implementation is based on an algorithm described in
112
 *   "How to optimize for the Pentium family of microprocessors"
113
 *   (http://www.agner.org/assem/).
114
 * More information about the basic algorithm can be found in
115
 * the paper "Integer Division Using Reciprocals" by Robert Alverson.
116
 *
117
 * The basic idea is to replace x/d by x * d^-1. In order to store
118
 * d^-1 with enough precision we shift it left a few places. It turns
119
 * out that this algoright gives just enough precision, and also fits
120
 * into DCTELEM:
121
 *
122
 *   b = (the number of significant bits in divisor) - 1
123
 *   r = (word size) + b
124
 *   f = 2^r / divisor
125
 *
126
 * f will not be an integer for most cases, so we need to compensate
127
 * for the rounding error introduced:
128
 *
129
 *   no fractional part:
130
 *
131
 *       result = input >> r
132
 *
133
 *   fractional part of f < 0.5:
134
 *
135
 *       round f down to nearest integer
136
 *       result = ((input + 1) * f) >> r
137
 *
138
 *   fractional part of f > 0.5:
139
 *
140
 *       round f up to nearest integer
141
 *       result = (input * f) >> r
142
 *
143
 * This is the original algorithm that gives truncated results. But we
144
 * want properly rounded results, so we replace "input" with
145
 * "input + divisor/2".
146
 *
147
 * In order to allow SIMD implementations we also tweak the values to
148
 * allow the same calculation to be made at all times:
149
 * 
150
 *   dctbl[0] = f rounded to nearest integer
151
 *   dctbl[1] = divisor / 2 (+ 1 if fractional part of f < 0.5)
152
 *   dctbl[2] = 1 << ((word size) * 2 - r)
153
 *   dctbl[3] = r - (word size)
154
 *
155
 * dctbl[2] is for stupid instruction sets where the shift operation
156
 * isn't member wise (e.g. MMX).
157
 *
158
 * The reason dctbl[2] and dctbl[3] reduce the shift with (word size)
159
 * is that most SIMD implementations have a "multiply and store top
160
 * half" operation.
161
 *
162
 * Lastly, we store each of the values in their own table instead
163
 * of in a consecutive manner, yet again in order to allow SIMD
164
 * routines.
165
 */
166
LOCAL(int)
167
compute_reciprocal (UINT16 divisor, DCTELEM * dtbl)
168
{
169
  UDCTELEM2 fq, fr;
170
  UDCTELEM c;
171
  int b, r;
172
173
  b = flss(divisor) - 1;
174
  r  = sizeof(DCTELEM) * 8 + b;
175
176
  fq = ((UDCTELEM2)1 << r) / divisor;
177
  fr = ((UDCTELEM2)1 << r) % divisor;
178
179
  c = divisor / 2; /* for rounding */
180
181
  if (fr == 0) { /* divisor is power of two */
182
    /* fq will be one bit too large to fit in DCTELEM, so adjust */
183
    fq >>= 1;
184
    r--;
185
  } else if (fr <= (divisor / 2)) { /* fractional part is < 0.5 */
186
    c++;
187
  } else { /* fractional part is > 0.5 */
188
    fq++;
189
  }
190
191
  dtbl[DCTSIZE2 * 0] = (DCTELEM) fq;      /* reciprocal */
192
  dtbl[DCTSIZE2 * 1] = (DCTELEM) c;       /* correction + roundfactor */
193
  dtbl[DCTSIZE2 * 2] = (DCTELEM) (1 << (sizeof(DCTELEM)*8*2 - r));  /* scale */
194
  dtbl[DCTSIZE2 * 3] = (DCTELEM) r - sizeof(DCTELEM)*8; /* shift */
195
196
  if(r <= 16) return 0;
197
  else return 1;
198
}
199
200
/*
45
 * Initialize for a processing pass.
201
 * Initialize for a processing pass.
46
 * Verify that all referenced Q-tables are present, and set up
202
 * Verify that all referenced Q-tables are present, and set up
47
 * the divisor table for each one.
203
 * the divisor table for each one.
48
 * In the current implementation, DCT of all components is done during
204
 * In the current implementation, DCT of all components is done during
49
 * the first pass, even if only some components will be output in the
205
 * the first pass, even if only some components will be output in the
50
 * first scan.  Hence all components should be examined here.
206
 * first scan.  Hence all components should be examined here.
51
 */
207
 */
52
208
 Lines 73-93   start_pass_fdctmgr (j_compress_ptr cinfo Link Here 
73
#ifdef DCT_ISLOW_SUPPORTED
229
#ifdef DCT_ISLOW_SUPPORTED
74
    case JDCT_ISLOW:
230
    case JDCT_ISLOW:
75
      /* For LL&M IDCT method, divisors are equal to raw quantization
231
      /* For LL&M IDCT method, divisors are equal to raw quantization
76
       * coefficients multiplied by 8 (to counteract scaling).
232
       * coefficients multiplied by 8 (to counteract scaling).
77
       */
233
       */
78
      if (fdct->divisors[qtblno] == NULL) {
234
      if (fdct->divisors[qtblno] == NULL) {
79
	fdct->divisors[qtblno] = (DCTELEM *)
235
	fdct->divisors[qtblno] = (DCTELEM *)
80
	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
236
	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
81
				      DCTSIZE2 * SIZEOF(DCTELEM));
237
				      (DCTSIZE2 * 4) * SIZEOF(DCTELEM));
82
      }
238
      }
83
      dtbl = fdct->divisors[qtblno];
239
      dtbl = fdct->divisors[qtblno];
84
      for (i = 0; i < DCTSIZE2; i++) {
240
      for (i = 0; i < DCTSIZE2; i++) {
85
	dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
241
	if(!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i])
242
	  && fdct->quantize == jsimd_quantize)
243
	  fdct->quantize = quantize;
86
      }
244
      }
87
      break;
245
      break;
88
#endif
246
#endif
89
#ifdef DCT_IFAST_SUPPORTED
247
#ifdef DCT_IFAST_SUPPORTED
90
    case JDCT_IFAST:
248
    case JDCT_IFAST:
91
      {
249
      {
92
	/* For AA&N IDCT method, divisors are equal to quantization
250
	/* For AA&N IDCT method, divisors are equal to quantization
93
	 * coefficients scaled by scalefactor[row]*scalefactor[col], where
251
	 * coefficients scaled by scalefactor[row]*scalefactor[col], where
 Lines 107-130   start_pass_fdctmgr (j_compress_ptr cinfo Link Here 
107
	   8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
265
	   8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
108
	   4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
266
	   4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
109
	};
267
	};
110
	SHIFT_TEMPS
268
	SHIFT_TEMPS
111
269
112
	if (fdct->divisors[qtblno] == NULL) {
270
	if (fdct->divisors[qtblno] == NULL) {
113
	  fdct->divisors[qtblno] = (DCTELEM *)
271
	  fdct->divisors[qtblno] = (DCTELEM *)
114
	    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
272
	    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
115
					DCTSIZE2 * SIZEOF(DCTELEM));
273
					(DCTSIZE2 * 4) * SIZEOF(DCTELEM));
116
	}
274
	}
117
	dtbl = fdct->divisors[qtblno];
275
	dtbl = fdct->divisors[qtblno];
118
	for (i = 0; i < DCTSIZE2; i++) {
276
	for (i = 0; i < DCTSIZE2; i++) {
119
	  dtbl[i] = (DCTELEM)
277
	  if(!compute_reciprocal(
120
	    DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
278
	    DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
121
				  (INT32) aanscales[i]),
279
				  (INT32) aanscales[i]),
122
		    CONST_BITS-3);
280
		    CONST_BITS-3), &dtbl[i])
281
	    && fdct->quantize == jsimd_quantize)
282
	    fdct->quantize = quantize;
123
	}
283
	}
124
      }
284
      }
125
      break;
285
      break;
126
#endif
286
#endif
127
#ifdef DCT_FLOAT_SUPPORTED
287
#ifdef DCT_FLOAT_SUPPORTED
128
    case JDCT_FLOAT:
288
    case JDCT_FLOAT:
129
      {
289
      {
130
	/* For float AA&N IDCT method, divisors are equal to quantization
290
	/* For float AA&N IDCT method, divisors are equal to quantization
 Lines 164-343   start_pass_fdctmgr (j_compress_ptr cinfo Link Here 
164
      ERREXIT(cinfo, JERR_NOT_COMPILED);
324
      ERREXIT(cinfo, JERR_NOT_COMPILED);
165
      break;
325
      break;
166
    }
326
    }
167
  }
327
  }
168
}
328
}
169
329
170
330
171
/*
331
/*
332
 * Load data into workspace, applying unsigned->signed conversion.
333
 */
334
335
METHODDEF(void)
336
convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM * workspace)
337
{
338
  register DCTELEM *workspaceptr;
339
  register JSAMPROW elemptr;
340
  register int elemr;
341
342
  workspaceptr = workspace;
343
  for (elemr = 0; elemr < DCTSIZE; elemr++) {
344
    elemptr = sample_data[elemr] + start_col;
345
346
#if DCTSIZE == 8		/* unroll the inner loop */
347
    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
348
    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
349
    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
350
    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
351
    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
352
    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
353
    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
354
    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
355
#else
356
    {
357
      register int elemc;
358
      for (elemc = DCTSIZE; elemc > 0; elemc--)
359
        *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
360
    }
361
#endif
362
  }
363
}
364
365
366
/*
367
 * Quantize/descale the coefficients, and store into coef_blocks[].
368
 */
369
370
METHODDEF(void)
371
quantize (JCOEFPTR coef_block, DCTELEM * divisors, DCTELEM * workspace)
372
{
373
  int i;
374
  DCTELEM temp;
375
  UDCTELEM recip, corr, shift;
376
  UDCTELEM2 product;
377
  JCOEFPTR output_ptr = coef_block;
378
379
  for (i = 0; i < DCTSIZE2; i++) {
380
    temp = workspace[i];
381
    recip = divisors[i + DCTSIZE2 * 0];
382
    corr =  divisors[i + DCTSIZE2 * 1];
383
    shift = divisors[i + DCTSIZE2 * 3];
384
385
    if (temp < 0) {
386
      temp = -temp;
387
      product = (UDCTELEM2)(temp + corr) * recip;
388
      product >>= shift + sizeof(DCTELEM)*8;
389
      temp = product;
390
      temp = -temp;
391
    } else {
392
      product = (UDCTELEM2)(temp + corr) * recip;
393
      product >>= shift + sizeof(DCTELEM)*8;
394
      temp = product;
395
    }
396
397
    output_ptr[i] = (JCOEF) temp;
398
  }
399
}
400
401
402
/*
172
 * Perform forward DCT on one or more blocks of a component.
403
 * Perform forward DCT on one or more blocks of a component.
173
 *
404
 *
174
 * The input samples are taken from the sample_data[] array starting at
405
 * The input samples are taken from the sample_data[] array starting at
175
 * position start_row/start_col, and moving to the right for any additional
406
 * position start_row/start_col, and moving to the right for any additional
176
 * blocks. The quantized coefficients are returned in coef_blocks[].
407
 * blocks. The quantized coefficients are returned in coef_blocks[].
177
 */
408
 */
178
409
179
METHODDEF(void)
410
METHODDEF(void)
180
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
411
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
181
	     JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
412
	     JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
182
	     JDIMENSION start_row, JDIMENSION start_col,
413
	     JDIMENSION start_row, JDIMENSION start_col,
183
	     JDIMENSION num_blocks)
414
	     JDIMENSION num_blocks)
184
/* This version is used for integer DCT implementations. */
415
/* This version is used for integer DCT implementations. */
185
{
416
{
186
  /* This routine is heavily used, so it's worth coding it tightly. */
417
  /* This routine is heavily used, so it's worth coding it tightly. */
187
  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
418
  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
188
  forward_DCT_method_ptr do_dct = fdct->do_dct;
189
  DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
419
  DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
190
  DCTELEM workspace[DCTSIZE2];	/* work area for FDCT subroutine */
420
  DCTELEM * workspace;
191
  JDIMENSION bi;
421
  JDIMENSION bi;
192
422
423
  /* Make sure the compiler doesn't look up these every pass */
424
  forward_DCT_method_ptr do_dct = fdct->dct;
425
  convsamp_method_ptr do_convsamp = fdct->convsamp;
426
  quantize_method_ptr do_quantize = fdct->quantize;
427
  workspace = fdct->workspace;
428
193
  sample_data += start_row;	/* fold in the vertical offset once */
429
  sample_data += start_row;	/* fold in the vertical offset once */
194
430
195
  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
431
  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
196
    /* Load data into workspace, applying unsigned->signed conversion */
432
    /* Load data into workspace, applying unsigned->signed conversion */
197
    { register DCTELEM *workspaceptr;
433
    (*do_convsamp) (sample_data, start_col, workspace);
198
      register JSAMPROW elemptr;
199
      register int elemr;
200
201
      workspaceptr = workspace;
202
      for (elemr = 0; elemr < DCTSIZE; elemr++) {
203
	elemptr = sample_data[elemr] + start_col;
204
#if DCTSIZE == 8		/* unroll the inner loop */
205
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
206
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
207
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
208
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
209
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
210
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
211
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
212
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
213
#else
214
	{ register int elemc;
215
	  for (elemc = DCTSIZE; elemc > 0; elemc--) {
216
	    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
217
	  }
218
	}
219
#endif
220
      }
221
    }
222
434
223
    /* Perform the DCT */
435
    /* Perform the DCT */
224
    (*do_dct) (workspace);
436
    (*do_dct) (workspace);
225
437
226
    /* Quantize/descale the coefficients, and store into coef_blocks[] */
438
    /* Quantize/descale the coefficients, and store into coef_blocks[] */
227
    { register DCTELEM temp, qval;
439
    (*do_quantize) (coef_blocks[bi], divisors, workspace);
228
      register int i;
440
  }
229
      register JCOEFPTR output_ptr = coef_blocks[bi];
441
}
230
442
231
      for (i = 0; i < DCTSIZE2; i++) {
443
232
	qval = divisors[i];
444
#ifdef DCT_FLOAT_SUPPORTED
233
	temp = workspace[i];
445
234
	/* Divide the coefficient value by qval, ensuring proper rounding.
446
235
	 * Since C does not specify the direction of rounding for negative
447
METHODDEF(void)
236
	 * quotients, we have to force the dividend positive for portability.
448
convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, FAST_FLOAT * workspace)
237
	 *
449
{
238
	 * In most files, at least half of the output values will be zero
450
  register FAST_FLOAT *workspaceptr;
239
	 * (at default quantization settings, more like three-quarters...)
451
  register JSAMPROW elemptr;
240
	 * so we should ensure that this case is fast.  On many machines,
452
  register int elemr;
241
	 * a comparison is enough cheaper than a divide to make a special test
453
242
	 * a win.  Since both inputs will be nonnegative, we need only test
454
  workspaceptr = workspace;
243
	 * for a < b to discover whether a/b is 0.
455
  for (elemr = 0; elemr < DCTSIZE; elemr++) {
244
	 * If your machine's division is fast enough, define FAST_DIVIDE.
456
    elemptr = sample_data[elemr] + start_col;
245
	 */
457
#if DCTSIZE == 8		/* unroll the inner loop */
246
#ifdef FAST_DIVIDE
458
    *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
247
#define DIVIDE_BY(a,b)	a /= b
459
    *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
460
    *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
461
    *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
462
    *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
463
    *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
464
    *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
465
    *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
248
#else
466
#else
249
#define DIVIDE_BY(a,b)	if (a >= b) a /= b; else a = 0
467
    {
250
#endif
468
      register int elemc;
251
	if (temp < 0) {
469
      for (elemc = DCTSIZE; elemc > 0; elemc--)
252
	  temp = -temp;
470
        *workspaceptr++ = (FAST_FLOAT)
253
	  temp += qval>>1;	/* for rounding */
471
                          (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
254
	  DIVIDE_BY(temp, qval);
255
	  temp = -temp;
256
	} else {
257
	  temp += qval>>1;	/* for rounding */
258
	  DIVIDE_BY(temp, qval);
259
	}
260
	output_ptr[i] = (JCOEF) temp;
261
      }
262
    }
472
    }
263
  }
473
#endif
264
}
474
  }
265
475
}
266
476
267
#ifdef DCT_FLOAT_SUPPORTED
477
478
METHODDEF(void)
479
quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors, FAST_FLOAT * workspace)
480
{
481
  register FAST_FLOAT temp;
482
  register int i;
483
  register JCOEFPTR output_ptr = coef_block;
484
485
  for (i = 0; i < DCTSIZE2; i++) {
486
    /* Apply the quantization and scaling factor */
487
    temp = workspace[i] * divisors[i];
488
489
    /* Round to nearest integer.
490
     * Since C does not specify the direction of rounding for negative
491
     * quotients, we have to force the dividend positive for portability.
492
     * The maximum coefficient size is +-16K (for 12-bit data), so this
493
     * code should work for either 16-bit or 32-bit ints.
494
     */
495
    output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
496
  }
497
}
498
268
499
269
METHODDEF(void)
500
METHODDEF(void)
270
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
501
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
271
		   JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
502
		   JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
272
		   JDIMENSION start_row, JDIMENSION start_col,
503
		   JDIMENSION start_row, JDIMENSION start_col,
273
		   JDIMENSION num_blocks)
504
		   JDIMENSION num_blocks)
274
/* This version is used for floating-point DCT implementations. */
505
/* This version is used for floating-point DCT implementations. */
275
{
506
{
276
  /* This routine is heavily used, so it's worth coding it tightly. */
507
  /* This routine is heavily used, so it's worth coding it tightly. */
277
  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
508
  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
278
  float_DCT_method_ptr do_dct = fdct->do_float_dct;
279
  FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
509
  FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
280
  FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
510
  FAST_FLOAT * workspace;
281
  JDIMENSION bi;
511
  JDIMENSION bi;
282
512
513
514
  /* Make sure the compiler doesn't look up these every pass */
515
  float_DCT_method_ptr do_dct = fdct->float_dct;
516
  float_convsamp_method_ptr do_convsamp = fdct->float_convsamp;
517
  float_quantize_method_ptr do_quantize = fdct->float_quantize;
518
  workspace = fdct->float_workspace;
519
283
  sample_data += start_row;	/* fold in the vertical offset once */
520
  sample_data += start_row;	/* fold in the vertical offset once */
284
521
285
  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
522
  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
286
    /* Load data into workspace, applying unsigned->signed conversion */
523
    /* Load data into workspace, applying unsigned->signed conversion */
287
    { register FAST_FLOAT *workspaceptr;
524
    (*do_convsamp) (sample_data, start_col, workspace);
288
      register JSAMPROW elemptr;
289
      register int elemr;
290
291
      workspaceptr = workspace;
292
      for (elemr = 0; elemr < DCTSIZE; elemr++) {
293
	elemptr = sample_data[elemr] + start_col;
294
#if DCTSIZE == 8		/* unroll the inner loop */
295
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
296
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
297
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
298
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
299
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
300
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
301
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
302
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
303
#else
304
	{ register int elemc;
305
	  for (elemc = DCTSIZE; elemc > 0; elemc--) {
306
	    *workspaceptr++ = (FAST_FLOAT)
307
	      (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
308
	  }
309
	}
310
#endif
311
      }
312
    }
313
525
314
    /* Perform the DCT */
526
    /* Perform the DCT */
315
    (*do_dct) (workspace);
527
    (*do_dct) (workspace);
316
528
317
    /* Quantize/descale the coefficients, and store into coef_blocks[] */
529
    /* Quantize/descale the coefficients, and store into coef_blocks[] */
318
    { register FAST_FLOAT temp;
530
    (*do_quantize) (coef_blocks[bi], divisors, workspace);
319
      register int i;
531
  }
320
      register JCOEFPTR output_ptr = coef_blocks[bi];
532
}
321
322
      for (i = 0; i < DCTSIZE2; i++) {
323
	/* Apply the quantization and scaling factor */
324
	temp = workspace[i] * divisors[i];
325
	/* Round to nearest integer.
326
	 * Since C does not specify the direction of rounding for negative
327
	 * quotients, we have to force the dividend positive for portability.
328
	 * The maximum coefficient size is +-16K (for 12-bit data), so this
329
	 * code should work for either 16-bit or 32-bit ints.
330
	 */
331
	output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
332
      }
333
    }
334
  }
335
}
336
533
337
#endif /* DCT_FLOAT_SUPPORTED */
534
#endif /* DCT_FLOAT_SUPPORTED */
338
535
339
536
340
/*
537
/*
341
 * Initialize FDCT manager.
538
 * Initialize FDCT manager.
342
 */
539
 */
343
540
 Lines 348-387   jinit_forward_dct (j_compress_ptr cinfo) Link Here 
348
  int i;
545
  int i;
349
546
350
  fdct = (my_fdct_ptr)
547
  fdct = (my_fdct_ptr)
351
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
548
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
352
				SIZEOF(my_fdct_controller));
549
				SIZEOF(my_fdct_controller));
353
  cinfo->fdct = (struct jpeg_forward_dct *) fdct;
550
  cinfo->fdct = (struct jpeg_forward_dct *) fdct;
354
  fdct->pub.start_pass = start_pass_fdctmgr;
551
  fdct->pub.start_pass = start_pass_fdctmgr;
355
552
553
  /* First determine the DCT... */
356
  switch (cinfo->dct_method) {
554
  switch (cinfo->dct_method) {
357
#ifdef DCT_ISLOW_SUPPORTED
555
#ifdef DCT_ISLOW_SUPPORTED
358
  case JDCT_ISLOW:
556
  case JDCT_ISLOW:
359
    fdct->pub.forward_DCT = forward_DCT;
557
    fdct->pub.forward_DCT = forward_DCT;
360
    fdct->do_dct = jpeg_fdct_islow;
558
    if (jsimd_can_fdct_islow())
559
      fdct->dct = jsimd_fdct_islow;
560
    else
561
      fdct->dct = jpeg_fdct_islow;
361
    break;
562
    break;
362
#endif
563
#endif
363
#ifdef DCT_IFAST_SUPPORTED
564
#ifdef DCT_IFAST_SUPPORTED
364
  case JDCT_IFAST:
565
  case JDCT_IFAST:
365
    fdct->pub.forward_DCT = forward_DCT;
566
    fdct->pub.forward_DCT = forward_DCT;
366
    fdct->do_dct = jpeg_fdct_ifast;
567
    if (jsimd_can_fdct_ifast())
568
      fdct->dct = jsimd_fdct_ifast;
569
    else
570
      fdct->dct = jpeg_fdct_ifast;
367
    break;
571
    break;
368
#endif
572
#endif
369
#ifdef DCT_FLOAT_SUPPORTED
573
#ifdef DCT_FLOAT_SUPPORTED
370
  case JDCT_FLOAT:
574
  case JDCT_FLOAT:
371
    fdct->pub.forward_DCT = forward_DCT_float;
575
    fdct->pub.forward_DCT = forward_DCT_float;
372
    fdct->do_float_dct = jpeg_fdct_float;
576
    if (jsimd_can_fdct_float())
577
      fdct->float_dct = jsimd_fdct_float;
578
    else
579
      fdct->float_dct = jpeg_fdct_float;
373
    break;
580
    break;
374
#endif
581
#endif
375
  default:
582
  default:
376
    ERREXIT(cinfo, JERR_NOT_COMPILED);
583
    ERREXIT(cinfo, JERR_NOT_COMPILED);
377
    break;
584
    break;
378
  }
585
  }
379
586
587
  /* ...then the supporting stages. */
588
  switch (cinfo->dct_method) {
589
#ifdef DCT_ISLOW_SUPPORTED
590
  case JDCT_ISLOW:
591
#endif
592
#ifdef DCT_IFAST_SUPPORTED
593
  case JDCT_IFAST:
594
#endif
595
#if defined(DCT_ISLOW_SUPPORTED) || defined(DCT_IFAST_SUPPORTED)
596
    if (jsimd_can_convsamp())
597
      fdct->convsamp = jsimd_convsamp;
598
    else
599
      fdct->convsamp = convsamp;
600
    if (jsimd_can_quantize())
601
      fdct->quantize = jsimd_quantize;
602
    else
603
      fdct->quantize = quantize;
604
    break;
605
#endif
606
#ifdef DCT_FLOAT_SUPPORTED
607
  case JDCT_FLOAT:
608
    if (jsimd_can_convsamp_float())
609
      fdct->float_convsamp = jsimd_convsamp_float;
610
    else
611
      fdct->float_convsamp = convsamp_float;
612
    if (jsimd_can_quantize_float())
613
      fdct->float_quantize = jsimd_quantize_float;
614
    else
615
      fdct->float_quantize = quantize_float;
616
    break;
617
#endif
618
  default:
619
    ERREXIT(cinfo, JERR_NOT_COMPILED);
620
    break;
621
  }
622
623
  /* Allocate workspace memory */
624
#ifdef DCT_FLOAT_SUPPORTED
625
  if (cinfo->dct_method == JDCT_FLOAT)
626
    fdct->float_workspace = (FAST_FLOAT *)
627
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
628
				  SIZEOF(FAST_FLOAT) * DCTSIZE2);
629
  else
630
#endif
631
    fdct->workspace = (DCTELEM *)
632
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
633
				  SIZEOF(DCTELEM) * DCTSIZE2);
634
380
  /* Mark divisor tables unallocated */
635
  /* Mark divisor tables unallocated */
381
  for (i = 0; i < NUM_QUANT_TBLS; i++) {
636
  for (i = 0; i < NUM_QUANT_TBLS; i++) {
382
    fdct->divisors[i] = NULL;
637
    fdct->divisors[i] = NULL;
383
#ifdef DCT_FLOAT_SUPPORTED
638
#ifdef DCT_FLOAT_SUPPORTED
384
    fdct->float_divisors[i] = NULL;
639
    fdct->float_divisors[i] = NULL;
385
#endif
640
#endif
386
  }
641
  }
387
}
642
}
(-)a/jpeg/jchuff.c (+3 lines)
Line     Link Here 
 Lines 14-29    Link Here 
14
 * permanent JPEG objects only upon successful completion of an MCU.
14
 * permanent JPEG objects only upon successful completion of an MCU.
15
 */
15
 */
16
16
17
#define JPEG_INTERNALS
17
#define JPEG_INTERNALS
18
#include "jinclude.h"
18
#include "jinclude.h"
19
#include "jpeglib.h"
19
#include "jpeglib.h"
20
#include "jchuff.h"		/* Declarations shared with jcphuff.c */
20
#include "jchuff.h"		/* Declarations shared with jcphuff.c */
21
21
22
/* MOZILLA CHANGE: libjpeg-turbo doesn't define INLINE in its config file, so
23
 * we define it here. */
24
#define INLINE
22
25
23
/* Expanded entropy encoder object for Huffman encoding.
26
/* Expanded entropy encoder object for Huffman encoding.
24
 *
27
 *
25
 * The savable_state subrecord contains fields that change within an MCU,
28
 * The savable_state subrecord contains fields that change within an MCU,
26
 * but must not be updated permanently until we complete the MCU.
29
 * but must not be updated permanently until we complete the MCU.
27
 */
30
 */
28
31
29
typedef struct {
32
typedef struct {
(-)a/jpeg/jcinit.c (+4 lines)
Line     Link Here 
 Lines 37-53   jinit_compress_master (j_compress_ptr ci Link Here 
37
    jinit_color_converter(cinfo);
37
    jinit_color_converter(cinfo);
38
    jinit_downsampler(cinfo);
38
    jinit_downsampler(cinfo);
39
    jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
39
    jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
40
  }
40
  }
41
  /* Forward DCT */
41
  /* Forward DCT */
42
  jinit_forward_dct(cinfo);
42
  jinit_forward_dct(cinfo);
43
  /* Entropy encoding: either Huffman or arithmetic coding. */
43
  /* Entropy encoding: either Huffman or arithmetic coding. */
44
  if (cinfo->arith_code) {
44
  if (cinfo->arith_code) {
45
#ifdef C_ARITH_CODING_SUPPORTED
46
    jinit_arith_encoder(cinfo);
47
#else
45
    ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
48
    ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
49
#endif
46
  } else {
50
  } else {
47
    if (cinfo->progressive_mode) {
51
    if (cinfo->progressive_mode) {
48
#ifdef C_PROGRESSIVE_SUPPORTED
52
#ifdef C_PROGRESSIVE_SUPPORTED
49
      jinit_phuff_encoder(cinfo);
53
      jinit_phuff_encoder(cinfo);
50
#else
54
#else
51
      ERREXIT(cinfo, JERR_NOT_COMPILED);
55
      ERREXIT(cinfo, JERR_NOT_COMPILED);
52
#endif
56
#endif
53
    } else
57
    } else
(-)a/jpeg/jcmarker.c (-35 / +39 lines)
Line     Link Here 
 Lines 1-21    Link Here 
1
/*
1
/*
2
 * jcmarker.c
2
 * jcmarker.c
3
 *
3
 *
4
 * Copyright (C) 1991-1998, Thomas G. Lane.
4
 * Copyright (C) 1991-1998, Thomas G. Lane.
5
 * Copyright (C) 2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains routines to write JPEG datastream markers.
9
 * This file contains routines to write JPEG datastream markers.
9
 */
10
 */
10
11
11
#define JPEG_INTERNALS
12
#define JPEG_INTERNALS
12
#include "jinclude.h"
13
#include "jinclude.h"
13
#include "jpeglib.h"
14
#include "jpeglib.h"
15
#include "jpegcomp.h"
14
16
15
17
16
typedef enum {			/* JPEG marker codes */
18
typedef enum {			/* JPEG marker codes */
17
  M_SOF0  = 0xc0,
19
  M_SOF0  = 0xc0,
18
  M_SOF1  = 0xc1,
20
  M_SOF1  = 0xc1,
19
  M_SOF2  = 0xc2,
21
  M_SOF2  = 0xc2,
20
  M_SOF3  = 0xc3,
22
  M_SOF3  = 0xc3,
21
  
23
  
 Lines 70-86   typedef enum { /* JPEG marker codes */ Link Here 
70
  M_APP13 = 0xed,
72
  M_APP13 = 0xed,
71
  M_APP14 = 0xee,
73
  M_APP14 = 0xee,
72
  M_APP15 = 0xef,
74
  M_APP15 = 0xef,
73
  
75
  
74
  M_JPG0  = 0xf0,
76
  M_JPG0  = 0xf0,
75
  M_JPG13 = 0xfd,
77
  M_JPG13 = 0xfd,
76
  M_COM   = 0xfe,
78
  M_COM   = 0xfe,
77
  
79
  
78
  M_TEM   = 0x01
80
  M_TEM   = 0x01,
81
  
82
  M_ERROR = 0x100
79
} JPEG_MARKER;
83
} JPEG_MARKER;
80
84
81
85
82
/* Private state */
86
/* Private state */
83
87
84
typedef struct {
88
typedef struct {
85
  struct jpeg_marker_writer pub; /* public fields */
89
  struct jpeg_marker_writer pub; /* public fields */
86
90
 Lines 98-114   typedef my_marker_writer * my_marker_ptr Link Here 
98
 * enough buffer space for the initial markers (typ. 600-700 bytes) before
102
 * enough buffer space for the initial markers (typ. 600-700 bytes) before
99
 * calling jpeg_start_compress, and enough space to write the trailing EOI
103
 * calling jpeg_start_compress, and enough space to write the trailing EOI
100
 * (a few bytes) before calling jpeg_finish_compress.  Multipass compression
104
 * (a few bytes) before calling jpeg_finish_compress.  Multipass compression
101
 * modes are not supported at all with suspension, so those two are the only
105
 * modes are not supported at all with suspension, so those two are the only
102
 * points where markers will be written.
106
 * points where markers will be written.
103
 */
107
 */
104
108
105
LOCAL(void)
109
LOCAL(void)
106
emit_byte (j_compress_ptr cinfo, int16 val)
110
emit_byte (j_compress_ptr cinfo, int val)
107
/* Emit a byte */
111
/* Emit a byte */
108
{
112
{
109
  struct jpeg_destination_mgr * dest = cinfo->dest;
113
  struct jpeg_destination_mgr * dest = cinfo->dest;
110
114
111
  *(dest->next_output_byte)++ = (JOCTET) val;
115
  *(dest->next_output_byte)++ = (JOCTET) val;
112
  if (--dest->free_in_buffer == 0) {
116
  if (--dest->free_in_buffer == 0) {
113
    if (! (*dest->empty_output_buffer) (cinfo))
117
    if (! (*dest->empty_output_buffer) (cinfo))
114
      ERREXIT(cinfo, JERR_CANT_SUSPEND);
118
      ERREXIT(cinfo, JERR_CANT_SUSPEND);
 Lines 116-156   emit_byte (j_compress_ptr cinfo, int16 v Link Here 
116
}
120
}
117
121
118
122
119
LOCAL(void)
123
LOCAL(void)
120
emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
124
emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
121
/* Emit a marker code */
125
/* Emit a marker code */
122
{
126
{
123
  emit_byte(cinfo, 0xFF);
127
  emit_byte(cinfo, 0xFF);
124
  emit_byte(cinfo, (int16) mark);
128
  emit_byte(cinfo, (int) mark);
125
}
129
}
126
130
127
131
128
LOCAL(void)
132
LOCAL(void)
129
emit_2bytes (j_compress_ptr cinfo, int16 value)
133
emit_2bytes (j_compress_ptr cinfo, int value)
130
/* Emit a 2-byte integer; these are always MSB first in JPEG files */
134
/* Emit a 2-byte integer; these are always MSB first in JPEG files */
131
{
135
{
132
  emit_byte(cinfo, (value >> 8) & 0xFF);
136
  emit_byte(cinfo, (value >> 8) & 0xFF);
133
  emit_byte(cinfo, value & 0xFF);
137
  emit_byte(cinfo, value & 0xFF);
134
}
138
}
135
139
136
140
137
/*
141
/*
138
 * Routines to write specific marker types.
142
 * Routines to write specific marker types.
139
 */
143
 */
140
144
141
LOCAL(int16)
145
LOCAL(int)
142
emit_dqt (j_compress_ptr cinfo, int16 index)
146
emit_dqt (j_compress_ptr cinfo, int index)
143
/* Emit a DQT marker */
147
/* Emit a DQT marker */
144
/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
148
/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
145
{
149
{
146
  JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
150
  JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
147
  int16 prec;
151
  int prec;
148
  int16 i;
152
  int i;
149
153
150
  if (qtbl == NULL)
154
  if (qtbl == NULL)
151
    ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
155
    ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
152
156
153
  prec = 0;
157
  prec = 0;
154
  for (i = 0; i < DCTSIZE2; i++) {
158
  for (i = 0; i < DCTSIZE2; i++) {
155
    if (qtbl->quantval[i] > 255)
159
    if (qtbl->quantval[i] > 255)
156
      prec = 1;
160
      prec = 1;
 Lines 162-194   emit_dqt (j_compress_ptr cinfo, int16 in Link Here 
162
    emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
166
    emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
163
167
164
    emit_byte(cinfo, index + (prec<<4));
168
    emit_byte(cinfo, index + (prec<<4));
165
169
166
    for (i = 0; i < DCTSIZE2; i++) {
170
    for (i = 0; i < DCTSIZE2; i++) {
167
      /* The table entries must be emitted in zigzag order. */
171
      /* The table entries must be emitted in zigzag order. */
168
      unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
172
      unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
169
      if (prec)
173
      if (prec)
170
	emit_byte(cinfo, (int16) (qval >> 8));
174
	emit_byte(cinfo, (int) (qval >> 8));
171
      emit_byte(cinfo, (int16) (qval & 0xFF));
175
      emit_byte(cinfo, (int) (qval & 0xFF));
172
    }
176
    }
173
177
174
    qtbl->sent_table = TRUE;
178
    qtbl->sent_table = TRUE;
175
  }
179
  }
176
180
177
  return prec;
181
  return prec;
178
}
182
}
179
183
180
184
181
LOCAL(void)
185
LOCAL(void)
182
emit_dht (j_compress_ptr cinfo, int16 index, boolean is_ac)
186
emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
183
/* Emit a DHT marker */
187
/* Emit a DHT marker */
184
{
188
{
185
  JHUFF_TBL * htbl;
189
  JHUFF_TBL * htbl;
186
  int16 length, i;
190
  int length, i;
187
  
191
  
188
  if (is_ac) {
192
  if (is_ac) {
189
    htbl = cinfo->ac_huff_tbl_ptrs[index];
193
    htbl = cinfo->ac_huff_tbl_ptrs[index];
190
    index += 0x10;		/* output index has AC bit set */
194
    index += 0x10;		/* output index has AC bit set */
191
  } else {
195
  } else {
192
    htbl = cinfo->dc_huff_tbl_ptrs[index];
196
    htbl = cinfo->dc_huff_tbl_ptrs[index];
193
  }
197
  }
194
198
 Lines 220-236   LOCAL(void) Link Here 
220
emit_dac (j_compress_ptr cinfo)
224
emit_dac (j_compress_ptr cinfo)
221
/* Emit a DAC marker */
225
/* Emit a DAC marker */
222
/* Since the useful info is so small, we want to emit all the tables in */
226
/* Since the useful info is so small, we want to emit all the tables in */
223
/* one DAC marker.  Therefore this routine does its own scan of the table. */
227
/* one DAC marker.  Therefore this routine does its own scan of the table. */
224
{
228
{
225
#ifdef C_ARITH_CODING_SUPPORTED
229
#ifdef C_ARITH_CODING_SUPPORTED
226
  char dc_in_use[NUM_ARITH_TBLS];
230
  char dc_in_use[NUM_ARITH_TBLS];
227
  char ac_in_use[NUM_ARITH_TBLS];
231
  char ac_in_use[NUM_ARITH_TBLS];
228
  int16 length, i;
232
  int length, i;
229
  jpeg_component_info *compptr;
233
  jpeg_component_info *compptr;
230
  
234
  
231
  for (i = 0; i < NUM_ARITH_TBLS; i++)
235
  for (i = 0; i < NUM_ARITH_TBLS; i++)
232
    dc_in_use[i] = ac_in_use[i] = 0;
236
    dc_in_use[i] = ac_in_use[i] = 0;
233
  
237
  
234
  for (i = 0; i < cinfo->comps_in_scan; i++) {
238
  for (i = 0; i < cinfo->comps_in_scan; i++) {
235
    compptr = cinfo->cur_comp_info[i];
239
    compptr = cinfo->cur_comp_info[i];
236
    dc_in_use[compptr->dc_tbl_no] = 1;
240
    dc_in_use[compptr->dc_tbl_no] = 1;
 Lines 262-317   emit_dac (j_compress_ptr cinfo) Link Here 
262
LOCAL(void)
266
LOCAL(void)
263
emit_dri (j_compress_ptr cinfo)
267
emit_dri (j_compress_ptr cinfo)
264
/* Emit a DRI marker */
268
/* Emit a DRI marker */
265
{
269
{
266
  emit_marker(cinfo, M_DRI);
270
  emit_marker(cinfo, M_DRI);
267
  
271
  
268
  emit_2bytes(cinfo, 4);	/* fixed length */
272
  emit_2bytes(cinfo, 4);	/* fixed length */
269
273
270
  emit_2bytes(cinfo, (int16) cinfo->restart_interval);
274
  emit_2bytes(cinfo, (int) cinfo->restart_interval);
271
}
275
}
272
276
273
277
274
LOCAL(void)
278
LOCAL(void)
275
emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
279
emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
276
/* Emit a SOF marker */
280
/* Emit a SOF marker */
277
{
281
{
278
  int16 ci;
282
  int ci;
279
  jpeg_component_info *compptr;
283
  jpeg_component_info *compptr;
280
  
284
  
281
  emit_marker(cinfo, code);
285
  emit_marker(cinfo, code);
282
  
286
  
283
  emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
287
  emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
284
288
285
  /* Make sure image isn't bigger than SOF field can handle */
289
  /* Make sure image isn't bigger than SOF field can handle */
286
  if ((long) cinfo->image_height > 65535L ||
290
  if ((long) cinfo->_jpeg_height > 65535L ||
287
      (long) cinfo->image_width > 65535L)
291
      (long) cinfo->_jpeg_width > 65535L)
288
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
292
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
289
293
290
  emit_byte(cinfo, cinfo->data_precision);
294
  emit_byte(cinfo, cinfo->data_precision);
291
  emit_2bytes(cinfo, (int16) cinfo->image_height);
295
  emit_2bytes(cinfo, (int) cinfo->_jpeg_height);
292
  emit_2bytes(cinfo, (int16) cinfo->image_width);
296
  emit_2bytes(cinfo, (int) cinfo->_jpeg_width);
293
297
294
  emit_byte(cinfo, cinfo->num_components);
298
  emit_byte(cinfo, cinfo->num_components);
295
299
296
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
300
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
297
       ci++, compptr++) {
301
       ci++, compptr++) {
298
    emit_byte(cinfo, compptr->component_id);
302
    emit_byte(cinfo, compptr->component_id);
299
    emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
303
    emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
300
    emit_byte(cinfo, compptr->quant_tbl_no);
304
    emit_byte(cinfo, compptr->quant_tbl_no);
301
  }
305
  }
302
}
306
}
303
307
304
308
305
LOCAL(void)
309
LOCAL(void)
306
emit_sos (j_compress_ptr cinfo)
310
emit_sos (j_compress_ptr cinfo)
307
/* Emit a SOS marker */
311
/* Emit a SOS marker */
308
{
312
{
309
  int16 i, td, ta;
313
  int i, td, ta;
310
  jpeg_component_info *compptr;
314
  jpeg_component_info *compptr;
311
  
315
  
312
  emit_marker(cinfo, M_SOS);
316
  emit_marker(cinfo, M_SOS);
313
  
317
  
314
  emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
318
  emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
315
  
319
  
316
  emit_byte(cinfo, cinfo->comps_in_scan);
320
  emit_byte(cinfo, cinfo->comps_in_scan);
317
  
321
  
 Lines 366-383   emit_jfif_app0 (j_compress_ptr cinfo) Link Here 
366
  emit_byte(cinfo, 0x4A);	/* Identifier: ASCII "JFIF" */
370
  emit_byte(cinfo, 0x4A);	/* Identifier: ASCII "JFIF" */
367
  emit_byte(cinfo, 0x46);
371
  emit_byte(cinfo, 0x46);
368
  emit_byte(cinfo, 0x49);
372
  emit_byte(cinfo, 0x49);
369
  emit_byte(cinfo, 0x46);
373
  emit_byte(cinfo, 0x46);
370
  emit_byte(cinfo, 0);
374
  emit_byte(cinfo, 0);
371
  emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
375
  emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
372
  emit_byte(cinfo, cinfo->JFIF_minor_version);
376
  emit_byte(cinfo, cinfo->JFIF_minor_version);
373
  emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
377
  emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
374
  emit_2bytes(cinfo, (int16) cinfo->X_density);
378
  emit_2bytes(cinfo, (int) cinfo->X_density);
375
  emit_2bytes(cinfo, (int16) cinfo->Y_density);
379
  emit_2bytes(cinfo, (int) cinfo->Y_density);
376
  emit_byte(cinfo, 0);		/* No thumbnail image */
380
  emit_byte(cinfo, 0);		/* No thumbnail image */
377
  emit_byte(cinfo, 0);
381
  emit_byte(cinfo, 0);
378
}
382
}
379
383
380
384
381
LOCAL(void)
385
LOCAL(void)
382
emit_adobe_app14 (j_compress_ptr cinfo)
386
emit_adobe_app14 (j_compress_ptr cinfo)
383
/* Emit an Adobe APP14 marker */
387
/* Emit an Adobe APP14 marker */
 Lines 436-460   METHODDEF(void) Link Here 
436
write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
440
write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
437
/* Emit an arbitrary marker header */
441
/* Emit an arbitrary marker header */
438
{
442
{
439
  if (datalen > (unsigned int) 65533)		/* safety check */
443
  if (datalen > (unsigned int) 65533)		/* safety check */
440
    ERREXIT(cinfo, JERR_BAD_LENGTH);
444
    ERREXIT(cinfo, JERR_BAD_LENGTH);
441
445
442
  emit_marker(cinfo, (JPEG_MARKER) marker);
446
  emit_marker(cinfo, (JPEG_MARKER) marker);
443
447
444
  emit_2bytes(cinfo, (int16) (datalen + 2));	/* total length */
448
  emit_2bytes(cinfo, (int) (datalen + 2));	/* total length */
445
}
449
}
446
450
447
METHODDEF(void)
451
METHODDEF(void)
448
write_marker_byte (j_compress_ptr cinfo, int val)
452
write_marker_byte (j_compress_ptr cinfo, int val)
449
/* Emit one byte of marker parameters following write_marker_header */
453
/* Emit one byte of marker parameters following write_marker_header */
450
{
454
{
451
  emit_byte(cinfo, (int16) val);
455
  emit_byte(cinfo, val);
452
}
456
}
453
457
454
458
455
/*
459
/*
456
 * Write datastream header.
460
 * Write datastream header.
457
 * This consists of an SOI and optional APPn markers.
461
 * This consists of an SOI and optional APPn markers.
458
 * We recommend use of the JFIF marker, but not the Adobe marker,
462
 * We recommend use of the JFIF marker, but not the Adobe marker,
459
 * when using YCbCr or grayscale data.  The JFIF marker should NOT
463
 * when using YCbCr or grayscale data.  The JFIF marker should NOT
460
 * be used for any other JPEG colorspace.  The Adobe marker is helpful
464
 * be used for any other JPEG colorspace.  The Adobe marker is helpful
 Lines 486-502   write_file_header (j_compress_ptr cinfo) Link Here 
486
 * Note that we do not emit the SOF until we have emitted the DQT(s).
490
 * Note that we do not emit the SOF until we have emitted the DQT(s).
487
 * This avoids compatibility problems with incorrect implementations that
491
 * This avoids compatibility problems with incorrect implementations that
488
 * try to error-check the quant table numbers as soon as they see the SOF.
492
 * try to error-check the quant table numbers as soon as they see the SOF.
489
 */
493
 */
490
494
491
METHODDEF(void)
495
METHODDEF(void)
492
write_frame_header (j_compress_ptr cinfo)
496
write_frame_header (j_compress_ptr cinfo)
493
{
497
{
494
  int16 ci, prec;
498
  int ci, prec;
495
  boolean is_baseline;
499
  boolean is_baseline;
496
  jpeg_component_info *compptr;
500
  jpeg_component_info *compptr;
497
  
501
  
498
  /* Emit DQT for each quantization table.
502
  /* Emit DQT for each quantization table.
499
   * Note that emit_dqt() suppresses any duplicate tables.
503
   * Note that emit_dqt() suppresses any duplicate tables.
500
   */
504
   */
501
  prec = 0;
505
  prec = 0;
502
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
506
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
 Lines 544-560   write_frame_header (j_compress_ptr cinfo Link Here 
544
 * This consists of DHT or DAC markers, optional DRI, and SOS.
548
 * This consists of DHT or DAC markers, optional DRI, and SOS.
545
 * Compressed data will be written following the SOS.
549
 * Compressed data will be written following the SOS.
546
 */
550
 */
547
551
548
METHODDEF(void)
552
METHODDEF(void)
549
write_scan_header (j_compress_ptr cinfo)
553
write_scan_header (j_compress_ptr cinfo)
550
{
554
{
551
  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
555
  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
552
  int16 i;
556
  int i;
553
  jpeg_component_info *compptr;
557
  jpeg_component_info *compptr;
554
558
555
  if (cinfo->arith_code) {
559
  if (cinfo->arith_code) {
556
    /* Emit arith conditioning info.  We may have some duplication
560
    /* Emit arith conditioning info.  We may have some duplication
557
     * if the file has multiple scans, but it's so small it's hardly
561
     * if the file has multiple scans, but it's so small it's hardly
558
     * worth worrying about.
562
     * worth worrying about.
559
     */
563
     */
560
    emit_dac(cinfo);
564
    emit_dac(cinfo);
 Lines 608-624   write_file_trailer (j_compress_ptr cinfo Link Here 
608
 * This consists of SOI, DQT and DHT tables, and EOI.
612
 * This consists of SOI, DQT and DHT tables, and EOI.
609
 * Any table that is defined and not marked sent_table = TRUE will be
613
 * Any table that is defined and not marked sent_table = TRUE will be
610
 * emitted.  Note that all tables will be marked sent_table = TRUE at exit.
614
 * emitted.  Note that all tables will be marked sent_table = TRUE at exit.
611
 */
615
 */
612
616
613
METHODDEF(void)
617
METHODDEF(void)
614
write_tables_only (j_compress_ptr cinfo)
618
write_tables_only (j_compress_ptr cinfo)
615
{
619
{
616
  int16 i;
620
  int i;
617
621
618
  emit_marker(cinfo, M_SOI);
622
  emit_marker(cinfo, M_SOI);
619
623
620
  for (i = 0; i < NUM_QUANT_TBLS; i++) {
624
  for (i = 0; i < NUM_QUANT_TBLS; i++) {
621
    if (cinfo->quant_tbl_ptrs[i] != NULL)
625
    if (cinfo->quant_tbl_ptrs[i] != NULL)
622
      (void) emit_dqt(cinfo, i);
626
      (void) emit_dqt(cinfo, i);
623
  }
627
  }
624
628
(-)a/jpeg/jcmaster.c (-12 / +44 lines)
Line     Link Here 
 Lines 1-24    Link Here 
1
/*
1
/*
2
 * jcmaster.c
2
 * jcmaster.c
3
 *
3
 *
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
5
 * Modified 2003-2010 by Guido Vollbeding.
6
 * Copyright (C) 2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
7
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
8
 * For conditions of distribution and use, see the accompanying README file.
7
 *
9
 *
8
 * This file contains master control logic for the JPEG compressor.
10
 * This file contains master control logic for the JPEG compressor.
9
 * These routines are concerned with parameter validation, initial setup,
11
 * These routines are concerned with parameter validation, initial setup,
10
 * and inter-pass control (determining the number of passes and the work 
12
 * and inter-pass control (determining the number of passes and the work 
11
 * to be done in each pass).
13
 * to be done in each pass).
12
 */
14
 */
13
15
14
#define JPEG_INTERNALS
16
#define JPEG_INTERNALS
15
#include "jinclude.h"
17
#include "jinclude.h"
16
#include "jpeglib.h"
18
#include "jpeglib.h"
19
#include "jpegcomp.h"
17
20
18
21
19
/* Private state */
22
/* Private state */
20
23
21
typedef enum {
24
typedef enum {
22
	main_pass,		/* input data, also do first output step */
25
	main_pass,		/* input data, also do first output step */
23
	huff_opt_pass,		/* Huffman code optimization pass */
26
	huff_opt_pass,		/* Huffman code optimization pass */
24
	output_pass		/* data output pass */
27
	output_pass		/* data output pass */
 Lines 37-69   typedef struct { Link Here 
37
40
38
typedef my_comp_master * my_master_ptr;
41
typedef my_comp_master * my_master_ptr;
39
42
40
43
41
/*
44
/*
42
 * Support routines that do various essential calculations.
45
 * Support routines that do various essential calculations.
43
 */
46
 */
44
47
48
#if JPEG_LIB_VERSION >= 70
49
/*
50
 * Compute JPEG image dimensions and related values.
51
 * NOTE: this is exported for possible use by application.
52
 * Hence it mustn't do anything that can't be done twice.
53
 */
54
55
GLOBAL(void)
56
jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)
57
/* Do computations that are needed before master selection phase */
58
{
59
  /* Hardwire it to "no scaling" */
60
  cinfo->jpeg_width = cinfo->image_width;
61
  cinfo->jpeg_height = cinfo->image_height;
62
  cinfo->min_DCT_h_scaled_size = DCTSIZE;
63
  cinfo->min_DCT_v_scaled_size = DCTSIZE;
64
}
65
#endif
66
67
45
LOCAL(void)
68
LOCAL(void)
46
initial_setup (j_compress_ptr cinfo)
69
initial_setup (j_compress_ptr cinfo, boolean transcode_only)
47
/* Do computations that are needed before master selection phase */
70
/* Do computations that are needed before master selection phase */
48
{
71
{
49
  int ci;
72
  int ci;
50
  jpeg_component_info *compptr;
73
  jpeg_component_info *compptr;
51
  long samplesperrow;
74
  long samplesperrow;
52
  JDIMENSION jd_samplesperrow;
75
  JDIMENSION jd_samplesperrow;
53
76
77
#if JPEG_LIB_VERSION >= 70
78
  if (!transcode_only)
79
    jpeg_calc_jpeg_dimensions(cinfo);
80
#endif
81
54
  /* Sanity check on image dimensions */
82
  /* Sanity check on image dimensions */
55
  if (cinfo->image_height <= 0 || cinfo->image_width <= 0
83
  if (cinfo->_jpeg_height <= 0 || cinfo->_jpeg_width <= 0
56
      || cinfo->num_components <= 0 || cinfo->input_components <= 0)
84
      || cinfo->num_components <= 0 || cinfo->input_components <= 0)
57
    ERREXIT(cinfo, JERR_EMPTY_IMAGE);
85
    ERREXIT(cinfo, JERR_EMPTY_IMAGE);
58
86
59
  /* Make sure image isn't bigger than I can handle */
87
  /* Make sure image isn't bigger than I can handle */
60
  if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
88
  if ((long) cinfo->_jpeg_height > (long) JPEG_MAX_DIMENSION ||
61
      (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
89
      (long) cinfo->_jpeg_width > (long) JPEG_MAX_DIMENSION)
62
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
90
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
63
91
64
  /* Width of an input scanline must be representable as JDIMENSION. */
92
  /* Width of an input scanline must be representable as JDIMENSION. */
65
  samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
93
  samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
66
  jd_samplesperrow = (JDIMENSION) samplesperrow;
94
  jd_samplesperrow = (JDIMENSION) samplesperrow;
67
  if ((long) jd_samplesperrow != samplesperrow)
95
  if ((long) jd_samplesperrow != samplesperrow)
68
    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
96
    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
69
97
 Lines 91-130   initial_setup (j_compress_ptr cinfo) Link Here 
91
  }
119
  }
92
120
93
  /* Compute dimensions of components */
121
  /* Compute dimensions of components */
94
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
122
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
95
       ci++, compptr++) {
123
       ci++, compptr++) {
96
    /* Fill in the correct component_index value; don't rely on application */
124
    /* Fill in the correct component_index value; don't rely on application */
97
    compptr->component_index = ci;
125
    compptr->component_index = ci;
98
    /* For compression, we never do DCT scaling. */
126
    /* For compression, we never do DCT scaling. */
127
#if JPEG_LIB_VERSION >= 70
128
    compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE;
129
#else
99
    compptr->DCT_scaled_size = DCTSIZE;
130
    compptr->DCT_scaled_size = DCTSIZE;
131
#endif
100
    /* Size in DCT blocks */
132
    /* Size in DCT blocks */
101
    compptr->width_in_blocks = (JDIMENSION)
133
    compptr->width_in_blocks = (JDIMENSION)
102
      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
134
      jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor,
103
		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
135
		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
104
    compptr->height_in_blocks = (JDIMENSION)
136
    compptr->height_in_blocks = (JDIMENSION)
105
      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
137
      jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor,
106
		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
138
		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
107
    /* Size in samples */
139
    /* Size in samples */
108
    compptr->downsampled_width = (JDIMENSION)
140
    compptr->downsampled_width = (JDIMENSION)
109
      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
141
      jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor,
110
		    (long) cinfo->max_h_samp_factor);
142
		    (long) cinfo->max_h_samp_factor);
111
    compptr->downsampled_height = (JDIMENSION)
143
    compptr->downsampled_height = (JDIMENSION)
112
      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
144
      jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor,
113
		    (long) cinfo->max_v_samp_factor);
145
		    (long) cinfo->max_v_samp_factor);
114
    /* Mark component needed (this flag isn't actually used for compression) */
146
    /* Mark component needed (this flag isn't actually used for compression) */
115
    compptr->component_needed = TRUE;
147
    compptr->component_needed = TRUE;
116
  }
148
  }
117
149
118
  /* Compute number of fully interleaved MCU rows (number of times that
150
  /* Compute number of fully interleaved MCU rows (number of times that
119
   * main controller will call coefficient controller).
151
   * main controller will call coefficient controller).
120
   */
152
   */
121
  cinfo->total_iMCU_rows = (JDIMENSION)
153
  cinfo->total_iMCU_rows = (JDIMENSION)
122
    jdiv_round_up((long) cinfo->image_height,
154
    jdiv_round_up((long) cinfo->_jpeg_height,
123
		  (long) (cinfo->max_v_samp_factor*DCTSIZE));
155
		  (long) (cinfo->max_v_samp_factor*DCTSIZE));
124
}
156
}
125
157
126
158
127
#ifdef C_MULTISCAN_FILES_SUPPORTED
159
#ifdef C_MULTISCAN_FILES_SUPPORTED
128
160
129
LOCAL(void)
161
LOCAL(void)
130
validate_script (j_compress_ptr cinfo)
162
validate_script (j_compress_ptr cinfo)
 Lines 342-361   per_scan_setup (j_compress_ptr cinfo) Link Here 
342
    
374
    
343
    /* Interleaved (multi-component) scan */
375
    /* Interleaved (multi-component) scan */
344
    if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
376
    if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
345
      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
377
      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
346
	       MAX_COMPS_IN_SCAN);
378
	       MAX_COMPS_IN_SCAN);
347
    
379
    
348
    /* Overall image size in MCUs */
380
    /* Overall image size in MCUs */
349
    cinfo->MCUs_per_row = (JDIMENSION)
381
    cinfo->MCUs_per_row = (JDIMENSION)
350
      jdiv_round_up((long) cinfo->image_width,
382
      jdiv_round_up((long) cinfo->_jpeg_width,
351
		    (long) (cinfo->max_h_samp_factor*DCTSIZE));
383
		    (long) (cinfo->max_h_samp_factor*DCTSIZE));
352
    cinfo->MCU_rows_in_scan = (JDIMENSION)
384
    cinfo->MCU_rows_in_scan = (JDIMENSION)
353
      jdiv_round_up((long) cinfo->image_height,
385
      jdiv_round_up((long) cinfo->_jpeg_height,
354
		    (long) (cinfo->max_v_samp_factor*DCTSIZE));
386
		    (long) (cinfo->max_v_samp_factor*DCTSIZE));
355
    
387
    
356
    cinfo->blocks_in_MCU = 0;
388
    cinfo->blocks_in_MCU = 0;
357
    
389
    
358
    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
390
    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
359
      compptr = cinfo->cur_comp_info[ci];
391
      compptr = cinfo->cur_comp_info[ci];
360
      /* Sampling factors give # of blocks of component in each MCU */
392
      /* Sampling factors give # of blocks of component in each MCU */
361
      compptr->MCU_width = compptr->h_samp_factor;
393
      compptr->MCU_width = compptr->h_samp_factor;
 Lines 549-565   jinit_c_master_control (j_compress_ptr c Link Here 
549
				  SIZEOF(my_comp_master));
581
				  SIZEOF(my_comp_master));
550
  cinfo->master = (struct jpeg_comp_master *) master;
582
  cinfo->master = (struct jpeg_comp_master *) master;
551
  master->pub.prepare_for_pass = prepare_for_pass;
583
  master->pub.prepare_for_pass = prepare_for_pass;
552
  master->pub.pass_startup = pass_startup;
584
  master->pub.pass_startup = pass_startup;
553
  master->pub.finish_pass = finish_pass_master;
585
  master->pub.finish_pass = finish_pass_master;
554
  master->pub.is_last_pass = FALSE;
586
  master->pub.is_last_pass = FALSE;
555
587
556
  /* Validate parameters, determine derived values */
588
  /* Validate parameters, determine derived values */
557
  initial_setup(cinfo);
589
  initial_setup(cinfo, transcode_only);
558
590
559
  if (cinfo->scan_info != NULL) {
591
  if (cinfo->scan_info != NULL) {
560
#ifdef C_MULTISCAN_FILES_SUPPORTED
592
#ifdef C_MULTISCAN_FILES_SUPPORTED
561
    validate_script(cinfo);
593
    validate_script(cinfo);
562
#else
594
#else
563
    ERREXIT(cinfo, JERR_NOT_COMPILED);
595
    ERREXIT(cinfo, JERR_NOT_COMPILED);
564
#endif
596
#endif
565
  } else {
597
  } else {
(-)a/jpeg/jconfig-mac-cw.h (-43 lines)
Line     Link Here 
 Lines 1-43    Link Here 
1
/* jconfig.h --- generated by ckconfig.c */
2
/* see jconfig.doc for explanations */
3
4
#define ALIGN_TYPE long /* memory alignment */
5
#define NO_GETENV /* we do have the function, but it's dead */
6
#ifdef __cplusplus
7
#define INLINE inline /* we have them in C++ */
8
#endif
9
10
#define HAVE_PROTOTYPES
11
#define HAVE_UNSIGNED_CHAR
12
#define HAVE_UNSIGNED_SHORT
13
/* #define void char */
14
/* #define const */
15
#undef CHAR_IS_UNSIGNED
16
#define HAVE_STDDEF_H
17
#define HAVE_STDLIB_H
18
#undef NEED_BSD_STRINGS
19
#undef NEED_SYS_TYPES_H
20
#undef NEED_FAR_POINTERS
21
#undef NEED_SHORT_EXTERNAL_NAMES
22
#undef INCOMPLETE_TYPES_BROKEN
23
24
#ifdef JPEG_INTERNALS
25
26
#undef RIGHT_SHIFT_IS_UNSIGNED
27
28
#endif /* JPEG_INTERNALS */
29
30
#ifdef JPEG_CJPEG_DJPEG
31
32
#define BMP_SUPPORTED		/* BMP image file format */
33
#define GIF_SUPPORTED		/* GIF image file format */
34
#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
35
#undef RLE_SUPPORTED		/* Utah RLE image file format */
36
#define TARGA_SUPPORTED		/* Targa image file format */
37
38
#undef TWO_FILE_COMMANDLINE	/* You may need this on non-Unix systems */
39
#undef NEED_SIGNAL_CATCHER	/* Define this if you use jmemname.c */
40
#undef DONT_USE_B_MODE
41
/* #define PROGRESS_REPORT */	/* optional */
42
43
#endif /* JPEG_CJPEG_DJPEG */
(-)a/jpeg/jconfig.doc (-155 lines)
Line     Link Here 
 Lines 1-155    Link Here 
1
/*
2
 * jconfig.doc
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 documents the configuration options that are required to
9
 * customize the JPEG software for a particular system.
10
 *
11
 * The actual configuration options for a particular installation are stored
12
 * in jconfig.h.  On many machines, jconfig.h can be generated automatically
13
 * or copied from one of the "canned" jconfig files that we supply.  But if
14
 * you need to generate a jconfig.h file by hand, this file tells you how.
15
 *
16
 * DO NOT EDIT THIS FILE --- IT WON'T ACCOMPLISH ANYTHING.
17
 * EDIT A COPY NAMED JCONFIG.H.
18
 */
19
20
21
/*
22
 * These symbols indicate the properties of your machine or compiler.
23
 * #define the symbol if yes, #undef it if no.
24
 */
25
26
/* Does your compiler support function prototypes?
27
 * (If not, you also need to use ansi2knr, see install.doc)
28
 */
29
#define HAVE_PROTOTYPES
30
31
/* Does your compiler support the declaration "unsigned char" ?
32
 * How about "unsigned short" ?
33
 */
34
#define HAVE_UNSIGNED_CHAR
35
#define HAVE_UNSIGNED_SHORT
36
37
/* Define "void" as "char" if your compiler doesn't know about type void.
38
 * NOTE: be sure to define void such that "void *" represents the most general
39
 * pointer type, e.g., that returned by malloc().
40
 */
41
/* #define void char */
42
43
/* Define "const" as empty if your compiler doesn't know the "const" keyword.
44
 */
45
/* #define const */
46
47
/* Define this if an ordinary "char" type is unsigned.
48
 * If you're not sure, leaving it undefined will work at some cost in speed.
49
 * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal.
50
 */
51
#undef CHAR_IS_UNSIGNED
52
53
/* Define this if your system has an ANSI-conforming <stddef.h> file.
54
 */
55
#define HAVE_STDDEF_H
56
57
/* Define this if your system has an ANSI-conforming <stdlib.h> file.
58
 */
59
#define HAVE_STDLIB_H
60
61
/* Define this if your system does not have an ANSI/SysV <string.h>,
62
 * but does have a BSD-style <strings.h>.
63
 */
64
#undef NEED_BSD_STRINGS
65
66
/* Define this if your system does not provide typedef size_t in any of the
67
 * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in
68
 * <sys/types.h> instead.
69
 */
70
#undef NEED_SYS_TYPES_H
71
72
/* For 80x86 machines, you need to define NEED_FAR_POINTERS,
73
 * unless you are using a large-data memory model or 80386 flat-memory mode.
74
 * On less brain-damaged CPUs this symbol must not be defined.
75
 * (Defining this symbol causes large data structures to be referenced through
76
 * "far" pointers and to be allocated with a special version of malloc.)
77
 */
78
#undef NEED_FAR_POINTERS
79
80
/* Define this if your linker needs global names to be unique in less
81
 * than the first 15 characters.
82
 */
83
#undef NEED_SHORT_EXTERNAL_NAMES
84
85
/* Although a real ANSI C compiler can deal perfectly well with pointers to
86
 * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
87
 * and pseudo-ANSI compilers get confused.  To keep one of these bozos happy,
88
 * define INCOMPLETE_TYPES_BROKEN.  This is not recommended unless you
89
 * actually get "missing structure definition" warnings or errors while
90
 * compiling the JPEG code.
91
 */
92
#undef INCOMPLETE_TYPES_BROKEN
93
94
95
/*
96
 * The following options affect code selection within the JPEG library,
97
 * but they don't need to be visible to applications using the library.
98
 * To minimize application namespace pollution, the symbols won't be
99
 * defined unless JPEG_INTERNALS has been defined.
100
 */
101
102
#ifdef JPEG_INTERNALS
103
104
/* Define this if your compiler implements ">>" on signed values as a logical
105
 * (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift,
106
 * which is the normal and rational definition.
107
 */
108
#undef RIGHT_SHIFT_IS_UNSIGNED
109
110
111
#endif /* JPEG_INTERNALS */
112
113
114
/*
115
 * The remaining options do not affect the JPEG library proper,
116
 * but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c).
117
 * Other applications can ignore these.
118
 */
119
120
#ifdef JPEG_CJPEG_DJPEG
121
122
/* These defines indicate which image (non-JPEG) file formats are allowed. */
123
124
#define BMP_SUPPORTED		/* BMP image file format */
125
#define GIF_SUPPORTED		/* GIF image file format */
126
#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
127
#undef RLE_SUPPORTED		/* Utah RLE image file format */
128
#define TARGA_SUPPORTED		/* Targa image file format */
129
130
/* Define this if you want to name both input and output files on the command
131
 * line, rather than using stdout and optionally stdin.  You MUST do this if
132
 * your system can't cope with binary I/O to stdin/stdout.  See comments at
133
 * head of cjpeg.c or djpeg.c.
134
 */
135
#undef TWO_FILE_COMMANDLINE
136
137
/* Define this if your system needs explicit cleanup of temporary files.
138
 * This is crucial under MS-DOS, where the temporary "files" may be areas
139
 * of extended memory; on most other systems it's not as important.
140
 */
141
#undef NEED_SIGNAL_CATCHER
142
143
/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb").
144
 * This is necessary on systems that distinguish text files from binary files,
145
 * and is harmless on most systems that don't.  If you have one of the rare
146
 * systems that complains about the "b" spec, define this symbol.
147
 */
148
#undef DONT_USE_B_MODE
149
150
/* Define this if you want percent-done progress reports from cjpeg/djpeg.
151
 */
152
#undef PROGRESS_REPORT
153
154
155
#endif /* JPEG_CJPEG_DJPEG */
(-)a/jpeg/jconfig.h (-107 / +55 lines)
Line     Link Here 
 Lines 1-107    Link Here 
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
1
/* jconfig.h.  Generated from jconfig.h.in by configure, then manually edited
2
/* ***** BEGIN LICENSE BLOCK *****
2
   for Mozilla. */
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3
4
 *
4
/* Export libjpeg v6.2's ABI. */
5
 * The contents of this file are subject to the Mozilla Public License Version
5
#define JPEG_LIB_VERSION 62
6
 * 1.1 (the "License"); you may not use this file except in compliance with
6
7
 * the License. You may obtain a copy of the License at
7
/* Define if your compiler supports prototypes */
8
 * http://www.mozilla.org/MPL/
8
#define HAVE_PROTOTYPES 1
9
 *
9
10
 * Software distributed under the License is distributed on an "AS IS" basis,
10
/* Define to 1 if you have the <stddef.h> header file. */
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
#define HAVE_STDDEF_H 1
12
 * for the specific language governing rights and limitations under the
12
13
 * License.
13
/* Define to 1 if you have the <stdlib.h> header file. */
14
 *
14
#define HAVE_STDLIB_H 1
15
 * The Original Code is mozilla.org code.
15
16
 *
16
/* Define to 1 if the system has the type `unsigned char'. */
17
 * The Initial Developer of the Original Code is
17
#define HAVE_UNSIGNED_CHAR 1
18
 * Netscape Communications Corporation.
18
19
 * Portions created by the Initial Developer are Copyright (C) 1998
19
/* Define to 1 if the system has the type `unsigned short'. */
20
 * the Initial Developer. All Rights Reserved.
20
#define HAVE_UNSIGNED_SHORT 1
21
 *
21
22
 * Contributor(s):
22
/* Define if you want use complete types */
23
 *
23
/* #define INCOMPLETE_TYPES_BROKEN 1 */
24
 * Alternatively, the contents of this file may be used under the terms of
24
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
25
/* Define if you have BSD-like bzero and bcopy */
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26
/* #undef NEED_BSD_STRINGS */
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
27
28
 * of those above. If you wish to allow use of your version of this file only
28
/* Define if you need short function names */
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
29
/* #undef NEED_SHORT_EXTERNAL_NAMES */
30
 * use your version of this file under the terms of the MPL, indicate your
30
31
 * decision by deleting the provisions above and replace them with the notice
31
/* Define if you have sys/types.h */
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
32
#define NEED_SYS_TYPES_H 1
33
 * the provisions above, a recipient may use your version of this file under
33
34
 * the terms of any one of the MPL, the GPL or the LGPL.
34
/* Define if shift is unsigned */
35
 *
35
/* #undef RIGHT_SHIFT_IS_UNSIGNED */
36
 * ***** END LICENSE BLOCK ***** */
36
37
37
/* Use accelerated SIMD routines. */
38
/*
38
#define WITH_SIMD 1
39
 * jconfig.h to configure the IJG JPEG library for the Mozilla/Netscape
39
40
 * environment.  Note that there are also Mozilla mods in jmorecfg.h.
40
/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
41
 */
41
#ifndef __CHAR_UNSIGNED__
42
42
/* # undef __CHAR_UNSIGNED__ */
43
/* We assume an ANSI C or C++ compilation environment */
43
#endif
44
#define HAVE_PROTOTYPES 
44
45
#define HAVE_UNSIGNED_CHAR 
45
/* Define to empty if `const' does not conform to ANSI C. */
46
#define HAVE_UNSIGNED_SHORT 
46
/* #undef const */
47
/* #define void char */
47
48
/* #define const */
48
/* Define to `__inline__' or `__inline' if that's what the C compiler
49
#ifndef HAVE_STDDEF_H 
49
   calls it, or to nothing if 'inline' is not supported under any name.  */
50
#define HAVE_STDDEF_H 
50
#ifndef __cplusplus
51
#endif /* HAVE_STDDEF_H */
51
/* #undef inline */
52
#ifndef HAVE_STDLIB_H
52
#endif
53
#define HAVE_STDLIB_H 
53
54
#endif /* HAVE_STDLIB_H */
54
/* Define to `unsigned int' if <sys/types.h> does not define. */
55
#undef NEED_BSD_STRINGS
55
/* #undef size_t */
56
#undef NEED_SYS_TYPES_H
57
#undef NEED_FAR_POINTERS
58
#undef NEED_SHORT_EXTERNAL_NAMES
59
/* Define this if you get warnings about undefined structures. */
60
#undef INCOMPLETE_TYPES_BROKEN
61
62
/* With this setting, the IJG code will work regardless of whether
63
 * type "char" is signed or unsigned.
64
 */
65
#undef CHAR_IS_UNSIGNED
66
67
68
/* defines that need not be visible to callers of the IJG library */
69
70
#ifdef JPEG_INTERNALS
71
72
/* If right shift of "long" quantities is unsigned on your machine,
73
 * you'll have to define this.  Fortunately few people should need it.
74
 */
75
#undef RIGHT_SHIFT_IS_UNSIGNED
76
77
#endif /* JPEG_INTERNALS */
78
79
80
/* these defines are not interesting for building just the IJG library,
81
 * but we leave 'em here anyway.
82
 */
83
#ifdef JPEG_CJPEG_DJPEG
84
85
#define BMP_SUPPORTED		/* BMP image file format */
86
#define GIF_SUPPORTED		/* GIF image file format */
87
#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
88
#undef RLE_SUPPORTED		/* Utah RLE image file format */
89
#define TARGA_SUPPORTED		/* Targa image file format */
90
91
#undef TWO_FILE_COMMANDLINE
92
#undef NEED_SIGNAL_CATCHER
93
#undef DONT_USE_B_MODE
94
#undef PROGRESS_REPORT
95
96
#endif /* JPEG_CJPEG_DJPEG */
97
98
/* SSE* alignment support - only use on platforms that support declspec and __attribute__ */
99
100
#if defined(XP_WIN32) && defined(_M_IX86) && !defined(__GNUC__)
101
#define ALIGN16_const_vector_short(name) __declspec(align(16)) const short name[8]
102
#define ALIGN16_const_vector_uchar(name) __declspec(align(16)) const unsigned char name[16]
103
#else
104
#define ALIGN16_const_vector_short(name) const short name[8] __attribute__ ((aligned (16)))
105
#define ALIGN16_const_vector_uchar(name) const unsigned char name[16] __attribute__ ((aligned (16)))
106
#endif /* ! XP_WIN32 && _M_IX86 && !__GNUC */
107
(-)a/jpeg/jconfig.h.in (+60 lines)
Line     Link Here 
Line 0    Link Here 
1
/* Version ID for the JPEG library.
2
 * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
3
 */
4
#define JPEG_LIB_VERSION  62	/* Version 6b */
5
6
/* Support arithmetic encoding */
7
#undef C_ARITH_CODING_SUPPORTED
8
9
/* Support arithmetic decoding */
10
#undef D_ARITH_CODING_SUPPORTED
11
12
/* Define if your compiler supports prototypes */
13
#undef HAVE_PROTOTYPES
14
15
/* Define to 1 if you have the <stddef.h> header file. */
16
#undef HAVE_STDDEF_H
17
18
/* Define to 1 if you have the <stdlib.h> header file. */
19
#undef HAVE_STDLIB_H
20
21
/* Define to 1 if the system has the type `unsigned char'. */
22
#undef HAVE_UNSIGNED_CHAR
23
24
/* Define to 1 if the system has the type `unsigned short'. */
25
#undef HAVE_UNSIGNED_SHORT
26
27
/* Define if you want use complete types */
28
#undef INCOMPLETE_TYPES_BROKEN
29
30
/* Define if you have BSD-like bzero and bcopy */
31
#undef NEED_BSD_STRINGS
32
33
/* Define if you need short function names */
34
#undef NEED_SHORT_EXTERNAL_NAMES
35
36
/* Define if you have sys/types.h */
37
#undef NEED_SYS_TYPES_H
38
39
/* Define if shift is unsigned */
40
#undef RIGHT_SHIFT_IS_UNSIGNED
41
42
/* Use accelerated SIMD routines. */
43
#undef WITH_SIMD
44
45
/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
46
#ifndef __CHAR_UNSIGNED__
47
# undef __CHAR_UNSIGNED__
48
#endif
49
50
/* Define to empty if `const' does not conform to ANSI C. */
51
#undef const
52
53
/* Define to `__inline__' or `__inline' if that's what the C compiler
54
   calls it, or to nothing if 'inline' is not supported under any name.  */
55
#ifndef __cplusplus
56
#undef inline
57
#endif
58
59
/* Define to `unsigned int' if <sys/types.h> does not define. */
60
#undef size_t
(-)a/jpeg/jconfig.wat (-38 lines)
Line     Link Here 
 Lines 1-38    Link Here 
1
/* jconfig.wat --- jconfig.h for Watcom C/C++ on MS-DOS or OS/2. */
2
/* see jconfig.doc for explanations */
3
4
#define HAVE_PROTOTYPES
5
#define HAVE_UNSIGNED_CHAR
6
#define HAVE_UNSIGNED_SHORT
7
/* #define void char */
8
/* #define const */
9
#define CHAR_IS_UNSIGNED
10
#define HAVE_STDDEF_H
11
#define HAVE_STDLIB_H
12
#undef NEED_BSD_STRINGS
13
#undef NEED_SYS_TYPES_H
14
#undef NEED_FAR_POINTERS	/* Watcom uses flat 32-bit addressing */
15
#undef NEED_SHORT_EXTERNAL_NAMES
16
#undef INCOMPLETE_TYPES_BROKEN
17
18
#ifdef JPEG_INTERNALS
19
20
#undef RIGHT_SHIFT_IS_UNSIGNED
21
22
#endif /* JPEG_INTERNALS */
23
24
#ifdef JPEG_CJPEG_DJPEG
25
26
#define BMP_SUPPORTED		/* BMP image file format */
27
#define GIF_SUPPORTED		/* GIF image file format */
28
#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
29
#undef RLE_SUPPORTED		/* Utah RLE image file format */
30
#define TARGA_SUPPORTED		/* Targa image file format */
31
32
#undef TWO_FILE_COMMANDLINE	/* optional */
33
#define USE_SETMODE		/* Needed to make one-file style work in Watcom */
34
#undef NEED_SIGNAL_CATCHER	/* Define this if you use jmemname.c */
35
#undef DONT_USE_B_MODE
36
#undef PROGRESS_REPORT		/* optional */
37
38
#endif /* JPEG_CJPEG_DJPEG */
(-)a/jpeg/jcparam.c (-27 / +62 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jcparam.c
2
 * jcparam.c
3
 *
3
 *
4
 * Copyright (C) 1991-1998, Thomas G. Lane.
4
 * Copyright (C) 1991-1998, Thomas G. Lane.
5
 * Modified 2003-2008 by Guido Vollbeding.
6
 * Copyright (C) 2009-2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
7
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
8
 * For conditions of distribution and use, see the accompanying README file.
7
 *
9
 *
8
 * This file contains optional default-setting code for the JPEG compressor.
10
 * This file contains optional default-setting code for the JPEG compressor.
9
 * Applications do not have to use this file, but those that don't use it
11
 * Applications do not have to use this file, but those that don't use it
10
 * must know a lot more about the innards of the JPEG code.
12
 * must know a lot more about the innards of the JPEG code.
11
 */
13
 */
12
14
 Lines 55-108   jpeg_add_quant_table (j_compress_ptr cin Link Here 
55
    (*qtblptr)->quantval[i] = (UINT16) temp;
57
    (*qtblptr)->quantval[i] = (UINT16) temp;
56
  }
58
  }
57
59
58
  /* Initialize sent_table FALSE so table will be written to JPEG file. */
60
  /* Initialize sent_table FALSE so table will be written to JPEG file. */
59
  (*qtblptr)->sent_table = FALSE;
61
  (*qtblptr)->sent_table = FALSE;
60
}
62
}
61
63
62
64
65
/* These are the sample quantization tables given in JPEG spec section K.1.
66
 * The spec says that the values given produce "good" quality, and
67
 * when divided by 2, "very good" quality.
68
 */
69
static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
70
  16,  11,  10,  16,  24,  40,  51,  61,
71
  12,  12,  14,  19,  26,  58,  60,  55,
72
  14,  13,  16,  24,  40,  57,  69,  56,
73
  14,  17,  22,  29,  51,  87,  80,  62,
74
  18,  22,  37,  56,  68, 109, 103,  77,
75
  24,  35,  55,  64,  81, 104, 113,  92,
76
  49,  64,  78,  87, 103, 121, 120, 101,
77
  72,  92,  95,  98, 112, 100, 103,  99
78
};
79
static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
80
  17,  18,  24,  47,  99,  99,  99,  99,
81
  18,  21,  26,  66,  99,  99,  99,  99,
82
  24,  26,  56,  99,  99,  99,  99,  99,
83
  47,  66,  99,  99,  99,  99,  99,  99,
84
  99,  99,  99,  99,  99,  99,  99,  99,
85
  99,  99,  99,  99,  99,  99,  99,  99,
86
  99,  99,  99,  99,  99,  99,  99,  99,
87
  99,  99,  99,  99,  99,  99,  99,  99
88
};
89
90
91
#if JPEG_LIB_VERSION >= 70
92
GLOBAL(void)
93
jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
94
/* Set or change the 'quality' (quantization) setting, using default tables
95
 * and straight percentage-scaling quality scales.
96
 * This entry point allows different scalings for luminance and chrominance.
97
 */
98
{
99
  /* Set up two quantization tables using the specified scaling */
100
  jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
101
		       cinfo->q_scale_factor[0], force_baseline);
102
  jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
103
		       cinfo->q_scale_factor[1], force_baseline);
104
}
105
#endif
106
107
63
GLOBAL(void)
108
GLOBAL(void)
64
jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
109
jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
65
			 boolean force_baseline)
110
			 boolean force_baseline)
66
/* Set or change the 'quality' (quantization) setting, using default tables
111
/* Set or change the 'quality' (quantization) setting, using default tables
67
 * and a straight percentage-scaling quality scale.  In most cases it's better
112
 * and a straight percentage-scaling quality scale.  In most cases it's better
68
 * to use jpeg_set_quality (below); this entry point is provided for
113
 * to use jpeg_set_quality (below); this entry point is provided for
69
 * applications that insist on a linear percentage scaling.
114
 * applications that insist on a linear percentage scaling.
70
 */
115
 */
71
{
116
{
72
  /* These are the sample quantization tables given in JPEG spec section K.1.
73
   * The spec says that the values given produce "good" quality, and
74
   * when divided by 2, "very good" quality.
75
   */
76
  static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
77
    16,  11,  10,  16,  24,  40,  51,  61,
78
    12,  12,  14,  19,  26,  58,  60,  55,
79
    14,  13,  16,  24,  40,  57,  69,  56,
80
    14,  17,  22,  29,  51,  87,  80,  62,
81
    18,  22,  37,  56,  68, 109, 103,  77,
82
    24,  35,  55,  64,  81, 104, 113,  92,
83
    49,  64,  78,  87, 103, 121, 120, 101,
84
    72,  92,  95,  98, 112, 100, 103,  99
85
  };
86
  static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
87
    17,  18,  24,  47,  99,  99,  99,  99,
88
    18,  21,  26,  66,  99,  99,  99,  99,
89
    24,  26,  56,  99,  99,  99,  99,  99,
90
    47,  66,  99,  99,  99,  99,  99,  99,
91
    99,  99,  99,  99,  99,  99,  99,  99,
92
    99,  99,  99,  99,  99,  99,  99,  99,
93
    99,  99,  99,  99,  99,  99,  99,  99,
94
    99,  99,  99,  99,  99,  99,  99,  99
95
  };
96
97
  /* Set up two quantization tables using the specified scaling */
117
  /* Set up two quantization tables using the specified scaling */
98
  jpeg_add_quant_table(cinfo, 0, (const unsigned int *)std_luminance_quant_tbl,
118
  jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
99
		       scale_factor, force_baseline);
119
		       scale_factor, force_baseline);
100
  jpeg_add_quant_table(cinfo, 1, (const unsigned int *)std_chrominance_quant_tbl,
120
  jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
101
		       scale_factor, force_baseline);
121
		       scale_factor, force_baseline);
102
}
122
}
103
123
104
124
105
GLOBAL(int)
125
GLOBAL(int)
106
jpeg_quality_scaling (int quality)
126
jpeg_quality_scaling (int quality)
107
/* Convert a user-specified quality rating to a percentage scaling factor
127
/* Convert a user-specified quality rating to a percentage scaling factor
108
 * for an underlying quantization table, using our recommended scaling curve.
128
 * for an underlying quantization table, using our recommended scaling curve.
 Lines 279-294   jpeg_set_defaults (j_compress_ptr cinfo) Link Here 
279
   */
299
   */
280
  if (cinfo->comp_info == NULL)
300
  if (cinfo->comp_info == NULL)
281
    cinfo->comp_info = (jpeg_component_info *)
301
    cinfo->comp_info = (jpeg_component_info *)
282
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
302
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
283
				  MAX_COMPONENTS * SIZEOF(jpeg_component_info));
303
				  MAX_COMPONENTS * SIZEOF(jpeg_component_info));
284
304
285
  /* Initialize everything not dependent on the color space */
305
  /* Initialize everything not dependent on the color space */
286
306
307
#if JPEG_LIB_VERSION >= 70
308
  cinfo->scale_num = 1;		/* 1:1 scaling */
309
  cinfo->scale_denom = 1;
310
#endif
287
  cinfo->data_precision = BITS_IN_JSAMPLE;
311
  cinfo->data_precision = BITS_IN_JSAMPLE;
288
  /* Set up two quantization tables using default quality of 75 */
312
  /* Set up two quantization tables using default quality of 75 */
289
  jpeg_set_quality(cinfo, 75, TRUE);
313
  jpeg_set_quality(cinfo, 75, TRUE);
290
  /* Set up two Huffman tables */
314
  /* Set up two Huffman tables */
291
  std_huff_tables(cinfo);
315
  std_huff_tables(cinfo);
292
316
293
  /* Initialize default arithmetic coding conditioning */
317
  /* Initialize default arithmetic coding conditioning */
294
  for (i = 0; i < NUM_ARITH_TBLS; i++) {
318
  for (i = 0; i < NUM_ARITH_TBLS; i++) {
 Lines 315-330   jpeg_set_defaults (j_compress_ptr cinfo) Link Here 
315
   * are supplied that are valid for the desired precision.
339
   * are supplied that are valid for the desired precision.
316
   */
340
   */
317
  if (cinfo->data_precision > 8)
341
  if (cinfo->data_precision > 8)
318
    cinfo->optimize_coding = TRUE;
342
    cinfo->optimize_coding = TRUE;
319
343
320
  /* By default, use the simpler non-cosited sampling alignment */
344
  /* By default, use the simpler non-cosited sampling alignment */
321
  cinfo->CCIR601_sampling = FALSE;
345
  cinfo->CCIR601_sampling = FALSE;
322
346
347
#if JPEG_LIB_VERSION >= 70
348
  /* By default, apply fancy downsampling */
349
  cinfo->do_fancy_downsampling = TRUE;
350
#endif
351
323
  /* No input smoothing */
352
  /* No input smoothing */
324
  cinfo->smoothing_factor = 0;
353
  cinfo->smoothing_factor = 0;
325
354
326
  /* DCT algorithm preference */
355
  /* DCT algorithm preference */
327
  cinfo->dct_method = JDCT_DEFAULT;
356
  cinfo->dct_method = JDCT_DEFAULT;
328
357
329
  /* No restart markers */
358
  /* No restart markers */
330
  cinfo->restart_interval = 0;
359
  cinfo->restart_interval = 0;
 Lines 358-373   jpeg_set_defaults (j_compress_ptr cinfo) Link Here 
358
GLOBAL(void)
387
GLOBAL(void)
359
jpeg_default_colorspace (j_compress_ptr cinfo)
388
jpeg_default_colorspace (j_compress_ptr cinfo)
360
{
389
{
361
  switch (cinfo->in_color_space) {
390
  switch (cinfo->in_color_space) {
362
  case JCS_GRAYSCALE:
391
  case JCS_GRAYSCALE:
363
    jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
392
    jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
364
    break;
393
    break;
365
  case JCS_RGB:
394
  case JCS_RGB:
395
  case JCS_EXT_RGB:
396
  case JCS_EXT_RGBX:
397
  case JCS_EXT_BGR:
398
  case JCS_EXT_BGRX:
399
  case JCS_EXT_XBGR:
400
  case JCS_EXT_XRGB:
366
    jpeg_set_colorspace(cinfo, JCS_YCbCr);
401
    jpeg_set_colorspace(cinfo, JCS_YCbCr);
367
    break;
402
    break;
368
  case JCS_YCbCr:
403
  case JCS_YCbCr:
369
    jpeg_set_colorspace(cinfo, JCS_YCbCr);
404
    jpeg_set_colorspace(cinfo, JCS_YCbCr);
370
    break;
405
    break;
371
  case JCS_CMYK:
406
  case JCS_CMYK:
372
    jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
407
    jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
373
    break;
408
    break;
(-)a/jpeg/jcphuff.c (-2 lines)
Line     Link Here 
 Lines 218-234   dump_buffer (phuff_entropy_ptr entropy) Link Here 
218
/* Outputting bits to the file */
218
/* Outputting bits to the file */
219
219
220
/* Only the right 24 bits of put_buffer are used; the valid bits are
220
/* Only the right 24 bits of put_buffer are used; the valid bits are
221
 * left-justified in this part.  At most 16 bits can be passed to emit_bits
221
 * left-justified in this part.  At most 16 bits can be passed to emit_bits
222
 * in one call, and we never retain more than 7 bits in put_buffer
222
 * in one call, and we never retain more than 7 bits in put_buffer
223
 * between calls, so 24 bits are sufficient.
223
 * between calls, so 24 bits are sufficient.
224
 */
224
 */
225
225
226
INLINE
227
LOCAL(void)
226
LOCAL(void)
228
emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
227
emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
229
/* Emit some bits, unless we are in gather mode */
228
/* Emit some bits, unless we are in gather mode */
230
{
229
{
231
  /* This routine is heavily used, so it's worth coding tightly. */
230
  /* This routine is heavily used, so it's worth coding tightly. */
232
  register INT32 put_buffer = (INT32) code;
231
  register INT32 put_buffer = (INT32) code;
233
  register int put_bits = entropy->put_bits;
232
  register int put_bits = entropy->put_bits;
234
233
 Lines 271-287   flush_bits (phuff_entropy_ptr entropy) Link Here 
271
  entropy->put_bits = 0;
270
  entropy->put_bits = 0;
272
}
271
}
273
272
274
273
275
/*
274
/*
276
 * Emit (or just count) a Huffman symbol.
275
 * Emit (or just count) a Huffman symbol.
277
 */
276
 */
278
277
279
INLINE
280
LOCAL(void)
278
LOCAL(void)
281
emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
279
emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
282
{
280
{
283
  if (entropy->gather_statistics)
281
  if (entropy->gather_statistics)
284
    entropy->count_ptrs[tbl_no][symbol]++;
282
    entropy->count_ptrs[tbl_no][symbol]++;
285
  else {
283
  else {
286
    c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
284
    c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
287
    emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
285
    emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
(-)a/jpeg/jcsample.c (-2 / +10 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jcsample.c
2
 * jcsample.c
3
 *
3
 *
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
5
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains downsampling routines.
9
 * This file contains downsampling routines.
9
 *
10
 *
10
 * Downsampling input data is counted in "row groups".  A row group
11
 * Downsampling input data is counted in "row groups".  A row group
11
 * is defined to be max_v_samp_factor pixel rows of each component,
12
 * is defined to be max_v_samp_factor pixel rows of each component,
12
 * from which the downsampler produces v_samp_factor sample rows.
13
 * from which the downsampler produces v_samp_factor sample rows.
 Lines 43-58    Link Here 
43
 * eight neighbors.  P's weight is 1-8*SF and each neighbor's weight is SF,
44
 * eight neighbors.  P's weight is 1-8*SF and each neighbor's weight is SF,
44
 * where SF = (smoothing_factor / 1024).
45
 * where SF = (smoothing_factor / 1024).
45
 * Currently, smoothing is only supported for 2h2v sampling factors.
46
 * Currently, smoothing is only supported for 2h2v sampling factors.
46
 */
47
 */
47
48
48
#define JPEG_INTERNALS
49
#define JPEG_INTERNALS
49
#include "jinclude.h"
50
#include "jinclude.h"
50
#include "jpeglib.h"
51
#include "jpeglib.h"
52
#include "jsimd.h"
51
53
52
54
53
/* Pointer to routine to downsample a single component */
55
/* Pointer to routine to downsample a single component */
54
typedef JMETHOD(void, downsample1_ptr,
56
typedef JMETHOD(void, downsample1_ptr,
55
		(j_compress_ptr cinfo, jpeg_component_info * compptr,
57
		(j_compress_ptr cinfo, jpeg_component_info * compptr,
56
		 JSAMPARRAY input_data, JSAMPARRAY output_data));
58
		 JSAMPARRAY input_data, JSAMPARRAY output_data));
57
59
58
/* Private subobject */
60
/* Private subobject */
 Lines 489-514   jinit_downsampler (j_compress_ptr cinfo) Link Here 
489
	downsample->methods[ci] = fullsize_smooth_downsample;
491
	downsample->methods[ci] = fullsize_smooth_downsample;
490
	downsample->pub.need_context_rows = TRUE;
492
	downsample->pub.need_context_rows = TRUE;
491
      } else
493
      } else
492
#endif
494
#endif
493
	downsample->methods[ci] = fullsize_downsample;
495
	downsample->methods[ci] = fullsize_downsample;
494
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
496
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
495
	       compptr->v_samp_factor == cinfo->max_v_samp_factor) {
497
	       compptr->v_samp_factor == cinfo->max_v_samp_factor) {
496
      smoothok = FALSE;
498
      smoothok = FALSE;
497
      downsample->methods[ci] = h2v1_downsample;
499
      if (jsimd_can_h2v1_downsample())
500
        downsample->methods[ci] = jsimd_h2v1_downsample;
501
      else
502
        downsample->methods[ci] = h2v1_downsample;
498
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
503
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
499
	       compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
504
	       compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
500
#ifdef INPUT_SMOOTHING_SUPPORTED
505
#ifdef INPUT_SMOOTHING_SUPPORTED
501
      if (cinfo->smoothing_factor) {
506
      if (cinfo->smoothing_factor) {
502
	downsample->methods[ci] = h2v2_smooth_downsample;
507
	downsample->methods[ci] = h2v2_smooth_downsample;
503
	downsample->pub.need_context_rows = TRUE;
508
	downsample->pub.need_context_rows = TRUE;
504
      } else
509
      } else
505
#endif
510
#endif
506
	downsample->methods[ci] = h2v2_downsample;
511
	if (jsimd_can_h2v2_downsample())
512
	  downsample->methods[ci] = jsimd_h2v2_downsample;
513
	else
514
	  downsample->methods[ci] = h2v2_downsample;
507
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
515
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
508
	       (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
516
	       (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
509
      smoothok = FALSE;
517
      smoothok = FALSE;
510
      downsample->methods[ci] = int_downsample;
518
      downsample->methods[ci] = int_downsample;
511
    } else
519
    } else
512
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
520
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
513
  }
521
  }
514
522
(-)a/jpeg/jdapimin.c (-136 / +1 lines)
Line     Link Here 
 Lines 15-129    Link Here 
15
 * shared by compression and decompression, and jdtrans.c for the transcoding
15
 * shared by compression and decompression, and jdtrans.c for the transcoding
16
 * case.
16
 * case.
17
 */
17
 */
18
18
19
#define JPEG_INTERNALS
19
#define JPEG_INTERNALS
20
#include "jinclude.h"
20
#include "jinclude.h"
21
#include "jpeglib.h"
21
#include "jpeglib.h"
22
22
23
#ifdef HAVE_MMX_INTEL_MNEMONICS
24
#if _MSC_VER >= 1400
25
#include "intrin.h"
26
#else
27
/* no __cpuid intrinsic, use a manually rewritten replacement */
28
void __stdcall __cpuid( int CPUInfo[4], int InfoType )
29
{
30
  int my_eax = 0, my_ebx = 0, my_ecx = 0, my_edx = 0;
31
  __asm {
32
    /* check eflags bit 21 to see if cpuid is supported */
33
    pushfd             /* save eflags to stack */
34
    pop eax            /* and put it in eax */
35
    mov ecx, eax       /* save a copy in ecx to compare against */
36
    xor eax, 0x200000  /* toggle ID bit (bit 21) in eflags */
37
    push eax           /* save modified eflags to stack */
38
    popfd              /* set eflags register with modified value */
39
    pushfd             /* read eflags back out */
40
    pop eax
41
    xor eax, ecx       /* check for modified eflags */
42
    jz NOT_SUPPORTED   /* cpuid not supported */
43
44
    /* check to see if the requested cpuid type is supported */
45
    xor eax, eax       /* set eax to zero */
46
    cpuid
47
    cmp eax, InfoType
48
    jl NOT_SUPPORTED   /* the requested cpuid type is not supported */
49
50
    /* actually make the cpuid call */
51
    mov eax, InfoType
52
    cpuid
53
    mov my_eax, eax
54
    mov my_ebx, ebx
55
    mov my_ecx, ecx
56
    mov my_edx, edx
57
NOT_SUPPORTED:
58
  }
59
  CPUInfo[0] = my_eax;
60
  CPUInfo[1] = my_ebx;
61
  CPUInfo[2] = my_ecx;
62
  CPUInfo[3] = my_edx;
63
}
64
#endif /* _MSC_VER >= 1400 */
65
66
int MMXAvailable;
67
static int mmxsupport();
68
#endif
69
70
#ifdef HAVE_SSE2_INTRINSICS
71
int SSE2Available = 0;
72
#ifdef HAVE_SSE2_INTEL_MNEMONICS
73
static int sse2support();
74
#else
75
static int sse2supportGCC();
76
#endif /* HAVE_SSE2_INTEL_MNEMONICS */
77
#endif /* HAVE_SSE2_INTRINSICS */
78
79
23
80
/*
24
/*
81
 * Initialization of a JPEG decompression object.
25
 * Initialization of a JPEG decompression object.
82
 * The error manager must already be set up (in case memory manager fails).
26
 * The error manager must already be set up (in case memory manager fails).
83
 */
27
 */
84
28
85
GLOBAL(void)
29
GLOBAL(void)
86
jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
30
jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
87
{
31
{
88
  int i;
32
  int i;
89
33
90
#ifdef HAVE_MMX_INTEL_MNEMONICS
91
  static int cpuidDetected = 0;
92
93
  if(!cpuidDetected)
94
  {
95
	MMXAvailable = mmxsupport();
96
97
#ifdef HAVE_SSE2_INTEL_MNEMONICS
98
	/* only do the sse2 support check if mmx is supported (so
99
	   we know the processor supports cpuid) */
100
	if (MMXAvailable)
101
	    SSE2Available = sse2support();
102
#endif
103
104
	cpuidDetected = 1;
105
  }
106
#else
107
#ifdef HAVE_SSE2_INTRINSICS
108
  static int cpuidDetected = 0;
109
110
  if(!cpuidDetected) {
111
    SSE2Available = sse2supportGCC();
112
    cpuidDetected = 1;
113
  }
114
115
#endif /* HAVE_SSE2_INTRINSICS */
116
#endif /* HAVE_MMX_INTEL_MNEMONICS */
117
118
  /* For debugging purposes, zero the whole master structure.
119
   * But error manager pointer is already there, so save and restore it.
120
   */
121
122
  /* Guard against version mismatches between library and caller. */
34
  /* Guard against version mismatches between library and caller. */
123
  cinfo->mem = NULL;		/* so jpeg_destroy knows mem mgr not called */
35
  cinfo->mem = NULL;		/* so jpeg_destroy knows mem mgr not called */
124
  if (version != JPEG_LIB_VERSION)
36
  if (version != JPEG_LIB_VERSION)
125
    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
37
    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
126
  if (structsize != SIZEOF(struct jpeg_decompress_struct))
38
  if (structsize != SIZEOF(struct jpeg_decompress_struct))
127
    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, 
39
    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, 
128
	     (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
40
	     (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
129
41
 Lines 188-203   jpeg_destroy_decompress (j_decompress_pt Link Here 
188
 */
100
 */
189
101
190
GLOBAL(void)
102
GLOBAL(void)
191
jpeg_abort_decompress (j_decompress_ptr cinfo)
103
jpeg_abort_decompress (j_decompress_ptr cinfo)
192
{
104
{
193
  jpeg_abort((j_common_ptr) cinfo); /* use common routine */
105
  jpeg_abort((j_common_ptr) cinfo); /* use common routine */
194
}
106
}
195
107
108
196
/*
109
/*
197
 * Set default decompression parameters.
110
 * Set default decompression parameters.
198
 */
111
 */
199
112
200
LOCAL(void)
113
LOCAL(void)
201
default_decompress_parms (j_decompress_ptr cinfo)
114
default_decompress_parms (j_decompress_ptr cinfo)
202
{
115
{
203
  /* Guess the input colorspace, and set output colorspace accordingly. */
116
  /* Guess the input colorspace, and set output colorspace accordingly. */
 Lines 475-530   jpeg_finish_decompress (j_decompress_ptr Link Here 
475
      return FALSE;		/* Suspend, come back later */
388
      return FALSE;		/* Suspend, come back later */
476
  }
389
  }
477
  /* Do final cleanup */
390
  /* Do final cleanup */
478
  (*cinfo->src->term_source) (cinfo);
391
  (*cinfo->src->term_source) (cinfo);
479
  /* We can use jpeg_abort to release memory and reset global_state */
392
  /* We can use jpeg_abort to release memory and reset global_state */
480
  jpeg_abort((j_common_ptr) cinfo);
393
  jpeg_abort((j_common_ptr) cinfo);
481
  return TRUE;
394
  return TRUE;
482
}
395
}
483
484
485
#ifdef HAVE_MMX_INTEL_MNEMONICS
486
static int mmxsupport()
487
{
488
  int CPUInfo[4];
489
490
  __cpuid(CPUInfo, 1);
491
  if (CPUInfo[3] & (0x1 << 23))
492
    return 1;
493
  else
494
    return 0;
495
}
496
#endif
497
498
#ifdef HAVE_SSE2_INTEL_MNEMONICS
499
static int sse2support()
500
{
501
  int CPUInfo[4];
502
503
  __cpuid(CPUInfo, 1);
504
  if (CPUInfo[3] & (0x1 << 26))
505
    return 1;
506
  else
507
    return 2;
508
}
509
#else
510
#ifdef HAVE_SSE2_INTRINSICS
511
static int sse2supportGCC()
512
{
513
514
  /* Mac Intel started with Core Duo chips which have SSE2 Support */
515
516
#if defined(__GNUC__) && defined(__i386__)
517
#if defined(XP_MACOSX)
518
  return 1;
519
#endif /* XP_MACOSX */
520
#endif /* GNUC && i386 */
521
522
  /* Add checking for SSE2 support for other platforms here */
523
524
  /* We don't have SSE2 intrinsics support */
525
526
  return 2;
527
}
528
#endif /* HAVE_SSE2_INTRINSICS */
529
#endif /* HAVE_SSE2_INTEL_MNEMONICS */
530
(-)a/jpeg/jdapistd.c (-1 / +3 lines)
Line     Link Here 
 Lines 1-27    Link Here 
1
/*
1
/*
2
 * jdapistd.c
2
 * jdapistd.c
3
 *
3
 *
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
5
 * Copyright (C) 2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains application interface code for the decompression half
9
 * This file contains application interface code for the decompression half
9
 * of the JPEG library.  These are the "standard" API routines that are
10
 * of the JPEG library.  These are the "standard" API routines that are
10
 * used in the normal full-decompression case.  They are not used by a
11
 * used in the normal full-decompression case.  They are not used by a
11
 * transcoding-only application.  Note that if an application links in
12
 * transcoding-only application.  Note that if an application links in
12
 * jpeg_start_decompress, it will end up linking in the entire decompressor.
13
 * jpeg_start_decompress, it will end up linking in the entire decompressor.
13
 * We thus must separate this file from jdapimin.c to avoid linking the
14
 * We thus must separate this file from jdapimin.c to avoid linking the
14
 * whole decompression library into a transcoder.
15
 * whole decompression library into a transcoder.
15
 */
16
 */
16
17
17
#define JPEG_INTERNALS
18
#define JPEG_INTERNALS
18
#include "jinclude.h"
19
#include "jinclude.h"
19
#include "jpeglib.h"
20
#include "jpeglib.h"
21
#include "jpegcomp.h"
20
22
21
23
22
/* Forward declarations */
24
/* Forward declarations */
23
LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
25
LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
24
26
25
27
26
/*
28
/*
27
 * Decompression initialization.
29
 * Decompression initialization.
 Lines 197-213   jpeg_read_raw_data (j_decompress_ptr cin Link Here 
197
  /* Call progress monitor hook if present */
199
  /* Call progress monitor hook if present */
198
  if (cinfo->progress != NULL) {
200
  if (cinfo->progress != NULL) {
199
    cinfo->progress->pass_counter = (long) cinfo->output_scanline;
201
    cinfo->progress->pass_counter = (long) cinfo->output_scanline;
200
    cinfo->progress->pass_limit = (long) cinfo->output_height;
202
    cinfo->progress->pass_limit = (long) cinfo->output_height;
201
    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
203
    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
202
  }
204
  }
203
205
204
  /* Verify that at least one iMCU row can be returned. */
206
  /* Verify that at least one iMCU row can be returned. */
205
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
207
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size;
206
  if (max_lines < lines_per_iMCU_row)
208
  if (max_lines < lines_per_iMCU_row)
207
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
209
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
208
210
209
  /* Decompress directly into user's buffer. */
211
  /* Decompress directly into user's buffer. */
210
  if (! (*cinfo->coef->decompress_data) (cinfo, data))
212
  if (! (*cinfo->coef->decompress_data) (cinfo, data))
211
    return 0;			/* suspension forced, can do nothing more */
213
    return 0;			/* suspension forced, can do nothing more */
212
214
213
  /* OK, we processed one iMCU row. */
215
  /* OK, we processed one iMCU row. */
(-)a/jpeg/jdarith.c (+761 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * jdarith.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 portable arithmetic entropy decoding routines for JPEG
9
 * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81).
10
 *
11
 * Both sequential and progressive modes are supported in this single module.
12
 *
13
 * Suspension is not currently supported in this module.
14
 */
15
16
#define JPEG_INTERNALS
17
#include "jinclude.h"
18
#include "jpeglib.h"
19
20
21
/* Expanded entropy decoder object for arithmetic decoding. */
22
23
typedef struct {
24
  struct jpeg_entropy_decoder pub; /* public fields */
25
26
  INT32 c;       /* C register, base of coding interval + input bit buffer */
27
  INT32 a;               /* A register, normalized size of coding interval */
28
  int ct;     /* bit shift counter, # of bits left in bit buffer part of C */
29
                                                         /* init: ct = -16 */
30
                                                         /* run: ct = 0..7 */
31
                                                         /* error: ct = -1 */
32
  int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
33
  int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
34
35
  unsigned int restarts_to_go;	/* MCUs left in this restart interval */
36
37
  /* Pointers to statistics areas (these workspaces have image lifespan) */
38
  unsigned char * dc_stats[NUM_ARITH_TBLS];
39
  unsigned char * ac_stats[NUM_ARITH_TBLS];
40
41
  /* Statistics bin for coding with fixed probability 0.5 */
42
  unsigned char fixed_bin[4];
43
} arith_entropy_decoder;
44
45
typedef arith_entropy_decoder * arith_entropy_ptr;
46
47
/* The following two definitions specify the allocation chunk size
48
 * for the statistics area.
49
 * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least
50
 * 49 statistics bins for DC, and 245 statistics bins for AC coding.
51
 *
52
 * We use a compact representation with 1 byte per statistics bin,
53
 * thus the numbers directly represent byte sizes.
54
 * This 1 byte per statistics bin contains the meaning of the MPS
55
 * (more probable symbol) in the highest bit (mask 0x80), and the
56
 * index into the probability estimation state machine table
57
 * in the lower bits (mask 0x7F).
58
 */
59
60
#define DC_STAT_BINS 64
61
#define AC_STAT_BINS 256
62
63
64
LOCAL(int)
65
get_byte (j_decompress_ptr cinfo)
66
/* Read next input byte; we do not support suspension in this module. */
67
{
68
  struct jpeg_source_mgr * src = cinfo->src;
69
70
  if (src->bytes_in_buffer == 0)
71
    if (! (*src->fill_input_buffer) (cinfo))
72
      ERREXIT(cinfo, JERR_CANT_SUSPEND);
73
  src->bytes_in_buffer--;
74
  return GETJOCTET(*src->next_input_byte++);
75
}
76
77
78
/*
79
 * The core arithmetic decoding routine (common in JPEG and JBIG).
80
 * This needs to go as fast as possible.
81
 * Machine-dependent optimization facilities
82
 * are not utilized in this portable implementation.
83
 * However, this code should be fairly efficient and
84
 * may be a good base for further optimizations anyway.
85
 *
86
 * Return value is 0 or 1 (binary decision).
87
 *
88
 * Note: I've changed the handling of the code base & bit
89
 * buffer register C compared to other implementations
90
 * based on the standards layout & procedures.
91
 * While it also contains both the actual base of the
92
 * coding interval (16 bits) and the next-bits buffer,
93
 * the cut-point between these two parts is floating
94
 * (instead of fixed) with the bit shift counter CT.
95
 * Thus, we also need only one (variable instead of
96
 * fixed size) shift for the LPS/MPS decision, and
97
 * we can get away with any renormalization update
98
 * of C (except for new data insertion, of course).
99
 *
100
 * I've also introduced a new scheme for accessing
101
 * the probability estimation state machine table,
102
 * derived from Markus Kuhn's JBIG implementation.
103
 */
104
105
LOCAL(int)
106
arith_decode (j_decompress_ptr cinfo, unsigned char *st)
107
{
108
  register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
109
  register unsigned char nl, nm;
110
  register INT32 qe, temp;
111
  register int sv, data;
112
113
  /* Renormalization & data input per section D.2.6 */
114
  while (e->a < 0x8000L) {
115
    if (--e->ct < 0) {
116
      /* Need to fetch next data byte */
117
      if (cinfo->unread_marker)
118
	data = 0;		/* stuff zero data */
119
      else {
120
	data = get_byte(cinfo);	/* read next input byte */
121
	if (data == 0xFF) {	/* zero stuff or marker code */
122
	  do data = get_byte(cinfo);
123
	  while (data == 0xFF);	/* swallow extra 0xFF bytes */
124
	  if (data == 0)
125
	    data = 0xFF;	/* discard stuffed zero byte */
126
	  else {
127
	    /* Note: Different from the Huffman decoder, hitting
128
	     * a marker while processing the compressed data
129
	     * segment is legal in arithmetic coding.
130
	     * The convention is to supply zero data
131
	     * then until decoding is complete.
132
	     */
133
	    cinfo->unread_marker = data;
134
	    data = 0;
135
	  }
136
	}
137
      }
138
      e->c = (e->c << 8) | data; /* insert data into C register */
139
      if ((e->ct += 8) < 0)	 /* update bit shift counter */
140
	/* Need more initial bytes */
141
	if (++e->ct == 0)
142
	  /* Got 2 initial bytes -> re-init A and exit loop */
143
	  e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */
144
    }
145
    e->a <<= 1;
146
  }
147
148
  /* Fetch values from our compact representation of Table D.2:
149
   * Qe values and probability estimation state machine
150
   */
151
  sv = *st;
152
  qe = jpeg_aritab[sv & 0x7F];	/* => Qe_Value */
153
  nl = qe & 0xFF; qe >>= 8;	/* Next_Index_LPS + Switch_MPS */
154
  nm = qe & 0xFF; qe >>= 8;	/* Next_Index_MPS */
155
156
  /* Decode & estimation procedures per sections D.2.4 & D.2.5 */
157
  temp = e->a - qe;
158
  e->a = temp;
159
  temp <<= e->ct;
160
  if (e->c >= temp) {
161
    e->c -= temp;
162
    /* Conditional LPS (less probable symbol) exchange */
163
    if (e->a < qe) {
164
      e->a = qe;
165
      *st = (sv & 0x80) ^ nm;	/* Estimate_after_MPS */
166
    } else {
167
      e->a = qe;
168
      *st = (sv & 0x80) ^ nl;	/* Estimate_after_LPS */
169
      sv ^= 0x80;		/* Exchange LPS/MPS */
170
    }
171
  } else if (e->a < 0x8000L) {
172
    /* Conditional MPS (more probable symbol) exchange */
173
    if (e->a < qe) {
174
      *st = (sv & 0x80) ^ nl;	/* Estimate_after_LPS */
175
      sv ^= 0x80;		/* Exchange LPS/MPS */
176
    } else {
177
      *st = (sv & 0x80) ^ nm;	/* Estimate_after_MPS */
178
    }
179
  }
180
181
  return sv >> 7;
182
}
183
184
185
/*
186
 * Check for a restart marker & resynchronize decoder.
187
 */
188
189
LOCAL(void)
190
process_restart (j_decompress_ptr cinfo)
191
{
192
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
193
  int ci;
194
  jpeg_component_info * compptr;
195
196
  /* Advance past the RSTn marker */
197
  if (! (*cinfo->marker->read_restart_marker) (cinfo))
198
    ERREXIT(cinfo, JERR_CANT_SUSPEND);
199
200
  /* Re-initialize statistics areas */
201
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
202
    compptr = cinfo->cur_comp_info[ci];
203
    if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
204
      MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);
205
      /* Reset DC predictions to 0 */
206
      entropy->last_dc_val[ci] = 0;
207
      entropy->dc_context[ci] = 0;
208
    }
209
    if (! cinfo->progressive_mode || cinfo->Ss) {
210
      MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);
211
    }
212
  }
213
214
  /* Reset arithmetic decoding variables */
215
  entropy->c = 0;
216
  entropy->a = 0;
217
  entropy->ct = -16;	/* force reading 2 initial bytes to fill C */
218
219
  /* Reset restart counter */
220
  entropy->restarts_to_go = cinfo->restart_interval;
221
}
222
223
224
/*
225
 * Arithmetic MCU decoding.
226
 * Each of these routines decodes and returns one MCU's worth of
227
 * arithmetic-compressed coefficients.
228
 * The coefficients are reordered from zigzag order into natural array order,
229
 * but are not dequantized.
230
 *
231
 * The i'th block of the MCU is stored into the block pointed to by
232
 * MCU_data[i].  WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER.
233
 */
234
235
/*
236
 * MCU decoding for DC initial scan (either spectral selection,
237
 * or first pass of successive approximation).
238
 */
239
240
METHODDEF(boolean)
241
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
242
{
243
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
244
  JBLOCKROW block;
245
  unsigned char *st;
246
  int blkn, ci, tbl, sign;
247
  int v, m;
248
249
  /* Process restart marker if needed */
250
  if (cinfo->restart_interval) {
251
    if (entropy->restarts_to_go == 0)
252
      process_restart(cinfo);
253
    entropy->restarts_to_go--;
254
  }
255
256
  if (entropy->ct == -1) return TRUE;	/* if error do nothing */
257
258
  /* Outer loop handles each block in the MCU */
259
260
  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
261
    block = MCU_data[blkn];
262
    ci = cinfo->MCU_membership[blkn];
263
    tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
264
265
    /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */
266
267
    /* Table F.4: Point to statistics bin S0 for DC coefficient coding */
268
    st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
269
270
    /* Figure F.19: Decode_DC_DIFF */
271
    if (arith_decode(cinfo, st) == 0)
272
      entropy->dc_context[ci] = 0;
273
    else {
274
      /* Figure F.21: Decoding nonzero value v */
275
      /* Figure F.22: Decoding the sign of v */
276
      sign = arith_decode(cinfo, st + 1);
277
      st += 2; st += sign;
278
      /* Figure F.23: Decoding the magnitude category of v */
279
      if ((m = arith_decode(cinfo, st)) != 0) {
280
	st = entropy->dc_stats[tbl] + 20;	/* Table F.4: X1 = 20 */
281
	while (arith_decode(cinfo, st)) {
282
	  if ((m <<= 1) == 0x8000) {
283
	    WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
284
	    entropy->ct = -1;			/* magnitude overflow */
285
	    return TRUE;
286
	  }
287
	  st += 1;
288
	}
289
      }
290
      /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
291
      if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
292
	entropy->dc_context[ci] = 0;		   /* zero diff category */
293
      else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
294
	entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
295
      else
296
	entropy->dc_context[ci] = 4 + (sign * 4);  /* small diff category */
297
      v = m;
298
      /* Figure F.24: Decoding the magnitude bit pattern of v */
299
      st += 14;
300
      while (m >>= 1)
301
	if (arith_decode(cinfo, st)) v |= m;
302
      v += 1; if (sign) v = -v;
303
      entropy->last_dc_val[ci] += v;
304
    }
305
306
    /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */
307
    (*block)[0] = (JCOEF) (entropy->last_dc_val[ci] << cinfo->Al);
308
  }
309
310
  return TRUE;
311
}
312
313
314
/*
315
 * MCU decoding for AC initial scan (either spectral selection,
316
 * or first pass of successive approximation).
317
 */
318
319
METHODDEF(boolean)
320
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
321
{
322
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
323
  JBLOCKROW block;
324
  unsigned char *st;
325
  int tbl, sign, k;
326
  int v, m;
327
328
  /* Process restart marker if needed */
329
  if (cinfo->restart_interval) {
330
    if (entropy->restarts_to_go == 0)
331
      process_restart(cinfo);
332
    entropy->restarts_to_go--;
333
  }
334
335
  if (entropy->ct == -1) return TRUE;	/* if error do nothing */
336
337
  /* There is always only one block per MCU */
338
  block = MCU_data[0];
339
  tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
340
341
  /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
342
343
  /* Figure F.20: Decode_AC_coefficients */
344
  for (k = cinfo->Ss; k <= cinfo->Se; k++) {
345
    st = entropy->ac_stats[tbl] + 3 * (k - 1);
346
    if (arith_decode(cinfo, st)) break;		/* EOB flag */
347
    while (arith_decode(cinfo, st + 1) == 0) {
348
      st += 3; k++;
349
      if (k > cinfo->Se) {
350
	WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
351
	entropy->ct = -1;			/* spectral overflow */
352
	return TRUE;
353
      }
354
    }
355
    /* Figure F.21: Decoding nonzero value v */
356
    /* Figure F.22: Decoding the sign of v */
357
    sign = arith_decode(cinfo, entropy->fixed_bin);
358
    st += 2;
359
    /* Figure F.23: Decoding the magnitude category of v */
360
    if ((m = arith_decode(cinfo, st)) != 0) {
361
      if (arith_decode(cinfo, st)) {
362
	m <<= 1;
363
	st = entropy->ac_stats[tbl] +
364
	     (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
365
	while (arith_decode(cinfo, st)) {
366
	  if ((m <<= 1) == 0x8000) {
367
	    WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
368
	    entropy->ct = -1;			/* magnitude overflow */
369
	    return TRUE;
370
	  }
371
	  st += 1;
372
	}
373
      }
374
    }
375
    v = m;
376
    /* Figure F.24: Decoding the magnitude bit pattern of v */
377
    st += 14;
378
    while (m >>= 1)
379
      if (arith_decode(cinfo, st)) v |= m;
380
    v += 1; if (sign) v = -v;
381
    /* Scale and output coefficient in natural (dezigzagged) order */
382
    (*block)[jpeg_natural_order[k]] = (JCOEF) (v << cinfo->Al);
383
  }
384
385
  return TRUE;
386
}
387
388
389
/*
390
 * MCU decoding for DC successive approximation refinement scan.
391
 */
392
393
METHODDEF(boolean)
394
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
395
{
396
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
397
  unsigned char *st;
398
  int p1, blkn;
399
400
  /* Process restart marker if needed */
401
  if (cinfo->restart_interval) {
402
    if (entropy->restarts_to_go == 0)
403
      process_restart(cinfo);
404
    entropy->restarts_to_go--;
405
  }
406
407
  st = entropy->fixed_bin;	/* use fixed probability estimation */
408
  p1 = 1 << cinfo->Al;		/* 1 in the bit position being coded */
409
410
  /* Outer loop handles each block in the MCU */
411
412
  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
413
    /* Encoded data is simply the next bit of the two's-complement DC value */
414
    if (arith_decode(cinfo, st))
415
      MCU_data[blkn][0][0] |= p1;
416
  }
417
418
  return TRUE;
419
}
420
421
422
/*
423
 * MCU decoding for AC successive approximation refinement scan.
424
 */
425
426
METHODDEF(boolean)
427
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
428
{
429
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
430
  JBLOCKROW block;
431
  JCOEFPTR thiscoef;
432
  unsigned char *st;
433
  int tbl, k, kex;
434
  int p1, m1;
435
436
  /* Process restart marker if needed */
437
  if (cinfo->restart_interval) {
438
    if (entropy->restarts_to_go == 0)
439
      process_restart(cinfo);
440
    entropy->restarts_to_go--;
441
  }
442
443
  if (entropy->ct == -1) return TRUE;	/* if error do nothing */
444
445
  /* There is always only one block per MCU */
446
  block = MCU_data[0];
447
  tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
448
449
  p1 = 1 << cinfo->Al;		/* 1 in the bit position being coded */
450
  m1 = (-1) << cinfo->Al;	/* -1 in the bit position being coded */
451
452
  /* Establish EOBx (previous stage end-of-block) index */
453
  for (kex = cinfo->Se; kex > 0; kex--)
454
    if ((*block)[jpeg_natural_order[kex]]) break;
455
456
  for (k = cinfo->Ss; k <= cinfo->Se; k++) {
457
    st = entropy->ac_stats[tbl] + 3 * (k - 1);
458
    if (k > kex)
459
      if (arith_decode(cinfo, st)) break;	/* EOB flag */
460
    for (;;) {
461
      thiscoef = *block + jpeg_natural_order[k];
462
      if (*thiscoef) {				/* previously nonzero coef */
463
	if (arith_decode(cinfo, st + 2)) {
464
	  if (*thiscoef < 0)
465
	    *thiscoef += m1;
466
	  else
467
	    *thiscoef += p1;
468
	}
469
	break;
470
      }
471
      if (arith_decode(cinfo, st + 1)) {	/* newly nonzero coef */
472
	if (arith_decode(cinfo, entropy->fixed_bin))
473
	  *thiscoef = m1;
474
	else
475
	  *thiscoef = p1;
476
	break;
477
      }
478
      st += 3; k++;
479
      if (k > cinfo->Se) {
480
	WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
481
	entropy->ct = -1;			/* spectral overflow */
482
	return TRUE;
483
      }
484
    }
485
  }
486
487
  return TRUE;
488
}
489
490
491
/*
492
 * Decode one MCU's worth of arithmetic-compressed coefficients.
493
 */
494
495
METHODDEF(boolean)
496
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
497
{
498
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
499
  jpeg_component_info * compptr;
500
  JBLOCKROW block;
501
  unsigned char *st;
502
  int blkn, ci, tbl, sign, k;
503
  int v, m;
504
505
  /* Process restart marker if needed */
506
  if (cinfo->restart_interval) {
507
    if (entropy->restarts_to_go == 0)
508
      process_restart(cinfo);
509
    entropy->restarts_to_go--;
510
  }
511
512
  if (entropy->ct == -1) return TRUE;	/* if error do nothing */
513
514
  /* Outer loop handles each block in the MCU */
515
516
  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
517
    block = MCU_data[blkn];
518
    ci = cinfo->MCU_membership[blkn];
519
    compptr = cinfo->cur_comp_info[ci];
520
521
    /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */
522
523
    tbl = compptr->dc_tbl_no;
524
525
    /* Table F.4: Point to statistics bin S0 for DC coefficient coding */
526
    st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
527
528
    /* Figure F.19: Decode_DC_DIFF */
529
    if (arith_decode(cinfo, st) == 0)
530
      entropy->dc_context[ci] = 0;
531
    else {
532
      /* Figure F.21: Decoding nonzero value v */
533
      /* Figure F.22: Decoding the sign of v */
534
      sign = arith_decode(cinfo, st + 1);
535
      st += 2; st += sign;
536
      /* Figure F.23: Decoding the magnitude category of v */
537
      if ((m = arith_decode(cinfo, st)) != 0) {
538
	st = entropy->dc_stats[tbl] + 20;	/* Table F.4: X1 = 20 */
539
	while (arith_decode(cinfo, st)) {
540
	  if ((m <<= 1) == 0x8000) {
541
	    WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
542
	    entropy->ct = -1;			/* magnitude overflow */
543
	    return TRUE;
544
	  }
545
	  st += 1;
546
	}
547
      }
548
      /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
549
      if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
550
	entropy->dc_context[ci] = 0;		   /* zero diff category */
551
      else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
552
	entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
553
      else
554
	entropy->dc_context[ci] = 4 + (sign * 4);  /* small diff category */
555
      v = m;
556
      /* Figure F.24: Decoding the magnitude bit pattern of v */
557
      st += 14;
558
      while (m >>= 1)
559
	if (arith_decode(cinfo, st)) v |= m;
560
      v += 1; if (sign) v = -v;
561
      entropy->last_dc_val[ci] += v;
562
    }
563
564
    (*block)[0] = (JCOEF) entropy->last_dc_val[ci];
565
566
    /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
567
568
    tbl = compptr->ac_tbl_no;
569
570
    /* Figure F.20: Decode_AC_coefficients */
571
    for (k = 1; k <= DCTSIZE2 - 1; k++) {
572
      st = entropy->ac_stats[tbl] + 3 * (k - 1);
573
      if (arith_decode(cinfo, st)) break;	/* EOB flag */
574
      while (arith_decode(cinfo, st + 1) == 0) {
575
	st += 3; k++;
576
	if (k > DCTSIZE2 - 1) {
577
	  WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
578
	  entropy->ct = -1;			/* spectral overflow */
579
	  return TRUE;
580
	}
581
      }
582
      /* Figure F.21: Decoding nonzero value v */
583
      /* Figure F.22: Decoding the sign of v */
584
      sign = arith_decode(cinfo, entropy->fixed_bin);
585
      st += 2;
586
      /* Figure F.23: Decoding the magnitude category of v */
587
      if ((m = arith_decode(cinfo, st)) != 0) {
588
	if (arith_decode(cinfo, st)) {
589
	  m <<= 1;
590
	  st = entropy->ac_stats[tbl] +
591
	       (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
592
	  while (arith_decode(cinfo, st)) {
593
	    if ((m <<= 1) == 0x8000) {
594
	      WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
595
	      entropy->ct = -1;			/* magnitude overflow */
596
	      return TRUE;
597
	    }
598
	    st += 1;
599
	  }
600
	}
601
      }
602
      v = m;
603
      /* Figure F.24: Decoding the magnitude bit pattern of v */
604
      st += 14;
605
      while (m >>= 1)
606
	if (arith_decode(cinfo, st)) v |= m;
607
      v += 1; if (sign) v = -v;
608
      (*block)[jpeg_natural_order[k]] = (JCOEF) v;
609
    }
610
  }
611
612
  return TRUE;
613
}
614
615
616
/*
617
 * Initialize for an arithmetic-compressed scan.
618
 */
619
620
METHODDEF(void)
621
start_pass (j_decompress_ptr cinfo)
622
{
623
  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
624
  int ci, tbl;
625
  jpeg_component_info * compptr;
626
627
  if (cinfo->progressive_mode) {
628
    /* Validate progressive scan parameters */
629
    if (cinfo->Ss == 0) {
630
      if (cinfo->Se != 0)
631
	goto bad;
632
    } else {
633
      /* need not check Ss/Se < 0 since they came from unsigned bytes */
634
      if (cinfo->Se < cinfo->Ss || cinfo->Se > DCTSIZE2 - 1)
635
	goto bad;
636
      /* AC scans may have only one component */
637
      if (cinfo->comps_in_scan != 1)
638
	goto bad;
639
    }
640
    if (cinfo->Ah != 0) {
641
      /* Successive approximation refinement scan: must have Al = Ah-1. */
642
      if (cinfo->Ah-1 != cinfo->Al)
643
	goto bad;
644
    }
645
    if (cinfo->Al > 13) {	/* need not check for < 0 */
646
      bad:
647
      ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
648
	       cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
649
    }
650
    /* Update progression status, and verify that scan order is legal.
651
     * Note that inter-scan inconsistencies are treated as warnings
652
     * not fatal errors ... not clear if this is right way to behave.
653
     */
654
    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
655
      int coefi, cindex = cinfo->cur_comp_info[ci]->component_index;
656
      int *coef_bit_ptr = & cinfo->coef_bits[cindex][0];
657
      if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
658
	WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
659
      for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
660
	int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
661
	if (cinfo->Ah != expected)
662
	  WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
663
	coef_bit_ptr[coefi] = cinfo->Al;
664
      }
665
    }
666
    /* Select MCU decoding routine */
667
    if (cinfo->Ah == 0) {
668
      if (cinfo->Ss == 0)
669
	entropy->pub.decode_mcu = decode_mcu_DC_first;
670
      else
671
	entropy->pub.decode_mcu = decode_mcu_AC_first;
672
    } else {
673
      if (cinfo->Ss == 0)
674
	entropy->pub.decode_mcu = decode_mcu_DC_refine;
675
      else
676
	entropy->pub.decode_mcu = decode_mcu_AC_refine;
677
    }
678
  } else {
679
    /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
680
     * This ought to be an error condition, but we make it a warning.
681
     */
682
    if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 ||
683
	(cinfo->Se < DCTSIZE2 && cinfo->Se != DCTSIZE2 - 1))
684
      WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
685
    /* Select MCU decoding routine */
686
    entropy->pub.decode_mcu = decode_mcu;
687
  }
688
689
  /* Allocate & initialize requested statistics areas */
690
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
691
    compptr = cinfo->cur_comp_info[ci];
692
    if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
693
      tbl = compptr->dc_tbl_no;
694
      if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
695
	ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
696
      if (entropy->dc_stats[tbl] == NULL)
697
	entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
698
	  ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);
699
      MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
700
      /* Initialize DC predictions to 0 */
701
      entropy->last_dc_val[ci] = 0;
702
      entropy->dc_context[ci] = 0;
703
    }
704
    if (! cinfo->progressive_mode || cinfo->Ss) {
705
      tbl = compptr->ac_tbl_no;
706
      if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
707
	ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
708
      if (entropy->ac_stats[tbl] == NULL)
709
	entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
710
	  ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);
711
      MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
712
    }
713
  }
714
715
  /* Initialize arithmetic decoding variables */
716
  entropy->c = 0;
717
  entropy->a = 0;
718
  entropy->ct = -16;	/* force reading 2 initial bytes to fill C */
719
720
  /* Initialize restart counter */
721
  entropy->restarts_to_go = cinfo->restart_interval;
722
}
723
724
725
/*
726
 * Module initialization routine for arithmetic entropy decoding.
727
 */
728
729
GLOBAL(void)
730
jinit_arith_decoder (j_decompress_ptr cinfo)
731
{
732
  arith_entropy_ptr entropy;
733
  int i;
734
735
  entropy = (arith_entropy_ptr)
736
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
737
				SIZEOF(arith_entropy_decoder));
738
  cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
739
  entropy->pub.start_pass = start_pass;
740
741
  /* Mark tables unallocated */
742
  for (i = 0; i < NUM_ARITH_TBLS; i++) {
743
    entropy->dc_stats[i] = NULL;
744
    entropy->ac_stats[i] = NULL;
745
  }
746
747
  /* Initialize index for fixed probability estimation */
748
  entropy->fixed_bin[0] = 113;
749
750
  if (cinfo->progressive_mode) {
751
    /* Create progression status table */
752
    int *coef_bit_ptr, ci;
753
    cinfo->coef_bits = (int (*)[DCTSIZE2])
754
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
755
				  cinfo->num_components*DCTSIZE2*SIZEOF(int));
756
    coef_bit_ptr = & cinfo->coef_bits[0][0];
757
    for (ci = 0; ci < cinfo->num_components; ci++) 
758
      for (i = 0; i < DCTSIZE2; i++)
759
	*coef_bit_ptr++ = -1;
760
  }
761
}
(-)a/jpeg/jdatadst.c (-57 / +120 lines)
Line     Link Here 
 Lines 1-44    Link Here 
1
/*
1
/*
2
 * jdatadst.c
2
 * jdatadst.c
3
 *
3
 *
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
5
 * Modified 2009 by Guido Vollbeding.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains compression data destination routines for the case of
9
 * This file contains compression data destination routines for the case of
9
 * emitting JPEG data to a file (or any stdio stream).  While these routines
10
 * emitting JPEG data to memory or to a file (or any stdio stream).
10
 * are sufficient for most applications, some will want to use a different
11
 * While these routines are sufficient for most applications,
11
 * destination manager.
12
 * some will want to use a different destination manager.
12
 * IMPORTANT: we assume that fwrite() will correctly transcribe an array of
13
 * IMPORTANT: we assume that fwrite() will correctly transcribe an array of
13
 * JOCTETs into 8-bit-wide elements on external storage.  If char is wider
14
 * JOCTETs into 8-bit-wide elements on external storage.  If char is wider
14
 * than 8 bits on your machine, you may need to do some tweaking.
15
 * than 8 bits on your machine, you may need to do some tweaking.
15
 */
16
 */
16
17
17
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
18
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
18
#include "jinclude.h"
19
#include "jinclude.h"
19
#include "jpeglib.h"
20
#include "jpeglib.h"
20
#include "jerror.h"
21
#include "jerror.h"
21
22
23
#ifndef HAVE_STDLIB_H		/* <stdlib.h> should declare malloc(),free() */
24
extern void * malloc JPP((size_t size));
25
extern void free JPP((void *ptr));
26
#endif
27
22
28
23
/* Expanded data destination object for stdio output */
29
/* Expanded data destination object for stdio output */
24
30
25
typedef struct {
31
typedef struct {
26
  struct jpeg_destination_mgr pub; /* public fields */
32
  struct jpeg_destination_mgr pub; /* public fields */
27
33
28
  FILE * outfile;		/* target stream */
34
  FILE * outfile;		/* target stream */
29
  JOCTET * buffer;		/* start of buffer */
35
  JOCTET * buffer;		/* start of buffer */
30
} my_destination_mgr;
36
} my_destination_mgr;
31
37
32
typedef my_destination_mgr * my_dest_ptr;
38
typedef my_destination_mgr * my_dest_ptr;
33
39
34
#define OUTPUT_BUF_SIZE  4096	/* choose an efficiently fwrite'able size */
40
#define OUTPUT_BUF_SIZE  4096	/* choose an efficiently fwrite'able size */
35
41
36
42
43
#if JPEG_LIB_VERSION >= 80
44
/* Expanded data destination object for memory output */
45
46
typedef struct {
47
  struct jpeg_destination_mgr pub; /* public fields */
48
49
  unsigned char ** outbuffer;	/* target buffer */
50
  unsigned long * outsize;
51
  unsigned char * newbuffer;	/* newly allocated buffer */
52
  JOCTET * buffer;		/* start of buffer */
53
  size_t bufsize;
54
} my_mem_destination_mgr;
55
56
typedef my_mem_destination_mgr * my_mem_dest_ptr;
57
#endif
58
59
37
/*
60
/*
38
 * Initialize destination --- called by jpeg_start_compress
61
 * Initialize destination --- called by jpeg_start_compress
39
 * before any data is actually written.
62
 * before any data is actually written.
40
 */
63
 */
41
64
42
METHODDEF(void)
65
METHODDEF(void)
43
init_destination (j_compress_ptr cinfo)
66
init_destination (j_compress_ptr cinfo)
44
{
67
{
 Lines 48-63   init_destination (j_compress_ptr cinfo) Link Here 
48
  dest->buffer = (JOCTET *)
71
  dest->buffer = (JOCTET *)
49
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
72
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
50
				  OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
73
				  OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
51
74
52
  dest->pub.next_output_byte = dest->buffer;
75
  dest->pub.next_output_byte = dest->buffer;
53
  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
76
  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
54
}
77
}
55
78
79
#if JPEG_LIB_VERSION >= 80
80
METHODDEF(void)
81
init_mem_destination (j_compress_ptr cinfo)
82
{
83
  /* no work necessary here */
84
}
85
#endif
86
56
87
57
/*
88
/*
58
 * Empty the output buffer --- called whenever buffer fills up.
89
 * Empty the output buffer --- called whenever buffer fills up.
59
 *
90
 *
60
 * In typical applications, this should write the entire output buffer
91
 * In typical applications, this should write the entire output buffer
61
 * (ignoring the current state of next_output_byte & free_in_buffer),
92
 * (ignoring the current state of next_output_byte & free_in_buffer),
62
 * reset the pointer & count to the start of the buffer, and return TRUE
93
 * reset the pointer & count to the start of the buffer, and return TRUE
63
 * indicating that the buffer has been dumped.
94
 * indicating that the buffer has been dumped.
 Lines 87-102   empty_output_buffer (j_compress_ptr cinf Link Here 
87
    ERREXIT(cinfo, JERR_FILE_WRITE);
118
    ERREXIT(cinfo, JERR_FILE_WRITE);
88
119
89
  dest->pub.next_output_byte = dest->buffer;
120
  dest->pub.next_output_byte = dest->buffer;
90
  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
121
  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
91
122
92
  return TRUE;
123
  return TRUE;
93
}
124
}
94
125
126
#if JPEG_LIB_VERSION >= 80
127
METHODDEF(boolean)
128
empty_mem_output_buffer (j_compress_ptr cinfo)
129
{
130
  size_t nextsize;
131
  JOCTET * nextbuffer;
132
  my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;
133
134
  /* Try to allocate new buffer with double size */
135
  nextsize = dest->bufsize * 2;
136
  nextbuffer = malloc(nextsize);
137
138
  if (nextbuffer == NULL)
139
    ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
140
141
  MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
142
143
  if (dest->newbuffer != NULL)
144
    free(dest->newbuffer);
145
146
  dest->newbuffer = nextbuffer;
147
148
  dest->pub.next_output_byte = nextbuffer + dest->bufsize;
149
  dest->pub.free_in_buffer = dest->bufsize;
150
151
  dest->buffer = nextbuffer;
152
  dest->bufsize = nextsize;
153
154
  return TRUE;
155
}
156
#endif
157
95
158
96
/*
159
/*
97
 * Terminate destination --- called by jpeg_finish_compress
160
 * Terminate destination --- called by jpeg_finish_compress
98
 * after all data has been written.  Usually needs to flush buffer.
161
 * after all data has been written.  Usually needs to flush buffer.
99
 *
162
 *
100
 * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
163
 * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
101
 * application must deal with any cleanup that should happen even
164
 * application must deal with any cleanup that should happen even
102
 * for error exit.
165
 * for error exit.
 Lines 114-129   term_destination (j_compress_ptr cinfo) Link Here 
114
      ERREXIT(cinfo, JERR_FILE_WRITE);
177
      ERREXIT(cinfo, JERR_FILE_WRITE);
115
  }
178
  }
116
  fflush(dest->outfile);
179
  fflush(dest->outfile);
117
  /* Make sure we wrote the output file OK */
180
  /* Make sure we wrote the output file OK */
118
  if (ferror(dest->outfile))
181
  if (ferror(dest->outfile))
119
    ERREXIT(cinfo, JERR_FILE_WRITE);
182
    ERREXIT(cinfo, JERR_FILE_WRITE);
120
}
183
}
121
184
185
#if JPEG_LIB_VERSION >= 80
186
METHODDEF(void)
187
term_mem_destination (j_compress_ptr cinfo)
188
{
189
  my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;
190
191
  *dest->outbuffer = dest->buffer;
192
  *dest->outsize = dest->bufsize - dest->pub.free_in_buffer;
193
}
194
#endif
195
122
196
123
/*
197
/*
124
 * Prepare for output to a stdio stream.
198
 * Prepare for output to a stdio stream.
125
 * The caller must have already opened the stream, and is responsible
199
 * The caller must have already opened the stream, and is responsible
126
 * for closing it after finishing compression.
200
 * for closing it after finishing compression.
127
 */
201
 */
128
202
129
GLOBAL(void)
203
GLOBAL(void)
 Lines 145-214   jpeg_stdio_dest (j_compress_ptr cinfo, F Link Here 
145
219
146
  dest = (my_dest_ptr) cinfo->dest;
220
  dest = (my_dest_ptr) cinfo->dest;
147
  dest->pub.init_destination = init_destination;
221
  dest->pub.init_destination = init_destination;
148
  dest->pub.empty_output_buffer = empty_output_buffer;
222
  dest->pub.empty_output_buffer = empty_output_buffer;
149
  dest->pub.term_destination = term_destination;
223
  dest->pub.term_destination = term_destination;
150
  dest->outfile = outfile;
224
  dest->outfile = outfile;
151
}
225
}
152
226
153
/*
227
154
 * term_destination_file_close --- called by jpeg_finish_compress
228
#if JPEG_LIB_VERSION >= 80
155
 * after all data has been written.  Usually needs to flush buffer.
229
/*
156
 * also will need to close file
230
 * Prepare for output to a memory buffer.
157
 * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
231
 * The caller may supply an own initial buffer with appropriate size.
158
 * application must deal with any cleanup that should happen even
232
 * Otherwise, or when the actual data output exceeds the given size,
159
 * for error exit.
233
 * the library adapts the buffer size as necessary.
160
 */
234
 * The standard library functions malloc/free are used for allocating
161
235
 * larger memory, so the buffer is available to the application after
162
METHODDEF(void)
236
 * finishing compression, and then the application is responsible for
163
term_destination_file_close(j_compress_ptr cinfo)
237
 * freeing the requested memory.
164
{
238
 */
165
  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
166
  size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
167
168
  /* Write any data remaining in the buffer */
169
  if (datacount > 0) {
170
    if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
171
      ERREXIT(cinfo, JERR_FILE_WRITE);
172
  }
173
  fflush(dest->outfile);
174
  
175
  /* Make sure we wrote the output file OK */
176
  if (ferror(dest->outfile))
177
    ERREXIT(cinfo, JERR_FILE_WRITE);
178
  else
179
      fclose(dest->outfile);
180
}
181
182
183
184
185
186
/*
187
 * Prepare for output to a file from a char *
188
 * The caller is responsible
189
 * for closing it after finishing compression.
190
 */
191
239
192
GLOBAL(void)
240
GLOBAL(void)
193
jpeg_file_dest (j_compress_ptr cinfo, char * outfile)
241
jpeg_mem_dest (j_compress_ptr cinfo,
194
{
242
	       unsigned char ** outbuffer, unsigned long * outsize)
195
  my_dest_ptr dest;
243
{
244
  my_mem_dest_ptr dest;
245
246
  if (outbuffer == NULL || outsize == NULL)	/* sanity check */
247
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
196
248
197
  /* The destination object is made permanent so that multiple JPEG images
249
  /* The destination object is made permanent so that multiple JPEG images
198
   * can be written to the same file without re-executing jpeg_stdio_dest.
250
   * can be written to the same buffer without re-executing jpeg_mem_dest.
199
   * This makes it dangerous to use this manager and a different destination
200
   * manager serially with the same JPEG object, because their private object
201
   * sizes may be different.  Caveat programmer.
202
   */
251
   */
203
  if (cinfo->dest == NULL) {	/* first time for this JPEG object? */
252
  if (cinfo->dest == NULL) {	/* first time for this JPEG object? */
204
    cinfo->dest = (struct jpeg_destination_mgr *)
253
    cinfo->dest = (struct jpeg_destination_mgr *)
205
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
254
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
206
				  SIZEOF(my_destination_mgr));
255
				  SIZEOF(my_mem_destination_mgr));
207
  }
256
  }
208
257
209
  dest = (my_dest_ptr) cinfo->dest;
258
  dest = (my_mem_dest_ptr) cinfo->dest;
210
  dest->pub.init_destination = init_destination;
259
  dest->pub.init_destination = init_mem_destination;
211
  dest->pub.empty_output_buffer = empty_output_buffer;
260
  dest->pub.empty_output_buffer = empty_mem_output_buffer;
212
  dest->pub.term_destination = term_destination_file_close;
261
  dest->pub.term_destination = term_mem_destination;
213
  dest->outfile = fopen(outfile,"wb");
262
  dest->outbuffer = outbuffer;
214
}
263
  dest->outsize = outsize;
264
  dest->newbuffer = NULL;
265
266
  if (*outbuffer == NULL || *outsize == 0) {
267
    /* Allocate initial buffer */
268
    dest->newbuffer = *outbuffer = malloc(OUTPUT_BUF_SIZE);
269
    if (dest->newbuffer == NULL)
270
      ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
271
    *outsize = OUTPUT_BUF_SIZE;
272
  }
273
274
  dest->pub.next_output_byte = dest->buffer = *outbuffer;
275
  dest->pub.free_in_buffer = dest->bufsize = *outsize;
276
}
277
#endif
(-)a/jpeg/jdatasrc.c (-11 / +79 lines)
Line     Link Here 
 Lines 1-19    Link Here 
1
/*
1
/*
2
 * jdatasrc.c
2
 * jdatasrc.c
3
 *
3
 *
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
5
 * Modified 2009-2010 by Guido Vollbeding.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains decompression data source routines for the case of
9
 * This file contains decompression data source routines for the case of
9
 * reading JPEG data from a file (or any stdio stream).  While these routines
10
 * reading JPEG data from memory or from a file (or any stdio stream).
10
 * are sufficient for most applications, some will want to use a different
11
 * While these routines are sufficient for most applications,
11
 * source manager.
12
 * some will want to use a different source manager.
12
 * IMPORTANT: we assume that fread() will correctly transcribe an array of
13
 * IMPORTANT: we assume that fread() will correctly transcribe an array of
13
 * JOCTETs from 8-bit-wide elements on external storage.  If char is wider
14
 * JOCTETs from 8-bit-wide elements on external storage.  If char is wider
14
 * than 8 bits on your machine, you may need to do some tweaking.
15
 * than 8 bits on your machine, you may need to do some tweaking.
15
 */
16
 */
16
17
17
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
18
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
18
#include "jinclude.h"
19
#include "jinclude.h"
19
#include "jpeglib.h"
20
#include "jpeglib.h"
 Lines 47-62   init_source (j_decompress_ptr cinfo) Link Here 
47
48
48
  /* We reset the empty-input-file flag for each image,
49
  /* We reset the empty-input-file flag for each image,
49
   * but we don't clear the input buffer.
50
   * but we don't clear the input buffer.
50
   * This is correct behavior for reading a series of images from one source.
51
   * This is correct behavior for reading a series of images from one source.
51
   */
52
   */
52
  src->start_of_file = TRUE;
53
  src->start_of_file = TRUE;
53
}
54
}
54
55
56
#if JPEG_LIB_VERSION >= 80
57
METHODDEF(void)
58
init_mem_source (j_decompress_ptr cinfo)
59
{
60
  /* no work necessary here */
61
}
62
#endif
63
55
64
56
/*
65
/*
57
 * Fill the input buffer --- called whenever buffer is emptied.
66
 * Fill the input buffer --- called whenever buffer is emptied.
58
 *
67
 *
59
 * In typical applications, this should read fresh data into the buffer
68
 * In typical applications, this should read fresh data into the buffer
60
 * (ignoring the current state of next_input_byte & bytes_in_buffer),
69
 * (ignoring the current state of next_input_byte & bytes_in_buffer),
61
 * reset the pointer & count to the start of the buffer, and return TRUE
70
 * reset the pointer & count to the start of the buffer, and return TRUE
62
 * indicating that the buffer has been reloaded.  It is not necessary to
71
 * indicating that the buffer has been reloaded.  It is not necessary to
 Lines 106-155   fill_input_buffer (j_decompress_ptr cinf Link Here 
106
115
107
  src->pub.next_input_byte = src->buffer;
116
  src->pub.next_input_byte = src->buffer;
108
  src->pub.bytes_in_buffer = nbytes;
117
  src->pub.bytes_in_buffer = nbytes;
109
  src->start_of_file = FALSE;
118
  src->start_of_file = FALSE;
110
119
111
  return TRUE;
120
  return TRUE;
112
}
121
}
113
122
123
#if JPEG_LIB_VERSION >= 80
124
METHODDEF(boolean)
125
fill_mem_input_buffer (j_decompress_ptr cinfo)
126
{
127
  static JOCTET mybuffer[4];
128
129
  /* The whole JPEG data is expected to reside in the supplied memory
130
   * buffer, so any request for more data beyond the given buffer size
131
   * is treated as an error.
132
   */
133
  WARNMS(cinfo, JWRN_JPEG_EOF);
134
  /* Insert a fake EOI marker */
135
  mybuffer[0] = (JOCTET) 0xFF;
136
  mybuffer[1] = (JOCTET) JPEG_EOI;
137
138
  cinfo->src->next_input_byte = mybuffer;
139
  cinfo->src->bytes_in_buffer = 2;
140
141
  return TRUE;
142
}
143
#endif
144
114
145
115
/*
146
/*
116
 * Skip data --- used to skip over a potentially large amount of
147
 * Skip data --- used to skip over a potentially large amount of
117
 * uninteresting data (such as an APPn marker).
148
 * uninteresting data (such as an APPn marker).
118
 *
149
 *
119
 * Writers of suspendable-input applications must note that skip_input_data
150
 * Writers of suspendable-input applications must note that skip_input_data
120
 * is not granted the right to give a suspension return.  If the skip extends
151
 * is not granted the right to give a suspension return.  If the skip extends
121
 * beyond the data currently in the buffer, the buffer can be marked empty so
152
 * beyond the data currently in the buffer, the buffer can be marked empty so
122
 * that the next read will cause a fill_input_buffer call that can suspend.
153
 * that the next read will cause a fill_input_buffer call that can suspend.
123
 * Arranging for additional bytes to be discarded before reloading the input
154
 * Arranging for additional bytes to be discarded before reloading the input
124
 * buffer is the application writer's problem.
155
 * buffer is the application writer's problem.
125
 */
156
 */
126
157
127
METHODDEF(void)
158
METHODDEF(void)
128
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
159
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
129
{
160
{
130
  my_src_ptr src = (my_src_ptr) cinfo->src;
161
  struct jpeg_source_mgr * src = cinfo->src;
131
162
132
  /* Just a dumb implementation for now.  Could use fseek() except
163
  /* Just a dumb implementation for now.  Could use fseek() except
133
   * it doesn't work on pipes.  Not clear that being smart is worth
164
   * it doesn't work on pipes.  Not clear that being smart is worth
134
   * any trouble anyway --- large skips are infrequent.
165
   * any trouble anyway --- large skips are infrequent.
135
   */
166
   */
136
  if (num_bytes > 0) {
167
  if (num_bytes > 0) {
137
    while (num_bytes > (long) src->pub.bytes_in_buffer) {
168
    while (num_bytes > (long) src->bytes_in_buffer) {
138
      num_bytes -= (long) src->pub.bytes_in_buffer;
169
      num_bytes -= (long) src->bytes_in_buffer;
139
      (void) fill_input_buffer(cinfo);
170
      (void) (*src->fill_input_buffer) (cinfo);
140
      /* note we assume that fill_input_buffer will never return FALSE,
171
      /* note we assume that fill_input_buffer will never return FALSE,
141
       * so suspension need not be handled.
172
       * so suspension need not be handled.
142
       */
173
       */
143
    }
174
    }
144
    src->pub.next_input_byte += (size_t) num_bytes;
175
    src->next_input_byte += (size_t) num_bytes;
145
    src->pub.bytes_in_buffer -= (size_t) num_bytes;
176
    src->bytes_in_buffer -= (size_t) num_bytes;
146
  }
177
  }
147
}
178
}
148
179
149
180
150
/*
181
/*
151
 * An additional method that can be provided by data source modules is the
182
 * An additional method that can be provided by data source modules is the
152
 * resync_to_restart method for error recovery in the presence of RST markers.
183
 * resync_to_restart method for error recovery in the presence of RST markers.
153
 * For the moment, this source module just uses the default resync method
184
 * For the moment, this source module just uses the default resync method
154
 * provided by the JPEG library.  That method assumes that no backtracking
185
 * provided by the JPEG library.  That method assumes that no backtracking
155
 * is possible.
186
 * is possible.
 Lines 205-212   jpeg_stdio_src (j_decompress_ptr cinfo, Link Here 
205
  src->pub.fill_input_buffer = fill_input_buffer;
236
  src->pub.fill_input_buffer = fill_input_buffer;
206
  src->pub.skip_input_data = skip_input_data;
237
  src->pub.skip_input_data = skip_input_data;
207
  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
238
  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
208
  src->pub.term_source = term_source;
239
  src->pub.term_source = term_source;
209
  src->infile = infile;
240
  src->infile = infile;
210
  src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
241
  src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
211
  src->pub.next_input_byte = NULL; /* until buffer loaded */
242
  src->pub.next_input_byte = NULL; /* until buffer loaded */
212
}
243
}
244
245
246
#if JPEG_LIB_VERSION >= 80
247
/*
248
 * Prepare for input from a supplied memory buffer.
249
 * The buffer must contain the whole JPEG data.
250
 */
251
252
GLOBAL(void)
253
jpeg_mem_src (j_decompress_ptr cinfo,
254
	      unsigned char * inbuffer, unsigned long insize)
255
{
256
  struct jpeg_source_mgr * src;
257
258
  if (inbuffer == NULL || insize == 0)	/* Treat empty input as fatal error */
259
    ERREXIT(cinfo, JERR_INPUT_EMPTY);
260
261
  /* The source object is made permanent so that a series of JPEG images
262
   * can be read from the same buffer by calling jpeg_mem_src only before
263
   * the first one.
264
   */
265
  if (cinfo->src == NULL) {	/* first time for this JPEG object? */
266
    cinfo->src = (struct jpeg_source_mgr *)
267
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
268
				  SIZEOF(struct jpeg_source_mgr));
269
  }
270
271
  src = cinfo->src;
272
  src->init_source = init_mem_source;
273
  src->fill_input_buffer = fill_mem_input_buffer;
274
  src->skip_input_data = skip_input_data;
275
  src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
276
  src->term_source = term_source;
277
  src->bytes_in_buffer = (size_t) insize;
278
  src->next_input_byte = (JOCTET *) inbuffer;
279
}
280
#endif
(-)a/jpeg/jdcoefct.c (-13 / +26 lines)
Line     Link Here 
 Lines 1-27    Link Here 
1
/*
1
/*
2
 * jdcoefct.c
2
 * jdcoefct.c
3
 *
3
 *
4
 * Copyright (C) 1994-1997, Thomas G. Lane.
4
 * Copyright (C) 1994-1997, Thomas G. Lane.
5
 * Copyright (C) 2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains the coefficient buffer controller for decompression.
9
 * This file contains the coefficient buffer controller for decompression.
9
 * This controller is the top level of the JPEG decompressor proper.
10
 * This controller is the top level of the JPEG decompressor proper.
10
 * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
11
 * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
11
 *
12
 *
12
 * In buffered-image mode, this controller is the interface between
13
 * In buffered-image mode, this controller is the interface between
13
 * input-oriented processing and output-oriented processing.
14
 * input-oriented processing and output-oriented processing.
14
 * Also, the input side (only) is used when reading a file for transcoding.
15
 * Also, the input side (only) is used when reading a file for transcoding.
15
 */
16
 */
16
17
17
#define JPEG_INTERNALS
18
#define JPEG_INTERNALS
18
#include "jinclude.h"
19
#include "jinclude.h"
19
#include "jpeglib.h"
20
#include "jpeglib.h"
21
#include "jpegcomp.h"
20
22
21
/* Block smoothing is only applicable for progressive JPEG, so: */
23
/* Block smoothing is only applicable for progressive JPEG, so: */
22
#ifndef D_PROGRESSIVE_SUPPORTED
24
#ifndef D_PROGRESSIVE_SUPPORTED
23
#undef BLOCK_SMOOTHING_SUPPORTED
25
#undef BLOCK_SMOOTHING_SUPPORTED
24
#endif
26
#endif
25
27
26
/* Private buffer controller object */
28
/* Private buffer controller object */
27
29
 Lines 42-57   typedef struct { Link Here 
42
   * (On 80x86, the workspace is FAR even though it's not really very big;
44
   * (On 80x86, the workspace is FAR even though it's not really very big;
43
   * this is to keep the module interfaces unchanged when a large coefficient
45
   * this is to keep the module interfaces unchanged when a large coefficient
44
   * buffer is necessary.)
46
   * buffer is necessary.)
45
   * In multi-pass modes, this array points to the current MCU's blocks
47
   * In multi-pass modes, this array points to the current MCU's blocks
46
   * within the virtual arrays; it is used only by the input side.
48
   * within the virtual arrays; it is used only by the input side.
47
   */
49
   */
48
  JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
50
  JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
49
51
52
  /* Temporary workspace for one MCU */
53
  JCOEF * workspace;
54
50
#ifdef D_MULTISCAN_FILES_SUPPORTED
55
#ifdef D_MULTISCAN_FILES_SUPPORTED
51
  /* In multi-pass modes, we need a virtual block array for each component. */
56
  /* In multi-pass modes, we need a virtual block array for each component. */
52
  jvirt_barray_ptr whole_image[MAX_COMPONENTS];
57
  jvirt_barray_ptr whole_image[MAX_COMPONENTS];
53
#endif
58
#endif
54
59
55
#ifdef BLOCK_SMOOTHING_SUPPORTED
60
#ifdef BLOCK_SMOOTHING_SUPPORTED
56
  /* When doing block smoothing, we latch coefficient Al values here */
61
  /* When doing block smoothing, we latch coefficient Al values here */
57
  int * coef_bits_latch;
62
  int * coef_bits_latch;
 Lines 182-212   decompress_onepass (j_decompress_ptr cin Link Here 
182
	if (! compptr->component_needed) {
187
	if (! compptr->component_needed) {
183
	  blkn += compptr->MCU_blocks;
188
	  blkn += compptr->MCU_blocks;
184
	  continue;
189
	  continue;
185
	}
190
	}
186
	inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
191
	inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
187
	useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
192
	useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
188
						    : compptr->last_col_width;
193
						    : compptr->last_col_width;
189
	output_ptr = output_buf[compptr->component_index] +
194
	output_ptr = output_buf[compptr->component_index] +
190
	  yoffset * compptr->DCT_scaled_size;
195
	  yoffset * compptr->_DCT_scaled_size;
191
	start_col = MCU_col_num * compptr->MCU_sample_width;
196
	start_col = MCU_col_num * compptr->MCU_sample_width;
192
	for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
197
	for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
193
	  if (cinfo->input_iMCU_row < last_iMCU_row ||
198
	  if (cinfo->input_iMCU_row < last_iMCU_row ||
194
	      yoffset+yindex < compptr->last_row_height) {
199
	      yoffset+yindex < compptr->last_row_height) {
195
	    output_col = start_col;
200
	    output_col = start_col;
196
	    for (xindex = 0; xindex < useful_width; xindex++) {
201
	    for (xindex = 0; xindex < useful_width; xindex++) {
197
	      (*inverse_DCT) (cinfo, compptr,
202
	      (*inverse_DCT) (cinfo, compptr,
198
			      (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
203
			      (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
199
			      output_ptr, output_col);
204
			      output_ptr, output_col);
200
	      output_col += compptr->DCT_scaled_size;
205
	      output_col += compptr->_DCT_scaled_size;
201
	    }
206
	    }
202
	  }
207
	  }
203
	  blkn += compptr->MCU_width;
208
	  blkn += compptr->MCU_width;
204
	  output_ptr += compptr->DCT_scaled_size;
209
	  output_ptr += compptr->_DCT_scaled_size;
205
	}
210
	}
206
      }
211
      }
207
    }
212
    }
208
    /* Completed an MCU row, but perhaps not an iMCU row */
213
    /* Completed an MCU row, but perhaps not an iMCU row */
209
    coef->MCU_ctr = 0;
214
    coef->MCU_ctr = 0;
210
  }
215
  }
211
  /* Completed the iMCU row, advance counters for next one */
216
  /* Completed the iMCU row, advance counters for next one */
212
  cinfo->output_iMCU_row++;
217
  cinfo->output_iMCU_row++;
 Lines 357-377   decompress_data (j_decompress_ptr cinfo, Link Here 
357
    /* Loop over all DCT blocks to be processed. */
362
    /* Loop over all DCT blocks to be processed. */
358
    for (block_row = 0; block_row < block_rows; block_row++) {
363
    for (block_row = 0; block_row < block_rows; block_row++) {
359
      buffer_ptr = buffer[block_row];
364
      buffer_ptr = buffer[block_row];
360
      output_col = 0;
365
      output_col = 0;
361
      for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
366
      for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
362
	(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
367
	(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
363
			output_ptr, output_col);
368
			output_ptr, output_col);
364
	buffer_ptr++;
369
	buffer_ptr++;
365
	output_col += compptr->DCT_scaled_size;
370
	output_col += compptr->_DCT_scaled_size;
366
      }
371
      }
367
      output_ptr += compptr->DCT_scaled_size;
372
      output_ptr += compptr->_DCT_scaled_size;
368
    }
373
    }
369
  }
374
  }
370
375
371
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
376
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
372
    return JPEG_ROW_COMPLETED;
377
    return JPEG_ROW_COMPLETED;
373
  return JPEG_SCAN_COMPLETED;
378
  return JPEG_SCAN_COMPLETED;
374
}
379
}
375
380
376
#endif /* D_MULTISCAN_FILES_SUPPORTED */
381
#endif /* D_MULTISCAN_FILES_SUPPORTED */
377
382
 Lines 466-488   decompress_smooth_data (j_decompress_ptr Link Here 
466
  int ci, block_row, block_rows, access_rows;
471
  int ci, block_row, block_rows, access_rows;
467
  JBLOCKARRAY buffer;
472
  JBLOCKARRAY buffer;
468
  JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
473
  JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
469
  JSAMPARRAY output_ptr;
474
  JSAMPARRAY output_ptr;
470
  JDIMENSION output_col;
475
  JDIMENSION output_col;
471
  jpeg_component_info *compptr;
476
  jpeg_component_info *compptr;
472
  inverse_DCT_method_ptr inverse_DCT;
477
  inverse_DCT_method_ptr inverse_DCT;
473
  boolean first_row, last_row;
478
  boolean first_row, last_row;
474
  JBLOCK workspace;
479
  JCOEF * workspace;
475
  int *coef_bits;
480
  int *coef_bits;
476
  JQUANT_TBL *quanttbl;
481
  JQUANT_TBL *quanttbl;
477
  INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
482
  INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
478
  int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
483
  int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
479
  int Al, pred;
484
  int Al, pred;
480
485
486
  /* Keep a local variable to avoid looking it up more than once */
487
  workspace = coef->workspace;
488
481
  /* Force some input to be done if we are getting ahead of the input. */
489
  /* Force some input to be done if we are getting ahead of the input. */
482
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
490
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
483
	 ! cinfo->inputctl->eoi_reached) {
491
	 ! cinfo->inputctl->eoi_reached) {
484
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
492
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
485
      /* If input is working on current scan, we ordinarily want it to
493
      /* If input is working on current scan, we ordinarily want it to
486
       * have completed the current row.  But if input scan is DC,
494
       * have completed the current row.  But if input scan is DC,
487
       * we want it to keep one row ahead so that next block row's DC
495
       * we want it to keep one row ahead so that next block row's DC
488
       * values are up to date.
496
       * values are up to date.
 Lines 649-669   decompress_smooth_data (j_decompress_ptr Link Here 
649
	/* OK, do the IDCT */
657
	/* OK, do the IDCT */
650
	(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
658
	(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
651
			output_ptr, output_col);
659
			output_ptr, output_col);
652
	/* Advance for next column */
660
	/* Advance for next column */
653
	DC1 = DC2; DC2 = DC3;
661
	DC1 = DC2; DC2 = DC3;
654
	DC4 = DC5; DC5 = DC6;
662
	DC4 = DC5; DC5 = DC6;
655
	DC7 = DC8; DC8 = DC9;
663
	DC7 = DC8; DC8 = DC9;
656
	buffer_ptr++, prev_block_row++, next_block_row++;
664
	buffer_ptr++, prev_block_row++, next_block_row++;
657
	output_col += compptr->DCT_scaled_size;
665
	output_col += compptr->_DCT_scaled_size;
658
      }
666
      }
659
      output_ptr += compptr->DCT_scaled_size;
667
      output_ptr += compptr->_DCT_scaled_size;
660
    }
668
    }
661
  }
669
  }
662
670
663
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
671
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
664
    return JPEG_ROW_COMPLETED;
672
    return JPEG_ROW_COMPLETED;
665
  return JPEG_SCAN_COMPLETED;
673
  return JPEG_SCAN_COMPLETED;
666
}
674
}
667
675
668
#endif /* BLOCK_SMOOTHING_SUPPORTED */
676
#endif /* BLOCK_SMOOTHING_SUPPORTED */
669
677
 Lines 728-736   jinit_d_coef_controller (j_decompress_pt Link Here 
728
				  D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
736
				  D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
729
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
737
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
730
      coef->MCU_buffer[i] = buffer + i;
738
      coef->MCU_buffer[i] = buffer + i;
731
    }
739
    }
732
    coef->pub.consume_data = dummy_consume_data;
740
    coef->pub.consume_data = dummy_consume_data;
733
    coef->pub.decompress_data = decompress_onepass;
741
    coef->pub.decompress_data = decompress_onepass;
734
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
742
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
735
  }
743
  }
736
}
744
745
  /* Allocate the workspace buffer */
746
  coef->workspace = (JCOEF *)
747
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
748
                                SIZEOF(JCOEF) * DCTSIZE2);
749
}
(-)a/jpeg/jdcolor.c (-221 / +52 lines)
Line     Link Here 
 Lines 1-38    Link Here 
1
/*
1
/*
2
 * jdcolor.c
2
 * jdcolor.c
3
 *
3
 *
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
5
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
 * Copyright (C) 2009, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
7
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
8
 * For conditions of distribution and use, see the accompanying README file.
7
 *
9
 *
8
 * This file contains output colorspace conversion routines.
10
 * This file contains output colorspace conversion routines.
9
 */
11
 */
10
12
11
#define JPEG_INTERNALS
13
#define JPEG_INTERNALS
12
#include "jinclude.h"
14
#include "jinclude.h"
13
#include "jpeglib.h"
15
#include "jpeglib.h"
14
#include "jconfig.h"
16
#include "jsimd.h"
15
17
16
18
17
/* Private subobject */
19
/* Private subobject */
18
20
19
typedef struct {
21
typedef struct {
20
  struct jpeg_color_deconverter pub; /* public fields */
22
  struct jpeg_color_deconverter pub; /* public fields */
21
23
22
  /* These fields are not needed anymore as these are now static tables */
23
24
#if 0
25
  /* Private state for YCC->RGB conversion */
24
  /* Private state for YCC->RGB conversion */
26
  int * Cr_r_tab;		/* => table for Cr to R conversion */
25
  int * Cr_r_tab;		/* => table for Cr to R conversion */
27
  int * Cb_b_tab;		/* => table for Cb to B conversion */
26
  int * Cb_b_tab;		/* => table for Cb to B conversion */
28
  INT32 * Cr_g_tab;		/* => table for Cr to G conversion */
27
  INT32 * Cr_g_tab;		/* => table for Cr to G conversion */
29
  INT32 * Cb_g_tab;		/* => table for Cb to G conversion */
28
  INT32 * Cb_g_tab;		/* => table for Cb to G conversion */
30
#endif
31
} my_color_deconverter;
29
} my_color_deconverter;
32
30
33
typedef my_color_deconverter * my_cconvert_ptr;
31
typedef my_color_deconverter * my_cconvert_ptr;
34
32
35
33
36
/**************** YCbCr -> RGB conversion: most common case **************/
34
/**************** YCbCr -> RGB conversion: most common case **************/
37
35
38
/*
36
/*
 Lines 61-273   typedef my_color_deconverter * my_cconve Link Here 
61
 * values for the G calculation are left scaled up, since we must add them
59
 * values for the G calculation are left scaled up, since we must add them
62
 * together before rounding.
60
 * together before rounding.
63
 */
61
 */
64
62
65
#define SCALEBITS	16	/* speediest right-shift on some machines */
63
#define SCALEBITS	16	/* speediest right-shift on some machines */
66
#define ONE_HALF	((INT32) 1 << (SCALEBITS-1))
64
#define ONE_HALF	((INT32) 1 << (SCALEBITS-1))
67
#define FIX(x)		((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
65
#define FIX(x)		((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
68
66
69
/* Use static tables for color processing. */
70
71
const int Cr_r_tab[(MAXJSAMPLE+1) * SIZEOF(int)] ={
72
  0xffffff4dUL, 0xffffff4eUL, 0xffffff4fUL, 0xffffff51UL, 0xffffff52UL, 0xffffff54UL, 
73
  0xffffff55UL, 0xffffff56UL, 0xffffff58UL, 0xffffff59UL, 0xffffff5bUL, 0xffffff5cUL, 
74
  0xffffff5dUL, 0xffffff5fUL, 0xffffff60UL, 0xffffff62UL, 0xffffff63UL, 0xffffff64UL, 
75
  0xffffff66UL, 0xffffff67UL, 0xffffff69UL, 0xffffff6aUL, 0xffffff6bUL, 0xffffff6dUL, 
76
  0xffffff6eUL, 0xffffff70UL, 0xffffff71UL, 0xffffff72UL, 0xffffff74UL, 0xffffff75UL, 
77
  0xffffff77UL, 0xffffff78UL, 0xffffff79UL, 0xffffff7bUL, 0xffffff7cUL, 0xffffff7eUL, 
78
  0xffffff7fUL, 0xffffff80UL, 0xffffff82UL, 0xffffff83UL, 0xffffff85UL, 0xffffff86UL, 
79
  0xffffff87UL, 0xffffff89UL, 0xffffff8aUL, 0xffffff8cUL, 0xffffff8dUL, 0xffffff8eUL, 
80
  0xffffff90UL, 0xffffff91UL, 0xffffff93UL, 0xffffff94UL, 0xffffff95UL, 0xffffff97UL, 
81
  0xffffff98UL, 0xffffff9aUL, 0xffffff9bUL, 0xffffff9cUL, 0xffffff9eUL, 0xffffff9fUL, 
82
  0xffffffa1UL, 0xffffffa2UL, 0xffffffa3UL, 0xffffffa5UL, 0xffffffa6UL, 0xffffffa8UL, 
83
  0xffffffa9UL, 0xffffffaaUL, 0xffffffacUL, 0xffffffadUL, 0xffffffafUL, 0xffffffb0UL, 
84
  0xffffffb1UL, 0xffffffb3UL, 0xffffffb4UL, 0xffffffb6UL, 0xffffffb7UL, 0xffffffb8UL, 
85
  0xffffffbaUL, 0xffffffbbUL, 0xffffffbdUL, 0xffffffbeUL, 0xffffffc0UL, 0xffffffc1UL, 
86
  0xffffffc2UL, 0xffffffc4UL, 0xffffffc5UL, 0xffffffc7UL, 0xffffffc8UL, 0xffffffc9UL, 
87
  0xffffffcbUL, 0xffffffccUL, 0xffffffceUL, 0xffffffcfUL, 0xffffffd0UL, 0xffffffd2UL, 
88
  0xffffffd3UL, 0xffffffd5UL, 0xffffffd6UL, 0xffffffd7UL, 0xffffffd9UL, 0xffffffdaUL, 
89
  0xffffffdcUL, 0xffffffddUL, 0xffffffdeUL, 0xffffffe0UL, 0xffffffe1UL, 0xffffffe3UL, 
90
  0xffffffe4UL, 0xffffffe5UL, 0xffffffe7UL, 0xffffffe8UL, 0xffffffeaUL, 0xffffffebUL, 
91
  0xffffffecUL, 0xffffffeeUL, 0xffffffefUL, 0xfffffff1UL, 0xfffffff2UL, 0xfffffff3UL, 
92
  0xfffffff5UL, 0xfffffff6UL, 0xfffffff8UL, 0xfffffff9UL, 0xfffffffaUL, 0xfffffffcUL, 
93
  0xfffffffdUL, 0xffffffffUL,       0x00UL,       0x01UL,       0x03UL,       0x04UL, 
94
        0x06UL,       0x07UL,       0x08UL,       0x0aUL,       0x0bUL,       0x0dUL, 
95
        0x0eUL,       0x0fUL,       0x11UL,       0x12UL,       0x14UL,       0x15UL, 
96
        0x16UL,       0x18UL,       0x19UL,       0x1bUL,       0x1cUL,       0x1dUL, 
97
        0x1fUL,       0x20UL,       0x22UL,       0x23UL,       0x24UL,       0x26UL, 
98
        0x27UL,       0x29UL,       0x2aUL,       0x2bUL,       0x2dUL,       0x2eUL, 
99
        0x30UL,       0x31UL,       0x32UL,       0x34UL,       0x35UL,       0x37UL, 
100
        0x38UL,       0x39UL,       0x3bUL,       0x3cUL,       0x3eUL,       0x3fUL, 
101
        0x40UL,       0x42UL,       0x43UL,       0x45UL,       0x46UL,       0x48UL, 
102
        0x49UL,       0x4aUL,       0x4cUL,       0x4dUL,       0x4fUL,       0x50UL, 
103
        0x51UL,       0x53UL,       0x54UL,       0x56UL,       0x57UL,       0x58UL, 
104
        0x5aUL,       0x5bUL,       0x5dUL,       0x5eUL,       0x5fUL,       0x61UL, 
105
        0x62UL,       0x64UL,       0x65UL,       0x66UL,       0x68UL,       0x69UL, 
106
        0x6bUL,       0x6cUL,       0x6dUL,       0x6fUL,       0x70UL,       0x72UL, 
107
        0x73UL,       0x74UL,       0x76UL,       0x77UL,       0x79UL,       0x7aUL, 
108
        0x7bUL,       0x7dUL,       0x7eUL,       0x80UL,       0x81UL,       0x82UL, 
109
        0x84UL,       0x85UL,       0x87UL,       0x88UL,       0x89UL,       0x8bUL, 
110
        0x8cUL,       0x8eUL,       0x8fUL,       0x90UL,       0x92UL,       0x93UL, 
111
        0x95UL,       0x96UL,       0x97UL,       0x99UL,       0x9aUL,       0x9cUL, 
112
        0x9dUL,       0x9eUL,       0xa0UL,       0xa1UL,       0xa3UL,       0xa4UL, 
113
        0xa5UL,       0xa7UL,       0xa8UL,       0xaaUL,       0xabUL,       0xacUL, 
114
        0xaeUL,       0xafUL,       0xb1UL,       0xb2UL
115
  };
116
117
const int Cb_b_tab[(MAXJSAMPLE+1) * SIZEOF(int)] ={
118
  0xffffff1dUL, 0xffffff1fUL, 0xffffff21UL, 0xffffff22UL, 0xffffff24UL, 0xffffff26UL, 
119
  0xffffff28UL, 0xffffff2aUL, 0xffffff2bUL, 0xffffff2dUL, 0xffffff2fUL, 0xffffff31UL, 
120
  0xffffff32UL, 0xffffff34UL, 0xffffff36UL, 0xffffff38UL, 0xffffff3aUL, 0xffffff3bUL, 
121
  0xffffff3dUL, 0xffffff3fUL, 0xffffff41UL, 0xffffff42UL, 0xffffff44UL, 0xffffff46UL, 
122
  0xffffff48UL, 0xffffff49UL, 0xffffff4bUL, 0xffffff4dUL, 0xffffff4fUL, 0xffffff51UL, 
123
  0xffffff52UL, 0xffffff54UL, 0xffffff56UL, 0xffffff58UL, 0xffffff59UL, 0xffffff5bUL, 
124
  0xffffff5dUL, 0xffffff5fUL, 0xffffff61UL, 0xffffff62UL, 0xffffff64UL, 0xffffff66UL, 
125
  0xffffff68UL, 0xffffff69UL, 0xffffff6bUL, 0xffffff6dUL, 0xffffff6fUL, 0xffffff70UL, 
126
  0xffffff72UL, 0xffffff74UL, 0xffffff76UL, 0xffffff78UL, 0xffffff79UL, 0xffffff7bUL, 
127
  0xffffff7dUL, 0xffffff7fUL, 0xffffff80UL, 0xffffff82UL, 0xffffff84UL, 0xffffff86UL, 
128
  0xffffff88UL, 0xffffff89UL, 0xffffff8bUL, 0xffffff8dUL, 0xffffff8fUL, 0xffffff90UL, 
129
  0xffffff92UL, 0xffffff94UL, 0xffffff96UL, 0xffffff97UL, 0xffffff99UL, 0xffffff9bUL, 
130
  0xffffff9dUL, 0xffffff9fUL, 0xffffffa0UL, 0xffffffa2UL, 0xffffffa4UL, 0xffffffa6UL, 
131
  0xffffffa7UL, 0xffffffa9UL, 0xffffffabUL, 0xffffffadUL, 0xffffffaeUL, 0xffffffb0UL, 
132
  0xffffffb2UL, 0xffffffb4UL, 0xffffffb6UL, 0xffffffb7UL, 0xffffffb9UL, 0xffffffbbUL, 
133
  0xffffffbdUL, 0xffffffbeUL, 0xffffffc0UL, 0xffffffc2UL, 0xffffffc4UL, 0xffffffc6UL, 
134
  0xffffffc7UL, 0xffffffc9UL, 0xffffffcbUL, 0xffffffcdUL, 0xffffffceUL, 0xffffffd0UL, 
135
  0xffffffd2UL, 0xffffffd4UL, 0xffffffd5UL, 0xffffffd7UL, 0xffffffd9UL, 0xffffffdbUL, 
136
  0xffffffddUL, 0xffffffdeUL, 0xffffffe0UL, 0xffffffe2UL, 0xffffffe4UL, 0xffffffe5UL, 
137
  0xffffffe7UL, 0xffffffe9UL, 0xffffffebUL, 0xffffffedUL, 0xffffffeeUL, 0xfffffff0UL, 
138
  0xfffffff2UL, 0xfffffff4UL, 0xfffffff5UL, 0xfffffff7UL, 0xfffffff9UL, 0xfffffffbUL, 
139
  0xfffffffcUL, 0xfffffffeUL,       0x00UL,       0x02UL,       0x04UL,       0x05UL, 
140
        0x07UL,       0x09UL,       0x0bUL,       0x0cUL,       0x0eUL,       0x10UL, 
141
        0x12UL,       0x13UL,       0x15UL,       0x17UL,       0x19UL,       0x1bUL, 
142
        0x1cUL,       0x1eUL,       0x20UL,       0x22UL,       0x23UL,       0x25UL, 
143
        0x27UL,       0x29UL,       0x2bUL,       0x2cUL,       0x2eUL,       0x30UL, 
144
        0x32UL,       0x33UL,       0x35UL,       0x37UL,       0x39UL,       0x3aUL, 
145
        0x3cUL,       0x3eUL,       0x40UL,       0x42UL,       0x43UL,       0x45UL, 
146
        0x47UL,       0x49UL,       0x4aUL,       0x4cUL,       0x4eUL,       0x50UL, 
147
        0x52UL,       0x53UL,       0x55UL,       0x57UL,       0x59UL,       0x5aUL, 
148
        0x5cUL,       0x5eUL,       0x60UL,       0x61UL,       0x63UL,       0x65UL, 
149
        0x67UL,       0x69UL,       0x6aUL,       0x6cUL,       0x6eUL,       0x70UL, 
150
        0x71UL,       0x73UL,       0x75UL,       0x77UL,       0x78UL,       0x7aUL, 
151
        0x7cUL,       0x7eUL,       0x80UL,       0x81UL,       0x83UL,       0x85UL, 
152
        0x87UL,       0x88UL,       0x8aUL,       0x8cUL,       0x8eUL,       0x90UL, 
153
        0x91UL,       0x93UL,       0x95UL,       0x97UL,       0x98UL,       0x9aUL, 
154
        0x9cUL,       0x9eUL,       0x9fUL,       0xa1UL,       0xa3UL,       0xa5UL, 
155
        0xa7UL,       0xa8UL,       0xaaUL,       0xacUL,       0xaeUL,       0xafUL, 
156
        0xb1UL,       0xb3UL,       0xb5UL,       0xb7UL,       0xb8UL,       0xbaUL, 
157
        0xbcUL,       0xbeUL,       0xbfUL,       0xc1UL,       0xc3UL,       0xc5UL, 
158
        0xc6UL,       0xc8UL,       0xcaUL,       0xccUL,       0xceUL,       0xcfUL, 
159
        0xd1UL,       0xd3UL,       0xd5UL,       0xd6UL,       0xd8UL,       0xdaUL, 
160
        0xdcUL,       0xdeUL,       0xdfUL,       0xe1UL
161
  };
162
163
const int Cr_g_tab[(MAXJSAMPLE+1) * SIZEOF(int)] ={
164
    0x5b6900UL,   0x5ab22eUL,   0x59fb5cUL,   0x59448aUL,   0x588db8UL,   0x57d6e6UL, 
165
    0x572014UL,   0x566942UL,   0x55b270UL,   0x54fb9eUL,   0x5444ccUL,   0x538dfaUL, 
166
    0x52d728UL,   0x522056UL,   0x516984UL,   0x50b2b2UL,   0x4ffbe0UL,   0x4f450eUL, 
167
    0x4e8e3cUL,   0x4dd76aUL,   0x4d2098UL,   0x4c69c6UL,   0x4bb2f4UL,   0x4afc22UL, 
168
    0x4a4550UL,   0x498e7eUL,   0x48d7acUL,   0x4820daUL,   0x476a08UL,   0x46b336UL, 
169
    0x45fc64UL,   0x454592UL,   0x448ec0UL,   0x43d7eeUL,   0x43211cUL,   0x426a4aUL, 
170
    0x41b378UL,   0x40fca6UL,   0x4045d4UL,   0x3f8f02UL,   0x3ed830UL,   0x3e215eUL, 
171
    0x3d6a8cUL,   0x3cb3baUL,   0x3bfce8UL,   0x3b4616UL,   0x3a8f44UL,   0x39d872UL, 
172
    0x3921a0UL,   0x386aceUL,   0x37b3fcUL,   0x36fd2aUL,   0x364658UL,   0x358f86UL, 
173
    0x34d8b4UL,   0x3421e2UL,   0x336b10UL,   0x32b43eUL,   0x31fd6cUL,   0x31469aUL, 
174
    0x308fc8UL,   0x2fd8f6UL,   0x2f2224UL,   0x2e6b52UL,   0x2db480UL,   0x2cfdaeUL, 
175
    0x2c46dcUL,   0x2b900aUL,   0x2ad938UL,   0x2a2266UL,   0x296b94UL,   0x28b4c2UL, 
176
    0x27fdf0UL,   0x27471eUL,   0x26904cUL,   0x25d97aUL,   0x2522a8UL,   0x246bd6UL, 
177
    0x23b504UL,   0x22fe32UL,   0x224760UL,   0x21908eUL,   0x20d9bcUL,   0x2022eaUL, 
178
    0x1f6c18UL,   0x1eb546UL,   0x1dfe74UL,   0x1d47a2UL,   0x1c90d0UL,   0x1bd9feUL, 
179
    0x1b232cUL,   0x1a6c5aUL,   0x19b588UL,   0x18feb6UL,   0x1847e4UL,   0x179112UL, 
180
    0x16da40UL,   0x16236eUL,   0x156c9cUL,   0x14b5caUL,   0x13fef8UL,   0x134826UL, 
181
    0x129154UL,   0x11da82UL,   0x1123b0UL,   0x106cdeUL,    0xfb60cUL,    0xeff3aUL, 
182
     0xe4868UL,    0xd9196UL,    0xcdac4UL,    0xc23f2UL,    0xb6d20UL,    0xab64eUL, 
183
     0x9ff7cUL,    0x948aaUL,    0x891d8UL,    0x7db06UL,    0x72434UL,    0x66d62UL, 
184
     0x5b690UL,    0x4ffbeUL,    0x448ecUL,    0x3921aUL,    0x2db48UL,    0x22476UL, 
185
     0x16da4UL,     0xb6d2UL,        0x0UL, 0xffff492eUL, 0xfffe925cUL, 0xfffddb8aUL, 
186
  0xfffd24b8UL, 0xfffc6de6UL, 0xfffbb714UL, 0xfffb0042UL, 0xfffa4970UL, 0xfff9929eUL, 
187
  0xfff8dbccUL, 0xfff824faUL, 0xfff76e28UL, 0xfff6b756UL, 0xfff60084UL, 0xfff549b2UL, 
188
  0xfff492e0UL, 0xfff3dc0eUL, 0xfff3253cUL, 0xfff26e6aUL, 0xfff1b798UL, 0xfff100c6UL, 
189
  0xfff049f4UL, 0xffef9322UL, 0xffeedc50UL, 0xffee257eUL, 0xffed6eacUL, 0xffecb7daUL, 
190
  0xffec0108UL, 0xffeb4a36UL, 0xffea9364UL, 0xffe9dc92UL, 0xffe925c0UL, 0xffe86eeeUL, 
191
  0xffe7b81cUL, 0xffe7014aUL, 0xffe64a78UL, 0xffe593a6UL, 0xffe4dcd4UL, 0xffe42602UL, 
192
  0xffe36f30UL, 0xffe2b85eUL, 0xffe2018cUL, 0xffe14abaUL, 0xffe093e8UL, 0xffdfdd16UL, 
193
  0xffdf2644UL, 0xffde6f72UL, 0xffddb8a0UL, 0xffdd01ceUL, 0xffdc4afcUL, 0xffdb942aUL, 
194
  0xffdadd58UL, 0xffda2686UL, 0xffd96fb4UL, 0xffd8b8e2UL, 0xffd80210UL, 0xffd74b3eUL, 
195
  0xffd6946cUL, 0xffd5dd9aUL, 0xffd526c8UL, 0xffd46ff6UL, 0xffd3b924UL, 0xffd30252UL, 
196
  0xffd24b80UL, 0xffd194aeUL, 0xffd0dddcUL, 0xffd0270aUL, 0xffcf7038UL, 0xffceb966UL, 
197
  0xffce0294UL, 0xffcd4bc2UL, 0xffcc94f0UL, 0xffcbde1eUL, 0xffcb274cUL, 0xffca707aUL, 
198
  0xffc9b9a8UL, 0xffc902d6UL, 0xffc84c04UL, 0xffc79532UL, 0xffc6de60UL, 0xffc6278eUL, 
199
  0xffc570bcUL, 0xffc4b9eaUL, 0xffc40318UL, 0xffc34c46UL, 0xffc29574UL, 0xffc1dea2UL, 
200
  0xffc127d0UL, 0xffc070feUL, 0xffbfba2cUL, 0xffbf035aUL, 0xffbe4c88UL, 0xffbd95b6UL, 
201
  0xffbcdee4UL, 0xffbc2812UL, 0xffbb7140UL, 0xffbaba6eUL, 0xffba039cUL, 0xffb94ccaUL, 
202
  0xffb895f8UL, 0xffb7df26UL, 0xffb72854UL, 0xffb67182UL, 0xffb5bab0UL, 0xffb503deUL, 
203
  0xffb44d0cUL, 0xffb3963aUL, 0xffb2df68UL, 0xffb22896UL, 0xffb171c4UL, 0xffb0baf2UL, 
204
  0xffb00420UL, 0xffaf4d4eUL, 0xffae967cUL, 0xffaddfaaUL, 0xffad28d8UL, 0xffac7206UL, 
205
  0xffabbb34UL, 0xffab0462UL, 0xffaa4d90UL, 0xffa996beUL, 0xffa8dfecUL, 0xffa8291aUL, 
206
  0xffa77248UL, 0xffa6bb76UL, 0xffa604a4UL, 0xffa54dd2UL
207
 };
208
209
const int Cb_g_tab[(MAXJSAMPLE+1) * SIZEOF(int)] ={
210
    0x2c8d00UL,   0x2c34e6UL,   0x2bdcccUL,   0x2b84b2UL,   0x2b2c98UL,   0x2ad47eUL, 
211
    0x2a7c64UL,   0x2a244aUL,   0x29cc30UL,   0x297416UL,   0x291bfcUL,   0x28c3e2UL, 
212
    0x286bc8UL,   0x2813aeUL,   0x27bb94UL,   0x27637aUL,   0x270b60UL,   0x26b346UL, 
213
    0x265b2cUL,   0x260312UL,   0x25aaf8UL,   0x2552deUL,   0x24fac4UL,   0x24a2aaUL, 
214
    0x244a90UL,   0x23f276UL,   0x239a5cUL,   0x234242UL,   0x22ea28UL,   0x22920eUL, 
215
    0x2239f4UL,   0x21e1daUL,   0x2189c0UL,   0x2131a6UL,   0x20d98cUL,   0x208172UL, 
216
    0x202958UL,   0x1fd13eUL,   0x1f7924UL,   0x1f210aUL,   0x1ec8f0UL,   0x1e70d6UL, 
217
    0x1e18bcUL,   0x1dc0a2UL,   0x1d6888UL,   0x1d106eUL,   0x1cb854UL,   0x1c603aUL, 
218
    0x1c0820UL,   0x1bb006UL,   0x1b57ecUL,   0x1affd2UL,   0x1aa7b8UL,   0x1a4f9eUL, 
219
    0x19f784UL,   0x199f6aUL,   0x194750UL,   0x18ef36UL,   0x18971cUL,   0x183f02UL, 
220
    0x17e6e8UL,   0x178eceUL,   0x1736b4UL,   0x16de9aUL,   0x168680UL,   0x162e66UL, 
221
    0x15d64cUL,   0x157e32UL,   0x152618UL,   0x14cdfeUL,   0x1475e4UL,   0x141dcaUL, 
222
    0x13c5b0UL,   0x136d96UL,   0x13157cUL,   0x12bd62UL,   0x126548UL,   0x120d2eUL, 
223
    0x11b514UL,   0x115cfaUL,   0x1104e0UL,   0x10acc6UL,   0x1054acUL,    0xffc92UL, 
224
     0xfa478UL,    0xf4c5eUL,    0xef444UL,    0xe9c2aUL,    0xe4410UL,    0xdebf6UL, 
225
     0xd93dcUL,    0xd3bc2UL,    0xce3a8UL,    0xc8b8eUL,    0xc3374UL,    0xbdb5aUL, 
226
     0xb8340UL,    0xb2b26UL,    0xad30cUL,    0xa7af2UL,    0xa22d8UL,    0x9cabeUL, 
227
     0x972a4UL,    0x91a8aUL,    0x8c270UL,    0x86a56UL,    0x8123cUL,    0x7ba22UL, 
228
     0x76208UL,    0x709eeUL,    0x6b1d4UL,    0x659baUL,    0x601a0UL,    0x5a986UL, 
229
     0x5516cUL,    0x4f952UL,    0x4a138UL,    0x4491eUL,    0x3f104UL,    0x398eaUL, 
230
     0x340d0UL,    0x2e8b6UL,    0x2909cUL,    0x23882UL,    0x1e068UL,    0x1884eUL, 
231
     0x13034UL,     0xd81aUL,     0x8000UL,     0x27e6UL, 0xffffcfccUL, 0xffff77b2UL,
232
  0xffff1f98UL, 0xfffec77eUL, 0xfffe6f64UL, 0xfffe174aUL, 0xfffdbf30UL, 0xfffd6716UL,
233
  0xfffd0efcUL, 0xfffcb6e2UL, 0xfffc5ec8UL, 0xfffc06aeUL, 0xfffbae94UL, 0xfffb567aUL,
234
  0xfffafe60UL, 0xfffaa646UL, 0xfffa4e2cUL, 0xfff9f612UL, 0xfff99df8UL, 0xfff945deUL,
235
  0xfff8edc4UL, 0xfff895aaUL, 0xfff83d90UL, 0xfff7e576UL, 0xfff78d5cUL, 0xfff73542UL,
236
  0xfff6dd28UL, 0xfff6850eUL, 0xfff62cf4UL, 0xfff5d4daUL, 0xfff57cc0UL, 0xfff524a6UL,
237
  0xfff4cc8cUL, 0xfff47472UL, 0xfff41c58UL, 0xfff3c43eUL, 0xfff36c24UL, 0xfff3140aUL,
238
  0xfff2bbf0UL, 0xfff263d6UL, 0xfff20bbcUL, 0xfff1b3a2UL, 0xfff15b88UL, 0xfff1036eUL,
239
  0xfff0ab54UL, 0xfff0533aUL, 0xffeffb20UL, 0xffefa306UL, 0xffef4aecUL, 0xffeef2d2UL,
240
  0xffee9ab8UL, 0xffee429eUL, 0xffedea84UL, 0xffed926aUL, 0xffed3a50UL, 0xffece236UL,
241
  0xffec8a1cUL, 0xffec3202UL, 0xffebd9e8UL, 0xffeb81ceUL, 0xffeb29b4UL, 0xffead19aUL,
242
  0xffea7980UL, 0xffea2166UL, 0xffe9c94cUL, 0xffe97132UL, 0xffe91918UL, 0xffe8c0feUL,
243
  0xffe868e4UL, 0xffe810caUL, 0xffe7b8b0UL, 0xffe76096UL, 0xffe7087cUL, 0xffe6b062UL,
244
  0xffe65848UL, 0xffe6002eUL, 0xffe5a814UL, 0xffe54ffaUL, 0xffe4f7e0UL, 0xffe49fc6UL,
245
  0xffe447acUL, 0xffe3ef92UL, 0xffe39778UL, 0xffe33f5eUL, 0xffe2e744UL, 0xffe28f2aUL,
246
  0xffe23710UL, 0xffe1def6UL, 0xffe186dcUL, 0xffe12ec2UL, 0xffe0d6a8UL, 0xffe07e8eUL,
247
  0xffe02674UL, 0xffdfce5aUL, 0xffdf7640UL, 0xffdf1e26UL, 0xffdec60cUL, 0xffde6df2UL,
248
  0xffde15d8UL, 0xffddbdbeUL, 0xffdd65a4UL, 0xffdd0d8aUL, 0xffdcb570UL, 0xffdc5d56UL,
249
  0xffdc053cUL, 0xffdbad22UL, 0xffdb5508UL, 0xffdafceeUL, 0xffdaa4d4UL, 0xffda4cbaUL,
250
  0xffd9f4a0UL, 0xffd99c86UL, 0xffd9446cUL, 0xffd8ec52UL, 0xffd89438UL, 0xffd83c1eUL,
251
  0xffd7e404UL, 0xffd78beaUL, 0xffd733d0UL, 0xffd6dbb6UL, 0xffd6839cUL, 0xffd62b82UL,
252
  0xffd5d368UL, 0xffd57b4eUL, 0xffd52334UL, 0xffd4cb1aUL
253
 };
254
67
255
/*
68
/*
256
 * Initialize tables for YCC->RGB colorspace conversion.
69
 * Initialize tables for YCC->RGB colorspace conversion.
257
 */
70
 */
258
71
259
LOCAL(void)
72
LOCAL(void)
260
build_ycc_rgb_table (j_decompress_ptr cinfo)
73
build_ycc_rgb_table (j_decompress_ptr cinfo)
261
{
74
{
262
263
  /* The code below was used to generate the static tables above */
264
265
#if 0
266
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
75
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
267
  int i;
76
  int i;
268
  INT32 x;
77
  INT32 x;
269
  SHIFT_TEMPS
78
  SHIFT_TEMPS
270
79
271
  cconvert->Cr_r_tab = (int *)
80
  cconvert->Cr_r_tab = (int *)
272
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
81
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
273
				(MAXJSAMPLE+1) * SIZEOF(int));
82
				(MAXJSAMPLE+1) * SIZEOF(int));
 Lines 291-308   build_ycc_rgb_table (j_decompress_ptr ci Link Here 
291
    cconvert->Cb_b_tab[i] = (int)
100
    cconvert->Cb_b_tab[i] = (int)
292
		    RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
101
		    RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
293
    /* Cr=>G value is scaled-up -0.71414 * x */
102
    /* Cr=>G value is scaled-up -0.71414 * x */
294
    cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
103
    cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
295
    /* Cb=>G value is scaled-up -0.34414 * x */
104
    /* Cb=>G value is scaled-up -0.34414 * x */
296
    /* We also add in ONE_HALF so that need not do it in inner loop */
105
    /* We also add in ONE_HALF so that need not do it in inner loop */
297
    cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
106
    cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
298
  }
107
  }
299
#endif /* 0 */
108
}
300
}
301
109
302
110
303
/*
111
/*
304
 * Convert some rows of samples to the output colorspace.
112
 * Convert some rows of samples to the output colorspace.
305
 *
113
 *
306
 * Note that we change from noninterleaved, one-plane-per-component format
114
 * Note that we change from noninterleaved, one-plane-per-component format
307
 * to interleaved-pixel format.  The output buffer is therefore three times
115
 * to interleaved-pixel format.  The output buffer is therefore three times
308
 * as wide as the input buffer.
116
 * as wide as the input buffer.
 Lines 313-354   build_ycc_rgb_table (j_decompress_ptr ci Link Here 
313
121
314
METHODDEF(void)
122
METHODDEF(void)
315
ycc_rgb_convert (j_decompress_ptr cinfo,
123
ycc_rgb_convert (j_decompress_ptr cinfo,
316
		 JSAMPIMAGE input_buf, JDIMENSION input_row,
124
		 JSAMPIMAGE input_buf, JDIMENSION input_row,
317
		 JSAMPARRAY output_buf, int num_rows)
125
		 JSAMPARRAY output_buf, int num_rows)
318
{
126
{
319
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
127
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
320
  register int y, cb, cr;
128
  register int y, cb, cr;
321
  JSAMPLE * range_limit_y;
129
  register JSAMPROW outptr;
322
  JSAMPROW outptr;
130
  register JSAMPROW inptr0, inptr1, inptr2;
323
  JSAMPROW inptr0, inptr1, inptr2;
131
  register JDIMENSION col;
324
  JDIMENSION col;
325
  JDIMENSION num_cols = cinfo->output_width;
132
  JDIMENSION num_cols = cinfo->output_width;
326
  JSAMPLE * range_limit = cinfo->sample_range_limit;
133
  /* copy these pointers into registers if possible */
134
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
135
  register int * Crrtab = cconvert->Cr_r_tab;
136
  register int * Cbbtab = cconvert->Cb_b_tab;
137
  register INT32 * Crgtab = cconvert->Cr_g_tab;
138
  register INT32 * Cbgtab = cconvert->Cb_g_tab;
327
  SHIFT_TEMPS
139
  SHIFT_TEMPS
328
140
329
  while (--num_rows >= 0) {
141
  while (--num_rows >= 0) {
330
    inptr0 = input_buf[0][input_row];
142
    inptr0 = input_buf[0][input_row];
331
    inptr1 = input_buf[1][input_row];
143
    inptr1 = input_buf[1][input_row];
332
    inptr2 = input_buf[2][input_row];
144
    inptr2 = input_buf[2][input_row];
333
    input_row++;
145
    input_row++;
334
    outptr = *output_buf++;
146
    outptr = *output_buf++;
335
    for (col = 0; col < num_cols; col++) {
147
    for (col = 0; col < num_cols; col++) {
336
      y  = GETJSAMPLE(inptr0[col]);
148
      y  = GETJSAMPLE(inptr0[col]);
337
      cb = GETJSAMPLE(inptr1[col]);
149
      cb = GETJSAMPLE(inptr1[col]);
338
      cr = GETJSAMPLE(inptr2[col]);
150
      cr = GETJSAMPLE(inptr2[col]);
339
      range_limit_y = range_limit + y;
340
      /* Range-limiting is essential due to noise introduced by DCT losses. */
151
      /* Range-limiting is essential due to noise introduced by DCT losses. */
341
      outptr[RGB_RED] =   range_limit_y[Cr_r_tab[cr]];
152
      outptr[rgb_red[cinfo->out_color_space]] =   range_limit[y + Crrtab[cr]];
342
      outptr[RGB_GREEN] = range_limit_y[
153
      outptr[rgb_green[cinfo->out_color_space]] = range_limit[y +
343
			      ((int) RIGHT_SHIFT(Cb_g_tab[cb] + Cr_g_tab[cr],
154
			      ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
344
						 SCALEBITS))];
155
						 SCALEBITS))];
345
      outptr[RGB_BLUE] =  range_limit_y[Cb_b_tab[cb]];
156
      outptr[rgb_blue[cinfo->out_color_space]] =  range_limit[y + Cbbtab[cb]];
346
      outptr += RGB_PIXELSIZE;
157
      outptr += rgb_pixelsize[cinfo->out_color_space];
347
    }
158
    }
348
  }
159
  }
349
}
160
}
350
161
351
162
352
/**************** Cases other than YCbCr -> RGB **************/
163
/**************** Cases other than YCbCr -> RGB **************/
353
164
354
165
 Lines 406-474   grayscale_convert (j_decompress_ptr cinf Link Here 
406
 */
217
 */
407
218
408
METHODDEF(void)
219
METHODDEF(void)
409
gray_rgb_convert (j_decompress_ptr cinfo,
220
gray_rgb_convert (j_decompress_ptr cinfo,
410
		  JSAMPIMAGE input_buf, JDIMENSION input_row,
221
		  JSAMPIMAGE input_buf, JDIMENSION input_row,
411
		  JSAMPARRAY output_buf, int num_rows)
222
		  JSAMPARRAY output_buf, int num_rows)
412
{
223
{
413
  register JSAMPROW inptr, outptr;
224
  register JSAMPROW inptr, outptr;
414
  register JDIMENSION col;
225
  JSAMPLE *maxinptr;
415
  JDIMENSION num_cols = cinfo->output_width;
226
  JDIMENSION num_cols = cinfo->output_width;
227
  int rindex = rgb_red[cinfo->out_color_space];
228
  int gindex = rgb_green[cinfo->out_color_space];
229
  int bindex = rgb_blue[cinfo->out_color_space];
230
  int rgbstride = rgb_pixelsize[cinfo->out_color_space];
416
231
417
  while (--num_rows >= 0) {
232
  while (--num_rows >= 0) {
418
    inptr = input_buf[0][input_row++];
233
    inptr = input_buf[0][input_row++];
234
    maxinptr = &inptr[num_cols];
419
    outptr = *output_buf++;
235
    outptr = *output_buf++;
420
    for (col = 0; col < num_cols; col++) {
236
    for (; inptr < maxinptr; inptr++, outptr += rgbstride) {
421
      /* We can dispense with GETJSAMPLE() here */
237
      /* We can dispense with GETJSAMPLE() here */
422
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
238
      outptr[rindex] = outptr[gindex] = outptr[bindex] = *inptr;
423
      outptr += RGB_PIXELSIZE;
424
    }
239
    }
425
  }
240
  }
426
}
241
}
427
242
428
243
429
/*
244
/*
430
 * Adobe-style YCCK->CMYK conversion.
245
 * Adobe-style YCCK->CMYK conversion.
431
 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
246
 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
432
 * conversion as above, while passing K (black) unchanged.
247
 * conversion as above, while passing K (black) unchanged.
433
 */
248
 * We assume build_ycc_rgb_table has been called.
249
 */
434
250
435
METHODDEF(void)
251
METHODDEF(void)
436
ycck_cmyk_convert (j_decompress_ptr cinfo,
252
ycck_cmyk_convert (j_decompress_ptr cinfo,
437
		   JSAMPIMAGE input_buf, JDIMENSION input_row,
253
		   JSAMPIMAGE input_buf, JDIMENSION input_row,
438
		   JSAMPARRAY output_buf, int num_rows)
254
		   JSAMPARRAY output_buf, int num_rows)
439
{
255
{
440
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
256
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
441
  register int y, cb, cr;
257
  register int y, cb, cr;
442
  register JSAMPROW outptr;
258
  register JSAMPROW outptr;
443
  register JSAMPROW inptr0, inptr1, inptr2, inptr3;
259
  register JSAMPROW inptr0, inptr1, inptr2, inptr3;
444
  register JDIMENSION col;
260
  register JDIMENSION col;
445
  JDIMENSION num_cols = cinfo->output_width;
261
  JDIMENSION num_cols = cinfo->output_width;
446
  /* copy these pointers into registers if possible */
262
  /* copy these pointers into registers if possible */
447
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
263
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
264
  register int * Crrtab = cconvert->Cr_r_tab;
265
  register int * Cbbtab = cconvert->Cb_b_tab;
266
  register INT32 * Crgtab = cconvert->Cr_g_tab;
267
  register INT32 * Cbgtab = cconvert->Cb_g_tab;
448
  SHIFT_TEMPS
268
  SHIFT_TEMPS
449
269
450
  while (--num_rows >= 0) {
270
  while (--num_rows >= 0) {
451
    inptr0 = input_buf[0][input_row];
271
    inptr0 = input_buf[0][input_row];
452
    inptr1 = input_buf[1][input_row];
272
    inptr1 = input_buf[1][input_row];
453
    inptr2 = input_buf[2][input_row];
273
    inptr2 = input_buf[2][input_row];
454
    inptr3 = input_buf[3][input_row];
274
    inptr3 = input_buf[3][input_row];
455
    input_row++;
275
    input_row++;
456
    outptr = *output_buf++;
276
    outptr = *output_buf++;
457
    for (col = 0; col < num_cols; col++) {
277
    for (col = 0; col < num_cols; col++) {
458
      y  = GETJSAMPLE(inptr0[col]);
278
      y  = GETJSAMPLE(inptr0[col]);
459
      cb = GETJSAMPLE(inptr1[col]);
279
      cb = GETJSAMPLE(inptr1[col]);
460
      cr = GETJSAMPLE(inptr2[col]);
280
      cr = GETJSAMPLE(inptr2[col]);
461
      /* Range-limiting is essential due to noise introduced by DCT losses. */
281
      /* Range-limiting is essential due to noise introduced by DCT losses. */
462
      outptr[0] = range_limit[MAXJSAMPLE - (y + Cr_r_tab[cr])];   /* red */
282
      outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])];	/* red */
463
      outptr[1] = range_limit[MAXJSAMPLE - (y +                   /* green */
283
      outptr[1] = range_limit[MAXJSAMPLE - (y +			/* green */
464
				  ((int) RIGHT_SHIFT(Cb_g_tab[cb] + Cr_g_tab[cr],
284
			      ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
465
                         SCALEBITS)))];
285
						 SCALEBITS)))];
466
      outptr[2] = range_limit[MAXJSAMPLE - (y + Cb_b_tab[cb])];   /* blue */
286
      outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])];	/* blue */
467
      /* K passes through unchanged */
287
      /* K passes through unchanged */
468
      outptr[3] = inptr3[col];	/* don't need GETJSAMPLE here */
288
      outptr[3] = inptr3[col];	/* don't need GETJSAMPLE here */
469
      outptr += 4;
289
      outptr += 4;
470
    }
290
    }
471
  }
291
  }
472
}
292
}
473
293
474
294
 Lines 538-560   jinit_color_deconverter (j_decompress_pt Link Here 
538
      /* For color->grayscale conversion, only the Y (0) component is needed */
358
      /* For color->grayscale conversion, only the Y (0) component is needed */
539
      for (ci = 1; ci < cinfo->num_components; ci++)
359
      for (ci = 1; ci < cinfo->num_components; ci++)
540
	cinfo->comp_info[ci].component_needed = FALSE;
360
	cinfo->comp_info[ci].component_needed = FALSE;
541
    } else
361
    } else
542
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
362
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
543
    break;
363
    break;
544
364
545
  case JCS_RGB:
365
  case JCS_RGB:
546
    cinfo->out_color_components = RGB_PIXELSIZE;
366
  case JCS_EXT_RGB:
367
  case JCS_EXT_RGBX:
368
  case JCS_EXT_BGR:
369
  case JCS_EXT_BGRX:
370
  case JCS_EXT_XBGR:
371
  case JCS_EXT_XRGB:
372
    cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
547
    if (cinfo->jpeg_color_space == JCS_YCbCr) {
373
    if (cinfo->jpeg_color_space == JCS_YCbCr) {
548
      cconvert->pub.color_convert = ycc_rgb_convert;
374
      if (jsimd_can_ycc_rgb())
549
      build_ycc_rgb_table(cinfo);
375
        cconvert->pub.color_convert = jsimd_ycc_rgb_convert;
376
      else {
377
        cconvert->pub.color_convert = ycc_rgb_convert;
378
        build_ycc_rgb_table(cinfo);
379
      }
550
    } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
380
    } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
551
      cconvert->pub.color_convert = gray_rgb_convert;
381
      cconvert->pub.color_convert = gray_rgb_convert;
552
    } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
382
    } else if (cinfo->jpeg_color_space == cinfo->out_color_space &&
383
      rgb_pixelsize[cinfo->out_color_space] == 3) {
553
      cconvert->pub.color_convert = null_convert;
384
      cconvert->pub.color_convert = null_convert;
554
    } else
385
    } else
555
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
386
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
556
    break;
387
    break;
557
388
558
  case JCS_CMYK:
389
  case JCS_CMYK:
559
    cinfo->out_color_components = 4;
390
    cinfo->out_color_components = 4;
560
    if (cinfo->jpeg_color_space == JCS_YCCK) {
391
    if (cinfo->jpeg_color_space == JCS_YCCK) {
(-)a/jpeg/jdct.h (-4 / +12 lines)
Line     Link Here 
 Lines 18-45    Link Here 
18
 * the DCT is to be performed in-place in that buffer.  Type DCTELEM is int
18
 * the DCT is to be performed in-place in that buffer.  Type DCTELEM is int
19
 * for 8-bit samples, INT32 for 12-bit samples.  (NOTE: Floating-point DCT
19
 * for 8-bit samples, INT32 for 12-bit samples.  (NOTE: Floating-point DCT
20
 * implementations use an array of type FAST_FLOAT, instead.)
20
 * implementations use an array of type FAST_FLOAT, instead.)
21
 * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
21
 * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
22
 * The DCT outputs are returned scaled up by a factor of 8; they therefore
22
 * The DCT outputs are returned scaled up by a factor of 8; they therefore
23
 * have a range of +-8K for 8-bit data, +-128K for 12-bit data.  This
23
 * have a range of +-8K for 8-bit data, +-128K for 12-bit data.  This
24
 * convention improves accuracy in integer implementations and saves some
24
 * convention improves accuracy in integer implementations and saves some
25
 * work in floating-point ones.
25
 * work in floating-point ones.
26
 * Quantization of the output coefficients is done by jcdctmgr.c.
26
 * Quantization of the output coefficients is done by jcdctmgr.c. This
27
 * step requires an unsigned type and also one with twice the bits.
27
 */
28
 */
28
29
29
#if BITS_IN_JSAMPLE == 8
30
#if BITS_IN_JSAMPLE == 8
31
#ifndef WITH_SIMD
30
typedef int DCTELEM;		/* 16 or 32 bits is fine */
32
typedef int DCTELEM;		/* 16 or 32 bits is fine */
33
typedef unsigned int UDCTELEM;
34
typedef unsigned long long UDCTELEM2;
35
#else
36
typedef short DCTELEM;  /* prefer 16 bit with SIMD for parellelism */
37
typedef unsigned short UDCTELEM;
38
typedef unsigned int UDCTELEM2;
39
#endif
31
#else
40
#else
32
typedef INT32 DCTELEM;		/* must have 32 bits */
41
typedef INT32 DCTELEM;		/* must have 32 bits */
42
typedef UINT32 UDCTELEM;
43
typedef unsigned long long UDCTELEM2;
33
#endif
44
#endif
34
45
35
typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
36
typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
37
38
46
39
/*
47
/*
40
 * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer
48
 * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer
41
 * to an output sample array.  The routine must dequantize the input data as
49
 * to an output sample array.  The routine must dequantize the input data as
42
 * well as perform the IDCT; for dequantization, it uses the multiplier table
50
 * well as perform the IDCT; for dequantization, it uses the multiplier table
43
 * pointed to by compptr->dct_table.  The output data is to be placed into the
51
 * pointed to by compptr->dct_table.  The output data is to be placed into the
44
 * sample array starting at a specified column.  (Any row offset needed will
52
 * sample array starting at a specified column.  (Any row offset needed will
45
 * be applied to the array pointer before it is passed to the IDCT code.)
53
 * be applied to the array pointer before it is passed to the IDCT code.)
(-)a/jpeg/jddctmgr.c (-49 / +30 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jddctmgr.c
2
 * jddctmgr.c
3
 *
3
 *
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
5
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
 * Copyright (C) 2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
7
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
8
 * For conditions of distribution and use, see the accompanying README file.
7
 *
9
 *
8
 * This file contains the inverse-DCT management logic.
10
 * This file contains the inverse-DCT management logic.
9
 * This code selects a particular IDCT implementation to be used,
11
 * This code selects a particular IDCT implementation to be used,
10
 * and it performs related housekeeping chores.  No code in this file
12
 * and it performs related housekeeping chores.  No code in this file
11
 * is executed per IDCT step, only during output pass setup.
13
 * is executed per IDCT step, only during output pass setup.
12
 *
14
 *
 Lines 14-32    Link Here 
14
 * dequantization as well as the IDCT proper.  This module sets up the
16
 * dequantization as well as the IDCT proper.  This module sets up the
15
 * dequantization multiplier table needed by the IDCT routine.
17
 * dequantization multiplier table needed by the IDCT routine.
16
 */
18
 */
17
19
18
#define JPEG_INTERNALS
20
#define JPEG_INTERNALS
19
#include "jinclude.h"
21
#include "jinclude.h"
20
#include "jpeglib.h"
22
#include "jpeglib.h"
21
#include "jdct.h"		/* Private declarations for DCT subsystem */
23
#include "jdct.h"		/* Private declarations for DCT subsystem */
22
#ifdef HAVE_SSE2_INTRINSICS
24
#include "jsimddct.h"
23
extern int SSE2Available;
25
#include "jpegcomp.h"
24
#endif
26
25
27
26
/*
28
/*
27
 * The decompressor input side (jdinput.c) saves away the appropriate
29
 * The decompressor input side (jdinput.c) saves away the appropriate
28
 * quantization table for each component at the start of the first scan
30
 * quantization table for each component at the start of the first scan
29
 * involving that component.  (This is necessary in order to correctly
31
 * involving that component.  (This is necessary in order to correctly
30
 * decode files that reuse Q-table slots.)
32
 * decode files that reuse Q-table slots.)
31
 * When we are ready to make an output pass, the saved Q-table is converted
33
 * When we are ready to make an output pass, the saved Q-table is converted
32
 * to a multiplier table that will actually be used by the IDCT routine.
34
 * to a multiplier table that will actually be used by the IDCT routine.
 Lines 75-98   typedef union { Link Here 
75
#ifdef DCT_ISLOW_SUPPORTED
77
#ifdef DCT_ISLOW_SUPPORTED
76
#define PROVIDE_ISLOW_TABLES
78
#define PROVIDE_ISLOW_TABLES
77
#else
79
#else
78
#ifdef IDCT_SCALING_SUPPORTED
80
#ifdef IDCT_SCALING_SUPPORTED
79
#define PROVIDE_ISLOW_TABLES
81
#define PROVIDE_ISLOW_TABLES
80
#endif
82
#endif
81
#endif
83
#endif
82
84
83
GLOBAL(void)
84
jpeg_idct_islow_sse2 (
85
	j_decompress_ptr cinfo, 
86
	jpeg_component_info * compptr,
87
	JCOEFPTR coef_block,
88
	JSAMPARRAY output_buf, 
89
	JDIMENSION output_col);
90
91
85
92
/*
86
/*
93
 * Prepare for an output pass.
87
 * Prepare for an output pass.
94
 * Here we select the proper IDCT routine for each component and build
88
 * Here we select the proper IDCT routine for each component and build
95
 * a matching multiplier table.
89
 * a matching multiplier table.
96
 */
90
 */
97
91
98
METHODDEF(void)
92
METHODDEF(void)
 Lines 103-188   start_pass (j_decompress_ptr cinfo) Link Here 
103
  jpeg_component_info *compptr;
97
  jpeg_component_info *compptr;
104
  int method = 0;
98
  int method = 0;
105
  inverse_DCT_method_ptr method_ptr = NULL;
99
  inverse_DCT_method_ptr method_ptr = NULL;
106
  JQUANT_TBL * qtbl;
100
  JQUANT_TBL * qtbl;
107
101
108
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
102
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
109
       ci++, compptr++) {
103
       ci++, compptr++) {
110
    /* Select the proper IDCT routine for this component's scaling */
104
    /* Select the proper IDCT routine for this component's scaling */
111
    switch (compptr->DCT_scaled_size) {
105
    switch (compptr->_DCT_scaled_size) {
112
#ifdef IDCT_SCALING_SUPPORTED
106
#ifdef IDCT_SCALING_SUPPORTED
113
    case 1:
107
    case 1:
114
      method_ptr = jpeg_idct_1x1;
108
      method_ptr = jpeg_idct_1x1;
115
      method = JDCT_ISLOW;	/* jidctred uses islow-style table */
109
      method = JDCT_ISLOW;	/* jidctred uses islow-style table */
116
      break;
110
      break;
117
    case 2:
111
    case 2:
118
      method_ptr = jpeg_idct_2x2;
112
      if (jsimd_can_idct_2x2())
113
        method_ptr = jsimd_idct_2x2;
114
      else
115
        method_ptr = jpeg_idct_2x2;
119
      method = JDCT_ISLOW;	/* jidctred uses islow-style table */
116
      method = JDCT_ISLOW;	/* jidctred uses islow-style table */
120
      break;
117
      break;
121
    case 4:
118
    case 4:
122
      method_ptr = jpeg_idct_4x4;
119
      if (jsimd_can_idct_4x4())
120
        method_ptr = jsimd_idct_4x4;
121
      else
122
        method_ptr = jpeg_idct_4x4;
123
      method = JDCT_ISLOW;	/* jidctred uses islow-style table */
123
      method = JDCT_ISLOW;	/* jidctred uses islow-style table */
124
      break;
124
      break;
125
#endif
125
#endif
126
    case DCTSIZE:
126
    case DCTSIZE:
127
      switch (cinfo->dct_method) {
127
      switch (cinfo->dct_method) {
128
#ifdef DCT_ISLOW_SUPPORTED
128
#ifdef DCT_ISLOW_SUPPORTED
129
      case JDCT_ISLOW:
129
      case JDCT_ISLOW:
130
#ifdef HAVE_SSE2_INTEL_MNEMONICS
130
	if (jsimd_can_idct_islow())
131
		if(SSE2Available == 1)
131
	  method_ptr = jsimd_idct_islow;
132
		{
132
	else
133
			method_ptr = jpeg_idct_islow_sse2;
133
	  method_ptr = jpeg_idct_islow;
134
			method = JDCT_ISLOW;
134
	method = JDCT_ISLOW;
135
		}
136
		else
137
		{
138
			method_ptr = jpeg_idct_islow;
139
			method = JDCT_ISLOW;
140
		}
141
#else
142
		method_ptr = jpeg_idct_islow;
143
		method = JDCT_ISLOW;
144
		  
145
#endif /* HAVE_SSE2_INTEL_MNEMONICS */
146
	break;
135
	break;
147
#endif
136
#endif
148
#ifdef DCT_IFAST_SUPPORTED
137
#ifdef DCT_IFAST_SUPPORTED
149
      case JDCT_IFAST:
138
      case JDCT_IFAST:
150
#ifdef HAVE_SSE2_INTEL_MNEMONICS
139
	if (jsimd_can_idct_ifast())
151
		if (SSE2Available==1) 
140
	  method_ptr = jsimd_idct_ifast;
152
		{
141
	else
153
			method_ptr = jpeg_idct_islow_sse2;
142
	  method_ptr = jpeg_idct_ifast;
154
			method = JDCT_ISLOW;
143
	method = JDCT_IFAST;
155
		}
144
	break;
156
		else
157
		{
158
			method_ptr = jpeg_idct_ifast;
159
			method = JDCT_IFAST;
160
		}
161
#else
162
		method_ptr = jpeg_idct_ifast;
163
		method = JDCT_IFAST;
164
#endif /* HAVE_SSE2_INTEL_MNEMONICS */
165
	break;
166
167
#endif
145
#endif
168
#ifdef DCT_FLOAT_SUPPORTED
146
#ifdef DCT_FLOAT_SUPPORTED
169
      case JDCT_FLOAT:
147
      case JDCT_FLOAT:
170
	method_ptr = jpeg_idct_float;
148
	if (jsimd_can_idct_float())
149
	  method_ptr = jsimd_idct_float;
150
	else
151
	  method_ptr = jpeg_idct_float;
171
	method = JDCT_FLOAT;
152
	method = JDCT_FLOAT;
172
	break;
153
	break;
173
#endif
154
#endif
174
      default:
155
      default:
175
	ERREXIT(cinfo, JERR_NOT_COMPILED);
156
	ERREXIT(cinfo, JERR_NOT_COMPILED);
176
	break;
157
	break;
177
      }
158
      }
178
      break;
159
      break;
179
    default:
160
    default:
180
      ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
161
      ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size);
181
      break;
162
      break;
182
    }
163
    }
183
    idct->pub.inverse_DCT[ci] = method_ptr;
164
    idct->pub.inverse_DCT[ci] = method_ptr;
184
    /* Create multiplier table from quant table.
165
    /* Create multiplier table from quant table.
185
     * However, we can skip this if the component is uninteresting
166
     * However, we can skip this if the component is uninteresting
186
     * or if we already built the table.  Also, if no quant table
167
     * or if we already built the table.  Also, if no quant table
187
     * has yet been saved for the component, we leave the
168
     * has yet been saved for the component, we leave the
188
     * multiplier table all-zero; we'll be reading zeroes from the
169
     * multiplier table all-zero; we'll be reading zeroes from the
(-)a/jpeg/jdinput.c (-2 / +92 lines)
Line     Link Here 
 Lines 1-24    Link Here 
1
/*
1
/*
2
 * jdinput.c
2
 * jdinput.c
3
 *
3
 *
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
5
 * Modified 2002-2009 by Guido Vollbeding.
6
 * Copyright (C) 2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
7
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
8
 * For conditions of distribution and use, see the accompanying README file.
7
 *
9
 *
8
 * This file contains input control logic for the JPEG decompressor.
10
 * This file contains input control logic for the JPEG decompressor.
9
 * These routines are concerned with controlling the decompressor's input
11
 * These routines are concerned with controlling the decompressor's input
10
 * processing (marker reading and coefficient decoding).  The actual input
12
 * processing (marker reading and coefficient decoding).  The actual input
11
 * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c.
13
 * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c.
12
 */
14
 */
13
15
14
#define JPEG_INTERNALS
16
#define JPEG_INTERNALS
15
#include "jinclude.h"
17
#include "jinclude.h"
16
#include "jpeglib.h"
18
#include "jpeglib.h"
19
#include "jpegcomp.h"
17
20
18
21
19
/* Private state */
22
/* Private state */
20
23
21
typedef struct {
24
typedef struct {
22
  struct jpeg_input_controller pub; /* public fields */
25
  struct jpeg_input_controller pub; /* public fields */
23
26
24
  boolean inheaders;		/* TRUE until first SOS is reached */
27
  boolean inheaders;		/* TRUE until first SOS is reached */
 Lines 30-45   typedef my_input_controller * my_inputct Link Here 
30
/* Forward declarations */
33
/* Forward declarations */
31
METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
34
METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
32
35
33
36
34
/*
37
/*
35
 * Routines to calculate various quantities related to the size of the image.
38
 * Routines to calculate various quantities related to the size of the image.
36
 */
39
 */
37
40
41
42
#if JPEG_LIB_VERSION >= 80
43
/*
44
 * Compute output image dimensions and related values.
45
 * NOTE: this is exported for possible use by application.
46
 * Hence it mustn't do anything that can't be done twice.
47
 */
48
49
GLOBAL(void)
50
jpeg_core_output_dimensions (j_decompress_ptr cinfo)
51
/* Do computations that are needed before master selection phase.
52
 * This function is used for transcoding and full decompression.
53
 */
54
{
55
#ifdef IDCT_SCALING_SUPPORTED
56
  int ci;
57
  jpeg_component_info *compptr;
58
59
  /* Compute actual output image dimensions and DCT scaling choices. */
60
  if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom) {
61
    /* Provide 1/block_size scaling */
62
    cinfo->output_width = (JDIMENSION)
63
      jdiv_round_up((long) cinfo->image_width, (long) cinfo->block_size);
64
    cinfo->output_height = (JDIMENSION)
65
      jdiv_round_up((long) cinfo->image_height, (long) cinfo->block_size);
66
    cinfo->min_DCT_h_scaled_size = 1;
67
    cinfo->min_DCT_v_scaled_size = 1;
68
  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 2) {
69
    /* Provide 2/block_size scaling */
70
    cinfo->output_width = (JDIMENSION)
71
      jdiv_round_up((long) cinfo->image_width * 2L, (long) cinfo->block_size);
72
    cinfo->output_height = (JDIMENSION)
73
      jdiv_round_up((long) cinfo->image_height * 2L, (long) cinfo->block_size);
74
    cinfo->min_DCT_h_scaled_size = 2;
75
    cinfo->min_DCT_v_scaled_size = 2;
76
  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 4) {
77
    /* Provide 4/block_size scaling */
78
    cinfo->output_width = (JDIMENSION)
79
      jdiv_round_up((long) cinfo->image_width * 4L, (long) cinfo->block_size);
80
    cinfo->output_height = (JDIMENSION)
81
      jdiv_round_up((long) cinfo->image_height * 4L, (long) cinfo->block_size);
82
    cinfo->min_DCT_h_scaled_size = 4;
83
    cinfo->min_DCT_v_scaled_size = 4;
84
  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 8) {
85
    /* Provide 8/block_size scaling */
86
    cinfo->output_width = (JDIMENSION)
87
      jdiv_round_up((long) cinfo->image_width * 8L, (long) cinfo->block_size);
88
    cinfo->output_height = (JDIMENSION)
89
      jdiv_round_up((long) cinfo->image_height * 8L, (long) cinfo->block_size);
90
    cinfo->min_DCT_h_scaled_size = 8;
91
    cinfo->min_DCT_v_scaled_size = 8;
92
  }
93
  /* Recompute dimensions of components */
94
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
95
       ci++, compptr++) {
96
    compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size;
97
    compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size;
98
  }
99
100
#else /* !IDCT_SCALING_SUPPORTED */
101
102
  /* Hardwire it to "no scaling" */
103
  cinfo->output_width = cinfo->image_width;
104
  cinfo->output_height = cinfo->image_height;
105
  /* jdinput.c has already initialized DCT_scaled_size,
106
   * and has computed unscaled downsampled_width and downsampled_height.
107
   */
108
109
#endif /* IDCT_SCALING_SUPPORTED */
110
}
111
#endif
112
113
38
LOCAL(void)
114
LOCAL(void)
39
initial_setup (j_decompress_ptr cinfo)
115
initial_setup (j_decompress_ptr cinfo)
40
/* Called once, when first SOS marker is reached */
116
/* Called once, when first SOS marker is reached */
41
{
117
{
42
  int ci;
118
  int ci;
43
  jpeg_component_info *compptr;
119
  jpeg_component_info *compptr;
44
120
45
  /* Make sure image isn't bigger than I can handle */
121
  /* Make sure image isn't bigger than I can handle */
 Lines 65-90   initial_setup (j_decompress_ptr cinfo) Link Here 
65
	compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
141
	compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
66
      ERREXIT(cinfo, JERR_BAD_SAMPLING);
142
      ERREXIT(cinfo, JERR_BAD_SAMPLING);
67
    cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
143
    cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
68
				   compptr->h_samp_factor);
144
				   compptr->h_samp_factor);
69
    cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
145
    cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
70
				   compptr->v_samp_factor);
146
				   compptr->v_samp_factor);
71
  }
147
  }
72
148
149
#if JPEG_LIB_VERSION >=80
150
    cinfo->block_size = DCTSIZE;
151
    cinfo->natural_order = jpeg_natural_order;
152
    cinfo->lim_Se = DCTSIZE2-1;
153
#endif
154
73
  /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
155
  /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
74
   * In the full decompressor, this will be overridden by jdmaster.c;
156
   * In the full decompressor, this will be overridden by jdmaster.c;
75
   * but in the transcoder, jdmaster.c is not used, so we must do it here.
157
   * but in the transcoder, jdmaster.c is not used, so we must do it here.
76
   */
158
   */
159
#if JPEG_LIB_VERSION >= 70
160
  cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE;
161
#else
77
  cinfo->min_DCT_scaled_size = DCTSIZE;
162
  cinfo->min_DCT_scaled_size = DCTSIZE;
163
#endif
78
164
79
  /* Compute dimensions of components */
165
  /* Compute dimensions of components */
80
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
166
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
81
       ci++, compptr++) {
167
       ci++, compptr++) {
168
#if JPEG_LIB_VERSION >= 70
169
    compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE;
170
#else
82
    compptr->DCT_scaled_size = DCTSIZE;
171
    compptr->DCT_scaled_size = DCTSIZE;
172
#endif
83
    /* Size in DCT blocks */
173
    /* Size in DCT blocks */
84
    compptr->width_in_blocks = (JDIMENSION)
174
    compptr->width_in_blocks = (JDIMENSION)
85
      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
175
      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
86
		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
176
		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
87
    compptr->height_in_blocks = (JDIMENSION)
177
    compptr->height_in_blocks = (JDIMENSION)
88
      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
178
      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
89
		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
179
		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
90
    /* downsampled_width and downsampled_height will also be overridden by
180
    /* downsampled_width and downsampled_height will also be overridden by
 Lines 133-149   per_scan_setup (j_decompress_ptr cinfo) Link Here 
133
    /* Overall image size in MCUs */
223
    /* Overall image size in MCUs */
134
    cinfo->MCUs_per_row = compptr->width_in_blocks;
224
    cinfo->MCUs_per_row = compptr->width_in_blocks;
135
    cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
225
    cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
136
    
226
    
137
    /* For noninterleaved scan, always one block per MCU */
227
    /* For noninterleaved scan, always one block per MCU */
138
    compptr->MCU_width = 1;
228
    compptr->MCU_width = 1;
139
    compptr->MCU_height = 1;
229
    compptr->MCU_height = 1;
140
    compptr->MCU_blocks = 1;
230
    compptr->MCU_blocks = 1;
141
    compptr->MCU_sample_width = compptr->DCT_scaled_size;
231
    compptr->MCU_sample_width = compptr->_DCT_scaled_size;
142
    compptr->last_col_width = 1;
232
    compptr->last_col_width = 1;
143
    /* For noninterleaved scans, it is convenient to define last_row_height
233
    /* For noninterleaved scans, it is convenient to define last_row_height
144
     * as the number of block rows present in the last iMCU row.
234
     * as the number of block rows present in the last iMCU row.
145
     */
235
     */
146
    tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
236
    tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
147
    if (tmp == 0) tmp = compptr->v_samp_factor;
237
    if (tmp == 0) tmp = compptr->v_samp_factor;
148
    compptr->last_row_height = tmp;
238
    compptr->last_row_height = tmp;
149
    
239
    
 Lines 169-185   per_scan_setup (j_decompress_ptr cinfo) Link Here 
169
    cinfo->blocks_in_MCU = 0;
259
    cinfo->blocks_in_MCU = 0;
170
    
260
    
171
    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
261
    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
172
      compptr = cinfo->cur_comp_info[ci];
262
      compptr = cinfo->cur_comp_info[ci];
173
      /* Sampling factors give # of blocks of component in each MCU */
263
      /* Sampling factors give # of blocks of component in each MCU */
174
      compptr->MCU_width = compptr->h_samp_factor;
264
      compptr->MCU_width = compptr->h_samp_factor;
175
      compptr->MCU_height = compptr->v_samp_factor;
265
      compptr->MCU_height = compptr->v_samp_factor;
176
      compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
266
      compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
177
      compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
267
      compptr->MCU_sample_width = compptr->MCU_width * compptr->_DCT_scaled_size;
178
      /* Figure number of non-dummy blocks in last MCU column & row */
268
      /* Figure number of non-dummy blocks in last MCU column & row */
179
      tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
269
      tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
180
      if (tmp == 0) tmp = compptr->MCU_width;
270
      if (tmp == 0) tmp = compptr->MCU_width;
181
      compptr->last_col_width = tmp;
271
      compptr->last_col_width = tmp;
182
      tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
272
      tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
183
      if (tmp == 0) tmp = compptr->MCU_height;
273
      if (tmp == 0) tmp = compptr->MCU_height;
184
      compptr->last_row_height = tmp;
274
      compptr->last_row_height = tmp;
185
      /* Prepare array describing MCU composition */
275
      /* Prepare array describing MCU composition */
(-)a/jpeg/jdmainct.c (-22 / +24 lines)
Line     Link Here 
 Lines 1-26    Link Here 
1
/*
1
/*
2
 * jdmainct.c
2
 * jdmainct.c
3
 *
3
 *
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
5
 * Copyright (C) 2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains the main buffer controller for decompression.
9
 * This file contains the main buffer controller for decompression.
9
 * The main buffer lies between the JPEG decompressor proper and the
10
 * The main buffer lies between the JPEG decompressor proper and the
10
 * post-processor; it holds downsampled data in the JPEG colorspace.
11
 * post-processor; it holds downsampled data in the JPEG colorspace.
11
 *
12
 *
12
 * Note that this code is bypassed in raw-data mode, since the application
13
 * Note that this code is bypassed in raw-data mode, since the application
13
 * supplies the equivalent of the main buffer in that case.
14
 * supplies the equivalent of the main buffer in that case.
14
 */
15
 */
15
16
16
#define JPEG_INTERNALS
17
#define JPEG_INTERNALS
17
#include "jinclude.h"
18
#include "jinclude.h"
18
#include "jpeglib.h"
19
#include "jpeglib.h"
20
#include "jpegcomp.h"
19
21
20
22
21
/*
23
/*
22
 * In the current system design, the main buffer need never be a full-image
24
 * In the current system design, the main buffer need never be a full-image
23
 * buffer; any full-height buffers will be found inside the coefficient or
25
 * buffer; any full-height buffers will be found inside the coefficient or
24
 * postprocessing controllers.  Nonetheless, the main controller is not
26
 * postprocessing controllers.  Nonetheless, the main controller is not
25
 * trivial.  Its responsibility is to provide context rows for upsampling/
27
 * trivial.  Its responsibility is to provide context rows for upsampling/
26
 * rescaling, and doing this in an efficient fashion is a bit tricky.
28
 * rescaling, and doing this in an efficient fashion is a bit tricky.
 Lines 156-187   METHODDEF(void) process_data_crank_post Link Here 
156
LOCAL(void)
158
LOCAL(void)
157
alloc_funny_pointers (j_decompress_ptr cinfo)
159
alloc_funny_pointers (j_decompress_ptr cinfo)
158
/* Allocate space for the funny pointer lists.
160
/* Allocate space for the funny pointer lists.
159
 * This is done only once, not once per pass.
161
 * This is done only once, not once per pass.
160
 */
162
 */
161
{
163
{
162
  my_main_ptr main = (my_main_ptr) cinfo->main;
164
  my_main_ptr main = (my_main_ptr) cinfo->main;
163
  int ci, rgroup;
165
  int ci, rgroup;
164
  int M = cinfo->min_DCT_scaled_size;
166
  int M = cinfo->_min_DCT_scaled_size;
165
  jpeg_component_info *compptr;
167
  jpeg_component_info *compptr;
166
  JSAMPARRAY xbuf;
168
  JSAMPARRAY xbuf;
167
169
168
  /* Get top-level space for component array pointers.
170
  /* Get top-level space for component array pointers.
169
   * We alloc both arrays with one call to save a few cycles.
171
   * We alloc both arrays with one call to save a few cycles.
170
   */
172
   */
171
  main->xbuffer[0] = (JSAMPIMAGE)
173
  main->xbuffer[0] = (JSAMPIMAGE)
172
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
174
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
173
				cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
175
				cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
174
  main->xbuffer[1] = main->xbuffer[0] + cinfo->num_components;
176
  main->xbuffer[1] = main->xbuffer[0] + cinfo->num_components;
175
177
176
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
178
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
177
       ci++, compptr++) {
179
       ci++, compptr++) {
178
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
180
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
179
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
181
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
180
    /* Get space for pointer lists --- M+4 row groups in each list.
182
    /* Get space for pointer lists --- M+4 row groups in each list.
181
     * We alloc both pointer lists with one call to save a few cycles.
183
     * We alloc both pointer lists with one call to save a few cycles.
182
     */
184
     */
183
    xbuf = (JSAMPARRAY)
185
    xbuf = (JSAMPARRAY)
184
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
186
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
185
				  2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
187
				  2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
186
    xbuf += rgroup;		/* want one row group at negative offsets */
188
    xbuf += rgroup;		/* want one row group at negative offsets */
187
    main->xbuffer[0][ci] = xbuf;
189
    main->xbuffer[0][ci] = xbuf;
 Lines 197-220   make_funny_pointers (j_decompress_ptr ci Link Here 
197
 * The actual workspace is already allocated (in main->buffer),
199
 * The actual workspace is already allocated (in main->buffer),
198
 * and the space for the pointer lists is allocated too.
200
 * and the space for the pointer lists is allocated too.
199
 * This routine just fills in the curiously ordered lists.
201
 * This routine just fills in the curiously ordered lists.
200
 * This will be repeated at the beginning of each pass.
202
 * This will be repeated at the beginning of each pass.
201
 */
203
 */
202
{
204
{
203
  my_main_ptr main = (my_main_ptr) cinfo->main;
205
  my_main_ptr main = (my_main_ptr) cinfo->main;
204
  int ci, i, rgroup;
206
  int ci, i, rgroup;
205
  int M = cinfo->min_DCT_scaled_size;
207
  int M = cinfo->_min_DCT_scaled_size;
206
  jpeg_component_info *compptr;
208
  jpeg_component_info *compptr;
207
  JSAMPARRAY buf, xbuf0, xbuf1;
209
  JSAMPARRAY buf, xbuf0, xbuf1;
208
210
209
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
211
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
210
       ci++, compptr++) {
212
       ci++, compptr++) {
211
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
213
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
212
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
214
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
213
    xbuf0 = main->xbuffer[0][ci];
215
    xbuf0 = main->xbuffer[0][ci];
214
    xbuf1 = main->xbuffer[1][ci];
216
    xbuf1 = main->xbuffer[1][ci];
215
    /* First copy the workspace pointers as-is */
217
    /* First copy the workspace pointers as-is */
216
    buf = main->buffer[ci];
218
    buf = main->buffer[ci];
217
    for (i = 0; i < rgroup * (M + 2); i++) {
219
    for (i = 0; i < rgroup * (M + 2); i++) {
218
      xbuf0[i] = xbuf1[i] = buf[i];
220
      xbuf0[i] = xbuf1[i] = buf[i];
219
    }
221
    }
220
    /* In the second list, put the last four row groups in swapped order */
222
    /* In the second list, put the last four row groups in swapped order */
 Lines 237-260   make_funny_pointers (j_decompress_ptr ci Link Here 
237
LOCAL(void)
239
LOCAL(void)
238
set_wraparound_pointers (j_decompress_ptr cinfo)
240
set_wraparound_pointers (j_decompress_ptr cinfo)
239
/* Set up the "wraparound" pointers at top and bottom of the pointer lists.
241
/* Set up the "wraparound" pointers at top and bottom of the pointer lists.
240
 * This changes the pointer list state from top-of-image to the normal state.
242
 * This changes the pointer list state from top-of-image to the normal state.
241
 */
243
 */
242
{
244
{
243
  my_main_ptr main = (my_main_ptr) cinfo->main;
245
  my_main_ptr main = (my_main_ptr) cinfo->main;
244
  int ci, i, rgroup;
246
  int ci, i, rgroup;
245
  int M = cinfo->min_DCT_scaled_size;
247
  int M = cinfo->_min_DCT_scaled_size;
246
  jpeg_component_info *compptr;
248
  jpeg_component_info *compptr;
247
  JSAMPARRAY xbuf0, xbuf1;
249
  JSAMPARRAY xbuf0, xbuf1;
248
250
249
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
251
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
250
       ci++, compptr++) {
252
       ci++, compptr++) {
251
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
253
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
252
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
254
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
253
    xbuf0 = main->xbuffer[0][ci];
255
    xbuf0 = main->xbuffer[0][ci];
254
    xbuf1 = main->xbuffer[1][ci];
256
    xbuf1 = main->xbuffer[1][ci];
255
    for (i = 0; i < rgroup; i++) {
257
    for (i = 0; i < rgroup; i++) {
256
      xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
258
      xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
257
      xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
259
      xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
258
      xbuf0[rgroup*(M+2) + i] = xbuf0[i];
260
      xbuf0[rgroup*(M+2) + i] = xbuf0[i];
259
      xbuf1[rgroup*(M+2) + i] = xbuf1[i];
261
      xbuf1[rgroup*(M+2) + i] = xbuf1[i];
260
    }
262
    }
 Lines 272-289   set_bottom_pointers (j_decompress_ptr ci Link Here 
272
  my_main_ptr main = (my_main_ptr) cinfo->main;
274
  my_main_ptr main = (my_main_ptr) cinfo->main;
273
  int ci, i, rgroup, iMCUheight, rows_left;
275
  int ci, i, rgroup, iMCUheight, rows_left;
274
  jpeg_component_info *compptr;
276
  jpeg_component_info *compptr;
275
  JSAMPARRAY xbuf;
277
  JSAMPARRAY xbuf;
276
278
277
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
279
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
278
       ci++, compptr++) {
280
       ci++, compptr++) {
279
    /* Count sample rows in one iMCU row and in one row group */
281
    /* Count sample rows in one iMCU row and in one row group */
280
    iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
282
    iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
281
    rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
283
    rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
282
    /* Count nondummy sample rows remaining for this component */
284
    /* Count nondummy sample rows remaining for this component */
283
    rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
285
    rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
284
    if (rows_left == 0) rows_left = iMCUheight;
286
    if (rows_left == 0) rows_left = iMCUheight;
285
    /* Count nondummy row groups.  Should get same answer for each component,
287
    /* Count nondummy row groups.  Should get same answer for each component,
286
     * so we need only do it once.
288
     * so we need only do it once.
287
     */
289
     */
288
    if (ci == 0) {
290
    if (ci == 0) {
289
      main->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
291
      main->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
 Lines 352-368   process_data_simple_main (j_decompress_p Link Here 
352
  /* Read input data if we haven't filled the main buffer yet */
354
  /* Read input data if we haven't filled the main buffer yet */
353
  if (! main->buffer_full) {
355
  if (! main->buffer_full) {
354
    if (! (*cinfo->coef->decompress_data) (cinfo, main->buffer))
356
    if (! (*cinfo->coef->decompress_data) (cinfo, main->buffer))
355
      return;			/* suspension forced, can do nothing more */
357
      return;			/* suspension forced, can do nothing more */
356
    main->buffer_full = TRUE;	/* OK, we have an iMCU row to work with */
358
    main->buffer_full = TRUE;	/* OK, we have an iMCU row to work with */
357
  }
359
  }
358
360
359
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
361
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
360
  rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
362
  rowgroups_avail = (JDIMENSION) cinfo->_min_DCT_scaled_size;
361
  /* Note: at the bottom of the image, we may pass extra garbage row groups
363
  /* Note: at the bottom of the image, we may pass extra garbage row groups
362
   * to the postprocessor.  The postprocessor has to check for bottom
364
   * to the postprocessor.  The postprocessor has to check for bottom
363
   * of image anyway (at row resolution), so no point in us doing it too.
365
   * of image anyway (at row resolution), so no point in us doing it too.
364
   */
366
   */
365
367
366
  /* Feed the postprocessor */
368
  /* Feed the postprocessor */
367
  (*cinfo->post->post_process_data) (cinfo, main->buffer,
369
  (*cinfo->post->post_process_data) (cinfo, main->buffer,
368
				     &main->rowgroup_ctr, rowgroups_avail,
370
				     &main->rowgroup_ctr, rowgroups_avail,
 Lines 412-428   process_data_context_main (j_decompress_ Link Here 
412
      return;			/* Need to suspend */
414
      return;			/* Need to suspend */
413
    main->context_state = CTX_PREPARE_FOR_IMCU;
415
    main->context_state = CTX_PREPARE_FOR_IMCU;
414
    if (*out_row_ctr >= out_rows_avail)
416
    if (*out_row_ctr >= out_rows_avail)
415
      return;			/* Postprocessor exactly filled output buf */
417
      return;			/* Postprocessor exactly filled output buf */
416
    /*FALLTHROUGH*/
418
    /*FALLTHROUGH*/
417
  case CTX_PREPARE_FOR_IMCU:
419
  case CTX_PREPARE_FOR_IMCU:
418
    /* Prepare to process first M-1 row groups of this iMCU row */
420
    /* Prepare to process first M-1 row groups of this iMCU row */
419
    main->rowgroup_ctr = 0;
421
    main->rowgroup_ctr = 0;
420
    main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
422
    main->rowgroups_avail = (JDIMENSION) (cinfo->_min_DCT_scaled_size - 1);
421
    /* Check for bottom of image: if so, tweak pointers to "duplicate"
423
    /* Check for bottom of image: if so, tweak pointers to "duplicate"
422
     * the last sample row, and adjust rowgroups_avail to ignore padding rows.
424
     * the last sample row, and adjust rowgroups_avail to ignore padding rows.
423
     */
425
     */
424
    if (main->iMCU_row_ctr == cinfo->total_iMCU_rows)
426
    if (main->iMCU_row_ctr == cinfo->total_iMCU_rows)
425
      set_bottom_pointers(cinfo);
427
      set_bottom_pointers(cinfo);
426
    main->context_state = CTX_PROCESS_IMCU;
428
    main->context_state = CTX_PROCESS_IMCU;
427
    /*FALLTHROUGH*/
429
    /*FALLTHROUGH*/
428
  case CTX_PROCESS_IMCU:
430
  case CTX_PROCESS_IMCU:
 Lines 435-452   process_data_context_main (j_decompress_ Link Here 
435
    /* After the first iMCU, change wraparound pointers to normal state */
437
    /* After the first iMCU, change wraparound pointers to normal state */
436
    if (main->iMCU_row_ctr == 1)
438
    if (main->iMCU_row_ctr == 1)
437
      set_wraparound_pointers(cinfo);
439
      set_wraparound_pointers(cinfo);
438
    /* Prepare to load new iMCU row using other xbuffer list */
440
    /* Prepare to load new iMCU row using other xbuffer list */
439
    main->whichptr ^= 1;	/* 0=>1 or 1=>0 */
441
    main->whichptr ^= 1;	/* 0=>1 or 1=>0 */
440
    main->buffer_full = FALSE;
442
    main->buffer_full = FALSE;
441
    /* Still need to process last row group of this iMCU row, */
443
    /* Still need to process last row group of this iMCU row, */
442
    /* which is saved at index M+1 of the other xbuffer */
444
    /* which is saved at index M+1 of the other xbuffer */
443
    main->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
445
    main->rowgroup_ctr = (JDIMENSION) (cinfo->_min_DCT_scaled_size + 1);
444
    main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
446
    main->rowgroups_avail = (JDIMENSION) (cinfo->_min_DCT_scaled_size + 2);
445
    main->context_state = CTX_POSTPONED_ROW;
447
    main->context_state = CTX_POSTPONED_ROW;
446
  }
448
  }
447
}
449
}
448
450
449
451
450
/*
452
/*
451
 * Process some data.
453
 * Process some data.
452
 * Final pass of two-pass quantization: just call the postprocessor.
454
 * Final pass of two-pass quantization: just call the postprocessor.
 Lines 487-512   jinit_d_main_controller (j_decompress_pt Link Here 
487
489
488
  if (need_full_buffer)		/* shouldn't happen */
490
  if (need_full_buffer)		/* shouldn't happen */
489
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
491
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
490
492
491
  /* Allocate the workspace.
493
  /* Allocate the workspace.
492
   * ngroups is the number of row groups we need.
494
   * ngroups is the number of row groups we need.
493
   */
495
   */
494
  if (cinfo->upsample->need_context_rows) {
496
  if (cinfo->upsample->need_context_rows) {
495
    if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
497
    if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */
496
      ERREXIT(cinfo, JERR_NOTIMPL);
498
      ERREXIT(cinfo, JERR_NOTIMPL);
497
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
499
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
498
    ngroups = cinfo->min_DCT_scaled_size + 2;
500
    ngroups = cinfo->_min_DCT_scaled_size + 2;
499
  } else {
501
  } else {
500
    ngroups = cinfo->min_DCT_scaled_size;
502
    ngroups = cinfo->_min_DCT_scaled_size;
501
  }
503
  }
502
504
503
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
504
       ci++, compptr++) {
506
       ci++, compptr++) {
505
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
507
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
506
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
508
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
507
    main->buffer[ci] = (*cinfo->mem->alloc_sarray)
509
    main->buffer[ci] = (*cinfo->mem->alloc_sarray)
508
			((j_common_ptr) cinfo, JPOOL_IMAGE,
510
			((j_common_ptr) cinfo, JPOOL_IMAGE,
509
			 compptr->width_in_blocks * compptr->DCT_scaled_size,
511
			 compptr->width_in_blocks * compptr->_DCT_scaled_size,
510
			 (JDIMENSION) (rgroup * ngroups));
512
			 (JDIMENSION) (rgroup * ngroups));
511
  }
513
  }
512
}
514
}
(-)a/jpeg/jdmarker.c (-1 / +3 lines)
Line     Link Here 
 Lines 74-90   typedef enum { /* JPEG marker codes */ Link Here 
74
  M_APP13 = 0xed,
74
  M_APP13 = 0xed,
75
  M_APP14 = 0xee,
75
  M_APP14 = 0xee,
76
  M_APP15 = 0xef,
76
  M_APP15 = 0xef,
77
  
77
  
78
  M_JPG0  = 0xf0,
78
  M_JPG0  = 0xf0,
79
  M_JPG13 = 0xfd,
79
  M_JPG13 = 0xfd,
80
  M_COM   = 0xfe,
80
  M_COM   = 0xfe,
81
  
81
  
82
  M_TEM   = 0x01
82
  M_TEM   = 0x01,
83
  
84
  M_ERROR = 0x100
83
} JPEG_MARKER;
85
} JPEG_MARKER;
84
86
85
87
86
/* Private state */
88
/* Private state */
87
89
88
typedef struct {
90
typedef struct {
89
  struct jpeg_marker_reader pub; /* public fields */
91
  struct jpeg_marker_reader pub; /* public fields */
90
92
(-)a/jpeg/jdmaster.c (-124 / +52 lines)
Line     Link Here 
 Lines 1-123    Link Here 
1
/*
1
/*
2
 * jdmaster.c
2
 * jdmaster.c
3
 *
3
 *
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
5
 * Copyright (C) 2009-2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains master control logic for the JPEG decompressor.
9
 * This file contains master control logic for the JPEG decompressor.
9
 * These routines are concerned with selecting the modules to be executed
10
 * These routines are concerned with selecting the modules to be executed
10
 * and with determining the number of passes and the work to be done in each
11
 * and with determining the number of passes and the work to be done in each
11
 * pass.
12
 * pass.
12
 */
13
 */
13
14
14
#define JPEG_INTERNALS
15
#define JPEG_INTERNALS
15
#include "jinclude.h"
16
#include "jinclude.h"
16
#include "jpeglib.h"
17
#include "jpeglib.h"
17
18
#include "jpegcomp.h"
18
/* Use static array */
19
19
20
const JSAMPLE static_range_table[ (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE) ]={
21
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
22
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
23
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
24
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
25
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
26
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
27
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
28
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
29
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
30
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
31
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
32
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
33
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
34
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
35
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
36
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
37
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
38
 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 
39
 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 
40
 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 
41
 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 
42
 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 
43
 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
44
 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 
45
 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 
46
 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 
47
 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 
48
 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 
49
 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 
50
 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 
51
 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 
52
 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
53
 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 
54
 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 
55
 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
56
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
57
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
58
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
59
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
60
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
61
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
62
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
63
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
64
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
65
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
66
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
67
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
68
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
69
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
70
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
71
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
72
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
73
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
74
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
75
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
76
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
77
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
78
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
79
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
80
 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 
81
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
82
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
83
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
84
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
85
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
86
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
87
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
88
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
89
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
90
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
91
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
92
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
93
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
94
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
95
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
96
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
97
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
98
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
99
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
100
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
101
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
102
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
103
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
104
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
105
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
106
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
107
 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 
108
 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 
109
 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 
110
 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 
111
 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 
112
 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 
113
 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 
114
 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f
115
};
116
20
117
/* Private state */
21
/* Private state */
118
22
119
typedef struct {
23
typedef struct {
120
  struct jpeg_decomp_master pub; /* public fields */
24
  struct jpeg_decomp_master pub; /* public fields */
121
25
122
  int pass_number;		/* # of passes completed */
26
  int pass_number;		/* # of passes completed */
123
27
 Lines 142-172   LOCAL(boolean) Link Here 
142
use_merged_upsample (j_decompress_ptr cinfo)
46
use_merged_upsample (j_decompress_ptr cinfo)
143
{
47
{
144
#ifdef UPSAMPLE_MERGING_SUPPORTED
48
#ifdef UPSAMPLE_MERGING_SUPPORTED
145
  /* Merging is the equivalent of plain box-filter upsampling */
49
  /* Merging is the equivalent of plain box-filter upsampling */
146
  if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
50
  if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
147
    return FALSE;
51
    return FALSE;
148
  /* jdmerge.c only supports YCC=>RGB color conversion */
52
  /* jdmerge.c only supports YCC=>RGB color conversion */
149
  if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
53
  if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
150
      cinfo->out_color_space != JCS_RGB ||
54
      (cinfo->out_color_space != JCS_RGB &&
151
      cinfo->out_color_components != RGB_PIXELSIZE)
55
      cinfo->out_color_space != JCS_EXT_RGB &&
56
      cinfo->out_color_space != JCS_EXT_RGBX &&
57
      cinfo->out_color_space != JCS_EXT_BGR &&
58
      cinfo->out_color_space != JCS_EXT_BGRX &&
59
      cinfo->out_color_space != JCS_EXT_XBGR &&
60
      cinfo->out_color_space != JCS_EXT_XRGB) ||
61
      cinfo->out_color_components != rgb_pixelsize[cinfo->out_color_space])
152
    return FALSE;
62
    return FALSE;
153
  /* and it only handles 2h1v or 2h2v sampling ratios */
63
  /* and it only handles 2h1v or 2h2v sampling ratios */
154
  if (cinfo->comp_info[0].h_samp_factor != 2 ||
64
  if (cinfo->comp_info[0].h_samp_factor != 2 ||
155
      cinfo->comp_info[1].h_samp_factor != 1 ||
65
      cinfo->comp_info[1].h_samp_factor != 1 ||
156
      cinfo->comp_info[2].h_samp_factor != 1 ||
66
      cinfo->comp_info[2].h_samp_factor != 1 ||
157
      cinfo->comp_info[0].v_samp_factor >  2 ||
67
      cinfo->comp_info[0].v_samp_factor >  2 ||
158
      cinfo->comp_info[1].v_samp_factor != 1 ||
68
      cinfo->comp_info[1].v_samp_factor != 1 ||
159
      cinfo->comp_info[2].v_samp_factor != 1)
69
      cinfo->comp_info[2].v_samp_factor != 1)
160
    return FALSE;
70
    return FALSE;
161
  /* furthermore, it doesn't work if we've scaled the IDCTs differently */
71
  /* furthermore, it doesn't work if we've scaled the IDCTs differently */
162
  if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
72
  if (cinfo->comp_info[0]._DCT_scaled_size != cinfo->_min_DCT_scaled_size ||
163
      cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
73
      cinfo->comp_info[1]._DCT_scaled_size != cinfo->_min_DCT_scaled_size ||
164
      cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
74
      cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size)
165
    return FALSE;
75
    return FALSE;
166
  /* ??? also need to test for upsample-time rescaling, when & if supported */
76
  /* ??? also need to test for upsample-time rescaling, when & if supported */
167
  return TRUE;			/* by golly, it'll work... */
77
  return TRUE;			/* by golly, it'll work... */
168
#else
78
#else
169
  return FALSE;
79
  return FALSE;
170
#endif
80
#endif
171
}
81
}
172
82
 Lines 195-262   jpeg_calc_output_dimensions (j_decompres Link Here 
195
105
196
  /* Compute actual output image dimensions and DCT scaling choices. */
106
  /* Compute actual output image dimensions and DCT scaling choices. */
197
  if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
107
  if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
198
    /* Provide 1/8 scaling */
108
    /* Provide 1/8 scaling */
199
    cinfo->output_width = (JDIMENSION)
109
    cinfo->output_width = (JDIMENSION)
200
      jdiv_round_up((long) cinfo->image_width, 8L);
110
      jdiv_round_up((long) cinfo->image_width, 8L);
201
    cinfo->output_height = (JDIMENSION)
111
    cinfo->output_height = (JDIMENSION)
202
      jdiv_round_up((long) cinfo->image_height, 8L);
112
      jdiv_round_up((long) cinfo->image_height, 8L);
113
#if JPEG_LIB_VERSION >= 70
114
    cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 1;
115
#else
203
    cinfo->min_DCT_scaled_size = 1;
116
    cinfo->min_DCT_scaled_size = 1;
117
#endif
204
  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
118
  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
205
    /* Provide 1/4 scaling */
119
    /* Provide 1/4 scaling */
206
    cinfo->output_width = (JDIMENSION)
120
    cinfo->output_width = (JDIMENSION)
207
      jdiv_round_up((long) cinfo->image_width, 4L);
121
      jdiv_round_up((long) cinfo->image_width, 4L);
208
    cinfo->output_height = (JDIMENSION)
122
    cinfo->output_height = (JDIMENSION)
209
      jdiv_round_up((long) cinfo->image_height, 4L);
123
      jdiv_round_up((long) cinfo->image_height, 4L);
124
#if JPEG_LIB_VERSION >= 70
125
    cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 2;
126
#else
210
    cinfo->min_DCT_scaled_size = 2;
127
    cinfo->min_DCT_scaled_size = 2;
128
#endif
211
  } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
129
  } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
212
    /* Provide 1/2 scaling */
130
    /* Provide 1/2 scaling */
213
    cinfo->output_width = (JDIMENSION)
131
    cinfo->output_width = (JDIMENSION)
214
      jdiv_round_up((long) cinfo->image_width, 2L);
132
      jdiv_round_up((long) cinfo->image_width, 2L);
215
    cinfo->output_height = (JDIMENSION)
133
    cinfo->output_height = (JDIMENSION)
216
      jdiv_round_up((long) cinfo->image_height, 2L);
134
      jdiv_round_up((long) cinfo->image_height, 2L);
135
#if JPEG_LIB_VERSION >= 70
136
    cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 4;
137
#else
217
    cinfo->min_DCT_scaled_size = 4;
138
    cinfo->min_DCT_scaled_size = 4;
139
#endif
218
  } else {
140
  } else {
219
    /* Provide 1/1 scaling */
141
    /* Provide 1/1 scaling */
220
    cinfo->output_width = cinfo->image_width;
142
    cinfo->output_width = cinfo->image_width;
221
    cinfo->output_height = cinfo->image_height;
143
    cinfo->output_height = cinfo->image_height;
144
#if JPEG_LIB_VERSION >= 70
145
    cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE;
146
#else
222
    cinfo->min_DCT_scaled_size = DCTSIZE;
147
    cinfo->min_DCT_scaled_size = DCTSIZE;
148
#endif
223
  }
149
  }
224
  /* In selecting the actual DCT scaling for each component, we try to
150
  /* In selecting the actual DCT scaling for each component, we try to
225
   * scale up the chroma components via IDCT scaling rather than upsampling.
151
   * scale up the chroma components via IDCT scaling rather than upsampling.
226
   * This saves time if the upsampler gets to use 1:1 scaling.
152
   * This saves time if the upsampler gets to use 1:1 scaling.
227
   * Note this code assumes that the supported DCT scalings are powers of 2.
153
   * Note this code assumes that the supported DCT scalings are powers of 2.
228
   */
154
   */
229
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
155
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
230
       ci++, compptr++) {
156
       ci++, compptr++) {
231
    int ssize = cinfo->min_DCT_scaled_size;
157
    int ssize = cinfo->_min_DCT_scaled_size;
232
    while (ssize < DCTSIZE &&
158
    while (ssize < DCTSIZE &&
233
	   (compptr->h_samp_factor * ssize * 2 <=
159
	   (compptr->h_samp_factor * ssize * 2 <=
234
	    cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
160
	    cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) &&
235
	   (compptr->v_samp_factor * ssize * 2 <=
161
	   (compptr->v_samp_factor * ssize * 2 <=
236
	    cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
162
	    cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size)) {
237
      ssize = ssize * 2;
163
      ssize = ssize * 2;
238
    }
164
    }
165
#if JPEG_LIB_VERSION >= 70
166
    compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize;
167
#else
239
    compptr->DCT_scaled_size = ssize;
168
    compptr->DCT_scaled_size = ssize;
240
  }
169
#endif
170
  }
241
171
242
  /* Recompute downsampled dimensions of components;
172
  /* Recompute downsampled dimensions of components;
243
   * application needs to know these if using raw downsampled data.
173
   * application needs to know these if using raw downsampled data.
244
   */
174
   */
245
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
175
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
246
       ci++, compptr++) {
176
       ci++, compptr++) {
247
    /* Size in samples, after IDCT scaling */
177
    /* Size in samples, after IDCT scaling */
248
    compptr->downsampled_width = (JDIMENSION)
178
    compptr->downsampled_width = (JDIMENSION)
249
      jdiv_round_up((long) cinfo->image_width *
179
      jdiv_round_up((long) cinfo->image_width *
250
		    (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
180
		    (long) (compptr->h_samp_factor * compptr->_DCT_scaled_size),
251
		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
181
		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
252
    compptr->downsampled_height = (JDIMENSION)
182
    compptr->downsampled_height = (JDIMENSION)
253
      jdiv_round_up((long) cinfo->image_height *
183
      jdiv_round_up((long) cinfo->image_height *
254
		    (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
184
		    (long) (compptr->v_samp_factor * compptr->_DCT_scaled_size),
255
		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
185
		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
256
  }
186
  }
257
187
258
#else /* !IDCT_SCALING_SUPPORTED */
188
#else /* !IDCT_SCALING_SUPPORTED */
259
189
260
  /* Hardwire it to "no scaling" */
190
  /* Hardwire it to "no scaling" */
261
  cinfo->output_width = cinfo->image_width;
191
  cinfo->output_width = cinfo->image_width;
262
  cinfo->output_height = cinfo->image_height;
192
  cinfo->output_height = cinfo->image_height;
 Lines 268-287   jpeg_calc_output_dimensions (j_decompres Link Here 
268
198
269
  /* Report number of components in selected colorspace. */
199
  /* Report number of components in selected colorspace. */
270
  /* Probably this should be in the color conversion module... */
200
  /* Probably this should be in the color conversion module... */
271
  switch (cinfo->out_color_space) {
201
  switch (cinfo->out_color_space) {
272
  case JCS_GRAYSCALE:
202
  case JCS_GRAYSCALE:
273
    cinfo->out_color_components = 1;
203
    cinfo->out_color_components = 1;
274
    break;
204
    break;
275
  case JCS_RGB:
205
  case JCS_RGB:
276
#if RGB_PIXELSIZE != 3
206
  case JCS_EXT_RGB:
277
    cinfo->out_color_components = RGB_PIXELSIZE;
207
  case JCS_EXT_RGBX:
208
  case JCS_EXT_BGR:
209
  case JCS_EXT_BGRX:
210
  case JCS_EXT_XBGR:
211
  case JCS_EXT_XRGB:
212
    cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
278
    break;
213
    break;
279
#endif /* else share code with YCbCr */
280
  case JCS_YCbCr:
214
  case JCS_YCbCr:
281
    cinfo->out_color_components = 3;
215
    cinfo->out_color_components = 3;
282
    break;
216
    break;
283
  case JCS_CMYK:
217
  case JCS_CMYK:
284
  case JCS_YCCK:
218
  case JCS_YCCK:
285
    cinfo->out_color_components = 4;
219
    cinfo->out_color_components = 4;
286
    break;
220
    break;
287
  default:			/* else must be same colorspace as in file */
221
  default:			/* else must be same colorspace as in file */
 Lines 341-364   jpeg_calc_output_dimensions (j_decompres Link Here 
341
 * Note that the table is allocated in near data space on PCs; it's small
275
 * Note that the table is allocated in near data space on PCs; it's small
342
 * enough and used often enough to justify this.
276
 * enough and used often enough to justify this.
343
 */
277
 */
344
278
345
LOCAL(void)
279
LOCAL(void)
346
prepare_range_limit_table (j_decompress_ptr cinfo)
280
prepare_range_limit_table (j_decompress_ptr cinfo)
347
/* Allocate and fill in the sample_range_limit table */
281
/* Allocate and fill in the sample_range_limit table */
348
{
282
{
349
  /* Use a static table and allow negative subscripts of simple table */
350
351
  cinfo->sample_range_limit = (JSAMPLE *) static_range_table + (MAXJSAMPLE+1);
352
353
  /* This code is used to create the values for the static table used above */
354
355
#if 0
356
357
  JSAMPLE * table;
283
  JSAMPLE * table;
358
  int i;
284
  int i;
359
285
360
  table = (JSAMPLE *)
286
  table = (JSAMPLE *)
361
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
287
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
362
		(5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
288
		(5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
363
  table += (MAXJSAMPLE+1);	/* allow negative subscripts of simple table */
289
  table += (MAXJSAMPLE+1);	/* allow negative subscripts of simple table */
364
  cinfo->sample_range_limit = table;
290
  cinfo->sample_range_limit = table;
 Lines 371-389   prepare_range_limit_table (j_decompress_ Link Here 
371
  /* End of simple table, rest of first half of post-IDCT table */
297
  /* End of simple table, rest of first half of post-IDCT table */
372
  for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
298
  for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
373
    table[i] = MAXJSAMPLE;
299
    table[i] = MAXJSAMPLE;
374
  /* Second half of post-IDCT table */
300
  /* Second half of post-IDCT table */
375
  MEMZERO(table + (2 * (MAXJSAMPLE+1)),
301
  MEMZERO(table + (2 * (MAXJSAMPLE+1)),
376
	  (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
302
	  (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
377
  MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
303
  MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
378
	  cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
304
	  cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
379
305
}
380
#endif /* 0 */
381
}
382
306
383
307
384
/*
308
/*
385
 * Master selection of decompression modules.
309
 * Master selection of decompression modules.
386
 * This is done once at jpeg_start_decompress time.  We determine
310
 * This is done once at jpeg_start_decompress time.  We determine
387
 * which modules will be used and give them appropriate initialization calls.
311
 * which modules will be used and give them appropriate initialization calls.
388
 * We also initialize the decompressor input side to begin consuming data.
312
 * We also initialize the decompressor input side to begin consuming data.
389
 *
313
 *
 Lines 476-492   master_selection (j_decompress_ptr cinfo Link Here 
476
      jinit_upsampler(cinfo);
400
      jinit_upsampler(cinfo);
477
    }
401
    }
478
    jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
402
    jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
479
  }
403
  }
480
  /* Inverse DCT */
404
  /* Inverse DCT */
481
  jinit_inverse_dct(cinfo);
405
  jinit_inverse_dct(cinfo);
482
  /* Entropy decoding: either Huffman or arithmetic coding. */
406
  /* Entropy decoding: either Huffman or arithmetic coding. */
483
  if (cinfo->arith_code) {
407
  if (cinfo->arith_code) {
408
#ifdef D_ARITH_CODING_SUPPORTED
409
    jinit_arith_decoder(cinfo);
410
#else
484
    ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
411
    ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
412
#endif
485
  } else {
413
  } else {
486
    if (cinfo->progressive_mode) {
414
    if (cinfo->progressive_mode) {
487
#ifdef D_PROGRESSIVE_SUPPORTED
415
#ifdef D_PROGRESSIVE_SUPPORTED
488
      jinit_phuff_decoder(cinfo);
416
      jinit_phuff_decoder(cinfo);
489
#else
417
#else
490
      ERREXIT(cinfo, JERR_NOT_COMPILED);
418
      ERREXIT(cinfo, JERR_NOT_COMPILED);
491
#endif
419
#endif
492
    } else
420
    } else
(-)a/jpeg/jdmerge.c (-660 / +45 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jdmerge.c
2
 * jdmerge.c
3
 *
3
 *
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
4
 * Copyright (C) 1994-1996, Thomas G. Lane.
5
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
 * Copyright (C) 2009, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
7
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
8
 * For conditions of distribution and use, see the accompanying README file.
7
 *
9
 *
8
 * This file contains code for merged upsampling/color conversion.
10
 * This file contains code for merged upsampling/color conversion.
9
 *
11
 *
10
 * This file combines functions from jdsample.c and jdcolor.c;
12
 * This file combines functions from jdsample.c and jdcolor.c;
11
 * read those files first to understand what's going on.
13
 * read those files first to understand what's going on.
12
 *
14
 *
 Lines 30-61    Link Here 
30
 * Other special cases could be added, but in most applications these are
32
 * Other special cases could be added, but in most applications these are
31
 * the only common cases.  (For uncommon cases we fall back on the more
33
 * the only common cases.  (For uncommon cases we fall back on the more
32
 * general code in jdsample.c and jdcolor.c.)
34
 * general code in jdsample.c and jdcolor.c.)
33
 */
35
 */
34
36
35
#define JPEG_INTERNALS
37
#define JPEG_INTERNALS
36
#include "jinclude.h"
38
#include "jinclude.h"
37
#include "jpeglib.h"
39
#include "jpeglib.h"
40
#include "jsimd.h"
38
41
39
#ifdef UPSAMPLE_MERGING_SUPPORTED
42
#ifdef UPSAMPLE_MERGING_SUPPORTED
40
43
41
#ifdef HAVE_MMX_INTEL_MNEMONICS
42
  __int64 const1 = 0x59BA0000D24B59BA;       // Cr_r Cr_b Cr_g Cr_r
43
  __int64 const2 = 0x00007168E9FA0000;		 // Cb-r Cb_b Cb_g Cb_r
44
  __int64 const5 = 0x0000D24B59BA0000;		 // Cr_b Cr_g Cr_r Cr_b
45
  __int64 const6 = 0x7168E9FA00007168;		 // Cb_b Cb_g Cb_r Cb_b
46
47
  // constants for factors (One_Half/fix(x)) << 2
48
49
  __int64 const05 = 0x0001000000000001;	// Cr_r Cr_b Cr_g Cr_r
50
  __int64 const15 = 0x00000001FFFA0000;	// Cb-r Cb_b Cb_g Cb_r
51
  __int64 const45 = 0x0000000000010000;	// Cr_b Cr_g Cr_r Cr_b
52
  __int64 const55 = 0x0001FFFA00000001;	// Cb_b Cb_g Cb_r Cb_b
53
#endif
54
44
55
/* Private subobject */
45
/* Private subobject */
56
46
57
typedef struct {
47
typedef struct {
58
  struct jpeg_upsampler pub;	/* public fields */
48
  struct jpeg_upsampler pub;	/* public fields */
59
49
60
  /* Pointer to routine to do actual upsampling/conversion of one row group */
50
  /* Pointer to routine to do actual upsampling/conversion of one row group */
61
  JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
51
  JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
 Lines 235-253   merged_1v_upsample (j_decompress_ptr cin Link Here 
235
 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
225
 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
236
 */
226
 */
237
227
238
METHODDEF(void)
228
METHODDEF(void)
239
h2v1_merged_upsample (j_decompress_ptr cinfo,
229
h2v1_merged_upsample (j_decompress_ptr cinfo,
240
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
230
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
241
		      JSAMPARRAY output_buf)
231
		      JSAMPARRAY output_buf)
242
{
232
{
243
 
233
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
244
245
 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
246
  register int y, cred, cgreen, cblue;
234
  register int y, cred, cgreen, cblue;
247
  int cb, cr;
235
  int cb, cr;
248
  register JSAMPROW outptr;
236
  register JSAMPROW outptr;
249
  JSAMPROW inptr0, inptr1, inptr2;
237
  JSAMPROW inptr0, inptr1, inptr2;
250
  JDIMENSION col;
238
  JDIMENSION col;
251
  /* copy these pointers into registers if possible */
239
  /* copy these pointers into registers if possible */
252
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
240
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
253
  int * Crrtab = upsample->Cr_r_tab;
241
  int * Crrtab = upsample->Cr_r_tab;
 Lines 265-344   h2v1_merged_upsample (j_decompress_ptr c Link Here 
265
    /* Do the chroma part of the calculation */
253
    /* Do the chroma part of the calculation */
266
    cb = GETJSAMPLE(*inptr1++);
254
    cb = GETJSAMPLE(*inptr1++);
267
    cr = GETJSAMPLE(*inptr2++);
255
    cr = GETJSAMPLE(*inptr2++);
268
    cred = Crrtab[cr];
256
    cred = Crrtab[cr];
269
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
257
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
270
    cblue = Cbbtab[cb];
258
    cblue = Cbbtab[cb];
271
    /* Fetch 2 Y values and emit 2 pixels */
259
    /* Fetch 2 Y values and emit 2 pixels */
272
    y  = GETJSAMPLE(*inptr0++);
260
    y  = GETJSAMPLE(*inptr0++);
273
    outptr[RGB_RED] =   range_limit[y + cred];
261
    outptr[rgb_red[cinfo->out_color_space]] =   range_limit[y + cred];
274
    outptr[RGB_GREEN] = range_limit[y + cgreen];
262
    outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
275
    outptr[RGB_BLUE] =  range_limit[y + cblue];
263
    outptr[rgb_blue[cinfo->out_color_space]] =  range_limit[y + cblue];
276
    outptr += RGB_PIXELSIZE;
264
    outptr += rgb_pixelsize[cinfo->out_color_space];
277
    y  = GETJSAMPLE(*inptr0++);
265
    y  = GETJSAMPLE(*inptr0++);
278
    outptr[RGB_RED] =   range_limit[y + cred];
266
    outptr[rgb_red[cinfo->out_color_space]] =   range_limit[y + cred];
279
    outptr[RGB_GREEN] = range_limit[y + cgreen];
267
    outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
280
    outptr[RGB_BLUE] =  range_limit[y + cblue];
268
    outptr[rgb_blue[cinfo->out_color_space]] =  range_limit[y + cblue];
281
    outptr += RGB_PIXELSIZE;
269
    outptr += rgb_pixelsize[cinfo->out_color_space];
282
  }
270
  }
283
  /* If image width is odd, do the last output column separately */
271
  /* If image width is odd, do the last output column separately */
284
  if (cinfo->output_width & 1) {
272
  if (cinfo->output_width & 1) {
285
    cb = GETJSAMPLE(*inptr1);
273
    cb = GETJSAMPLE(*inptr1);
286
    cr = GETJSAMPLE(*inptr2);
274
    cr = GETJSAMPLE(*inptr2);
287
    cred = Crrtab[cr];
275
    cred = Crrtab[cr];
288
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
276
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
289
    cblue = Cbbtab[cb];
277
    cblue = Cbbtab[cb];
290
    y  = GETJSAMPLE(*inptr0);
278
    y  = GETJSAMPLE(*inptr0);
291
    outptr[RGB_RED] =   range_limit[y + cred];
279
    outptr[rgb_red[cinfo->out_color_space]] =   range_limit[y + cred];
292
    outptr[RGB_GREEN] = range_limit[y + cgreen];
280
    outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
293
    outptr[RGB_BLUE] =  range_limit[y + cblue];
281
    outptr[rgb_blue[cinfo->out_color_space]] =  range_limit[y + cblue];
294
  }
282
  }
295
}
283
}
296
284
297
285
298
/*
286
/*
299
 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
287
 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
300
 */
288
 */
301
289
302
#ifdef HAVE_MMX_INTEL_MNEMONICS
303
__inline METHODDEF(void)
304
h2v2_merged_upsample_orig (j_decompress_ptr cinfo,
305
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
306
		      JSAMPARRAY output_buf);
307
__inline METHODDEF(void)
308
h2v2_merged_upsample_mmx (j_decompress_ptr cinfo,
309
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
310
		      JSAMPARRAY output_buf);
311
#endif
312
 
313
METHODDEF(void)
314
h2v2_merged_upsample (j_decompress_ptr cinfo,
315
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
316
		      JSAMPARRAY output_buf);
317
318
#ifdef HAVE_MMX_INTEL_MNEMONICS
319
METHODDEF(void)
290
METHODDEF(void)
320
h2v2_merged_upsample (j_decompress_ptr cinfo,
291
h2v2_merged_upsample (j_decompress_ptr cinfo,
321
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
292
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
322
		      JSAMPARRAY output_buf)
293
		      JSAMPARRAY output_buf)
323
{
294
{
324
if (MMXAvailable && (cinfo->image_width >= 8))
325
	h2v2_merged_upsample_mmx (cinfo, input_buf, in_row_group_ctr, output_buf);
326
else
327
	h2v2_merged_upsample_orig (cinfo, input_buf, in_row_group_ctr, output_buf);
328
329
}
330
331
__inline METHODDEF(void)
332
h2v2_merged_upsample_orig (j_decompress_ptr cinfo,
333
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
334
		      JSAMPARRAY output_buf)
335
{
336
337
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
295
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
338
  register int y, cred, cgreen, cblue;
296
  register int y, cred, cgreen, cblue;
339
  int cb, cr;
297
  int cb, cr;
340
  register JSAMPROW outptr0, outptr1;
298
  register JSAMPROW outptr0, outptr1;
341
  JSAMPROW inptr00, inptr01, inptr1, inptr2;
299
  JSAMPROW inptr00, inptr01, inptr1, inptr2;
342
  JDIMENSION col;
300
  JDIMENSION col;
343
  /* copy these pointers into registers if possible */
301
  /* copy these pointers into registers if possible */
344
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
302
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
 Lines 359-990   h2v2_merged_upsample_orig (j_decompress_ Link Here 
359
    /* Do the chroma part of the calculation */
317
    /* Do the chroma part of the calculation */
360
    cb = GETJSAMPLE(*inptr1++);
318
    cb = GETJSAMPLE(*inptr1++);
361
    cr = GETJSAMPLE(*inptr2++);
319
    cr = GETJSAMPLE(*inptr2++);
362
    cred = Crrtab[cr];
320
    cred = Crrtab[cr];
363
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
321
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
364
    cblue = Cbbtab[cb];
322
    cblue = Cbbtab[cb];
365
    /* Fetch 4 Y values and emit 4 pixels */
323
    /* Fetch 4 Y values and emit 4 pixels */
366
    y  = GETJSAMPLE(*inptr00++);
324
    y  = GETJSAMPLE(*inptr00++);
367
    outptr0[RGB_RED] =   range_limit[y + cred];
325
    outptr0[rgb_red[cinfo->out_color_space]] =   range_limit[y + cred];
368
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
326
    outptr0[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
369
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
327
    outptr0[rgb_blue[cinfo->out_color_space]] =  range_limit[y + cblue];
370
    outptr0 += RGB_PIXELSIZE;
328
    outptr0 += RGB_PIXELSIZE;
371
    y  = GETJSAMPLE(*inptr00++);
329
    y  = GETJSAMPLE(*inptr00++);
372
    outptr0[RGB_RED] =   range_limit[y + cred];
330
    outptr0[rgb_red[cinfo->out_color_space]] =   range_limit[y + cred];
373
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
331
    outptr0[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
374
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
332
    outptr0[rgb_blue[cinfo->out_color_space]] =  range_limit[y + cblue];
375
    outptr0 += RGB_PIXELSIZE;
333
    outptr0 += RGB_PIXELSIZE;
376
    y  = GETJSAMPLE(*inptr01++);
334
    y  = GETJSAMPLE(*inptr01++);
377
    outptr1[RGB_RED] =   range_limit[y + cred];
335
    outptr1[rgb_red[cinfo->out_color_space]] =   range_limit[y + cred];
378
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
336
    outptr1[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
379
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
337
    outptr1[rgb_blue[cinfo->out_color_space]] =  range_limit[y + cblue];
380
    outptr1 += RGB_PIXELSIZE;
338
    outptr1 += RGB_PIXELSIZE;
381
    y  = GETJSAMPLE(*inptr01++);
339
    y  = GETJSAMPLE(*inptr01++);
382
    outptr1[RGB_RED] =   range_limit[y + cred];
340
    outptr1[rgb_red[cinfo->out_color_space]] =   range_limit[y + cred];
383
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
341
    outptr1[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
384
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
342
    outptr1[rgb_blue[cinfo->out_color_space]] =  range_limit[y + cblue];
385
    outptr1 += RGB_PIXELSIZE;
343
    outptr1 += RGB_PIXELSIZE;
386
  }
344
  }
387
  /* If image width is odd, do the last output column separately */
345
  /* If image width is odd, do the last output column separately */
388
  if (cinfo->output_width & 1) {
346
  if (cinfo->output_width & 1) {
389
    cb = GETJSAMPLE(*inptr1);
347
    cb = GETJSAMPLE(*inptr1);
390
    cr = GETJSAMPLE(*inptr2);
348
    cr = GETJSAMPLE(*inptr2);
391
    cred = Crrtab[cr];
349
    cred = Crrtab[cr];
392
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
350
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
393
    cblue = Cbbtab[cb];
351
    cblue = Cbbtab[cb];
394
    y  = GETJSAMPLE(*inptr00);
352
    y  = GETJSAMPLE(*inptr00);
395
    outptr0[RGB_RED] =   range_limit[y + cred];
353
    outptr0[rgb_red[cinfo->out_color_space]] =   range_limit[y + cred];
396
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
354
    outptr0[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
397
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
355
    outptr0[rgb_blue[cinfo->out_color_space]] =  range_limit[y + cblue];
398
    y  = GETJSAMPLE(*inptr01);
356
    y  = GETJSAMPLE(*inptr01);
399
    outptr1[RGB_RED] =   range_limit[y + cred];
357
    outptr1[rgb_red[cinfo->out_color_space]] =   range_limit[y + cred];
400
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
358
    outptr1[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
401
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
359
    outptr1[rgb_blue[cinfo->out_color_space]] =  range_limit[y + cblue];
402
  }
360
  }
403
}
361
}
404
405
/*
406
 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
407
 */
408
__inline METHODDEF(void)
409
h2v2_merged_upsample_mmx (j_decompress_ptr cinfo,
410
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
411
		      JSAMPARRAY output_buf)
412
{
413
	// added for MMX
414
  __int64 const128 = 0x0080008000800080;
415
  __int64 empty = 0x0000000000000000;
416
  __int64 davemask = 0x0000FFFFFFFF0000;
417
  ////////////////////////////////
418
419
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
420
  register int y, cred, cgreen, cblue;
421
  int cb, cr;
422
  register JSAMPROW outptr0, outptr1;
423
  JSAMPROW inptr00, inptr01, inptr1, inptr2;
424
  JDIMENSION col;
425
  /* copy these pointers into registers if possible */
426
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
427
  int * Crrtab = upsample->Cr_r_tab;
428
  int * Cbbtab = upsample->Cb_b_tab;
429
  INT32 * Crgtab = upsample->Cr_g_tab;
430
  INT32 * Cbgtab = upsample->Cb_g_tab;
431
  SHIFT_TEMPS
432
  
433
434
  // Added for MMX	  
435
  register int width = cinfo->image_width;
436
  int cols = cinfo->output_width;
437
  int cols_asm = (cols >> 3);
438
  int diff = cols - (cols_asm<<3);
439
  int cols_asm_copy = cols_asm;
440
441
 ///////////////////////////////////////
442
443
  inptr00 = input_buf[0][in_row_group_ctr*2];
444
  inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
445
  inptr1 = input_buf[1][in_row_group_ctr];
446
  inptr2 = input_buf[2][in_row_group_ctr];
447
  outptr0 = output_buf[0];
448
  outptr1 = output_buf[1];
449
  /* Loop for each group of output pixels */
450
451
	   
452
  _asm
453
  {
454
	  mov esi, inptr00
455
456
	  mov eax, inptr01
457
	  
458
	  mov ebx, inptr2
459
460
	  mov ecx, inptr1
461
462
	  mov edi, outptr0
463
464
	  mov edx, outptr1
465
466
do_next16:
467
	  
468
	  movd mm0, [ebx]			; Cr7 Cr6.....Cr1 Cr0
469
470
	  pxor mm6, mm6
471
472
	  punpcklbw mm0, mm0		; Cr3 Cr3 Cr2 Cr2 Cr1 Cr1 Cr0 Cr0
473
474
	  movq mm7, const128
475
476
	  punpcklwd mm0, mm0		; Cr1 Cr1 Cr1 Cr1 Cr0 Cr0 Cr0 Cr0
477
478
	  movq mm4, mm0
479
480
	  punpcklbw mm0, mm6		; Cr0 Cr0 Cr0 Cr0
481
482
	  psubsw mm0, mm7			; Cr0 - 128:Cr0-128:Cr0-128:Cr0 -128
483
	  
484
	  movd mm1, [ecx]			; Cb7 Cb6...... Cb1 Cb0
485
	  	   
486
	  psllw mm0, 2				; left shift by 2 bits
487
488
	  punpcklbw mm1, mm1		; Cb3 Cb3 Cb2 Cb2 Cb1 Cb1 Cb0 Cb0
489
	  
490
	  paddsw mm0, const05		; add (one_half/fix(x)) << 2
491
492
	  punpcklwd mm1, mm1		; Cb1 Cb1 Cb1 Cb1 Cb0 Cb0 Cb0 Cb0
493
494
	  movq mm5, mm1
495
496
	  pmulhw mm0, const1		; multiply by (fix(x) >> 1) 
497
498
	  punpcklbw mm1, mm6		; Cb0 Cb0 Cb0 Cb0
499
500
	  punpckhbw mm4, mm6		; Cr1 Cr1 Cr1 Cr1
501
502
	  psubsw mm1, mm7			; Cb0 - 128:Cb0-128:Cb0-128:Cb0 -128
503
504
	  punpckhbw mm5, mm6		; Cb1 Cb1 Cb1 Cb1
505
506
	  psllw mm1, 2				; left shift by 2 bits
507
 
508
	  paddsw mm1, const15		; add (one_half/fix(x)) << 2
509
510
	  psubsw mm4, mm7			; Cr1 - 128:Cr1-128:Cr1-128:Cr1 -128
511
						
512
	  psubsw mm5, mm7			; Cb1 - 128:Cb1-128:Cb1-128:Cb1 -128
513
514
	  pmulhw mm1, const2		; multiply by (fix(x) >> 1) 
515
516
	  psllw mm4, 2				; left shift by 2 bits
517
518
	  psllw mm5, 2				; left shift by 2 bits
519
520
	  paddsw mm4, const45		; add (one_half/fix(x)) << 2
521
522
	  movd mm7, [esi]			;  Y13 Y12 Y9 Y8 Y5 Y4 Y1 Y0
523
524
	  pmulhw mm4, const5		; multiply by (fix(x) >> 1) 
525
526
	  movq mm6, mm7
527
528
	  punpcklbw mm7, mm7		; Y5 Y5 Y4 Y4 Y1 Y1 Y0 Y0
529
530
	  paddsw mm5, const55		; add (one_half/fix(x)) << 2
531
532
	  paddsw  mm0, mm1			; cred0 cbl0 cgr0 cred0
533
534
	  movq mm1, mm7
535
536
	  pmulhw mm5, const6		; multiply by (fix(x) >> 1) 
537
538
	  movq	mm2, mm0			; cred0 cbl0 cgr0 cred0
539
540
	  punpcklwd mm7, mm6		; Y5 Y4 Y1 Y1 Y1 Y0 Y0 Y0
541
542
	  pand mm2, davemask		; 0 cbl0 cgr0 0
543
544
	  psrlq mm1, 16				; 0 0 Y5 Y5 Y4 Y4 Y1 Y1
545
546
	  psrlq	mm2, 16				; 0 0 cbl0 cgr0
547
548
	  punpcklbw mm7, empty		; Y1 Y0 Y0 Y0
549
550
	  paddsw mm4, mm5			; cbl1 cgr1 cred1 cbl1
551
552
	  movq	mm3, mm4			; cbl1 cgr1 cred1 cbl1
553
554
	  pand	mm3, davemask		; 0 cgr1 cred1 0
555
556
	  paddsw mm7, mm0			; r1 b0 g0 r0
557
558
	  psllq	mm3, 16				; cgr1 cred1 0 0
559
560
	  movq mm6, mm1				; 0 0 Y5 Y5 Y4 Y4 Y1 Y1
561
	
562
	  por	mm2, mm3			; cgr1 cred1 cbl0 cgr0
563
564
	  punpcklbw mm6, empty		; Y4 Y4 Y1 Y1
565
566
	  movd mm3, [eax]			; Y15 Y14 Y11 Y10 Y7 Y6 Y3 Y2
567
	  
568
	  paddsw mm6, mm2			; g4 r4 b1 g1
569
570
	  packuswb mm7, mm6			; g4 r4 b1 g1 r1 b0 g0 r0
571
572
	  movq mm6, mm3				; Y15 Y14 Y11 Y10 Y7 Y6 Y3 Y2
573
574
	  punpcklbw mm3, mm3		; Y7 Y7 Y6 Y6 Y3 Y3 Y2 Y2
575
576
	  movq [edi], mm7			; move to memory g4 r4 b1 g1 r1 b0 g0 r0
577
578
	  movq mm5, mm3				; Y7 Y7 Y6 Y6 Y3 Y3 Y2 Y2
579
580
	  punpcklwd mm3, mm6		; X X X X Y3 Y2 Y2 Y2
581
582
	  punpcklbw mm3, empty		; Y3 Y2 Y2 Y2
583
584
	  psrlq mm5, 16				; 0 0 Y7 Y7 Y6 Y6 Y3 Y3
585
586
	  paddsw mm3, mm0			; r3 b2 g2 r2
587
588
	  movq mm6, mm5				; 0 0 Y7 Y7 Y6 Y6 Y3 Y3
589
590
	  movq mm0, mm1				; 0 0 Y5 Y5 Y4 Y4 Y1 Y1
591
592
	  punpckldq mm6, mm6		; X X X X Y6 Y6 Y3 Y3
593
594
	  punpcklbw mm6, empty		; Y6 Y6 Y3 Y3
595
596
	  psrlq mm1, 24				; 0 0 0 0 0 Y5 Y5 Y4
597
	  
598
	  paddsw mm6, mm2			; g6 r6 b3 g3
599
600
	  packuswb mm3, mm6			; g6 r6 b3 g3 r3 b2 g2 r2
601
602
	  movq mm2, mm5				; 0 0 Y7 Y7 Y6 Y6 Y3 Y3
603
604
	  psrlq mm0, 32				; 0 0 0 0 0 0 Y5 Y5
605
606
	  movq [edx], mm3			; move to memory g6 r6 b3 g3 r3 b2 g2 r2
607
	  
608
	  punpcklwd mm1, mm0		; X X X X Y5 Y5 Y5 Y4
609
610
	  psrlq mm5, 24				; 0 0 0 0 0 Y7 Y7 Y6 
611
612
	  movd mm0, [ebx]			; Cr9 Cr8.....Cr3 Cr2
613
614
	  psrlq mm2, 32	   			; 0 0 0 0 0 0 Y7 Y7	 
615
	  
616
	  psrlq	mm0, 16		
617
618
	  punpcklbw mm1, empty		; Y5 Y5 Y5 Y4
619
620
	  punpcklwd mm5, mm2		; X X X X Y7 Y7 Y7 Y6
621
622
	  paddsw mm1, mm4			; b5 g5 r5 b4
623
	 
624
	  punpcklbw mm5, empty		; Y7 Y7 Y7 Y6	    
625
626
	  pxor mm6, mm6				; clear mm6 registr
627
	  
628
	  punpcklbw mm0, mm0		; X X X X Cr3 Cr3 Cr2 Cr2
629
  
630
	  paddsw mm5, mm4			; b7 g7 r7 b6
631
	  
632
	  punpcklwd mm0, mm0		; Cr3 Cr3 Cr3 Cr3 Cr2 Cr2 Cr2 Cr2
633
634
	  movq mm4, mm0
635
636
	  movd mm3, [ecx]			; Cb9 Cb8...... Cb3 Cb2
637
	  
638
	  punpcklbw mm0, mm6		; Cr2 Cr2 Cr2 Cr2
639
640
	  psrlq	mm3, 16
641
642
	  psubsw mm0, const128		; Cr2 - 128:Cr2-128:Cr2-128:Cr2 -128
643
644
	  punpcklbw mm3, mm3		; X X X X Cb3 Cb3 Cb2 Cb2
645
646
	  psllw mm0, 2				; left shift by 2 bits
647
648
	  paddsw mm0, const05		; add (one_half/fix(x)) << 2
649
650
	  punpcklwd mm3, mm3		; Cb3 Cb3 Cb3 Cb3 Cb2 Cb2 Cb2 Cb2
651
652
	  movq mm7, mm3
653
	  
654
	  pmulhw mm0, const1		; multiply by (fix(x) >> 1) 	  	  
655
656
	  punpcklbw mm3, mm6		; Cb2 Cb2 Cb2 Cb2
657
658
	  psubsw mm3, const128		; Cb0 - 128:Cb0-128:Cb0-128:Cb0 -128
659
660
	  punpckhbw mm4, mm6		; Cr3 Cr3 Cr3 Cr3
661
	  
662
	  psllw mm3, 2				; left shift by 2 bits
663
664
	  paddsw mm3, const15		; add (one_half/fix(x)) << 2
665
666
	  punpckhbw mm7, mm6		; Cb3 Cb3 Cb3 Cb3
667
668
	  pmulhw mm3, const2		; multiply by (fix(x) >> 1) 
669
	  
670
	  psubsw mm7, const128		; Cb3 - 128:Cb3-128:Cb3-128:Cb3 -128
671
672
	  paddsw  mm0, mm3			; cred2 cbl2 cgr2 cred2
673
	    
674
	  psllw mm7, 2				; left shift by 2 bits
675
676
	  psubsw mm4, const128		; Cr3 - 128:Cr3-128:Cr3-128:Cr3 -128
677
	  
678
	  movd mm3, [esi+4]			;  Y21 Y20 Y17 Y16 Y13 Y12 Y9 Y8
679
	  
680
	  psllw mm4, 2				; left shift by 2 bits
681
682
	  paddsw mm7, const55		; add (one_half/fix(x)) << 2
683
	  	  
684
	  movq mm6, mm3				;  Y21 Y20 Y17 Y16 Y13 Y12 Y9 Y8
685
686
	  movq	mm2, mm0
687
	  	  
688
	  pand mm2, davemask
689
690
	  punpcklbw mm3, mm3		; Y13 Y13 Y12 Y12 Y9 Y9 Y8 Y8
691
692
	  psrlq	mm2, 16
693
	    	  
694
	  paddsw mm4, const45		; add (one_half/fix(x)) << 2
695
696
	  punpcklwd mm3, mm6		; X X X X Y9 Y8 Y8 Y8
697
	  
698
	  pmulhw mm4, const5		; multiply by (fix(x) >> 1) 
699
700
	  pmulhw mm7, const6		; multiply by (fix(x) >> 1) 
701
702
	  punpcklbw mm3, empty		; Y9 Y8 Y8 Y8
703
	  
704
	  paddsw mm4, mm7			; cbl3 cgr3 cred3 cbl3
705
706
	  paddsw mm3, mm0			; r9 b8 g8 r8
707
708
	  movq	mm7, mm4
709
710
	  packuswb mm1, mm3			; r9 b8 g8 r8 b5 g5 r5 b4
711
712
	  movd mm3, [eax+4]			; Y23 Y22 Y19 Y18 Y15 Y14 Y11 Y10
713
 	  
714
	  pand	mm7, davemask
715
716
	  psrlq mm6, 8				; 0 Y21 Y20 Y17 Y16 Y13 Y12 Y9
717
718
	  psllq	mm7, 16
719
						   
720
	  movq [edi+8], mm1			; move to memory r9 b8 g8 r8 b5 g5 r5 b4
721
722
	  por	mm2, mm7
723
724
	  movq mm7, mm3				; Y23 Y22 Y19 Y18 Y15 Y14 Y11 Y10
725
726
	  punpcklbw mm3, mm3		; X X X X Y11 Y11 Y10 Y10
727
728
	  pxor mm1, mm1
729
730
	  punpcklwd mm3, mm7		; X X X X Y11 Y10 Y10 Y10
731
732
	  punpcklbw mm3, mm1		; Y11 Y10 Y10 Y10
733
734
	  psrlq mm7, 8				; 0 Y23 Y22 Y19 Y18 Y15 Y14 Y11
735
	  
736
	  paddsw mm3, mm0			; r11 b10 g10 r10
737
738
	  movq mm0, mm7				; 0 Y23 Y22 Y19 Y18 Y15 Y14 Y11
739
740
	  packuswb mm5, mm3			; r11 b10 g10 r10 b7 g7 r7 b6
741
742
	  punpcklbw mm7, mm7		; X X X X Y14 Y14 Y11 Y11
743
744
	  movq [edx+8], mm5			; move to memory r11 b10 g10 r10 b7 g7 r7 b6
745
746
	  movq mm3, mm6				; 0 Y21 Y20 Y17 Y16 Y13 Y12 Y9
747
748
	  punpcklbw mm6, mm6		; X X X X Y12 Y12 Y9 Y9
749
750
	  punpcklbw mm7, mm1		; Y14 Y14 Y11 Y11
751
752
	  punpcklbw mm6, mm1		; Y12 Y12 Y9 Y9
753
754
	  paddsw mm7, mm2			; g14 r14 b11 g11
755
756
	  paddsw mm6, mm2			; g12 r12 b9 g9
757
758
	  psrlq mm3, 8				; 0 0 Y21 Y20 Y17 Y16 Y13 Y12
759
760
	  movq mm1, mm3				; 0 0 Y21 Y20 Y17 Y16 Y13 Y12
761
762
	  punpcklbw mm3, mm3		; X X X X Y13 Y13 Y12 Y12
763
764
	  add esi, 8
765
766
	  psrlq mm3, 16				; X X X X X X Y13 Y13 modified on 09/24
767
768
	  punpcklwd mm1, mm3		; X X X X Y13 Y13 Y13 Y12
769
770
	  add eax, 8
771
772
	  psrlq mm0, 8				; 0 0 Y23 Y22 Y19 Y18 Y15 Y14	
773
774
	  punpcklbw mm1, empty		; Y13 Y13 Y13 Y12
775
776
	  movq mm5, mm0				; 0 0 Y23 Y22 Y19 Y18 Y15 Y14	
777
778
	  punpcklbw mm0, mm0		; X X X X Y15 Y15 Y14 Y14
779
780
	  paddsw mm1, mm4			; b13 g13 r13 b12
781
782
	  psrlq mm0, 16				; X X X X X X Y15 Y15
783
784
	  add edi, 24
785
	  
786
	  punpcklwd mm5, mm0		; X X X X Y15 Y15 Y15 Y14
787
788
	  packuswb mm6, mm1			; b13 g13 r13 b12 g12 r12 b9 g9
789
790
	  add edx, 24
791
	  
792
	  punpcklbw mm5, empty		; Y15 Y15 Y15 Y14
793
794
	  add ebx, 4
795
	  	  
796
	  paddsw mm5, mm4			; b15 g15 r15 b14
797
798
	  movq [edi-8], mm6		; move to memory b13 g13 r13 b12 g12 r12 b9 g9
799
800
	  packuswb mm7, mm5			; b15 g15 r15 b14 g14 r14 b11 g11
801
802
	  add ecx, 4
803
  
804
	  movq [edx-8], mm7		; move to memory b15 g15 r15 b14 g14 r14 b11 g11
805
806
	  dec cols_asm
807
	  
808
	  jnz do_next16
809
810
	  EMMS
811
	  	  
812
	  }
813
814
	  
815
  inptr1 += (cols_asm_copy<<2);
816
817
  inptr2 += (cols_asm_copy<<2);
818
819
  inptr00 += (cols_asm_copy<<3);
820
821
  inptr01 += (cols_asm_copy<<3);
822
823
  outptr0 += cols_asm_copy*24;
824
825
  outptr1 += cols_asm_copy*24;
826
  		  
827
  //for (col = cinfo->output_width >> 1; col > 0; col--) {
828
      /* Do the chroma part of the calculation */
829
    /*cb = GETJSAMPLE(*inptr1++);
830
    cr = GETJSAMPLE(*inptr2++);
831
    cred = Crrtab[cr];
832
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
833
    cblue = Cbbtab[cb];*/
834
    /* Fetch 4 Y values and emit 4 pixels */
835
    /*y  = GETJSAMPLE(*inptr00++);
836
    outptr0[RGB_RED] =   range_limit[y + cred];
837
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
838
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
839
    outptr0 += RGB_PIXELSIZE;
840
    y  = GETJSAMPLE(*inptr00++);
841
    outptr0[RGB_RED] =   range_limit[y + cred];
842
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
843
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
844
    outptr0 += RGB_PIXELSIZE;
845
    y  = GETJSAMPLE(*inptr01++);
846
    outptr1[RGB_RED] =   range_limit[y + cred];
847
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
848
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
849
    outptr1 += RGB_PIXELSIZE;
850
    y  = GETJSAMPLE(*inptr01++);
851
    outptr1[RGB_RED] =   range_limit[y + cred];
852
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
853
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
854
    outptr1 += RGB_PIXELSIZE;
855
  }	  */
856
857
858
  for (col = diff >> 1; col > 0; col--) {
859
      /* Do the chroma part of the calculation */
860
    cb = GETJSAMPLE(*inptr1++);
861
    cr = GETJSAMPLE(*inptr2++);
862
    cred = Crrtab[cr];
863
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
864
    cblue = Cbbtab[cb];
865
    /* Fetch 4 Y values and emit 4 pixels */
866
    y  = GETJSAMPLE(*inptr00++);
867
    outptr0[RGB_RED] =   range_limit[y + cred];
868
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
869
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
870
    outptr0 += RGB_PIXELSIZE;
871
    y  = GETJSAMPLE(*inptr00++);
872
    outptr0[RGB_RED] =   range_limit[y + cred];
873
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
874
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
875
    outptr0 += RGB_PIXELSIZE;
876
    y  = GETJSAMPLE(*inptr01++);
877
    outptr1[RGB_RED] =   range_limit[y + cred];
878
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
879
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
880
    outptr1 += RGB_PIXELSIZE;
881
    y  = GETJSAMPLE(*inptr01++);
882
    outptr1[RGB_RED] =   range_limit[y + cred];
883
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
884
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
885
    outptr1 += RGB_PIXELSIZE;
886
  }	  
887
888
					  
889
  /* If image width is odd, do the last output column separately */
890
  //if (cinfo->output_width & 1) {
891
  if (diff & 1) {
892
    cb = GETJSAMPLE(*inptr1);
893
    cr = GETJSAMPLE(*inptr2);
894
    cred = Crrtab[cr];
895
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
896
    cblue = Cbbtab[cb];
897
    y  = GETJSAMPLE(*inptr00);
898
    outptr0[RGB_RED] =   range_limit[y + cred];
899
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
900
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
901
    y  = GETJSAMPLE(*inptr01);
902
    outptr1[RGB_RED] =   range_limit[y + cred];
903
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
904
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
905
  }    
906
}
907
#else
908
909
910
METHODDEF(void)
911
h2v2_merged_upsample (j_decompress_ptr cinfo,
912
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
913
		      JSAMPARRAY output_buf)
914
{
915
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
916
  register int y, cred, cgreen, cblue;
917
  int cb, cr;
918
  register JSAMPROW outptr0, outptr1;
919
  JSAMPROW inptr00, inptr01, inptr1, inptr2;
920
  JDIMENSION col;
921
  /* copy these pointers into registers if possible */
922
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
923
  int * Crrtab = upsample->Cr_r_tab;
924
  int * Cbbtab = upsample->Cb_b_tab;
925
  INT32 * Crgtab = upsample->Cr_g_tab;
926
  INT32 * Cbgtab = upsample->Cb_g_tab;
927
  SHIFT_TEMPS
928
929
  inptr00 = input_buf[0][in_row_group_ctr*2];
930
  inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
931
  inptr1 = input_buf[1][in_row_group_ctr];
932
  inptr2 = input_buf[2][in_row_group_ctr];
933
  outptr0 = output_buf[0];
934
  outptr1 = output_buf[1];
935
  /* Loop for each group of output pixels */
936
  for (col = cinfo->output_width >> 1; col > 0; col--) {
937
    /* Do the chroma part of the calculation */
938
    cb = GETJSAMPLE(*inptr1++);
939
    cr = GETJSAMPLE(*inptr2++);
940
    cred = Crrtab[cr];
941
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
942
    cblue = Cbbtab[cb];
943
    /* Fetch 4 Y values and emit 4 pixels */
944
    y  = GETJSAMPLE(*inptr00++);
945
    outptr0[RGB_RED] =   range_limit[y + cred];
946
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
947
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
948
    outptr0 += RGB_PIXELSIZE;
949
    y  = GETJSAMPLE(*inptr00++);
950
    outptr0[RGB_RED] =   range_limit[y + cred];
951
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
952
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
953
    outptr0 += RGB_PIXELSIZE;
954
    y  = GETJSAMPLE(*inptr01++);
955
    outptr1[RGB_RED] =   range_limit[y + cred];
956
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
957
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
958
    outptr1 += RGB_PIXELSIZE;
959
    y  = GETJSAMPLE(*inptr01++);
960
    outptr1[RGB_RED] =   range_limit[y + cred];
961
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
962
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
963
    outptr1 += RGB_PIXELSIZE;
964
  }
965
  /* If image width is odd, do the last output column separately */
966
  if (cinfo->output_width & 1) {
967
    cb = GETJSAMPLE(*inptr1);
968
    cr = GETJSAMPLE(*inptr2);
969
    cred = Crrtab[cr];
970
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
971
    cblue = Cbbtab[cb];
972
    y  = GETJSAMPLE(*inptr00);
973
    outptr0[RGB_RED] =   range_limit[y + cred];
974
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
975
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
976
    y  = GETJSAMPLE(*inptr01);
977
    outptr1[RGB_RED] =   range_limit[y + cred];
978
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
979
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
980
  }
981
}
982
#endif
983
362
984
363
985
/*
364
/*
986
 * Module initialization routine for merged upsampling/color conversion.
365
 * Module initialization routine for merged upsampling/color conversion.
987
 *
366
 *
988
 * NB: this is called under the conditions determined by use_merged_upsample()
367
 * NB: this is called under the conditions determined by use_merged_upsample()
989
 * in jdmaster.c.  That routine MUST correspond to the actual capabilities
368
 * in jdmaster.c.  That routine MUST correspond to the actual capabilities
990
 * of this module; no safety checks are made here.
369
 * of this module; no safety checks are made here.
 Lines 1001-1024   jinit_merged_upsampler (j_decompress_ptr Link Here 
1001
  cinfo->upsample = (struct jpeg_upsampler *) upsample;
380
  cinfo->upsample = (struct jpeg_upsampler *) upsample;
1002
  upsample->pub.start_pass = start_pass_merged_upsample;
381
  upsample->pub.start_pass = start_pass_merged_upsample;
1003
  upsample->pub.need_context_rows = FALSE;
382
  upsample->pub.need_context_rows = FALSE;
1004
383
1005
  upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
384
  upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
1006
385
1007
  if (cinfo->max_v_samp_factor == 2) {
386
  if (cinfo->max_v_samp_factor == 2) {
1008
    upsample->pub.upsample = merged_2v_upsample;
387
    upsample->pub.upsample = merged_2v_upsample;
1009
    upsample->upmethod = h2v2_merged_upsample;
388
    if (jsimd_can_h2v2_merged_upsample())
389
      upsample->upmethod = jsimd_h2v2_merged_upsample;
390
    else
391
      upsample->upmethod = h2v2_merged_upsample;
1010
    /* Allocate a spare row buffer */
392
    /* Allocate a spare row buffer */
1011
    upsample->spare_row = (JSAMPROW)
393
    upsample->spare_row = (JSAMPROW)
1012
      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
394
      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
1013
		(size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
395
		(size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
1014
  } else {
396
  } else {
1015
    upsample->pub.upsample = merged_1v_upsample;
397
    upsample->pub.upsample = merged_1v_upsample;
1016
    upsample->upmethod = h2v1_merged_upsample;
398
    if (jsimd_can_h2v1_merged_upsample())
399
      upsample->upmethod = jsimd_h2v1_merged_upsample;
400
    else
401
      upsample->upmethod = h2v1_merged_upsample;
1017
    /* No spare row needed */
402
    /* No spare row needed */
1018
    upsample->spare_row = NULL;
403
    upsample->spare_row = NULL;
1019
  }
404
  }
1020
405
1021
  build_ycc_rgb_table(cinfo);
406
  build_ycc_rgb_table(cinfo);
1022
}
407
}
1023
408
1024
#endif /* UPSAMPLE_MERGING_SUPPORTED */
409
#endif /* UPSAMPLE_MERGING_SUPPORTED */
(-)a/jpeg/jdsample.c (-12 / +30 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jdsample.c
2
 * jdsample.c
3
 *
3
 *
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
5
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
 * Copyright (C) 2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
7
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
8
 * For conditions of distribution and use, see the accompanying README file.
7
 *
9
 *
8
 * This file contains upsampling routines.
10
 * This file contains upsampling routines.
9
 *
11
 *
10
 * Upsampling input data is counted in "row groups".  A row group
12
 * Upsampling input data is counted in "row groups".  A row group
11
 * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
13
 * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
12
 * sample rows of each component.  Upsampling will normally produce
14
 * sample rows of each component.  Upsampling will normally produce
 Lines 16-31    Link Here 
16
 * An excellent reference for image resampling is
18
 * An excellent reference for image resampling is
17
 *   Digital Image Warping, George Wolberg, 1990.
19
 *   Digital Image Warping, George Wolberg, 1990.
18
 *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
20
 *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
19
 */
21
 */
20
22
21
#define JPEG_INTERNALS
23
#define JPEG_INTERNALS
22
#include "jinclude.h"
24
#include "jinclude.h"
23
#include "jpeglib.h"
25
#include "jpeglib.h"
26
#include "jsimd.h"
27
#include "jpegcomp.h"
24
28
25
29
26
/* Pointer to routine to upsample a single component */
30
/* Pointer to routine to upsample a single component */
27
typedef JMETHOD(void, upsample1_ptr,
31
typedef JMETHOD(void, upsample1_ptr,
28
		(j_decompress_ptr cinfo, jpeg_component_info * compptr,
32
		(j_decompress_ptr cinfo, jpeg_component_info * compptr,
29
		 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
33
		 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
30
34
31
/* Private subobject */
35
/* Private subobject */
 Lines 413-469   jinit_upsampler (j_decompress_ptr cinfo) Link Here 
413
  upsample->pub.need_context_rows = FALSE; /* until we find out differently */
417
  upsample->pub.need_context_rows = FALSE; /* until we find out differently */
414
418
415
  if (cinfo->CCIR601_sampling)	/* this isn't supported */
419
  if (cinfo->CCIR601_sampling)	/* this isn't supported */
416
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
420
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
417
421
418
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
422
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
419
   * so don't ask for it.
423
   * so don't ask for it.
420
   */
424
   */
421
  do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
425
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
422
426
423
  /* Verify we can handle the sampling factors, select per-component methods,
427
  /* Verify we can handle the sampling factors, select per-component methods,
424
   * and create storage as needed.
428
   * and create storage as needed.
425
   */
429
   */
426
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
430
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
427
       ci++, compptr++) {
431
       ci++, compptr++) {
428
    /* Compute size of an "input group" after IDCT scaling.  This many samples
432
    /* Compute size of an "input group" after IDCT scaling.  This many samples
429
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
433
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
430
     */
434
     */
431
    h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
435
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
432
		 cinfo->min_DCT_scaled_size;
436
		 cinfo->_min_DCT_scaled_size;
433
    v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
437
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
434
		 cinfo->min_DCT_scaled_size;
438
		 cinfo->_min_DCT_scaled_size;
435
    h_out_group = cinfo->max_h_samp_factor;
439
    h_out_group = cinfo->max_h_samp_factor;
436
    v_out_group = cinfo->max_v_samp_factor;
440
    v_out_group = cinfo->max_v_samp_factor;
437
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
441
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
438
    need_buffer = TRUE;
442
    need_buffer = TRUE;
439
    if (! compptr->component_needed) {
443
    if (! compptr->component_needed) {
440
      /* Don't bother to upsample an uninteresting component. */
444
      /* Don't bother to upsample an uninteresting component. */
441
      upsample->methods[ci] = noop_upsample;
445
      upsample->methods[ci] = noop_upsample;
442
      need_buffer = FALSE;
446
      need_buffer = FALSE;
443
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
447
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
444
      /* Fullsize components can be processed without any work. */
448
      /* Fullsize components can be processed without any work. */
445
      upsample->methods[ci] = fullsize_upsample;
449
      upsample->methods[ci] = fullsize_upsample;
446
      need_buffer = FALSE;
450
      need_buffer = FALSE;
447
    } else if (h_in_group * 2 == h_out_group &&
451
    } else if (h_in_group * 2 == h_out_group &&
448
	       v_in_group == v_out_group) {
452
	       v_in_group == v_out_group) {
449
      /* Special cases for 2h1v upsampling */
453
      /* Special cases for 2h1v upsampling */
450
      if (do_fancy && compptr->downsampled_width > 2)
454
      if (do_fancy && compptr->downsampled_width > 2) {
451
	upsample->methods[ci] = h2v1_fancy_upsample;
455
	if (jsimd_can_h2v1_fancy_upsample())
452
      else
456
	  upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
453
	upsample->methods[ci] = h2v1_upsample;
457
	else
458
	  upsample->methods[ci] = h2v1_fancy_upsample;
459
      } else {
460
	if (jsimd_can_h2v1_upsample())
461
	  upsample->methods[ci] = jsimd_h2v1_upsample;
462
	else
463
	  upsample->methods[ci] = h2v1_upsample;
464
      }
454
    } else if (h_in_group * 2 == h_out_group &&
465
    } else if (h_in_group * 2 == h_out_group &&
455
	       v_in_group * 2 == v_out_group) {
466
	       v_in_group * 2 == v_out_group) {
456
      /* Special cases for 2h2v upsampling */
467
      /* Special cases for 2h2v upsampling */
457
      if (do_fancy && compptr->downsampled_width > 2) {
468
      if (do_fancy && compptr->downsampled_width > 2) {
458
	upsample->methods[ci] = h2v2_fancy_upsample;
469
	if (jsimd_can_h2v2_fancy_upsample())
470
	  upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
471
	else
472
	  upsample->methods[ci] = h2v2_fancy_upsample;
459
	upsample->pub.need_context_rows = TRUE;
473
	upsample->pub.need_context_rows = TRUE;
460
      } else
474
      } else {
461
	upsample->methods[ci] = h2v2_upsample;
475
	if (jsimd_can_h2v2_upsample())
476
	  upsample->methods[ci] = jsimd_h2v2_upsample;
477
	else
478
	  upsample->methods[ci] = h2v2_upsample;
479
      }
462
    } else if ((h_out_group % h_in_group) == 0 &&
480
    } else if ((h_out_group % h_in_group) == 0 &&
463
	       (v_out_group % v_in_group) == 0) {
481
	       (v_out_group % v_in_group) == 0) {
464
      /* Generic integral-factors upsampling method */
482
      /* Generic integral-factors upsampling method */
465
      upsample->methods[ci] = int_upsample;
483
      upsample->methods[ci] = int_upsample;
466
      upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
484
      upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
467
      upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
485
      upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
468
    } else
486
    } else
469
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
487
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
(-)a/jpeg/jdtrans.c (+147 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * jdtrans.c
3
 *
4
 * Copyright (C) 1995-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 library routines for transcoding decompression,
9
 * that is, reading raw DCT coefficient arrays from an input JPEG file.
10
 * The routines in jdapimin.c will also be needed by a transcoder.
11
 */
12
13
#define JPEG_INTERNALS
14
#include "jinclude.h"
15
#include "jpeglib.h"
16
17
18
/* Forward declarations */
19
LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
20
21
22
/*
23
 * Read the coefficient arrays from a JPEG file.
24
 * jpeg_read_header must be completed before calling this.
25
 *
26
 * The entire image is read into a set of virtual coefficient-block arrays,
27
 * one per component.  The return value is a pointer to the array of
28
 * virtual-array descriptors.  These can be manipulated directly via the
29
 * JPEG memory manager, or handed off to jpeg_write_coefficients().
30
 * To release the memory occupied by the virtual arrays, call
31
 * jpeg_finish_decompress() when done with the data.
32
 *
33
 * An alternative usage is to simply obtain access to the coefficient arrays
34
 * during a buffered-image-mode decompression operation.  This is allowed
35
 * after any jpeg_finish_output() call.  The arrays can be accessed until
36
 * jpeg_finish_decompress() is called.  (Note that any call to the library
37
 * may reposition the arrays, so don't rely on access_virt_barray() results
38
 * to stay valid across library calls.)
39
 *
40
 * Returns NULL if suspended.  This case need be checked only if
41
 * a suspending data source is used.
42
 */
43
44
GLOBAL(jvirt_barray_ptr *)
45
jpeg_read_coefficients (j_decompress_ptr cinfo)
46
{
47
  if (cinfo->global_state == DSTATE_READY) {
48
    /* First call: initialize active modules */
49
    transdecode_master_selection(cinfo);
50
    cinfo->global_state = DSTATE_RDCOEFS;
51
  }
52
  if (cinfo->global_state == DSTATE_RDCOEFS) {
53
    /* Absorb whole file into the coef buffer */
54
    for (;;) {
55
      int retcode;
56
      /* Call progress monitor hook if present */
57
      if (cinfo->progress != NULL)
58
	(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
59
      /* Absorb some more input */
60
      retcode = (*cinfo->inputctl->consume_input) (cinfo);
61
      if (retcode == JPEG_SUSPENDED)
62
	return NULL;
63
      if (retcode == JPEG_REACHED_EOI)
64
	break;
65
      /* Advance progress counter if appropriate */
66
      if (cinfo->progress != NULL &&
67
	  (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
68
	if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
69
	  /* startup underestimated number of scans; ratchet up one scan */
70
	  cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
71
	}
72
      }
73
    }
74
    /* Set state so that jpeg_finish_decompress does the right thing */
75
    cinfo->global_state = DSTATE_STOPPING;
76
  }
77
  /* At this point we should be in state DSTATE_STOPPING if being used
78
   * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access
79
   * to the coefficients during a full buffered-image-mode decompression.
80
   */
81
  if ((cinfo->global_state == DSTATE_STOPPING ||
82
       cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
83
    return cinfo->coef->coef_arrays;
84
  }
85
  /* Oops, improper usage */
86
  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
87
  return NULL;			/* keep compiler happy */
88
}
89
90
91
/*
92
 * Master selection of decompression modules for transcoding.
93
 * This substitutes for jdmaster.c's initialization of the full decompressor.
94
 */
95
96
LOCAL(void)
97
transdecode_master_selection (j_decompress_ptr cinfo)
98
{
99
  /* This is effectively a buffered-image operation. */
100
  cinfo->buffered_image = TRUE;
101
102
  /* Entropy decoding: either Huffman or arithmetic coding. */
103
  if (cinfo->arith_code) {
104
#ifdef D_ARITH_CODING_SUPPORTED
105
    jinit_arith_decoder(cinfo);
106
#else
107
    ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
108
#endif
109
  } else {
110
    if (cinfo->progressive_mode) {
111
#ifdef D_PROGRESSIVE_SUPPORTED
112
      jinit_phuff_decoder(cinfo);
113
#else
114
      ERREXIT(cinfo, JERR_NOT_COMPILED);
115
#endif
116
    } else
117
      jinit_huff_decoder(cinfo);
118
  }
119
120
  /* Always get a full-image coefficient buffer. */
121
  jinit_d_coef_controller(cinfo, TRUE);
122
123
  /* We can now tell the memory manager to allocate virtual arrays. */
124
  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
125
126
  /* Initialize input side of decompressor to consume first scan. */
127
  (*cinfo->inputctl->start_input_pass) (cinfo);
128
129
  /* Initialize progress monitoring. */
130
  if (cinfo->progress != NULL) {
131
    int nscans;
132
    /* Estimate number of scans to set pass_limit. */
133
    if (cinfo->progressive_mode) {
134
      /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
135
      nscans = 2 + 3 * cinfo->num_components;
136
    } else if (cinfo->inputctl->has_multiple_scans) {
137
      /* For a nonprogressive multiscan file, estimate 1 scan per component. */
138
      nscans = cinfo->num_components;
139
    } else {
140
      nscans = 1;
141
    }
142
    cinfo->progress->pass_counter = 0L;
143
    cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
144
    cinfo->progress->completed_passes = 0;
145
    cinfo->progress->total_passes = 1;
146
  }
147
}
(-)a/jpeg/jerror.c (-17 / +11 lines)
Line     Link Here 
 Lines 13-35    Link Here 
13
 * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile,
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.
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,
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.
16
 * which is what happens to output to stderr under most Windows C compilers.
17
 *
17
 *
18
 * These routines are used by both the compression and decompression code.
18
 * These routines are used by both the compression and decompression code.
19
 */
19
 */
20
20
21
/*
22
 * This file has been modified for the Mozilla/Netscape environment.
23
 * Modifications are distributed under the mozilla.org tri-license and are
24
 * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
25
 * Reserved. See http://www.mozilla.org/MPL/
26
 */
27
28
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
21
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
29
#include "jinclude.h"
22
#include "jinclude.h"
30
#include "jpeglib.h"
23
#include "jpeglib.h"
31
#include "jversion.h"
24
#include "jversion.h"
32
#include "jerror.h"
25
#include "jerror.h"
33
26
34
#ifdef USE_WINDOWS_MESSAGEBOX
27
#ifdef USE_WINDOWS_MESSAGEBOX
35
#include <windows.h>
28
#include <windows.h>
 Lines 77-102   METHODDEF(void) Link Here 
77
error_exit (j_common_ptr cinfo)
70
error_exit (j_common_ptr cinfo)
78
{
71
{
79
  /* Always display the message */
72
  /* Always display the message */
80
  (*cinfo->err->output_message) (cinfo);
73
  (*cinfo->err->output_message) (cinfo);
81
74
82
  /* Let the memory manager delete any temp files before we die */
75
  /* Let the memory manager delete any temp files before we die */
83
  jpeg_destroy(cinfo);
76
  jpeg_destroy(cinfo);
84
77
85
/* Mozilla mod: in some Windows environments, the exit() function doesn't
86
 * even exist, so don't compile a reference to it.  Heaven help you if
87
 * you fail to provide a replacement error_exit function, because the
88
 * IJG library will NOT handle control returning from error_exit!
89
 */
90
91
#ifndef XP_WIN
92
  exit(EXIT_FAILURE);
78
  exit(EXIT_FAILURE);
93
#endif
79
}
94
}
95
80
96
81
97
/*
82
/*
98
 * Actual output of an error or trace message.
83
 * Actual output of an error or trace message.
99
 * Applications may override this method to send JPEG messages somewhere
84
 * Applications may override this method to send JPEG messages somewhere
100
 * other than stderr.
85
 * other than stderr.
101
 *
86
 *
102
 * On Windows, printing to stderr is generally completely useless,
87
 * On Windows, printing to stderr is generally completely useless,
 Lines 111-127   error_exit (j_common_ptr cinfo) Link Here 
111
96
112
METHODDEF(void)
97
METHODDEF(void)
113
output_message (j_common_ptr cinfo)
98
output_message (j_common_ptr cinfo)
114
{
99
{
115
  char buffer[JMSG_LENGTH_MAX];
100
  char buffer[JMSG_LENGTH_MAX];
116
101
117
  /* Create the message */
102
  /* Create the message */
118
  (*cinfo->err->format_message) (cinfo, buffer);
103
  (*cinfo->err->format_message) (cinfo, buffer);
119
}
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
}
120
114
121
115
122
/*
116
/*
123
 * Decide whether to emit a trace or warning message.
117
 * Decide whether to emit a trace or warning message.
124
 * msg_level is one of:
118
 * msg_level is one of:
125
 *   -1: recoverable corrupt-data warning, may want to abort.
119
 *   -1: recoverable corrupt-data warning, may want to abort.
126
 *    0: important advisory messages (always display to user).
120
 *    0: important advisory messages (always display to user).
127
 *    1: first level of tracing detail.
121
 *    1: first level of tracing detail.
(-)a/jpeg/jerror.h (-1 / +5 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jerror.h
2
 * jerror.h
3
 *
3
 *
4
 * Copyright (C) 1994-1997, Thomas G. Lane.
4
 * Copyright (C) 1994-1997, Thomas G. Lane.
5
 * Modified 1997-2009 by Guido Vollbeding.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file defines the error and message codes for the JPEG library.
9
 * This file defines the error and message codes for the JPEG library.
9
 * Edit this file to add new codes, or to translate the message strings to
10
 * Edit this file to add new codes, or to translate the message strings to
10
 * some other language.
11
 * some other language.
11
 * A set of error-reporting macros are defined too.  Some applications using
12
 * A set of error-reporting macros are defined too.  Some applications using
12
 * the JPEG library may wish to include this file to get the error codes
13
 * the JPEG library may wish to include this file to get the error codes
 Lines 35-55   typedef enum { Link Here 
35
#define JMESSAGE(code,string)	code ,
36
#define JMESSAGE(code,string)	code ,
36
37
37
#endif /* JMAKE_ENUM_LIST */
38
#endif /* JMAKE_ENUM_LIST */
38
39
39
JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
40
JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
40
41
41
/* For maintenance convenience, list is alphabetical by message code name */
42
/* For maintenance convenience, list is alphabetical by message code name */
42
JMESSAGE(JERR_ARITH_NOTIMPL,
43
JMESSAGE(JERR_ARITH_NOTIMPL,
43
	 "Sorry, there are legal restrictions on arithmetic coding")
44
	 "Sorry, arithmetic coding is not implemented")
44
JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
45
JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
45
JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
46
JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
46
JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
47
JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
47
JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
48
JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
49
JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request")
48
JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
50
JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
49
JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
51
JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
50
JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
52
JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
51
JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
53
JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
52
JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
54
JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
53
JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
55
JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
54
JMESSAGE(JERR_BAD_LIB_VERSION,
56
JMESSAGE(JERR_BAD_LIB_VERSION,
55
	 "Wrong JPEG library version: library is %d, caller expects %d")
57
	 "Wrong JPEG library version: library is %d, caller expects %d")
 Lines 88-103   JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum su Link Here 
88
JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
90
JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
89
JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
91
JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
90
JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
92
JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
91
	 "Cannot transcode due to multiple use of quantization table %d")
93
	 "Cannot transcode due to multiple use of quantization table %d")
92
JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
94
JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
93
JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
95
JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
94
JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
96
JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
95
JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
97
JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
98
JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined")
96
JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
99
JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
97
JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
100
JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
98
JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
101
JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
99
JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
102
JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
100
JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
103
JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
101
JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
104
JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
102
JMESSAGE(JERR_QUANT_COMPONENTS,
105
JMESSAGE(JERR_QUANT_COMPONENTS,
103
	 "Cannot quantize more than %d color components")
106
	 "Cannot quantize more than %d color components")
 Lines 165-180   JMESSAGE(JTRC_THUMB_PALETTE, Link Here 
165
	 "JFIF extension marker: palette thumbnail image, length %u")
168
	 "JFIF extension marker: palette thumbnail image, length %u")
166
JMESSAGE(JTRC_THUMB_RGB,
169
JMESSAGE(JTRC_THUMB_RGB,
167
	 "JFIF extension marker: RGB thumbnail image, length %u")
170
	 "JFIF extension marker: RGB thumbnail image, length %u")
168
JMESSAGE(JTRC_UNKNOWN_IDS,
171
JMESSAGE(JTRC_UNKNOWN_IDS,
169
	 "Unrecognized component IDs %d %d %d, assuming YCbCr")
172
	 "Unrecognized component IDs %d %d %d, assuming YCbCr")
170
JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
173
JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
171
JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
174
JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
172
JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
175
JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
176
JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
173
JMESSAGE(JWRN_BOGUS_PROGRESSION,
177
JMESSAGE(JWRN_BOGUS_PROGRESSION,
174
	 "Inconsistent progression sequence for component %d coefficient %d")
178
	 "Inconsistent progression sequence for component %d coefficient %d")
175
JMESSAGE(JWRN_EXTRANEOUS_DATA,
179
JMESSAGE(JWRN_EXTRANEOUS_DATA,
176
	 "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
180
	 "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
177
JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
181
JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
178
JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
182
JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
179
JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
183
JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
180
JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
184
JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
(-)a/jpeg/jidctfst.c (-1283 / +1 lines)
Line     Link Here 
 Lines 32-48    Link Here 
32
 * quality-setting files than with low-quality ones.
32
 * quality-setting files than with low-quality ones.
33
 */
33
 */
34
34
35
#define JPEG_INTERNALS
35
#define JPEG_INTERNALS
36
#include "jinclude.h"
36
#include "jinclude.h"
37
#include "jpeglib.h"
37
#include "jpeglib.h"
38
#include "jdct.h"		/* Private declarations for DCT subsystem */
38
#include "jdct.h"		/* Private declarations for DCT subsystem */
39
39
40
41
#ifdef DCT_IFAST_SUPPORTED
40
#ifdef DCT_IFAST_SUPPORTED
42
41
43
42
44
/*
43
/*
45
 * This module is specialized to the case DCTSIZE = 8.
44
 * This module is specialized to the case DCTSIZE = 8.
46
 */
45
 */
47
46
48
#if DCTSIZE != 8
47
#if DCTSIZE != 8
 Lines 155-205    Link Here 
155
#endif
154
#endif
156
155
157
#ifdef USE_ACCURATE_ROUNDING
156
#ifdef USE_ACCURATE_ROUNDING
158
#define IDESCALE(x,n)  ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
157
#define IDESCALE(x,n)  ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
159
#else
158
#else
160
#define IDESCALE(x,n)  ((int) IRIGHT_SHIFT(x, n))
159
#define IDESCALE(x,n)  ((int) IRIGHT_SHIFT(x, n))
161
#endif
160
#endif
162
161
163
#ifdef HAVE_MMX_INTEL_MNEMONICS
164
__inline GLOBAL(void)
165
jpeg_idct_ifast_mmx (j_decompress_ptr cinfo, jpeg_component_info * compptr,
166
		 JCOEFPTR coef_block,
167
		 JSAMPARRAY output_buf, JDIMENSION output_col);
168
__inline GLOBAL(void)
169
jpeg_idct_ifast_orig (j_decompress_ptr cinfo, jpeg_component_info * compptr,
170
		 JCOEFPTR coef_block,
171
		 JSAMPARRAY output_buf, JDIMENSION output_col);
172
#endif
173
174
GLOBAL(void)
175
jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info * compptr,
176
		 JCOEFPTR coef_block,
177
		 JSAMPARRAY output_buf, JDIMENSION output_col);
178
179
180
#ifdef HAVE_MMX_INTEL_MNEMONICS
181
GLOBAL(void)
182
jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
183
		 JCOEFPTR coef_block,
184
		 JSAMPARRAY output_buf, JDIMENSION output_col)
185
{
186
if (MMXAvailable)
187
	jpeg_idct_ifast_mmx(cinfo, compptr, coef_block, output_buf, output_col);
188
else
189
	jpeg_idct_ifast_orig(cinfo, compptr, coef_block, output_buf, output_col);
190
}
191
#else
192
162
193
/*
163
/*
194
 * Perform dequantization and inverse DCT on one block of coefficients.
164
 * Perform dequantization and inverse DCT on one block of coefficients.
195
 */
165
 */
196
166
197
GLOBAL (void)
167
GLOBAL(void)
198
jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
168
jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
199
		 JCOEFPTR coef_block,
169
		 JCOEFPTR coef_block,
200
		 JSAMPARRAY output_buf, JDIMENSION output_col)
170
		 JSAMPARRAY output_buf, JDIMENSION output_col)
201
{
171
{
202
  DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
172
  DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
203
  DCTELEM tmp10, tmp11, tmp12, tmp13;
173
  DCTELEM tmp10, tmp11, tmp12, tmp13;
204
  DCTELEM z5, z10, z11, z12, z13;
174
  DCTELEM z5, z10, z11, z12, z13;
205
  JCOEFPTR inptr;
175
  JCOEFPTR inptr;
 Lines 390-1650   jpeg_idct_ifast (j_decompress_ptr cinfo, Link Here 
390
			    & RANGE_MASK];
360
			    & RANGE_MASK];
391
    outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
361
    outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
392
			    & RANGE_MASK];
362
			    & RANGE_MASK];
393
363
394
    wsptr += DCTSIZE;		/* advance pointer to next row */
364
    wsptr += DCTSIZE;		/* advance pointer to next row */
395
  }
365
  }
396
}
366
}
397
367
398
#endif
399
400
#ifdef HAVE_MMX_INTEL_MNEMONICS
401
402
403
_inline GLOBAL(void)
404
jpeg_idct_ifast_orig (j_decompress_ptr cinfo, jpeg_component_info * compptr,
405
		 JCOEFPTR coef_block,
406
		 JSAMPARRAY output_buf, JDIMENSION output_col)
407
{
408
  DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
409
  DCTELEM tmp10, tmp11, tmp12, tmp13;
410
  DCTELEM z5, z10, z11, z12, z13;
411
  JCOEFPTR inptr;
412
  IFAST_MULT_TYPE * quantptr;
413
  int * wsptr;
414
  JSAMPROW outptr;
415
  JSAMPLE *range_limit = IDCT_range_limit(cinfo);
416
  int ctr;
417
  int workspace[DCTSIZE2];	/* buffers data between passes */
418
  SHIFT_TEMPS			/* for DESCALE */
419
  ISHIFT_TEMPS			/* for IDESCALE */
420
421
  /* Pass 1: process columns from input, store into work array. */
422
423
  inptr = coef_block;
424
  quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
425
  wsptr = workspace;
426
  for (ctr = DCTSIZE; ctr > 0; ctr--) {
427
    /* Due to quantization, we will usually find that many of the input
428
     * coefficients are zero, especially the AC terms.  We can exploit this
429
     * by short-circuiting the IDCT calculation for any column in which all
430
     * the AC terms are zero.  In that case each output is equal to the
431
     * DC coefficient (with scale factor as needed).
432
     * With typical images and quantization tables, half or more of the
433
     * column DCT calculations can be simplified this way.
434
     */
435
    
436
    if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
437
	 inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] |
438
	 inptr[DCTSIZE*7]) == 0) {
439
      /* AC terms all zero */
440
      int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
441
442
      wsptr[DCTSIZE*0] = dcval;
443
      wsptr[DCTSIZE*1] = dcval;
444
      wsptr[DCTSIZE*2] = dcval;
445
      wsptr[DCTSIZE*3] = dcval;
446
      wsptr[DCTSIZE*4] = dcval;
447
      wsptr[DCTSIZE*5] = dcval;
448
      wsptr[DCTSIZE*6] = dcval;
449
      wsptr[DCTSIZE*7] = dcval;
450
      
451
      inptr++;			/* advance pointers to next column */
452
      quantptr++;
453
      wsptr++;
454
      continue;
455
    }
456
    
457
    /* Even part */
458
459
    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
460
    tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
461
    tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
462
    tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
463
464
    tmp10 = tmp0 + tmp2;	/* phase 3 */
465
    tmp11 = tmp0 - tmp2;
466
467
    tmp13 = tmp1 + tmp3;	/* phases 5-3 */
468
    tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
469
470
    tmp0 = tmp10 + tmp13;	/* phase 2 */
471
    tmp3 = tmp10 - tmp13;
472
    tmp1 = tmp11 + tmp12;
473
    tmp2 = tmp11 - tmp12;
474
    
475
    /* Odd part */
476
477
    tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
478
    tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
479
    tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
480
    tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
481
482
    z13 = tmp6 + tmp5;		/* phase 6 */
483
    z10 = tmp6 - tmp5;
484
    z11 = tmp4 + tmp7;
485
    z12 = tmp4 - tmp7;
486
487
    tmp7 = z11 + z13;		/* phase 5 */
488
    tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
489
490
    z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
491
    tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
492
    tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
493
494
    tmp6 = tmp12 - tmp7;	/* phase 2 */
495
    tmp5 = tmp11 - tmp6;
496
    tmp4 = tmp10 + tmp5;
497
498
    wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
499
    wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
500
    wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
501
    wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
502
    wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
503
    wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
504
    wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
505
    wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
506
507
    inptr++;			/* advance pointers to next column */
508
    quantptr++;
509
    wsptr++;
510
  }
511
  
512
  /* Pass 2: process rows from work array, store into output array. */
513
  /* Note that we must descale the results by a factor of 8 == 2**3, */
514
  /* and also undo the PASS1_BITS scaling. */
515
516
  wsptr = workspace;
517
  for (ctr = 0; ctr < DCTSIZE; ctr++) {
518
    outptr = output_buf[ctr] + output_col;
519
    /* Rows of zeroes can be exploited in the same way as we did with columns.
520
     * However, the column calculation has created many nonzero AC terms, so
521
     * the simplification applies less often (typically 5% to 10% of the time).
522
     * On machines with very fast multiplication, it's possible that the
523
     * test takes more time than it's worth.  In that case this section
524
     * may be commented out.
525
     */
526
    
527
#ifndef NO_ZERO_ROW_TEST
528
    if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[4] | wsptr[5] | wsptr[6] |
529
	 wsptr[7]) == 0) {
530
      /* AC terms all zero */
531
      JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
532
				  & RANGE_MASK];
533
      
534
      outptr[0] = dcval;
535
      outptr[1] = dcval;
536
      outptr[2] = dcval;
537
      outptr[3] = dcval;
538
      outptr[4] = dcval;
539
      outptr[5] = dcval;
540
      outptr[6] = dcval;
541
      outptr[7] = dcval;
542
543
      wsptr += DCTSIZE;		/* advance pointer to next row */
544
      continue;
545
    }
546
#endif
547
    
548
    /* Even part */
549
550
    tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
551
    tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
552
553
    tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
554
    tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
555
	    - tmp13;
556
557
    tmp0 = tmp10 + tmp13;
558
    tmp3 = tmp10 - tmp13;
559
    tmp1 = tmp11 + tmp12;
560
    tmp2 = tmp11 - tmp12;
561
562
    /* Odd part */
563
564
    z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
565
    z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
566
    z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
567
    z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
568
569
    tmp7 = z11 + z13;		/* phase 5 */
570
    tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
571
572
    z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
573
    tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
574
    tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
575
576
    tmp6 = tmp12 - tmp7;	/* phase 2 */
577
    tmp5 = tmp11 - tmp6;
578
    tmp4 = tmp10 + tmp5;
579
580
    /* Final output stage: scale down by a factor of 8 and range-limit */
581
582
    outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
583
			    & RANGE_MASK];
584
    outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
585
			    & RANGE_MASK];
586
    outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
587
			    & RANGE_MASK];
588
    outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
589
			    & RANGE_MASK];
590
    outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
591
			    & RANGE_MASK];
592
    outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
593
			    & RANGE_MASK];
594
    outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
595
			    & RANGE_MASK];
596
    outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
597
			    & RANGE_MASK];
598
599
    wsptr += DCTSIZE;		/* advance pointer to next row */
600
  }
601
}
602
603
604
	static	  __int64 fix_141		= 0x5a825a825a825a82;
605
	static	  __int64 fix_184n261	= 0xcf04cf04cf04cf04;
606
	static	  __int64 fix_184		= 0x7641764176417641;
607
	static	  __int64 fix_n184		= 0x896f896f896f896f;
608
	static	  __int64 fix_108n184	= 0xcf04cf04cf04cf04;
609
	static	  __int64 const_0x0080	= 0x0080008000800080;
610
611
612
__inline GLOBAL(void)
613
jpeg_idct_ifast_mmx (j_decompress_ptr cinfo, jpeg_component_info * compptr,
614
		 JCOEFPTR inptr,
615
		 JSAMPARRAY outptr, JDIMENSION output_col)
616
{
617
618
  int16 workspace[DCTSIZE2 + 4];	/* buffers data between passes */
619
  int16 *wsptr=workspace;
620
  int16 *quantptr=compptr->dct_table;
621
622
  __asm{ 
623
    
624
	mov		edi, quantptr
625
	mov		ebx, inptr
626
	mov		esi, wsptr
627
	add		esi, 0x07		;align wsptr to qword
628
	and		esi, 0xfffffff8	;align wsptr to qword
629
630
	mov		eax, esi
631
632
    /* Odd part */
633
634
635
	movq		mm1, [ebx + 8*10]		;load inptr[DCTSIZE*5]
636
637
	pmullw		mm1, [edi + 8*10]		;tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
638
639
	movq		mm0, [ebx + 8*6]		;load inptr[DCTSIZE*3]
640
641
	pmullw		mm0, [edi + 8*6]		;tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
642
643
	movq		mm3, [ebx + 8*2]		;load inptr[DCTSIZE*1]
644
	movq	mm2, mm1					;copy tmp6	/* phase 6 */
645
646
	pmullw		mm3, [edi + 8*2]		;tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
647
648
	movq		mm4, [ebx + 8*14]		;load inptr[DCTSIZE*1]
649
	paddw	mm1, mm0					;z13 = tmp6 + tmp5;
650
651
	pmullw		mm4, [edi + 8*14]	    ;tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
652
	psubw	mm2, mm0					;z10 = tmp6 - tmp5   
653
654
	psllw		mm2, 2				;shift z10
655
	movq		mm0, mm2			;copy z10
656
657
	pmulhw		mm2, fix_184n261	;MULTIPLY( z12, FIX_1_847759065); /* 2*c2 */
658
	movq		mm5, mm3				;copy tmp4
659
660
	pmulhw		mm0, fix_n184		;MULTIPLY(z10, -FIX_1_847759065); /* 2*c2 */
661
	paddw		mm3, mm4				;z11 = tmp4 + tmp7;
662
663
	movq		mm6, mm3				;copy z11			/* phase 5 */
664
	psubw		mm5, mm4				;z12 = tmp4 - tmp7;
665
666
	psubw		mm6, mm1				;z11-z13
667
	psllw		mm5, 2				;shift z12
668
669
	movq		mm4, [ebx + 8*12]		;load inptr[DCTSIZE*6], even part
670
 	movq		mm7, mm5			;copy z12
671
672
	pmulhw		mm5, fix_108n184	;MULT(z12, (FIX_1_08-FIX_1_84)) //- z5; /* 2*(c2-c6) */ even part
673
	paddw		mm3, mm1				;tmp7 = z11 + z13;	
674
675
676
    /* Even part */
677
	pmulhw		mm7, fix_184		;MULTIPLY(z10,(FIX_1_847759065 - FIX_2_613125930)) //+ z5; /* -2*(c2+c6) */
678
	psllw		mm6, 2
679
680
	movq		mm1, [ebx + 8*4]		;load inptr[DCTSIZE*2]
681
682
	pmullw		mm1, [edi + 8*4]		;tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
683
	paddw		mm0, mm5			;tmp10
684
685
	pmullw		mm4, [edi + 8*12]		;tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
686
	paddw		mm2, mm7			;tmp12
687
688
	pmulhw		mm6, fix_141			;tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
689
	psubw		mm2, mm3		;tmp6 = tmp12 - tmp7
690
691
	movq		mm5, mm1				;copy tmp1
692
	paddw		mm1, mm4				;tmp13= tmp1 + tmp3;	/* phases 5-3 */
693
694
	psubw		mm5, mm4				;tmp1-tmp3
695
	psubw		mm6, mm2		;tmp5 = tmp11 - tmp6;
696
697
	movq		[esi+8*0], mm1			;save tmp13 in workspace
698
	psllw		mm5, 2					;shift tmp1-tmp3
699
    
700
	movq		mm7, [ebx + 8*0]		;load inptr[DCTSIZE*0]
701
702
	pmulhw		mm5, fix_141			;MULTIPLY(tmp1 - tmp3, FIX_1_414213562)
703
	paddw		mm0, mm6		;tmp4 = tmp10 + tmp5;
704
705
	pmullw		mm7, [edi + 8*0]		;tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
706
707
	movq		mm4, [ebx + 8*8]		;load inptr[DCTSIZE*4]
708
	
709
	pmullw		mm4, [edi + 8*8]		;tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
710
	psubw		mm5, mm1				;tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
711
712
	movq		[esi+8*4], mm0		;save tmp4 in workspace
713
	movq		mm1, mm7			;copy tmp0	/* phase 3 */
714
715
	movq		[esi+8*2], mm5		;save tmp12 in workspace
716
	psubw		mm1, mm4			;tmp11 = tmp0 - tmp2; 
717
718
	paddw		mm7, mm4			;tmp10 = tmp0 + tmp2;
719
    movq		mm5, mm1		;copy tmp11
720
	
721
	paddw		mm1, [esi+8*2]	;tmp1 = tmp11 + tmp12;
722
	movq		mm4, mm7		;copy tmp10		/* phase 2 */
723
724
	paddw		mm7, [esi+8*0]	;tmp0 = tmp10 + tmp13;	
725
726
	psubw		mm4, [esi+8*0]	;tmp3 = tmp10 - tmp13;
727
	movq		mm0, mm7		;copy tmp0
728
729
	psubw		mm5, [esi+8*2]	;tmp2 = tmp11 - tmp12;
730
	paddw		mm7, mm3		;wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
731
	
732
	psubw		mm0, mm3			;wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
733
734
	movq		[esi + 8*0], mm7	;wsptr[DCTSIZE*0]
735
	movq		mm3, mm1			;copy tmp1
736
737
	movq		[esi + 8*14], mm0	;wsptr[DCTSIZE*7]
738
	paddw		mm1, mm2			;wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
739
740
	psubw		mm3, mm2			;wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
741
742
	movq		[esi + 8*2], mm1	;wsptr[DCTSIZE*1]
743
	movq		mm1, mm4			;copy tmp3
744
745
	movq		[esi + 8*12], mm3	;wsptr[DCTSIZE*6]
746
747
	paddw		mm4, [esi+8*4]		;wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
748
749
	psubw		mm1, [esi+8*4]		;wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
750
751
	movq		[esi + 8*8], mm4
752
	movq		mm7, mm5			;copy tmp2
753
754
	paddw		mm5, mm6			;wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5)
755
756
	movq		[esi+8*6], mm1		;
757
	psubw		mm7, mm6			;wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
758
759
	movq		[esi + 8*4], mm5
760
761
	movq		[esi + 8*10], mm7
762
763
764
765
/*****************************************************************/
766
	add		edi, 8
767
	add		ebx, 8
768
	add		esi, 8
769
770
/*****************************************************************/
771
772
773
774
775
	movq		mm1, [ebx + 8*10]		;load inptr[DCTSIZE*5]
776
777
	pmullw		mm1, [edi + 8*10]		;tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
778
779
	movq		mm0, [ebx + 8*6]		;load inptr[DCTSIZE*3]
780
781
	pmullw		mm0, [edi + 8*6]		;tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
782
783
	movq		mm3, [ebx + 8*2]		;load inptr[DCTSIZE*1]
784
	movq	mm2, mm1					;copy tmp6	/* phase 6 */
785
786
	pmullw		mm3, [edi + 8*2]		;tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
787
788
	movq		mm4, [ebx + 8*14]		;load inptr[DCTSIZE*1]
789
	paddw	mm1, mm0					;z13 = tmp6 + tmp5;
790
791
	pmullw		mm4, [edi + 8*14]	    ;tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
792
	psubw	mm2, mm0					;z10 = tmp6 - tmp5   
793
794
	psllw		mm2, 2				;shift z10
795
	movq		mm0, mm2			;copy z10
796
797
	pmulhw		mm2, fix_184n261	;MULTIPLY( z12, FIX_1_847759065); /* 2*c2 */
798
	movq		mm5, mm3				;copy tmp4
799
800
	pmulhw		mm0, fix_n184		;MULTIPLY(z10, -FIX_1_847759065); /* 2*c2 */
801
	paddw		mm3, mm4				;z11 = tmp4 + tmp7;
802
803
	movq		mm6, mm3				;copy z11			/* phase 5 */
804
	psubw		mm5, mm4				;z12 = tmp4 - tmp7;
805
806
	psubw		mm6, mm1				;z11-z13
807
	psllw		mm5, 2				;shift z12
808
809
	movq		mm4, [ebx + 8*12]		;load inptr[DCTSIZE*6], even part
810
 	movq		mm7, mm5			;copy z12
811
812
	pmulhw		mm5, fix_108n184	;MULT(z12, (FIX_1_08-FIX_1_84)) //- z5; /* 2*(c2-c6) */ even part
813
	paddw		mm3, mm1				;tmp7 = z11 + z13;	
814
815
816
    /* Even part */
817
	pmulhw		mm7, fix_184		;MULTIPLY(z10,(FIX_1_847759065 - FIX_2_613125930)) //+ z5; /* -2*(c2+c6) */
818
	psllw		mm6, 2
819
820
	movq		mm1, [ebx + 8*4]		;load inptr[DCTSIZE*2]
821
822
	pmullw		mm1, [edi + 8*4]		;tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
823
	paddw		mm0, mm5			;tmp10
824
825
	pmullw		mm4, [edi + 8*12]		;tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
826
	paddw		mm2, mm7			;tmp12
827
828
	pmulhw		mm6, fix_141			;tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
829
	psubw		mm2, mm3		;tmp6 = tmp12 - tmp7
830
831
	movq		mm5, mm1				;copy tmp1
832
	paddw		mm1, mm4				;tmp13= tmp1 + tmp3;	/* phases 5-3 */
833
834
	psubw		mm5, mm4				;tmp1-tmp3
835
	psubw		mm6, mm2		;tmp5 = tmp11 - tmp6;
836
837
	movq		[esi+8*0], mm1			;save tmp13 in workspace
838
	psllw		mm5, 2					;shift tmp1-tmp3
839
    
840
	movq		mm7, [ebx + 8*0]		;load inptr[DCTSIZE*0]
841
	paddw		mm0, mm6		;tmp4 = tmp10 + tmp5;
842
843
	pmulhw		mm5, fix_141			;MULTIPLY(tmp1 - tmp3, FIX_1_414213562)
844
845
	pmullw		mm7, [edi + 8*0]		;tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
846
847
	movq		mm4, [ebx + 8*8]		;load inptr[DCTSIZE*4]
848
	
849
	pmullw		mm4, [edi + 8*8]		;tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
850
	psubw		mm5, mm1				;tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
851
852
	movq		[esi+8*4], mm0		;save tmp4 in workspace
853
	movq		mm1, mm7			;copy tmp0	/* phase 3 */
854
855
	movq		[esi+8*2], mm5		;save tmp12 in workspace
856
	psubw		mm1, mm4			;tmp11 = tmp0 - tmp2; 
857
858
	paddw		mm7, mm4			;tmp10 = tmp0 + tmp2;
859
    movq		mm5, mm1		;copy tmp11
860
	
861
	paddw		mm1, [esi+8*2]	;tmp1 = tmp11 + tmp12;
862
	movq		mm4, mm7		;copy tmp10		/* phase 2 */
863
864
	paddw		mm7, [esi+8*0]	;tmp0 = tmp10 + tmp13;	
865
866
	psubw		mm4, [esi+8*0]	;tmp3 = tmp10 - tmp13;
867
	movq		mm0, mm7		;copy tmp0
868
869
	psubw		mm5, [esi+8*2]	;tmp2 = tmp11 - tmp12;
870
	paddw		mm7, mm3		;wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
871
	
872
	psubw		mm0, mm3			;wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
873
874
	movq		[esi + 8*0], mm7	;wsptr[DCTSIZE*0]
875
	movq		mm3, mm1			;copy tmp1
876
877
	movq		[esi + 8*14], mm0	;wsptr[DCTSIZE*7]
878
	paddw		mm1, mm2			;wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
879
880
	psubw		mm3, mm2			;wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
881
882
	movq		[esi + 8*2], mm1	;wsptr[DCTSIZE*1]
883
	movq		mm1, mm4			;copy tmp3
884
885
	movq		[esi + 8*12], mm3	;wsptr[DCTSIZE*6]
886
887
	paddw		mm4, [esi+8*4]		;wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
888
889
	psubw		mm1, [esi+8*4]		;wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
890
891
	movq		[esi + 8*8], mm4
892
	movq		mm7, mm5			;copy tmp2
893
894
	paddw		mm5, mm6			;wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5)
895
896
	movq		[esi+8*6], mm1		;
897
	psubw		mm7, mm6			;wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
898
899
	movq		[esi + 8*4], mm5
900
901
	movq		[esi + 8*10], mm7
902
903
904
905
906
/*****************************************************************/
907
908
  /* Pass 2: process rows from work array, store into output array. */
909
  /* Note that we must descale the results by a factor of 8 == 2**3, */
910
  /* and also undo the PASS1_BITS scaling. */
911
912
/*****************************************************************/
913
    /* Even part */
914
915
	mov			esi, eax
916
	mov			eax, outptr
917
918
//    tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
919
//    tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
920
//    tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
921
//    tmp14 = ((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6]);
922
	movq		mm0, [esi+8*0]		;wsptr[0,0],[0,1],[0,2],[0,3]
923
924
	movq		mm1, [esi+8*1]		;wsptr[0,4],[0,5],[0,6],[0,7]
925
	movq		mm2, mm0
926
	
927
	movq		mm3, [esi+8*2]		;wsptr[1,0],[1,1],[1,2],[1,3]
928
	paddw		mm0, mm1			;wsptr[0,tmp10],[xxx],[0,tmp13],[xxx]
929
930
	movq		mm4, [esi+8*3]		;wsptr[1,4],[1,5],[1,6],[1,7]
931
	psubw		mm2, mm1			;wsptr[0,tmp11],[xxx],[0,tmp14],[xxx]
932
933
	movq		mm6, mm0
934
	movq		mm5, mm3
935
	
936
	paddw		mm3, mm4			;wsptr[1,tmp10],[xxx],[1,tmp13],[xxx]
937
	movq		mm1, mm2
938
939
	psubw		mm5, mm4			;wsptr[1,tmp11],[xxx],[1,tmp14],[xxx]
940
	punpcklwd	mm0, mm3			;wsptr[0,tmp10],[1,tmp10],[xxx],[xxx]
941
942
	movq		mm7, [esi+8*7]		;wsptr[3,4],[3,5],[3,6],[3,7]
943
	punpckhwd	mm6, mm3			;wsptr[0,tmp13],[1,tmp13],[xxx],[xxx]
944
945
	movq		mm3, [esi+8*4]		;wsptr[2,0],[2,1],[2,2],[2,3]
946
	punpckldq	mm0, mm6	;wsptr[0,tmp10],[1,tmp10],[0,tmp13],[1,tmp13]
947
948
	punpcklwd	mm1, mm5			;wsptr[0,tmp11],[1,tmp11],[xxx],[xxx]
949
	movq		mm4, mm3
950
951
	movq		mm6, [esi+8*6]		;wsptr[3,0],[3,1],[3,2],[3,3]
952
	punpckhwd	mm2, mm5			;wsptr[0,tmp14],[1,tmp14],[xxx],[xxx]
953
954
	movq		mm5, [esi+8*5]		;wsptr[2,4],[2,5],[2,6],[2,7]
955
	punpckldq	mm1, mm2	;wsptr[0,tmp11],[1,tmp11],[0,tmp14],[1,tmp14]
956
957
	
958
	paddw		mm3, mm5			;wsptr[2,tmp10],[xxx],[2,tmp13],[xxx]
959
	movq		mm2, mm6
960
961
	psubw		mm4, mm5			;wsptr[2,tmp11],[xxx],[2,tmp14],[xxx]
962
	paddw		mm6, mm7			;wsptr[3,tmp10],[xxx],[3,tmp13],[xxx]
963
964
	movq		mm5, mm3
965
	punpcklwd	mm3, mm6			;wsptr[2,tmp10],[3,tmp10],[xxx],[xxx]
966
	
967
	psubw		mm2, mm7			;wsptr[3,tmp11],[xxx],[3,tmp14],[xxx]
968
	punpckhwd	mm5, mm6			;wsptr[2,tmp13],[3,tmp13],[xxx],[xxx]
969
970
	movq		mm7, mm4
971
	punpckldq	mm3, mm5	;wsptr[2,tmp10],[3,tmp10],[2,tmp13],[3,tmp13]
972
973
	punpcklwd	mm4, mm2			;wsptr[2,tmp11],[3,tmp11],[xxx],[xxx]
974
975
	punpckhwd	mm7, mm2			;wsptr[2,tmp14],[3,tmp14],[xxx],[xxx]
976
977
	punpckldq	mm4, mm7	;wsptr[2,tmp11],[3,tmp11],[2,tmp14],[3,tmp14]
978
	movq		mm6, mm1
979
980
//	mm0 = 	;wsptr[0,tmp10],[1,tmp10],[0,tmp13],[1,tmp13]
981
//	mm1 =	;wsptr[0,tmp11],[1,tmp11],[0,tmp14],[1,tmp14]
982
983
984
	movq		mm2, mm0
985
	punpckhdq	mm6, mm4	;wsptr[0,tmp14],[1,tmp14],[2,tmp14],[3,tmp14]
986
987
	punpckldq	mm1, mm4	;wsptr[0,tmp11],[1,tmp11],[2,tmp11],[3,tmp11]
988
	psllw		mm6, 2
989
990
	pmulhw		mm6, fix_141
991
	punpckldq	mm0, mm3	;wsptr[0,tmp10],[1,tmp10],[2,tmp10],[3,tmp10]
992
993
	punpckhdq	mm2, mm3	;wsptr[0,tmp13],[1,tmp13],[2,tmp13],[3,tmp13]
994
	movq		mm7, mm0
995
996
//    tmp0 = tmp10 + tmp13;
997
//    tmp3 = tmp10 - tmp13;
998
	paddw		mm0, mm2	;[0,tmp0],[1,tmp0],[2,tmp0],[3,tmp0]
999
	psubw		mm7, mm2	;[0,tmp3],[1,tmp3],[2,tmp3],[3,tmp3]
1000
1001
//    tmp12 = MULTIPLY(tmp14, FIX_1_414213562) - tmp13;
1002
	psubw		mm6, mm2	;wsptr[0,tmp12],[1,tmp12],[2,tmp12],[3,tmp12]
1003
//    tmp1 = tmp11 + tmp12;
1004
//    tmp2 = tmp11 - tmp12;
1005
	movq		mm5, mm1
1006
1007
1008
1009
    /* Odd part */
1010
1011
//    z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
1012
//    z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
1013
//    z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
1014
//    z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
1015
	movq		mm3, [esi+8*0]		;wsptr[0,0],[0,1],[0,2],[0,3]
1016
	paddw		mm1, mm6	;[0,tmp1],[1,tmp1],[2,tmp1],[3,tmp1]
1017
1018
	movq		mm4, [esi+8*1]		;wsptr[0,4],[0,5],[0,6],[0,7]
1019
	psubw		mm5, mm6	;[0,tmp2],[1,tmp2],[2,tmp2],[3,tmp2]
1020
1021
	movq		mm6, mm3
1022
	punpckldq	mm3, mm4			;wsptr[0,0],[0,1],[0,4],[0,5]
1023
1024
	punpckhdq	mm4, mm6			;wsptr[0,6],[0,7],[0,2],[0,3]
1025
	movq		mm2, mm3
1026
1027
//Save tmp0 and tmp1 in wsptr
1028
	movq		[esi+8*0], mm0		;save tmp0
1029
	paddw		mm2, mm4			;wsptr[xxx],[0,z11],[xxx],[0,z13]
1030
1031
	
1032
//Continue with z10 --- z13
1033
	movq		mm6, [esi+8*2]		;wsptr[1,0],[1,1],[1,2],[1,3]
1034
	psubw		mm3, mm4			;wsptr[xxx],[0,z12],[xxx],[0,z10]
1035
1036
	movq		mm0, [esi+8*3]		;wsptr[1,4],[1,5],[1,6],[1,7]
1037
	movq		mm4, mm6
1038
1039
	movq		[esi+8*1], mm1		;save tmp1
1040
	punpckldq	mm6, mm0			;wsptr[1,0],[1,1],[1,4],[1,5]
1041
1042
	punpckhdq	mm0, mm4			;wsptr[1,6],[1,7],[1,2],[1,3]
1043
	movq		mm1, mm6
1044
	
1045
//Save tmp2 and tmp3 in wsptr
1046
	paddw		mm6, mm0		;wsptr[xxx],[1,z11],[xxx],[1,z13]
1047
	movq		mm4, mm2
1048
	
1049
//Continue with z10 --- z13
1050
	movq		[esi+8*2], mm5		;save tmp2
1051
	punpcklwd	mm2, mm6		;wsptr[xxx],[xxx],[0,z11],[1,z11]
1052
1053
	psubw		mm1, mm0		;wsptr[xxx],[1,z12],[xxx],[1,z10]
1054
	punpckhwd	mm4, mm6		;wsptr[xxx],[xxx],[0,z13],[1,z13]
1055
1056
	movq		mm0, mm3
1057
	punpcklwd	mm3, mm1		;wsptr[xxx],[xxx],[0,z12],[1,z12]
1058
1059
	movq		[esi+8*3], mm7		;save tmp3
1060
	punpckhwd	mm0, mm1		;wsptr[xxx],[xxx],[0,z10],[1,z10]
1061
1062
	movq		mm6, [esi+8*4]		;wsptr[2,0],[2,1],[2,2],[2,3]
1063
	punpckhdq	mm0, mm2		;wsptr[0,z10],[1,z10],[0,z11],[1,z11]
1064
1065
	movq		mm7, [esi+8*5]		;wsptr[2,4],[2,5],[2,6],[2,7]
1066
	punpckhdq	mm3, mm4		;wsptr[0,z12],[1,z12],[0,z13],[1,z13]
1067
1068
	movq		mm1, [esi+8*6]		;wsptr[3,0],[3,1],[3,2],[3,3]
1069
	movq		mm4, mm6
1070
1071
	punpckldq	mm6, mm7			;wsptr[2,0],[2,1],[2,4],[2,5]
1072
	movq		mm5, mm1
1073
1074
	punpckhdq	mm7, mm4			;wsptr[2,6],[2,7],[2,2],[2,3]
1075
	movq		mm2, mm6
1076
	
1077
	movq		mm4, [esi+8*7]		;wsptr[3,4],[3,5],[3,6],[3,7]
1078
	paddw		mm6, mm7		;wsptr[xxx],[2,z11],[xxx],[2,z13]
1079
1080
	psubw		mm2, mm7		;wsptr[xxx],[2,z12],[xxx],[2,z10]
1081
	punpckldq	mm1, mm4			;wsptr[3,0],[3,1],[3,4],[3,5]
1082
1083
	punpckhdq	mm4, mm5			;wsptr[3,6],[3,7],[3,2],[3,3]
1084
	movq		mm7, mm1
1085
1086
	paddw		mm1, mm4		;wsptr[xxx],[3,z11],[xxx],[3,z13]
1087
	psubw		mm7, mm4		;wsptr[xxx],[3,z12],[xxx],[3,z10]
1088
1089
	movq		mm5, mm6
1090
	punpcklwd	mm6, mm1		;wsptr[xxx],[xxx],[2,z11],[3,z11]
1091
1092
	punpckhwd	mm5, mm1		;wsptr[xxx],[xxx],[2,z13],[3,z13]
1093
	movq		mm4, mm2
1094
1095
	punpcklwd	mm2, mm7		;wsptr[xxx],[xxx],[2,z12],[3,z12]
1096
1097
	punpckhwd	mm4, mm7		;wsptr[xxx],[xxx],[2,z10],[3,z10]
1098
1099
	punpckhdq	mm4, mm6		;wsptr[2,z10],[3,z10],[2,z11],[3,z11]
1100
1101
	punpckhdq	mm2, mm5		;wsptr[2,z12],[3,z12],[2,z13],[3,z13]
1102
	movq		mm5, mm0
1103
1104
	punpckldq	mm0, mm4		;wsptr[0,z10],[1,z10],[2,z10],[3,z10]
1105
1106
	punpckhdq	mm5, mm4		;wsptr[0,z11],[1,z11],[2,z11],[3,z11]
1107
	movq		mm4, mm3
1108
1109
	punpckhdq	mm4, mm2		;wsptr[0,z13],[1,z13],[2,z13],[3,z13]
1110
	movq		mm1, mm5
1111
1112
	punpckldq	mm3, mm2		;wsptr[0,z12],[1,z12],[2,z12],[3,z12]
1113
//    tmp7 = z11 + z13;		/* phase 5 */
1114
//    tmp8 = z11 - z13;		/* phase 5 */
1115
	psubw		mm1, mm4		;tmp8
1116
1117
	paddw		mm5, mm4		;tmp7
1118
//    tmp21 = MULTIPLY(tmp8, FIX_1_414213562); /* 2*c4 */
1119
	psllw		mm1, 2
1120
1121
	psllw		mm0, 2
1122
1123
	pmulhw		mm1, fix_141	;tmp21
1124
//    tmp20 = MULTIPLY(z12, (FIX_1_082392200- FIX_1_847759065))  /* 2*(c2-c6) */
1125
//			+ MULTIPLY(z10, - FIX_1_847759065); /* 2*c2 */
1126
	psllw		mm3, 2
1127
	movq		mm7, mm0
1128
1129
	pmulhw		mm7, fix_n184
1130
	movq		mm6, mm3
1131
1132
	movq		mm2, [esi+8*0]	;tmp0,final1
1133
1134
	pmulhw		mm6, fix_108n184
1135
//	 tmp22 = MULTIPLY(z10,(FIX_1_847759065 - FIX_2_613125930)) /* -2*(c2+c6) */
1136
//			+ MULTIPLY(z12, FIX_1_847759065); /* 2*c2 */
1137
	movq		mm4, mm2		;final1
1138
  
1139
	pmulhw		mm0, fix_184n261
1140
	paddw		mm2, mm5		;tmp0+tmp7,final1
1141
1142
	pmulhw		mm3, fix_184
1143
	psubw		mm4, mm5		;tmp0-tmp7,final1
1144
1145
//    tmp6 = tmp22 - tmp7;	/* phase 2 */
1146
	psraw		mm2, 5			;outptr[0,0],[1,0],[2,0],[3,0],final1
1147
1148
	paddsw		mm2, const_0x0080	;final1
1149
	paddw		mm7, mm6			;tmp20
1150
	psraw		mm4, 5			;outptr[0,7],[1,7],[2,7],[3,7],final1
1151
1152
	paddsw		mm4, const_0x0080	;final1
1153
	paddw		mm3, mm0			;tmp22
1154
1155
//    tmp5 = tmp21 - tmp6;
1156
	psubw		mm3, mm5		;tmp6
1157
1158
//    tmp4 = tmp20 + tmp5;
1159
	movq		mm0, [esi+8*1]		;tmp1,final2
1160
	psubw		mm1, mm3		;tmp5
1161
1162
	movq		mm6, mm0			;final2
1163
	paddw		mm0, mm3		;tmp1+tmp6,final2
1164
1165
    /* Final output stage: scale down by a factor of 8 and range-limit */
1166
1167
1168
//    outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
1169
//			    & RANGE_MASK];
1170
//    outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
1171
//			    & RANGE_MASK];	final1
1172
1173
1174
//    outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
1175
//			    & RANGE_MASK];
1176
//    outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
1177
//			    & RANGE_MASK];	final2
1178
	psubw		mm6, mm3		;tmp1-tmp6,final2
1179
	psraw		mm0, 5			;outptr[0,1],[1,1],[2,1],[3,1]
1180
1181
	paddsw		mm0, const_0x0080
1182
	psraw		mm6, 5			;outptr[0,6],[1,6],[2,6],[3,6]
1183
	
1184
	paddsw		mm6, const_0x0080		;need to check this value
1185
	packuswb	mm0, mm4	;out[0,1],[1,1],[2,1],[3,1],[0,7],[1,7],[2,7],[3,7]
1186
	
1187
	movq		mm5, [esi+8*2]		;tmp2,final3
1188
	packuswb	mm2, mm6	;out[0,0],[1,0],[2,0],[3,0],[0,6],[1,6],[2,6],[3,6]
1189
1190
//    outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
1191
//			    & RANGE_MASK];
1192
//    outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
1193
//			    & RANGE_MASK];	final3
1194
	paddw		mm7, mm1		;tmp4
1195
	movq		mm3, mm5
1196
1197
	paddw		mm5, mm1		;tmp2+tmp5
1198
	psubw		mm3, mm1		;tmp2-tmp5
1199
1200
	psraw		mm5, 5			;outptr[0,2],[1,2],[2,2],[3,2]
1201
1202
	paddsw		mm5, const_0x0080
1203
	movq		mm4, [esi+8*3]		;tmp3,final4
1204
	psraw		mm3, 5			;outptr[0,5],[1,5],[2,5],[3,5]
1205
1206
	paddsw		mm3, const_0x0080
1207
1208
1209
//    outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
1210
//			    & RANGE_MASK];
1211
//    outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
1212
//			    & RANGE_MASK];	final4
1213
	movq		mm6, mm4
1214
	paddw		mm4, mm7		;tmp3+tmp4
1215
1216
	psubw		mm6, mm7		;tmp3-tmp4
1217
	psraw		mm4, 5			;outptr[0,4],[1,4],[2,4],[3,4]
1218
	mov			ecx, [eax]
1219
1220
	paddsw		mm4, const_0x0080
1221
	psraw		mm6, 5			;outptr[0,3],[1,3],[2,3],[3,3]
1222
1223
	paddsw		mm6, const_0x0080
1224
	packuswb	mm5, mm4	;out[0,2],[1,2],[2,2],[3,2],[0,4],[1,4],[2,4],[3,4]
1225
1226
	packuswb	mm6, mm3	;out[0,3],[1,3],[2,3],[3,3],[0,5],[1,5],[2,5],[3,5]
1227
	movq		mm4, mm2
1228
1229
	movq		mm7, mm5
1230
	punpcklbw	mm2, mm0	;out[0,0],[0,1],[1,0],[1,1],[2,0],[2,1],[3,0],[3,1]
1231
1232
	punpckhbw	mm4, mm0	;out[0,6],[0,7],[1,6],[1,7],[2,6],[2,7],[3,6],[3,7]
1233
	movq		mm1, mm2
1234
1235
	punpcklbw	mm5, mm6	;out[0,2],[0,3],[1,2],[1,3],[2,2],[2,3],[3,2],[3,3]
1236
	add		 	eax, 4
1237
1238
	punpckhbw	mm7, mm6	;out[0,4],[0,5],[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]
1239
1240
	punpcklwd	mm2, mm5	;out[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3]
1241
	add			ecx, output_col
1242
1243
	movq		mm6, mm7
1244
	punpckhwd	mm1, mm5	;out[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]
1245
1246
	movq		mm0, mm2
1247
	punpcklwd	mm6, mm4	;out[0,4],[0,5],[0,6],[0,7],[1,4],[1,5],[1,6],[1,7]
1248
1249
	mov			ebx, [eax]
1250
	punpckldq	mm2, mm6	;out[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7]
1251
1252
	add		 	eax, 4
1253
	movq		mm3, mm1
1254
1255
	add			ebx, output_col 
1256
	punpckhwd	mm7, mm4	;out[2,4],[2,5],[2,6],[2,7],[3,4],[3,5],[3,6],[3,7]
1257
	
1258
	movq		[ecx], mm2
1259
	punpckhdq	mm0, mm6	;out[1,0],[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7]
1260
1261
	mov			ecx, [eax]
1262
	add		 	eax, 4
1263
	add			ecx, output_col
1264
1265
	movq		[ebx], mm0
1266
	punpckldq	mm1, mm7	;out[2,0],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7]
1267
1268
	mov			ebx, [eax]
1269
1270
	add			ebx, output_col
1271
	punpckhdq	mm3, mm7	;out[3,0],[3,1],[3,2],[3,3],[3,4],[3,5],[3,6],[3,7]
1272
	movq		[ecx], mm1
1273
1274
1275
	movq		[ebx], mm3
1276
1277
1278
		
1279
/*******************************************************************/
1280
	
1281
1282
	add			esi, 64
1283
	add			eax, 4
1284
1285
/*******************************************************************/
1286
1287
//    tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
1288
//    tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
1289
//    tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
1290
//    tmp14 = ((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6]);
1291
	movq		mm0, [esi+8*0]		;wsptr[0,0],[0,1],[0,2],[0,3]
1292
1293
	movq		mm1, [esi+8*1]		;wsptr[0,4],[0,5],[0,6],[0,7]
1294
	movq		mm2, mm0
1295
	
1296
	movq		mm3, [esi+8*2]		;wsptr[1,0],[1,1],[1,2],[1,3]
1297
	paddw		mm0, mm1			;wsptr[0,tmp10],[xxx],[0,tmp13],[xxx]
1298
1299
	movq		mm4, [esi+8*3]		;wsptr[1,4],[1,5],[1,6],[1,7]
1300
	psubw		mm2, mm1			;wsptr[0,tmp11],[xxx],[0,tmp14],[xxx]
1301
1302
	movq		mm6, mm0
1303
	movq		mm5, mm3
1304
	
1305
	paddw		mm3, mm4			;wsptr[1,tmp10],[xxx],[1,tmp13],[xxx]
1306
	movq		mm1, mm2
1307
1308
	psubw		mm5, mm4			;wsptr[1,tmp11],[xxx],[1,tmp14],[xxx]
1309
	punpcklwd	mm0, mm3			;wsptr[0,tmp10],[1,tmp10],[xxx],[xxx]
1310
1311
	movq		mm7, [esi+8*7]		;wsptr[3,4],[3,5],[3,6],[3,7]
1312
	punpckhwd	mm6, mm3			;wsptr[0,tmp13],[1,tmp13],[xxx],[xxx]
1313
1314
	movq		mm3, [esi+8*4]		;wsptr[2,0],[2,1],[2,2],[2,3]
1315
	punpckldq	mm0, mm6	;wsptr[0,tmp10],[1,tmp10],[0,tmp13],[1,tmp13]
1316
1317
	punpcklwd	mm1, mm5			;wsptr[0,tmp11],[1,tmp11],[xxx],[xxx]
1318
	movq		mm4, mm3
1319
1320
	movq		mm6, [esi+8*6]		;wsptr[3,0],[3,1],[3,2],[3,3]
1321
	punpckhwd	mm2, mm5			;wsptr[0,tmp14],[1,tmp14],[xxx],[xxx]
1322
1323
	movq		mm5, [esi+8*5]		;wsptr[2,4],[2,5],[2,6],[2,7]
1324
	punpckldq	mm1, mm2	;wsptr[0,tmp11],[1,tmp11],[0,tmp14],[1,tmp14]
1325
1326
	
1327
	paddw		mm3, mm5			;wsptr[2,tmp10],[xxx],[2,tmp13],[xxx]
1328
	movq		mm2, mm6
1329
1330
	psubw		mm4, mm5			;wsptr[2,tmp11],[xxx],[2,tmp14],[xxx]
1331
	paddw		mm6, mm7			;wsptr[3,tmp10],[xxx],[3,tmp13],[xxx]
1332
1333
	movq		mm5, mm3
1334
	punpcklwd	mm3, mm6			;wsptr[2,tmp10],[3,tmp10],[xxx],[xxx]
1335
	
1336
	psubw		mm2, mm7			;wsptr[3,tmp11],[xxx],[3,tmp14],[xxx]
1337
	punpckhwd	mm5, mm6			;wsptr[2,tmp13],[3,tmp13],[xxx],[xxx]
1338
1339
	movq		mm7, mm4
1340
	punpckldq	mm3, mm5	;wsptr[2,tmp10],[3,tmp10],[2,tmp13],[3,tmp13]
1341
1342
	punpcklwd	mm4, mm2			;wsptr[2,tmp11],[3,tmp11],[xxx],[xxx]
1343
1344
	punpckhwd	mm7, mm2			;wsptr[2,tmp14],[3,tmp14],[xxx],[xxx]
1345
1346
	punpckldq	mm4, mm7	;wsptr[2,tmp11],[3,tmp11],[2,tmp14],[3,tmp14]
1347
	movq		mm6, mm1
1348
1349
//	mm0 = 	;wsptr[0,tmp10],[1,tmp10],[0,tmp13],[1,tmp13]
1350
//	mm1 =	;wsptr[0,tmp11],[1,tmp11],[0,tmp14],[1,tmp14]
1351
1352
1353
	movq		mm2, mm0
1354
	punpckhdq	mm6, mm4	;wsptr[0,tmp14],[1,tmp14],[2,tmp14],[3,tmp14]
1355
1356
	punpckldq	mm1, mm4	;wsptr[0,tmp11],[1,tmp11],[2,tmp11],[3,tmp11]
1357
	psllw		mm6, 2
1358
1359
	pmulhw		mm6, fix_141
1360
	punpckldq	mm0, mm3	;wsptr[0,tmp10],[1,tmp10],[2,tmp10],[3,tmp10]
1361
1362
	punpckhdq	mm2, mm3	;wsptr[0,tmp13],[1,tmp13],[2,tmp13],[3,tmp13]
1363
	movq		mm7, mm0
1364
1365
//    tmp0 = tmp10 + tmp13;
1366
//    tmp3 = tmp10 - tmp13;
1367
	paddw		mm0, mm2	;[0,tmp0],[1,tmp0],[2,tmp0],[3,tmp0]
1368
	psubw		mm7, mm2	;[0,tmp3],[1,tmp3],[2,tmp3],[3,tmp3]
1369
1370
//    tmp12 = MULTIPLY(tmp14, FIX_1_414213562) - tmp13;
1371
	psubw		mm6, mm2	;wsptr[0,tmp12],[1,tmp12],[2,tmp12],[3,tmp12]
1372
//    tmp1 = tmp11 + tmp12;
1373
//    tmp2 = tmp11 - tmp12;
1374
	movq		mm5, mm1
1375
1376
1377
1378
    /* Odd part */
1379
1380
//    z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
1381
//    z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
1382
//    z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
1383
//    z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
1384
	movq		mm3, [esi+8*0]		;wsptr[0,0],[0,1],[0,2],[0,3]
1385
	paddw		mm1, mm6	;[0,tmp1],[1,tmp1],[2,tmp1],[3,tmp1]
1386
1387
	movq		mm4, [esi+8*1]		;wsptr[0,4],[0,5],[0,6],[0,7]
1388
	psubw		mm5, mm6	;[0,tmp2],[1,tmp2],[2,tmp2],[3,tmp2]
1389
1390
	movq		mm6, mm3
1391
	punpckldq	mm3, mm4			;wsptr[0,0],[0,1],[0,4],[0,5]
1392
1393
	punpckhdq	mm4, mm6			;wsptr[0,6],[0,7],[0,2],[0,3]
1394
	movq		mm2, mm3
1395
1396
//Save tmp0 and tmp1 in wsptr
1397
	movq		[esi+8*0], mm0		;save tmp0
1398
	paddw		mm2, mm4			;wsptr[xxx],[0,z11],[xxx],[0,z13]
1399
1400
	
1401
//Continue with z10 --- z13
1402
	movq		mm6, [esi+8*2]		;wsptr[1,0],[1,1],[1,2],[1,3]
1403
	psubw		mm3, mm4			;wsptr[xxx],[0,z12],[xxx],[0,z10]
1404
1405
	movq		mm0, [esi+8*3]		;wsptr[1,4],[1,5],[1,6],[1,7]
1406
	movq		mm4, mm6
1407
1408
	movq		[esi+8*1], mm1		;save tmp1
1409
	punpckldq	mm6, mm0			;wsptr[1,0],[1,1],[1,4],[1,5]
1410
1411
	punpckhdq	mm0, mm4			;wsptr[1,6],[1,7],[1,2],[1,3]
1412
	movq		mm1, mm6
1413
	
1414
//Save tmp2 and tmp3 in wsptr
1415
	paddw		mm6, mm0		;wsptr[xxx],[1,z11],[xxx],[1,z13]
1416
	movq		mm4, mm2
1417
	
1418
//Continue with z10 --- z13
1419
	movq		[esi+8*2], mm5		;save tmp2
1420
	punpcklwd	mm2, mm6		;wsptr[xxx],[xxx],[0,z11],[1,z11]
1421
1422
	psubw		mm1, mm0		;wsptr[xxx],[1,z12],[xxx],[1,z10]
1423
	punpckhwd	mm4, mm6		;wsptr[xxx],[xxx],[0,z13],[1,z13]
1424
1425
	movq		mm0, mm3
1426
	punpcklwd	mm3, mm1		;wsptr[xxx],[xxx],[0,z12],[1,z12]
1427
1428
	movq		[esi+8*3], mm7		;save tmp3
1429
	punpckhwd	mm0, mm1		;wsptr[xxx],[xxx],[0,z10],[1,z10]
1430
1431
	movq		mm6, [esi+8*4]		;wsptr[2,0],[2,1],[2,2],[2,3]
1432
	punpckhdq	mm0, mm2		;wsptr[0,z10],[1,z10],[0,z11],[1,z11]
1433
1434
	movq		mm7, [esi+8*5]		;wsptr[2,4],[2,5],[2,6],[2,7]
1435
	punpckhdq	mm3, mm4		;wsptr[0,z12],[1,z12],[0,z13],[1,z13]
1436
1437
	movq		mm1, [esi+8*6]		;wsptr[3,0],[3,1],[3,2],[3,3]
1438
	movq		mm4, mm6
1439
1440
	punpckldq	mm6, mm7			;wsptr[2,0],[2,1],[2,4],[2,5]
1441
	movq		mm5, mm1
1442
1443
	punpckhdq	mm7, mm4			;wsptr[2,6],[2,7],[2,2],[2,3]
1444
	movq		mm2, mm6
1445
	
1446
	movq		mm4, [esi+8*7]		;wsptr[3,4],[3,5],[3,6],[3,7]
1447
	paddw		mm6, mm7		;wsptr[xxx],[2,z11],[xxx],[2,z13]
1448
1449
	psubw		mm2, mm7		;wsptr[xxx],[2,z12],[xxx],[2,z10]
1450
	punpckldq	mm1, mm4			;wsptr[3,0],[3,1],[3,4],[3,5]
1451
1452
	punpckhdq	mm4, mm5			;wsptr[3,6],[3,7],[3,2],[3,3]
1453
	movq		mm7, mm1
1454
1455
	paddw		mm1, mm4		;wsptr[xxx],[3,z11],[xxx],[3,z13]
1456
	psubw		mm7, mm4		;wsptr[xxx],[3,z12],[xxx],[3,z10]
1457
1458
	movq		mm5, mm6
1459
	punpcklwd	mm6, mm1		;wsptr[xxx],[xxx],[2,z11],[3,z11]
1460
1461
	punpckhwd	mm5, mm1		;wsptr[xxx],[xxx],[2,z13],[3,z13]
1462
	movq		mm4, mm2
1463
1464
	punpcklwd	mm2, mm7		;wsptr[xxx],[xxx],[2,z12],[3,z12]
1465
1466
	punpckhwd	mm4, mm7		;wsptr[xxx],[xxx],[2,z10],[3,z10]
1467
1468
	punpckhdq	mm4, mm6		;wsptr[2,z10],[3,z10],[2,z11],[3,z11]
1469
1470
	punpckhdq	mm2, mm5		;wsptr[2,z12],[3,z12],[2,z13],[3,z13]
1471
	movq		mm5, mm0
1472
1473
	punpckldq	mm0, mm4		;wsptr[0,z10],[1,z10],[2,z10],[3,z10]
1474
1475
	punpckhdq	mm5, mm4		;wsptr[0,z11],[1,z11],[2,z11],[3,z11]
1476
	movq		mm4, mm3
1477
1478
	punpckhdq	mm4, mm2		;wsptr[0,z13],[1,z13],[2,z13],[3,z13]
1479
	movq		mm1, mm5
1480
1481
	punpckldq	mm3, mm2		;wsptr[0,z12],[1,z12],[2,z12],[3,z12]
1482
//    tmp7 = z11 + z13;		/* phase 5 */
1483
//    tmp8 = z11 - z13;		/* phase 5 */
1484
	psubw		mm1, mm4		;tmp8
1485
1486
	paddw		mm5, mm4		;tmp7
1487
//    tmp21 = MULTIPLY(tmp8, FIX_1_414213562); /* 2*c4 */
1488
	psllw		mm1, 2
1489
1490
	psllw		mm0, 2
1491
1492
	pmulhw		mm1, fix_141	;tmp21
1493
//    tmp20 = MULTIPLY(z12, (FIX_1_082392200- FIX_1_847759065))  /* 2*(c2-c6) */
1494
//			+ MULTIPLY(z10, - FIX_1_847759065); /* 2*c2 */
1495
	psllw		mm3, 2
1496
	movq		mm7, mm0
1497
1498
	pmulhw		mm7, fix_n184
1499
	movq		mm6, mm3
1500
1501
	movq		mm2, [esi+8*0]	;tmp0,final1
1502
1503
	pmulhw		mm6, fix_108n184
1504
//	 tmp22 = MULTIPLY(z10,(FIX_1_847759065 - FIX_2_613125930)) /* -2*(c2+c6) */
1505
//			+ MULTIPLY(z12, FIX_1_847759065); /* 2*c2 */
1506
	movq		mm4, mm2		;final1
1507
  
1508
	pmulhw		mm0, fix_184n261
1509
	paddw		mm2, mm5		;tmp0+tmp7,final1
1510
1511
	pmulhw		mm3, fix_184
1512
	psubw		mm4, mm5		;tmp0-tmp7,final1
1513
1514
//    tmp6 = tmp22 - tmp7;	/* phase 2 */
1515
	psraw		mm2, 5			;outptr[0,0],[1,0],[2,0],[3,0],final1
1516
1517
	paddsw		mm2, const_0x0080	;final1
1518
	paddw		mm7, mm6			;tmp20
1519
	psraw		mm4, 5			;outptr[0,7],[1,7],[2,7],[3,7],final1
1520
1521
	paddsw		mm4, const_0x0080	;final1
1522
	paddw		mm3, mm0			;tmp22
1523
1524
//    tmp5 = tmp21 - tmp6;
1525
	psubw		mm3, mm5		;tmp6
1526
1527
//    tmp4 = tmp20 + tmp5;
1528
	movq		mm0, [esi+8*1]		;tmp1,final2
1529
	psubw		mm1, mm3		;tmp5
1530
1531
	movq		mm6, mm0			;final2
1532
	paddw		mm0, mm3		;tmp1+tmp6,final2
1533
1534
    /* Final output stage: scale down by a factor of 8 and range-limit */
1535
1536
1537
//    outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
1538
//			    & RANGE_MASK];
1539
//    outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
1540
//			    & RANGE_MASK];	final1
1541
1542
1543
//    outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
1544
//			    & RANGE_MASK];
1545
//    outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
1546
//			    & RANGE_MASK];	final2
1547
	psubw		mm6, mm3		;tmp1-tmp6,final2
1548
	psraw		mm0, 5			;outptr[0,1],[1,1],[2,1],[3,1]
1549
1550
	paddsw		mm0, const_0x0080
1551
	psraw		mm6, 5			;outptr[0,6],[1,6],[2,6],[3,6]
1552
	
1553
	paddsw		mm6, const_0x0080		;need to check this value
1554
	packuswb	mm0, mm4	;out[0,1],[1,1],[2,1],[3,1],[0,7],[1,7],[2,7],[3,7]
1555
	
1556
	movq		mm5, [esi+8*2]		;tmp2,final3
1557
	packuswb	mm2, mm6	;out[0,0],[1,0],[2,0],[3,0],[0,6],[1,6],[2,6],[3,6]
1558
1559
//    outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
1560
//			    & RANGE_MASK];
1561
//    outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
1562
//			    & RANGE_MASK];	final3
1563
	paddw		mm7, mm1		;tmp4
1564
	movq		mm3, mm5
1565
1566
	paddw		mm5, mm1		;tmp2+tmp5
1567
	psubw		mm3, mm1		;tmp2-tmp5
1568
1569
	psraw		mm5, 5			;outptr[0,2],[1,2],[2,2],[3,2]
1570
1571
	paddsw		mm5, const_0x0080
1572
	movq		mm4, [esi+8*3]		;tmp3,final4
1573
	psraw		mm3, 5			;outptr[0,5],[1,5],[2,5],[3,5]
1574
1575
	paddsw		mm3, const_0x0080
1576
1577
1578
//    outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
1579
//			    & RANGE_MASK];
1580
//    outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
1581
//			    & RANGE_MASK];	final4
1582
	movq		mm6, mm4
1583
	paddw		mm4, mm7		;tmp3+tmp4
1584
1585
	psubw		mm6, mm7		;tmp3-tmp4
1586
	psraw		mm4, 5			;outptr[0,4],[1,4],[2,4],[3,4]
1587
	mov			ecx, [eax]
1588
1589
	paddsw		mm4, const_0x0080
1590
	psraw		mm6, 5			;outptr[0,3],[1,3],[2,3],[3,3]
1591
1592
	paddsw		mm6, const_0x0080
1593
	packuswb	mm5, mm4	;out[0,2],[1,2],[2,2],[3,2],[0,4],[1,4],[2,4],[3,4]
1594
1595
	packuswb	mm6, mm3	;out[0,3],[1,3],[2,3],[3,3],[0,5],[1,5],[2,5],[3,5]
1596
	movq		mm4, mm2
1597
1598
	movq		mm7, mm5
1599
	punpcklbw	mm2, mm0	;out[0,0],[0,1],[1,0],[1,1],[2,0],[2,1],[3,0],[3,1]
1600
1601
	punpckhbw	mm4, mm0	;out[0,6],[0,7],[1,6],[1,7],[2,6],[2,7],[3,6],[3,7]
1602
	movq		mm1, mm2
1603
1604
	punpcklbw	mm5, mm6	;out[0,2],[0,3],[1,2],[1,3],[2,2],[2,3],[3,2],[3,3]
1605
	add		 	eax, 4
1606
1607
	punpckhbw	mm7, mm6	;out[0,4],[0,5],[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]
1608
1609
	punpcklwd	mm2, mm5	;out[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3]
1610
	add			ecx, output_col
1611
1612
	movq		mm6, mm7
1613
	punpckhwd	mm1, mm5	;out[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]
1614
1615
	movq		mm0, mm2
1616
	punpcklwd	mm6, mm4	;out[0,4],[0,5],[0,6],[0,7],[1,4],[1,5],[1,6],[1,7]
1617
1618
	mov			ebx, [eax]
1619
	punpckldq	mm2, mm6	;out[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7]
1620
1621
	add		 	eax, 4
1622
	movq		mm3, mm1
1623
1624
	add			ebx, output_col 
1625
	punpckhwd	mm7, mm4	;out[2,4],[2,5],[2,6],[2,7],[3,4],[3,5],[3,6],[3,7]
1626
	
1627
	movq		[ecx], mm2
1628
	punpckhdq	mm0, mm6	;out[1,0],[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7]
1629
1630
	mov			ecx, [eax]
1631
	add		 	eax, 4
1632
	add			ecx, output_col
1633
1634
	movq		[ebx], mm0
1635
	punpckldq	mm1, mm7	;out[2,0],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7]
1636
1637
	mov			ebx, [eax]
1638
1639
	add			ebx, output_col
1640
	punpckhdq	mm3, mm7	;out[3,0],[3,1],[3,2],[3,3],[3,4],[3,5],[3,6],[3,7]
1641
	movq		[ecx], mm1
1642
1643
	movq		[ebx], mm3
1644
1645
	emms
1646
	}
1647
}
1648
#endif
1649
1650
#endif /* DCT_IFAST_SUPPORTED */
368
#endif /* DCT_IFAST_SUPPORTED */
(-)a/jpeg/jidctint.c (-574 lines)
Line     Link Here 
 Lines 381-963   jpeg_idct_islow (j_decompress_ptr cinfo, Link Here 
381
    outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
381
    outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
382
					  CONST_BITS+PASS1_BITS+3)
382
					  CONST_BITS+PASS1_BITS+3)
383
			    & RANGE_MASK];
383
			    & RANGE_MASK];
384
    
384
    
385
    wsptr += DCTSIZE;		/* advance pointer to next row */
385
    wsptr += DCTSIZE;		/* advance pointer to next row */
386
  }
386
  }
387
}
387
}
388
388
389
390
#ifdef HAVE_SSE2_INTEL_MNEMONICS
391
392
/*
393
* Intel SSE2 optimized Inverse Discrete Cosine Transform
394
*
395
*
396
* Copyright (c) 2001-2002 Intel Corporation
397
* All Rights Reserved
398
*
399
*
400
*  Authors:
401
*      Danilov G.
402
*
403
*
404
*-----------------------------------------------------------------------------
405
*
406
* References:
407
*    K.R. Rao and P. Yip
408
*       Discrete Cosine Transform.
409
*       Algorithms, Advantages, Applications.
410
*       Academic Press, Inc, London, 1990.
411
*    JPEG Group's software.
412
*       This implementation is based on Appendix A.2 of the book (R&Y) ...
413
*
414
*-----------------------------------------------------------------------------
415
*/
416
417
typedef unsigned char   Ipp8u;
418
typedef unsigned short  Ipp16u;
419
typedef unsigned int    Ipp32u;
420
421
typedef signed char    Ipp8s;
422
typedef signed short   Ipp16s;
423
typedef signed int     Ipp32s;
424
425
#define BITS_INV_ACC  4			
426
#define SHIFT_INV_ROW  16 - BITS_INV_ACC
427
#define SHIFT_INV_COL 1 + BITS_INV_ACC
428
429
#define RND_INV_ROW  1024 * (6 - BITS_INV_ACC)	/* 1 << (SHIFT_INV_ROW-1)		*/
430
#define RND_INV_COL = 16 * (BITS_INV_ACC - 3)   /* 1 << (SHIFT_INV_COL-1)		*/
431
#define RND_INV_CORR = RND_INV_COL - 1          /* correction -1.0 and round	*/
432
433
#define c_inv_corr_0 -1024 * (6 - BITS_INV_ACC) + 65536		/* -0.5 + (16.0 or 32.0)	*/
434
#define c_inv_corr_1 1877 * (6 - BITS_INV_ACC)				/* 0.9167	*/	
435
#define c_inv_corr_2 1236 * (6 - BITS_INV_ACC)				/* 0.6035	*/					
436
#define c_inv_corr_3 680  * (6 - BITS_INV_ACC)				/* 0.3322	*/
437
#define c_inv_corr_4 0    * (6 - BITS_INV_ACC)				/* 0.0		*/	
438
#define c_inv_corr_5 -569  * (6 - BITS_INV_ACC)				/* -0.278	*/
439
#define c_inv_corr_6 -512  * (6 - BITS_INV_ACC)				/* -0.25	*/	
440
#define c_inv_corr_7 -651  * (6 - BITS_INV_ACC)				/* -0.3176	*/	
441
442
#define RND_INV_ROW_0 RND_INV_ROW + c_inv_corr_0
443
#define RND_INV_ROW_1 RND_INV_ROW + c_inv_corr_1
444
#define RND_INV_ROW_2 RND_INV_ROW + c_inv_corr_2
445
#define RND_INV_ROW_3 RND_INV_ROW + c_inv_corr_3
446
#define RND_INV_ROW_4 RND_INV_ROW + c_inv_corr_4
447
#define RND_INV_ROW_5 RND_INV_ROW + c_inv_corr_5
448
#define RND_INV_ROW_6 RND_INV_ROW + c_inv_corr_6
449
#define RND_INV_ROW_7 RND_INV_ROW + c_inv_corr_7
450
451
/* Table for rows 0,4 - constants are multiplied on cos_4_16 */
452
453
__declspec(align(16)) short tab_i_04[] = { 
454
	16384, 21407, 16384, 8867,		
455
	-16384, 21407, 16384, -8867,	
456
	16384,  -8867,  16384, -21407,  
457
    16384,   8867, -16384, -21407,  
458
    22725,  19266,  19266,  -4520,  
459
    4520,  19266,  19266, -22725,   
460
    12873, -22725,   4520, -12873,  
461
    12873,   4520, -22725, -12873}; 
462
463
/* Table for rows 1,7 - constants are multiplied on cos_1_16 */
464
465
__declspec(align(16)) short tab_i_17[] = {
466
	22725,  29692,  22725,  12299,   
467
    -22725,  29692,  22725, -12299,  
468
    22725, -12299,  22725, -29692,   
469
    22725,  12299, -22725, -29692,   
470
    31521,  26722,  26722,  -6270,   
471
    6270,  26722,  26722, -31521,    
472
    17855, -31521,   6270, -17855,   
473
    17855,   6270, -31521, -17855};  
474
475
/* Table for rows 2,6 - constants are multiplied on cos_2_16 */
476
477
__declspec(align(16)) short tab_i_26[] = {
478
	21407,  27969,  21407,  11585,	
479
    -21407,  27969,  21407, -11585,	
480
    21407, -11585,  21407, -27969,	
481
    21407,  11585, -21407, -27969,	
482
    29692,  25172,  25172,  -5906,	
483
    5906,  25172,  25172, -29692,	
484
    16819, -29692,   5906, -16819,	
485
    16819,   5906, -29692, -16819};	
486
487
/* Table for rows 3,5 - constants are multiplied on cos_3_16 */
488
489
__declspec(align(16)) short tab_i_35[] = {
490
	19266,  25172,  19266,  10426,	
491
    -19266,  25172,  19266, -10426,	
492
    19266, -10426,  19266, -25172,	
493
    19266,  10426, -19266, -25172,	
494
    26722,  22654,  22654,  -5315,	
495
    5315,  22654,  22654, -26722,	
496
    15137, -26722,   5315, -15137,	
497
    15137,   5315, -26722, -15137};	
498
	
499
__declspec(align(16)) long round_i_0[] = {RND_INV_ROW_0,RND_INV_ROW_0,
500
	RND_INV_ROW_0,RND_INV_ROW_0};
501
__declspec(align(16)) long round_i_1[] = {RND_INV_ROW_1,RND_INV_ROW_1,
502
	RND_INV_ROW_1,RND_INV_ROW_1};
503
__declspec(align(16)) long round_i_2[] = {RND_INV_ROW_2,RND_INV_ROW_2,
504
	RND_INV_ROW_2,RND_INV_ROW_2};
505
__declspec(align(16)) long round_i_3[] = {RND_INV_ROW_3,RND_INV_ROW_3,
506
	RND_INV_ROW_3,RND_INV_ROW_3};
507
__declspec(align(16)) long round_i_4[] = {RND_INV_ROW_4,RND_INV_ROW_4,
508
	RND_INV_ROW_4,RND_INV_ROW_4};
509
__declspec(align(16)) long round_i_5[] = {RND_INV_ROW_5,RND_INV_ROW_5,
510
	RND_INV_ROW_5,RND_INV_ROW_5};
511
__declspec(align(16)) long round_i_6[] = {RND_INV_ROW_6,RND_INV_ROW_6,
512
	RND_INV_ROW_6,RND_INV_ROW_6};
513
__declspec(align(16)) long round_i_7[] = {RND_INV_ROW_7,RND_INV_ROW_7,
514
	RND_INV_ROW_7,RND_INV_ROW_7};
515
516
__declspec(align(16)) short tg_1_16[] = {
517
	13036,  13036,  13036,  13036,	/* tg * (2<<16) + 0.5 */
518
	13036,  13036,  13036,  13036};
519
__declspec(align(16)) short tg_2_16[] = {
520
	27146,  27146,  27146,  27146,	/* tg * (2<<16) + 0.5 */
521
	27146,  27146,  27146,  27146};
522
__declspec(align(16)) short tg_3_16[] = {
523
	-21746, -21746, -21746, -21746,	/* tg * (2<<16) + 0.5 */
524
	-21746, -21746, -21746, -21746};
525
__declspec(align(16)) short cos_4_16[] = {
526
	-19195, -19195, -19195, -19195,	/* cos * (2<<16) + 0.5 */
527
	-19195, -19195, -19195, -19195};
528
529
/*
530
* In this implementation the outputs of the iDCT-1D are multiplied
531
*    for rows 0,4 - on cos_4_16,
532
*    for rows 1,7 - on cos_1_16,
533
*    for rows 2,6 - on cos_2_16,
534
*    for rows 3,5 - on cos_3_16
535
* and are shifted to the left for rise of accuracy
536
*
537
* For used constants
538
*    FIX(float_const) = (short) (float_const * (1<<15) + 0.5)
539
*
540
*-----------------------------------------------------------------------------
541
*
542
* On the first stage the calculation is executed at once for two rows.
543
* The permutation for each output row is done on second stage
544
*    t7 t6 t5 t4 t3 t2 t1 t0 -> t4 t5 t6 t7 t3 t2 t1 t0
545
*
546
*-----------------------------------------------------------------------------
547
*/
548
	
549
#define DCT_8_INV_ROW_2R(TABLE, ROUND1, ROUND2) __asm {	\
550
	__asm pshuflw  xmm1, xmm0, 10001000b				\
551
    __asm pshuflw  xmm0, xmm0, 11011101b    			\
552
    __asm pshufhw  xmm1, xmm1, 10001000b    			\
553
	__asm pshufhw  xmm0, xmm0, 11011101b				\
554
	__asm movdqa   xmm2, XMMWORD PTR [TABLE]			\
555
	__asm pmaddwd  xmm2, xmm1							\
556
	__asm movdqa   xmm3, XMMWORD PTR [TABLE + 32]		\
557
	__asm pmaddwd  xmm3, xmm0               			\
558
	__asm pmaddwd  xmm1, XMMWORD PTR [TABLE + 16]		\
559
	__asm pmaddwd  xmm0, XMMWORD PTR [TABLE + 48]		\
560
	__asm pshuflw  xmm5, xmm4, 10001000b				\
561
	__asm pshuflw  xmm4, xmm4, 11011101b    			\
562
	__asm pshufhw  xmm5, xmm5, 10001000b    			\
563
	__asm pshufhw  xmm4, xmm4, 11011101b    			\
564
	__asm movdqa   xmm6, XMMWORD PTR [TABLE]			\
565
	__asm pmaddwd  xmm6, xmm5               			\
566
	__asm movdqa   xmm7, XMMWORD PTR [TABLE + 32]		\
567
	__asm pmaddwd  xmm7, xmm4               			\
568
	__asm pmaddwd  xmm5, XMMWORD PTR [TABLE + 16]		\
569
	__asm pmaddwd  xmm4, XMMWORD PTR [TABLE + 48]		\
570
	__asm pshufd   xmm1, xmm1, 01001110b    			\
571
	__asm pshufd   xmm0, xmm0, 01001110b    			\
572
	__asm paddd    xmm2, XMMWORD PTR [ROUND1]			\
573
	__asm paddd    xmm3, xmm0							\
574
	__asm paddd    xmm1, xmm2							\
575
	__asm pshufd   xmm5, xmm5, 01001110b    			\
576
	__asm pshufd   xmm4, xmm4, 01001110b    			\
577
	__asm movdqa   xmm2, xmm1             				\
578
	__asm psubd    xmm2, xmm3             				\
579
	__asm psrad    xmm2, SHIFT_INV_ROW    				\
580
	__asm paddd    xmm1, xmm3							\
581
	__asm psrad    xmm1, SHIFT_INV_ROW      			\
582
	__asm packssdw xmm1, xmm2							\
583
	__asm paddd    xmm6, XMMWORD PTR [ROUND2]			\
584
	__asm paddd    xmm7, xmm4							\
585
	__asm paddd    xmm5, xmm6							\
586
	__asm movdqa   xmm6, xmm5	            			\
587
	__asm psubd    xmm6, xmm7               			\
588
	__asm psrad    xmm6, SHIFT_INV_ROW      			\
589
	__asm paddd    xmm5, xmm7							\
590
	__asm psrad    xmm5, SHIFT_INV_ROW      			\
591
	__asm packssdw xmm5, xmm6							\
592
	}
593
594
/*
595
*
596
* The second stage - inverse DCTs of columns
597
*
598
* The inputs are multiplied
599
*    for rows 0,4 - on cos_4_16,
600
*    for rows 1,7 - on cos_1_16,
601
*    for rows 2,6 - on cos_2_16,
602
*    for rows 3,5 - on cos_3_16
603
* and are shifted to the left for rise of accuracy
604
*/
605
606
#define DCT_8_INV_COL_8R(INP, OUTP) __asm {		\
607
	__asm movdqa   xmm0, [INP + 5*16]			\
608
    __asm movdqa   xmm1, XMMWORD PTR tg_3_16	\
609
    __asm movdqa   xmm2, xmm0            		\
610
    __asm movdqa   xmm3, [INP + 3*16]   		\
611
    __asm pmulhw   xmm0, xmm1           		\
612
    __asm movdqa   xmm4, [INP + 7*16]   		\
613
    __asm pmulhw   xmm1, xmm3           		\
614
    __asm movdqa   xmm5, XMMWORD PTR tg_1_16   	\
615
    __asm movdqa   xmm6, xmm4            		\
616
    __asm pmulhw   xmm4, xmm5           		\
617
    __asm paddsw   xmm0, xmm2           		\
618
    __asm pmulhw   xmm5, [INP + 1*16]   		\
619
    __asm paddsw   xmm1, xmm3           		\
620
    __asm movdqa   xmm7, [INP + 6*16]    		\
621
    __asm paddsw   xmm0, xmm3					\
622
    __asm movdqa   xmm3, XMMWORD PTR tg_2_16	\
623
    __asm psubsw   xmm2, xmm1					\
624
    __asm pmulhw   xmm7, xmm3            		\
625
    __asm movdqa   xmm1, xmm0            		\
626
    __asm pmulhw   xmm3, [INP + 2*16]   		\
627
    __asm psubsw   xmm5, xmm6					\
628
    __asm paddsw   xmm4, [INP + 1*16]    		\
629
    __asm paddsw   xmm0, xmm4            		\
630
    __asm psubsw   xmm4, xmm1					\
631
    __asm pshufhw  xmm0, xmm0, 00011011b		\
632
    __asm paddsw   xmm7, [INP + 2*16]    		\
633
    __asm movdqa   xmm6, xmm5					\
634
    __asm psubsw   xmm3, [INP + 6*16]    		\
635
    __asm psubsw   xmm5, xmm2            		\
636
    __asm paddsw   xmm6, xmm2					\
637
	__asm movdqa   [OUTP + 7*16], xmm0    		\
638
    __asm movdqa   xmm1, xmm4            		\
639
    __asm movdqa   xmm2, XMMWORD PTR cos_4_16  	\
640
    __asm paddsw   xmm4, xmm5            		\
641
    __asm movdqa   xmm0, XMMWORD PTR cos_4_16  	\
642
    __asm pmulhw   xmm2, xmm4					\
643
    __asm pshufhw  xmm6, xmm6, 00011011b		\
644
    __asm movdqa   [OUTP + 3*16], xmm6    		\
645
    __asm psubsw   xmm1, xmm5            		\
646
    __asm movdqa   xmm6, [INP + 0*16]   		\
647
    __asm pmulhw   xmm0, xmm1					\
648
    __asm movdqa   xmm5, [INP + 4*16]    		\
649
    __asm paddsw   xmm4, xmm2					\
650
    __asm paddsw   xmm5, xmm6       			\
651
    __asm psubsw   xmm6, [INP + 4*16]   		\
652
    __asm paddsw   xmm0, xmm1					\
653
    __asm pshufhw  xmm4, xmm4, 00011011b		\
654
    __asm movdqa   xmm2, xmm5            		\
655
    __asm paddsw   xmm5, xmm7            		\
656
    __asm movdqa   xmm1, xmm6					\
657
    __asm psubsw   xmm2, xmm7					\
658
    __asm movdqa   xmm7, [OUTP + 7*16]    		\
659
    __asm paddsw   xmm6, xmm3            		\
660
    __asm pshufhw  xmm5, xmm5, 00011011b		\
661
	__asm paddsw   xmm7, xmm5					\
662
    __asm psubsw   xmm1, xmm3					\
663
    __asm pshufhw  xmm6, xmm6, 00011011b		\
664
	__asm movdqa   xmm3, xmm6					\
665
    __asm paddsw   xmm6, xmm4            		\
666
    __asm pshufhw  xmm2, xmm2, 00011011b		\
667
    __asm psraw    xmm7, SHIFT_INV_COL   		\
668
    __asm movdqa   [OUTP + 0*16], xmm7    		\
669
    __asm movdqa   xmm7, xmm1            		\
670
    __asm paddsw   xmm1, xmm0					\
671
    __asm psraw    xmm6, SHIFT_INV_COL			\
672
    __asm movdqa   [OUTP + 1*16], xmm6    		\
673
    __asm pshufhw  xmm1, xmm1, 00011011b		\
674
	__asm movdqa   xmm6, [OUTP + 3*16]			\
675
    __asm psubsw   xmm7, xmm0            		\
676
    __asm psraw    xmm1, SHIFT_INV_COL   		\
677
    __asm movdqa   [OUTP + 2*16], xmm1    		\
678
    __asm psubsw   xmm5, [OUTP + 7*16]			\
679
    __asm paddsw   xmm6, xmm2            		\
680
    __asm psubsw   xmm2, [OUTP + 3*16]			\
681
    __asm psubsw   xmm3, xmm4            		\
682
    __asm psraw    xmm7, SHIFT_INV_COL  		\
683
    __asm pshufhw  xmm7, xmm7, 00011011b		\
684
    __asm movdqa   [OUTP + 5*16], xmm7    		\
685
    __asm psraw    xmm5, SHIFT_INV_COL			\
686
    __asm movdqa   [OUTP + 7*16], xmm5    		\
687
    __asm psraw    xmm6, SHIFT_INV_COL			\
688
    __asm movdqa   [OUTP + 3*16], xmm6    		\
689
    __asm psraw    xmm2, SHIFT_INV_COL			\
690
    __asm movdqa   [OUTP + 4*16], xmm2    		\
691
    __asm psraw    xmm3, SHIFT_INV_COL			\
692
    __asm movdqa   [OUTP + 6*16], xmm3    		\
693
	}
694
695
/*
696
*
697
*  Name:      dct_8x8_inv_16s
698
*  Purpose:   Inverse Discrete Cosine Transform 8x8 with
699
*             2D buffer of short int data
700
*  Context:
701
*      void dct_8x8_inv_16s ( short *src, short *dst )
702
*  Parameters:
703
*      src  - Pointer to the source buffer
704
*      dst  - Pointer to the destination buffer
705
*
706
*/
707
708
GLOBAL(void)
709
dct_8x8_inv_16s ( short *src, short *dst ) {
710
	
711
	__asm {
712
713
		mov     ecx,  src
714
		mov     edx,  dst
715
716
		movdqa  xmm0, [ecx+0*16]
717
		movdqa  xmm4, [ecx+4*16]
718
		DCT_8_INV_ROW_2R(tab_i_04, round_i_0, round_i_4)
719
		movdqa     [edx+0*16], xmm1 
720
		movdqa     [edx+4*16], xmm5 
721
722
		movdqa  xmm0, [ecx+1*16]
723
		movdqa  xmm4, [ecx+7*16]
724
		DCT_8_INV_ROW_2R(tab_i_17, round_i_1, round_i_7)
725
		movdqa     [edx+1*16], xmm1 
726
		movdqa     [edx+7*16], xmm5 
727
728
		movdqa  xmm0, [ecx+3*16]
729
		movdqa  xmm4, [ecx+5*16]
730
		DCT_8_INV_ROW_2R(tab_i_35, round_i_3, round_i_5);
731
		movdqa     [edx+3*16], xmm1 
732
		movdqa     [edx+5*16], xmm5 
733
734
		movdqa  xmm0, [ecx+2*16]
735
		movdqa  xmm4, [ecx+6*16]
736
		DCT_8_INV_ROW_2R(tab_i_26, round_i_2, round_i_6);
737
		movdqa     [edx+2*16], xmm1
738
		movdqa     [edx+6*16], xmm5    
739
740
		DCT_8_INV_COL_8R(edx+0, edx+0);
741
	}
742
}
743
744
745
/*
746
*  Name:
747
*    ownpj_QuantInv_8x8_16s
748
*
749
*  Purpose:
750
*    Dequantize 8x8 block of DCT coefficients
751
*
752
*  Context:
753
*    void ownpj_QuantInv_8x8_16s
754
*            Ipp16s*  pSrc,
755
*            Ipp16s*  pDst,
756
*      const Ipp16u*  pQTbl)*
757
*
758
*/
759
760
GLOBAL(void)
761
ownpj_QuantInv_8x8_16s(short * pSrc, short * pDst, const unsigned short * pQTbl)
762
{
763
	__asm {
764
765
		push        ebx
766
		push        ecx
767
		push        edx
768
		push        esi
769
		push        edi
770
771
		mov         esi, pSrc
772
		mov         edi, pDst
773
		mov         edx, pQTbl
774
		mov         ecx, 4
775
		mov         ebx, 32
776
777
	again:
778
779
		movq        mm0, QWORD PTR [esi+0]
780
		movq        mm1, QWORD PTR [esi+8]
781
		movq        mm2, QWORD PTR [esi+16]
782
		movq        mm3, QWORD PTR [esi+24]
783
784
		prefetcht0  [esi+ebx] ; fetch next cache line
785
786
		pmullw      mm0, QWORD PTR [edx+0]
787
		pmullw      mm1, QWORD PTR [edx+8]
788
		pmullw      mm2, QWORD PTR [edx+16]
789
		pmullw      mm3, QWORD PTR [edx+24]
790
791
		movq        QWORD PTR [edi+0], mm0
792
		movq        QWORD PTR [edi+8], mm1
793
		movq        QWORD PTR [edi+16], mm2
794
		movq        QWORD PTR [edi+24], mm3
795
796
		add         esi, ebx
797
		add         edi, ebx
798
		add         edx, ebx
799
		dec         ecx
800
		jnz         again
801
802
		emms
803
804
		pop         edi
805
		pop         esi
806
		pop         edx
807
		pop         ecx
808
		pop         ebx
809
	}
810
}
811
812
813
/*
814
*  Name:
815
*    ownpj_Add128_8x8_16s8u
816
*
817
*  Purpose:
818
*    signed to unsigned conversion (level shift)
819
*    for 8x8 block of DCT coefficients
820
*
821
*  Context:
822
*    void ownpj_Add128_8x8_16s8u
823
*      const Ipp16s* pSrc,
824
*            Ipp8u*  pDst,
825
*            int     DstStep);
826
*
827
*/
828
829
__declspec(align(16)) long const_128[]= {0x00800080, 0x00800080, 0x00800080, 0x00800080};
830
831
GLOBAL(void)
832
ownpj_Add128_8x8_16s8u(const short * pSrc, unsigned char * pDst, int DstStep)
833
{
834
	__asm {
835
		push        eax
836
		push        ebx
837
		push        ecx
838
		push        edx
839
		push        esi
840
		push        edi
841
842
		mov         esi, pSrc
843
		mov         edi, pDst
844
		mov         edx, DstStep
845
		mov         ecx, 2
846
		mov         ebx, edx
847
		mov         eax, edx
848
		sal         ebx, 1
849
		add         eax, ebx
850
		movdqa      xmm7, XMMWORD PTR const_128
851
852
	again:
853
854
		movdqa      xmm0, XMMWORD PTR [esi+0]  ; line 0
855
		movdqa      xmm1, XMMWORD PTR [esi+16] ; line 1
856
		movdqa      xmm2, XMMWORD PTR [esi+32] ; line 2
857
		movdqa      xmm3, XMMWORD PTR [esi+48] ; line 3
858
859
		paddw     xmm0, xmm7
860
		paddw     xmm1, xmm7
861
		paddw     xmm2, xmm7
862
		paddw     xmm3, xmm7
863
864
		packuswb  xmm0, xmm1
865
		packuswb  xmm2, xmm3
866
867
		movq      QWORD PTR [edi], xmm0      ;0*DstStep
868
		movq      QWORD PTR [edi+ebx], xmm2  ;2*DstStep
869
870
		psrldq      xmm0, 8
871
		psrldq      xmm2, 8
872
873
		movq      QWORD PTR [edi+edx], xmm0  ;1*DstStep
874
		movq      QWORD PTR [edi+eax], xmm2  ;3*DstStep
875
876
		add         edi, ebx
877
		add         esi, 64
878
		add         edi, ebx
879
		dec         ecx
880
		jnz         again
881
882
		pop         edi
883
		pop         esi
884
		pop         edx
885
		pop         ecx
886
		pop         ebx
887
		pop         eax
888
	}
889
}
890
891
892
/* 
893
*  Name:
894
*    ippiDCTQuantInv8x8LS_JPEG_16s8u_C1R
895
*
896
*  Purpose:
897
*    Inverse DCT transform, de-quantization and level shift
898
*
899
*  Parameters:
900
*    pSrc               - pointer to source
901
*    pDst               - pointer to output array
902
*    DstStep            - line offset for output data
903
*    pEncoderQuantTable - pointer to Quantization table
904
*
905
*/
906
907
GLOBAL(void)
908
ippiDCTQuantInv8x8LS_JPEG_16s8u_C1R(
909
  short * pSrc,
910
  unsigned char *  pDst,
911
  int     DstStep,
912
  const unsigned short * pQuantInvTable)
913
{
914
915
	__declspec(align(16)) Ipp8u buf[DCTSIZE2*sizeof(Ipp16s)];
916
	Ipp16s * workbuf = (Ipp16s *)buf;	
917
918
	ownpj_QuantInv_8x8_16s(pSrc,workbuf,pQuantInvTable);
919
	dct_8x8_inv_16s(workbuf,workbuf);
920
	ownpj_Add128_8x8_16s8u(workbuf,pDst,DstStep);
921
  
922
} 
923
924
GLOBAL(void)
925
jpeg_idct_islow_sse2 (
926
	j_decompress_ptr cinfo, 
927
	jpeg_component_info * compptr,
928
	JCOEFPTR coef_block,
929
	JSAMPARRAY output_buf, 
930
	JDIMENSION output_col)
931
{
932
	int			ctr;
933
	JCOEFPTR	inptr;
934
	Ipp16u*		quantptr;
935
	Ipp8u*		wsptr;
936
	__declspec(align(16)) Ipp8u workspace[DCTSIZE2];  	
937
	JSAMPROW	outptr;
938
939
	inptr = coef_block;
940
	quantptr = (Ipp16u*)compptr->dct_table;
941
	wsptr = workspace;
942
	
943
	ippiDCTQuantInv8x8LS_JPEG_16s8u_C1R(inptr, workspace, 8, quantptr);
944
945
	for(ctr = 0; ctr < DCTSIZE; ctr++)
946
	{
947
		outptr = output_buf[ctr] + output_col;
948
949
		outptr[0] = wsptr[0];
950
		outptr[1] = wsptr[1];
951
		outptr[2] = wsptr[2];
952
		outptr[3] = wsptr[3];
953
		outptr[4] = wsptr[4];
954
		outptr[5] = wsptr[5];
955
		outptr[6] = wsptr[6];
956
		outptr[7] = wsptr[7];
957
958
		wsptr += DCTSIZE;
959
	}
960
}
961
#endif /* HAVE_SSE2_INTEL_MNEMONICS */
962
963
#endif /* DCT_ISLOW_SUPPORTED */
389
#endif /* DCT_ISLOW_SUPPORTED */
(-)a/jpeg/jmemansi.c (-167 lines)
Line     Link Here 
 Lines 1-167    Link Here 
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		/* <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
}
(-)a/jpeg/jmemdos.c (-638 lines)
Line     Link Here 
 Lines 1-638    Link Here 
1
/*
2
 * jmemdos.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 an MS-DOS-compatible implementation of the system-
9
 * dependent portion of the JPEG memory manager.  Temporary data can be
10
 * stored in extended or expanded memory as well as in regular DOS files.
11
 *
12
 * If you use this file, you must be sure that NEED_FAR_POINTERS is defined
13
 * if you compile in a small-data memory model; it should NOT be defined if
14
 * you use a large-data memory model.  This file is not recommended if you
15
 * are using a flat-memory-space 386 environment such as DJGCC or Watcom C.
16
 * Also, this code will NOT work if struct fields are aligned on greater than
17
 * 2-byte boundaries.
18
 *
19
 * Based on code contributed by Ge' Weijers.
20
 */
21
22
/*
23
 * If you have both extended and expanded memory, you may want to change the
24
 * order in which they are tried in jopen_backing_store.  On a 286 machine
25
 * expanded memory is usually faster, since extended memory access involves
26
 * an expensive protected-mode-and-back switch.  On 386 and better, extended
27
 * memory is usually faster.  As distributed, the code tries extended memory
28
 * first (what? not everyone has a 386? :-).
29
 *
30
 * You can disable use of extended/expanded memory entirely by altering these
31
 * definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0).
32
 */
33
34
#ifndef XMS_SUPPORTED
35
#define XMS_SUPPORTED  1
36
#endif
37
#ifndef EMS_SUPPORTED
38
#define EMS_SUPPORTED  1
39
#endif
40
41
42
#define JPEG_INTERNALS
43
#include "jinclude.h"
44
#include "jpeglib.h"
45
#include "jmemsys.h"		/* import the system-dependent declarations */
46
47
#ifndef HAVE_STDLIB_H		/* <stdlib.h> should declare these */
48
extern void * malloc JPP((size_t size));
49
extern void free JPP((void *ptr));
50
extern char * getenv JPP((const char * name));
51
#endif
52
53
#ifdef NEED_FAR_POINTERS
54
55
#ifdef __TURBOC__
56
/* These definitions work for Borland C (Turbo C) */
57
#include <alloc.h>		/* need farmalloc(), farfree() */
58
#define far_malloc(x)	farmalloc(x)
59
#define far_free(x)	farfree(x)
60
#else
61
/* These definitions work for Microsoft C and compatible compilers */
62
#include <malloc.h>		/* need _fmalloc(), _ffree() */
63
#define far_malloc(x)	_fmalloc(x)
64
#define far_free(x)	_ffree(x)
65
#endif
66
67
#else /* not NEED_FAR_POINTERS */
68
69
#define far_malloc(x)	malloc(x)
70
#define far_free(x)	free(x)
71
72
#endif /* NEED_FAR_POINTERS */
73
74
#ifdef DONT_USE_B_MODE		/* define mode parameters for fopen() */
75
#define READ_BINARY	"r"
76
#else
77
#define READ_BINARY	"rb"
78
#endif
79
80
#ifndef USE_MSDOS_MEMMGR	/* make sure user got configuration right */
81
  You forgot to define USE_MSDOS_MEMMGR in jconfig.h. /* deliberate syntax error */
82
#endif
83
84
#if MAX_ALLOC_CHUNK >= 65535L	/* make sure jconfig.h got this right */
85
  MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */
86
#endif
87
88
89
/*
90
 * Declarations for assembly-language support routines (see jmemdosa.asm).
91
 *
92
 * The functions are declared "far" as are all their pointer arguments;
93
 * this ensures the assembly source code will work regardless of the
94
 * compiler memory model.  We assume "short" is 16 bits, "long" is 32.
95
 */
96
97
typedef void far * XMSDRIVER;	/* actually a pointer to code */
98
typedef struct {		/* registers for calling XMS driver */
99
	unsigned short ax, dx, bx;
100
	void far * ds_si;
101
      } XMScontext;
102
typedef struct {		/* registers for calling EMS driver */
103
	unsigned short ax, dx, bx;
104
	void far * ds_si;
105
      } EMScontext;
106
107
extern short far jdos_open JPP((short far * handle, char far * filename));
108
extern short far jdos_close JPP((short handle));
109
extern short far jdos_seek JPP((short handle, long offset));
110
extern short far jdos_read JPP((short handle, void far * buffer,
111
				unsigned short count));
112
extern short far jdos_write JPP((short handle, void far * buffer,
113
				 unsigned short count));
114
extern void far jxms_getdriver JPP((XMSDRIVER far *));
115
extern void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *));
116
extern short far jems_available JPP((void));
117
extern void far jems_calldriver JPP((EMScontext far *));
118
119
120
/*
121
 * Selection of a file name for a temporary file.
122
 * This is highly system-dependent, and you may want to customize it.
123
 */
124
125
static int next_file_num;	/* to distinguish among several temp files */
126
127
LOCAL(void)
128
select_file_name (char * fname)
129
{
130
  const char * env;
131
  char * ptr;
132
  FILE * tfile;
133
134
  /* Keep generating file names till we find one that's not in use */
135
  for (;;) {
136
    /* Get temp directory name from environment TMP or TEMP variable;
137
     * if none, use "."
138
     */
139
    if ((env = (const char *) getenv("TMP")) == NULL)
140
      if ((env = (const char *) getenv("TEMP")) == NULL)
141
	env = ".";
142
    if (*env == '\0')		/* null string means "." */
143
      env = ".";
144
    ptr = fname;		/* copy name to fname */
145
    while (*env != '\0')
146
      *ptr++ = *env++;
147
    if (ptr[-1] != '\\' && ptr[-1] != '/')
148
      *ptr++ = '\\';		/* append backslash if not in env variable */
149
    /* Append a suitable file name */
150
    next_file_num++;		/* advance counter */
151
    sprintf(ptr, "JPG%03d.TMP", next_file_num);
152
    /* Probe to see if file name is already in use */
153
    if ((tfile = fopen(fname, READ_BINARY)) == NULL)
154
      break;
155
    fclose(tfile);		/* oops, it's there; close tfile & try again */
156
  }
157
}
158
159
160
/*
161
 * Near-memory allocation and freeing are controlled by the regular library
162
 * routines malloc() and free().
163
 */
164
165
GLOBAL(void *)
166
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
167
{
168
  return (void *) malloc(sizeofobject);
169
}
170
171
GLOBAL(void)
172
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
173
{
174
  free(object);
175
}
176
177
178
/*
179
 * "Large" objects are allocated in far memory, if possible
180
 */
181
182
GLOBAL(void FAR *)
183
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
184
{
185
  return (void FAR *) far_malloc(sizeofobject);
186
}
187
188
GLOBAL(void)
189
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
190
{
191
  far_free(object);
192
}
193
194
195
/*
196
 * This routine computes the total memory space available for allocation.
197
 * It's impossible to do this in a portable way; our current solution is
198
 * to make the user tell us (with a default value set at compile time).
199
 * If you can actually get the available space, it's a good idea to subtract
200
 * a slop factor of 5% or so.
201
 */
202
203
#ifndef DEFAULT_MAX_MEM		/* so can override from makefile */
204
#define DEFAULT_MAX_MEM		300000L /* for total usage about 450K */
205
#endif
206
207
GLOBAL(long)
208
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
209
		    long max_bytes_needed, long already_allocated)
210
{
211
  return cinfo->mem->max_memory_to_use - already_allocated;
212
}
213
214
215
/*
216
 * Backing store (temporary file) management.
217
 * Backing store objects are only used when the value returned by
218
 * jpeg_mem_available is less than the total space needed.  You can dispense
219
 * with these routines if you have plenty of virtual memory; see jmemnobs.c.
220
 */
221
222
/*
223
 * For MS-DOS we support three types of backing storage:
224
 *   1. Conventional DOS files.  We access these by direct DOS calls rather
225
 *      than via the stdio package.  This provides a bit better performance,
226
 *      but the real reason is that the buffers to be read or written are FAR.
227
 *      The stdio library for small-data memory models can't cope with that.
228
 *   2. Extended memory, accessed per the XMS V2.0 specification.
229
 *   3. Expanded memory, accessed per the LIM/EMS 4.0 specification.
230
 * You'll need copies of those specs to make sense of the related code.
231
 * The specs are available by Internet FTP from the SIMTEL archives 
232
 * (oak.oakland.edu and its various mirror sites).  See files
233
 * pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip.
234
 */
235
236
237
/*
238
 * Access methods for a DOS file.
239
 */
240
241
242
METHODDEF(void)
243
read_file_store (j_common_ptr cinfo, backing_store_ptr info,
244
		 void FAR * buffer_address,
245
		 long file_offset, long byte_count)
246
{
247
  if (jdos_seek(info->handle.file_handle, file_offset))
248
    ERREXIT(cinfo, JERR_TFILE_SEEK);
249
  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
250
  if (byte_count > 65535L)	/* safety check */
251
    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
252
  if (jdos_read(info->handle.file_handle, buffer_address,
253
		(unsigned short) byte_count))
254
    ERREXIT(cinfo, JERR_TFILE_READ);
255
}
256
257
258
METHODDEF(void)
259
write_file_store (j_common_ptr cinfo, backing_store_ptr info,
260
		  void FAR * buffer_address,
261
		  long file_offset, long byte_count)
262
{
263
  if (jdos_seek(info->handle.file_handle, file_offset))
264
    ERREXIT(cinfo, JERR_TFILE_SEEK);
265
  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
266
  if (byte_count > 65535L)	/* safety check */
267
    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
268
  if (jdos_write(info->handle.file_handle, buffer_address,
269
		 (unsigned short) byte_count))
270
    ERREXIT(cinfo, JERR_TFILE_WRITE);
271
}
272
273
274
METHODDEF(void)
275
close_file_store (j_common_ptr cinfo, backing_store_ptr info)
276
{
277
  jdos_close(info->handle.file_handle);	/* close the file */
278
  remove(info->temp_name);	/* delete the file */
279
/* If your system doesn't have remove(), try unlink() instead.
280
 * remove() is the ANSI-standard name for this function, but
281
 * unlink() was more common in pre-ANSI systems.
282
 */
283
  TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
284
}
285
286
287
LOCAL(boolean)
288
open_file_store (j_common_ptr cinfo, backing_store_ptr info,
289
		 long total_bytes_needed)
290
{
291
  short handle;
292
293
  select_file_name(info->temp_name);
294
  if (jdos_open((short far *) & handle, (char far *) info->temp_name)) {
295
    /* might as well exit since jpeg_open_backing_store will fail anyway */
296
    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
297
    return FALSE;
298
  }
299
  info->handle.file_handle = handle;
300
  info->read_backing_store = read_file_store;
301
  info->write_backing_store = write_file_store;
302
  info->close_backing_store = close_file_store;
303
  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
304
  return TRUE;			/* succeeded */
305
}
306
307
308
/*
309
 * Access methods for extended memory.
310
 */
311
312
#if XMS_SUPPORTED
313
314
static XMSDRIVER xms_driver;	/* saved address of XMS driver */
315
316
typedef union {			/* either long offset or real-mode pointer */
317
	long offset;
318
	void far * ptr;
319
      } XMSPTR;
320
321
typedef struct {		/* XMS move specification structure */
322
	long length;
323
	XMSH src_handle;
324
	XMSPTR src;
325
	XMSH dst_handle;
326
	XMSPTR dst;
327
      } XMSspec;
328
329
#define ODD(X)	(((X) & 1L) != 0)
330
331
332
METHODDEF(void)
333
read_xms_store (j_common_ptr cinfo, backing_store_ptr info,
334
		void FAR * buffer_address,
335
		long file_offset, long byte_count)
336
{
337
  XMScontext ctx;
338
  XMSspec spec;
339
  char endbuffer[2];
340
341
  /* The XMS driver can't cope with an odd length, so handle the last byte
342
   * specially if byte_count is odd.  We don't expect this to be common.
343
   */
344
345
  spec.length = byte_count & (~ 1L);
346
  spec.src_handle = info->handle.xms_handle;
347
  spec.src.offset = file_offset;
348
  spec.dst_handle = 0;
349
  spec.dst.ptr = buffer_address;
350
  
351
  ctx.ds_si = (void far *) & spec;
352
  ctx.ax = 0x0b00;		/* EMB move */
353
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
354
  if (ctx.ax != 1)
355
    ERREXIT(cinfo, JERR_XMS_READ);
356
357
  if (ODD(byte_count)) {
358
    read_xms_store(cinfo, info, (void FAR *) endbuffer,
359
		   file_offset + byte_count - 1L, 2L);
360
    ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0];
361
  }
362
}
363
364
365
METHODDEF(void)
366
write_xms_store (j_common_ptr cinfo, backing_store_ptr info,
367
		 void FAR * buffer_address,
368
		 long file_offset, long byte_count)
369
{
370
  XMScontext ctx;
371
  XMSspec spec;
372
  char endbuffer[2];
373
374
  /* The XMS driver can't cope with an odd length, so handle the last byte
375
   * specially if byte_count is odd.  We don't expect this to be common.
376
   */
377
378
  spec.length = byte_count & (~ 1L);
379
  spec.src_handle = 0;
380
  spec.src.ptr = buffer_address;
381
  spec.dst_handle = info->handle.xms_handle;
382
  spec.dst.offset = file_offset;
383
384
  ctx.ds_si = (void far *) & spec;
385
  ctx.ax = 0x0b00;		/* EMB move */
386
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
387
  if (ctx.ax != 1)
388
    ERREXIT(cinfo, JERR_XMS_WRITE);
389
390
  if (ODD(byte_count)) {
391
    read_xms_store(cinfo, info, (void FAR *) endbuffer,
392
		   file_offset + byte_count - 1L, 2L);
393
    endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L];
394
    write_xms_store(cinfo, info, (void FAR *) endbuffer,
395
		    file_offset + byte_count - 1L, 2L);
396
  }
397
}
398
399
400
METHODDEF(void)
401
close_xms_store (j_common_ptr cinfo, backing_store_ptr info)
402
{
403
  XMScontext ctx;
404
405
  ctx.dx = info->handle.xms_handle;
406
  ctx.ax = 0x0a00;
407
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
408
  TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);
409
  /* we ignore any error return from the driver */
410
}
411
412
413
LOCAL(boolean)
414
open_xms_store (j_common_ptr cinfo, backing_store_ptr info,
415
		long total_bytes_needed)
416
{
417
  XMScontext ctx;
418
419
  /* Get address of XMS driver */
420
  jxms_getdriver((XMSDRIVER far *) & xms_driver);
421
  if (xms_driver == NULL)
422
    return FALSE;		/* no driver to be had */
423
424
  /* Get version number, must be >= 2.00 */
425
  ctx.ax = 0x0000;
426
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
427
  if (ctx.ax < (unsigned short) 0x0200)
428
    return FALSE;
429
430
  /* Try to get space (expressed in kilobytes) */
431
  ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10);
432
  ctx.ax = 0x0900;
433
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
434
  if (ctx.ax != 1)
435
    return FALSE;
436
437
  /* Succeeded, save the handle and away we go */
438
  info->handle.xms_handle = ctx.dx;
439
  info->read_backing_store = read_xms_store;
440
  info->write_backing_store = write_xms_store;
441
  info->close_backing_store = close_xms_store;
442
  TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);
443
  return TRUE;			/* succeeded */
444
}
445
446
#endif /* XMS_SUPPORTED */
447
448
449
/*
450
 * Access methods for expanded memory.
451
 */
452
453
#if EMS_SUPPORTED
454
455
/* The EMS move specification structure requires word and long fields aligned
456
 * at odd byte boundaries.  Some compilers will align struct fields at even
457
 * byte boundaries.  While it's usually possible to force byte alignment,
458
 * that causes an overall performance penalty and may pose problems in merging
459
 * JPEG into a larger application.  Instead we accept some rather dirty code
460
 * here.  Note this code would fail if the hardware did not allow odd-byte
461
 * word & long accesses, but all 80x86 CPUs do.
462
 */
463
464
typedef void far * EMSPTR;
465
466
typedef union {			/* EMS move specification structure */
467
	long length;		/* It's easy to access first 4 bytes */
468
	char bytes[18];		/* Misaligned fields in here! */
469
      } EMSspec;
470
471
/* Macros for accessing misaligned fields */
472
#define FIELD_AT(spec,offset,type)  (*((type *) &(spec.bytes[offset])))
473
#define SRC_TYPE(spec)		FIELD_AT(spec,4,char)
474
#define SRC_HANDLE(spec)	FIELD_AT(spec,5,EMSH)
475
#define SRC_OFFSET(spec)	FIELD_AT(spec,7,unsigned short)
476
#define SRC_PAGE(spec)		FIELD_AT(spec,9,unsigned short)
477
#define SRC_PTR(spec)		FIELD_AT(spec,7,EMSPTR)
478
#define DST_TYPE(spec)		FIELD_AT(spec,11,char)
479
#define DST_HANDLE(spec)	FIELD_AT(spec,12,EMSH)
480
#define DST_OFFSET(spec)	FIELD_AT(spec,14,unsigned short)
481
#define DST_PAGE(spec)		FIELD_AT(spec,16,unsigned short)
482
#define DST_PTR(spec)		FIELD_AT(spec,14,EMSPTR)
483
484
#define EMSPAGESIZE	16384L	/* gospel, see the EMS specs */
485
486
#define HIBYTE(W)  (((W) >> 8) & 0xFF)
487
#define LOBYTE(W)  ((W) & 0xFF)
488
489
490
METHODDEF(void)
491
read_ems_store (j_common_ptr cinfo, backing_store_ptr info,
492
		void FAR * buffer_address,
493
		long file_offset, long byte_count)
494
{
495
  EMScontext ctx;
496
  EMSspec spec;
497
498
  spec.length = byte_count;
499
  SRC_TYPE(spec) = 1;
500
  SRC_HANDLE(spec) = info->handle.ems_handle;
501
  SRC_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);
502
  SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
503
  DST_TYPE(spec) = 0;
504
  DST_HANDLE(spec) = 0;
505
  DST_PTR(spec)    = buffer_address;
506
  
507
  ctx.ds_si = (void far *) & spec;
508
  ctx.ax = 0x5700;		/* move memory region */
509
  jems_calldriver((EMScontext far *) & ctx);
510
  if (HIBYTE(ctx.ax) != 0)
511
    ERREXIT(cinfo, JERR_EMS_READ);
512
}
513
514
515
METHODDEF(void)
516
write_ems_store (j_common_ptr cinfo, backing_store_ptr info,
517
		 void FAR * buffer_address,
518
		 long file_offset, long byte_count)
519
{
520
  EMScontext ctx;
521
  EMSspec spec;
522
523
  spec.length = byte_count;
524
  SRC_TYPE(spec) = 0;
525
  SRC_HANDLE(spec) = 0;
526
  SRC_PTR(spec)    = buffer_address;
527
  DST_TYPE(spec) = 1;
528
  DST_HANDLE(spec) = info->handle.ems_handle;
529
  DST_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);
530
  DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
531
  
532
  ctx.ds_si = (void far *) & spec;
533
  ctx.ax = 0x5700;		/* move memory region */
534
  jems_calldriver((EMScontext far *) & ctx);
535
  if (HIBYTE(ctx.ax) != 0)
536
    ERREXIT(cinfo, JERR_EMS_WRITE);
537
}
538
539
540
METHODDEF(void)
541
close_ems_store (j_common_ptr cinfo, backing_store_ptr info)
542
{
543
  EMScontext ctx;
544
545
  ctx.ax = 0x4500;
546
  ctx.dx = info->handle.ems_handle;
547
  jems_calldriver((EMScontext far *) & ctx);
548
  TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);
549
  /* we ignore any error return from the driver */
550
}
551
552
553
LOCAL(boolean)
554
open_ems_store (j_common_ptr cinfo, backing_store_ptr info,
555
		long total_bytes_needed)
556
{
557
  EMScontext ctx;
558
559
  /* Is EMS driver there? */
560
  if (! jems_available())
561
    return FALSE;
562
563
  /* Get status, make sure EMS is OK */
564
  ctx.ax = 0x4000;
565
  jems_calldriver((EMScontext far *) & ctx);
566
  if (HIBYTE(ctx.ax) != 0)
567
    return FALSE;
568
569
  /* Get version, must be >= 4.0 */
570
  ctx.ax = 0x4600;
571
  jems_calldriver((EMScontext far *) & ctx);
572
  if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40)
573
    return FALSE;
574
575
  /* Try to allocate requested space */
576
  ctx.ax = 0x4300;
577
  ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE);
578
  jems_calldriver((EMScontext far *) & ctx);
579
  if (HIBYTE(ctx.ax) != 0)
580
    return FALSE;
581
582
  /* Succeeded, save the handle and away we go */
583
  info->handle.ems_handle = ctx.dx;
584
  info->read_backing_store = read_ems_store;
585
  info->write_backing_store = write_ems_store;
586
  info->close_backing_store = close_ems_store;
587
  TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);
588
  return TRUE;			/* succeeded */
589
}
590
591
#endif /* EMS_SUPPORTED */
592
593
594
/*
595
 * Initial opening of a backing-store object.
596
 */
597
598
GLOBAL(void)
599
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
600
			 long total_bytes_needed)
601
{
602
  /* Try extended memory, then expanded memory, then regular file. */
603
#if XMS_SUPPORTED
604
  if (open_xms_store(cinfo, info, total_bytes_needed))
605
    return;
606
#endif
607
#if EMS_SUPPORTED
608
  if (open_ems_store(cinfo, info, total_bytes_needed))
609
    return;
610
#endif
611
  if (open_file_store(cinfo, info, total_bytes_needed))
612
    return;
613
  ERREXITS(cinfo, JERR_TFILE_CREATE, "");
614
}
615
616
617
/*
618
 * These routines take care of any system-dependent initialization and
619
 * cleanup required.
620
 */
621
622
GLOBAL(long)
623
jpeg_mem_init (j_common_ptr cinfo)
624
{
625
  next_file_num = 0;		/* initialize temp file name generator */
626
  return DEFAULT_MAX_MEM;	/* default for max_memory_to_use */
627
}
628
629
GLOBAL(void)
630
jpeg_mem_term (j_common_ptr cinfo)
631
{
632
  /* Microsoft C, at least in v6.00A, will not successfully reclaim freed
633
   * blocks of size > 32Kbytes unless we give it a kick in the rear, like so:
634
   */
635
#ifdef NEED_FHEAPMIN
636
  _fheapmin();
637
#endif
638
}
(-)a/jpeg/jmemdosa.asm (-379 lines)
Line     Link Here 
 Lines 1-379    Link Here 
1
;
2
; jmemdosa.asm
3
;
4
; Copyright (C) 1992, 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 low-level interface routines to support the MS-DOS
9
; backing store manager (jmemdos.c).  Routines are provided to access disk
10
; files through direct DOS calls, and to access XMS and EMS drivers.
11
;
12
; This file should assemble with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).  If you haven't got
14
; a compatible assembler, better fall back to jmemansi.c or jmemname.c.
15
;
16
; To minimize dependence on the C compiler's register usage conventions,
17
; we save and restore all 8086 registers, even though most compilers only
18
; require SI,DI,DS to be preserved.  Also, we use only 16-bit-wide return
19
; values, which everybody returns in AX.
20
;
21
; Based on code contributed by Ge' Weijers.
22
;
23
24
JMEMDOSA_TXT	segment byte public 'CODE'
25
26
		assume	cs:JMEMDOSA_TXT
27
28
		public	_jdos_open
29
		public	_jdos_close
30
		public	_jdos_seek
31
		public	_jdos_read
32
		public	_jdos_write
33
		public	_jxms_getdriver
34
		public	_jxms_calldriver
35
		public	_jems_available
36
		public	_jems_calldriver
37
38
;
39
; short far jdos_open (short far * handle, char far * filename)
40
;
41
; Create and open a temporary file
42
;
43
_jdos_open	proc	far
44
		push	bp			; linkage
45
		mov 	bp,sp
46
		push	si			; save all registers for safety
47
		push	di
48
		push	bx
49
		push	cx
50
		push	dx
51
		push	es
52
		push	ds
53
		mov	cx,0			; normal file attributes
54
		lds	dx,dword ptr [bp+10]	; get filename pointer
55
		mov	ah,3ch			; create file
56
		int	21h
57
		jc	open_err		; if failed, return error code
58
		lds	bx,dword ptr [bp+6]	; get handle pointer
59
		mov	word ptr [bx],ax	; save the handle
60
		xor	ax,ax			; return zero for OK
61
open_err:	pop	ds			; restore registers and exit
62
		pop	es
63
		pop	dx
64
		pop	cx
65
		pop	bx
66
		pop	di
67
		pop	si
68
		pop 	bp
69
		ret
70
_jdos_open	endp
71
72
73
;
74
; short far jdos_close (short handle)
75
;
76
; Close the file handle
77
;
78
_jdos_close	proc	far
79
		push	bp			; linkage
80
		mov 	bp,sp
81
		push	si			; save all registers for safety
82
		push	di
83
		push	bx
84
		push	cx
85
		push	dx
86
		push	es
87
		push	ds
88
		mov	bx,word ptr [bp+6]	; file handle
89
		mov	ah,3eh			; close file
90
		int	21h
91
		jc	close_err		; if failed, return error code
92
		xor	ax,ax			; return zero for OK
93
close_err:	pop	ds			; restore registers and exit
94
		pop	es
95
		pop	dx
96
		pop	cx
97
		pop	bx
98
		pop	di
99
		pop	si
100
		pop 	bp
101
		ret
102
_jdos_close	endp
103
104
105
;
106
; short far jdos_seek (short handle, long offset)
107
;
108
; Set file position
109
;
110
_jdos_seek	proc	far
111
		push	bp			; linkage
112
		mov 	bp,sp
113
		push	si			; save all registers for safety
114
		push	di
115
		push	bx
116
		push	cx
117
		push	dx
118
		push	es
119
		push	ds
120
		mov	bx,word ptr [bp+6]	; file handle
121
		mov	dx,word ptr [bp+8]	; LS offset
122
		mov	cx,word ptr [bp+10]	; MS offset
123
		mov	ax,4200h		; absolute seek
124
		int	21h
125
		jc	seek_err		; if failed, return error code
126
		xor	ax,ax			; return zero for OK
127
seek_err:	pop	ds			; restore registers and exit
128
		pop	es
129
		pop	dx
130
		pop	cx
131
		pop	bx
132
		pop	di
133
		pop	si
134
		pop 	bp
135
		ret
136
_jdos_seek	endp
137
138
139
;
140
; short far jdos_read (short handle, void far * buffer, unsigned short count)
141
;
142
; Read from file
143
;
144
_jdos_read	proc	far
145
		push	bp			; linkage
146
		mov 	bp,sp
147
		push	si			; save all registers for safety
148
		push	di
149
		push	bx
150
		push	cx
151
		push	dx
152
		push	es
153
		push	ds
154
		mov	bx,word ptr [bp+6]	; file handle
155
		lds	dx,dword ptr [bp+8]	; buffer address
156
		mov	cx,word ptr [bp+12]	; number of bytes
157
		mov	ah,3fh			; read file
158
		int	21h
159
		jc	read_err		; if failed, return error code
160
		cmp	ax,word ptr [bp+12]	; make sure all bytes were read
161
		je	read_ok
162
		mov	ax,1			; else return 1 for not OK
163
		jmp	short read_err
164
read_ok:	xor	ax,ax			; return zero for OK
165
read_err:	pop	ds			; restore registers and exit
166
		pop	es
167
		pop	dx
168
		pop	cx
169
		pop	bx
170
		pop	di
171
		pop	si
172
		pop 	bp
173
		ret
174
_jdos_read	endp
175
176
177
;
178
; short far jdos_write (short handle, void far * buffer, unsigned short count)
179
;
180
; Write to file
181
;
182
_jdos_write	proc	far
183
		push	bp			; linkage
184
		mov 	bp,sp
185
		push	si			; save all registers for safety
186
		push	di
187
		push	bx
188
		push	cx
189
		push	dx
190
		push	es
191
		push	ds
192
		mov	bx,word ptr [bp+6]	; file handle
193
		lds	dx,dword ptr [bp+8]	; buffer address
194
		mov	cx,word ptr [bp+12]	; number of bytes
195
		mov	ah,40h			; write file
196
		int	21h
197
		jc	write_err		; if failed, return error code
198
		cmp	ax,word ptr [bp+12]	; make sure all bytes written
199
		je	write_ok
200
		mov	ax,1			; else return 1 for not OK
201
		jmp	short write_err
202
write_ok:	xor	ax,ax			; return zero for OK
203
write_err:	pop	ds			; restore registers and exit
204
		pop	es
205
		pop	dx
206
		pop	cx
207
		pop	bx
208
		pop	di
209
		pop	si
210
		pop 	bp
211
		ret
212
_jdos_write	endp
213
214
215
;
216
; void far jxms_getdriver (XMSDRIVER far *)
217
;
218
; Get the address of the XMS driver, or NULL if not available
219
;
220
_jxms_getdriver	proc	far
221
		push	bp			; linkage
222
		mov 	bp,sp
223
		push	si			; save all registers for safety
224
		push	di
225
		push	bx
226
		push	cx
227
		push	dx
228
		push	es
229
		push	ds
230
		mov 	ax,4300h		; call multiplex interrupt with
231
		int	2fh			; a magic cookie, hex 4300
232
		cmp 	al,80h			; AL should contain hex 80
233
		je	xmsavail
234
		xor 	dx,dx			; no XMS driver available
235
		xor 	ax,ax			; return a nil pointer
236
		jmp	short xmsavail_done
237
xmsavail:	mov 	ax,4310h		; fetch driver address with
238
		int	2fh			; another magic cookie
239
		mov 	dx,es			; copy address to dx:ax
240
		mov 	ax,bx
241
xmsavail_done:	les 	bx,dword ptr [bp+6]	; get pointer to return value
242
		mov	word ptr es:[bx],ax
243
		mov	word ptr es:[bx+2],dx
244
		pop	ds			; restore registers and exit
245
		pop	es
246
		pop	dx
247
		pop	cx
248
		pop	bx
249
		pop	di
250
		pop	si
251
		pop	bp
252
		ret
253
_jxms_getdriver	endp
254
255
256
;
257
; void far jxms_calldriver (XMSDRIVER, XMScontext far *)
258
;
259
; The XMScontext structure contains values for the AX,DX,BX,SI,DS registers.
260
; These are loaded, the XMS call is performed, and the new values of the
261
; AX,DX,BX registers are written back to the context structure.
262
;
263
_jxms_calldriver 	proc	far
264
		push	bp			; linkage
265
		mov 	bp,sp
266
		push	si			; save all registers for safety
267
		push	di
268
		push	bx
269
		push	cx
270
		push	dx
271
		push	es
272
		push	ds
273
		les 	bx,dword ptr [bp+10]	; get XMScontext pointer
274
		mov 	ax,word ptr es:[bx]	; load registers
275
		mov 	dx,word ptr es:[bx+2]
276
		mov 	si,word ptr es:[bx+6]
277
		mov 	ds,word ptr es:[bx+8]
278
		mov 	bx,word ptr es:[bx+4]
279
		call	dword ptr [bp+6]	; call the driver
280
		mov	cx,bx			; save returned BX for a sec
281
		les 	bx,dword ptr [bp+10]	; get XMScontext pointer
282
		mov 	word ptr es:[bx],ax	; put back ax,dx,bx
283
		mov 	word ptr es:[bx+2],dx
284
		mov 	word ptr es:[bx+4],cx
285
		pop	ds			; restore registers and exit
286
		pop	es
287
		pop	dx
288
		pop	cx
289
		pop	bx
290
		pop	di
291
		pop	si
292
		pop 	bp
293
		ret
294
_jxms_calldriver 	endp
295
296
297
;
298
; short far jems_available (void)
299
;
300
; Have we got an EMS driver? (this comes straight from the EMS 4.0 specs)
301
;
302
_jems_available	proc	far
303
		push	si			; save all registers for safety
304
		push	di
305
		push	bx
306
		push	cx
307
		push	dx
308
		push	es
309
		push	ds
310
		mov	ax,3567h		; get interrupt vector 67h
311
		int	21h
312
		push	cs
313
		pop	ds
314
		mov	di,000ah		; check offs 10 in returned seg
315
		lea	si,ASCII_device_name	; against literal string
316
		mov	cx,8
317
		cld
318
		repe cmpsb
319
		jne	no_ems
320
		mov	ax,1			; match, it's there
321
		jmp	short avail_done
322
no_ems:		xor	ax,ax			; it's not there
323
avail_done:	pop	ds			; restore registers and exit
324
		pop	es
325
		pop	dx
326
		pop	cx
327
		pop	bx
328
		pop	di
329
		pop	si
330
		ret
331
332
ASCII_device_name	db	"EMMXXXX0"
333
334
_jems_available	endp
335
336
337
;
338
; void far jems_calldriver (EMScontext far *)
339
;
340
; The EMScontext structure contains values for the AX,DX,BX,SI,DS registers.
341
; These are loaded, the EMS trap is performed, and the new values of the
342
; AX,DX,BX registers are written back to the context structure.
343
;
344
_jems_calldriver	proc far
345
		push	bp			; linkage
346
		mov 	bp,sp
347
		push	si			; save all registers for safety
348
		push	di
349
		push	bx
350
		push	cx
351
		push	dx
352
		push	es
353
		push	ds
354
		les 	bx,dword ptr [bp+6]	; get EMScontext pointer
355
		mov 	ax,word ptr es:[bx]	; load registers
356
		mov 	dx,word ptr es:[bx+2]
357
		mov 	si,word ptr es:[bx+6]
358
		mov 	ds,word ptr es:[bx+8]
359
		mov 	bx,word ptr es:[bx+4]
360
		int	67h			; call the EMS driver
361
		mov	cx,bx			; save returned BX for a sec
362
		les 	bx,dword ptr [bp+6]	; get EMScontext pointer
363
		mov 	word ptr es:[bx],ax	; put back ax,dx,bx
364
		mov 	word ptr es:[bx+2],dx
365
		mov 	word ptr es:[bx+4],cx
366
		pop	ds			; restore registers and exit
367
		pop	es
368
		pop	dx
369
		pop	cx
370
		pop	bx
371
		pop	di
372
		pop	si
373
		pop 	bp
374
		ret
375
_jems_calldriver	endp
376
377
JMEMDOSA_TXT	ends
378
379
		end
(-)a/jpeg/jmemmgr.c (-87 / +111 lines)
Line     Link Here 
 Lines 52-119   extern char * getenv JPP((const char * n Link Here 
52
52
53
/*
53
/*
54
 * Many machines require storage alignment: longs must start on 4-byte
54
 * Many machines require storage alignment: longs must start on 4-byte
55
 * boundaries, doubles on 8-byte boundaries, etc.  On such machines, malloc()
55
 * boundaries, doubles on 8-byte boundaries, etc.  On such machines, malloc()
56
 * always returns pointers that are multiples of the worst-case alignment
56
 * always returns pointers that are multiples of the worst-case alignment
57
 * requirement, and we had better do so too.
57
 * requirement, and we had better do so too.
58
 * There isn't any really portable way to determine the worst-case alignment
58
 * There isn't any really portable way to determine the worst-case alignment
59
 * requirement.  This module assumes that the alignment requirement is
59
 * requirement.  This module assumes that the alignment requirement is
60
 * multiples of sizeof(ALIGN_TYPE).
60
 * multiples of ALIGN_SIZE.
61
 * By default, we define ALIGN_TYPE as double.  This is necessary on some
61
 * By default, we define ALIGN_SIZE as sizeof(double).  This is necessary on some
62
 * workstations (where doubles really do need 8-byte alignment) and will work
62
 * workstations (where doubles really do need 8-byte alignment) and will work
63
 * fine on nearly everything.  If your machine has lesser alignment needs,
63
 * fine on nearly everything.  If your machine has lesser alignment needs,
64
 * you can save a few bytes by making ALIGN_TYPE smaller.
64
 * you can save a few bytes by making ALIGN_SIZE smaller.
65
 * The only place I know of where this will NOT work is certain Macintosh
65
 * The only place I know of where this will NOT work is certain Macintosh
66
 * 680x0 compilers that define double as a 10-byte IEEE extended float.
66
 * 680x0 compilers that define double as a 10-byte IEEE extended float.
67
 * Doing 10-byte alignment is counterproductive because longwords won't be
67
 * Doing 10-byte alignment is counterproductive because longwords won't be
68
 * aligned well.  Put "#define ALIGN_TYPE long" in jconfig.h if you have
68
 * aligned well.  Put "#define ALIGN_SIZE 4" in jconfig.h if you have
69
 * such a compiler.
69
 * such a compiler.
70
 */
70
 */
71
71
72
#ifndef ALIGN_TYPE		/* so can override from jconfig.h */
72
#ifndef ALIGN_SIZE		/* so can override from jconfig.h */
73
#define ALIGN_TYPE  double
73
#ifndef WITH_SIMD
74
#define ALIGN_SIZE  SIZEOF(double)
75
#else
76
#define ALIGN_SIZE  16 /* Most SIMD implementations require this */
74
#endif
77
#endif
75
78
#endif
76
79
77
/*
80
/*
78
 * We allocate objects from "pools", where each pool is gotten with a single
81
 * We allocate objects from "pools", where each pool is gotten with a single
79
 * request to jpeg_get_small() or jpeg_get_large().  There is no per-object
82
 * request to jpeg_get_small() or jpeg_get_large().  There is no per-object
80
 * overhead within a pool, except for alignment padding.  Each pool has a
83
 * overhead within a pool, except for alignment padding.  Each pool has a
81
 * header with a link to the next pool of the same class.
84
 * header with a link to the next pool of the same class.
82
 * Small and large pool headers are identical except that the latter's
85
 * Small and large pool headers are identical except that the latter's
83
 * link pointer must be FAR on 80x86 machines.
86
 * link pointer must be FAR on 80x86 machines.
84
 * Notice that the "real" header fields are union'ed with a dummy ALIGN_TYPE
87
 */
85
 * field.  This forces the compiler to make SIZEOF(small_pool_hdr) a multiple
88
86
 * of the alignment requirement of ALIGN_TYPE.
89
typedef struct small_pool_struct * small_pool_ptr;
87
 */
90
88
91
typedef struct small_pool_struct {
89
typedef union small_pool_struct * small_pool_ptr;
92
  small_pool_ptr next;	/* next in list of pools */
90
93
  size_t bytes_used;		/* how many bytes already used within pool */
91
typedef union small_pool_struct {
94
  size_t bytes_left;		/* bytes still available in this pool */
92
  struct {
93
    small_pool_ptr next;	/* next in list of pools */
94
    size_t bytes_used;		/* how many bytes already used within pool */
95
    size_t bytes_left;		/* bytes still available in this pool */
96
  } hdr;
97
  ALIGN_TYPE dummy;		/* included in union to ensure alignment */
98
} small_pool_hdr;
95
} small_pool_hdr;
99
96
100
typedef union large_pool_struct FAR * large_pool_ptr;
97
typedef struct large_pool_struct FAR * large_pool_ptr;
101
98
102
typedef union large_pool_struct {
99
typedef struct large_pool_struct {
103
  struct {
100
  large_pool_ptr next;	/* next in list of pools */
104
    large_pool_ptr next;	/* next in list of pools */
101
  size_t bytes_used;		/* how many bytes already used within pool */
105
    size_t bytes_used;		/* how many bytes already used within pool */
102
  size_t bytes_left;		/* bytes still available in this pool */
106
    size_t bytes_left;		/* bytes still available in this pool */
107
  } hdr;
108
  ALIGN_TYPE dummy;		/* included in union to ensure alignment */
109
} large_pool_hdr;
103
} large_pool_hdr;
110
104
111
112
/*
105
/*
113
 * Here is the full definition of a memory manager object.
106
 * Here is the full definition of a memory manager object.
114
 */
107
 */
115
108
116
typedef struct {
109
typedef struct {
117
  struct jpeg_memory_mgr pub;	/* public fields */
110
  struct jpeg_memory_mgr pub;	/* public fields */
118
111
119
  /* Each pool identifier (lifetime class) names a linked list of pools. */
112
  /* Each pool identifier (lifetime class) names a linked list of pools. */
 Lines 124-140   typedef struct { Link Here 
124
   * linked list is necessary (for each datatype).  Note that the virtual
117
   * linked list is necessary (for each datatype).  Note that the virtual
125
   * array control blocks being linked together are actually stored somewhere
118
   * array control blocks being linked together are actually stored somewhere
126
   * in the small-pool list.
119
   * in the small-pool list.
127
   */
120
   */
128
  jvirt_sarray_ptr virt_sarray_list;
121
  jvirt_sarray_ptr virt_sarray_list;
129
  jvirt_barray_ptr virt_barray_list;
122
  jvirt_barray_ptr virt_barray_list;
130
123
131
  /* This counts total space obtained from jpeg_get_small/large */
124
  /* This counts total space obtained from jpeg_get_small/large */
132
  long total_space_allocated;
125
  size_t total_space_allocated;
133
126
134
  /* alloc_sarray and alloc_barray set this value for use by virtual
127
  /* alloc_sarray and alloc_barray set this value for use by virtual
135
   * array routines.
128
   * array routines.
136
   */
129
   */
137
  JDIMENSION last_rowsperchunk;	/* from most recent alloc_sarray/barray */
130
  JDIMENSION last_rowsperchunk;	/* from most recent alloc_sarray/barray */
138
} my_memory_mgr;
131
} my_memory_mgr;
139
132
140
typedef my_memory_mgr * my_mem_ptr;
133
typedef my_memory_mgr * my_mem_ptr;
 Lines 192-219   print_mem_stats (j_common_ptr cinfo, int Link Here 
192
  /* Since this is only a debugging stub, we can cheat a little by using
185
  /* Since this is only a debugging stub, we can cheat a little by using
193
   * fprintf directly rather than going through the trace message code.
186
   * fprintf directly rather than going through the trace message code.
194
   * This is helpful because message parm array can't handle longs.
187
   * This is helpful because message parm array can't handle longs.
195
   */
188
   */
196
  fprintf(stderr, "Freeing pool %d, total space = %ld\n",
189
  fprintf(stderr, "Freeing pool %d, total space = %ld\n",
197
	  pool_id, mem->total_space_allocated);
190
	  pool_id, mem->total_space_allocated);
198
191
199
  for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
192
  for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
200
       lhdr_ptr = lhdr_ptr->hdr.next) {
193
       lhdr_ptr = lhdr_ptr->next) {
201
    fprintf(stderr, "  Large chunk used %ld\n",
194
    fprintf(stderr, "  Large chunk used %ld\n",
202
	    (long) lhdr_ptr->hdr.bytes_used);
195
	    (long) lhdr_ptr->bytes_used);
203
  }
196
  }
204
197
205
  for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
198
  for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
206
       shdr_ptr = shdr_ptr->hdr.next) {
199
       shdr_ptr = shdr_ptr->next) {
207
    fprintf(stderr, "  Small chunk used %ld free %ld\n",
200
    fprintf(stderr, "  Small chunk used %ld free %ld\n",
208
	    (long) shdr_ptr->hdr.bytes_used,
201
	    (long) shdr_ptr->bytes_used,
209
	    (long) shdr_ptr->hdr.bytes_left);
202
	    (long) shdr_ptr->bytes_left);
210
  }
203
  }
211
}
204
}
212
205
213
#endif /* MEM_STATS */
206
#endif /* MEM_STATS */
214
207
215
208
216
LOCAL(void)
209
LOCAL(void)
217
out_of_memory (j_common_ptr cinfo, int which)
210
out_of_memory (j_common_ptr cinfo, int which)
218
/* Report an out-of-memory error and stop execution */
211
/* Report an out-of-memory error and stop execution */
219
/* If we compiled MEM_STATS support, report alloc requests before dying */
212
/* If we compiled MEM_STATS support, report alloc requests before dying */
 Lines 231-247   out_of_memory (j_common_ptr cinfo, int w Link Here 
231
 * For these, we use pooled storage.  When a new pool must be created,
224
 * For these, we use pooled storage.  When a new pool must be created,
232
 * we try to get enough space for the current request plus a "slop" factor,
225
 * we try to get enough space for the current request plus a "slop" factor,
233
 * where the slop will be the amount of leftover space in the new pool.
226
 * where the slop will be the amount of leftover space in the new pool.
234
 * The speed vs. space tradeoff is largely determined by the slop values.
227
 * The speed vs. space tradeoff is largely determined by the slop values.
235
 * A different slop value is provided for each pool class (lifetime),
228
 * A different slop value is provided for each pool class (lifetime),
236
 * and we also distinguish the first pool of a class from later ones.
229
 * and we also distinguish the first pool of a class from later ones.
237
 * NOTE: the values given work fairly well on both 16- and 32-bit-int
230
 * NOTE: the values given work fairly well on both 16- and 32-bit-int
238
 * machines, but may be too small if longs are 64 bits or more.
231
 * machines, but may be too small if longs are 64 bits or more.
239
 */
232
 *
233
 * Since we do not know what alignment malloc() gives us, we have to
234
 * allocate ALIGN_SIZE-1 extra space per pool to have room for alignment
235
 * adjustment.
236
 */
240
237
241
static const size_t first_pool_slop[JPOOL_NUMPOOLS] = 
238
static const size_t first_pool_slop[JPOOL_NUMPOOLS] = 
242
{
239
{
243
	1600,			/* first PERMANENT pool */
240
	1600,			/* first PERMANENT pool */
244
	16000			/* first IMAGE pool */
241
	16000			/* first IMAGE pool */
245
};
242
};
246
243
247
static const size_t extra_pool_slop[JPOOL_NUMPOOLS] = 
244
static const size_t extra_pool_slop[JPOOL_NUMPOOLS] = 
 Lines 255-297   static const size_t extra_pool_slop[JPOO Link Here 
255
252
256
METHODDEF(void *)
253
METHODDEF(void *)
257
alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
254
alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
258
/* Allocate a "small" object */
255
/* Allocate a "small" object */
259
{
256
{
260
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
257
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
261
  small_pool_ptr hdr_ptr, prev_hdr_ptr;
258
  small_pool_ptr hdr_ptr, prev_hdr_ptr;
262
  char * data_ptr;
259
  char * data_ptr;
263
  size_t odd_bytes, min_request, slop;
260
  size_t min_request, slop;
261
262
  /*
263
   * Round up the requested size to a multiple of ALIGN_SIZE in order
264
   * to assure alignment for the next object allocated in the same pool
265
   * and so that algorithms can straddle outside the proper area up
266
   * to the next alignment.
267
   */
268
  sizeofobject = jround_up(sizeofobject, ALIGN_SIZE);
264
269
265
  /* Check for unsatisfiable request (do now to ensure no overflow below) */
270
  /* Check for unsatisfiable request (do now to ensure no overflow below) */
266
  if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
271
  if ((SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK)
267
    out_of_memory(cinfo, 1);	/* request exceeds malloc's ability */
272
    out_of_memory(cinfo, 1);	/* request exceeds malloc's ability */
268
273
269
  /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
270
  odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
271
  if (odd_bytes > 0)
272
    sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
273
274
  /* See if space is available in any existing pool */
274
  /* See if space is available in any existing pool */
275
  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
275
  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
276
    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);	/* safety check */
276
    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);	/* safety check */
277
  prev_hdr_ptr = NULL;
277
  prev_hdr_ptr = NULL;
278
  hdr_ptr = mem->small_list[pool_id];
278
  hdr_ptr = mem->small_list[pool_id];
279
  while (hdr_ptr != NULL) {
279
  while (hdr_ptr != NULL) {
280
    if (hdr_ptr->hdr.bytes_left >= sizeofobject)
280
    if (hdr_ptr->bytes_left >= sizeofobject)
281
      break;			/* found pool with enough space */
281
      break;			/* found pool with enough space */
282
    prev_hdr_ptr = hdr_ptr;
282
    prev_hdr_ptr = hdr_ptr;
283
    hdr_ptr = hdr_ptr->hdr.next;
283
    hdr_ptr = hdr_ptr->next;
284
  }
284
  }
285
285
286
  /* Time to make a new pool? */
286
  /* Time to make a new pool? */
287
  if (hdr_ptr == NULL) {
287
  if (hdr_ptr == NULL) {
288
    /* min_request is what we need now, slop is what will be leftover */
288
    /* min_request is what we need now, slop is what will be leftover */
289
    min_request = sizeofobject + SIZEOF(small_pool_hdr);
289
    min_request = SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1;
290
    if (prev_hdr_ptr == NULL)	/* first pool in class? */
290
    if (prev_hdr_ptr == NULL)	/* first pool in class? */
291
      slop = first_pool_slop[pool_id];
291
      slop = first_pool_slop[pool_id];
292
    else
292
    else
293
      slop = extra_pool_slop[pool_id];
293
      slop = extra_pool_slop[pool_id];
294
    /* Don't ask for more than MAX_ALLOC_CHUNK */
294
    /* Don't ask for more than MAX_ALLOC_CHUNK */
295
    if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
295
    if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
296
      slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
296
      slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
297
    /* Try to get space, if fail reduce slop and try again */
297
    /* Try to get space, if fail reduce slop and try again */
 Lines 300-329   alloc_small (j_common_ptr cinfo, int poo Link Here 
300
      if (hdr_ptr != NULL)
300
      if (hdr_ptr != NULL)
301
	break;
301
	break;
302
      slop /= 2;
302
      slop /= 2;
303
      if (slop < MIN_SLOP)	/* give up when it gets real small */
303
      if (slop < MIN_SLOP)	/* give up when it gets real small */
304
	out_of_memory(cinfo, 2); /* jpeg_get_small failed */
304
	out_of_memory(cinfo, 2); /* jpeg_get_small failed */
305
    }
305
    }
306
    mem->total_space_allocated += min_request + slop;
306
    mem->total_space_allocated += min_request + slop;
307
    /* Success, initialize the new pool header and add to end of list */
307
    /* Success, initialize the new pool header and add to end of list */
308
    hdr_ptr->hdr.next = NULL;
308
    hdr_ptr->next = NULL;
309
    hdr_ptr->hdr.bytes_used = 0;
309
    hdr_ptr->bytes_used = 0;
310
    hdr_ptr->hdr.bytes_left = sizeofobject + slop;
310
    hdr_ptr->bytes_left = sizeofobject + slop;
311
    if (prev_hdr_ptr == NULL)	/* first pool in class? */
311
    if (prev_hdr_ptr == NULL)	/* first pool in class? */
312
      mem->small_list[pool_id] = hdr_ptr;
312
      mem->small_list[pool_id] = hdr_ptr;
313
    else
313
    else
314
      prev_hdr_ptr->hdr.next = hdr_ptr;
314
      prev_hdr_ptr->next = hdr_ptr;
315
  }
315
  }
316
316
317
  /* OK, allocate the object from the current pool */
317
  /* OK, allocate the object from the current pool */
318
  data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
318
  data_ptr = (char *) hdr_ptr; /* point to first data byte in pool... */
319
  data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
319
  data_ptr += SIZEOF(small_pool_hdr); /* ...by skipping the header... */
320
  hdr_ptr->hdr.bytes_used += sizeofobject;
320
  if ((size_t)data_ptr % ALIGN_SIZE) /* ...and adjust for alignment */
321
  hdr_ptr->hdr.bytes_left -= sizeofobject;
321
    data_ptr += ALIGN_SIZE - (size_t)data_ptr % ALIGN_SIZE;
322
  data_ptr += hdr_ptr->bytes_used; /* point to place for object */
323
  hdr_ptr->bytes_used += sizeofobject;
324
  hdr_ptr->bytes_left -= sizeofobject;
322
325
323
  return (void *) data_ptr;
326
  return (void *) data_ptr;
324
}
327
}
325
328
326
329
327
/*
330
/*
328
 * Allocation of "large" objects.
331
 * Allocation of "large" objects.
329
 *
332
 *
 Lines 339-412   alloc_small (j_common_ptr cinfo, int poo Link Here 
339
 */
342
 */
340
343
341
METHODDEF(void FAR *)
344
METHODDEF(void FAR *)
342
alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
345
alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
343
/* Allocate a "large" object */
346
/* Allocate a "large" object */
344
{
347
{
345
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
348
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
346
  large_pool_ptr hdr_ptr;
349
  large_pool_ptr hdr_ptr;
347
  size_t odd_bytes;
350
  char FAR * data_ptr;
351
352
  /*
353
   * Round up the requested size to a multiple of ALIGN_SIZE so that
354
   * algorithms can straddle outside the proper area up to the next
355
   * alignment.
356
   */
357
  sizeofobject = jround_up(sizeofobject, ALIGN_SIZE);
348
358
349
  /* Check for unsatisfiable request (do now to ensure no overflow below) */
359
  /* Check for unsatisfiable request (do now to ensure no overflow below) */
350
  if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
360
  if ((SIZEOF(large_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK)
351
    out_of_memory(cinfo, 3);	/* request exceeds malloc's ability */
361
    out_of_memory(cinfo, 3);	/* request exceeds malloc's ability */
352
362
353
  /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
354
  odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
355
  if (odd_bytes > 0)
356
    sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
357
358
  /* Always make a new pool */
363
  /* Always make a new pool */
359
  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
364
  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
360
    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);	/* safety check */
365
    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);	/* safety check */
361
366
362
  hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
367
  hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
363
					    SIZEOF(large_pool_hdr));
368
					    SIZEOF(large_pool_hdr) +
369
					    ALIGN_SIZE - 1);
364
  if (hdr_ptr == NULL)
370
  if (hdr_ptr == NULL)
365
    out_of_memory(cinfo, 4);	/* jpeg_get_large failed */
371
    out_of_memory(cinfo, 4);	/* jpeg_get_large failed */
366
  mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
372
  mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr) + ALIGN_SIZE - 1;
367
373
368
  /* Success, initialize the new pool header and add to list */
374
  /* Success, initialize the new pool header and add to list */
369
  hdr_ptr->hdr.next = mem->large_list[pool_id];
375
  hdr_ptr->next = mem->large_list[pool_id];
370
  /* We maintain space counts in each pool header for statistical purposes,
376
  /* We maintain space counts in each pool header for statistical purposes,
371
   * even though they are not needed for allocation.
377
   * even though they are not needed for allocation.
372
   */
378
   */
373
  hdr_ptr->hdr.bytes_used = sizeofobject;
379
  hdr_ptr->bytes_used = sizeofobject;
374
  hdr_ptr->hdr.bytes_left = 0;
380
  hdr_ptr->bytes_left = 0;
375
  mem->large_list[pool_id] = hdr_ptr;
381
  mem->large_list[pool_id] = hdr_ptr;
376
382
377
  return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
383
  data_ptr = (char *) hdr_ptr; /* point to first data byte in pool... */
378
}
384
  data_ptr += SIZEOF(small_pool_hdr); /* ...by skipping the header... */
385
  if ((size_t)data_ptr % ALIGN_SIZE) /* ...and adjust for alignment */
386
    data_ptr += ALIGN_SIZE - (size_t)data_ptr % ALIGN_SIZE;
387
388
  return (void FAR *) data_ptr;
389
}
379
390
380
391
381
/*
392
/*
382
 * Creation of 2-D sample arrays.
393
 * Creation of 2-D sample arrays.
383
 * The pointers are in near heap, the samples themselves in FAR heap.
394
 * The pointers are in near heap, the samples themselves in FAR heap.
384
 *
395
 *
385
 * To minimize allocation overhead and to allow I/O of large contiguous
396
 * To minimize allocation overhead and to allow I/O of large contiguous
386
 * blocks, we allocate the sample rows in groups of as many rows as possible
397
 * blocks, we allocate the sample rows in groups of as many rows as possible
387
 * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request.
398
 * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request.
388
 * NB: the virtual array control routines, later in this file, know about
399
 * NB: the virtual array control routines, later in this file, know about
389
 * this chunking of rows.  The rowsperchunk value is left in the mem manager
400
 * this chunking of rows.  The rowsperchunk value is left in the mem manager
390
 * object so that it can be saved away if this sarray is the workspace for
401
 * object so that it can be saved away if this sarray is the workspace for
391
 * a virtual array.
402
 * a virtual array.
392
 */
403
 *
404
 * Since we are often upsampling with a factor 2, we align the size (not
405
 * the start) to 2 * ALIGN_SIZE so that the upsampling routines don't have
406
 * to be as careful about size.
407
 */
393
408
394
METHODDEF(JSAMPARRAY)
409
METHODDEF(JSAMPARRAY)
395
alloc_sarray (j_common_ptr cinfo, int pool_id,
410
alloc_sarray (j_common_ptr cinfo, int pool_id,
396
	      JDIMENSION samplesperrow, JDIMENSION numrows)
411
	      JDIMENSION samplesperrow, JDIMENSION numrows)
397
/* Allocate a 2-D sample array */
412
/* Allocate a 2-D sample array */
398
{
413
{
399
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
414
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
400
  JSAMPARRAY result;
415
  JSAMPARRAY result;
401
  JSAMPROW workspace;
416
  JSAMPROW workspace;
402
  JDIMENSION rowsperchunk, currow, i;
417
  JDIMENSION rowsperchunk, currow, i;
403
  long ltemp;
418
  long ltemp;
404
419
420
  /* Make sure each row is properly aligned */
421
  if ((ALIGN_SIZE % SIZEOF(JSAMPLE)) != 0)
422
    out_of_memory(cinfo, 5);	/* safety check */
423
  samplesperrow = (JDIMENSION)jround_up(samplesperrow, (2 * ALIGN_SIZE) / SIZEOF(JSAMPLE));
424
405
  /* Calculate max # of rows allowed in one allocation chunk */
425
  /* Calculate max # of rows allowed in one allocation chunk */
406
  ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
426
  ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
407
	  ((long) samplesperrow * SIZEOF(JSAMPLE));
427
	  ((long) samplesperrow * SIZEOF(JSAMPLE));
408
  if (ltemp <= 0)
428
  if (ltemp <= 0)
409
    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
429
    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
410
  if (ltemp < (long) numrows)
430
  if (ltemp < (long) numrows)
411
    rowsperchunk = (JDIMENSION) ltemp;
431
    rowsperchunk = (JDIMENSION) ltemp;
412
  else
432
  else
 Lines 445-460   alloc_barray (j_common_ptr cinfo, int po Link Here 
445
/* Allocate a 2-D coefficient-block array */
465
/* Allocate a 2-D coefficient-block array */
446
{
466
{
447
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
467
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
448
  JBLOCKARRAY result;
468
  JBLOCKARRAY result;
449
  JBLOCKROW workspace;
469
  JBLOCKROW workspace;
450
  JDIMENSION rowsperchunk, currow, i;
470
  JDIMENSION rowsperchunk, currow, i;
451
  long ltemp;
471
  long ltemp;
452
472
473
  /* Make sure each row is properly aligned */
474
  if ((SIZEOF(JBLOCK) % ALIGN_SIZE) != 0)
475
    out_of_memory(cinfo, 6);	/* safety check */
476
453
  /* Calculate max # of rows allowed in one allocation chunk */
477
  /* Calculate max # of rows allowed in one allocation chunk */
454
  ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
478
  ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
455
	  ((long) blocksperrow * SIZEOF(JBLOCK));
479
	  ((long) blocksperrow * SIZEOF(JBLOCK));
456
  if (ltemp <= 0)
480
  if (ltemp <= 0)
457
    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
481
    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
458
  if (ltemp < (long) numrows)
482
  if (ltemp < (long) numrows)
459
    rowsperchunk = (JDIMENSION) ltemp;
483
    rowsperchunk = (JDIMENSION) ltemp;
460
  else
484
  else
 Lines 579-596   request_virt_barray (j_common_ptr cinfo, Link Here 
579
}
603
}
580
604
581
605
582
METHODDEF(void)
606
METHODDEF(void)
583
realize_virt_arrays (j_common_ptr cinfo)
607
realize_virt_arrays (j_common_ptr cinfo)
584
/* Allocate the in-memory buffers for any unrealized virtual arrays */
608
/* Allocate the in-memory buffers for any unrealized virtual arrays */
585
{
609
{
586
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
610
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
587
  long space_per_minheight, maximum_space, avail_mem;
611
  size_t space_per_minheight, maximum_space, avail_mem;
588
  long minheights, max_minheights;
612
  size_t minheights, max_minheights;
589
  jvirt_sarray_ptr sptr;
613
  jvirt_sarray_ptr sptr;
590
  jvirt_barray_ptr bptr;
614
  jvirt_barray_ptr bptr;
591
615
592
  /* Compute the minimum space needed (maxaccess rows in each buffer)
616
  /* Compute the minimum space needed (maxaccess rows in each buffer)
593
   * and the maximum space needed (full image height in each buffer).
617
   * and the maximum space needed (full image height in each buffer).
594
   * These may be of use to the system-dependent jpeg_mem_available routine.
618
   * These may be of use to the system-dependent jpeg_mem_available routine.
595
   */
619
   */
596
  space_per_minheight = 0;
620
  space_per_minheight = 0;
 Lines 963-995   free_pool (j_common_ptr cinfo, int pool_ Link Here 
963
    mem->virt_barray_list = NULL;
987
    mem->virt_barray_list = NULL;
964
  }
988
  }
965
989
966
  /* Release large objects */
990
  /* Release large objects */
967
  lhdr_ptr = mem->large_list[pool_id];
991
  lhdr_ptr = mem->large_list[pool_id];
968
  mem->large_list[pool_id] = NULL;
992
  mem->large_list[pool_id] = NULL;
969
993
970
  while (lhdr_ptr != NULL) {
994
  while (lhdr_ptr != NULL) {
971
    large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
995
    large_pool_ptr next_lhdr_ptr = lhdr_ptr->next;
972
    space_freed = lhdr_ptr->hdr.bytes_used +
996
    space_freed = lhdr_ptr->bytes_used +
973
		  lhdr_ptr->hdr.bytes_left +
997
		  lhdr_ptr->bytes_left +
974
		  SIZEOF(large_pool_hdr);
998
		  SIZEOF(large_pool_hdr);
975
    jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
999
    jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
976
    mem->total_space_allocated -= space_freed;
1000
    mem->total_space_allocated -= space_freed;
977
    lhdr_ptr = next_lhdr_ptr;
1001
    lhdr_ptr = next_lhdr_ptr;
978
  }
1002
  }
979
1003
980
  /* Release small objects */
1004
  /* Release small objects */
981
  shdr_ptr = mem->small_list[pool_id];
1005
  shdr_ptr = mem->small_list[pool_id];
982
  mem->small_list[pool_id] = NULL;
1006
  mem->small_list[pool_id] = NULL;
983
1007
984
  while (shdr_ptr != NULL) {
1008
  while (shdr_ptr != NULL) {
985
    small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
1009
    small_pool_ptr next_shdr_ptr = shdr_ptr->next;
986
    space_freed = shdr_ptr->hdr.bytes_used +
1010
    space_freed = shdr_ptr->bytes_used +
987
		  shdr_ptr->hdr.bytes_left +
1011
		  shdr_ptr->bytes_left +
988
		  SIZEOF(small_pool_hdr);
1012
		  SIZEOF(small_pool_hdr);
989
    jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
1013
    jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
990
    mem->total_space_allocated -= space_freed;
1014
    mem->total_space_allocated -= space_freed;
991
    shdr_ptr = next_shdr_ptr;
1015
    shdr_ptr = next_shdr_ptr;
992
  }
1016
  }
993
}
1017
}
994
1018
995
1019
 Lines 1036-1061   jinit_memory_mgr (j_common_ptr cinfo) Link Here 
1036
1060
1037
  /* Check for configuration errors.
1061
  /* Check for configuration errors.
1038
   * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably
1062
   * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably
1039
   * doesn't reflect any real hardware alignment requirement.
1063
   * doesn't reflect any real hardware alignment requirement.
1040
   * The test is a little tricky: for X>0, X and X-1 have no one-bits
1064
   * The test is a little tricky: for X>0, X and X-1 have no one-bits
1041
   * in common if and only if X is a power of 2, ie has only one one-bit.
1065
   * in common if and only if X is a power of 2, ie has only one one-bit.
1042
   * Some compilers may give an "unreachable code" warning here; ignore it.
1066
   * Some compilers may give an "unreachable code" warning here; ignore it.
1043
   */
1067
   */
1044
  if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
1068
  if ((ALIGN_SIZE & (ALIGN_SIZE-1)) != 0)
1045
    ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
1069
    ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
1046
  /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be
1070
  /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be
1047
   * a multiple of SIZEOF(ALIGN_TYPE).
1071
   * a multiple of ALIGN_SIZE.
1048
   * Again, an "unreachable code" warning may be ignored here.
1072
   * Again, an "unreachable code" warning may be ignored here.
1049
   * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK.
1073
   * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK.
1050
   */
1074
   */
1051
  test_mac = (size_t) MAX_ALLOC_CHUNK;
1075
  test_mac = (size_t) MAX_ALLOC_CHUNK;
1052
  if ((long) test_mac != MAX_ALLOC_CHUNK ||
1076
  if ((long) test_mac != MAX_ALLOC_CHUNK ||
1053
      (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
1077
      (MAX_ALLOC_CHUNK % ALIGN_SIZE) != 0)
1054
    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
1078
    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
1055
1079
1056
  max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
1080
  max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
1057
1081
1058
  /* Attempt to allocate memory manager's control block */
1082
  /* Attempt to allocate memory manager's control block */
1059
  mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
1083
  mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
1060
1084
1061
  if (mem == NULL) {
1085
  if (mem == NULL) {
(-)a/jpeg/jmemname.c (-276 lines)
Line     Link Here 
 Lines 1-276    Link Here 
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		/* <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 <errno.h>, 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 <errno.h>		/* 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 <errno.h> 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
}
(-)a/jpeg/jmemnobs.c (-3 / +3 lines)
Line     Link Here 
 Lines 64-82   jpeg_free_large (j_common_ptr cinfo, voi Link Here 
64
}
64
}
65
65
66
66
67
/*
67
/*
68
 * This routine computes the total memory space available for allocation.
68
 * This routine computes the total memory space available for allocation.
69
 * Here we always say, "we got all you want bud!"
69
 * Here we always say, "we got all you want bud!"
70
 */
70
 */
71
71
72
GLOBAL(long)
72
GLOBAL(size_t)
73
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
73
jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed,
74
		    long max_bytes_needed, long already_allocated)
74
		    size_t max_bytes_needed, size_t already_allocated)
75
{
75
{
76
  return max_bytes_needed;
76
  return max_bytes_needed;
77
}
77
}
78
78
79
79
80
/*
80
/*
81
 * Backing store (temporary file) management.
81
 * Backing store (temporary file) management.
82
 * Since jpeg_mem_available always promised the moon,
82
 * Since jpeg_mem_available always promised the moon,
(-)a/jpeg/jmemsys.h (-4 / +4 lines)
Line     Link Here 
 Lines 95-114   EXTERN(void) jpeg_free_large JPP((j_comm Link Here 
95
 * (that'll just lead to more backing-store access than is really necessary).
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
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.
97
 * a slop factor from the true available space.  5% should be enough.
98
 *
98
 *
99
 * On machines with lots of virtual memory, any large constant may be returned.
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.
100
 * Conversely, zero may be returned to always use the minimum amount of memory.
101
 */
101
 */
102
102
103
EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
103
EXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo,
104
				     long min_bytes_needed,
104
				     size_t min_bytes_needed,
105
				     long max_bytes_needed,
105
				     size_t max_bytes_needed,
106
				     long already_allocated));
106
				     size_t already_allocated));
107
107
108
108
109
/*
109
/*
110
 * This structure holds whatever state is needed to access a single
110
 * This structure holds whatever state is needed to access a single
111
 * backing-store object.  The read/write/close method pointers are called
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
112
 * by jmemmgr.c to manipulate the backing-store object; all other fields
113
 * are private to the system-dependent backing store routines.
113
 * are private to the system-dependent backing store routines.
114
 */
114
 */
(-)a/jpeg/jmorecfg.h (-120 / +44 lines)
Line     Link Here 
 Lines 1-27    Link Here 
1
/*
1
/*
2
 * jmorecfg.h
2
 * jmorecfg.h
3
 *
3
 *
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
5
 * Copyright (C) 2009, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains additional configuration options that customize the
9
 * This file contains additional configuration options that customize the
9
 * JPEG software for special applications or support machine-dependent
10
 * JPEG software for special applications or support machine-dependent
10
 * optimizations.  Most users will not need to touch this file.
11
 * optimizations.  Most users will not need to touch this file.
11
 */
12
 */
12
13
13
/*
14
#include "prtypes.h"
14
 * This file has been modified for the Mozilla/Netscape environment.
15
 * Modifications are distributed under the mozilla.org tri-license and are
16
 * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
17
 * Reserved. See http://www.mozilla.org/MPL/
18
 */
19
20
15
21
/*
16
/*
22
 * Define BITS_IN_JSAMPLE as either
17
 * Define BITS_IN_JSAMPLE as either
23
 *   8   for 8-bit sample values (the usual setting)
18
 *   8   for 8-bit sample values (the usual setting)
24
 *   12  for 12-bit sample values
19
 *   12  for 12-bit sample values
25
 * Only 8 and 12 are legal data precisions for lossy JPEG according to the
20
 * Only 8 and 12 are legal data precisions for lossy JPEG according to the
26
 * JPEG standard, and the IJG code does not support anything else!
21
 * JPEG standard, and the IJG code does not support anything else!
27
 * We do not support run-time selection of data precision, sorry.
22
 * We do not support run-time selection of data precision, sorry.
 Lines 64-84    Link Here 
64
#ifdef HAVE_UNSIGNED_CHAR
59
#ifdef HAVE_UNSIGNED_CHAR
65
60
66
typedef unsigned char JSAMPLE;
61
typedef unsigned char JSAMPLE;
67
#define GETJSAMPLE(value)  ((int) (value))
62
#define GETJSAMPLE(value)  ((int) (value))
68
63
69
#else /* not HAVE_UNSIGNED_CHAR */
64
#else /* not HAVE_UNSIGNED_CHAR */
70
65
71
typedef char JSAMPLE;
66
typedef char JSAMPLE;
72
#ifdef CHAR_IS_UNSIGNED
67
#ifdef __CHAR_UNSIGNED__
73
#define GETJSAMPLE(value)  ((int) (value))
68
#define GETJSAMPLE(value)  ((int) (value))
74
#else
69
#else
75
#define GETJSAMPLE(value)  ((int) (value) & 0xFF)
70
#define GETJSAMPLE(value)  ((int) (value) & 0xFF)
76
#endif /* CHAR_IS_UNSIGNED */
71
#endif /* __CHAR_UNSIGNED__ */
77
72
78
#endif /* HAVE_UNSIGNED_CHAR */
73
#endif /* HAVE_UNSIGNED_CHAR */
79
74
80
#define MAXJSAMPLE	255
75
#define MAXJSAMPLE	255
81
#define CENTERJSAMPLE	128
76
#define CENTERJSAMPLE	128
82
77
83
#endif /* BITS_IN_JSAMPLE == 8 */
78
#endif /* BITS_IN_JSAMPLE == 8 */
84
79
 Lines 100-199   typedef short JSAMPLE; Link Here 
100
/* Representation of a DCT frequency coefficient.
95
/* Representation of a DCT frequency coefficient.
101
 * This should be a signed value of at least 16 bits; "short" is usually OK.
96
 * This should be a signed value of at least 16 bits; "short" is usually OK.
102
 * Again, we allocate large arrays of these, but you can change to int
97
 * Again, we allocate large arrays of these, but you can change to int
103
 * if you have memory to burn and "short" is really slow.
98
 * if you have memory to burn and "short" is really slow.
104
 */
99
 */
105
100
106
typedef short JCOEF;
101
typedef short JCOEF;
107
102
108
/* Defines for MMX/SSE2 support. */
109
110
#if defined(XP_WIN32) && defined(_M_IX86) && !defined(__GNUC__)
111
#define HAVE_MMX_INTEL_MNEMONICS 
112
113
/* SSE2 code appears broken for some cpus (bug 247437) */
114
#define HAVE_SSE2_INTEL_MNEMONICS
115
#define HAVE_SSE2_INTRINSICS
116
#endif
117
118
#if defined(__GNUC__) && defined(__i386__)
119
#if defined(XP_MACOSX)
120
#define HAVE_SSE2_INTRINSICS
121
#endif /* ! XP_MACOSX */
122
#endif /* ! GNUC && i386 */
123
124
/* Add support for other platforms here */
125
126
103
127
/* Compressed datastreams are represented as arrays of JOCTET.
104
/* Compressed datastreams are represented as arrays of JOCTET.
128
 * These must be EXACTLY 8 bits wide, at least once they are written to
105
 * These must be EXACTLY 8 bits wide, at least once they are written to
129
 * external storage.  Note that when using the stdio data source/destination
106
 * external storage.  Note that when using the stdio data source/destination
130
 * managers, this is also the data type passed to fread/fwrite.
107
 * managers, this is also the data type passed to fread/fwrite.
131
 */
108
 */
132
109
133
#ifdef HAVE_UNSIGNED_CHAR
110
#ifdef HAVE_UNSIGNED_CHAR
134
111
135
typedef unsigned char JOCTET;
112
typedef unsigned char JOCTET;
136
#define GETJOCTET(value)  (value)
113
#define GETJOCTET(value)  (value)
137
114
138
#else /* not HAVE_UNSIGNED_CHAR */
115
#else /* not HAVE_UNSIGNED_CHAR */
139
116
140
typedef char JOCTET;
117
typedef char JOCTET;
141
#ifdef CHAR_IS_UNSIGNED
118
#ifdef __CHAR_UNSIGNED__
142
#define GETJOCTET(value)  (value)
119
#define GETJOCTET(value)  (value)
143
#else
120
#else
144
#define GETJOCTET(value)  ((value) & 0xFF)
121
#define GETJOCTET(value)  ((value) & 0xFF)
145
#endif /* CHAR_IS_UNSIGNED */
122
#endif /* __CHAR_UNSIGNED__ */
146
123
147
#endif /* HAVE_UNSIGNED_CHAR */
124
#endif /* HAVE_UNSIGNED_CHAR */
148
125
149
126
150
/* These typedefs are used for various table entries and so forth.
127
/* These typedefs are used for various table entries and so forth.
151
 * They must be at least as wide as specified; but making them too big
128
 * They must be at least as wide as specified; but making them too big
152
 * won't cost a huge amount of memory, so we don't provide special
129
 * won't cost a huge amount of memory, so we don't provide special
153
 * extraction code like we did for JSAMPLE.  (In other words, these
130
 * extraction code like we did for JSAMPLE.  (In other words, these
154
 * typedefs live at a different point on the speed/space tradeoff curve.)
131
 * typedefs live at a different point on the speed/space tradeoff curve.)
155
 */
132
 */
156
133
157
/* UINT8 must hold at least the values 0..255. */
134
/* UINT8 must hold at least the values 0..255. */
158
135
159
#ifdef HAVE_UNSIGNED_CHAR
136
typedef PRUint8 UINT8;
160
typedef unsigned char UINT8;
161
#else /* not HAVE_UNSIGNED_CHAR */
162
#ifdef CHAR_IS_UNSIGNED
163
typedef char UINT8;
164
#else /* not CHAR_IS_UNSIGNED */
165
typedef short UINT8;
166
#endif /* CHAR_IS_UNSIGNED */
167
#endif /* HAVE_UNSIGNED_CHAR */
168
137
169
/* UINT16 must hold at least the values 0..65535. */
138
/* UINT16 must hold at least the values 0..65535. */
170
139
171
#ifdef HAVE_UNSIGNED_SHORT
140
typedef PRUint16 UINT16;
172
typedef unsigned short UINT16;
173
#else /* not HAVE_UNSIGNED_SHORT */
174
typedef unsigned int UINT16;
175
#endif /* HAVE_UNSIGNED_SHORT */
176
141
177
/* INT16 must hold at least the values -32768..32767. */
142
/* INT16 must hold at least the values -32768..32767. */
178
143
179
#ifndef XMD_H			/* X11/xmd.h correctly defines INT16 */
144
typedef PRInt16 INT16;
180
typedef short INT16;
181
#endif
182
145
183
/* INT32 must hold at least signed 32-bit values. */
146
/* INT32 must hold at least signed 32-bit values. */
184
147
185
#ifndef XMD_H			/* X11/xmd.h correctly defines INT32 */
148
typedef PRInt32 INT32;
186
#ifndef _BASETSD_H_		/* basetsd.h correctly defines INT32 */
187
#ifndef _BASETSD_H
188
typedef long INT32;
189
#endif
190
#endif
191
#endif
192
149
193
/* Datatype used for image dimensions.  The JPEG standard only supports
150
/* Datatype used for image dimensions.  The JPEG standard only supports
194
 * images up to 64K*64K due to 16-bit fields in SOF markers.  Therefore
151
 * images up to 64K*64K due to 16-bit fields in SOF markers.  Therefore
195
 * "unsigned int" is sufficient on all machines.  However, if you need to
152
 * "unsigned int" is sufficient on all machines.  However, if you need to
196
 * handle larger images and you don't mind deviating from the spec, you
153
 * handle larger images and you don't mind deviating from the spec, you
197
 * can change this datatype.
154
 * can change this datatype.
198
 */
155
 */
199
156
 Lines 204-234   typedef unsigned int JDIMENSION; Link Here 
204
161
205
/* These macros are used in all function definitions and extern declarations.
162
/* These macros are used in all function definitions and extern declarations.
206
 * You could modify them if you need to change function linkage conventions;
163
 * You could modify them if you need to change function linkage conventions;
207
 * in particular, you'll need to do that to make the library a Windows DLL.
164
 * in particular, you'll need to do that to make the library a Windows DLL.
208
 * Another application is to make all functions global for use with debuggers
165
 * Another application is to make all functions global for use with debuggers
209
 * or code profilers that require it.
166
 * or code profilers that require it.
210
 */
167
 */
211
168
212
/* Mozilla mod: make external functions be DLL-able via JRI_PUBLIC_API(),
213
 * and supply extern "C" for C++ users of the C-compiled IJG library.
214
 * (Well, not anymore, but there's still a modification here.)
215
 */
216
#include "prtypes.h"
217
218
/* a function called through method pointers: */
169
/* a function called through method pointers: */
219
#define METHODDEF(type)		static type
170
#define METHODDEF(type)		static type
220
/* a function used only in its module: */
171
/* a function used only in its module: */
221
#define LOCAL(type)		static type
172
#define LOCAL(type)		static type
222
173
/* a function referenced thru EXTERNs: */
223
PR_BEGIN_EXTERN_C
174
#define GLOBAL(type)		type
224
#define GLOBAL(type) type
175
/* a reference to a GLOBAL function: */
225
#define EXTERN(type) extern type
176
#define EXTERN(type)		extern type
226
PR_END_EXTERN_C
227
177
228
178
229
/* This macro is used to declare a "method", that is, a function pointer.
179
/* This macro is used to declare a "method", that is, a function pointer.
230
 * We want to supply prototype parameters if the compiler can cope.
180
 * We want to supply prototype parameters if the compiler can cope.
231
 * Note that the arglist parameter must be parenthesized!
181
 * Note that the arglist parameter must be parenthesized!
232
 * Again, you can customize this if you need special linkage keywords.
182
 * Again, you can customize this if you need special linkage keywords.
233
 */
183
 */
234
184
 Lines 240-285   PR_END_EXTERN_C Link Here 
240
190
241
191
242
/* Here is the pseudo-keyword for declaring pointers that must be "far"
192
/* Here is the pseudo-keyword for declaring pointers that must be "far"
243
 * on 80x86 machines.  Most of the specialized coding for 80x86 is handled
193
 * on 80x86 machines.  Most of the specialized coding for 80x86 is handled
244
 * by just saying "FAR *" where such a pointer is needed.  In a few places
194
 * by just saying "FAR *" where such a pointer is needed.  In a few places
245
 * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
195
 * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
246
 */
196
 */
247
197
248
#ifndef FAR
249
#ifdef NEED_FAR_POINTERS
198
#ifdef NEED_FAR_POINTERS
250
#define FAR  far
199
#define FAR  far
251
#else
200
#else
252
#define FAR
201
#define FAR
253
#endif
202
#endif
254
#endif
255
203
256
204
257
/*
205
/*
258
 * On a few systems, type boolean and/or its values FALSE, TRUE may appear
206
 * On a few systems, type boolean and/or its values FALSE, TRUE may appear
259
 * in standard header files.  Or you may have conflicts with application-
207
 * in standard header files.  Or you may have conflicts with application-
260
 * specific header files that you want to include together with these files.
208
 * specific header files that you want to include together with these files.
261
 * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
209
 * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
262
 */
210
 */
263
211
264
/* Mozilla mod: IJG distribution makes boolean = int, but on Windows
265
 * it's far safer to define boolean = unsigned char.  Easier to switch
266
 * than fight.
267
 */
268
269
/* For some reason, on SunOS 5.3 HAVE_BOOLEAN gets defined when using
270
 * gcc, but boolean doesn't.  Even if you use -UHAVE_BOOLEAN, it still
271
 * gets reset somewhere.
272
 */
273
#if defined(MUST_UNDEF_HAVE_BOOLEAN_AFTER_INCLUDES) && defined(HAVE_BOOLEAN)
274
#undef HAVE_BOOLEAN
275
#endif
276
#ifndef HAVE_BOOLEAN
212
#ifndef HAVE_BOOLEAN
277
typedef unsigned char boolean;
213
typedef int boolean;
278
#endif
214
#endif
279
#ifndef FALSE			/* in case these macros already exist */
215
#ifndef FALSE			/* in case these macros already exist */
280
#define FALSE	0		/* values of boolean */
216
#define FALSE	0		/* values of boolean */
281
#endif
217
#endif
282
#ifndef TRUE
218
#ifndef TRUE
283
#define TRUE	1
219
#define TRUE	1
284
#endif
220
#endif
285
221
 Lines 301-361   typedef unsigned char boolean; Link Here 
301
/*
237
/*
302
 * These defines indicate whether to include various optional functions.
238
 * These defines indicate whether to include various optional functions.
303
 * Undefining some of these symbols will produce a smaller but less capable
239
 * Undefining some of these symbols will produce a smaller but less capable
304
 * library.  Note that you can leave certain source files out of the
240
 * library.  Note that you can leave certain source files out of the
305
 * compilation/linking process if you've #undef'd the corresponding symbols.
241
 * compilation/linking process if you've #undef'd the corresponding symbols.
306
 * (You may HAVE to do that if your compiler doesn't like null source files.)
242
 * (You may HAVE to do that if your compiler doesn't like null source files.)
307
 */
243
 */
308
244
309
/*
310
 * Mozilla mods here: undef some features not actually used by the browser.
311
 * This reduces object code size and more importantly allows us to compile
312
 * even with broken compilers that crash when fed certain modules of the
313
 * IJG sources.  Currently we undef:
314
 * DCT_FLOAT_SUPPORTED INPUT_SMOOTHING_SUPPORTED IDCT_SCALING_SUPPORTED
315
 * QUANT_1PASS_SUPPORTED QUANT_2PASS_SUPPORTED
316
 */
317
318
/* Arithmetic coding is unsupported for legal reasons.  Complaints to IBM. */
245
/* Arithmetic coding is unsupported for legal reasons.  Complaints to IBM. */
319
246
320
/* Capability options common to encoder and decoder: */
247
/* Capability options common to encoder and decoder: */
321
248
322
#define DCT_ISLOW_SUPPORTED	/* slow but accurate integer algorithm */
249
#define DCT_ISLOW_SUPPORTED	/* slow but accurate integer algorithm */
323
#undef  DCT_IFAST_SUPPORTED	/* faster, less accurate integer method */
250
#define DCT_IFAST_SUPPORTED	/* faster, less accurate integer method */
324
#undef  DCT_FLOAT_SUPPORTED	/* floating-point: accurate, fast on fast HW */
251
#define DCT_FLOAT_SUPPORTED	/* floating-point: accurate, fast on fast HW */
325
252
326
/* Encoder capability options: */
253
/* Encoder capability options: */
327
254
328
#undef  C_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
255
#undef  C_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
329
#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
256
#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
330
#define C_PROGRESSIVE_SUPPORTED	    /* Progressive JPEG? (Requires MULTISCAN)*/
257
#define C_PROGRESSIVE_SUPPORTED	    /* Progressive JPEG? (Requires MULTISCAN)*/
331
#define ENTROPY_OPT_SUPPORTED	    /* Optimization of entropy coding parms? */
258
#define ENTROPY_OPT_SUPPORTED	    /* Optimization of entropy coding parms? */
332
/* Note: if you selected 12-bit data precision, it is dangerous to turn off
259
/* Note: if you selected 12-bit data precision, it is dangerous to turn off
333
 * ENTROPY_OPT_SUPPORTED.  The standard Huffman tables are only good for 8-bit
260
 * ENTROPY_OPT_SUPPORTED.  The standard Huffman tables are only good for 8-bit
334
 * precision, so jchuff.c normally uses entropy optimization to compute
261
 * precision, so jchuff.c normally uses entropy optimization to compute
335
 * usable tables for higher precision.  If you don't want to do optimization,
262
 * usable tables for higher precision.  If you don't want to do optimization,
336
 * you'll have to supply different default Huffman tables.
263
 * you'll have to supply different default Huffman tables.
337
 * The exact same statements apply for progressive JPEG: the default tables
264
 * The exact same statements apply for progressive JPEG: the default tables
338
 * don't work for progressive mode.  (This may get fixed, however.)
265
 * don't work for progressive mode.  (This may get fixed, however.)
339
 */
266
 */
340
#undef  INPUT_SMOOTHING_SUPPORTED   /* Input image smoothing option? */
267
#define INPUT_SMOOTHING_SUPPORTED   /* Input image smoothing option? */
341
268
342
/* Decoder capability options: */
269
/* Decoder capability options: */
343
270
344
#undef  D_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
271
#undef  D_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
345
#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
272
#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
346
#define D_PROGRESSIVE_SUPPORTED	    /* Progressive JPEG? (Requires MULTISCAN)*/
273
#define D_PROGRESSIVE_SUPPORTED	    /* Progressive JPEG? (Requires MULTISCAN)*/
347
#define SAVE_MARKERS_SUPPORTED	    /* jpeg_save_markers() needed? */
274
#define SAVE_MARKERS_SUPPORTED	    /* jpeg_save_markers() needed? */
348
#define BLOCK_SMOOTHING_SUPPORTED   /* Block smoothing? (Progressive only) */
275
#define BLOCK_SMOOTHING_SUPPORTED   /* Block smoothing? (Progressive only) */
349
#undef  IDCT_SCALING_SUPPORTED	    /* Output rescaling via IDCT? */
276
#define IDCT_SCALING_SUPPORTED	    /* Output rescaling via IDCT? */
350
#undef  UPSAMPLE_SCALING_SUPPORTED  /* Output rescaling at upsample stage? */
277
#undef  UPSAMPLE_SCALING_SUPPORTED  /* Output rescaling at upsample stage? */
351
#define UPSAMPLE_MERGING_SUPPORTED  /* Fast path for sloppy upsampling? */
278
#define UPSAMPLE_MERGING_SUPPORTED  /* Fast path for sloppy upsampling? */
352
#undef  QUANT_1PASS_SUPPORTED	    /* 1-pass color quantization? */
279
#define QUANT_1PASS_SUPPORTED	    /* 1-pass color quantization? */
353
#undef  QUANT_2PASS_SUPPORTED	    /* 2-pass color quantization? */
280
#define QUANT_2PASS_SUPPORTED	    /* 2-pass color quantization? */
354
281
355
/* more capability options later, no doubt */
282
/* more capability options later, no doubt */
356
283
357
284
358
/*
285
/*
359
 * Ordering of RGB data in scanlines passed to or from the application.
286
 * Ordering of RGB data in scanlines passed to or from the application.
360
 * If your application wants to deal with data in the order B,G,R, just
287
 * If your application wants to deal with data in the order B,G,R, just
361
 * change these macros.  You can also deal with formats such as R,G,B,X
288
 * change these macros.  You can also deal with formats such as R,G,B,X
 Lines 370-420   typedef unsigned char boolean; Link Here 
370
 *    can't use color quantization if you change that value.
297
 *    can't use color quantization if you change that value.
371
 */
298
 */
372
299
373
#define RGB_RED		0	/* Offset of Red in an RGB scanline element */
300
#define RGB_RED		0	/* Offset of Red in an RGB scanline element */
374
#define RGB_GREEN	1	/* Offset of Green */
301
#define RGB_GREEN	1	/* Offset of Green */
375
#define RGB_BLUE	2	/* Offset of Blue */
302
#define RGB_BLUE	2	/* Offset of Blue */
376
#define RGB_PIXELSIZE	3	/* JSAMPLEs per RGB scanline element */
303
#define RGB_PIXELSIZE	3	/* JSAMPLEs per RGB scanline element */
377
304
305
#define JPEG_NUMCS 12
306
307
static const int rgb_red[JPEG_NUMCS] = {
308
	-1, -1, RGB_RED, -1, -1, -1, 0, 0, 2, 2, 3, 1
309
};
310
311
static const int rgb_green[JPEG_NUMCS] = {
312
	-1, -1, RGB_GREEN, -1, -1, -1, 1, 1, 1, 1, 2, 2
313
};
314
315
static const int rgb_blue[JPEG_NUMCS] = {
316
	-1, -1, RGB_BLUE, -1, -1, -1, 2, 2, 0, 0, 1, 3
317
};
318
319
static const int rgb_pixelsize[JPEG_NUMCS] = {
320
	-1, -1, RGB_PIXELSIZE, -1, -1, -1, 3, 4, 3, 4, 4, 4
321
};
378
322
379
/* Definitions for speed-related optimizations. */
323
/* Definitions for speed-related optimizations. */
380
324
381
382
/* If your compiler supports inline functions, define INLINE
383
 * as the inline keyword; otherwise define it as empty.
384
 */
385
386
/* Mozilla mods here: add more ways of defining INLINE */
387
388
#ifndef INLINE
389
#ifdef __GNUC__			/* for instance, GNU C knows about inline */
390
#define INLINE __inline__
391
#endif
392
#if defined( __IBMC__ ) || defined (__IBMCPP__)
393
#define INLINE _Inline
394
#endif
395
#ifndef INLINE
396
#ifdef __cplusplus
397
#define INLINE inline		/* a C++ compiler should have it too */
398
#else
399
#define INLINE			/* default is to define it as empty */
400
#endif
401
#endif
402
#endif
403
404
405
/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying
325
/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying
406
 * two 16-bit shorts is faster than multiplying two ints.  Define MULTIPLIER
326
 * two 16-bit shorts is faster than multiplying two ints.  Define MULTIPLIER
407
 * as short on such a machine.  MULTIPLIER must be at least 16 bits wide.
327
 * as short on such a machine.  MULTIPLIER must be at least 16 bits wide.
408
 */
328
 */
409
329
410
#ifndef MULTIPLIER
330
#ifndef MULTIPLIER
411
#define MULTIPLIER  int16		/* type for fastest integer multiply */
331
#ifndef WITH_SIMD
412
#endif
332
#define MULTIPLIER  int		/* type for fastest integer multiply */
333
#else
334
#define MULTIPLIER short  /* prefer 16-bit with SIMD for parellelism */
335
#endif
336
#endif
413
337
414
338
415
/* FAST_FLOAT should be either float or double, whichever is done faster
339
/* FAST_FLOAT should be either float or double, whichever is done faster
416
 * by your compiler.  (Note that this type is only used in the floating point
340
 * by your compiler.  (Note that this type is only used in the floating point
417
 * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
341
 * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
418
 * Typically, float is faster in ANSI C compilers, while double is faster in
342
 * Typically, float is faster in ANSI C compilers, while double is faster in
419
 * pre-ANSI compilers (because they insist on converting to double anyway).
343
 * pre-ANSI compilers (because they insist on converting to double anyway).
420
 * The code below therefore chooses float if we have ANSI-style prototypes.
344
 * The code below therefore chooses float if we have ANSI-style prototypes.
(-)a/jpeg/jos2fig.h (-45 lines)
Line     Link Here 
 Lines 1-45    Link Here 
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is mozilla.org code.
16
 *
17
 * The Initial Developer of the Original Code is
18
 * Netscape Communications Corporation.
19
 * Portions created by the Initial Developer are Copyright (C) 1998
20
 * the Initial Developer. All Rights Reserved.
21
 *
22
 * Contributor(s):
23
 *
24
 * Alternatively, the contents of this file may be used under the terms of
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 * of those above. If you wish to allow use of your version of this file only
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 * use your version of this file under the terms of the MPL, indicate your
31
 * decision by deleting the provisions above and replace them with the notice
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
36
 * ***** END LICENSE BLOCK ***** */
37
38
#ifndef __jos2fig_h__
39
#define __jos2fig_h__
40
41
/*
42
** Place holder for the OS/2 code that might actually make it into the trunk someday.  Maybe.
43
*/
44
45
#endif  /* __jos2fig_h__ */
(-)a/jpeg/jpegcomp.h (+26 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * jpegcomp.h
3
 *
4
 * Copyright (C) 2010, D. R. Commander
5
 * For conditions of distribution and use, see the accompanying README file.
6
 *
7
 * JPEG compatibility macros
8
 * These declarations are considered internal to the JPEG library; most
9
 * applications using the library shouldn't need to include this file.
10
 */
11
12
#if JPEG_LIB_VERSION >= 70
13
#define _DCT_scaled_size DCT_h_scaled_size
14
#define _min_DCT_scaled_size min_DCT_h_scaled_size
15
#define _min_DCT_h_scaled_size min_DCT_h_scaled_size
16
#define _min_DCT_v_scaled_size min_DCT_v_scaled_size
17
#define _jpeg_width jpeg_width
18
#define _jpeg_height jpeg_height
19
#else
20
#define _DCT_scaled_size DCT_scaled_size
21
#define _min_DCT_scaled_size min_DCT_scaled_size
22
#define _min_DCT_h_scaled_size min_DCT_scaled_size
23
#define _min_DCT_v_scaled_size min_DCT_scaled_size
24
#define _jpeg_width image_width
25
#define _jpeg_height image_height
26
#endif
(-)a/jpeg/jpegint.h (-1 / +10 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jpegint.h
2
 * jpegint.h
3
 *
3
 *
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
4
 * Copyright (C) 1991-1997, Thomas G. Lane.
5
 * Modified 1997-2009 by Guido Vollbeding.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file provides common declarations for the various JPEG modules.
9
 * This file provides common declarations for the various JPEG modules.
9
 * These declarations are considered internal to the JPEG library; most
10
 * These declarations are considered internal to the JPEG library; most
10
 * applications using the library shouldn't need to include this file.
11
 * applications using the library shouldn't need to include this file.
11
 */
12
 */
12
13
 Lines 299-337   struct jpeg_color_quantizer { Link Here 
299
#define jinit_c_main_controller	jICMainC
300
#define jinit_c_main_controller	jICMainC
300
#define jinit_c_prep_controller	jICPrepC
301
#define jinit_c_prep_controller	jICPrepC
301
#define jinit_c_coef_controller	jICCoefC
302
#define jinit_c_coef_controller	jICCoefC
302
#define jinit_color_converter	jICColor
303
#define jinit_color_converter	jICColor
303
#define jinit_downsampler	jIDownsampler
304
#define jinit_downsampler	jIDownsampler
304
#define jinit_forward_dct	jIFDCT
305
#define jinit_forward_dct	jIFDCT
305
#define jinit_huff_encoder	jIHEncoder
306
#define jinit_huff_encoder	jIHEncoder
306
#define jinit_phuff_encoder	jIPHEncoder
307
#define jinit_phuff_encoder	jIPHEncoder
308
#define jinit_arith_encoder	jIAEncoder
307
#define jinit_marker_writer	jIMWriter
309
#define jinit_marker_writer	jIMWriter
308
#define jinit_master_decompress	jIDMaster
310
#define jinit_master_decompress	jIDMaster
309
#define jinit_d_main_controller	jIDMainC
311
#define jinit_d_main_controller	jIDMainC
310
#define jinit_d_coef_controller	jIDCoefC
312
#define jinit_d_coef_controller	jIDCoefC
311
#define jinit_d_post_controller	jIDPostC
313
#define jinit_d_post_controller	jIDPostC
312
#define jinit_input_controller	jIInCtlr
314
#define jinit_input_controller	jIInCtlr
313
#define jinit_marker_reader	jIMReader
315
#define jinit_marker_reader	jIMReader
314
#define jinit_huff_decoder	jIHDecoder
316
#define jinit_huff_decoder	jIHDecoder
315
#define jinit_phuff_decoder	jIPHDecoder
317
#define jinit_phuff_decoder	jIPHDecoder
318
#define jinit_arith_decoder	jIADecoder
316
#define jinit_inverse_dct	jIIDCT
319
#define jinit_inverse_dct	jIIDCT
317
#define jinit_upsampler		jIUpsampler
320
#define jinit_upsampler		jIUpsampler
318
#define jinit_color_deconverter	jIDColor
321
#define jinit_color_deconverter	jIDColor
319
#define jinit_1pass_quantizer	jI1Quant
322
#define jinit_1pass_quantizer	jI1Quant
320
#define jinit_2pass_quantizer	jI2Quant
323
#define jinit_2pass_quantizer	jI2Quant
321
#define jinit_merged_upsampler	jIMUpsampler
324
#define jinit_merged_upsampler	jIMUpsampler
322
#define jinit_memory_mgr	jIMemMgr
325
#define jinit_memory_mgr	jIMemMgr
323
#define jdiv_round_up		jDivRound
326
#define jdiv_round_up		jDivRound
324
#define jround_up		jRound
327
#define jround_up		jRound
325
#define jcopy_sample_rows	jCopySamples
328
#define jcopy_sample_rows	jCopySamples
326
#define jcopy_block_row		jCopyBlocks
329
#define jcopy_block_row		jCopyBlocks
327
#define jzero_far		jZeroFar
330
#define jzero_far		jZeroFar
328
#define jpeg_zigzag_order	jZIGTable
331
#define jpeg_zigzag_order	jZIGTable
329
#define jpeg_natural_order	jZAGTable
332
#define jpeg_natural_order	jZAGTable
333
#define jpeg_aritab		jAriTab
330
#endif /* NEED_SHORT_EXTERNAL_NAMES */
334
#endif /* NEED_SHORT_EXTERNAL_NAMES */
331
335
332
336
333
/* Compression module initialization routines */
337
/* Compression module initialization routines */
334
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
338
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
335
EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
339
EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
336
					 boolean transcode_only));
340
					 boolean transcode_only));
337
EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
341
EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
 Lines 340-392   EXTERN(void) jinit_c_prep_controller JPP Link Here 
340
					  boolean need_full_buffer));
344
					  boolean need_full_buffer));
341
EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
345
EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
342
					  boolean need_full_buffer));
346
					  boolean need_full_buffer));
343
EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
347
EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
344
EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
348
EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
345
EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
349
EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
346
EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
350
EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
347
EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
351
EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
352
EXTERN(void) jinit_arith_encoder JPP((j_compress_ptr cinfo));
348
EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
353
EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
349
/* Decompression module initialization routines */
354
/* Decompression module initialization routines */
350
EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
355
EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
351
EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
356
EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
352
					  boolean need_full_buffer));
357
					  boolean need_full_buffer));
353
EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
358
EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
354
					  boolean need_full_buffer));
359
					  boolean need_full_buffer));
355
EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
360
EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
356
					  boolean need_full_buffer));
361
					  boolean need_full_buffer));
357
EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
362
EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
358
EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
363
EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
359
EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
364
EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
360
EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
365
EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
366
EXTERN(void) jinit_arith_decoder JPP((j_decompress_ptr cinfo));
361
EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
367
EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
362
EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
368
EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
363
EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
369
EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
364
EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
370
EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
365
EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
371
EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
366
EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
372
EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
367
/* Memory manager initialization */
373
/* Memory manager initialization */
368
EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
374
EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
369
375
370
/* Utility routines in jutils.c */
376
/* Utility routines in jutils.c */
371
EXTERN(long) jdiv_round_up JPP((long a, long b));
377
EXTERN(long) jdiv_round_up JPP((long a, long b));
372
EXTERN(long) jround_up JPP((long a, long b));
378
EXTERN(size_t) jround_up JPP((size_t a, size_t b));
373
EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
379
EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
374
				    JSAMPARRAY output_array, int dest_row,
380
				    JSAMPARRAY output_array, int dest_row,
375
				    int num_rows, JDIMENSION num_cols));
381
				    int num_rows, JDIMENSION num_cols));
376
EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
382
EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
377
				  JDIMENSION num_blocks));
383
				  JDIMENSION num_blocks));
378
EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
384
EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
379
/* Constant tables in jutils.c */
385
/* Constant tables in jutils.c */
380
#if 0				/* This table is not actually needed in v6a */
386
#if 0				/* This table is not actually needed in v6a */
381
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
387
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
382
#endif
388
#endif
383
extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
389
extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
384
390
391
/* Arithmetic coding probability estimation tables in jaricom.c */
392
extern const INT32 jpeg_aritab[];
393
385
/* Suppress undefined-structure complaints if necessary. */
394
/* Suppress undefined-structure complaints if necessary. */
386
395
387
#ifdef INCOMPLETE_TYPES_BROKEN
396
#ifdef INCOMPLETE_TYPES_BROKEN
388
#ifndef AM_MEMORY_MANAGER	/* only jmemmgr.c defines these */
397
#ifndef AM_MEMORY_MANAGER	/* only jmemmgr.c defines these */
389
struct jvirt_sarray_control { long dummy; };
398
struct jvirt_sarray_control { long dummy; };
390
struct jvirt_barray_control { long dummy; };
399
struct jvirt_barray_control { long dummy; };
391
#endif
400
#endif
392
#endif /* INCOMPLETE_TYPES_BROKEN */
401
#endif /* INCOMPLETE_TYPES_BROKEN */
(-)a/jpeg/jpeglib.h (-44 / +121 lines)
Line     Link Here 
 Lines 1-63    Link Here 
1
/*
1
/*
2
 * jpeglib.h
2
 * jpeglib.h
3
 *
3
 *
4
 * Copyright (C) 1991-1998, Thomas G. Lane.
4
 * Copyright (C) 1991-1998, Thomas G. Lane.
5
 * Modified 2002-2009 by Guido Vollbeding.
6
 * Copyright (C) 2009-2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
7
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
8
 * For conditions of distribution and use, see the accompanying README file.
7
 *
9
 *
8
 * This file defines the application interface for the JPEG library.
10
 * This file defines the application interface for the JPEG library.
9
 * Most applications using the library need only include this file,
11
 * Most applications using the library need only include this file,
10
 * and perhaps jerror.h if they want to know the exact error codes.
12
 * and perhaps jerror.h if they want to know the exact error codes.
11
 */
13
 */
12
14
13
#ifndef JPEGLIB_H
15
#ifndef JPEGLIB_H
14
#define JPEGLIB_H
16
#define JPEGLIB_H
15
17
16
#ifdef XP_OS2
17
/*
18
 * On OS/2, the system will have defined RGB_* so we #undef 'em to avoid warnings
19
 * from jmorecfg.h.
20
 */
21
#ifdef RGB_RED
22
	#undef RGB_RED
23
#endif
24
#ifdef RGB_GREEN
25
	#undef RGB_GREEN
26
#endif
27
#ifdef RGB_BLUE
28
	#undef RGB_BLUE
29
#endif
30
31
#endif
32
33
/*
18
/*
34
 * First we include the configuration files that record how this
19
 * First we include the configuration files that record how this
35
 * installation of the JPEG library is set up.  jconfig.h can be
20
 * installation of the JPEG library is set up.  jconfig.h can be
36
 * generated automatically for many systems.  jmorecfg.h contains
21
 * generated automatically for many systems.  jmorecfg.h contains
37
 * manual configuration options that most people need not worry about.
22
 * manual configuration options that most people need not worry about.
38
 */
23
 */
39
24
40
#ifndef JCONFIG_INCLUDED	/* in case jinclude.h already did */
25
#ifndef JCONFIG_INCLUDED	/* in case jinclude.h already did */
41
#include "jconfig.h"		/* widely used configuration options */
26
#include "jconfig.h"		/* widely used configuration options */
42
#endif
27
#endif
43
#include "jmorecfg.h"		/* seldom changed options */
28
#include "jmorecfg.h"		/* seldom changed options */
44
29
45
30
46
#ifdef HAVE_MMX_INTEL_MNEMONICS
31
#ifdef __cplusplus
47
	extern int MMXAvailable;
32
#ifndef DONT_USE_EXTERN_C
48
#endif
33
extern "C" {
49
34
#endif
50
35
#endif
51
/* Version ID for the JPEG library.
52
 * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
53
 */
54
55
#define JPEG_LIB_VERSION  62	/* Version 6b */
56
36
57
37
58
/* Various constants determining the sizes of things.
38
/* Various constants determining the sizes of things.
59
 * All of these are specified by the JPEG standard, so don't change them
39
 * All of these are specified by the JPEG standard, so don't change them
60
 * if you want to be compatible.
40
 * if you want to be compatible.
61
 */
41
 */
62
42
63
#define DCTSIZE		    8	/* The basic DCT block is 8x8 samples */
43
#define DCTSIZE		    8	/* The basic DCT block is 8x8 samples */
 Lines 161-197   typedef struct { Link Here 
161
  JDIMENSION width_in_blocks;
141
  JDIMENSION width_in_blocks;
162
  JDIMENSION height_in_blocks;
142
  JDIMENSION height_in_blocks;
163
  /* Size of a DCT block in samples.  Always DCTSIZE for compression.
143
  /* Size of a DCT block in samples.  Always DCTSIZE for compression.
164
   * For decompression this is the size of the output from one DCT block,
144
   * For decompression this is the size of the output from one DCT block,
165
   * reflecting any scaling we choose to apply during the IDCT step.
145
   * reflecting any scaling we choose to apply during the IDCT step.
166
   * Values of 1,2,4,8 are likely to be supported.  Note that different
146
   * Values of 1,2,4,8 are likely to be supported.  Note that different
167
   * components may receive different IDCT scalings.
147
   * components may receive different IDCT scalings.
168
   */
148
   */
149
#if JPEG_LIB_VERSION >= 70
150
  int DCT_h_scaled_size;
151
  int DCT_v_scaled_size;
152
#else
169
  int DCT_scaled_size;
153
  int DCT_scaled_size;
154
#endif
170
  /* The downsampled dimensions are the component's actual, unpadded number
155
  /* The downsampled dimensions are the component's actual, unpadded number
171
   * of samples at the main buffer (preprocessing/compression interface), thus
156
   * of samples at the main buffer (preprocessing/compression interface), thus
172
   * downsampled_width = ceil(image_width * Hi/Hmax)
157
   * downsampled_width = ceil(image_width * Hi/Hmax)
173
   * and similarly for height.  For decompression, IDCT scaling is included, so
158
   * and similarly for height.  For decompression, IDCT scaling is included, so
174
   * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
159
   * downsampled_width = ceil(image_width * Hi/Hmax * DCT_[h_]scaled_size/DCTSIZE)
175
   */
160
   */
176
  JDIMENSION downsampled_width;	 /* actual width in samples */
161
  JDIMENSION downsampled_width;	 /* actual width in samples */
177
  JDIMENSION downsampled_height; /* actual height in samples */
162
  JDIMENSION downsampled_height; /* actual height in samples */
178
  /* This flag is used only for decompression.  In cases where some of the
163
  /* This flag is used only for decompression.  In cases where some of the
179
   * components will be ignored (eg grayscale output from YCbCr image),
164
   * components will be ignored (eg grayscale output from YCbCr image),
180
   * we can skip most computations for the unused components.
165
   * we can skip most computations for the unused components.
181
   */
166
   */
182
  boolean component_needed;	/* do we need the value of this component? */
167
  boolean component_needed;	/* do we need the value of this component? */
183
168
184
  /* These values are computed before starting a scan of the component. */
169
  /* These values are computed before starting a scan of the component. */
185
  /* The decompressor output side may not use these variables. */
170
  /* The decompressor output side may not use these variables. */
186
  int MCU_width;		/* number of blocks per MCU, horizontally */
171
  int MCU_width;		/* number of blocks per MCU, horizontally */
187
  int MCU_height;		/* number of blocks per MCU, vertically */
172
  int MCU_height;		/* number of blocks per MCU, vertically */
188
  int MCU_blocks;		/* MCU_width * MCU_height */
173
  int MCU_blocks;		/* MCU_width * MCU_height */
189
  int MCU_sample_width;		/* MCU width in samples, MCU_width*DCT_scaled_size */
174
  int MCU_sample_width;		/* MCU width in samples, MCU_width*DCT_[h_]scaled_size */
190
  int last_col_width;		/* # of non-dummy blocks across in last MCU */
175
  int last_col_width;		/* # of non-dummy blocks across in last MCU */
191
  int last_row_height;		/* # of non-dummy blocks down in last MCU */
176
  int last_row_height;		/* # of non-dummy blocks down in last MCU */
192
177
193
  /* Saved quantization table for component; NULL if none yet saved.
178
  /* Saved quantization table for component; NULL if none yet saved.
194
   * See jdinput.c comments about the need for this information.
179
   * See jdinput.c comments about the need for this information.
195
   * This field is currently used only for decompression.
180
   * This field is currently used only for decompression.
196
   */
181
   */
197
  JQUANT_TBL * quant_table;
182
  JQUANT_TBL * quant_table;
 Lines 220-242   struct jpeg_marker_struct { Link Here 
220
  unsigned int original_length;	/* # bytes of data in the file */
205
  unsigned int original_length;	/* # bytes of data in the file */
221
  unsigned int data_length;	/* # bytes of data saved at data[] */
206
  unsigned int data_length;	/* # bytes of data saved at data[] */
222
  JOCTET FAR * data;		/* the data contained in the marker */
207
  JOCTET FAR * data;		/* the data contained in the marker */
223
  /* the marker length word is not counted in data_length or original_length */
208
  /* the marker length word is not counted in data_length or original_length */
224
};
209
};
225
210
226
/* Known color spaces. */
211
/* Known color spaces. */
227
212
213
#define JCS_EXTENSIONS 1
214
228
typedef enum {
215
typedef enum {
229
	JCS_UNKNOWN,		/* error/unspecified */
216
	JCS_UNKNOWN,		/* error/unspecified */
230
	JCS_GRAYSCALE,		/* monochrome */
217
	JCS_GRAYSCALE,		/* monochrome */
231
	JCS_RGB,		/* red/green/blue */
218
	JCS_RGB,		/* red/green/blue as specified by the RGB_RED, RGB_GREEN,
219
                 RGB_BLUE, and RGB_PIXELSIZE macros */
232
	JCS_YCbCr,		/* Y/Cb/Cr (also known as YUV) */
220
	JCS_YCbCr,		/* Y/Cb/Cr (also known as YUV) */
233
	JCS_CMYK,		/* C/M/Y/K */
221
	JCS_CMYK,		/* C/M/Y/K */
234
	JCS_YCCK		/* Y/Cb/Cr/K */
222
	JCS_YCCK,		/* Y/Cb/Cr/K */
223
	JCS_EXT_RGB,		/* red/green/blue */
224
	JCS_EXT_RGBX,		/* red/green/blue/x */
225
	JCS_EXT_BGR,		/* blue/green/red */
226
	JCS_EXT_BGRX,		/* blue/green/red/x */
227
	JCS_EXT_XBGR,		/* x/blue/green/red */
228
	JCS_EXT_XRGB		/* x/red/green/blue */
235
} J_COLOR_SPACE;
229
} J_COLOR_SPACE;
236
230
237
/* DCT/IDCT algorithm options. */
231
/* DCT/IDCT algorithm options. */
238
232
239
typedef enum {
233
typedef enum {
240
	JDCT_ISLOW,		/* slow but accurate integer algorithm */
234
	JDCT_ISLOW,		/* slow but accurate integer algorithm */
241
	JDCT_IFAST,		/* faster, less accurate integer method */
235
	JDCT_IFAST,		/* faster, less accurate integer method */
242
	JDCT_FLOAT		/* floating-point: accurate, fast on fast HW */
236
	JDCT_FLOAT		/* floating-point: accurate, fast on fast HW */
 Lines 308-353   struct jpeg_compress_struct { Link Here 
308
  /* Compression parameters --- these fields must be set before calling
302
  /* Compression parameters --- these fields must be set before calling
309
   * jpeg_start_compress().  We recommend calling jpeg_set_defaults() to
303
   * jpeg_start_compress().  We recommend calling jpeg_set_defaults() to
310
   * initialize everything to reasonable defaults, then changing anything
304
   * initialize everything to reasonable defaults, then changing anything
311
   * the application specifically wants to change.  That way you won't get
305
   * the application specifically wants to change.  That way you won't get
312
   * burnt when new parameters are added.  Also note that there are several
306
   * burnt when new parameters are added.  Also note that there are several
313
   * helper routines to simplify changing parameters.
307
   * helper routines to simplify changing parameters.
314
   */
308
   */
315
309
310
#if JPEG_LIB_VERSION >= 70
311
  unsigned int scale_num, scale_denom; /* fraction by which to scale image */
312
313
  JDIMENSION jpeg_width;	/* scaled JPEG image width */
314
  JDIMENSION jpeg_height;	/* scaled JPEG image height */
315
  /* Dimensions of actual JPEG image that will be written to file,
316
   * derived from input dimensions by scaling factors above.
317
   * These fields are computed by jpeg_start_compress().
318
   * You can also use jpeg_calc_jpeg_dimensions() to determine these values
319
   * in advance of calling jpeg_start_compress().
320
   */
321
#endif
322
316
  int data_precision;		/* bits of precision in image data */
323
  int data_precision;		/* bits of precision in image data */
317
324
318
  int num_components;		/* # of color components in JPEG image */
325
  int num_components;		/* # of color components in JPEG image */
319
  J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
326
  J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
320
327
321
  jpeg_component_info * comp_info;
328
  jpeg_component_info * comp_info;
322
  /* comp_info[i] describes component that appears i'th in SOF */
329
  /* comp_info[i] describes component that appears i'th in SOF */
323
  
330
324
  JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
331
  JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
325
  /* ptrs to coefficient quantization tables, or NULL if not defined */
332
#if JPEG_LIB_VERSION >= 70
326
  
333
  int q_scale_factor[NUM_QUANT_TBLS];
334
#endif
335
  /* ptrs to coefficient quantization tables, or NULL if not defined,
336
   * and corresponding scale factors (percentage, initialized 100).
337
   */
338
327
  JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
339
  JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
328
  JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
340
  JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
329
  /* ptrs to Huffman coding tables, or NULL if not defined */
341
  /* ptrs to Huffman coding tables, or NULL if not defined */
330
  
342
331
  UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
343
  UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
332
  UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
344
  UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
333
  UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
345
  UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
334
346
335
  int num_scans;		/* # of entries in scan_info array */
347
  int num_scans;		/* # of entries in scan_info array */
336
  const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
348
  const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
337
  /* The default value of scan_info is NULL, which causes a single-scan
349
  /* The default value of scan_info is NULL, which causes a single-scan
338
   * sequential JPEG file to be emitted.  To create a multi-scan file,
350
   * sequential JPEG file to be emitted.  To create a multi-scan file,
339
   * set num_scans and scan_info to point to an array of scan definitions.
351
   * set num_scans and scan_info to point to an array of scan definitions.
340
   */
352
   */
341
353
342
  boolean raw_data_in;		/* TRUE=caller supplies downsampled data */
354
  boolean raw_data_in;		/* TRUE=caller supplies downsampled data */
343
  boolean arith_code;		/* TRUE=arithmetic coding, FALSE=Huffman */
355
  boolean arith_code;		/* TRUE=arithmetic coding, FALSE=Huffman */
344
  boolean optimize_coding;	/* TRUE=optimize entropy encoding parms */
356
  boolean optimize_coding;	/* TRUE=optimize entropy encoding parms */
345
  boolean CCIR601_sampling;	/* TRUE=first samples are cosited */
357
  boolean CCIR601_sampling;	/* TRUE=first samples are cosited */
358
#if JPEG_LIB_VERSION >= 70
359
  boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */
360
#endif
346
  int smoothing_factor;		/* 1..100, or 0 for no input smoothing */
361
  int smoothing_factor;		/* 1..100, or 0 for no input smoothing */
347
  J_DCT_METHOD dct_method;	/* DCT algorithm selector */
362
  J_DCT_METHOD dct_method;	/* DCT algorithm selector */
348
363
349
  /* The restart interval can be specified in absolute MCUs by setting
364
  /* The restart interval can be specified in absolute MCUs by setting
350
   * restart_interval, or in MCU rows by setting restart_in_rows
365
   * restart_interval, or in MCU rows by setting restart_in_rows
351
   * (in which case the correct restart_interval will be figured
366
   * (in which case the correct restart_interval will be figured
352
   * for each scan).
367
   * for each scan).
353
   */
368
   */
 Lines 381-396   struct jpeg_compress_struct { Link Here 
381
396
382
  /*
397
  /*
383
   * These fields are computed during compression startup
398
   * These fields are computed during compression startup
384
   */
399
   */
385
  boolean progressive_mode;	/* TRUE if scan script uses progressive mode */
400
  boolean progressive_mode;	/* TRUE if scan script uses progressive mode */
386
  int max_h_samp_factor;	/* largest h_samp_factor */
401
  int max_h_samp_factor;	/* largest h_samp_factor */
387
  int max_v_samp_factor;	/* largest v_samp_factor */
402
  int max_v_samp_factor;	/* largest v_samp_factor */
388
403
404
#if JPEG_LIB_VERSION >= 70
405
  int min_DCT_h_scaled_size;	/* smallest DCT_h_scaled_size of any component */
406
  int min_DCT_v_scaled_size;	/* smallest DCT_v_scaled_size of any component */
407
#endif
408
389
  JDIMENSION total_iMCU_rows;	/* # of iMCU rows to be input to coef ctlr */
409
  JDIMENSION total_iMCU_rows;	/* # of iMCU rows to be input to coef ctlr */
390
  /* The coefficient controller receives data in units of MCU rows as defined
410
  /* The coefficient controller receives data in units of MCU rows as defined
391
   * for fully interleaved scans (whether the JPEG file is interleaved or not).
411
   * for fully interleaved scans (whether the JPEG file is interleaved or not).
392
   * There are v_samp_factor * DCTSIZE sample rows of each component in an
412
   * There are v_samp_factor * DCTSIZE sample rows of each component in an
393
   * "iMCU" (interleaved MCU) row.
413
   * "iMCU" (interleaved MCU) row.
394
   */
414
   */
395
  
415
  
396
  /*
416
  /*
 Lines 406-421   struct jpeg_compress_struct { Link Here 
406
  
426
  
407
  int blocks_in_MCU;		/* # of DCT blocks per MCU */
427
  int blocks_in_MCU;		/* # of DCT blocks per MCU */
408
  int MCU_membership[C_MAX_BLOCKS_IN_MCU];
428
  int MCU_membership[C_MAX_BLOCKS_IN_MCU];
409
  /* MCU_membership[i] is index in cur_comp_info of component owning */
429
  /* MCU_membership[i] is index in cur_comp_info of component owning */
410
  /* i'th block in an MCU */
430
  /* i'th block in an MCU */
411
431
412
  int Ss, Se, Ah, Al;		/* progressive JPEG parameters for scan */
432
  int Ss, Se, Ah, Al;		/* progressive JPEG parameters for scan */
413
433
434
#if JPEG_LIB_VERSION >= 80
435
  int block_size;		/* the basic DCT block size: 1..16 */
436
  const int * natural_order;	/* natural-order position array */
437
  int lim_Se;			/* min( Se, DCTSIZE2-1 ) */
438
#endif
439
414
  /*
440
  /*
415
   * Links to compression subobjects (methods and private variables of modules)
441
   * Links to compression subobjects (methods and private variables of modules)
416
   */
442
   */
417
  struct jpeg_comp_master * master;
443
  struct jpeg_comp_master * master;
418
  struct jpeg_c_main_controller * main;
444
  struct jpeg_c_main_controller * main;
419
  struct jpeg_c_prep_controller * prep;
445
  struct jpeg_c_prep_controller * prep;
420
  struct jpeg_c_coef_controller * coef;
446
  struct jpeg_c_coef_controller * coef;
421
  struct jpeg_marker_writer * marker;
447
  struct jpeg_marker_writer * marker;
 Lines 552-567   struct jpeg_decompress_struct { Link Here 
552
   * are given in SOF/SOS markers or defined to be reset by SOI.
578
   * are given in SOF/SOS markers or defined to be reset by SOI.
553
   */
579
   */
554
580
555
  int data_precision;		/* bits of precision in image data */
581
  int data_precision;		/* bits of precision in image data */
556
582
557
  jpeg_component_info * comp_info;
583
  jpeg_component_info * comp_info;
558
  /* comp_info[i] describes component that appears i'th in SOF */
584
  /* comp_info[i] describes component that appears i'th in SOF */
559
585
586
#if JPEG_LIB_VERSION >= 80
587
  boolean is_baseline;		/* TRUE if Baseline SOF0 encountered */
588
#endif
560
  boolean progressive_mode;	/* TRUE if SOFn specifies progressive mode */
589
  boolean progressive_mode;	/* TRUE if SOFn specifies progressive mode */
561
  boolean arith_code;		/* TRUE=arithmetic coding, FALSE=Huffman */
590
  boolean arith_code;		/* TRUE=arithmetic coding, FALSE=Huffman */
562
591
563
  UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
592
  UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
564
  UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
593
  UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
565
  UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
594
  UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
566
595
567
  unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
596
  unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
 Lines 592-617   struct jpeg_decompress_struct { Link Here 
592
   */
621
   */
593
622
594
  /*
623
  /*
595
   * These fields are computed during decompression startup
624
   * These fields are computed during decompression startup
596
   */
625
   */
597
  int max_h_samp_factor;	/* largest h_samp_factor */
626
  int max_h_samp_factor;	/* largest h_samp_factor */
598
  int max_v_samp_factor;	/* largest v_samp_factor */
627
  int max_v_samp_factor;	/* largest v_samp_factor */
599
628
629
#if JPEG_LIB_VERSION >= 70
630
  int min_DCT_h_scaled_size;	/* smallest DCT_h_scaled_size of any component */
631
  int min_DCT_v_scaled_size;	/* smallest DCT_v_scaled_size of any component */
632
#else
600
  int min_DCT_scaled_size;	/* smallest DCT_scaled_size of any component */
633
  int min_DCT_scaled_size;	/* smallest DCT_scaled_size of any component */
634
#endif
601
635
602
  JDIMENSION total_iMCU_rows;	/* # of iMCU rows in image */
636
  JDIMENSION total_iMCU_rows;	/* # of iMCU rows in image */
603
  /* The coefficient controller's input and output progress is measured in
637
  /* The coefficient controller's input and output progress is measured in
604
   * units of "iMCU" (interleaved MCU) rows.  These are the same as MCU rows
638
   * units of "iMCU" (interleaved MCU) rows.  These are the same as MCU rows
605
   * in fully interleaved JPEG scans, but are used whether the scan is
639
   * in fully interleaved JPEG scans, but are used whether the scan is
606
   * interleaved or not.  We define an iMCU row as v_samp_factor DCT block
640
   * interleaved or not.  We define an iMCU row as v_samp_factor DCT block
607
   * rows of each component.  Therefore, the IDCT output contains
641
   * rows of each component.  Therefore, the IDCT output contains
608
   * v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row.
642
   * v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row.
609
   */
643
   */
610
644
611
  JSAMPLE * sample_range_limit; /* table for fast range-limiting */
645
  JSAMPLE * sample_range_limit; /* table for fast range-limiting */
612
646
613
  /*
647
  /*
614
   * These fields are valid during any one scan.
648
   * These fields are valid during any one scan.
615
   * They describe the components and MCUs actually appearing in the scan.
649
   * They describe the components and MCUs actually appearing in the scan.
616
   * Note that the decompressor output side must not use these fields.
650
   * Note that the decompressor output side must not use these fields.
617
   */
651
   */
 Lines 624-639   struct jpeg_decompress_struct { Link Here 
624
658
625
  int blocks_in_MCU;		/* # of DCT blocks per MCU */
659
  int blocks_in_MCU;		/* # of DCT blocks per MCU */
626
  int MCU_membership[D_MAX_BLOCKS_IN_MCU];
660
  int MCU_membership[D_MAX_BLOCKS_IN_MCU];
627
  /* MCU_membership[i] is index in cur_comp_info of component owning */
661
  /* MCU_membership[i] is index in cur_comp_info of component owning */
628
  /* i'th block in an MCU */
662
  /* i'th block in an MCU */
629
663
630
  int Ss, Se, Ah, Al;		/* progressive JPEG parameters for scan */
664
  int Ss, Se, Ah, Al;		/* progressive JPEG parameters for scan */
631
665
666
#if JPEG_LIB_VERSION >= 80
667
  /* These fields are derived from Se of first SOS marker.
668
   */
669
  int block_size;		/* the basic DCT block size: 1..16 */
670
  const int * natural_order; /* natural-order position array for entropy decode */
671
  int lim_Se;			/* min( Se, DCTSIZE2-1 ) for entropy decode */
672
#endif
673
632
  /* This field is shared between entropy decoder and marker parser.
674
  /* This field is shared between entropy decoder and marker parser.
633
   * It is either zero or the code of a JPEG marker that has been
675
   * It is either zero or the code of a JPEG marker that has been
634
   * read from the data source, but has not yet been processed.
676
   * read from the data source, but has not yet been processed.
635
   */
677
   */
636
  int unread_marker;
678
  int unread_marker;
637
679
638
  /*
680
  /*
639
   * Links to decompression subobjects (methods, private variables of modules)
681
   * Links to decompression subobjects (methods, private variables of modules)
 Lines 853-914   typedef JMETHOD(boolean, jpeg_marker_par Link Here 
853
#ifdef NEED_SHORT_EXTERNAL_NAMES
895
#ifdef NEED_SHORT_EXTERNAL_NAMES
854
#define jpeg_std_error		jStdError
896
#define jpeg_std_error		jStdError
855
#define jpeg_CreateCompress	jCreaCompress
897
#define jpeg_CreateCompress	jCreaCompress
856
#define jpeg_CreateDecompress	jCreaDecompress
898
#define jpeg_CreateDecompress	jCreaDecompress
857
#define jpeg_destroy_compress	jDestCompress
899
#define jpeg_destroy_compress	jDestCompress
858
#define jpeg_destroy_decompress	jDestDecompress
900
#define jpeg_destroy_decompress	jDestDecompress
859
#define jpeg_stdio_dest		jStdDest
901
#define jpeg_stdio_dest		jStdDest
860
#define jpeg_stdio_src		jStdSrc
902
#define jpeg_stdio_src		jStdSrc
903
#if JPEG_LIB_VERSION >= 80
904
#define jpeg_mem_dest		jMemDest
905
#define jpeg_mem_src		jMemSrc
906
#endif
861
#define jpeg_set_defaults	jSetDefaults
907
#define jpeg_set_defaults	jSetDefaults
862
#define jpeg_set_colorspace	jSetColorspace
908
#define jpeg_set_colorspace	jSetColorspace
863
#define jpeg_default_colorspace	jDefColorspace
909
#define jpeg_default_colorspace	jDefColorspace
864
#define jpeg_set_quality	jSetQuality
910
#define jpeg_set_quality	jSetQuality
865
#define jpeg_set_linear_quality	jSetLQuality
911
#define jpeg_set_linear_quality	jSetLQuality
912
#if JPEG_LIB_VERSION >= 70
913
#define jpeg_default_qtables	jDefQTables
914
#endif
866
#define jpeg_add_quant_table	jAddQuantTable
915
#define jpeg_add_quant_table	jAddQuantTable
867
#define jpeg_quality_scaling	jQualityScaling
916
#define jpeg_quality_scaling	jQualityScaling
868
#define jpeg_simple_progression	jSimProgress
917
#define jpeg_simple_progression	jSimProgress
869
#define jpeg_suppress_tables	jSuppressTables
918
#define jpeg_suppress_tables	jSuppressTables
870
#define jpeg_alloc_quant_table	jAlcQTable
919
#define jpeg_alloc_quant_table	jAlcQTable
871
#define jpeg_alloc_huff_table	jAlcHTable
920
#define jpeg_alloc_huff_table	jAlcHTable
872
#define jpeg_start_compress	jStrtCompress
921
#define jpeg_start_compress	jStrtCompress
873
#define jpeg_write_scanlines	jWrtScanlines
922
#define jpeg_write_scanlines	jWrtScanlines
874
#define jpeg_finish_compress	jFinCompress
923
#define jpeg_finish_compress	jFinCompress
924
#if JPEG_LIB_VERSION >= 70
925
#define jpeg_calc_jpeg_dimensions	jCjpegDimensions
926
#endif
875
#define jpeg_write_raw_data	jWrtRawData
927
#define jpeg_write_raw_data	jWrtRawData
876
#define jpeg_write_marker	jWrtMarker
928
#define jpeg_write_marker	jWrtMarker
877
#define jpeg_write_m_header	jWrtMHeader
929
#define jpeg_write_m_header	jWrtMHeader
878
#define jpeg_write_m_byte	jWrtMByte
930
#define jpeg_write_m_byte	jWrtMByte
879
#define jpeg_write_tables	jWrtTables
931
#define jpeg_write_tables	jWrtTables
880
#define jpeg_read_header	jReadHeader
932
#define jpeg_read_header	jReadHeader
881
#define jpeg_start_decompress	jStrtDecompress
933
#define jpeg_start_decompress	jStrtDecompress
882
#define jpeg_read_scanlines	jReadScanlines
934
#define jpeg_read_scanlines	jReadScanlines
883
#define jpeg_finish_decompress	jFinDecompress
935
#define jpeg_finish_decompress	jFinDecompress
884
#define jpeg_read_raw_data	jReadRawData
936
#define jpeg_read_raw_data	jReadRawData
885
#define jpeg_has_multiple_scans	jHasMultScn
937
#define jpeg_has_multiple_scans	jHasMultScn
886
#define jpeg_start_output	jStrtOutput
938
#define jpeg_start_output	jStrtOutput
887
#define jpeg_finish_output	jFinOutput
939
#define jpeg_finish_output	jFinOutput
888
#define jpeg_input_complete	jInComplete
940
#define jpeg_input_complete	jInComplete
889
#define jpeg_new_colormap	jNewCMap
941
#define jpeg_new_colormap	jNewCMap
890
#define jpeg_consume_input	jConsumeInput
942
#define jpeg_consume_input	jConsumeInput
943
#if JPEG_LIB_VERSION >= 80
944
#define jpeg_core_output_dimensions	jCoreDimensions
945
#endif
891
#define jpeg_calc_output_dimensions	jCalcDimensions
946
#define jpeg_calc_output_dimensions	jCalcDimensions
892
#define jpeg_save_markers	jSaveMarkers
947
#define jpeg_save_markers	jSaveMarkers
893
#define jpeg_set_marker_processor	jSetMarker
948
#define jpeg_set_marker_processor	jSetMarker
894
#define jpeg_read_coefficients	jReadCoefs
949
#define jpeg_read_coefficients	jReadCoefs
895
#define jpeg_write_coefficients	jWrtCoefs
950
#define jpeg_write_coefficients	jWrtCoefs
896
#define jpeg_copy_critical_parameters	jCopyCrit
951
#define jpeg_copy_critical_parameters	jCopyCrit
897
#define jpeg_abort_compress	jAbrtCompress
952
#define jpeg_abort_compress	jAbrtCompress
898
#define jpeg_abort_decompress	jAbrtDecompress
953
#define jpeg_abort_decompress	jAbrtDecompress
899
#define jpeg_abort		jAbort
954
#define jpeg_abort		jAbort
900
#define jpeg_destroy		jDestroy
955
#define jpeg_destroy		jDestroy
901
#define jpeg_resync_to_restart	jResyncRestart
956
#define jpeg_resync_to_restart	jResyncRestart
902
#endif /* NEED_SHORT_EXTERNAL_NAMES */
957
#endif /* NEED_SHORT_EXTERNAL_NAMES */
903
958
904
#ifdef __cplusplus
905
extern "C" {
906
#endif
907
959
908
/* Default error-management setup */
960
/* Default error-management setup */
909
EXTERN(struct jpeg_error_mgr *) jpeg_std_error
961
EXTERN(struct jpeg_error_mgr *) jpeg_std_error
910
	JPP((struct jpeg_error_mgr * err));
962
	JPP((struct jpeg_error_mgr * err));
911
963
912
/* Initialization of JPEG compression objects.
964
/* Initialization of JPEG compression objects.
913
 * jpeg_create_compress() and jpeg_create_decompress() are the exported
965
 * jpeg_create_compress() and jpeg_create_decompress() are the exported
914
 * names that applications should call.  These expand to calls on
966
 * names that applications should call.  These expand to calls on
 Lines 930-956   EXTERN(void) jpeg_CreateDecompress JPP(( Link Here 
930
EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
982
EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
931
EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
983
EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
932
984
933
/* Standard data source and destination managers: stdio streams. */
985
/* Standard data source and destination managers: stdio streams. */
934
/* Caller is responsible for opening the file before and closing after. */
986
/* Caller is responsible for opening the file before and closing after. */
935
EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
987
EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
936
EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
988
EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
937
989
990
#if JPEG_LIB_VERSION >= 80
991
/* Data source and destination managers: memory buffers. */
992
EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo,
993
			       unsigned char ** outbuffer,
994
			       unsigned long * outsize));
995
EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo,
996
			      unsigned char * inbuffer,
997
			      unsigned long insize));
998
#endif
999
938
/* Default parameter setup for compression */
1000
/* Default parameter setup for compression */
939
EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
1001
EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
940
/* Compression parameter setup aids */
1002
/* Compression parameter setup aids */
941
EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
1003
EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
942
				      J_COLOR_SPACE colorspace));
1004
				      J_COLOR_SPACE colorspace));
943
EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
1005
EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
944
EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
1006
EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
945
				   boolean force_baseline));
1007
				   boolean force_baseline));
946
EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
1008
EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
947
					  int scale_factor,
1009
					  int scale_factor,
948
					  boolean force_baseline));
1010
					  boolean force_baseline));
1011
#if JPEG_LIB_VERSION >= 70
1012
EXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo,
1013
				       boolean force_baseline));
1014
#endif
949
EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
1015
EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
950
				       const unsigned int *basic_table,
1016
				       const unsigned int *basic_table,
951
				       int scale_factor,
1017
				       int scale_factor,
952
				       boolean force_baseline));
1018
				       boolean force_baseline));
953
EXTERN(int) jpeg_quality_scaling JPP((int quality));
1019
EXTERN(int) jpeg_quality_scaling JPP((int quality));
954
EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
1020
EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
955
EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
1021
EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
956
				       boolean suppress));
1022
				       boolean suppress));
 Lines 960-981   EXTERN(JHUFF_TBL *) jpeg_alloc_huff_tabl Link Here 
960
/* Main entry points for compression */
1026
/* Main entry points for compression */
961
EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
1027
EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
962
				      boolean write_all_tables));
1028
				      boolean write_all_tables));
963
EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
1029
EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
964
					     JSAMPARRAY scanlines,
1030
					     JSAMPARRAY scanlines,
965
					     JDIMENSION num_lines));
1031
					     JDIMENSION num_lines));
966
EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
1032
EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
967
1033
1034
#if JPEG_LIB_VERSION >= 70
1035
/* Precalculate JPEG dimensions for current compression parameters. */
1036
EXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo));
1037
#endif
1038
968
/* Replaces jpeg_write_scanlines when writing raw downsampled data. */
1039
/* Replaces jpeg_write_scanlines when writing raw downsampled data. */
969
EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
1040
EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
970
					    JSAMPIMAGE data,
1041
					    JSAMPIMAGE data,
971
					    JDIMENSION num_lines));
1042
					    JDIMENSION num_lines));
972
1043
973
/* Write a special marker.  See libjpeg.doc concerning safe usage. */
1044
/* Write a special marker.  See libjpeg.txt concerning safe usage. */
974
EXTERN(void) jpeg_write_marker
1045
EXTERN(void) jpeg_write_marker
975
	JPP((j_compress_ptr cinfo, int marker,
1046
	JPP((j_compress_ptr cinfo, int marker,
976
	     const JOCTET * dataptr, unsigned int datalen));
1047
	     const JOCTET * dataptr, unsigned int datalen));
977
/* Same, but piecemeal. */
1048
/* Same, but piecemeal. */
978
EXTERN(void) jpeg_write_m_header
1049
EXTERN(void) jpeg_write_m_header
979
	JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
1050
	JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
980
EXTERN(void) jpeg_write_m_byte
1051
EXTERN(void) jpeg_write_m_byte
981
	JPP((j_compress_ptr cinfo, int val));
1052
	JPP((j_compress_ptr cinfo, int val));
 Lines 1019-1034   EXTERN(int) jpeg_consume_input JPP((j_de Link Here 
1019
/* Return value is one of: */
1090
/* Return value is one of: */
1020
/* #define JPEG_SUSPENDED	0    Suspended due to lack of input data */
1091
/* #define JPEG_SUSPENDED	0    Suspended due to lack of input data */
1021
#define JPEG_REACHED_SOS	1 /* Reached start of new scan */
1092
#define JPEG_REACHED_SOS	1 /* Reached start of new scan */
1022
#define JPEG_REACHED_EOI	2 /* Reached end of image */
1093
#define JPEG_REACHED_EOI	2 /* Reached end of image */
1023
#define JPEG_ROW_COMPLETED	3 /* Completed one iMCU row */
1094
#define JPEG_ROW_COMPLETED	3 /* Completed one iMCU row */
1024
#define JPEG_SCAN_COMPLETED	4 /* Completed last iMCU row of a scan */
1095
#define JPEG_SCAN_COMPLETED	4 /* Completed last iMCU row of a scan */
1025
1096
1026
/* Precalculate output dimensions for current decompression parameters. */
1097
/* Precalculate output dimensions for current decompression parameters. */
1098
#if JPEG_LIB_VERSION >= 80
1099
EXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo));
1100
#endif
1027
EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
1101
EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
1028
1102
1029
/* Control saving of COM and APPn markers into marker_list. */
1103
/* Control saving of COM and APPn markers into marker_list. */
1030
EXTERN(void) jpeg_save_markers
1104
EXTERN(void) jpeg_save_markers
1031
	JPP((j_decompress_ptr cinfo, int marker_code,
1105
	JPP((j_decompress_ptr cinfo, int marker_code,
1032
	     unsigned int length_limit));
1106
	     unsigned int length_limit));
1033
1107
1034
/* Install a special processing method for COM or APPn markers. */
1108
/* Install a special processing method for COM or APPn markers. */
 Lines 1057-1075   EXTERN(void) jpeg_abort_decompress JPP(( Link Here 
1057
 */
1131
 */
1058
EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
1132
EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
1059
EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
1133
EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
1060
1134
1061
/* Default restart-marker-resync procedure for use by data source modules */
1135
/* Default restart-marker-resync procedure for use by data source modules */
1062
EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
1136
EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
1063
					    int desired));
1137
					    int desired));
1064
1138
1065
#ifdef __cplusplus
1066
} /* extern "C" */
1067
#endif /* __cplusplus */
1068
1139
1069
/* These marker codes are exported since applications and data source modules
1140
/* These marker codes are exported since applications and data source modules
1070
 * are likely to want to use them.
1141
 * are likely to want to use them.
1071
 */
1142
 */
1072
1143
1073
#define JPEG_RST0	0xD0	/* RST0 marker code */
1144
#define JPEG_RST0	0xD0	/* RST0 marker code */
1074
#define JPEG_EOI	0xD9	/* EOI marker code */
1145
#define JPEG_EOI	0xD9	/* EOI marker code */
1075
#define JPEG_APP0	0xE0	/* APP0 marker code */
1146
#define JPEG_APP0	0xE0	/* APP0 marker code */
 Lines 1116-1124   struct jpeg_color_quantizer { long dummy Link Here 
1116
 * to include jerror.h.
1187
 * to include jerror.h.
1117
 */
1188
 */
1118
1189
1119
#ifdef JPEG_INTERNALS
1190
#ifdef JPEG_INTERNALS
1120
#include "jpegint.h"		/* fetch private declarations */
1191
#include "jpegint.h"		/* fetch private declarations */
1121
#include "jerror.h"		/* fetch error codes too */
1192
#include "jerror.h"		/* fetch error codes too */
1122
#endif
1193
#endif
1123
1194
1195
#ifdef __cplusplus
1196
#ifndef DONT_USE_EXTERN_C
1197
}
1198
#endif
1199
#endif
1200
1124
#endif /* JPEGLIB_H */
1201
#endif /* JPEGLIB_H */
(-)a/jpeg/jquant1.c (-1 / +5 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jquant1.c
2
 * jquant1.c
3
 *
3
 *
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
5
 * Copyright (C) 2009, D. R. Commander
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains 1-pass color quantization (color mapping) routines.
9
 * This file contains 1-pass color quantization (color mapping) routines.
9
 * These routines provide mapping to a fixed color map using equally spaced
10
 * These routines provide mapping to a fixed color map using equally spaced
10
 * color values.  Optional Floyd-Steinberg or ordered dithering is available.
11
 * color values.  Optional Floyd-Steinberg or ordered dithering is available.
11
 */
12
 */
12
13
 Lines 188-204   select_ncolors (j_decompress_ptr cinfo, Link Here 
188
/* and fill in Ncolors[] array to indicate choice. */
189
/* and fill in Ncolors[] array to indicate choice. */
189
/* Return value is total number of colors (product of Ncolors[] values). */
190
/* Return value is total number of colors (product of Ncolors[] values). */
190
{
191
{
191
  int nc = cinfo->out_color_components; /* number of color components */
192
  int nc = cinfo->out_color_components; /* number of color components */
192
  int max_colors = cinfo->desired_number_of_colors;
193
  int max_colors = cinfo->desired_number_of_colors;
193
  int total_colors, iroot, i, j;
194
  int total_colors, iroot, i, j;
194
  boolean changed;
195
  boolean changed;
195
  long temp;
196
  long temp;
196
  static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
197
  int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
198
  RGB_order[0] = rgb_green[cinfo->out_color_space];
199
  RGB_order[1] = rgb_red[cinfo->out_color_space];
200
  RGB_order[2] = rgb_blue[cinfo->out_color_space];
197
201
198
  /* We can allocate at least the nc'th root of max_colors per component. */
202
  /* We can allocate at least the nc'th root of max_colors per component. */
199
  /* Compute floor(nc'th root of max_colors). */
203
  /* Compute floor(nc'th root of max_colors). */
200
  iroot = 1;
204
  iroot = 1;
201
  do {
205
  do {
202
    iroot++;
206
    iroot++;
203
    temp = iroot;		/* set temp = iroot ** nc */
207
    temp = iroot;		/* set temp = iroot ** nc */
204
    for (i = 1; i < nc; i++)
208
    for (i = 1; i < nc; i++)
(-)a/jpeg/jquant2.c (-32 / +15 lines)
Line     Link Here 
 Lines 1-12    Link Here 
1
/*
1
/*
2
 * jquant2.c
2
 * jquant2.c
3
 *
3
 *
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
4
 * Copyright (C) 1991-1996, Thomas G. Lane.
5
 * Copyright (C) 2009, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains 2-pass color quantization (color mapping) routines.
9
 * This file contains 2-pass color quantization (color mapping) routines.
9
 * These routines provide selection of a custom color map for an image,
10
 * These routines provide selection of a custom color map for an image,
10
 * followed by mapping of the image to that color map, with optional
11
 * followed by mapping of the image to that color map, with optional
11
 * Floyd-Steinberg dithering.
12
 * Floyd-Steinberg dithering.
12
 * It is also possible to use just the second pass to map to an arbitrary
13
 * It is also possible to use just the second pass to map to an arbitrary
 Lines 69-107    Link Here 
69
 * If you want to use this code to quantize a non-RGB color space, you'll
70
 * If you want to use this code to quantize a non-RGB color space, you'll
70
 * probably need to change these scale factors.
71
 * probably need to change these scale factors.
71
 */
72
 */
72
73
73
#define R_SCALE 2		/* scale R distances by this much */
74
#define R_SCALE 2		/* scale R distances by this much */
74
#define G_SCALE 3		/* scale G distances by this much */
75
#define G_SCALE 3		/* scale G distances by this much */
75
#define B_SCALE 1		/* and B by this much */
76
#define B_SCALE 1		/* and B by this much */
76
77
77
/* Relabel R/G/B as components 0/1/2, respecting the RGB ordering defined
78
static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
78
 * in jmorecfg.h.  As the code stands, it will do the right thing for R,G,B
79
#define C0_SCALE c_scales[rgb_red[cinfo->out_color_space]]
79
 * and B,G,R orders.  If you define some other weird order in jmorecfg.h,
80
#define C1_SCALE c_scales[rgb_green[cinfo->out_color_space]]
80
 * you'll get compile errors until you extend this logic.  In that case
81
#define C2_SCALE c_scales[rgb_blue[cinfo->out_color_space]]
81
 * you'll probably want to tweak the histogram sizes too.
82
 */
83
84
#if RGB_RED == 0
85
#define C0_SCALE R_SCALE
86
#endif
87
#if RGB_BLUE == 0
88
#define C0_SCALE B_SCALE
89
#endif
90
#if RGB_GREEN == 1
91
#define C1_SCALE G_SCALE
92
#endif
93
#if RGB_RED == 2
94
#define C2_SCALE R_SCALE
95
#endif
96
#if RGB_BLUE == 2
97
#define C2_SCALE B_SCALE
98
#endif
99
100
82
101
/*
83
/*
102
 * First we have the histogram data structure and routines for creating it.
84
 * First we have the histogram data structure and routines for creating it.
103
 *
85
 *
104
 * The number of bits of precision can be adjusted by changing these symbols.
86
 * The number of bits of precision can be adjusted by changing these symbols.
105
 * We recommend keeping 6 bits for G and 5 each for R and B.
87
 * We recommend keeping 6 bits for G and 5 each for R and B.
106
 * If you have plenty of memory and cycles, 6 bits all around gives marginally
88
 * If you have plenty of memory and cycles, 6 bits all around gives marginally
107
 * better results; if you are short of memory, 5 bits all around will save
89
 * better results; if you are short of memory, 5 bits all around will save
 Lines 449-473   median_cut (j_decompress_ptr cinfo, boxp Link Here 
449
     * See notes in update_box about scaling distances.
431
     * See notes in update_box about scaling distances.
450
     */
432
     */
451
    c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
433
    c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
452
    c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
434
    c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
453
    c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
435
    c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
454
    /* We want to break any ties in favor of green, then red, blue last.
436
    /* We want to break any ties in favor of green, then red, blue last.
455
     * This code does the right thing for R,G,B or B,G,R color orders only.
437
     * This code does the right thing for R,G,B or B,G,R color orders only.
456
     */
438
     */
457
#if RGB_RED == 0
439
    if (rgb_red[cinfo->out_color_space] == 0) {
458
    cmax = c1; n = 1;
440
      cmax = c1; n = 1;
459
    if (c0 > cmax) { cmax = c0; n = 0; }
441
      if (c0 > cmax) { cmax = c0; n = 0; }
460
    if (c2 > cmax) { n = 2; }
442
      if (c2 > cmax) { n = 2; }
461
#else
443
    }
462
    cmax = c1; n = 1;
444
    else {
463
    if (c2 > cmax) { cmax = c2; n = 2; }
445
      cmax = c1; n = 1;
464
    if (c0 > cmax) { n = 0; }
446
      if (c2 > cmax) { cmax = c2; n = 2; }
465
#endif
447
      if (c0 > cmax) { n = 0; }
448
    }
466
    /* Choose split point along selected axis, and update box bounds.
449
    /* Choose split point along selected axis, and update box bounds.
467
     * Current algorithm: split at halfway point.
450
     * Current algorithm: split at halfway point.
468
     * (Since the box has been shrunk to minimum volume,
451
     * (Since the box has been shrunk to minimum volume,
469
     * any split will produce two nonempty subboxes.)
452
     * any split will produce two nonempty subboxes.)
470
     * Note that lb value is max for lower box, so must be < old max.
453
     * Note that lb value is max for lower box, so must be < old max.
471
     */
454
     */
472
    switch (n) {
455
    switch (n) {
473
    case 0:
456
    case 0:
(-)a/jpeg/jsimd.h (+90 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * jsimd.h
3
 *
4
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
 * 
6
 * Based on the x86 SIMD extension for IJG JPEG library,
7
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
8
 * For conditions of distribution and use, see copyright notice in jsimdext.inc
9
 *
10
 */
11
12
/* Short forms of external names for systems with brain-damaged linkers. */
13
14
#ifdef NEED_SHORT_EXTERNAL_NAMES
15
#define jsimd_can_rgb_ycc                 jSCanRgbYcc
16
#define jsimd_can_ycc_rgb                 jSCanYccRgb
17
#define jsimd_rgb_ycc_convert             jSRgbYccConv
18
#define jsimd_ycc_rgb_convert             jSYccRgbConv
19
#define jsimd_can_h2v2_downsample         jSCanH2V2Down
20
#define jsimd_can_h2v1_downsample         jSCanH2V1Down
21
#define jsimd_h2v2_downsample             jSH2V2Down
22
#define jsimd_h2v1_downsample             jSH2V1Down
23
#define jsimd_can_h2v2_upsample           jSCanH2V2Up
24
#define jsimd_can_h2v1_upsample           jSCanH2V1Up
25
#define jsimd_h2v2_upsample               jSH2V2Up
26
#define jsimd_h2v1_upsample               jSH2V1Up
27
#define jsimd_can_h2v2_fancy_upsample     jSCanH2V2FUp
28
#define jsimd_can_h2v1_fancy_upsample     jSCanH2V1FUp
29
#define jsimd_h2v2_fancy_upsample         jSH2V2FUp
30
#define jsimd_h2v1_fancy_upsample         jSH2V1FUp
31
#define jsimd_can_h2v2_merged_upsample    jSCanH2V2MUp
32
#define jsimd_can_h2v1_merged_upsample    jSCanH2V1MUp
33
#define jsimd_h2v2_merged_upsample        jSH2V2MUp
34
#define jsimd_h2v1_merged_upsample        jSH2V1MUp
35
#endif /* NEED_SHORT_EXTERNAL_NAMES */
36
37
EXTERN(int) jsimd_can_rgb_ycc JPP((void));
38
EXTERN(int) jsimd_can_ycc_rgb JPP((void));
39
40
EXTERN(void) jsimd_rgb_ycc_convert
41
        JPP((j_compress_ptr cinfo,
42
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
43
             JDIMENSION output_row, int num_rows));
44
EXTERN(void) jsimd_ycc_rgb_convert
45
        JPP((j_decompress_ptr cinfo,
46
             JSAMPIMAGE input_buf, JDIMENSION input_row,
47
             JSAMPARRAY output_buf, int num_rows));
48
49
EXTERN(int) jsimd_can_h2v2_downsample JPP((void));
50
EXTERN(int) jsimd_can_h2v1_downsample JPP((void));
51
52
EXTERN(void) jsimd_h2v2_downsample
53
        JPP((j_compress_ptr cinfo, jpeg_component_info * compptr,
54
             JSAMPARRAY input_data, JSAMPARRAY output_data));
55
EXTERN(void) jsimd_h2v1_downsample
56
        JPP((j_compress_ptr cinfo, jpeg_component_info * compptr,
57
             JSAMPARRAY input_data, JSAMPARRAY output_data));
58
59
EXTERN(int) jsimd_can_h2v2_upsample JPP((void));
60
EXTERN(int) jsimd_can_h2v1_upsample JPP((void));
61
62
EXTERN(void) jsimd_h2v2_upsample
63
        JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
64
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
65
EXTERN(void) jsimd_h2v1_upsample
66
        JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
67
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
68
69
EXTERN(int) jsimd_can_h2v2_fancy_upsample JPP((void));
70
EXTERN(int) jsimd_can_h2v1_fancy_upsample JPP((void));
71
72
EXTERN(void) jsimd_h2v2_fancy_upsample
73
        JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
74
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
75
EXTERN(void) jsimd_h2v1_fancy_upsample
76
        JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
77
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
78
79
EXTERN(int) jsimd_can_h2v2_merged_upsample JPP((void));
80
EXTERN(int) jsimd_can_h2v1_merged_upsample JPP((void));
81
82
EXTERN(void) jsimd_h2v2_merged_upsample
83
        JPP((j_decompress_ptr cinfo,
84
             JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
85
             JSAMPARRAY output_buf));
86
EXTERN(void) jsimd_h2v1_merged_upsample
87
        JPP((j_decompress_ptr cinfo,
88
             JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
89
             JSAMPARRAY output_buf));
90
(-)a/jpeg/jsimd_none.c (+300 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * jsimd_none.c
3
 *
4
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
 * Copyright 2009 D. R. Commander
6
 * 
7
 * Based on the x86 SIMD extension for IJG JPEG library,
8
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
9
 * For conditions of distribution and use, see copyright notice in jsimdext.inc
10
 *
11
 * This file contains stubs for when there is no SIMD support available.
12
 */
13
14
#define JPEG_INTERNALS
15
#include "jinclude.h"
16
#include "jpeglib.h"
17
#include "jsimd.h"
18
#include "jdct.h"
19
#include "jsimddct.h"
20
21
GLOBAL(int)
22
jsimd_can_rgb_ycc (void)
23
{
24
  return 0;
25
}
26
27
GLOBAL(int)
28
jsimd_can_ycc_rgb (void)
29
{
30
  return 0;
31
}
32
33
GLOBAL(void)
34
jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
35
                       JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
36
                       JDIMENSION output_row, int num_rows)
37
{
38
}
39
40
GLOBAL(void)
41
jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
42
                       JSAMPIMAGE input_buf, JDIMENSION input_row,
43
                       JSAMPARRAY output_buf, int num_rows)
44
{
45
}
46
47
GLOBAL(int)
48
jsimd_can_h2v2_downsample (void)
49
{
50
  return 0;
51
}
52
53
GLOBAL(int)
54
jsimd_can_h2v1_downsample (void)
55
{
56
  return 0;
57
}
58
59
GLOBAL(void)
60
jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
61
                       JSAMPARRAY input_data, JSAMPARRAY output_data)
62
{
63
}
64
65
GLOBAL(void)
66
jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
67
                       JSAMPARRAY input_data, JSAMPARRAY output_data)
68
{
69
}
70
71
GLOBAL(int)
72
jsimd_can_h2v2_upsample (void)
73
{
74
  return 0;
75
}
76
77
GLOBAL(int)
78
jsimd_can_h2v1_upsample (void)
79
{
80
  return 0;
81
}
82
83
GLOBAL(void)
84
jsimd_h2v2_upsample (j_decompress_ptr cinfo,
85
                     jpeg_component_info * compptr, 
86
                     JSAMPARRAY input_data,
87
                     JSAMPARRAY * output_data_ptr)
88
{
89
}
90
91
GLOBAL(void)
92
jsimd_h2v1_upsample (j_decompress_ptr cinfo,
93
                     jpeg_component_info * compptr, 
94
                     JSAMPARRAY input_data,
95
                     JSAMPARRAY * output_data_ptr)
96
{
97
}
98
99
GLOBAL(int)
100
jsimd_can_h2v2_fancy_upsample (void)
101
{
102
  return 0;
103
}
104
105
GLOBAL(int)
106
jsimd_can_h2v1_fancy_upsample (void)
107
{
108
  return 0;
109
}
110
111
GLOBAL(void)
112
jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
113
                           jpeg_component_info * compptr, 
114
                           JSAMPARRAY input_data,
115
                           JSAMPARRAY * output_data_ptr)
116
{
117
}
118
119
GLOBAL(void)
120
jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
121
                           jpeg_component_info * compptr, 
122
                           JSAMPARRAY input_data,
123
                           JSAMPARRAY * output_data_ptr)
124
{
125
}
126
127
GLOBAL(int)
128
jsimd_can_h2v2_merged_upsample (void)
129
{
130
  return 0;
131
}
132
133
GLOBAL(int)
134
jsimd_can_h2v1_merged_upsample (void)
135
{
136
  return 0;
137
}
138
139
GLOBAL(void)
140
jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
141
                            JSAMPIMAGE input_buf,
142
                            JDIMENSION in_row_group_ctr,
143
                            JSAMPARRAY output_buf)
144
{
145
}
146
147
GLOBAL(void)
148
jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
149
                            JSAMPIMAGE input_buf,
150
                            JDIMENSION in_row_group_ctr,
151
                            JSAMPARRAY output_buf)
152
{
153
}
154
155
GLOBAL(int)
156
jsimd_can_convsamp (void)
157
{
158
  return 0;
159
}
160
161
GLOBAL(int)
162
jsimd_can_convsamp_float (void)
163
{
164
  return 0;
165
}
166
167
GLOBAL(void)
168
jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
169
                DCTELEM * workspace)
170
{
171
}
172
173
GLOBAL(void)
174
jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
175
                      FAST_FLOAT * workspace)
176
{
177
}
178
179
GLOBAL(int)
180
jsimd_can_fdct_islow (void)
181
{
182
  return 0;
183
}
184
185
GLOBAL(int)
186
jsimd_can_fdct_ifast (void)
187
{
188
  return 0;
189
}
190
191
GLOBAL(int)
192
jsimd_can_fdct_float (void)
193
{
194
  return 0;
195
}
196
197
GLOBAL(void)
198
jsimd_fdct_islow (DCTELEM * data)
199
{
200
}
201
202
GLOBAL(void)
203
jsimd_fdct_ifast (DCTELEM * data)
204
{
205
}
206
207
GLOBAL(void)
208
jsimd_fdct_float (FAST_FLOAT * data)
209
{
210
}
211
212
GLOBAL(int)
213
jsimd_can_quantize (void)
214
{
215
  return 0;
216
}
217
218
GLOBAL(int)
219
jsimd_can_quantize_float (void)
220
{
221
  return 0;
222
}
223
224
GLOBAL(void)
225
jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
226
                DCTELEM * workspace)
227
{
228
}
229
230
GLOBAL(void)
231
jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
232
                      FAST_FLOAT * workspace)
233
{
234
}
235
236
GLOBAL(int)
237
jsimd_can_idct_2x2 (void)
238
{
239
  return 0;
240
}
241
242
GLOBAL(int)
243
jsimd_can_idct_4x4 (void)
244
{
245
  return 0;
246
}
247
248
GLOBAL(void)
249
jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
250
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
251
                JDIMENSION output_col)
252
{
253
}
254
255
GLOBAL(void)
256
jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
257
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
258
                JDIMENSION output_col)
259
{
260
}
261
262
GLOBAL(int)
263
jsimd_can_idct_islow (void)
264
{
265
  return 0;
266
}
267
268
GLOBAL(int)
269
jsimd_can_idct_ifast (void)
270
{
271
  return 0;
272
}
273
274
GLOBAL(int)
275
jsimd_can_idct_float (void)
276
{
277
  return 0;
278
}
279
280
GLOBAL(void)
281
jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
282
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
283
                JDIMENSION output_col)
284
{
285
}
286
287
GLOBAL(void)
288
jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
289
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
290
                JDIMENSION output_col)
291
{
292
}
293
294
GLOBAL(void)
295
jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
296
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
297
                JDIMENSION output_col)
298
{
299
}
300
(-)a/jpeg/jsimddct.h (+102 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * jsimddct.h
3
 *
4
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
 * 
6
 * Based on the x86 SIMD extension for IJG JPEG library,
7
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
8
 * For conditions of distribution and use, see copyright notice in jsimdext.inc
9
 *
10
 */
11
12
/* Short forms of external names for systems with brain-damaged linkers. */
13
14
#ifdef NEED_SHORT_EXTERNAL_NAMES
15
#define jsimd_can_convsamp                jSCanConv
16
#define jsimd_can_convsamp_float          jSCanConvF
17
#define jsimd_convsamp                    jSConv
18
#define jsimd_convsamp_float              jSConvF
19
#define jsimd_can_fdct_islow              jSCanFDCTIS
20
#define jsimd_can_fdct_ifast              jSCanFDCTIF
21
#define jsimd_can_fdct_float              jSCanFDCTFl
22
#define jsimd_fdct_islow                  jSFDCTIS
23
#define jsimd_fdct_ifast                  jSFDCTIF
24
#define jsimd_fdct_float                  jSFDCTFl
25
#define jsimd_can_quantize                jSCanQuant
26
#define jsimd_can_quantize_float          jSCanQuantF
27
#define jsimd_quantize                    jSQuant
28
#define jsimd_quantize_float              jSQuantF
29
#define jsimd_can_idct_2x2                jSCanIDCT22
30
#define jsimd_can_idct_4x4                jSCanIDCT44
31
#define jsimd_idct_2x2                    jSIDCT22
32
#define jsimd_idct_4x4                    jSIDCT44
33
#define jsimd_can_idct_islow              jSCanIDCTIS
34
#define jsimd_can_idct_ifast              jSCanIDCTIF
35
#define jsimd_can_idct_float              jSCanIDCTFl
36
#define jsimd_idct_islow                  jSIDCTIS
37
#define jsimd_idct_ifast                  jSIDCTIF
38
#define jsimd_idct_float                  jSIDCTFl
39
#endif /* NEED_SHORT_EXTERNAL_NAMES */
40
41
EXTERN(int) jsimd_can_convsamp JPP((void));
42
EXTERN(int) jsimd_can_convsamp_float JPP((void));
43
44
EXTERN(void) jsimd_convsamp JPP((JSAMPARRAY sample_data,
45
                                 JDIMENSION start_col,
46
                                 DCTELEM * workspace));
47
EXTERN(void) jsimd_convsamp_float JPP((JSAMPARRAY sample_data,
48
                                       JDIMENSION start_col,
49
                                       FAST_FLOAT * workspace));
50
51
EXTERN(int) jsimd_can_fdct_islow JPP((void));
52
EXTERN(int) jsimd_can_fdct_ifast JPP((void));
53
EXTERN(int) jsimd_can_fdct_float JPP((void));
54
55
EXTERN(void) jsimd_fdct_islow JPP((DCTELEM * data));
56
EXTERN(void) jsimd_fdct_ifast JPP((DCTELEM * data));
57
EXTERN(void) jsimd_fdct_float JPP((FAST_FLOAT * data));
58
59
EXTERN(int) jsimd_can_quantize JPP((void));
60
EXTERN(int) jsimd_can_quantize_float JPP((void));
61
62
EXTERN(void) jsimd_quantize JPP((JCOEFPTR coef_block,
63
                                 DCTELEM * divisors,
64
                                 DCTELEM * workspace));
65
EXTERN(void) jsimd_quantize_float JPP((JCOEFPTR coef_block,
66
                                       FAST_FLOAT * divisors,
67
                                       FAST_FLOAT * workspace));
68
69
EXTERN(int) jsimd_can_idct_2x2 JPP((void));
70
EXTERN(int) jsimd_can_idct_4x4 JPP((void));
71
72
EXTERN(void) jsimd_idct_2x2 JPP((j_decompress_ptr cinfo,
73
                                 jpeg_component_info * compptr,
74
                                 JCOEFPTR coef_block,
75
                                 JSAMPARRAY output_buf,
76
                                 JDIMENSION output_col));
77
EXTERN(void) jsimd_idct_4x4 JPP((j_decompress_ptr cinfo,
78
                                 jpeg_component_info * compptr,
79
                                 JCOEFPTR coef_block,
80
                                 JSAMPARRAY output_buf,
81
                                 JDIMENSION output_col));
82
83
EXTERN(int) jsimd_can_idct_islow JPP((void));
84
EXTERN(int) jsimd_can_idct_ifast JPP((void));
85
EXTERN(int) jsimd_can_idct_float JPP((void));
86
87
EXTERN(void) jsimd_idct_islow JPP((j_decompress_ptr cinfo,
88
                                   jpeg_component_info * compptr,
89
                                   JCOEFPTR coef_block,
90
                                   JSAMPARRAY output_buf,
91
                                   JDIMENSION output_col));
92
EXTERN(void) jsimd_idct_ifast JPP((j_decompress_ptr cinfo,
93
                                   jpeg_component_info * compptr,
94
                                   JCOEFPTR coef_block,
95
                                   JSAMPARRAY output_buf,
96
                                   JDIMENSION output_col));
97
EXTERN(void) jsimd_idct_float JPP((j_decompress_ptr cinfo,
98
                                   jpeg_component_info * compptr,
99
                                   JCOEFPTR coef_block,
100
                                   JSAMPARRAY output_buf,
101
                                   JDIMENSION output_col));
102
(-)a/jpeg/jutils.c (-2 / +2 lines)
Line     Link Here 
 Lines 72-89   GLOBAL(long) Link Here 
72
jdiv_round_up (long a, long b)
72
jdiv_round_up (long a, long b)
73
/* Compute a/b rounded up to next integer, ie, ceil(a/b) */
73
/* Compute a/b rounded up to next integer, ie, ceil(a/b) */
74
/* Assumes a >= 0, b > 0 */
74
/* Assumes a >= 0, b > 0 */
75
{
75
{
76
  return (a + b - 1L) / b;
76
  return (a + b - 1L) / b;
77
}
77
}
78
78
79
79
80
GLOBAL(long)
80
GLOBAL(size_t)
81
jround_up (long a, long b)
81
jround_up (size_t a, size_t b)
82
/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
82
/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
83
/* Assumes a >= 0, b > 0 */
83
/* Assumes a >= 0, b > 0 */
84
{
84
{
85
  a += b - 1L;
85
  a += b - 1L;
86
  return a - (a % b);
86
  return a - (a % b);
87
}
87
}
88
88
89
89
(-)a/jpeg/jversion.h (-1 / +24 lines)
Line     Link Here 
 Lines 1-14    Link Here 
1
/*
1
/*
2
 * jversion.h
2
 * jversion.h
3
 *
3
 *
4
 * Copyright (C) 1991-1998, Thomas G. Lane.
4
 * Copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding.
5
 * Copyright (C) 2010, D. R. Commander.
5
 * This file is part of the Independent JPEG Group's software.
6
 * This file is part of the Independent JPEG Group's software.
6
 * For conditions of distribution and use, see the accompanying README file.
7
 * For conditions of distribution and use, see the accompanying README file.
7
 *
8
 *
8
 * This file contains software version identification.
9
 * This file contains software version identification.
9
 */
10
 */
10
11
11
12
13
#if JPEG_LIB_VERSION >= 80
14
15
#define JVERSION	"8b  16-May-2010"
16
17
#define JCOPYRIGHT	"Copyright (C) 2010, Thomas G. Lane, Guido Vollbeding"
18
19
#elif JPEG_LIB_VERSION >= 70
20
21
#define JVERSION        "7  27-Jun-2009"
22
23
#define JCOPYRIGHT      "Copyright (C) 2009, Thomas G. Lane, Guido Vollbeding"
24
25
#else
26
12
#define JVERSION	"6b  27-Mar-1998"
27
#define JVERSION	"6b  27-Mar-1998"
13
28
14
#define JCOPYRIGHT	"Copyright (C) 1998, Thomas G. Lane"
29
#define JCOPYRIGHT	"Copyright (C) 1998, Thomas G. Lane"
30
31
#endif
32
33
#define LJTCOPYRIGHT	"Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
34
			"Copyright (C) 2004 Landmark Graphics Corporation\n" \
35
			"Copyright (C) 2005-2007 Sun Microsystems, Inc.\n" \
36
			"Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \
37
			"Copyright (C) 2009-2011 D. R. Commander"
(-)a/jpeg/jwinfig.h (-48 lines)
Line     Link Here 
 Lines 1-48    Link Here 
1
/* jconfig.mc6 --- jconfig.h for Microsoft C on MS-DOS, version 6.00A & up. */
2
/* see jconfig.doc for explanations */
3
4
/* this is a hack */
5
#define HAVE_BOOLEAN
6
#ifndef __RPCNDR_H__
7
typedef unsigned char boolean;
8
#endif
9
10
#define HAVE_PROTOTYPES
11
#define HAVE_UNSIGNED_CHAR
12
#define HAVE_UNSIGNED_SHORT
13
/* #define void char */
14
/* #define const */
15
#undef CHAR_IS_UNSIGNED
16
#define HAVE_STDDEF_H
17
#define HAVE_STDLIB_H
18
#undef NEED_BSD_STRINGS
19
#undef NEED_SYS_TYPES_H
20
#undef NEED_FAR_POINTERS	/* for small or medium memory model */
21
#undef NEED_SHORT_EXTERNAL_NAMES
22
#undef INCOMPLETE_TYPES_BROKEN
23
24
#ifdef JPEG_INTERNALS
25
26
#undef RIGHT_SHIFT_IS_UNSIGNED
27
28
#define USE_MSDOS_MEMANSI
29
30
#define MAX_ALLOC_CHUNK 65520L	/* Maximum request to malloc() */
31
32
#endif /* JPEG_INTERNALS */
33
34
#ifdef JPEG_CJPEG_DJPEG
35
36
#define BMP_SUPPORTED		/* BMP image file format */
37
#define GIF_SUPPORTED		/* GIF image file format */
38
#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
39
#undef RLE_SUPPORTED		/* Utah RLE image file format */
40
#define TARGA_SUPPORTED		/* Targa image file format */
41
42
#define TWO_FILE_COMMANDLINE
43
#define USE_SETMODE		/* Microsoft has setmode() */
44
#define NEED_SIGNAL_CATCHER	/* Define this if you use jmemdos.c */
45
#undef DONT_USE_B_MODE
46
#undef PROGRESS_REPORT		/* optional */
47
48
#endif /* JPEG_CJPEG_DJPEG */
(-)a/jpeg/libjpeg.doc (-3006 lines)
Line     Link Here 
 Lines 1-3006    Link Here 
1
USING THE IJG JPEG LIBRARY
2
3
Copyright (C) 1994-1998, Thomas G. Lane.
4
This file is part of the Independent JPEG Group's software.
5
For conditions of distribution and use, see the accompanying README file.
6
7
8
This file describes how to use the IJG JPEG library within an application
9
program.  Read it if you want to write a program that uses the library.
10
11
The file example.c provides heavily commented skeleton code for calling the
12
JPEG library.  Also see jpeglib.h (the include file to be used by application
13
programs) for full details about data structures and function parameter lists.
14
The library source code, of course, is the ultimate reference.
15
16
Note that there have been *major* changes from the application interface
17
presented by IJG version 4 and earlier versions.  The old design had several
18
inherent limitations, and it had accumulated a lot of cruft as we added
19
features while trying to minimize application-interface changes.  We have
20
sacrificed backward compatibility in the version 5 rewrite, but we think the
21
improvements justify this.
22
23
24
TABLE OF CONTENTS
25
-----------------
26
27
Overview:
28
	Functions provided by the library
29
	Outline of typical usage
30
Basic library usage:
31
	Data formats
32
	Compression details
33
	Decompression details
34
	Mechanics of usage: include files, linking, etc
35
Advanced features:
36
	Compression parameter selection
37
	Decompression parameter selection
38
	Special color spaces
39
	Error handling
40
	Compressed data handling (source and destination managers)
41
	I/O suspension
42
	Progressive JPEG support
43
	Buffered-image mode
44
	Abbreviated datastreams and multiple images
45
	Special markers
46
	Raw (downsampled) image data
47
	Really raw data: DCT coefficients
48
	Progress monitoring
49
	Memory management
50
	Memory usage
51
	Library compile-time options
52
	Portability considerations
53
	Notes for MS-DOS implementors
54
55
You should read at least the overview and basic usage sections before trying
56
to program with the library.  The sections on advanced features can be read
57
if and when you need them.
58
59
60
OVERVIEW
61
========
62
63
Functions provided by the library
64
---------------------------------
65
66
The IJG JPEG library provides C code to read and write JPEG-compressed image
67
files.  The surrounding application program receives or supplies image data a
68
scanline at a time, using a straightforward uncompressed image format.  All
69
details of color conversion and other preprocessing/postprocessing can be
70
handled by the library.
71
72
The library includes a substantial amount of code that is not covered by the
73
JPEG standard but is necessary for typical applications of JPEG.  These
74
functions preprocess the image before JPEG compression or postprocess it after
75
decompression.  They include colorspace conversion, downsampling/upsampling,
76
and color quantization.  The application indirectly selects use of this code
77
by specifying the format in which it wishes to supply or receive image data.
78
For example, if colormapped output is requested, then the decompression
79
library automatically invokes color quantization.
80
81
A wide range of quality vs. speed tradeoffs are possible in JPEG processing,
82
and even more so in decompression postprocessing.  The decompression library
83
provides multiple implementations that cover most of the useful tradeoffs,
84
ranging from very-high-quality down to fast-preview operation.  On the
85
compression side we have generally not provided low-quality choices, since
86
compression is normally less time-critical.  It should be understood that the
87
low-quality modes may not meet the JPEG standard's accuracy requirements;
88
nonetheless, they are useful for viewers.
89
90
A word about functions *not* provided by the library.  We handle a subset of
91
the ISO JPEG standard; most baseline, extended-sequential, and progressive
92
JPEG processes are supported.  (Our subset includes all features now in common
93
use.)  Unsupported ISO options include:
94
	* Hierarchical storage
95
	* Lossless JPEG
96
	* Arithmetic entropy coding (unsupported for legal reasons)
97
	* DNL marker
98
	* Nonintegral subsampling ratios
99
We support both 8- and 12-bit data precision, but this is a compile-time
100
choice rather than a run-time choice; hence it is difficult to use both
101
precisions in a single application.
102
103
By itself, the library handles only interchange JPEG datastreams --- in
104
particular the widely used JFIF file format.  The library can be used by
105
surrounding code to process interchange or abbreviated JPEG datastreams that
106
are embedded in more complex file formats.  (For example, this library is
107
used by the free LIBTIFF library to support JPEG compression in TIFF.)
108
109
110
Outline of typical usage
111
------------------------
112
113
The rough outline of a JPEG compression operation is:
114
115
	Allocate and initialize a JPEG compression object
116
	Specify the destination for the compressed data (eg, a file)
117
	Set parameters for compression, including image size & colorspace
118
	jpeg_start_compress(...);
119
	while (scan lines remain to be written)
120
		jpeg_write_scanlines(...);
121
	jpeg_finish_compress(...);
122
	Release the JPEG compression object
123
124
A JPEG compression object holds parameters and working state for the JPEG
125
library.  We make creation/destruction of the object separate from starting
126
or finishing compression of an image; the same object can be re-used for a
127
series of image compression operations.  This makes it easy to re-use the
128
same parameter settings for a sequence of images.  Re-use of a JPEG object
129
also has important implications for processing abbreviated JPEG datastreams,
130
as discussed later.
131
132
The image data to be compressed is supplied to jpeg_write_scanlines() from
133
in-memory buffers.  If the application is doing file-to-file compression,
134
reading image data from the source file is the application's responsibility.
135
The library emits compressed data by calling a "data destination manager",
136
which typically will write the data into a file; but the application can
137
provide its own destination manager to do something else.
138
139
Similarly, the rough outline of a JPEG decompression operation is:
140
141
	Allocate and initialize a JPEG decompression object
142
	Specify the source of the compressed data (eg, a file)
143
	Call jpeg_read_header() to obtain image info
144
	Set parameters for decompression
145
	jpeg_start_decompress(...);
146
	while (scan lines remain to be read)
147
		jpeg_read_scanlines(...);
148
	jpeg_finish_decompress(...);
149
	Release the JPEG decompression object
150
151
This is comparable to the compression outline except that reading the
152
datastream header is a separate step.  This is helpful because information
153
about the image's size, colorspace, etc is available when the application
154
selects decompression parameters.  For example, the application can choose an
155
output scaling ratio that will fit the image into the available screen size.
156
157
The decompression library obtains compressed data by calling a data source
158
manager, which typically will read the data from a file; but other behaviors
159
can be obtained with a custom source manager.  Decompressed data is delivered
160
into in-memory buffers passed to jpeg_read_scanlines().
161
162
It is possible to abort an incomplete compression or decompression operation
163
by calling jpeg_abort(); or, if you do not need to retain the JPEG object,
164
simply release it by calling jpeg_destroy().
165
166
JPEG compression and decompression objects are two separate struct types.
167
However, they share some common fields, and certain routines such as
168
jpeg_destroy() can work on either type of object.
169
170
The JPEG library has no static variables: all state is in the compression
171
or decompression object.  Therefore it is possible to process multiple
172
compression and decompression operations concurrently, using multiple JPEG
173
objects.
174
175
Both compression and decompression can be done in an incremental memory-to-
176
memory fashion, if suitable source/destination managers are used.  See the
177
section on "I/O suspension" for more details.
178
179
180
BASIC LIBRARY USAGE
181
===================
182
183
Data formats
184
------------
185
186
Before diving into procedural details, it is helpful to understand the
187
image data format that the JPEG library expects or returns.
188
189
The standard input image format is a rectangular array of pixels, with each
190
pixel having the same number of "component" or "sample" values (color
191
channels).  You must specify how many components there are and the colorspace
192
interpretation of the components.  Most applications will use RGB data
193
(three components per pixel) or grayscale data (one component per pixel).
194
PLEASE NOTE THAT RGB DATA IS THREE SAMPLES PER PIXEL, GRAYSCALE ONLY ONE.
195
A remarkable number of people manage to miss this, only to find that their
196
programs don't work with grayscale JPEG files.
197
198
There is no provision for colormapped input.  JPEG files are always full-color
199
or full grayscale (or sometimes another colorspace such as CMYK).  You can
200
feed in a colormapped image by expanding it to full-color format.  However
201
JPEG often doesn't work very well with source data that has been colormapped,
202
because of dithering noise.  This is discussed in more detail in the JPEG FAQ
203
and the other references mentioned in the README file.
204
205
Pixels are stored by scanlines, with each scanline running from left to
206
right.  The component values for each pixel are adjacent in the row; for
207
example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color.  Each scanline is an
208
array of data type JSAMPLE --- which is typically "unsigned char", unless
209
you've changed jmorecfg.h.  (You can also change the RGB pixel layout, say
210
to B,G,R order, by modifying jmorecfg.h.  But see the restrictions listed in
211
that file before doing so.)
212
213
A 2-D array of pixels is formed by making a list of pointers to the starts of
214
scanlines; so the scanlines need not be physically adjacent in memory.  Even
215
if you process just one scanline at a time, you must make a one-element
216
pointer array to conform to this structure.  Pointers to JSAMPLE rows are of
217
type JSAMPROW, and the pointer to the pointer array is of type JSAMPARRAY.
218
219
The library accepts or supplies one or more complete scanlines per call.
220
It is not possible to process part of a row at a time.  Scanlines are always
221
processed top-to-bottom.  You can process an entire image in one call if you
222
have it all in memory, but usually it's simplest to process one scanline at
223
a time.
224
225
For best results, source data values should have the precision specified by
226
BITS_IN_JSAMPLE (normally 8 bits).  For instance, if you choose to compress
227
data that's only 6 bits/channel, you should left-justify each value in a
228
byte before passing it to the compressor.  If you need to compress data
229
that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 12.
230
(See "Library compile-time options", later.)
231
232
233
The data format returned by the decompressor is the same in all details,
234
except that colormapped output is supported.  (Again, a JPEG file is never
235
colormapped.  But you can ask the decompressor to perform on-the-fly color
236
quantization to deliver colormapped output.)  If you request colormapped
237
output then the returned data array contains a single JSAMPLE per pixel;
238
its value is an index into a color map.  The color map is represented as
239
a 2-D JSAMPARRAY in which each row holds the values of one color component,
240
that is, colormap[i][j] is the value of the i'th color component for pixel
241
value (map index) j.  Note that since the colormap indexes are stored in
242
JSAMPLEs, the maximum number of colors is limited by the size of JSAMPLE
243
(ie, at most 256 colors for an 8-bit JPEG library).
244
245
246
Compression details
247
-------------------
248
249
Here we revisit the JPEG compression outline given in the overview.
250
251
1. Allocate and initialize a JPEG compression object.
252
253
A JPEG compression object is a "struct jpeg_compress_struct".  (It also has
254
a bunch of subsidiary structures which are allocated via malloc(), but the
255
application doesn't control those directly.)  This struct can be just a local
256
variable in the calling routine, if a single routine is going to execute the
257
whole JPEG compression sequence.  Otherwise it can be static or allocated
258
from malloc().
259
260
You will also need a structure representing a JPEG error handler.  The part
261
of this that the library cares about is a "struct jpeg_error_mgr".  If you
262
are providing your own error handler, you'll typically want to embed the
263
jpeg_error_mgr struct in a larger structure; this is discussed later under
264
"Error handling".  For now we'll assume you are just using the default error
265
handler.  The default error handler will print JPEG error/warning messages
266
on stderr, and it will call exit() if a fatal error occurs.
267
268
You must initialize the error handler structure, store a pointer to it into
269
the JPEG object's "err" field, and then call jpeg_create_compress() to
270
initialize the rest of the JPEG object.
271
272
Typical code for this step, if you are using the default error handler, is
273
274
	struct jpeg_compress_struct cinfo;
275
	struct jpeg_error_mgr jerr;
276
	...
277
	cinfo.err = jpeg_std_error(&jerr);
278
	jpeg_create_compress(&cinfo);
279
280
jpeg_create_compress allocates a small amount of memory, so it could fail
281
if you are out of memory.  In that case it will exit via the error handler;
282
that's why the error handler must be initialized first.
283
284
285
2. Specify the destination for the compressed data (eg, a file).
286
287
As previously mentioned, the JPEG library delivers compressed data to a
288
"data destination" module.  The library includes one data destination
289
module which knows how to write to a stdio stream.  You can use your own
290
destination module if you want to do something else, as discussed later.
291
292
If you use the standard destination module, you must open the target stdio
293
stream beforehand.  Typical code for this step looks like:
294
295
	FILE * outfile;
296
	...
297
	if ((outfile = fopen(filename, "wb")) == NULL) {
298
	    fprintf(stderr, "can't open %s\n", filename);
299
	    exit(1);
300
	}
301
	jpeg_stdio_dest(&cinfo, outfile);
302
303
where the last line invokes the standard destination module.
304
305
WARNING: it is critical that the binary compressed data be delivered to the
306
output file unchanged.  On non-Unix systems the stdio library may perform
307
newline translation or otherwise corrupt binary data.  To suppress this
308
behavior, you may need to use a "b" option to fopen (as shown above), or use
309
setmode() or another routine to put the stdio stream in binary mode.  See
310
cjpeg.c and djpeg.c for code that has been found to work on many systems.
311
312
You can select the data destination after setting other parameters (step 3),
313
if that's more convenient.  You may not change the destination between
314
calling jpeg_start_compress() and jpeg_finish_compress().
315
316
317
3. Set parameters for compression, including image size & colorspace.
318
319
You must supply information about the source image by setting the following
320
fields in the JPEG object (cinfo structure):
321
322
	image_width		Width of image, in pixels
323
	image_height		Height of image, in pixels
324
	input_components	Number of color channels (samples per pixel)
325
	in_color_space		Color space of source image
326
327
The image dimensions are, hopefully, obvious.  JPEG supports image dimensions
328
of 1 to 64K pixels in either direction.  The input color space is typically
329
RGB or grayscale, and input_components is 3 or 1 accordingly.  (See "Special
330
color spaces", later, for more info.)  The in_color_space field must be
331
assigned one of the J_COLOR_SPACE enum constants, typically JCS_RGB or
332
JCS_GRAYSCALE.
333
334
JPEG has a large number of compression parameters that determine how the
335
image is encoded.  Most applications don't need or want to know about all
336
these parameters.  You can set all the parameters to reasonable defaults by
337
calling jpeg_set_defaults(); then, if there are particular values you want
338
to change, you can do so after that.  The "Compression parameter selection"
339
section tells about all the parameters.
340
341
You must set in_color_space correctly before calling jpeg_set_defaults(),
342
because the defaults depend on the source image colorspace.  However the
343
other three source image parameters need not be valid until you call
344
jpeg_start_compress().  There's no harm in calling jpeg_set_defaults() more
345
than once, if that happens to be convenient.
346
347
Typical code for a 24-bit RGB source image is
348
349
	cinfo.image_width = Width; 	/* image width and height, in pixels */
350
	cinfo.image_height = Height;
351
	cinfo.input_components = 3;	/* # of color components per pixel */
352
	cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
353
354
	jpeg_set_defaults(&cinfo);
355
	/* Make optional parameter settings here */
356
357
358
4. jpeg_start_compress(...);
359
360
After you have established the data destination and set all the necessary
361
source image info and other parameters, call jpeg_start_compress() to begin
362
a compression cycle.  This will initialize internal state, allocate working
363
storage, and emit the first few bytes of the JPEG datastream header.
364
365
Typical code:
366
367
	jpeg_start_compress(&cinfo, TRUE);
368
369
The "TRUE" parameter ensures that a complete JPEG interchange datastream
370
will be written.  This is appropriate in most cases.  If you think you might
371
want to use an abbreviated datastream, read the section on abbreviated
372
datastreams, below.
373
374
Once you have called jpeg_start_compress(), you may not alter any JPEG
375
parameters or other fields of the JPEG object until you have completed
376
the compression cycle.
377
378
379
5. while (scan lines remain to be written)
380
	jpeg_write_scanlines(...);
381
382
Now write all the required image data by calling jpeg_write_scanlines()
383
one or more times.  You can pass one or more scanlines in each call, up
384
to the total image height.  In most applications it is convenient to pass
385
just one or a few scanlines at a time.  The expected format for the passed
386
data is discussed under "Data formats", above.
387
388
Image data should be written in top-to-bottom scanline order.  The JPEG spec
389
contains some weasel wording about how top and bottom are application-defined
390
terms (a curious interpretation of the English language...) but if you want
391
your files to be compatible with everyone else's, you WILL use top-to-bottom
392
order.  If the source data must be read in bottom-to-top order, you can use
393
the JPEG library's virtual array mechanism to invert the data efficiently.
394
Examples of this can be found in the sample application cjpeg.
395
396
The library maintains a count of the number of scanlines written so far
397
in the next_scanline field of the JPEG object.  Usually you can just use
398
this variable as the loop counter, so that the loop test looks like
399
"while (cinfo.next_scanline < cinfo.image_height)".
400
401
Code for this step depends heavily on the way that you store the source data.
402
example.c shows the following code for the case of a full-size 2-D source
403
array containing 3-byte RGB pixels:
404
405
	JSAMPROW row_pointer[1];	/* pointer to a single row */
406
	int row_stride;			/* physical row width in buffer */
407
408
	row_stride = image_width * 3;	/* JSAMPLEs per row in image_buffer */
409
410
	while (cinfo.next_scanline < cinfo.image_height) {
411
	    row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
412
	    jpeg_write_scanlines(&cinfo, row_pointer, 1);
413
	}
414
415
jpeg_write_scanlines() returns the number of scanlines actually written.
416
This will normally be equal to the number passed in, so you can usually
417
ignore the return value.  It is different in just two cases:
418
  * If you try to write more scanlines than the declared image height,
419
    the additional scanlines are ignored.
420
  * If you use a suspending data destination manager, output buffer overrun
421
    will cause the compressor to return before accepting all the passed lines.
422
    This feature is discussed under "I/O suspension", below.  The normal
423
    stdio destination manager will NOT cause this to happen.
424
In any case, the return value is the same as the change in the value of
425
next_scanline.
426
427
428
6. jpeg_finish_compress(...);
429
430
After all the image data has been written, call jpeg_finish_compress() to
431
complete the compression cycle.  This step is ESSENTIAL to ensure that the
432
last bufferload of data is written to the data destination.
433
jpeg_finish_compress() also releases working memory associated with the JPEG
434
object.
435
436
Typical code:
437
438
	jpeg_finish_compress(&cinfo);
439
440
If using the stdio destination manager, don't forget to close the output
441
stdio stream (if necessary) afterwards.
442
443
If you have requested a multi-pass operating mode, such as Huffman code
444
optimization, jpeg_finish_compress() will perform the additional passes using
445
data buffered by the first pass.  In this case jpeg_finish_compress() may take
446
quite a while to complete.  With the default compression parameters, this will
447
not happen.
448
449
It is an error to call jpeg_finish_compress() before writing the necessary
450
total number of scanlines.  If you wish to abort compression, call
451
jpeg_abort() as discussed below.
452
453
After completing a compression cycle, you may dispose of the JPEG object
454
as discussed next, or you may use it to compress another image.  In that case
455
return to step 2, 3, or 4 as appropriate.  If you do not change the
456
destination manager, the new datastream will be written to the same target.
457
If you do not change any JPEG parameters, the new datastream will be written
458
with the same parameters as before.  Note that you can change the input image
459
dimensions freely between cycles, but if you change the input colorspace, you
460
should call jpeg_set_defaults() to adjust for the new colorspace; and then
461
you'll need to repeat all of step 3.
462
463
464
7. Release the JPEG compression object.
465
466
When you are done with a JPEG compression object, destroy it by calling
467
jpeg_destroy_compress().  This will free all subsidiary memory (regardless of
468
the previous state of the object).  Or you can call jpeg_destroy(), which
469
works for either compression or decompression objects --- this may be more
470
convenient if you are sharing code between compression and decompression
471
cases.  (Actually, these routines are equivalent except for the declared type
472
of the passed pointer.  To avoid gripes from ANSI C compilers, jpeg_destroy()
473
should be passed a j_common_ptr.)
474
475
If you allocated the jpeg_compress_struct structure from malloc(), freeing
476
it is your responsibility --- jpeg_destroy() won't.  Ditto for the error
477
handler structure.
478
479
Typical code:
480
481
	jpeg_destroy_compress(&cinfo);
482
483
484
8. Aborting.
485
486
If you decide to abort a compression cycle before finishing, you can clean up
487
in either of two ways:
488
489
* If you don't need the JPEG object any more, just call
490
  jpeg_destroy_compress() or jpeg_destroy() to release memory.  This is
491
  legitimate at any point after calling jpeg_create_compress() --- in fact,
492
  it's safe even if jpeg_create_compress() fails.
493
494
* If you want to re-use the JPEG object, call jpeg_abort_compress(), or call
495
  jpeg_abort() which works on both compression and decompression objects.
496
  This will return the object to an idle state, releasing any working memory.
497
  jpeg_abort() is allowed at any time after successful object creation.
498
499
Note that cleaning up the data destination, if required, is your
500
responsibility; neither of these routines will call term_destination().
501
(See "Compressed data handling", below, for more about that.)
502
503
jpeg_destroy() and jpeg_abort() are the only safe calls to make on a JPEG
504
object that has reported an error by calling error_exit (see "Error handling"
505
for more info).  The internal state of such an object is likely to be out of
506
whack.  Either of these two routines will return the object to a known state.
507
508
509
Decompression details
510
---------------------
511
512
Here we revisit the JPEG decompression outline given in the overview.
513
514
1. Allocate and initialize a JPEG decompression object.
515
516
This is just like initialization for compression, as discussed above,
517
except that the object is a "struct jpeg_decompress_struct" and you
518
call jpeg_create_decompress().  Error handling is exactly the same.
519
520
Typical code:
521
522
	struct jpeg_decompress_struct cinfo;
523
	struct jpeg_error_mgr jerr;
524
	...
525
	cinfo.err = jpeg_std_error(&jerr);
526
	jpeg_create_decompress(&cinfo);
527
528
(Both here and in the IJG code, we usually use variable name "cinfo" for
529
both compression and decompression objects.)
530
531
532
2. Specify the source of the compressed data (eg, a file).
533
534
As previously mentioned, the JPEG library reads compressed data from a "data
535
source" module.  The library includes one data source module which knows how
536
to read from a stdio stream.  You can use your own source module if you want
537
to do something else, as discussed later.
538
539
If you use the standard source module, you must open the source stdio stream
540
beforehand.  Typical code for this step looks like:
541
542
	FILE * infile;
543
	...
544
	if ((infile = fopen(filename, "rb")) == NULL) {
545
	    fprintf(stderr, "can't open %s\n", filename);
546
	    exit(1);
547
	}
548
	jpeg_stdio_src(&cinfo, infile);
549
550
where the last line invokes the standard source module.
551
552
WARNING: it is critical that the binary compressed data be read unchanged.
553
On non-Unix systems the stdio library may perform newline translation or
554
otherwise corrupt binary data.  To suppress this behavior, you may need to use
555
a "b" option to fopen (as shown above), or use setmode() or another routine to
556
put the stdio stream in binary mode.  See cjpeg.c and djpeg.c for code that
557
has been found to work on many systems.
558
559
You may not change the data source between calling jpeg_read_header() and
560
jpeg_finish_decompress().  If you wish to read a series of JPEG images from
561
a single source file, you should repeat the jpeg_read_header() to
562
jpeg_finish_decompress() sequence without reinitializing either the JPEG
563
object or the data source module; this prevents buffered input data from
564
being discarded.
565
566
567
3. Call jpeg_read_header() to obtain image info.
568
569
Typical code for this step is just
570
571
	jpeg_read_header(&cinfo, TRUE);
572
573
This will read the source datastream header markers, up to the beginning
574
of the compressed data proper.  On return, the image dimensions and other
575
info have been stored in the JPEG object.  The application may wish to
576
consult this information before selecting decompression parameters.
577
578
More complex code is necessary if
579
  * A suspending data source is used --- in that case jpeg_read_header()
580
    may return before it has read all the header data.  See "I/O suspension",
581
    below.  The normal stdio source manager will NOT cause this to happen.
582
  * Abbreviated JPEG files are to be processed --- see the section on
583
    abbreviated datastreams.  Standard applications that deal only in
584
    interchange JPEG files need not be concerned with this case either.
585
586
It is permissible to stop at this point if you just wanted to find out the
587
image dimensions and other header info for a JPEG file.  In that case,
588
call jpeg_destroy() when you are done with the JPEG object, or call
589
jpeg_abort() to return it to an idle state before selecting a new data
590
source and reading another header.
591
592
593
4. Set parameters for decompression.
594
595
jpeg_read_header() sets appropriate default decompression parameters based on
596
the properties of the image (in particular, its colorspace).  However, you
597
may well want to alter these defaults before beginning the decompression.
598
For example, the default is to produce full color output from a color file.
599
If you want colormapped output you must ask for it.  Other options allow the
600
returned image to be scaled and allow various speed/quality tradeoffs to be
601
selected.  "Decompression parameter selection", below, gives details.
602
603
If the defaults are appropriate, nothing need be done at this step.
604
605
Note that all default values are set by each call to jpeg_read_header().
606
If you reuse a decompression object, you cannot expect your parameter
607
settings to be preserved across cycles, as you can for compression.
608
You must set desired parameter values each time.
609
610
611
5. jpeg_start_decompress(...);
612
613
Once the parameter values are satisfactory, call jpeg_start_decompress() to
614
begin decompression.  This will initialize internal state, allocate working
615
memory, and prepare for returning data.
616
617
Typical code is just
618
619
	jpeg_start_decompress(&cinfo);
620
621
If you have requested a multi-pass operating mode, such as 2-pass color
622
quantization, jpeg_start_decompress() will do everything needed before data
623
output can begin.  In this case jpeg_start_decompress() may take quite a while
624
to complete.  With a single-scan (non progressive) JPEG file and default
625
decompression parameters, this will not happen; jpeg_start_decompress() will
626
return quickly.
627
628
After this call, the final output image dimensions, including any requested
629
scaling, are available in the JPEG object; so is the selected colormap, if
630
colormapped output has been requested.  Useful fields include
631
632
	output_width		image width and height, as scaled
633
	output_height
634
	out_color_components	# of color components in out_color_space
635
	output_components	# of color components returned per pixel
636
	colormap		the selected colormap, if any
637
	actual_number_of_colors		number of entries in colormap
638
639
output_components is 1 (a colormap index) when quantizing colors; otherwise it
640
equals out_color_components.  It is the number of JSAMPLE values that will be
641
emitted per pixel in the output arrays.
642
643
Typically you will need to allocate data buffers to hold the incoming image.
644
You will need output_width * output_components JSAMPLEs per scanline in your
645
output buffer, and a total of output_height scanlines will be returned.
646
647
Note: if you are using the JPEG library's internal memory manager to allocate
648
data buffers (as djpeg does), then the manager's protocol requires that you
649
request large buffers *before* calling jpeg_start_decompress().  This is a
650
little tricky since the output_XXX fields are not normally valid then.  You
651
can make them valid by calling jpeg_calc_output_dimensions() after setting the
652
relevant parameters (scaling, output color space, and quantization flag).
653
654
655
6. while (scan lines remain to be read)
656
	jpeg_read_scanlines(...);
657
658
Now you can read the decompressed image data by calling jpeg_read_scanlines()
659
one or more times.  At each call, you pass in the maximum number of scanlines
660
to be read (ie, the height of your working buffer); jpeg_read_scanlines()
661
will return up to that many lines.  The return value is the number of lines
662
actually read.  The format of the returned data is discussed under "Data
663
formats", above.  Don't forget that grayscale and color JPEGs will return
664
different data formats!
665
666
Image data is returned in top-to-bottom scanline order.  If you must write
667
out the image in bottom-to-top order, you can use the JPEG library's virtual
668
array mechanism to invert the data efficiently.  Examples of this can be
669
found in the sample application djpeg.
670
671
The library maintains a count of the number of scanlines returned so far
672
in the output_scanline field of the JPEG object.  Usually you can just use
673
this variable as the loop counter, so that the loop test looks like
674
"while (cinfo.output_scanline < cinfo.output_height)".  (Note that the test
675
should NOT be against image_height, unless you never use scaling.  The
676
image_height field is the height of the original unscaled image.)
677
The return value always equals the change in the value of output_scanline.
678
679
If you don't use a suspending data source, it is safe to assume that
680
jpeg_read_scanlines() reads at least one scanline per call, until the
681
bottom of the image has been reached.
682
683
If you use a buffer larger than one scanline, it is NOT safe to assume that
684
jpeg_read_scanlines() fills it.  (The current implementation returns only a
685
few scanlines per call, no matter how large a buffer you pass.)  So you must
686
always provide a loop that calls jpeg_read_scanlines() repeatedly until the
687
whole image has been read.
688
689
690
7. jpeg_finish_decompress(...);
691
692
After all the image data has been read, call jpeg_finish_decompress() to
693
complete the decompression cycle.  This causes working memory associated
694
with the JPEG object to be released.
695
696
Typical code:
697
698
	jpeg_finish_decompress(&cinfo);
699
700
If using the stdio source manager, don't forget to close the source stdio
701
stream if necessary.
702
703
It is an error to call jpeg_finish_decompress() before reading the correct
704
total number of scanlines.  If you wish to abort decompression, call
705
jpeg_abort() as discussed below.
706
707
After completing a decompression cycle, you may dispose of the JPEG object as
708
discussed next, or you may use it to decompress another image.  In that case
709
return to step 2 or 3 as appropriate.  If you do not change the source
710
manager, the next image will be read from the same source.
711
712
713
8. Release the JPEG decompression object.
714
715
When you are done with a JPEG decompression object, destroy it by calling
716
jpeg_destroy_decompress() or jpeg_destroy().  The previous discussion of
717
destroying compression objects applies here too.
718
719
Typical code:
720
721
	jpeg_destroy_decompress(&cinfo);
722
723
724
9. Aborting.
725
726
You can abort a decompression cycle by calling jpeg_destroy_decompress() or
727
jpeg_destroy() if you don't need the JPEG object any more, or
728
jpeg_abort_decompress() or jpeg_abort() if you want to reuse the object.
729
The previous discussion of aborting compression cycles applies here too.
730
731
732
Mechanics of usage: include files, linking, etc
733
-----------------------------------------------
734
735
Applications using the JPEG library should include the header file jpeglib.h
736
to obtain declarations of data types and routines.  Before including
737
jpeglib.h, include system headers that define at least the typedefs FILE and
738
size_t.  On ANSI-conforming systems, including <stdio.h> is sufficient; on
739
older Unix systems, you may need <sys/types.h> to define size_t.
740
741
If the application needs to refer to individual JPEG library error codes, also
742
include jerror.h to define those symbols.
743
744
jpeglib.h indirectly includes the files jconfig.h and jmorecfg.h.  If you are
745
installing the JPEG header files in a system directory, you will want to
746
install all four files: jpeglib.h, jerror.h, jconfig.h, jmorecfg.h.
747
748
The most convenient way to include the JPEG code into your executable program
749
is to prepare a library file ("libjpeg.a", or a corresponding name on non-Unix
750
machines) and reference it at your link step.  If you use only half of the
751
library (only compression or only decompression), only that much code will be
752
included from the library, unless your linker is hopelessly brain-damaged.
753
The supplied makefiles build libjpeg.a automatically (see install.doc).
754
755
While you can build the JPEG library as a shared library if the whim strikes
756
you, we don't really recommend it.  The trouble with shared libraries is that
757
at some point you'll probably try to substitute a new version of the library
758
without recompiling the calling applications.  That generally doesn't work
759
because the parameter struct declarations usually change with each new
760
version.  In other words, the library's API is *not* guaranteed binary
761
compatible across versions; we only try to ensure source-code compatibility.
762
(In hindsight, it might have been smarter to hide the parameter structs from
763
applications and introduce a ton of access functions instead.  Too late now,
764
however.)
765
766
On some systems your application may need to set up a signal handler to ensure
767
that temporary files are deleted if the program is interrupted.  This is most
768
critical if you are on MS-DOS and use the jmemdos.c memory manager back end;
769
it will try to grab extended memory for temp files, and that space will NOT be
770
freed automatically.  See cjpeg.c or djpeg.c for an example signal handler.
771
772
It may be worth pointing out that the core JPEG library does not actually
773
require the stdio library: only the default source/destination managers and
774
error handler need it.  You can use the library in a stdio-less environment
775
if you replace those modules and use jmemnobs.c (or another memory manager of
776
your own devising).  More info about the minimum system library requirements
777
may be found in jinclude.h.
778
779
780
ADVANCED FEATURES
781
=================
782
783
Compression parameter selection
784
-------------------------------
785
786
This section describes all the optional parameters you can set for JPEG
787
compression, as well as the "helper" routines provided to assist in this
788
task.  Proper setting of some parameters requires detailed understanding
789
of the JPEG standard; if you don't know what a parameter is for, it's best
790
not to mess with it!  See REFERENCES in the README file for pointers to
791
more info about JPEG.
792
793
It's a good idea to call jpeg_set_defaults() first, even if you plan to set
794
all the parameters; that way your code is more likely to work with future JPEG
795
libraries that have additional parameters.  For the same reason, we recommend
796
you use a helper routine where one is provided, in preference to twiddling
797
cinfo fields directly.
798
799
The helper routines are:
800
801
jpeg_set_defaults (j_compress_ptr cinfo)
802
	This routine sets all JPEG parameters to reasonable defaults, using
803
	only the input image's color space (field in_color_space, which must
804
	already be set in cinfo).  Many applications will only need to use
805
	this routine and perhaps jpeg_set_quality().
806
807
jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
808
	Sets the JPEG file's colorspace (field jpeg_color_space) as specified,
809
	and sets other color-space-dependent parameters appropriately.  See
810
	"Special color spaces", below, before using this.  A large number of
811
	parameters, including all per-component parameters, are set by this
812
	routine; if you want to twiddle individual parameters you should call
813
	jpeg_set_colorspace() before rather than after.
814
815
jpeg_default_colorspace (j_compress_ptr cinfo)
816
	Selects an appropriate JPEG colorspace based on cinfo->in_color_space,
817
	and calls jpeg_set_colorspace().  This is actually a subroutine of
818
	jpeg_set_defaults().  It's broken out in case you want to change
819
	just the colorspace-dependent JPEG parameters.
820
821
jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
822
	Constructs JPEG quantization tables appropriate for the indicated
823
	quality setting.  The quality value is expressed on the 0..100 scale
824
	recommended by IJG (cjpeg's "-quality" switch uses this routine).
825
	Note that the exact mapping from quality values to tables may change
826
	in future IJG releases as more is learned about DCT quantization.
827
	If the force_baseline parameter is TRUE, then the quantization table
828
	entries are constrained to the range 1..255 for full JPEG baseline
829
	compatibility.  In the current implementation, this only makes a
830
	difference for quality settings below 25, and it effectively prevents
831
	very small/low quality files from being generated.  The IJG decoder
832
	is capable of reading the non-baseline files generated at low quality
833
	settings when force_baseline is FALSE, but other decoders may not be.
834
835
jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
836
			 boolean force_baseline)
837
	Same as jpeg_set_quality() except that the generated tables are the
838
	sample tables given in the JPEC spec section K.1, multiplied by the
839
	specified scale factor (which is expressed as a percentage; thus
840
	scale_factor = 100 reproduces the spec's tables).  Note that larger
841
	scale factors give lower quality.  This entry point is useful for
842
	conforming to the Adobe PostScript DCT conventions, but we do not
843
	recommend linear scaling as a user-visible quality scale otherwise.
844
	force_baseline again constrains the computed table entries to 1..255.
845
846
int jpeg_quality_scaling (int quality)
847
	Converts a value on the IJG-recommended quality scale to a linear
848
	scaling percentage.  Note that this routine may change or go away
849
	in future releases --- IJG may choose to adopt a scaling method that
850
	can't be expressed as a simple scalar multiplier, in which case the
851
	premise of this routine collapses.  Caveat user.
852
853
jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
854
		      const unsigned int *basic_table,
855
		      int scale_factor, boolean force_baseline)
856
	Allows an arbitrary quantization table to be created.  which_tbl
857
	indicates which table slot to fill.  basic_table points to an array
858
	of 64 unsigned ints given in normal array order.  These values are
859
	multiplied by scale_factor/100 and then clamped to the range 1..65535
860
	(or to 1..255 if force_baseline is TRUE).
861
	CAUTION: prior to library version 6a, jpeg_add_quant_table expected
862
	the basic table to be given in JPEG zigzag order.  If you need to
863
	write code that works with either older or newer versions of this
864
	routine, you must check the library version number.  Something like
865
	"#if JPEG_LIB_VERSION >= 61" is the right test.
866
867
jpeg_simple_progression (j_compress_ptr cinfo)
868
	Generates a default scan script for writing a progressive-JPEG file.
869
	This is the recommended method of creating a progressive file,
870
	unless you want to make a custom scan sequence.  You must ensure that
871
	the JPEG color space is set correctly before calling this routine.
872
873
874
Compression parameters (cinfo fields) include:
875
876
J_DCT_METHOD dct_method
877
	Selects the algorithm used for the DCT step.  Choices are:
878
		JDCT_ISLOW: slow but accurate integer algorithm
879
		JDCT_IFAST: faster, less accurate integer method
880
		JDCT_FLOAT: floating-point method
881
		JDCT_DEFAULT: default method (normally JDCT_ISLOW)
882
		JDCT_FASTEST: fastest method (normally JDCT_IFAST)
883
	The FLOAT method is very slightly more accurate than the ISLOW method,
884
	but may give different results on different machines due to varying
885
	roundoff behavior.  The integer methods should give the same results
886
	on all machines.  On machines with sufficiently fast FP hardware, the
887
	floating-point method may also be the fastest.  The IFAST method is
888
	considerably less accurate than the other two; its use is not
889
	recommended if high quality is a concern.  JDCT_DEFAULT and
890
	JDCT_FASTEST are macros configurable by each installation.
891
892
J_COLOR_SPACE jpeg_color_space
893
int num_components
894
	The JPEG color space and corresponding number of components; see
895
	"Special color spaces", below, for more info.  We recommend using
896
	jpeg_set_color_space() if you want to change these.
897
898
boolean optimize_coding
899
	TRUE causes the compressor to compute optimal Huffman coding tables
900
	for the image.  This requires an extra pass over the data and
901
	therefore costs a good deal of space and time.  The default is
902
	FALSE, which tells the compressor to use the supplied or default
903
	Huffman tables.  In most cases optimal tables save only a few percent
904
	of file size compared to the default tables.  Note that when this is
905
	TRUE, you need not supply Huffman tables at all, and any you do
906
	supply will be overwritten.
907
908
unsigned int restart_interval
909
int restart_in_rows
910
	To emit restart markers in the JPEG file, set one of these nonzero.
911
	Set restart_interval to specify the exact interval in MCU blocks.
912
	Set restart_in_rows to specify the interval in MCU rows.  (If
913
	restart_in_rows is not 0, then restart_interval is set after the
914
	image width in MCUs is computed.)  Defaults are zero (no restarts).
915
	One restart marker per MCU row is often a good choice.
916
	NOTE: the overhead of restart markers is higher in grayscale JPEG
917
	files than in color files, and MUCH higher in progressive JPEGs.
918
	If you use restarts, you may want to use larger intervals in those
919
	cases.
920
921
const jpeg_scan_info * scan_info
922
int num_scans
923
	By default, scan_info is NULL; this causes the compressor to write a
924
	single-scan sequential JPEG file.  If not NULL, scan_info points to
925
	an array of scan definition records of length num_scans.  The
926
	compressor will then write a JPEG file having one scan for each scan
927
	definition record.  This is used to generate noninterleaved or
928
	progressive JPEG files.  The library checks that the scan array
929
	defines a valid JPEG scan sequence.  (jpeg_simple_progression creates
930
	a suitable scan definition array for progressive JPEG.)  This is
931
	discussed further under "Progressive JPEG support".
932
933
int smoothing_factor
934
	If non-zero, the input image is smoothed; the value should be 1 for
935
	minimal smoothing to 100 for maximum smoothing.  Consult jcsample.c
936
	for details of the smoothing algorithm.  The default is zero.
937
938
boolean write_JFIF_header
939
	If TRUE, a JFIF APP0 marker is emitted.  jpeg_set_defaults() and
940
	jpeg_set_colorspace() set this TRUE if a JFIF-legal JPEG color space
941
	(ie, YCbCr or grayscale) is selected, otherwise FALSE.
942
943
UINT8 JFIF_major_version
944
UINT8 JFIF_minor_version
945
	The version number to be written into the JFIF marker.
946
	jpeg_set_defaults() initializes the version to 1.01 (major=minor=1).
947
	You should set it to 1.02 (major=1, minor=2) if you plan to write
948
	any JFIF 1.02 extension markers.
949
950
UINT8 density_unit
951
UINT16 X_density
952
UINT16 Y_density
953
	The resolution information to be written into the JFIF marker;
954
	not used otherwise.  density_unit may be 0 for unknown,
955
	1 for dots/inch, or 2 for dots/cm.  The default values are 0,1,1
956
	indicating square pixels of unknown size.
957
958
boolean write_Adobe_marker
959
	If TRUE, an Adobe APP14 marker is emitted.  jpeg_set_defaults() and
960
	jpeg_set_colorspace() set this TRUE if JPEG color space RGB, CMYK,
961
	or YCCK is selected, otherwise FALSE.  It is generally a bad idea
962
	to set both write_JFIF_header and write_Adobe_marker.  In fact,
963
	you probably shouldn't change the default settings at all --- the
964
	default behavior ensures that the JPEG file's color space can be
965
	recognized by the decoder.
966
967
JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]
968
	Pointers to coefficient quantization tables, one per table slot,
969
	or NULL if no table is defined for a slot.  Usually these should
970
	be set via one of the above helper routines; jpeg_add_quant_table()
971
	is general enough to define any quantization table.  The other
972
	routines will set up table slot 0 for luminance quality and table
973
	slot 1 for chrominance.
974
975
JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]
976
JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]
977
	Pointers to Huffman coding tables, one per table slot, or NULL if
978
	no table is defined for a slot.  Slots 0 and 1 are filled with the
979
	JPEG sample tables by jpeg_set_defaults().  If you need to allocate
980
	more table structures, jpeg_alloc_huff_table() may be used.
981
	Note that optimal Huffman tables can be computed for an image
982
	by setting optimize_coding, as discussed above; there's seldom
983
	any need to mess with providing your own Huffman tables.
984
985
There are some additional cinfo fields which are not documented here
986
because you currently can't change them; for example, you can't set
987
arith_code TRUE because arithmetic coding is unsupported.
988
989
990
Per-component parameters are stored in the struct cinfo.comp_info[i] for
991
component number i.  Note that components here refer to components of the
992
JPEG color space, *not* the source image color space.  A suitably large
993
comp_info[] array is allocated by jpeg_set_defaults(); if you choose not
994
to use that routine, it's up to you to allocate the array.
995
996
int component_id
997
	The one-byte identifier code to be recorded in the JPEG file for
998
	this component.  For the standard color spaces, we recommend you
999
	leave the default values alone.
1000
1001
int h_samp_factor
1002
int v_samp_factor
1003
	Horizontal and vertical sampling factors for the component; must
1004
	be 1..4 according to the JPEG standard.  Note that larger sampling
1005
	factors indicate a higher-resolution component; many people find
1006
	this behavior quite unintuitive.  The default values are 2,2 for
1007
	luminance components and 1,1 for chrominance components, except
1008
	for grayscale where 1,1 is used.
1009
1010
int quant_tbl_no
1011
	Quantization table number for component.  The default value is
1012
	0 for luminance components and 1 for chrominance components.
1013
1014
int dc_tbl_no
1015
int ac_tbl_no
1016
	DC and AC entropy coding table numbers.  The default values are
1017
	0 for luminance components and 1 for chrominance components.
1018
1019
int component_index
1020
	Must equal the component's index in comp_info[].  (Beginning in
1021
	release v6, the compressor library will fill this in automatically;
1022
	you don't have to.)
1023
1024
1025
Decompression parameter selection
1026
---------------------------------
1027
1028
Decompression parameter selection is somewhat simpler than compression
1029
parameter selection, since all of the JPEG internal parameters are
1030
recorded in the source file and need not be supplied by the application.
1031
(Unless you are working with abbreviated files, in which case see
1032
"Abbreviated datastreams", below.)  Decompression parameters control
1033
the postprocessing done on the image to deliver it in a format suitable
1034
for the application's use.  Many of the parameters control speed/quality
1035
tradeoffs, in which faster decompression may be obtained at the price of
1036
a poorer-quality image.  The defaults select the highest quality (slowest)
1037
processing.
1038
1039
The following fields in the JPEG object are set by jpeg_read_header() and
1040
may be useful to the application in choosing decompression parameters:
1041
1042
JDIMENSION image_width			Width and height of image
1043
JDIMENSION image_height
1044
int num_components			Number of color components
1045
J_COLOR_SPACE jpeg_color_space		Colorspace of image
1046
boolean saw_JFIF_marker			TRUE if a JFIF APP0 marker was seen
1047
  UINT8 JFIF_major_version		Version information from JFIF marker
1048
  UINT8 JFIF_minor_version
1049
  UINT8 density_unit			Resolution data from JFIF marker
1050
  UINT16 X_density
1051
  UINT16 Y_density
1052
boolean saw_Adobe_marker		TRUE if an Adobe APP14 marker was seen
1053
  UINT8 Adobe_transform			Color transform code from Adobe marker
1054
1055
The JPEG color space, unfortunately, is something of a guess since the JPEG
1056
standard proper does not provide a way to record it.  In practice most files
1057
adhere to the JFIF or Adobe conventions, and the decoder will recognize these
1058
correctly.  See "Special color spaces", below, for more info.
1059
1060
1061
The decompression parameters that determine the basic properties of the
1062
returned image are:
1063
1064
J_COLOR_SPACE out_color_space
1065
	Output color space.  jpeg_read_header() sets an appropriate default
1066
	based on jpeg_color_space; typically it will be RGB or grayscale.
1067
	The application can change this field to request output in a different
1068
	colorspace.  For example, set it to JCS_GRAYSCALE to get grayscale
1069
	output from a color file.  (This is useful for previewing: grayscale
1070
	output is faster than full color since the color components need not
1071
	be processed.)  Note that not all possible color space transforms are
1072
	currently implemented; you may need to extend jdcolor.c if you want an
1073
	unusual conversion.
1074
1075
unsigned int scale_num, scale_denom
1076
	Scale the image by the fraction scale_num/scale_denom.  Default is
1077
	1/1, or no scaling.  Currently, the only supported scaling ratios
1078
	are 1/1, 1/2, 1/4, and 1/8.  (The library design allows for arbitrary
1079
	scaling ratios but this is not likely to be implemented any time soon.)
1080
	Smaller scaling ratios permit significantly faster decoding since
1081
	fewer pixels need be processed and a simpler IDCT method can be used.
1082
1083
boolean quantize_colors
1084
	If set TRUE, colormapped output will be delivered.  Default is FALSE,
1085
	meaning that full-color output will be delivered.
1086
1087
The next three parameters are relevant only if quantize_colors is TRUE.
1088
1089
int desired_number_of_colors
1090
	Maximum number of colors to use in generating a library-supplied color
1091
	map (the actual number of colors is returned in a different field).
1092
	Default 256.  Ignored when the application supplies its own color map.
1093
1094
boolean two_pass_quantize
1095
	If TRUE, an extra pass over the image is made to select a custom color
1096
	map for the image.  This usually looks a lot better than the one-size-
1097
	fits-all colormap that is used otherwise.  Default is TRUE.  Ignored
1098
	when the application supplies its own color map.
1099
1100
J_DITHER_MODE dither_mode
1101
	Selects color dithering method.  Supported values are:
1102
		JDITHER_NONE	no dithering: fast, very low quality
1103
		JDITHER_ORDERED	ordered dither: moderate speed and quality
1104
		JDITHER_FS	Floyd-Steinberg dither: slow, high quality
1105
	Default is JDITHER_FS.  (At present, ordered dither is implemented
1106
	only in the single-pass, standard-colormap case.  If you ask for
1107
	ordered dither when two_pass_quantize is TRUE or when you supply
1108
	an external color map, you'll get F-S dithering.)
1109
1110
When quantize_colors is TRUE, the target color map is described by the next
1111
two fields.  colormap is set to NULL by jpeg_read_header().  The application
1112
can supply a color map by setting colormap non-NULL and setting
1113
actual_number_of_colors to the map size.  Otherwise, jpeg_start_decompress()
1114
selects a suitable color map and sets these two fields itself.
1115
[Implementation restriction: at present, an externally supplied colormap is
1116
only accepted for 3-component output color spaces.]
1117
1118
JSAMPARRAY colormap
1119
	The color map, represented as a 2-D pixel array of out_color_components
1120
	rows and actual_number_of_colors columns.  Ignored if not quantizing.
1121
	CAUTION: if the JPEG library creates its own colormap, the storage
1122
	pointed to by this field is released by jpeg_finish_decompress().
1123
	Copy the colormap somewhere else first, if you want to save it.
1124
1125
int actual_number_of_colors
1126
	The number of colors in the color map.
1127
1128
Additional decompression parameters that the application may set include:
1129
1130
J_DCT_METHOD dct_method
1131
	Selects the algorithm used for the DCT step.  Choices are the same
1132
	as described above for compression.
1133
1134
boolean do_fancy_upsampling
1135
	If TRUE, do careful upsampling of chroma components.  If FALSE,
1136
	a faster but sloppier method is used.  Default is TRUE.  The visual
1137
	impact of the sloppier method is often very small.
1138
1139
boolean do_block_smoothing
1140
	If TRUE, interblock smoothing is applied in early stages of decoding
1141
	progressive JPEG files; if FALSE, not.  Default is TRUE.  Early
1142
	progression stages look "fuzzy" with smoothing, "blocky" without.
1143
	In any case, block smoothing ceases to be applied after the first few
1144
	AC coefficients are known to full accuracy, so it is relevant only
1145
	when using buffered-image mode for progressive images.
1146
1147
boolean enable_1pass_quant
1148
boolean enable_external_quant
1149
boolean enable_2pass_quant
1150
	These are significant only in buffered-image mode, which is
1151
	described in its own section below.
1152
1153
1154
The output image dimensions are given by the following fields.  These are
1155
computed from the source image dimensions and the decompression parameters
1156
by jpeg_start_decompress().  You can also call jpeg_calc_output_dimensions()
1157
to obtain the values that will result from the current parameter settings.
1158
This can be useful if you are trying to pick a scaling ratio that will get
1159
close to a desired target size.  It's also important if you are using the
1160
JPEG library's memory manager to allocate output buffer space, because you
1161
are supposed to request such buffers *before* jpeg_start_decompress().
1162
1163
JDIMENSION output_width		Actual dimensions of output image.
1164
JDIMENSION output_height
1165
int out_color_components	Number of color components in out_color_space.
1166
int output_components		Number of color components returned.
1167
int rec_outbuf_height		Recommended height of scanline buffer.
1168
1169
When quantizing colors, output_components is 1, indicating a single color map
1170
index per pixel.  Otherwise it equals out_color_components.  The output arrays
1171
are required to be output_width * output_components JSAMPLEs wide.
1172
1173
rec_outbuf_height is the recommended minimum height (in scanlines) of the
1174
buffer passed to jpeg_read_scanlines().  If the buffer is smaller, the
1175
library will still work, but time will be wasted due to unnecessary data
1176
copying.  In high-quality modes, rec_outbuf_height is always 1, but some
1177
faster, lower-quality modes set it to larger values (typically 2 to 4).
1178
If you are going to ask for a high-speed processing mode, you may as well
1179
go to the trouble of honoring rec_outbuf_height so as to avoid data copying.
1180
(An output buffer larger than rec_outbuf_height lines is OK, but won't
1181
provide any material speed improvement over that height.)
1182
1183
1184
Special color spaces
1185
--------------------
1186
1187
The JPEG standard itself is "color blind" and doesn't specify any particular
1188
color space.  It is customary to convert color data to a luminance/chrominance
1189
color space before compressing, since this permits greater compression.  The
1190
existing de-facto JPEG file format standards specify YCbCr or grayscale data
1191
(JFIF), or grayscale, RGB, YCbCr, CMYK, or YCCK (Adobe).  For special
1192
applications such as multispectral images, other color spaces can be used,
1193
but it must be understood that such files will be unportable.
1194
1195
The JPEG library can handle the most common colorspace conversions (namely
1196
RGB <=> YCbCr and CMYK <=> YCCK).  It can also deal with data of an unknown
1197
color space, passing it through without conversion.  If you deal extensively
1198
with an unusual color space, you can easily extend the library to understand
1199
additional color spaces and perform appropriate conversions.
1200
1201
For compression, the source data's color space is specified by field
1202
in_color_space.  This is transformed to the JPEG file's color space given
1203
by jpeg_color_space.  jpeg_set_defaults() chooses a reasonable JPEG color
1204
space depending on in_color_space, but you can override this by calling
1205
jpeg_set_colorspace().  Of course you must select a supported transformation.
1206
jccolor.c currently supports the following transformations:
1207
	RGB => YCbCr
1208
	RGB => GRAYSCALE
1209
	YCbCr => GRAYSCALE
1210
	CMYK => YCCK
1211
plus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB,
1212
YCbCr => YCbCr, CMYK => CMYK, YCCK => YCCK, and UNKNOWN => UNKNOWN.
1213
1214
The de-facto file format standards (JFIF and Adobe) specify APPn markers that
1215
indicate the color space of the JPEG file.  It is important to ensure that
1216
these are written correctly, or omitted if the JPEG file's color space is not
1217
one of the ones supported by the de-facto standards.  jpeg_set_colorspace()
1218
will set the compression parameters to include or omit the APPn markers
1219
properly, so long as it is told the truth about the JPEG color space.
1220
For example, if you are writing some random 3-component color space without
1221
conversion, don't try to fake out the library by setting in_color_space and
1222
jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN.  You may want to write an
1223
APPn marker of your own devising to identify the colorspace --- see "Special
1224
markers", below.
1225
1226
When told that the color space is UNKNOWN, the library will default to using
1227
luminance-quality compression parameters for all color components.  You may
1228
well want to change these parameters.  See the source code for
1229
jpeg_set_colorspace(), in jcparam.c, for details.
1230
1231
For decompression, the JPEG file's color space is given in jpeg_color_space,
1232
and this is transformed to the output color space out_color_space.
1233
jpeg_read_header's setting of jpeg_color_space can be relied on if the file
1234
conforms to JFIF or Adobe conventions, but otherwise it is no better than a
1235
guess.  If you know the JPEG file's color space for certain, you can override
1236
jpeg_read_header's guess by setting jpeg_color_space.  jpeg_read_header also
1237
selects a default output color space based on (its guess of) jpeg_color_space;
1238
set out_color_space to override this.  Again, you must select a supported
1239
transformation.  jdcolor.c currently supports
1240
	YCbCr => GRAYSCALE
1241
	YCbCr => RGB
1242
	GRAYSCALE => RGB
1243
	YCCK => CMYK
1244
as well as the null transforms.  (Since GRAYSCALE=>RGB is provided, an
1245
application can force grayscale JPEGs to look like color JPEGs if it only
1246
wants to handle one case.)
1247
1248
The two-pass color quantizer, jquant2.c, is specialized to handle RGB data
1249
(it weights distances appropriately for RGB colors).  You'll need to modify
1250
the code if you want to use it for non-RGB output color spaces.  Note that
1251
jquant2.c is used to map to an application-supplied colormap as well as for
1252
the normal two-pass colormap selection process.
1253
1254
CAUTION: it appears that Adobe Photoshop writes inverted data in CMYK JPEG
1255
files: 0 represents 100% ink coverage, rather than 0% ink as you'd expect.
1256
This is arguably a bug in Photoshop, but if you need to work with Photoshop
1257
CMYK files, you will have to deal with it in your application.  We cannot
1258
"fix" this in the library by inverting the data during the CMYK<=>YCCK
1259
transform, because that would break other applications, notably Ghostscript.
1260
Photoshop versions prior to 3.0 write EPS files containing JPEG-encoded CMYK
1261
data in the same inverted-YCCK representation used in bare JPEG files, but
1262
the surrounding PostScript code performs an inversion using the PS image
1263
operator.  I am told that Photoshop 3.0 will write uninverted YCCK in
1264
EPS/JPEG files, and will omit the PS-level inversion.  (But the data
1265
polarity used in bare JPEG files will not change in 3.0.)  In either case,
1266
the JPEG library must not invert the data itself, or else Ghostscript would
1267
read these EPS files incorrectly.
1268
1269
1270
Error handling
1271
--------------
1272
1273
When the default error handler is used, any error detected inside the JPEG
1274
routines will cause a message to be printed on stderr, followed by exit().
1275
You can supply your own error handling routines to override this behavior
1276
and to control the treatment of nonfatal warnings and trace/debug messages.
1277
The file example.c illustrates the most common case, which is to have the
1278
application regain control after an error rather than exiting.
1279
1280
The JPEG library never writes any message directly; it always goes through
1281
the error handling routines.  Three classes of messages are recognized:
1282
  * Fatal errors: the library cannot continue.
1283
  * Warnings: the library can continue, but the data is corrupt, and a
1284
    damaged output image is likely to result.
1285
  * Trace/informational messages.  These come with a trace level indicating
1286
    the importance of the message; you can control the verbosity of the
1287
    program by adjusting the maximum trace level that will be displayed.
1288
1289
You may, if you wish, simply replace the entire JPEG error handling module
1290
(jerror.c) with your own code.  However, you can avoid code duplication by
1291
only replacing some of the routines depending on the behavior you need.
1292
This is accomplished by calling jpeg_std_error() as usual, but then overriding
1293
some of the method pointers in the jpeg_error_mgr struct, as illustrated by
1294
example.c.
1295
1296
All of the error handling routines will receive a pointer to the JPEG object
1297
(a j_common_ptr which points to either a jpeg_compress_struct or a
1298
jpeg_decompress_struct; if you need to tell which, test the is_decompressor
1299
field).  This struct includes a pointer to the error manager struct in its
1300
"err" field.  Frequently, custom error handler routines will need to access
1301
additional data which is not known to the JPEG library or the standard error
1302
handler.  The most convenient way to do this is to embed either the JPEG
1303
object or the jpeg_error_mgr struct in a larger structure that contains
1304
additional fields; then casting the passed pointer provides access to the
1305
additional fields.  Again, see example.c for one way to do it.  (Beginning
1306
with IJG version 6b, there is also a void pointer "client_data" in each
1307
JPEG object, which the application can also use to find related data.
1308
The library does not touch client_data at all.)
1309
1310
The individual methods that you might wish to override are:
1311
1312
error_exit (j_common_ptr cinfo)
1313
	Receives control for a fatal error.  Information sufficient to
1314
	generate the error message has been stored in cinfo->err; call
1315
	output_message to display it.  Control must NOT return to the caller;
1316
	generally this routine will exit() or longjmp() somewhere.
1317
	Typically you would override this routine to get rid of the exit()
1318
	default behavior.  Note that if you continue processing, you should
1319
	clean up the JPEG object with jpeg_abort() or jpeg_destroy().
1320
1321
output_message (j_common_ptr cinfo)
1322
	Actual output of any JPEG message.  Override this to send messages
1323
	somewhere other than stderr.  Note that this method does not know
1324
	how to generate a message, only where to send it.
1325
1326
format_message (j_common_ptr cinfo, char * buffer)
1327
	Constructs a readable error message string based on the error info
1328
	stored in cinfo->err.  This method is called by output_message.  Few
1329
	applications should need to override this method.  One possible
1330
	reason for doing so is to implement dynamic switching of error message
1331
	language.
1332
1333
emit_message (j_common_ptr cinfo, int msg_level)
1334
	Decide whether or not to emit a warning or trace message; if so,
1335
	calls output_message.  The main reason for overriding this method
1336
	would be to abort on warnings.  msg_level is -1 for warnings,
1337
	0 and up for trace messages.
1338
1339
Only error_exit() and emit_message() are called from the rest of the JPEG
1340
library; the other two are internal to the error handler.
1341
1342
The actual message texts are stored in an array of strings which is pointed to
1343
by the field err->jpeg_message_table.  The messages are numbered from 0 to
1344
err->last_jpeg_message, and it is these code numbers that are used in the
1345
JPEG library code.  You could replace the message texts (for instance, with
1346
messages in French or German) by changing the message table pointer.  See
1347
jerror.h for the default texts.  CAUTION: this table will almost certainly
1348
change or grow from one library version to the next.
1349
1350
It may be useful for an application to add its own message texts that are
1351
handled by the same mechanism.  The error handler supports a second "add-on"
1352
message table for this purpose.  To define an addon table, set the pointer
1353
err->addon_message_table and the message numbers err->first_addon_message and
1354
err->last_addon_message.  If you number the addon messages beginning at 1000
1355
or so, you won't have to worry about conflicts with the library's built-in
1356
messages.  See the sample applications cjpeg/djpeg for an example of using
1357
addon messages (the addon messages are defined in cderror.h).
1358
1359
Actual invocation of the error handler is done via macros defined in jerror.h:
1360
	ERREXITn(...)	for fatal errors
1361
	WARNMSn(...)	for corrupt-data warnings
1362
	TRACEMSn(...)	for trace and informational messages.
1363
These macros store the message code and any additional parameters into the
1364
error handler struct, then invoke the error_exit() or emit_message() method.
1365
The variants of each macro are for varying numbers of additional parameters.
1366
The additional parameters are inserted into the generated message using
1367
standard printf() format codes.
1368
1369
See jerror.h and jerror.c for further details.
1370
1371
1372
Compressed data handling (source and destination managers)
1373
----------------------------------------------------------
1374
1375
The JPEG compression library sends its compressed data to a "destination
1376
manager" module.  The default destination manager just writes the data to a
1377
stdio stream, but you can provide your own manager to do something else.
1378
Similarly, the decompression library calls a "source manager" to obtain the
1379
compressed data; you can provide your own source manager if you want the data
1380
to come from somewhere other than a stdio stream.
1381
1382
In both cases, compressed data is processed a bufferload at a time: the
1383
destination or source manager provides a work buffer, and the library invokes
1384
the manager only when the buffer is filled or emptied.  (You could define a
1385
one-character buffer to force the manager to be invoked for each byte, but
1386
that would be rather inefficient.)  The buffer's size and location are
1387
controlled by the manager, not by the library.  For example, if you desired to
1388
decompress a JPEG datastream that was all in memory, you could just make the
1389
buffer pointer and length point to the original data in memory.  Then the
1390
buffer-reload procedure would be invoked only if the decompressor ran off the
1391
end of the datastream, which would indicate an erroneous datastream.
1392
1393
The work buffer is defined as an array of datatype JOCTET, which is generally
1394
"char" or "unsigned char".  On a machine where char is not exactly 8 bits
1395
wide, you must define JOCTET as a wider data type and then modify the data
1396
source and destination modules to transcribe the work arrays into 8-bit units
1397
on external storage.
1398
1399
A data destination manager struct contains a pointer and count defining the
1400
next byte to write in the work buffer and the remaining free space:
1401
1402
	JOCTET * next_output_byte;  /* => next byte to write in buffer */
1403
	size_t free_in_buffer;      /* # of byte spaces remaining in buffer */
1404
1405
The library increments the pointer and decrements the count until the buffer
1406
is filled.  The manager's empty_output_buffer method must reset the pointer
1407
and count.  The manager is expected to remember the buffer's starting address
1408
and total size in private fields not visible to the library.
1409
1410
A data destination manager provides three methods:
1411
1412
init_destination (j_compress_ptr cinfo)
1413
	Initialize destination.  This is called by jpeg_start_compress()
1414
	before any data is actually written.  It must initialize
1415
	next_output_byte and free_in_buffer.  free_in_buffer must be
1416
	initialized to a positive value.
1417
1418
empty_output_buffer (j_compress_ptr cinfo)
1419
	This is called whenever the buffer has filled (free_in_buffer
1420
	reaches zero).  In typical applications, it should write out the
1421
	*entire* buffer (use the saved start address and buffer length;
1422
	ignore the current state of next_output_byte and free_in_buffer).
1423
	Then reset the pointer & count to the start of the buffer, and
1424
	return TRUE indicating that the buffer has been dumped.
1425
	free_in_buffer must be set to a positive value when TRUE is
1426
	returned.  A FALSE return should only be used when I/O suspension is
1427
	desired (this operating mode is discussed in the next section).
1428
1429
term_destination (j_compress_ptr cinfo)
1430
	Terminate destination --- called by jpeg_finish_compress() after all
1431
	data has been written.  In most applications, this must flush any
1432
	data remaining in the buffer.  Use either next_output_byte or
1433
	free_in_buffer to determine how much data is in the buffer.
1434
1435
term_destination() is NOT called by jpeg_abort() or jpeg_destroy().  If you
1436
want the destination manager to be cleaned up during an abort, you must do it
1437
yourself.
1438
1439
You will also need code to create a jpeg_destination_mgr struct, fill in its
1440
method pointers, and insert a pointer to the struct into the "dest" field of
1441
the JPEG compression object.  This can be done in-line in your setup code if
1442
you like, but it's probably cleaner to provide a separate routine similar to
1443
the jpeg_stdio_dest() routine of the supplied destination manager.
1444
1445
Decompression source managers follow a parallel design, but with some
1446
additional frammishes.  The source manager struct contains a pointer and count
1447
defining the next byte to read from the work buffer and the number of bytes
1448
remaining:
1449
1450
	const JOCTET * next_input_byte; /* => next byte to read from buffer */
1451
	size_t bytes_in_buffer;         /* # of bytes remaining in buffer */
1452
1453
The library increments the pointer and decrements the count until the buffer
1454
is emptied.  The manager's fill_input_buffer method must reset the pointer and
1455
count.  In most applications, the manager must remember the buffer's starting
1456
address and total size in private fields not visible to the library.
1457
1458
A data source manager provides five methods:
1459
1460
init_source (j_decompress_ptr cinfo)
1461
	Initialize source.  This is called by jpeg_read_header() before any
1462
	data is actually read.  Unlike init_destination(), it may leave
1463
	bytes_in_buffer set to 0 (in which case a fill_input_buffer() call
1464
	will occur immediately).
1465
1466
fill_input_buffer (j_decompress_ptr cinfo)
1467
	This is called whenever bytes_in_buffer has reached zero and more
1468
	data is wanted.  In typical applications, it should read fresh data
1469
	into the buffer (ignoring the current state of next_input_byte and
1470
	bytes_in_buffer), reset the pointer & count to the start of the
1471
	buffer, and return TRUE indicating that the buffer has been reloaded.
1472
	It is not necessary to fill the buffer entirely, only to obtain at
1473
	least one more byte.  bytes_in_buffer MUST be set to a positive value
1474
	if TRUE is returned.  A FALSE return should only be used when I/O
1475
	suspension is desired (this mode is discussed in the next section).
1476
1477
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
1478
	Skip num_bytes worth of data.  The buffer pointer and count should
1479
	be advanced over num_bytes input bytes, refilling the buffer as
1480
	needed.  This is used to skip over a potentially large amount of
1481
	uninteresting data (such as an APPn marker).  In some applications
1482
	it may be possible to optimize away the reading of the skipped data,
1483
	but it's not clear that being smart is worth much trouble; large
1484
	skips are uncommon.  bytes_in_buffer may be zero on return.
1485
	A zero or negative skip count should be treated as a no-op.
1486
1487
resync_to_restart (j_decompress_ptr cinfo, int desired)
1488
	This routine is called only when the decompressor has failed to find
1489
	a restart (RSTn) marker where one is expected.  Its mission is to
1490
	find a suitable point for resuming decompression.  For most
1491
	applications, we recommend that you just use the default resync
1492
	procedure, jpeg_resync_to_restart().  However, if you are able to back
1493
	up in the input data stream, or if you have a-priori knowledge about
1494
	the likely location of restart markers, you may be able to do better.
1495
	Read the read_restart_marker() and jpeg_resync_to_restart() routines
1496
	in jdmarker.c if you think you'd like to implement your own resync
1497
	procedure.
1498
1499
term_source (j_decompress_ptr cinfo)
1500
	Terminate source --- called by jpeg_finish_decompress() after all
1501
	data has been read.  Often a no-op.
1502
1503
For both fill_input_buffer() and skip_input_data(), there is no such thing
1504
as an EOF return.  If the end of the file has been reached, the routine has
1505
a choice of exiting via ERREXIT() or inserting fake data into the buffer.
1506
In most cases, generating a warning message and inserting a fake EOI marker
1507
is the best course of action --- this will allow the decompressor to output
1508
however much of the image is there.  In pathological cases, the decompressor
1509
may swallow the EOI and again demand data ... just keep feeding it fake EOIs.
1510
jdatasrc.c illustrates the recommended error recovery behavior.
1511
1512
term_source() is NOT called by jpeg_abort() or jpeg_destroy().  If you want
1513
the source manager to be cleaned up during an abort, you must do it yourself.
1514
1515
You will also need code to create a jpeg_source_mgr struct, fill in its method
1516
pointers, and insert a pointer to the struct into the "src" field of the JPEG
1517
decompression object.  This can be done in-line in your setup code if you
1518
like, but it's probably cleaner to provide a separate routine similar to the
1519
jpeg_stdio_src() routine of the supplied source manager.
1520
1521
For more information, consult the stdio source and destination managers
1522
in jdatasrc.c and jdatadst.c.
1523
1524
1525
I/O suspension
1526
--------------
1527
1528
Some applications need to use the JPEG library as an incremental memory-to-
1529
memory filter: when the compressed data buffer is filled or emptied, they want
1530
control to return to the outer loop, rather than expecting that the buffer can
1531
be emptied or reloaded within the data source/destination manager subroutine.
1532
The library supports this need by providing an "I/O suspension" mode, which we
1533
describe in this section.
1534
1535
The I/O suspension mode is not a panacea: nothing is guaranteed about the
1536
maximum amount of time spent in any one call to the library, so it will not
1537
eliminate response-time problems in single-threaded applications.  If you
1538
need guaranteed response time, we suggest you "bite the bullet" and implement
1539
a real multi-tasking capability.
1540
1541
To use I/O suspension, cooperation is needed between the calling application
1542
and the data source or destination manager; you will always need a custom
1543
source/destination manager.  (Please read the previous section if you haven't
1544
already.)  The basic idea is that the empty_output_buffer() or
1545
fill_input_buffer() routine is a no-op, merely returning FALSE to indicate
1546
that it has done nothing.  Upon seeing this, the JPEG library suspends
1547
operation and returns to its caller.  The surrounding application is
1548
responsible for emptying or refilling the work buffer before calling the
1549
JPEG library again.
1550
1551
Compression suspension:
1552
1553
For compression suspension, use an empty_output_buffer() routine that returns
1554
FALSE; typically it will not do anything else.  This will cause the
1555
compressor to return to the caller of jpeg_write_scanlines(), with the return
1556
value indicating that not all the supplied scanlines have been accepted.
1557
The application must make more room in the output buffer, adjust the output
1558
buffer pointer/count appropriately, and then call jpeg_write_scanlines()
1559
again, pointing to the first unconsumed scanline.
1560
1561
When forced to suspend, the compressor will backtrack to a convenient stopping
1562
point (usually the start of the current MCU); it will regenerate some output
1563
data when restarted.  Therefore, although empty_output_buffer() is only
1564
called when the buffer is filled, you should NOT write out the entire buffer
1565
after a suspension.  Write only the data up to the current position of
1566
next_output_byte/free_in_buffer.  The data beyond that point will be
1567
regenerated after resumption.
1568
1569
Because of the backtracking behavior, a good-size output buffer is essential
1570
for efficiency; you don't want the compressor to suspend often.  (In fact, an
1571
overly small buffer could lead to infinite looping, if a single MCU required
1572
more data than would fit in the buffer.)  We recommend a buffer of at least
1573
several Kbytes.  You may want to insert explicit code to ensure that you don't
1574
call jpeg_write_scanlines() unless there is a reasonable amount of space in
1575
the output buffer; in other words, flush the buffer before trying to compress
1576
more data.
1577
1578
The compressor does not allow suspension while it is trying to write JPEG
1579
markers at the beginning and end of the file.  This means that:
1580
  * At the beginning of a compression operation, there must be enough free
1581
    space in the output buffer to hold the header markers (typically 600 or
1582
    so bytes).  The recommended buffer size is bigger than this anyway, so
1583
    this is not a problem as long as you start with an empty buffer.  However,
1584
    this restriction might catch you if you insert large special markers, such
1585
    as a JFIF thumbnail image, without flushing the buffer afterwards.
1586
  * When you call jpeg_finish_compress(), there must be enough space in the
1587
    output buffer to emit any buffered data and the final EOI marker.  In the
1588
    current implementation, half a dozen bytes should suffice for this, but
1589
    for safety's sake we recommend ensuring that at least 100 bytes are free
1590
    before calling jpeg_finish_compress().
1591
1592
A more significant restriction is that jpeg_finish_compress() cannot suspend.
1593
This means you cannot use suspension with multi-pass operating modes, namely
1594
Huffman code optimization and multiple-scan output.  Those modes write the
1595
whole file during jpeg_finish_compress(), which will certainly result in
1596
buffer overrun.  (Note that this restriction applies only to compression,
1597
not decompression.  The decompressor supports input suspension in all of its
1598
operating modes.)
1599
1600
Decompression suspension:
1601
1602
For decompression suspension, use a fill_input_buffer() routine that simply
1603
returns FALSE (except perhaps during error recovery, as discussed below).
1604
This will cause the decompressor to return to its caller with an indication
1605
that suspension has occurred.  This can happen at four places:
1606
  * jpeg_read_header(): will return JPEG_SUSPENDED.
1607
  * jpeg_start_decompress(): will return FALSE, rather than its usual TRUE.
1608
  * jpeg_read_scanlines(): will return the number of scanlines already
1609
	completed (possibly 0).
1610
  * jpeg_finish_decompress(): will return FALSE, rather than its usual TRUE.
1611
The surrounding application must recognize these cases, load more data into
1612
the input buffer, and repeat the call.  In the case of jpeg_read_scanlines(),
1613
increment the passed pointers past any scanlines successfully read.
1614
1615
Just as with compression, the decompressor will typically backtrack to a
1616
convenient restart point before suspending.  When fill_input_buffer() is
1617
called, next_input_byte/bytes_in_buffer point to the current restart point,
1618
which is where the decompressor will backtrack to if FALSE is returned.
1619
The data beyond that position must NOT be discarded if you suspend; it needs
1620
to be re-read upon resumption.  In most implementations, you'll need to shift
1621
this data down to the start of your work buffer and then load more data after
1622
it.  Again, this behavior means that a several-Kbyte work buffer is essential
1623
for decent performance; furthermore, you should load a reasonable amount of
1624
new data before resuming decompression.  (If you loaded, say, only one new
1625
byte each time around, you could waste a LOT of cycles.)
1626
1627
The skip_input_data() source manager routine requires special care in a
1628
suspension scenario.  This routine is NOT granted the ability to suspend the
1629
decompressor; it can decrement bytes_in_buffer to zero, but no more.  If the
1630
requested skip distance exceeds the amount of data currently in the input
1631
buffer, then skip_input_data() must set bytes_in_buffer to zero and record the
1632
additional skip distance somewhere else.  The decompressor will immediately
1633
call fill_input_buffer(), which should return FALSE, which will cause a
1634
suspension return.  The surrounding application must then arrange to discard
1635
the recorded number of bytes before it resumes loading the input buffer.
1636
(Yes, this design is rather baroque, but it avoids complexity in the far more
1637
common case where a non-suspending source manager is used.)
1638
1639
If the input data has been exhausted, we recommend that you emit a warning
1640
and insert dummy EOI markers just as a non-suspending data source manager
1641
would do.  This can be handled either in the surrounding application logic or
1642
within fill_input_buffer(); the latter is probably more efficient.  If
1643
fill_input_buffer() knows that no more data is available, it can set the
1644
pointer/count to point to a dummy EOI marker and then return TRUE just as
1645
though it had read more data in a non-suspending situation.
1646
1647
The decompressor does not attempt to suspend within standard JPEG markers;
1648
instead it will backtrack to the start of the marker and reprocess the whole
1649
marker next time.  Hence the input buffer must be large enough to hold the
1650
longest standard marker in the file.  Standard JPEG markers should normally
1651
not exceed a few hundred bytes each (DHT tables are typically the longest).
1652
We recommend at least a 2K buffer for performance reasons, which is much
1653
larger than any correct marker is likely to be.  For robustness against
1654
damaged marker length counts, you may wish to insert a test in your
1655
application for the case that the input buffer is completely full and yet
1656
the decoder has suspended without consuming any data --- otherwise, if this
1657
situation did occur, it would lead to an endless loop.  (The library can't
1658
provide this test since it has no idea whether "the buffer is full", or
1659
even whether there is a fixed-size input buffer.)
1660
1661
The input buffer would need to be 64K to allow for arbitrary COM or APPn
1662
markers, but these are handled specially: they are either saved into allocated
1663
memory, or skipped over by calling skip_input_data().  In the former case,
1664
suspension is handled correctly, and in the latter case, the problem of
1665
buffer overrun is placed on skip_input_data's shoulders, as explained above.
1666
Note that if you provide your own marker handling routine for large markers,
1667
you should consider how to deal with buffer overflow.
1668
1669
Multiple-buffer management:
1670
1671
In some applications it is desirable to store the compressed data in a linked
1672
list of buffer areas, so as to avoid data copying.  This can be handled by
1673
having empty_output_buffer() or fill_input_buffer() set the pointer and count
1674
to reference the next available buffer; FALSE is returned only if no more
1675
buffers are available.  Although seemingly straightforward, there is a
1676
pitfall in this approach: the backtrack that occurs when FALSE is returned
1677
could back up into an earlier buffer.  For example, when fill_input_buffer()
1678
is called, the current pointer & count indicate the backtrack restart point.
1679
Since fill_input_buffer() will set the pointer and count to refer to a new
1680
buffer, the restart position must be saved somewhere else.  Suppose a second
1681
call to fill_input_buffer() occurs in the same library call, and no
1682
additional input data is available, so fill_input_buffer must return FALSE.
1683
If the JPEG library has not moved the pointer/count forward in the current
1684
buffer, then *the correct restart point is the saved position in the prior
1685
buffer*.  Prior buffers may be discarded only after the library establishes
1686
a restart point within a later buffer.  Similar remarks apply for output into
1687
a chain of buffers.
1688
1689
The library will never attempt to backtrack over a skip_input_data() call,
1690
so any skipped data can be permanently discarded.  You still have to deal
1691
with the case of skipping not-yet-received data, however.
1692
1693
It's much simpler to use only a single buffer; when fill_input_buffer() is
1694
called, move any unconsumed data (beyond the current pointer/count) down to
1695
the beginning of this buffer and then load new data into the remaining buffer
1696
space.  This approach requires a little more data copying but is far easier
1697
to get right.
1698
1699
1700
Progressive JPEG support
1701
------------------------
1702
1703
Progressive JPEG rearranges the stored data into a series of scans of
1704
increasing quality.  In situations where a JPEG file is transmitted across a
1705
slow communications link, a decoder can generate a low-quality image very
1706
quickly from the first scan, then gradually improve the displayed quality as
1707
more scans are received.  The final image after all scans are complete is
1708
identical to that of a regular (sequential) JPEG file of the same quality
1709
setting.  Progressive JPEG files are often slightly smaller than equivalent
1710
sequential JPEG files, but the possibility of incremental display is the main
1711
reason for using progressive JPEG.
1712
1713
The IJG encoder library generates progressive JPEG files when given a
1714
suitable "scan script" defining how to divide the data into scans.
1715
Creation of progressive JPEG files is otherwise transparent to the encoder.
1716
Progressive JPEG files can also be read transparently by the decoder library.
1717
If the decoding application simply uses the library as defined above, it
1718
will receive a final decoded image without any indication that the file was
1719
progressive.  Of course, this approach does not allow incremental display.
1720
To perform incremental display, an application needs to use the decoder
1721
library's "buffered-image" mode, in which it receives a decoded image
1722
multiple times.
1723
1724
Each displayed scan requires about as much work to decode as a full JPEG
1725
image of the same size, so the decoder must be fairly fast in relation to the
1726
data transmission rate in order to make incremental display useful.  However,
1727
it is possible to skip displaying the image and simply add the incoming bits
1728
to the decoder's coefficient buffer.  This is fast because only Huffman
1729
decoding need be done, not IDCT, upsampling, colorspace conversion, etc.
1730
The IJG decoder library allows the application to switch dynamically between
1731
displaying the image and simply absorbing the incoming bits.  A properly
1732
coded application can automatically adapt the number of display passes to
1733
suit the time available as the image is received.  Also, a final
1734
higher-quality display cycle can be performed from the buffered data after
1735
the end of the file is reached.
1736
1737
Progressive compression:
1738
1739
To create a progressive JPEG file (or a multiple-scan sequential JPEG file),
1740
set the scan_info cinfo field to point to an array of scan descriptors, and
1741
perform compression as usual.  Instead of constructing your own scan list,
1742
you can call the jpeg_simple_progression() helper routine to create a
1743
recommended progression sequence; this method should be used by all
1744
applications that don't want to get involved in the nitty-gritty of
1745
progressive scan sequence design.  (If you want to provide user control of
1746
scan sequences, you may wish to borrow the scan script reading code found
1747
in rdswitch.c, so that you can read scan script files just like cjpeg's.)
1748
When scan_info is not NULL, the compression library will store DCT'd data
1749
into a buffer array as jpeg_write_scanlines() is called, and will emit all
1750
the requested scans during jpeg_finish_compress().  This implies that
1751
multiple-scan output cannot be created with a suspending data destination
1752
manager, since jpeg_finish_compress() does not support suspension.  We
1753
should also note that the compressor currently forces Huffman optimization
1754
mode when creating a progressive JPEG file, because the default Huffman
1755
tables are unsuitable for progressive files.
1756
1757
Progressive decompression:
1758
1759
When buffered-image mode is not used, the decoder library will read all of
1760
a multi-scan file during jpeg_start_decompress(), so that it can provide a
1761
final decoded image.  (Here "multi-scan" means either progressive or
1762
multi-scan sequential.)  This makes multi-scan files transparent to the
1763
decoding application.  However, existing applications that used suspending
1764
input with version 5 of the IJG library will need to be modified to check
1765
for a suspension return from jpeg_start_decompress().
1766
1767
To perform incremental display, an application must use the library's
1768
buffered-image mode.  This is described in the next section.
1769
1770
1771
Buffered-image mode
1772
-------------------
1773
1774
In buffered-image mode, the library stores the partially decoded image in a
1775
coefficient buffer, from which it can be read out as many times as desired.
1776
This mode is typically used for incremental display of progressive JPEG files,
1777
but it can be used with any JPEG file.  Each scan of a progressive JPEG file
1778
adds more data (more detail) to the buffered image.  The application can
1779
display in lockstep with the source file (one display pass per input scan),
1780
or it can allow input processing to outrun display processing.  By making
1781
input and display processing run independently, it is possible for the
1782
application to adapt progressive display to a wide range of data transmission
1783
rates.
1784
1785
The basic control flow for buffered-image decoding is
1786
1787
	jpeg_create_decompress()
1788
	set data source
1789
	jpeg_read_header()
1790
	set overall decompression parameters
1791
	cinfo.buffered_image = TRUE;	/* select buffered-image mode */
1792
	jpeg_start_decompress()
1793
	for (each output pass) {
1794
	    adjust output decompression parameters if required
1795
	    jpeg_start_output()		/* start a new output pass */
1796
	    for (all scanlines in image) {
1797
	        jpeg_read_scanlines()
1798
	        display scanlines
1799
	    }
1800
	    jpeg_finish_output()	/* terminate output pass */
1801
	}
1802
	jpeg_finish_decompress()
1803
	jpeg_destroy_decompress()
1804
1805
This differs from ordinary unbuffered decoding in that there is an additional
1806
level of looping.  The application can choose how many output passes to make
1807
and how to display each pass.
1808
1809
The simplest approach to displaying progressive images is to do one display
1810
pass for each scan appearing in the input file.  In this case the outer loop
1811
condition is typically
1812
	while (! jpeg_input_complete(&cinfo))
1813
and the start-output call should read
1814
	jpeg_start_output(&cinfo, cinfo.input_scan_number);
1815
The second parameter to jpeg_start_output() indicates which scan of the input
1816
file is to be displayed; the scans are numbered starting at 1 for this
1817
purpose.  (You can use a loop counter starting at 1 if you like, but using
1818
the library's input scan counter is easier.)  The library automatically reads
1819
data as necessary to complete each requested scan, and jpeg_finish_output()
1820
advances to the next scan or end-of-image marker (hence input_scan_number
1821
will be incremented by the time control arrives back at jpeg_start_output()).
1822
With this technique, data is read from the input file only as needed, and
1823
input and output processing run in lockstep.
1824
1825
After reading the final scan and reaching the end of the input file, the
1826
buffered image remains available; it can be read additional times by
1827
repeating the jpeg_start_output()/jpeg_read_scanlines()/jpeg_finish_output()
1828
sequence.  For example, a useful technique is to use fast one-pass color
1829
quantization for display passes made while the image is arriving, followed by
1830
a final display pass using two-pass quantization for highest quality.  This
1831
is done by changing the library parameters before the final output pass.
1832
Changing parameters between passes is discussed in detail below.
1833
1834
In general the last scan of a progressive file cannot be recognized as such
1835
until after it is read, so a post-input display pass is the best approach if
1836
you want special processing in the final pass.
1837
1838
When done with the image, be sure to call jpeg_finish_decompress() to release
1839
the buffered image (or just use jpeg_destroy_decompress()).
1840
1841
If input data arrives faster than it can be displayed, the application can
1842
cause the library to decode input data in advance of what's needed to produce
1843
output.  This is done by calling the routine jpeg_consume_input().
1844
The return value is one of the following:
1845
	JPEG_REACHED_SOS:    reached an SOS marker (the start of a new scan)
1846
	JPEG_REACHED_EOI:    reached the EOI marker (end of image)
1847
	JPEG_ROW_COMPLETED:  completed reading one MCU row of compressed data
1848
	JPEG_SCAN_COMPLETED: completed reading last MCU row of current scan
1849
	JPEG_SUSPENDED:      suspended before completing any of the above
1850
(JPEG_SUSPENDED can occur only if a suspending data source is used.)  This
1851
routine can be called at any time after initializing the JPEG object.  It
1852
reads some additional data and returns when one of the indicated significant
1853
events occurs.  (If called after the EOI marker is reached, it will
1854
immediately return JPEG_REACHED_EOI without attempting to read more data.)
1855
1856
The library's output processing will automatically call jpeg_consume_input()
1857
whenever the output processing overtakes the input; thus, simple lockstep
1858
display requires no direct calls to jpeg_consume_input().  But by adding
1859
calls to jpeg_consume_input(), you can absorb data in advance of what is
1860
being displayed.  This has two benefits:
1861
  * You can limit buildup of unprocessed data in your input buffer.
1862
  * You can eliminate extra display passes by paying attention to the
1863
    state of the library's input processing.
1864
1865
The first of these benefits only requires interspersing calls to
1866
jpeg_consume_input() with your display operations and any other processing
1867
you may be doing.  To avoid wasting cycles due to backtracking, it's best to
1868
call jpeg_consume_input() only after a hundred or so new bytes have arrived.
1869
This is discussed further under "I/O suspension", above.  (Note: the JPEG
1870
library currently is not thread-safe.  You must not call jpeg_consume_input()
1871
from one thread of control if a different library routine is working on the
1872
same JPEG object in another thread.)
1873
1874
When input arrives fast enough that more than one new scan is available
1875
before you start a new output pass, you may as well skip the output pass
1876
corresponding to the completed scan.  This occurs for free if you pass
1877
cinfo.input_scan_number as the target scan number to jpeg_start_output().
1878
The input_scan_number field is simply the index of the scan currently being
1879
consumed by the input processor.  You can ensure that this is up-to-date by
1880
emptying the input buffer just before calling jpeg_start_output(): call
1881
jpeg_consume_input() repeatedly until it returns JPEG_SUSPENDED or
1882
JPEG_REACHED_EOI.
1883
1884
The target scan number passed to jpeg_start_output() is saved in the
1885
cinfo.output_scan_number field.  The library's output processing calls
1886
jpeg_consume_input() whenever the current input scan number and row within
1887
that scan is less than or equal to the current output scan number and row.
1888
Thus, input processing can "get ahead" of the output processing but is not
1889
allowed to "fall behind".  You can achieve several different effects by
1890
manipulating this interlock rule.  For example, if you pass a target scan
1891
number greater than the current input scan number, the output processor will
1892
wait until that scan starts to arrive before producing any output.  (To avoid
1893
an infinite loop, the target scan number is automatically reset to the last
1894
scan number when the end of image is reached.  Thus, if you specify a large
1895
target scan number, the library will just absorb the entire input file and
1896
then perform an output pass.  This is effectively the same as what
1897
jpeg_start_decompress() does when you don't select buffered-image mode.)
1898
When you pass a target scan number equal to the current input scan number,
1899
the image is displayed no faster than the current input scan arrives.  The
1900
final possibility is to pass a target scan number less than the current input
1901
scan number; this disables the input/output interlock and causes the output
1902
processor to simply display whatever it finds in the image buffer, without
1903
waiting for input.  (However, the library will not accept a target scan
1904
number less than one, so you can't avoid waiting for the first scan.)
1905
1906
When data is arriving faster than the output display processing can advance
1907
through the image, jpeg_consume_input() will store data into the buffered
1908
image beyond the point at which the output processing is reading data out
1909
again.  If the input arrives fast enough, it may "wrap around" the buffer to
1910
the point where the input is more than one whole scan ahead of the output.
1911
If the output processing simply proceeds through its display pass without
1912
paying attention to the input, the effect seen on-screen is that the lower
1913
part of the image is one or more scans better in quality than the upper part.
1914
Then, when the next output scan is started, you have a choice of what target
1915
scan number to use.  The recommended choice is to use the current input scan
1916
number at that time, which implies that you've skipped the output scans
1917
corresponding to the input scans that were completed while you processed the
1918
previous output scan.  In this way, the decoder automatically adapts its
1919
speed to the arriving data, by skipping output scans as necessary to keep up
1920
with the arriving data.
1921
1922
When using this strategy, you'll want to be sure that you perform a final
1923
output pass after receiving all the data; otherwise your last display may not
1924
be full quality across the whole screen.  So the right outer loop logic is
1925
something like this:
1926
	do {
1927
	    absorb any waiting input by calling jpeg_consume_input()
1928
	    final_pass = jpeg_input_complete(&cinfo);
1929
	    adjust output decompression parameters if required
1930
	    jpeg_start_output(&cinfo, cinfo.input_scan_number);
1931
	    ...
1932
	    jpeg_finish_output()
1933
	} while (! final_pass);
1934
rather than quitting as soon as jpeg_input_complete() returns TRUE.  This
1935
arrangement makes it simple to use higher-quality decoding parameters
1936
for the final pass.  But if you don't want to use special parameters for
1937
the final pass, the right loop logic is like this:
1938
	for (;;) {
1939
	    absorb any waiting input by calling jpeg_consume_input()
1940
	    jpeg_start_output(&cinfo, cinfo.input_scan_number);
1941
	    ...
1942
	    jpeg_finish_output()
1943
	    if (jpeg_input_complete(&cinfo) &&
1944
	        cinfo.input_scan_number == cinfo.output_scan_number)
1945
	      break;
1946
	}
1947
In this case you don't need to know in advance whether an output pass is to
1948
be the last one, so it's not necessary to have reached EOF before starting
1949
the final output pass; rather, what you want to test is whether the output
1950
pass was performed in sync with the final input scan.  This form of the loop
1951
will avoid an extra output pass whenever the decoder is able (or nearly able)
1952
to keep up with the incoming data.
1953
1954
When the data transmission speed is high, you might begin a display pass,
1955
then find that much or all of the file has arrived before you can complete
1956
the pass.  (You can detect this by noting the JPEG_REACHED_EOI return code
1957
from jpeg_consume_input(), or equivalently by testing jpeg_input_complete().)
1958
In this situation you may wish to abort the current display pass and start a
1959
new one using the newly arrived information.  To do so, just call
1960
jpeg_finish_output() and then start a new pass with jpeg_start_output().
1961
1962
A variant strategy is to abort and restart display if more than one complete
1963
scan arrives during an output pass; this can be detected by noting
1964
JPEG_REACHED_SOS returns and/or examining cinfo.input_scan_number.  This
1965
idea should be employed with caution, however, since the display process
1966
might never get to the bottom of the image before being aborted, resulting
1967
in the lower part of the screen being several passes worse than the upper.
1968
In most cases it's probably best to abort an output pass only if the whole
1969
file has arrived and you want to begin the final output pass immediately.
1970
1971
When receiving data across a communication link, we recommend always using
1972
the current input scan number for the output target scan number; if a
1973
higher-quality final pass is to be done, it should be started (aborting any
1974
incomplete output pass) as soon as the end of file is received.  However,
1975
many other strategies are possible.  For example, the application can examine
1976
the parameters of the current input scan and decide whether to display it or
1977
not.  If the scan contains only chroma data, one might choose not to use it
1978
as the target scan, expecting that the scan will be small and will arrive
1979
quickly.  To skip to the next scan, call jpeg_consume_input() until it
1980
returns JPEG_REACHED_SOS or JPEG_REACHED_EOI.  Or just use the next higher
1981
number as the target scan for jpeg_start_output(); but that method doesn't
1982
let you inspect the next scan's parameters before deciding to display it.
1983
1984
1985
In buffered-image mode, jpeg_start_decompress() never performs input and
1986
thus never suspends.  An application that uses input suspension with
1987
buffered-image mode must be prepared for suspension returns from these
1988
routines:
1989
* jpeg_start_output() performs input only if you request 2-pass quantization
1990
  and the target scan isn't fully read yet.  (This is discussed below.)
1991
* jpeg_read_scanlines(), as always, returns the number of scanlines that it
1992
  was able to produce before suspending.
1993
* jpeg_finish_output() will read any markers following the target scan,
1994
  up to the end of the file or the SOS marker that begins another scan.
1995
  (But it reads no input if jpeg_consume_input() has already reached the
1996
  end of the file or a SOS marker beyond the target output scan.)
1997
* jpeg_finish_decompress() will read until the end of file, and thus can
1998
  suspend if the end hasn't already been reached (as can be tested by
1999
  calling jpeg_input_complete()).
2000
jpeg_start_output(), jpeg_finish_output(), and jpeg_finish_decompress()
2001
all return TRUE if they completed their tasks, FALSE if they had to suspend.
2002
In the event of a FALSE return, the application must load more input data
2003
and repeat the call.  Applications that use non-suspending data sources need
2004
not check the return values of these three routines.
2005
2006
2007
It is possible to change decoding parameters between output passes in the
2008
buffered-image mode.  The decoder library currently supports only very
2009
limited changes of parameters.  ONLY THE FOLLOWING parameter changes are
2010
allowed after jpeg_start_decompress() is called:
2011
* dct_method can be changed before each call to jpeg_start_output().
2012
  For example, one could use a fast DCT method for early scans, changing
2013
  to a higher quality method for the final scan.
2014
* dither_mode can be changed before each call to jpeg_start_output();
2015
  of course this has no impact if not using color quantization.  Typically
2016
  one would use ordered dither for initial passes, then switch to
2017
  Floyd-Steinberg dither for the final pass.  Caution: changing dither mode
2018
  can cause more memory to be allocated by the library.  Although the amount
2019
  of memory involved is not large (a scanline or so), it may cause the
2020
  initial max_memory_to_use specification to be exceeded, which in the worst
2021
  case would result in an out-of-memory failure.
2022
* do_block_smoothing can be changed before each call to jpeg_start_output().
2023
  This setting is relevant only when decoding a progressive JPEG image.
2024
  During the first DC-only scan, block smoothing provides a very "fuzzy" look
2025
  instead of the very "blocky" look seen without it; which is better seems a
2026
  matter of personal taste.  But block smoothing is nearly always a win
2027
  during later stages, especially when decoding a successive-approximation
2028
  image: smoothing helps to hide the slight blockiness that otherwise shows
2029
  up on smooth gradients until the lowest coefficient bits are sent.
2030
* Color quantization mode can be changed under the rules described below.
2031
  You *cannot* change between full-color and quantized output (because that
2032
  would alter the required I/O buffer sizes), but you can change which
2033
  quantization method is used.
2034
2035
When generating color-quantized output, changing quantization method is a
2036
very useful way of switching between high-speed and high-quality display.
2037
The library allows you to change among its three quantization methods:
2038
1. Single-pass quantization to a fixed color cube.
2039
   Selected by cinfo.two_pass_quantize = FALSE and cinfo.colormap = NULL.
2040
2. Single-pass quantization to an application-supplied colormap.
2041
   Selected by setting cinfo.colormap to point to the colormap (the value of
2042
   two_pass_quantize is ignored); also set cinfo.actual_number_of_colors.
2043
3. Two-pass quantization to a colormap chosen specifically for the image.
2044
   Selected by cinfo.two_pass_quantize = TRUE and cinfo.colormap = NULL.
2045
   (This is the default setting selected by jpeg_read_header, but it is
2046
   probably NOT what you want for the first pass of progressive display!)
2047
These methods offer successively better quality and lesser speed.  However,
2048
only the first method is available for quantizing in non-RGB color spaces.
2049
2050
IMPORTANT: because the different quantizer methods have very different
2051
working-storage requirements, the library requires you to indicate which
2052
one(s) you intend to use before you call jpeg_start_decompress().  (If we did
2053
not require this, the max_memory_to_use setting would be a complete fiction.)
2054
You do this by setting one or more of these three cinfo fields to TRUE:
2055
	enable_1pass_quant		Fixed color cube colormap
2056
	enable_external_quant		Externally-supplied colormap
2057
	enable_2pass_quant		Two-pass custom colormap
2058
All three are initialized FALSE by jpeg_read_header().  But
2059
jpeg_start_decompress() automatically sets TRUE the one selected by the
2060
current two_pass_quantize and colormap settings, so you only need to set the
2061
enable flags for any other quantization methods you plan to change to later.
2062
2063
After setting the enable flags correctly at jpeg_start_decompress() time, you
2064
can change to any enabled quantization method by setting two_pass_quantize
2065
and colormap properly just before calling jpeg_start_output().  The following
2066
special rules apply:
2067
1. You must explicitly set cinfo.colormap to NULL when switching to 1-pass
2068
   or 2-pass mode from a different mode, or when you want the 2-pass
2069
   quantizer to be re-run to generate a new colormap.
2070
2. To switch to an external colormap, or to change to a different external
2071
   colormap than was used on the prior pass, you must call
2072
   jpeg_new_colormap() after setting cinfo.colormap.
2073
NOTE: if you want to use the same colormap as was used in the prior pass,
2074
you should not do either of these things.  This will save some nontrivial
2075
switchover costs.
2076
(These requirements exist because cinfo.colormap will always be non-NULL
2077
after completing a prior output pass, since both the 1-pass and 2-pass
2078
quantizers set it to point to their output colormaps.  Thus you have to
2079
do one of these two things to notify the library that something has changed.
2080
Yup, it's a bit klugy, but it's necessary to do it this way for backwards
2081
compatibility.)
2082
2083
Note that in buffered-image mode, the library generates any requested colormap
2084
during jpeg_start_output(), not during jpeg_start_decompress().
2085
2086
When using two-pass quantization, jpeg_start_output() makes a pass over the
2087
buffered image to determine the optimum color map; it therefore may take a
2088
significant amount of time, whereas ordinarily it does little work.  The
2089
progress monitor hook is called during this pass, if defined.  It is also
2090
important to realize that if the specified target scan number is greater than
2091
or equal to the current input scan number, jpeg_start_output() will attempt
2092
to consume input as it makes this pass.  If you use a suspending data source,
2093
you need to check for a FALSE return from jpeg_start_output() under these
2094
conditions.  The combination of 2-pass quantization and a not-yet-fully-read
2095
target scan is the only case in which jpeg_start_output() will consume input.
2096
2097
2098
Application authors who support buffered-image mode may be tempted to use it
2099
for all JPEG images, even single-scan ones.  This will work, but it is
2100
inefficient: there is no need to create an image-sized coefficient buffer for
2101
single-scan images.  Requesting buffered-image mode for such an image wastes
2102
memory.  Worse, it can cost time on large images, since the buffered data has
2103
to be swapped out or written to a temporary file.  If you are concerned about
2104
maximum performance on baseline JPEG files, you should use buffered-image
2105
mode only when the incoming file actually has multiple scans.  This can be
2106
tested by calling jpeg_has_multiple_scans(), which will return a correct
2107
result at any time after jpeg_read_header() completes.
2108
2109
It is also worth noting that when you use jpeg_consume_input() to let input
2110
processing get ahead of output processing, the resulting pattern of access to
2111
the coefficient buffer is quite nonsequential.  It's best to use the memory
2112
manager jmemnobs.c if you can (ie, if you have enough real or virtual main
2113
memory).  If not, at least make sure that max_memory_to_use is set as high as
2114
possible.  If the JPEG memory manager has to use a temporary file, you will
2115
probably see a lot of disk traffic and poor performance.  (This could be
2116
improved with additional work on the memory manager, but we haven't gotten
2117
around to it yet.)
2118
2119
In some applications it may be convenient to use jpeg_consume_input() for all
2120
input processing, including reading the initial markers; that is, you may
2121
wish to call jpeg_consume_input() instead of jpeg_read_header() during
2122
startup.  This works, but note that you must check for JPEG_REACHED_SOS and
2123
JPEG_REACHED_EOI return codes as the equivalent of jpeg_read_header's codes.
2124
Once the first SOS marker has been reached, you must call
2125
jpeg_start_decompress() before jpeg_consume_input() will consume more input;
2126
it'll just keep returning JPEG_REACHED_SOS until you do.  If you read a
2127
tables-only file this way, jpeg_consume_input() will return JPEG_REACHED_EOI
2128
without ever returning JPEG_REACHED_SOS; be sure to check for this case.
2129
If this happens, the decompressor will not read any more input until you call
2130
jpeg_abort() to reset it.  It is OK to call jpeg_consume_input() even when not
2131
using buffered-image mode, but in that case it's basically a no-op after the
2132
initial markers have been read: it will just return JPEG_SUSPENDED.
2133
2134
2135
Abbreviated datastreams and multiple images
2136
-------------------------------------------
2137
2138
A JPEG compression or decompression object can be reused to process multiple
2139
images.  This saves a small amount of time per image by eliminating the
2140
"create" and "destroy" operations, but that isn't the real purpose of the
2141
feature.  Rather, reuse of an object provides support for abbreviated JPEG
2142
datastreams.  Object reuse can also simplify processing a series of images in
2143
a single input or output file.  This section explains these features.
2144
2145
A JPEG file normally contains several hundred bytes worth of quantization
2146
and Huffman tables.  In a situation where many images will be stored or
2147
transmitted with identical tables, this may represent an annoying overhead.
2148
The JPEG standard therefore permits tables to be omitted.  The standard
2149
defines three classes of JPEG datastreams:
2150
  * "Interchange" datastreams contain an image and all tables needed to decode
2151
     the image.  These are the usual kind of JPEG file.
2152
  * "Abbreviated image" datastreams contain an image, but are missing some or
2153
    all of the tables needed to decode that image.
2154
  * "Abbreviated table specification" (henceforth "tables-only") datastreams
2155
    contain only table specifications.
2156
To decode an abbreviated image, it is necessary to load the missing table(s)
2157
into the decoder beforehand.  This can be accomplished by reading a separate
2158
tables-only file.  A variant scheme uses a series of images in which the first
2159
image is an interchange (complete) datastream, while subsequent ones are
2160
abbreviated and rely on the tables loaded by the first image.  It is assumed
2161
that once the decoder has read a table, it will remember that table until a
2162
new definition for the same table number is encountered.
2163
2164
It is the application designer's responsibility to figure out how to associate
2165
the correct tables with an abbreviated image.  While abbreviated datastreams
2166
can be useful in a closed environment, their use is strongly discouraged in
2167
any situation where data exchange with other applications might be needed.
2168
Caveat designer.
2169
2170
The JPEG library provides support for reading and writing any combination of
2171
tables-only datastreams and abbreviated images.  In both compression and
2172
decompression objects, a quantization or Huffman table will be retained for
2173
the lifetime of the object, unless it is overwritten by a new table definition.
2174
2175
2176
To create abbreviated image datastreams, it is only necessary to tell the
2177
compressor not to emit some or all of the tables it is using.  Each
2178
quantization and Huffman table struct contains a boolean field "sent_table",
2179
which normally is initialized to FALSE.  For each table used by the image, the
2180
header-writing process emits the table and sets sent_table = TRUE unless it is
2181
already TRUE.  (In normal usage, this prevents outputting the same table
2182
definition multiple times, as would otherwise occur because the chroma
2183
components typically share tables.)  Thus, setting this field to TRUE before
2184
calling jpeg_start_compress() will prevent the table from being written at
2185
all.
2186
2187
If you want to create a "pure" abbreviated image file containing no tables,
2188
just call "jpeg_suppress_tables(&cinfo, TRUE)" after constructing all the
2189
tables.  If you want to emit some but not all tables, you'll need to set the
2190
individual sent_table fields directly.
2191
2192
To create an abbreviated image, you must also call jpeg_start_compress()
2193
with a second parameter of FALSE, not TRUE.  Otherwise jpeg_start_compress()
2194
will force all the sent_table fields to FALSE.  (This is a safety feature to
2195
prevent abbreviated images from being created accidentally.)
2196
2197
To create a tables-only file, perform the same parameter setup that you
2198
normally would, but instead of calling jpeg_start_compress() and so on, call
2199
jpeg_write_tables(&cinfo).  This will write an abbreviated datastream
2200
containing only SOI, DQT and/or DHT markers, and EOI.  All the quantization
2201
and Huffman tables that are currently defined in the compression object will
2202
be emitted unless their sent_tables flag is already TRUE, and then all the
2203
sent_tables flags will be set TRUE.
2204
2205
A sure-fire way to create matching tables-only and abbreviated image files
2206
is to proceed as follows:
2207
2208
	create JPEG compression object
2209
	set JPEG parameters
2210
	set destination to tables-only file
2211
	jpeg_write_tables(&cinfo);
2212
	set destination to image file
2213
	jpeg_start_compress(&cinfo, FALSE);
2214
	write data...
2215
	jpeg_finish_compress(&cinfo);
2216
2217
Since the JPEG parameters are not altered between writing the table file and
2218
the abbreviated image file, the same tables are sure to be used.  Of course,
2219
you can repeat the jpeg_start_compress() ... jpeg_finish_compress() sequence
2220
many times to produce many abbreviated image files matching the table file.
2221
2222
You cannot suppress output of the computed Huffman tables when Huffman
2223
optimization is selected.  (If you could, there'd be no way to decode the
2224
image...)  Generally, you don't want to set optimize_coding = TRUE when
2225
you are trying to produce abbreviated files.
2226
2227
In some cases you might want to compress an image using tables which are
2228
not stored in the application, but are defined in an interchange or
2229
tables-only file readable by the application.  This can be done by setting up
2230
a JPEG decompression object to read the specification file, then copying the
2231
tables into your compression object.  See jpeg_copy_critical_parameters()
2232
for an example of copying quantization tables.
2233
2234
2235
To read abbreviated image files, you simply need to load the proper tables
2236
into the decompression object before trying to read the abbreviated image.
2237
If the proper tables are stored in the application program, you can just
2238
allocate the table structs and fill in their contents directly.  For example,
2239
to load a fixed quantization table into table slot "n":
2240
2241
    if (cinfo.quant_tbl_ptrs[n] == NULL)
2242
      cinfo.quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) &cinfo);
2243
    quant_ptr = cinfo.quant_tbl_ptrs[n];	/* quant_ptr is JQUANT_TBL* */
2244
    for (i = 0; i < 64; i++) {
2245
      /* Qtable[] is desired quantization table, in natural array order */
2246
      quant_ptr->quantval[i] = Qtable[i];
2247
    }
2248
2249
Code to load a fixed Huffman table is typically (for AC table "n"):
2250
2251
    if (cinfo.ac_huff_tbl_ptrs[n] == NULL)
2252
      cinfo.ac_huff_tbl_ptrs[n] = jpeg_alloc_huff_table((j_common_ptr) &cinfo);
2253
    huff_ptr = cinfo.ac_huff_tbl_ptrs[n];	/* huff_ptr is JHUFF_TBL* */
2254
    for (i = 1; i <= 16; i++) {
2255
      /* counts[i] is number of Huffman codes of length i bits, i=1..16 */
2256
      huff_ptr->bits[i] = counts[i];
2257
    }
2258
    for (i = 0; i < 256; i++) {
2259
      /* symbols[] is the list of Huffman symbols, in code-length order */
2260
      huff_ptr->huffval[i] = symbols[i];
2261
    }
2262
2263
(Note that trying to set cinfo.quant_tbl_ptrs[n] to point directly at a
2264
constant JQUANT_TBL object is not safe.  If the incoming file happened to
2265
contain a quantization table definition, your master table would get
2266
overwritten!  Instead allocate a working table copy and copy the master table
2267
into it, as illustrated above.  Ditto for Huffman tables, of course.)
2268
2269
You might want to read the tables from a tables-only file, rather than
2270
hard-wiring them into your application.  The jpeg_read_header() call is
2271
sufficient to read a tables-only file.  You must pass a second parameter of
2272
FALSE to indicate that you do not require an image to be present.  Thus, the
2273
typical scenario is
2274
2275
	create JPEG decompression object
2276
	set source to tables-only file
2277
	jpeg_read_header(&cinfo, FALSE);
2278
	set source to abbreviated image file
2279
	jpeg_read_header(&cinfo, TRUE);
2280
	set decompression parameters
2281
	jpeg_start_decompress(&cinfo);
2282
	read data...
2283
	jpeg_finish_decompress(&cinfo);
2284
2285
In some cases, you may want to read a file without knowing whether it contains
2286
an image or just tables.  In that case, pass FALSE and check the return value
2287
from jpeg_read_header(): it will be JPEG_HEADER_OK if an image was found,
2288
JPEG_HEADER_TABLES_ONLY if only tables were found.  (A third return value,
2289
JPEG_SUSPENDED, is possible when using a suspending data source manager.)
2290
Note that jpeg_read_header() will not complain if you read an abbreviated
2291
image for which you haven't loaded the missing tables; the missing-table check
2292
occurs later, in jpeg_start_decompress().
2293
2294
2295
It is possible to read a series of images from a single source file by
2296
repeating the jpeg_read_header() ... jpeg_finish_decompress() sequence,
2297
without releasing/recreating the JPEG object or the data source module.
2298
(If you did reinitialize, any partial bufferload left in the data source
2299
buffer at the end of one image would be discarded, causing you to lose the
2300
start of the next image.)  When you use this method, stored tables are
2301
automatically carried forward, so some of the images can be abbreviated images
2302
that depend on tables from earlier images.
2303
2304
If you intend to write a series of images into a single destination file,
2305
you might want to make a specialized data destination module that doesn't
2306
flush the output buffer at term_destination() time.  This would speed things
2307
up by some trifling amount.  Of course, you'd need to remember to flush the
2308
buffer after the last image.  You can make the later images be abbreviated
2309
ones by passing FALSE to jpeg_start_compress().
2310
2311
2312
Special markers
2313
---------------
2314
2315
Some applications may need to insert or extract special data in the JPEG
2316
datastream.  The JPEG standard provides marker types "COM" (comment) and
2317
"APP0" through "APP15" (application) to hold application-specific data.
2318
Unfortunately, the use of these markers is not specified by the standard.
2319
COM markers are fairly widely used to hold user-supplied text.  The JFIF file
2320
format spec uses APP0 markers with specified initial strings to hold certain
2321
data.  Adobe applications use APP14 markers beginning with the string "Adobe"
2322
for miscellaneous data.  Other APPn markers are rarely seen, but might
2323
contain almost anything.
2324
2325
If you wish to store user-supplied text, we recommend you use COM markers
2326
and place readable 7-bit ASCII text in them.  Newline conventions are not
2327
standardized --- expect to find LF (Unix style), CR/LF (DOS style), or CR
2328
(Mac style).  A robust COM reader should be able to cope with random binary
2329
garbage, including nulls, since some applications generate COM markers
2330
containing non-ASCII junk.  (But yours should not be one of them.)
2331
2332
For program-supplied data, use an APPn marker, and be sure to begin it with an
2333
identifying string so that you can tell whether the marker is actually yours.
2334
It's probably best to avoid using APP0 or APP14 for any private markers.
2335
(NOTE: the upcoming SPIFF standard will use APP8 markers; we recommend you
2336
not use APP8 markers for any private purposes, either.)
2337
2338
Keep in mind that at most 65533 bytes can be put into one marker, but you
2339
can have as many markers as you like.
2340
2341
By default, the IJG compression library will write a JFIF APP0 marker if the
2342
selected JPEG colorspace is grayscale or YCbCr, or an Adobe APP14 marker if
2343
the selected colorspace is RGB, CMYK, or YCCK.  You can disable this, but
2344
we don't recommend it.  The decompression library will recognize JFIF and
2345
Adobe markers and will set the JPEG colorspace properly when one is found.
2346
2347
2348
You can write special markers immediately following the datastream header by
2349
calling jpeg_write_marker() after jpeg_start_compress() and before the first
2350
call to jpeg_write_scanlines().  When you do this, the markers appear after
2351
the SOI and the JFIF APP0 and Adobe APP14 markers (if written), but before
2352
all else.  Specify the marker type parameter as "JPEG_COM" for COM or
2353
"JPEG_APP0 + n" for APPn.  (Actually, jpeg_write_marker will let you write
2354
any marker type, but we don't recommend writing any other kinds of marker.)
2355
For example, to write a user comment string pointed to by comment_text:
2356
	jpeg_write_marker(cinfo, JPEG_COM, comment_text, strlen(comment_text));
2357
2358
If it's not convenient to store all the marker data in memory at once,
2359
you can instead call jpeg_write_m_header() followed by multiple calls to
2360
jpeg_write_m_byte().  If you do it this way, it's your responsibility to
2361
call jpeg_write_m_byte() exactly the number of times given in the length
2362
parameter to jpeg_write_m_header().  (This method lets you empty the
2363
output buffer partway through a marker, which might be important when
2364
using a suspending data destination module.  In any case, if you are using
2365
a suspending destination, you should flush its buffer after inserting
2366
any special markers.  See "I/O suspension".)
2367
2368
Or, if you prefer to synthesize the marker byte sequence yourself,
2369
you can just cram it straight into the data destination module.
2370
2371
If you are writing JFIF 1.02 extension markers (thumbnail images), don't
2372
forget to set cinfo.JFIF_minor_version = 2 so that the encoder will write the
2373
correct JFIF version number in the JFIF header marker.  The library's default
2374
is to write version 1.01, but that's wrong if you insert any 1.02 extension
2375
markers.  (We could probably get away with just defaulting to 1.02, but there
2376
used to be broken decoders that would complain about unknown minor version
2377
numbers.  To reduce compatibility risks it's safest not to write 1.02 unless
2378
you are actually using 1.02 extensions.)
2379
2380
2381
When reading, two methods of handling special markers are available:
2382
1. You can ask the library to save the contents of COM and/or APPn markers
2383
into memory, and then examine them at your leisure afterwards.
2384
2. You can supply your own routine to process COM and/or APPn markers
2385
on-the-fly as they are read.
2386
The first method is simpler to use, especially if you are using a suspending
2387
data source; writing a marker processor that copes with input suspension is
2388
not easy (consider what happens if the marker is longer than your available
2389
input buffer).  However, the second method conserves memory since the marker
2390
data need not be kept around after it's been processed.
2391
2392
For either method, you'd normally set up marker handling after creating a
2393
decompression object and before calling jpeg_read_header(), because the
2394
markers of interest will typically be near the head of the file and so will
2395
be scanned by jpeg_read_header.  Once you've established a marker handling
2396
method, it will be used for the life of that decompression object
2397
(potentially many datastreams), unless you change it.  Marker handling is
2398
determined separately for COM markers and for each APPn marker code.
2399
2400
2401
To save the contents of special markers in memory, call
2402
	jpeg_save_markers(cinfo, marker_code, length_limit)
2403
where marker_code is the marker type to save, JPEG_COM or JPEG_APP0+n.
2404
(To arrange to save all the special marker types, you need to call this
2405
routine 17 times, for COM and APP0-APP15.)  If the incoming marker is longer
2406
than length_limit data bytes, only length_limit bytes will be saved; this
2407
parameter allows you to avoid chewing up memory when you only need to see the
2408
first few bytes of a potentially large marker.  If you want to save all the
2409
data, set length_limit to 0xFFFF; that is enough since marker lengths are only
2410
16 bits.  As a special case, setting length_limit to 0 prevents that marker
2411
type from being saved at all.  (That is the default behavior, in fact.)
2412
2413
After jpeg_read_header() completes, you can examine the special markers by
2414
following the cinfo->marker_list pointer chain.  All the special markers in
2415
the file appear in this list, in order of their occurrence in the file (but
2416
omitting any markers of types you didn't ask for).  Both the original data
2417
length and the saved data length are recorded for each list entry; the latter
2418
will not exceed length_limit for the particular marker type.  Note that these
2419
lengths exclude the marker length word, whereas the stored representation
2420
within the JPEG file includes it.  (Hence the maximum data length is really
2421
only 65533.)
2422
2423
It is possible that additional special markers appear in the file beyond the
2424
SOS marker at which jpeg_read_header stops; if so, the marker list will be
2425
extended during reading of the rest of the file.  This is not expected to be
2426
common, however.  If you are short on memory you may want to reset the length
2427
limit to zero for all marker types after finishing jpeg_read_header, to
2428
ensure that the max_memory_to_use setting cannot be exceeded due to addition
2429
of later markers.
2430
2431
The marker list remains stored until you call jpeg_finish_decompress or
2432
jpeg_abort, at which point the memory is freed and the list is set to empty.
2433
(jpeg_destroy also releases the storage, of course.)
2434
2435
Note that the library is internally interested in APP0 and APP14 markers;
2436
if you try to set a small nonzero length limit on these types, the library
2437
will silently force the length up to the minimum it wants.  (But you can set
2438
a zero length limit to prevent them from being saved at all.)  Also, in a
2439
16-bit environment, the maximum length limit may be constrained to less than
2440
65533 by malloc() limitations.  It is therefore best not to assume that the
2441
effective length limit is exactly what you set it to be.
2442
2443
2444
If you want to supply your own marker-reading routine, you do it by calling
2445
jpeg_set_marker_processor().  A marker processor routine must have the
2446
signature
2447
	boolean jpeg_marker_parser_method (j_decompress_ptr cinfo)
2448
Although the marker code is not explicitly passed, the routine can find it
2449
in cinfo->unread_marker.  At the time of call, the marker proper has been
2450
read from the data source module.  The processor routine is responsible for
2451
reading the marker length word and the remaining parameter bytes, if any.
2452
Return TRUE to indicate success.  (FALSE should be returned only if you are
2453
using a suspending data source and it tells you to suspend.  See the standard
2454
marker processors in jdmarker.c for appropriate coding methods if you need to
2455
use a suspending data source.)
2456
2457
If you override the default APP0 or APP14 processors, it is up to you to
2458
recognize JFIF and Adobe markers if you want colorspace recognition to occur
2459
properly.  We recommend copying and extending the default processors if you
2460
want to do that.  (A better idea is to save these marker types for later
2461
examination by calling jpeg_save_markers(); that method doesn't interfere
2462
with the library's own processing of these markers.)
2463
2464
jpeg_set_marker_processor() and jpeg_save_markers() are mutually exclusive
2465
--- if you call one it overrides any previous call to the other, for the
2466
particular marker type specified.
2467
2468
A simple example of an external COM processor can be found in djpeg.c.
2469
Also, see jpegtran.c for an example of using jpeg_save_markers.
2470
2471
2472
Raw (downsampled) image data
2473
----------------------------
2474
2475
Some applications need to supply already-downsampled image data to the JPEG
2476
compressor, or to receive raw downsampled data from the decompressor.  The
2477
library supports this requirement by allowing the application to write or
2478
read raw data, bypassing the normal preprocessing or postprocessing steps.
2479
The interface is different from the standard one and is somewhat harder to
2480
use.  If your interest is merely in bypassing color conversion, we recommend
2481
that you use the standard interface and simply set jpeg_color_space =
2482
in_color_space (or jpeg_color_space = out_color_space for decompression).
2483
The mechanism described in this section is necessary only to supply or
2484
receive downsampled image data, in which not all components have the same
2485
dimensions.
2486
2487
2488
To compress raw data, you must supply the data in the colorspace to be used
2489
in the JPEG file (please read the earlier section on Special color spaces)
2490
and downsampled to the sampling factors specified in the JPEG parameters.
2491
You must supply the data in the format used internally by the JPEG library,
2492
namely a JSAMPIMAGE array.  This is an array of pointers to two-dimensional
2493
arrays, each of type JSAMPARRAY.  Each 2-D array holds the values for one
2494
color component.  This structure is necessary since the components are of
2495
different sizes.  If the image dimensions are not a multiple of the MCU size,
2496
you must also pad the data correctly (usually, this is done by replicating
2497
the last column and/or row).  The data must be padded to a multiple of a DCT
2498
block in each component: that is, each downsampled row must contain a
2499
multiple of 8 valid samples, and there must be a multiple of 8 sample rows
2500
for each component.  (For applications such as conversion of digital TV
2501
images, the standard image size is usually a multiple of the DCT block size,
2502
so that no padding need actually be done.)
2503
2504
The procedure for compression of raw data is basically the same as normal
2505
compression, except that you call jpeg_write_raw_data() in place of
2506
jpeg_write_scanlines().  Before calling jpeg_start_compress(), you must do
2507
the following:
2508
  * Set cinfo->raw_data_in to TRUE.  (It is set FALSE by jpeg_set_defaults().)
2509
    This notifies the library that you will be supplying raw data.
2510
  * Ensure jpeg_color_space is correct --- an explicit jpeg_set_colorspace()
2511
    call is a good idea.  Note that since color conversion is bypassed,
2512
    in_color_space is ignored, except that jpeg_set_defaults() uses it to
2513
    choose the default jpeg_color_space setting.
2514
  * Ensure the sampling factors, cinfo->comp_info[i].h_samp_factor and
2515
    cinfo->comp_info[i].v_samp_factor, are correct.  Since these indicate the
2516
    dimensions of the data you are supplying, it's wise to set them
2517
    explicitly, rather than assuming the library's defaults are what you want.
2518
2519
To pass raw data to the library, call jpeg_write_raw_data() in place of
2520
jpeg_write_scanlines().  The two routines work similarly except that
2521
jpeg_write_raw_data takes a JSAMPIMAGE data array rather than JSAMPARRAY.
2522
The scanlines count passed to and returned from jpeg_write_raw_data is
2523
measured in terms of the component with the largest v_samp_factor.
2524
2525
jpeg_write_raw_data() processes one MCU row per call, which is to say
2526
v_samp_factor*DCTSIZE sample rows of each component.  The passed num_lines
2527
value must be at least max_v_samp_factor*DCTSIZE, and the return value will
2528
be exactly that amount (or possibly some multiple of that amount, in future
2529
library versions).  This is true even on the last call at the bottom of the
2530
image; don't forget to pad your data as necessary.
2531
2532
The required dimensions of the supplied data can be computed for each
2533
component as
2534
	cinfo->comp_info[i].width_in_blocks*DCTSIZE  samples per row
2535
	cinfo->comp_info[i].height_in_blocks*DCTSIZE rows in image
2536
after jpeg_start_compress() has initialized those fields.  If the valid data
2537
is smaller than this, it must be padded appropriately.  For some sampling
2538
factors and image sizes, additional dummy DCT blocks are inserted to make
2539
the image a multiple of the MCU dimensions.  The library creates such dummy
2540
blocks itself; it does not read them from your supplied data.  Therefore you
2541
need never pad by more than DCTSIZE samples.  An example may help here.
2542
Assume 2h2v downsampling of YCbCr data, that is
2543
	cinfo->comp_info[0].h_samp_factor = 2		for Y
2544
	cinfo->comp_info[0].v_samp_factor = 2
2545
	cinfo->comp_info[1].h_samp_factor = 1		for Cb
2546
	cinfo->comp_info[1].v_samp_factor = 1
2547
	cinfo->comp_info[2].h_samp_factor = 1		for Cr
2548
	cinfo->comp_info[2].v_samp_factor = 1
2549
and suppose that the nominal image dimensions (cinfo->image_width and
2550
cinfo->image_height) are 101x101 pixels.  Then jpeg_start_compress() will
2551
compute downsampled_width = 101 and width_in_blocks = 13 for Y,
2552
downsampled_width = 51 and width_in_blocks = 7 for Cb and Cr (and the same
2553
for the height fields).  You must pad the Y data to at least 13*8 = 104
2554
columns and rows, the Cb/Cr data to at least 7*8 = 56 columns and rows.  The
2555
MCU height is max_v_samp_factor = 2 DCT rows so you must pass at least 16
2556
scanlines on each call to jpeg_write_raw_data(), which is to say 16 actual
2557
sample rows of Y and 8 each of Cb and Cr.  A total of 7 MCU rows are needed,
2558
so you must pass a total of 7*16 = 112 "scanlines".  The last DCT block row
2559
of Y data is dummy, so it doesn't matter what you pass for it in the data
2560
arrays, but the scanlines count must total up to 112 so that all of the Cb
2561
and Cr data gets passed.
2562
2563
Output suspension is supported with raw-data compression: if the data
2564
destination module suspends, jpeg_write_raw_data() will return 0.
2565
In this case the same data rows must be passed again on the next call.
2566
2567
2568
Decompression with raw data output implies bypassing all postprocessing:
2569
you cannot ask for rescaling or color quantization, for instance.  More
2570
seriously, you must deal with the color space and sampling factors present in
2571
the incoming file.  If your application only handles, say, 2h1v YCbCr data,
2572
you must check for and fail on other color spaces or other sampling factors.
2573
The library will not convert to a different color space for you.
2574
2575
To obtain raw data output, set cinfo->raw_data_out = TRUE before
2576
jpeg_start_decompress() (it is set FALSE by jpeg_read_header()).  Be sure to
2577
verify that the color space and sampling factors are ones you can handle.
2578
Then call jpeg_read_raw_data() in place of jpeg_read_scanlines().  The
2579
decompression process is otherwise the same as usual.
2580
2581
jpeg_read_raw_data() returns one MCU row per call, and thus you must pass a
2582
buffer of at least max_v_samp_factor*DCTSIZE scanlines (scanline counting is
2583
the same as for raw-data compression).  The buffer you pass must be large
2584
enough to hold the actual data plus padding to DCT-block boundaries.  As with
2585
compression, any entirely dummy DCT blocks are not processed so you need not
2586
allocate space for them, but the total scanline count includes them.  The
2587
above example of computing buffer dimensions for raw-data compression is
2588
equally valid for decompression.
2589
2590
Input suspension is supported with raw-data decompression: if the data source
2591
module suspends, jpeg_read_raw_data() will return 0.  You can also use
2592
buffered-image mode to read raw data in multiple passes.
2593
2594
2595
Really raw data: DCT coefficients
2596
---------------------------------
2597
2598
It is possible to read or write the contents of a JPEG file as raw DCT
2599
coefficients.  This facility is mainly intended for use in lossless
2600
transcoding between different JPEG file formats.  Other possible applications
2601
include lossless cropping of a JPEG image, lossless reassembly of a
2602
multi-strip or multi-tile TIFF/JPEG file into a single JPEG datastream, etc.
2603
2604
To read the contents of a JPEG file as DCT coefficients, open the file and do
2605
jpeg_read_header() as usual.  But instead of calling jpeg_start_decompress()
2606
and jpeg_read_scanlines(), call jpeg_read_coefficients().  This will read the
2607
entire image into a set of virtual coefficient-block arrays, one array per
2608
component.  The return value is a pointer to an array of virtual-array
2609
descriptors.  Each virtual array can be accessed directly using the JPEG
2610
memory manager's access_virt_barray method (see Memory management, below,
2611
and also read structure.doc's discussion of virtual array handling).  Or,
2612
for simple transcoding to a different JPEG file format, the array list can
2613
just be handed directly to jpeg_write_coefficients().
2614
2615
Each block in the block arrays contains quantized coefficient values in
2616
normal array order (not JPEG zigzag order).  The block arrays contain only
2617
DCT blocks containing real data; any entirely-dummy blocks added to fill out
2618
interleaved MCUs at the right or bottom edges of the image are discarded
2619
during reading and are not stored in the block arrays.  (The size of each
2620
block array can be determined from the width_in_blocks and height_in_blocks
2621
fields of the component's comp_info entry.)  This is also the data format
2622
expected by jpeg_write_coefficients().
2623
2624
When you are done using the virtual arrays, call jpeg_finish_decompress()
2625
to release the array storage and return the decompression object to an idle
2626
state; or just call jpeg_destroy() if you don't need to reuse the object.
2627
2628
If you use a suspending data source, jpeg_read_coefficients() will return
2629
NULL if it is forced to suspend; a non-NULL return value indicates successful
2630
completion.  You need not test for a NULL return value when using a
2631
non-suspending data source.
2632
2633
It is also possible to call jpeg_read_coefficients() to obtain access to the
2634
decoder's coefficient arrays during a normal decode cycle in buffered-image
2635
mode.  This frammish might be useful for progressively displaying an incoming
2636
image and then re-encoding it without loss.  To do this, decode in buffered-
2637
image mode as discussed previously, then call jpeg_read_coefficients() after
2638
the last jpeg_finish_output() call.  The arrays will be available for your use
2639
until you call jpeg_finish_decompress().
2640
2641
2642
To write the contents of a JPEG file as DCT coefficients, you must provide
2643
the DCT coefficients stored in virtual block arrays.  You can either pass
2644
block arrays read from an input JPEG file by jpeg_read_coefficients(), or
2645
allocate virtual arrays from the JPEG compression object and fill them
2646
yourself.  In either case, jpeg_write_coefficients() is substituted for
2647
jpeg_start_compress() and jpeg_write_scanlines().  Thus the sequence is
2648
  * Create compression object
2649
  * Set all compression parameters as necessary
2650
  * Request virtual arrays if needed
2651
  * jpeg_write_coefficients()
2652
  * jpeg_finish_compress()
2653
  * Destroy or re-use compression object
2654
jpeg_write_coefficients() is passed a pointer to an array of virtual block
2655
array descriptors; the number of arrays is equal to cinfo.num_components.
2656
2657
The virtual arrays need only have been requested, not realized, before
2658
jpeg_write_coefficients() is called.  A side-effect of
2659
jpeg_write_coefficients() is to realize any virtual arrays that have been
2660
requested from the compression object's memory manager.  Thus, when obtaining
2661
the virtual arrays from the compression object, you should fill the arrays
2662
after calling jpeg_write_coefficients().  The data is actually written out
2663
when you call jpeg_finish_compress(); jpeg_write_coefficients() only writes
2664
the file header.
2665
2666
When writing raw DCT coefficients, it is crucial that the JPEG quantization
2667
tables and sampling factors match the way the data was encoded, or the
2668
resulting file will be invalid.  For transcoding from an existing JPEG file,
2669
we recommend using jpeg_copy_critical_parameters().  This routine initializes
2670
all the compression parameters to default values (like jpeg_set_defaults()),
2671
then copies the critical information from a source decompression object.
2672
The decompression object should have just been used to read the entire
2673
JPEG input file --- that is, it should be awaiting jpeg_finish_decompress().
2674
2675
jpeg_write_coefficients() marks all tables stored in the compression object
2676
as needing to be written to the output file (thus, it acts like
2677
jpeg_start_compress(cinfo, TRUE)).  This is for safety's sake, to avoid
2678
emitting abbreviated JPEG files by accident.  If you really want to emit an
2679
abbreviated JPEG file, call jpeg_suppress_tables(), or set the tables'
2680
individual sent_table flags, between calling jpeg_write_coefficients() and
2681
jpeg_finish_compress().
2682
2683
2684
Progress monitoring
2685
-------------------
2686
2687
Some applications may need to regain control from the JPEG library every so
2688
often.  The typical use of this feature is to produce a percent-done bar or
2689
other progress display.  (For a simple example, see cjpeg.c or djpeg.c.)
2690
Although you do get control back frequently during the data-transferring pass
2691
(the jpeg_read_scanlines or jpeg_write_scanlines loop), any additional passes
2692
will occur inside jpeg_finish_compress or jpeg_start_decompress; those
2693
routines may take a long time to execute, and you don't get control back
2694
until they are done.
2695
2696
You can define a progress-monitor routine which will be called periodically
2697
by the library.  No guarantees are made about how often this call will occur,
2698
so we don't recommend you use it for mouse tracking or anything like that.
2699
At present, a call will occur once per MCU row, scanline, or sample row
2700
group, whichever unit is convenient for the current processing mode; so the
2701
wider the image, the longer the time between calls.  During the data
2702
transferring pass, only one call occurs per call of jpeg_read_scanlines or
2703
jpeg_write_scanlines, so don't pass a large number of scanlines at once if
2704
you want fine resolution in the progress count.  (If you really need to use
2705
the callback mechanism for time-critical tasks like mouse tracking, you could
2706
insert additional calls inside some of the library's inner loops.)
2707
2708
To establish a progress-monitor callback, create a struct jpeg_progress_mgr,
2709
fill in its progress_monitor field with a pointer to your callback routine,
2710
and set cinfo->progress to point to the struct.  The callback will be called
2711
whenever cinfo->progress is non-NULL.  (This pointer is set to NULL by
2712
jpeg_create_compress or jpeg_create_decompress; the library will not change
2713
it thereafter.  So if you allocate dynamic storage for the progress struct,
2714
make sure it will live as long as the JPEG object does.  Allocating from the
2715
JPEG memory manager with lifetime JPOOL_PERMANENT will work nicely.)  You
2716
can use the same callback routine for both compression and decompression.
2717
2718
The jpeg_progress_mgr struct contains four fields which are set by the library:
2719
	long pass_counter;	/* work units completed in this pass */
2720
	long pass_limit;	/* total number of work units in this pass */
2721
	int completed_passes;	/* passes completed so far */
2722
	int total_passes;	/* total number of passes expected */
2723
During any one pass, pass_counter increases from 0 up to (not including)
2724
pass_limit; the step size is usually but not necessarily 1.  The pass_limit
2725
value may change from one pass to another.  The expected total number of
2726
passes is in total_passes, and the number of passes already completed is in
2727
completed_passes.  Thus the fraction of work completed may be estimated as
2728
		completed_passes + (pass_counter/pass_limit)
2729
		--------------------------------------------
2730
				total_passes
2731
ignoring the fact that the passes may not be equal amounts of work.
2732
2733
When decompressing, pass_limit can even change within a pass, because it
2734
depends on the number of scans in the JPEG file, which isn't always known in
2735
advance.  The computed fraction-of-work-done may jump suddenly (if the library
2736
discovers it has overestimated the number of scans) or even decrease (in the
2737
opposite case).  It is not wise to put great faith in the work estimate.
2738
2739
When using the decompressor's buffered-image mode, the progress monitor work
2740
estimate is likely to be completely unhelpful, because the library has no way
2741
to know how many output passes will be demanded of it.  Currently, the library
2742
sets total_passes based on the assumption that there will be one more output
2743
pass if the input file end hasn't yet been read (jpeg_input_complete() isn't
2744
TRUE), but no more output passes if the file end has been reached when the
2745
output pass is started.  This means that total_passes will rise as additional
2746
output passes are requested.  If you have a way of determining the input file
2747
size, estimating progress based on the fraction of the file that's been read
2748
will probably be more useful than using the library's value.
2749
2750
2751
Memory management
2752
-----------------
2753
2754
This section covers some key facts about the JPEG library's built-in memory
2755
manager.  For more info, please read structure.doc's section about the memory
2756
manager, and consult the source code if necessary.
2757
2758
All memory and temporary file allocation within the library is done via the
2759
memory manager.  If necessary, you can replace the "back end" of the memory
2760
manager to control allocation yourself (for example, if you don't want the
2761
library to use malloc() and free() for some reason).
2762
2763
Some data is allocated "permanently" and will not be freed until the JPEG
2764
object is destroyed.  Most data is allocated "per image" and is freed by
2765
jpeg_finish_compress, jpeg_finish_decompress, or jpeg_abort.  You can call the
2766
memory manager yourself to allocate structures that will automatically be
2767
freed at these times.  Typical code for this is
2768
  ptr = (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, size);
2769
Use JPOOL_PERMANENT to get storage that lasts as long as the JPEG object.
2770
Use alloc_large instead of alloc_small for anything bigger than a few Kbytes.
2771
There are also alloc_sarray and alloc_barray routines that automatically
2772
build 2-D sample or block arrays.
2773
2774
The library's minimum space requirements to process an image depend on the
2775
image's width, but not on its height, because the library ordinarily works
2776
with "strip" buffers that are as wide as the image but just a few rows high.
2777
Some operating modes (eg, two-pass color quantization) require full-image
2778
buffers.  Such buffers are treated as "virtual arrays": only the current strip
2779
need be in memory, and the rest can be swapped out to a temporary file.
2780
2781
If you use the simplest memory manager back end (jmemnobs.c), then no
2782
temporary files are used; virtual arrays are simply malloc()'d.  Images bigger
2783
than memory can be processed only if your system supports virtual memory.
2784
The other memory manager back ends support temporary files of various flavors
2785
and thus work in machines without virtual memory.  They may also be useful on
2786
Unix machines if you need to process images that exceed available swap space.
2787
2788
When using temporary files, the library will make the in-memory buffers for
2789
its virtual arrays just big enough to stay within a "maximum memory" setting.
2790
Your application can set this limit by setting cinfo->mem->max_memory_to_use
2791
after creating the JPEG object.  (Of course, there is still a minimum size for
2792
the buffers, so the max-memory setting is effective only if it is bigger than
2793
the minimum space needed.)  If you allocate any large structures yourself, you
2794
must allocate them before jpeg_start_compress() or jpeg_start_decompress() in
2795
order to have them counted against the max memory limit.  Also keep in mind
2796
that space allocated with alloc_small() is ignored, on the assumption that
2797
it's too small to be worth worrying about; so a reasonable safety margin
2798
should be left when setting max_memory_to_use.
2799
2800
If you use the jmemname.c or jmemdos.c memory manager back end, it is
2801
important to clean up the JPEG object properly to ensure that the temporary
2802
files get deleted.  (This is especially crucial with jmemdos.c, where the
2803
"temporary files" may be extended-memory segments; if they are not freed,
2804
DOS will require a reboot to recover the memory.)  Thus, with these memory
2805
managers, it's a good idea to provide a signal handler that will trap any
2806
early exit from your program.  The handler should call either jpeg_abort()
2807
or jpeg_destroy() for any active JPEG objects.  A handler is not needed with
2808
jmemnobs.c, and shouldn't be necessary with jmemansi.c or jmemmac.c either,
2809
since the C library is supposed to take care of deleting files made with
2810
tmpfile().
2811
2812
2813
Memory usage
2814
------------
2815
2816
Working memory requirements while performing compression or decompression
2817
depend on image dimensions, image characteristics (such as colorspace and
2818
JPEG process), and operating mode (application-selected options).
2819
2820
As of v6b, the decompressor requires:
2821
 1. About 24K in more-or-less-fixed-size data.  This varies a bit depending
2822
    on operating mode and image characteristics (particularly color vs.
2823
    grayscale), but it doesn't depend on image dimensions.
2824
 2. Strip buffers (of size proportional to the image width) for IDCT and
2825
    upsampling results.  The worst case for commonly used sampling factors
2826
    is about 34 bytes * width in pixels for a color image.  A grayscale image
2827
    only needs about 8 bytes per pixel column.
2828
 3. A full-image DCT coefficient buffer is needed to decode a multi-scan JPEG
2829
    file (including progressive JPEGs), or whenever you select buffered-image
2830
    mode.  This takes 2 bytes/coefficient.  At typical 2x2 sampling, that's
2831
    3 bytes per pixel for a color image.  Worst case (1x1 sampling) requires
2832
    6 bytes/pixel.  For grayscale, figure 2 bytes/pixel.
2833
 4. To perform 2-pass color quantization, the decompressor also needs a
2834
    128K color lookup table and a full-image pixel buffer (3 bytes/pixel).
2835
This does not count any memory allocated by the application, such as a
2836
buffer to hold the final output image.
2837
2838
The above figures are valid for 8-bit JPEG data precision and a machine with
2839
32-bit ints.  For 12-bit JPEG data, double the size of the strip buffers and
2840
quantization pixel buffer.  The "fixed-size" data will be somewhat smaller
2841
with 16-bit ints, larger with 64-bit ints.  Also, CMYK or other unusual
2842
color spaces will require different amounts of space.
2843
2844
The full-image coefficient and pixel buffers, if needed at all, do not
2845
have to be fully RAM resident; you can have the library use temporary
2846
files instead when the total memory usage would exceed a limit you set.
2847
(But if your OS supports virtual memory, it's probably better to just use
2848
jmemnobs and let the OS do the swapping.)
2849
2850
The compressor's memory requirements are similar, except that it has no need
2851
for color quantization.  Also, it needs a full-image DCT coefficient buffer
2852
if Huffman-table optimization is asked for, even if progressive mode is not
2853
requested.
2854
2855
If you need more detailed information about memory usage in a particular
2856
situation, you can enable the MEM_STATS code in jmemmgr.c.
2857
2858
2859
Library compile-time options
2860
----------------------------
2861
2862
A number of compile-time options are available by modifying jmorecfg.h.
2863
2864
The JPEG standard provides for both the baseline 8-bit DCT process and
2865
a 12-bit DCT process.  The IJG code supports 12-bit lossy JPEG if you define
2866
BITS_IN_JSAMPLE as 12 rather than 8.  Note that this causes JSAMPLE to be
2867
larger than a char, so it affects the surrounding application's image data.
2868
The sample applications cjpeg and djpeg can support 12-bit mode only for PPM
2869
and GIF file formats; you must disable the other file formats to compile a
2870
12-bit cjpeg or djpeg.  (install.doc has more information about that.)
2871
At present, a 12-bit library can handle *only* 12-bit images, not both
2872
precisions.  (If you need to include both 8- and 12-bit libraries in a single
2873
application, you could probably do it by defining NEED_SHORT_EXTERNAL_NAMES
2874
for just one of the copies.  You'd have to access the 8-bit and 12-bit copies
2875
from separate application source files.  This is untested ... if you try it,
2876
we'd like to hear whether it works!)
2877
2878
Note that a 12-bit library always compresses in Huffman optimization mode,
2879
in order to generate valid Huffman tables.  This is necessary because our
2880
default Huffman tables only cover 8-bit data.  If you need to output 12-bit
2881
files in one pass, you'll have to supply suitable default Huffman tables.
2882
You may also want to supply your own DCT quantization tables; the existing
2883
quality-scaling code has been developed for 8-bit use, and probably doesn't
2884
generate especially good tables for 12-bit.
2885
2886
The maximum number of components (color channels) in the image is determined
2887
by MAX_COMPONENTS.  The JPEG standard allows up to 255 components, but we
2888
expect that few applications will need more than four or so.
2889
2890
On machines with unusual data type sizes, you may be able to improve
2891
performance or reduce memory space by tweaking the various typedefs in
2892
jmorecfg.h.  In particular, on some RISC CPUs, access to arrays of "short"s
2893
is quite slow; consider trading memory for speed by making JCOEF, INT16, and
2894
UINT16 be "int" or "unsigned int".  UINT8 is also a candidate to become int.
2895
You probably don't want to make JSAMPLE be int unless you have lots of memory
2896
to burn.
2897
2898
You can reduce the size of the library by compiling out various optional
2899
functions.  To do this, undefine xxx_SUPPORTED symbols as necessary.
2900
2901
You can also save a few K by not having text error messages in the library;
2902
the standard error message table occupies about 5Kb.  This is particularly
2903
reasonable for embedded applications where there's no good way to display 
2904
a message anyway.  To do this, remove the creation of the message table
2905
(jpeg_std_message_table[]) from jerror.c, and alter format_message to do
2906
something reasonable without it.  You could output the numeric value of the
2907
message code number, for example.  If you do this, you can also save a couple
2908
more K by modifying the TRACEMSn() macros in jerror.h to expand to nothing;
2909
you don't need trace capability anyway, right?
2910
2911
2912
Portability considerations
2913
--------------------------
2914
2915
The JPEG library has been written to be extremely portable; the sample
2916
applications cjpeg and djpeg are slightly less so.  This section summarizes
2917
the design goals in this area.  (If you encounter any bugs that cause the
2918
library to be less portable than is claimed here, we'd appreciate hearing
2919
about them.)
2920
2921
The code works fine on ANSI C, C++, and pre-ANSI C compilers, using any of
2922
the popular system include file setups, and some not-so-popular ones too.
2923
See install.doc for configuration procedures.
2924
2925
The code is not dependent on the exact sizes of the C data types.  As
2926
distributed, we make the assumptions that
2927
	char	is at least 8 bits wide
2928
	short	is at least 16 bits wide
2929
	int	is at least 16 bits wide
2930
	long	is at least 32 bits wide
2931
(These are the minimum requirements of the ANSI C standard.)  Wider types will
2932
work fine, although memory may be used inefficiently if char is much larger
2933
than 8 bits or short is much bigger than 16 bits.  The code should work
2934
equally well with 16- or 32-bit ints.
2935
2936
In a system where these assumptions are not met, you may be able to make the
2937
code work by modifying the typedefs in jmorecfg.h.  However, you will probably
2938
have difficulty if int is less than 16 bits wide, since references to plain
2939
int abound in the code.
2940
2941
char can be either signed or unsigned, although the code runs faster if an
2942
unsigned char type is available.  If char is wider than 8 bits, you will need
2943
to redefine JOCTET and/or provide custom data source/destination managers so
2944
that JOCTET represents exactly 8 bits of data on external storage.
2945
2946
The JPEG library proper does not assume ASCII representation of characters.
2947
But some of the image file I/O modules in cjpeg/djpeg do have ASCII
2948
dependencies in file-header manipulation; so does cjpeg's select_file_type()
2949
routine.
2950
2951
The JPEG library does not rely heavily on the C library.  In particular, C
2952
stdio is used only by the data source/destination modules and the error
2953
handler, all of which are application-replaceable.  (cjpeg/djpeg are more
2954
heavily dependent on stdio.)  malloc and free are called only from the memory
2955
manager "back end" module, so you can use a different memory allocator by
2956
replacing that one file.
2957
2958
The code generally assumes that C names must be unique in the first 15
2959
characters.  However, global function names can be made unique in the
2960
first 6 characters by defining NEED_SHORT_EXTERNAL_NAMES.
2961
2962
More info about porting the code may be gleaned by reading jconfig.doc,
2963
jmorecfg.h, and jinclude.h.
2964
2965
2966
Notes for MS-DOS implementors
2967
-----------------------------
2968
2969
The IJG code is designed to work efficiently in 80x86 "small" or "medium"
2970
memory models (i.e., data pointers are 16 bits unless explicitly declared
2971
"far"; code pointers can be either size).  You may be able to use small
2972
model to compile cjpeg or djpeg by itself, but you will probably have to use
2973
medium model for any larger application.  This won't make much difference in
2974
performance.  You *will* take a noticeable performance hit if you use a
2975
large-data memory model (perhaps 10%-25%), and you should avoid "huge" model
2976
if at all possible.
2977
2978
The JPEG library typically needs 2Kb-3Kb of stack space.  It will also
2979
malloc about 20K-30K of near heap space while executing (and lots of far
2980
heap, but that doesn't count in this calculation).  This figure will vary
2981
depending on selected operating mode, and to a lesser extent on image size.
2982
There is also about 5Kb-6Kb of constant data which will be allocated in the
2983
near data segment (about 4Kb of this is the error message table).
2984
Thus you have perhaps 20K available for other modules' static data and near
2985
heap space before you need to go to a larger memory model.  The C library's
2986
static data will account for several K of this, but that still leaves a good
2987
deal for your needs.  (If you are tight on space, you could reduce the sizes
2988
of the I/O buffers allocated by jdatasrc.c and jdatadst.c, say from 4K to
2989
1K.  Another possibility is to move the error message table to far memory;
2990
this should be doable with only localized hacking on jerror.c.)
2991
2992
About 2K of the near heap space is "permanent" memory that will not be
2993
released until you destroy the JPEG object.  This is only an issue if you
2994
save a JPEG object between compression or decompression operations.
2995
2996
Far data space may also be a tight resource when you are dealing with large
2997
images.  The most memory-intensive case is decompression with two-pass color
2998
quantization, or single-pass quantization to an externally supplied color
2999
map.  This requires a 128Kb color lookup table plus strip buffers amounting
3000
to about 40 bytes per column for typical sampling ratios (eg, about 25600
3001
bytes for a 640-pixel-wide image).  You may not be able to process wide
3002
images if you have large data structures of your own.
3003
3004
Of course, all of these concerns vanish if you use a 32-bit flat-memory-model
3005
compiler, such as DJGPP or Watcom C.  We highly recommend flat model if you
3006
can use it; the JPEG library is significantly faster in flat model.
(-)a/jpeg/makefile.gen (-274 lines)
Line     Link Here 
 Lines 1-274    Link Here 
1
# Generated automatically from makefile.cfg by configure.
2
# Makefile for Independent JPEG Group's software
3
4
# makefile.cfg is edited by configure to produce a custom Makefile.
5
6
# Read installation instructions before saying "make" !!
7
8
# For compiling with source and object files in different directories.
9
srcdir = $(VPATH)
10
11
# Where to install the programs and man pages.
12
prefix = /usr/local
13
exec_prefix = ${prefix}
14
bindir = $(exec_prefix)/bin
15
libdir = $(exec_prefix)/lib
16
includedir = $(prefix)/include
17
binprefix =
18
manprefix =
19
manext = 1
20
mandir = $(prefix)/man/man$(manext)
21
22
# The name of your C compiler:
23
CC= cc
24
25
# You may need to adjust these cc options:
26
CFLAGS= -O3  -I$(srcdir)
27
# Generally, we recommend defining any configuration symbols in jconfig.h,
28
# NOT via -D switches here.
29
# However, any special defines for ansi2knr.c may be included here:
30
ANSI2KNRFLAGS= 
31
32
# Link-time cc options:
33
LDFLAGS= 
34
35
# To link any special libraries, add the necessary -l commands here.
36
LDLIBS= 
37
38
# Put here the object file name for the correct system-dependent memory
39
# manager file.  For Unix this is usually jmemnobs.o, but you may want
40
# to use jmemansi.o or jmemname.o if you have limited swap space.
41
SYSDEPMEM= jmemnobs.o
42
43
# miscellaneous OS-dependent stuff
44
SHELL= /bin/sh
45
# linker
46
LN= $(CC)
47
# file deletion command
48
RM= rm -f
49
# file rename command
50
MV= mv
51
# library (.a) file creation command
52
AR= ar rc
53
# second step in .a creation (use "touch" if not needed)
54
AR2= ranlib
55
# installation program
56
INSTALL= cp
57
INSTALL_PROGRAM= ${INSTALL}
58
INSTALL_DATA= ${INSTALL}
59
60
# End of configurable options.
61
62
63
# source files: JPEG library proper
64
LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
65
        jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
66
        jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
67
        jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
68
        jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
69
        jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
70
        jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
71
        jquant2.c jutils.c jmemmgr.c jmemansi.c jmemname.c jmemnobs.c \
72
        jmemdos.c
73
# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
74
APPSOURCES= cjpeg.c djpeg.c jpegtran.c cdjpeg.c rdcolmap.c rdswitch.c \
75
        rdjpgcom.c wrjpgcom.c rdppm.c wrppm.c rdgif.c wrgif.c rdtarga.c \
76
        wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
77
SOURCES= $(LIBSOURCES) $(APPSOURCES)
78
# files included by source files
79
INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
80
        jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h
81
# documentation, test, and support files
82
DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
83
        wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
84
        coderules.doc filelist.doc change.log
85
MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
86
        makefile.mc6 makefile.dj makefile.wat makcjpeg.st makdjpeg.st \
87
        makljpeg.st maktjpeg.st makefile.manx makefile.sas makefile.mms \
88
        makefile.vms makvms.opt
89
CONFIGFILES= jconfig.cfg jconfig.manx jconfig.sas jconfig.st jconfig.bcc \
90
        jconfig.mc6 jconfig.dj jconfig.wat jconfig.vms
91
OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
92
TESTFILES= testorig.jpg testimg.ppm testimg.gif testimg.jpg testprog.jpg \
93
        testimgp.jpg
94
DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
95
        $(OTHERFILES) $(TESTFILES)
96
# library object files common to compression and decompression
97
COMOBJECTS= jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)
98
# compression library object files
99
CLIBOBJECTS= jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o jcinit.o \
100
        jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o \
101
        jcsample.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o \
102
        jfdctint.o
103
# decompression library object files
104
DLIBOBJECTS= jdapimin.o jdapistd.o jdatasrc.o jdmaster.o \
105
        jdinput.o jdmarker.o jdhuff.o jdphuff.o jdmainct.o jdcoefct.o \
106
        jdpostct.o jddctmgr.o jidctfst.o jidctflt.o jidctint.o jidctred.o \
107
        jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o
108
# These objectfiles are included in libjpeg.a
109
LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
110
# object files for sample applications (excluding library files)
111
COBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \
112
        cdjpeg.o
113
DOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \
114
        cdjpeg.o
115
TROBJECTS= jpegtran.o rdswitch.o cdjpeg.o
116
117
all: libjpeg.a
118
119
realall:  libjpeg.a cjpeg djpeg jpegtran rdjpgcom wrjpgcom
120
121
# This rule causes ansi2knr to be invoked.
122
# .c.o:
123
# 	./ansi2knr $(srcdir)/$*.c T$*.c
124
# 	$(CC) $(CFLAGS) -c T$*.c
125
# 	$(RM) T$*.c $*.o
126
# 	$(MV) T$*.o $*.o
127
128
ansi2knr: ansi2knr.c
129
	$(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr ansi2knr.c
130
131
# Decompression-only library
132
libjpeg.a:  $(DLIBOBJECTS) $(COMOBJECTS)
133
	$(RM) libjpeg.a
134
	$(AR) libjpeg.a  $(DLIBOBJECTS) $(COMOBJECTS)
135
	$(AR2) libjpeg.a
136
137
cjpeg: $(COBJECTS) libjpeg.a
138
	$(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)
139
140
djpeg: $(DOBJECTS) libjpeg.a
141
	$(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)
142
143
jpegtran: $(TROBJECTS) libjpeg.a
144
	$(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.a $(LDLIBS)
145
146
rdjpgcom: rdjpgcom.o
147
	$(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
148
149
wrjpgcom: wrjpgcom.o
150
	$(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)
151
152
jconfig.h: jconfig.doc
153
	echo You must prepare a system-dependent jconfig.h file.
154
	echo Please read the installation directions in install.doc.
155
	exit 1
156
157
install: cjpeg djpeg jpegtran rdjpgcom wrjpgcom
158
	$(INSTALL_PROGRAM) cjpeg $(bindir)/$(binprefix)cjpeg
159
	$(INSTALL_PROGRAM) djpeg $(bindir)/$(binprefix)djpeg
160
	$(INSTALL_PROGRAM) jpegtran $(bindir)/$(binprefix)jpegtran
161
	$(INSTALL_PROGRAM) rdjpgcom $(bindir)/$(binprefix)rdjpgcom
162
	$(INSTALL_PROGRAM) wrjpgcom $(bindir)/$(binprefix)wrjpgcom
163
	$(INSTALL_DATA) $(srcdir)/cjpeg.1 $(mandir)/$(manprefix)cjpeg.$(manext)
164
	$(INSTALL_DATA) $(srcdir)/djpeg.1 $(mandir)/$(manprefix)djpeg.$(manext)
165
	$(INSTALL_DATA) $(srcdir)/jpegtran.1 $(mandir)/$(manprefix)jpegtran.$(manext)
166
	$(INSTALL_DATA) $(srcdir)/rdjpgcom.1 $(mandir)/$(manprefix)rdjpgcom.$(manext)
167
	$(INSTALL_DATA) $(srcdir)/wrjpgcom.1 $(mandir)/$(manprefix)wrjpgcom.$(manext)
168
169
install-lib: libjpeg.a install-headers
170
	$(INSTALL_DATA) libjpeg.a $(libdir)/$(binprefix)libjpeg.a
171
172
install-headers: jconfig.h
173
	$(INSTALL_DATA) jconfig.h $(includedir)/jconfig.h
174
	$(INSTALL_DATA) $(srcdir)/jpeglib.h $(includedir)/jpeglib.h
175
	$(INSTALL_DATA) $(srcdir)/jmorecfg.h $(includedir)/jmorecfg.h
176
	$(INSTALL_DATA) $(srcdir)/jerror.h $(includedir)/jerror.h
177
178
clean:
179
	$(RM) *.o cjpeg djpeg jpegtran libjpeg.a rdjpgcom wrjpgcom
180
	$(RM) ansi2knr core testout* config.log config.status
181
182
distribute:
183
	$(RM) jpegsrc.tar*
184
	tar cvf jpegsrc.tar $(DISTFILES)
185
	compress -v jpegsrc.tar
186
187
test: cjpeg djpeg jpegtran
188
	$(RM) testout*
189
	./djpeg -dct int -ppm -outfile testout.ppm  $(srcdir)/testorig.jpg
190
	./djpeg -dct int -gif -outfile testout.gif  $(srcdir)/testorig.jpg
191
	./cjpeg -dct int -outfile testout.jpg  $(srcdir)/testimg.ppm
192
	./djpeg -dct int -ppm -outfile testoutp.ppm $(srcdir)/testprog.jpg
193
	./cjpeg -dct int -progressive -opt -outfile testoutp.jpg $(srcdir)/testimg.ppm
194
	./jpegtran -outfile testoutt.jpg $(srcdir)/testprog.jpg
195
	cmp $(srcdir)/testimg.ppm testout.ppm
196
	cmp $(srcdir)/testimg.gif testout.gif
197
	cmp $(srcdir)/testimg.jpg testout.jpg
198
	cmp $(srcdir)/testimg.ppm testoutp.ppm
199
	cmp $(srcdir)/testimgp.jpg testoutp.jpg
200
	cmp $(srcdir)/testorig.jpg testoutt.jpg
201
202
check: test
203
204
# GNU Make likes to know which target names are not really files to be made:
205
.PHONY: all install install-lib install-headers clean distribute test check
206
207
208
jcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
209
jcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
210
jccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
211
jccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
212
jcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
213
jchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
214
jcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
215
jcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
216
jcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
217
jcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
218
jcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
219
jcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
220
jcphuff.o: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
221
jcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
222
jcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
223
jctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
224
jdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
225
jdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
226
jdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
227
jdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
228
jdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
229
jdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
230
jddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
231
jdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
232
jdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
233
jdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
234
jdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
235
jdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
236
jdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
237
jdphuff.o: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
238
jdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
239
jdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
240
jdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
241
jerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
242
jfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
243
jfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
244
jfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
245
jidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
246
jidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
247
jidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
248
jidctred.o: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
249
jquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
250
jquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
251
jutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
252
jmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
253
jmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
254
jmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
255
jmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
256
jmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
257
cjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
258
djpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
259
jpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
260
cdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
261
rdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
262
rdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
263
rdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h
264
wrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h
265
rdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
266
wrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
267
rdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
268
wrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
269
rdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
270
wrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
271
rdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
272
wrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
273
rdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
274
wrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
(-)a/jpeg/netscape_mods.doc (-52 lines)
Line     Link Here 
 Lines 1-52    Link Here 
1
***** BEGIN LICENSE BLOCK *****
2
Version: MPL 1.1/GPL 2.0/LGPL 2.1
3
4
The contents of this file are subject to the Mozilla Public License Version 
5
1.1 (the "License"); you may not use this file except in compliance with 
6
the License. You may obtain a copy of the License at 
7
http://www.mozilla.org/MPL/
8
9
Software distributed under the License is distributed on an "AS IS" basis,
10
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
for the specific language governing rights and limitations under the
12
License.
13
14
The Original Code is mozilla.org code.
15
16
The Initial Developer of the Original Code is
17
Netscape Communications Corporation
18
Portions created by the Initial Developer are Copyright (C) 1998
19
the Initial Developer. All Rights Reserved.
20
21
Contributor(s):
22
23
Alternatively, the contents of this file may be used under the terms of
24
either the GNU General Public License Version 2 or later (the "GPL"), or
25
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26
in which case the provisions of the GPL or the LGPL are applicable instead
27
of those above. If you wish to allow use of your version of this file only
28
under the terms of either the GPL or the LGPL, and not to allow others to
29
use your version of this file under the terms of the MPL, indicate your
30
decision by deleting the provisions above and replace them with the notice
31
and other provisions required by the GPL or the LGPL. If you do not delete
32
the provisions above, a recipient may use your version of this file under
33
the terms of any one of the MPL, the GPL or the LGPL.
34
35
***** END LICENSE BLOCK *****
36
37
This directory contains a subset of the IJG JPEG library.  Among other
38
omissions, most of the original IJG documentation has been deleted.
39
You can find the full IJG distribution at the archive sites mentioned in
40
the README file.  Please note that the IJG code does not fall under the
41
Netscape NPL, but is freely distributable under its own copyright terms
42
(see README).
43
44
Several files have been modified to allow incorporation of the IJG code
45
into the Netscape environment.  As of this writing, jconfig.h, jmorecfg.h,
46
and jerror.c contain Netscape-specific changes.  In addition, we have created
47
our own makefiles following Netscape conventions, rather than using any of
48
those provided by IJG.
49
50
There are some other changes herein, such as MMX-specific optimizations,
51
which should eventually make their way back into the standard IJG
52
distribution.
(-)a/jpeg/simd/Makefile.in (+48 lines)
Line     Link Here 
Line 0    Link Here 
1
#
2
# ***** BEGIN LICENSE BLOCK *****
3
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
#
5
# The contents of this file are subject to the Mozilla Public License Version
6
# 1.1 (the "License"); you may not use this file except in compliance with
7
# the License. You may obtain a copy of the License at
8
# http://www.mozilla.org/MPL/
9
#
10
# Software distributed under the License is distributed on an "AS IS" basis,
11
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
# for the specific language governing rights and limitations under the
13
# License.
14
#
15
# The Original Code is mozilla.org code.
16
#
17
# The Initial Developer of the Original Code is
18
# Mozilla Corporation
19
# Portions created by the Initial Developer are Copyright (C) 2010
20
# the Initial Developer. All Rights Reserved.
21
#
22
# Contributor(s):
23
#  Justin Lebar <justin.lebar@gmail.com>
24
#
25
# Alternatively, the contents of this file may be used under the terms of
26
# either the GNU General Public License Version 2 or later (the "GPL"), or
27
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
# in which case the provisions of the GPL or the LGPL are applicable instead
29
# of those above. If you wish to allow use of your version of this file only
30
# under the terms of either the GPL or the LGPL, and not to allow others to
31
# use your version of this file under the terms of the MPL, indicate your
32
# decision by deleting the provisions above and replace them with the notice
33
# and other provisions required by the GPL or the LGPL. If you do not delete
34
# the provisions above, a recipient may use your version of this file under
35
# the terms of any one of the MPL, the GPL or the LGPL.
36
#
37
# ***** END LICENSE BLOCK *****
38
39
DEPTH		= ../..
40
topsrcdir	= @top_srcdir@
41
srcdir		= @srcdir@
42
VPATH		= @srcdir@
43
44
include $(DEPTH)/config/autoconf.mk
45
46
# empty makefile so this directory gets created in the objdir.
47
48
include $(topsrcdir)/config/rules.mk
(-)a/jpeg/simd/jcclrmmx.asm (+479 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcclrmmx.asm - colorspace conversion (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jcolsamp.inc"
20
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_TEXT
23
	BITS	32
24
;
25
; Convert some rows of samples to the output colorspace.
26
;
27
; GLOBAL(void)
28
; jsimd_rgb_ycc_convert_mmx (JDIMENSION img_width,
29
;                           JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
30
;                           JDIMENSION output_row, int num_rows);
31
;
32
33
%define img_width(b)	(b)+8			; JDIMENSION img_width
34
%define input_buf(b)	(b)+12		; JSAMPARRAY input_buf
35
%define output_buf(b)	(b)+16		; JSAMPIMAGE output_buf
36
%define output_row(b)	(b)+20		; JDIMENSION output_row
37
%define num_rows(b)	(b)+24		; int num_rows
38
39
%define original_ebp	ebp+0
40
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
41
%define WK_NUM		8
42
%define gotptr		wk(0)-SIZEOF_POINTER	; void * gotptr
43
44
	align	16
45
	global	EXTN(jsimd_rgb_ycc_convert_mmx)
46
47
EXTN(jsimd_rgb_ycc_convert_mmx):
48
	push	ebp
49
	mov	eax,esp				; eax = original ebp
50
	sub	esp, byte 4
51
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
52
	mov	[esp],eax
53
	mov	ebp,esp				; ebp = aligned ebp
54
	lea	esp, [wk(0)]
55
	pushpic	eax		; make a room for GOT address
56
	push	ebx
57
;	push	ecx		; need not be preserved
58
;	push	edx		; need not be preserved
59
	push	esi
60
	push	edi
61
62
	get_GOT	ebx			; get GOT address
63
	movpic	POINTER [gotptr], ebx	; save GOT address
64
65
	mov	ecx, JDIMENSION [img_width(eax)]	; num_cols
66
	test	ecx,ecx
67
	jz	near .return
68
69
	push	ecx
70
71
	mov	esi, JSAMPIMAGE [output_buf(eax)]
72
	mov	ecx, JDIMENSION [output_row(eax)]
73
	mov	edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY]
74
	mov	ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY]
75
	mov	edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY]
76
	lea	edi, [edi+ecx*SIZEOF_JSAMPROW]
77
	lea	ebx, [ebx+ecx*SIZEOF_JSAMPROW]
78
	lea	edx, [edx+ecx*SIZEOF_JSAMPROW]
79
80
	pop	ecx
81
82
	mov	esi, JSAMPARRAY [input_buf(eax)]
83
	mov	eax, INT [num_rows(eax)]
84
	test	eax,eax
85
	jle	near .return
86
	alignx	16,7
87
.rowloop:
88
	pushpic	eax
89
	push	edx
90
	push	ebx
91
	push	edi
92
	push	esi
93
	push	ecx			; col
94
95
	mov	esi, JSAMPROW [esi]	; inptr
96
	mov	edi, JSAMPROW [edi]	; outptr0
97
	mov	ebx, JSAMPROW [ebx]	; outptr1
98
	mov	edx, JSAMPROW [edx]	; outptr2
99
	movpic	eax, POINTER [gotptr]	; load GOT address (eax)
100
101
	cmp	ecx, byte SIZEOF_MMWORD
102
	jae	short .columnloop
103
	alignx	16,7
104
105
%if RGB_PIXELSIZE == 3 ; ---------------
106
107
.column_ld1:
108
	push	eax
109
	push	edx
110
	lea	ecx,[ecx+ecx*2]		; imul ecx,RGB_PIXELSIZE
111
	test	cl, SIZEOF_BYTE
112
	jz	short .column_ld2
113
	sub	ecx, byte SIZEOF_BYTE
114
	xor	eax,eax
115
	mov	al, BYTE [esi+ecx]
116
.column_ld2:
117
	test	cl, SIZEOF_WORD
118
	jz	short .column_ld4
119
	sub	ecx, byte SIZEOF_WORD
120
	xor	edx,edx
121
	mov	dx, WORD [esi+ecx]
122
	shl	eax, WORD_BIT
123
	or	eax,edx
124
.column_ld4:
125
	movd	mmA,eax
126
	pop	edx
127
	pop	eax
128
	test	cl, SIZEOF_DWORD
129
	jz	short .column_ld8
130
	sub	ecx, byte SIZEOF_DWORD
131
	movd	mmG, DWORD [esi+ecx]
132
	psllq	mmA, DWORD_BIT
133
	por	mmA,mmG
134
.column_ld8:
135
	test	cl, SIZEOF_MMWORD
136
	jz	short .column_ld16
137
	movq	mmG,mmA
138
	movq	mmA, MMWORD [esi+0*SIZEOF_MMWORD]
139
	mov	ecx, SIZEOF_MMWORD
140
	jmp	short .rgb_ycc_cnv
141
.column_ld16:
142
	test	cl, 2*SIZEOF_MMWORD
143
	mov	ecx, SIZEOF_MMWORD
144
	jz	short .rgb_ycc_cnv
145
	movq	mmF,mmA
146
	movq	mmA, MMWORD [esi+0*SIZEOF_MMWORD]
147
	movq	mmG, MMWORD [esi+1*SIZEOF_MMWORD]
148
	jmp	short .rgb_ycc_cnv
149
	alignx	16,7
150
151
.columnloop:
152
	movq	mmA, MMWORD [esi+0*SIZEOF_MMWORD]
153
	movq	mmG, MMWORD [esi+1*SIZEOF_MMWORD]
154
	movq	mmF, MMWORD [esi+2*SIZEOF_MMWORD]
155
156
.rgb_ycc_cnv:
157
	; mmA=(00 10 20 01 11 21 02 12)
158
	; mmG=(22 03 13 23 04 14 24 05)
159
	; mmF=(15 25 06 16 26 07 17 27)
160
161
	movq      mmD,mmA
162
	psllq     mmA,4*BYTE_BIT	; mmA=(-- -- -- -- 00 10 20 01)
163
	psrlq     mmD,4*BYTE_BIT	; mmD=(11 21 02 12 -- -- -- --)
164
165
	punpckhbw mmA,mmG		; mmA=(00 04 10 14 20 24 01 05)
166
	psllq     mmG,4*BYTE_BIT	; mmG=(-- -- -- -- 22 03 13 23)
167
168
	punpcklbw mmD,mmF		; mmD=(11 15 21 25 02 06 12 16)
169
	punpckhbw mmG,mmF		; mmG=(22 26 03 07 13 17 23 27)
170
171
	movq      mmE,mmA
172
	psllq     mmA,4*BYTE_BIT	; mmA=(-- -- -- -- 00 04 10 14)
173
	psrlq     mmE,4*BYTE_BIT	; mmE=(20 24 01 05 -- -- -- --)
174
175
	punpckhbw mmA,mmD		; mmA=(00 02 04 06 10 12 14 16)
176
	psllq     mmD,4*BYTE_BIT	; mmD=(-- -- -- -- 11 15 21 25)
177
178
	punpcklbw mmE,mmG		; mmE=(20 22 24 26 01 03 05 07)
179
	punpckhbw mmD,mmG		; mmD=(11 13 15 17 21 23 25 27)
180
181
	pxor      mmH,mmH
182
183
	movq      mmC,mmA
184
	punpcklbw mmA,mmH		; mmA=(00 02 04 06)
185
	punpckhbw mmC,mmH		; mmC=(10 12 14 16)
186
187
	movq      mmB,mmE
188
	punpcklbw mmE,mmH		; mmE=(20 22 24 26)
189
	punpckhbw mmB,mmH		; mmB=(01 03 05 07)
190
191
	movq      mmF,mmD
192
	punpcklbw mmD,mmH		; mmD=(11 13 15 17)
193
	punpckhbw mmF,mmH		; mmF=(21 23 25 27)
194
195
%else ; RGB_PIXELSIZE == 4 ; -----------
196
197
.column_ld1:
198
	test	cl, SIZEOF_MMWORD/8
199
	jz	short .column_ld2
200
	sub	ecx, byte SIZEOF_MMWORD/8
201
	movd	mmA, DWORD [esi+ecx*RGB_PIXELSIZE]
202
.column_ld2:
203
	test	cl, SIZEOF_MMWORD/4
204
	jz	short .column_ld4
205
	sub	ecx, byte SIZEOF_MMWORD/4
206
	movq	mmF,mmA
207
	movq	mmA, MMWORD [esi+ecx*RGB_PIXELSIZE]
208
.column_ld4:
209
	test	cl, SIZEOF_MMWORD/2
210
	mov	ecx, SIZEOF_MMWORD
211
	jz	short .rgb_ycc_cnv
212
	movq	mmD,mmA
213
	movq	mmC,mmF
214
	movq	mmA, MMWORD [esi+0*SIZEOF_MMWORD]
215
	movq	mmF, MMWORD [esi+1*SIZEOF_MMWORD]
216
	jmp	short .rgb_ycc_cnv
217
	alignx	16,7
218
219
.columnloop:
220
	movq	mmA, MMWORD [esi+0*SIZEOF_MMWORD]
221
	movq	mmF, MMWORD [esi+1*SIZEOF_MMWORD]
222
	movq	mmD, MMWORD [esi+2*SIZEOF_MMWORD]
223
	movq	mmC, MMWORD [esi+3*SIZEOF_MMWORD]
224
225
.rgb_ycc_cnv:
226
	; mmA=(00 10 20 30 01 11 21 31)
227
	; mmF=(02 12 22 32 03 13 23 33)
228
	; mmD=(04 14 24 34 05 15 25 35)
229
	; mmC=(06 16 26 36 07 17 27 37)
230
231
	movq      mmB,mmA
232
	punpcklbw mmA,mmF		; mmA=(00 02 10 12 20 22 30 32)
233
	punpckhbw mmB,mmF		; mmB=(01 03 11 13 21 23 31 33)
234
235
	movq      mmG,mmD
236
	punpcklbw mmD,mmC		; mmD=(04 06 14 16 24 26 34 36)
237
	punpckhbw mmG,mmC		; mmG=(05 07 15 17 25 27 35 37)
238
239
	movq      mmE,mmA
240
	punpcklwd mmA,mmD		; mmA=(00 02 04 06 10 12 14 16)
241
	punpckhwd mmE,mmD		; mmE=(20 22 24 26 30 32 34 36)
242
243
	movq      mmH,mmB
244
	punpcklwd mmB,mmG		; mmB=(01 03 05 07 11 13 15 17)
245
	punpckhwd mmH,mmG		; mmH=(21 23 25 27 31 33 35 37)
246
247
	pxor      mmF,mmF
248
249
	movq      mmC,mmA
250
	punpcklbw mmA,mmF		; mmA=(00 02 04 06)
251
	punpckhbw mmC,mmF		; mmC=(10 12 14 16)
252
253
	movq      mmD,mmB
254
	punpcklbw mmB,mmF		; mmB=(01 03 05 07)
255
	punpckhbw mmD,mmF		; mmD=(11 13 15 17)
256
257
	movq      mmG,mmE
258
	punpcklbw mmE,mmF		; mmE=(20 22 24 26)
259
	punpckhbw mmG,mmF		; mmG=(30 32 34 36)
260
261
	punpcklbw mmF,mmH
262
	punpckhbw mmH,mmH
263
	psrlw     mmF,BYTE_BIT		; mmF=(21 23 25 27)
264
	psrlw     mmH,BYTE_BIT		; mmH=(31 33 35 37)
265
266
%endif ; RGB_PIXELSIZE ; ---------------
267
268
	; mm0=(R0 R2 R4 R6)=RE, mm2=(G0 G2 G4 G6)=GE, mm4=(B0 B2 B4 B6)=BE
269
	; mm1=(R1 R3 R5 R7)=RO, mm3=(G1 G3 G5 G7)=GO, mm5=(B1 B3 B5 B7)=BO
270
271
	; (Original)
272
	; Y  =  0.29900 * R + 0.58700 * G + 0.11400 * B
273
	; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
274
	; Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
275
	;
276
	; (This implementation)
277
	; Y  =  0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
278
	; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
279
	; Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
280
281
	movq      MMWORD [wk(0)], mm0	; wk(0)=RE
282
	movq      MMWORD [wk(1)], mm1	; wk(1)=RO
283
	movq      MMWORD [wk(2)], mm4	; wk(2)=BE
284
	movq      MMWORD [wk(3)], mm5	; wk(3)=BO
285
286
	movq      mm6,mm1
287
	punpcklwd mm1,mm3
288
	punpckhwd mm6,mm3
289
	movq      mm7,mm1
290
	movq      mm4,mm6
291
	pmaddwd   mm1,[GOTOFF(eax,PW_F0299_F0337)] ; mm1=ROL*FIX(0.299)+GOL*FIX(0.337)
292
	pmaddwd   mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=ROH*FIX(0.299)+GOH*FIX(0.337)
293
	pmaddwd   mm7,[GOTOFF(eax,PW_MF016_MF033)] ; mm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
294
	pmaddwd   mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
295
296
	movq      MMWORD [wk(4)], mm1	; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
297
	movq      MMWORD [wk(5)], mm6	; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
298
299
	pxor      mm1,mm1
300
	pxor      mm6,mm6
301
	punpcklwd mm1,mm5		; mm1=BOL
302
	punpckhwd mm6,mm5		; mm6=BOH
303
	psrld     mm1,1			; mm1=BOL*FIX(0.500)
304
	psrld     mm6,1			; mm6=BOH*FIX(0.500)
305
306
	movq      mm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm5=[PD_ONEHALFM1_CJ]
307
308
	paddd     mm7,mm1
309
	paddd     mm4,mm6
310
	paddd     mm7,mm5
311
	paddd     mm4,mm5
312
	psrld     mm7,SCALEBITS		; mm7=CbOL
313
	psrld     mm4,SCALEBITS		; mm4=CbOH
314
	packssdw  mm7,mm4		; mm7=CbO
315
316
	movq      mm1, MMWORD [wk(2)]	; mm1=BE
317
318
	movq      mm6,mm0
319
	punpcklwd mm0,mm2
320
	punpckhwd mm6,mm2
321
	movq      mm5,mm0
322
	movq      mm4,mm6
323
	pmaddwd   mm0,[GOTOFF(eax,PW_F0299_F0337)] ; mm0=REL*FIX(0.299)+GEL*FIX(0.337)
324
	pmaddwd   mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=REH*FIX(0.299)+GEH*FIX(0.337)
325
	pmaddwd   mm5,[GOTOFF(eax,PW_MF016_MF033)] ; mm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
326
	pmaddwd   mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
327
328
	movq      MMWORD [wk(6)], mm0	; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
329
	movq      MMWORD [wk(7)], mm6	; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
330
331
	pxor      mm0,mm0
332
	pxor      mm6,mm6
333
	punpcklwd mm0,mm1		; mm0=BEL
334
	punpckhwd mm6,mm1		; mm6=BEH
335
	psrld     mm0,1			; mm0=BEL*FIX(0.500)
336
	psrld     mm6,1			; mm6=BEH*FIX(0.500)
337
338
	movq      mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ]
339
340
	paddd     mm5,mm0
341
	paddd     mm4,mm6
342
	paddd     mm5,mm1
343
	paddd     mm4,mm1
344
	psrld     mm5,SCALEBITS		; mm5=CbEL
345
	psrld     mm4,SCALEBITS		; mm4=CbEH
346
	packssdw  mm5,mm4		; mm5=CbE
347
348
	psllw     mm7,BYTE_BIT
349
	por       mm5,mm7		; mm5=Cb
350
	movq      MMWORD [ebx], mm5	; Save Cb
351
352
	movq      mm0, MMWORD [wk(3)]	; mm0=BO
353
	movq      mm6, MMWORD [wk(2)]	; mm6=BE
354
	movq      mm1, MMWORD [wk(1)]	; mm1=RO
355
356
	movq      mm4,mm0
357
	punpcklwd mm0,mm3
358
	punpckhwd mm4,mm3
359
	movq      mm7,mm0
360
	movq      mm5,mm4
361
	pmaddwd   mm0,[GOTOFF(eax,PW_F0114_F0250)] ; mm0=BOL*FIX(0.114)+GOL*FIX(0.250)
362
	pmaddwd   mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BOH*FIX(0.114)+GOH*FIX(0.250)
363
	pmaddwd   mm7,[GOTOFF(eax,PW_MF008_MF041)] ; mm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
364
	pmaddwd   mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
365
366
	movq      mm3,[GOTOFF(eax,PD_ONEHALF)]	; mm3=[PD_ONEHALF]
367
368
	paddd     mm0, MMWORD [wk(4)]
369
	paddd     mm4, MMWORD [wk(5)]
370
	paddd     mm0,mm3
371
	paddd     mm4,mm3
372
	psrld     mm0,SCALEBITS		; mm0=YOL
373
	psrld     mm4,SCALEBITS		; mm4=YOH
374
	packssdw  mm0,mm4		; mm0=YO
375
376
	pxor      mm3,mm3
377
	pxor      mm4,mm4
378
	punpcklwd mm3,mm1		; mm3=ROL
379
	punpckhwd mm4,mm1		; mm4=ROH
380
	psrld     mm3,1			; mm3=ROL*FIX(0.500)
381
	psrld     mm4,1			; mm4=ROH*FIX(0.500)
382
383
	movq      mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ]
384
385
	paddd     mm7,mm3
386
	paddd     mm5,mm4
387
	paddd     mm7,mm1
388
	paddd     mm5,mm1
389
	psrld     mm7,SCALEBITS		; mm7=CrOL
390
	psrld     mm5,SCALEBITS		; mm5=CrOH
391
	packssdw  mm7,mm5		; mm7=CrO
392
393
	movq      mm3, MMWORD [wk(0)]	; mm3=RE
394
395
	movq      mm4,mm6
396
	punpcklwd mm6,mm2
397
	punpckhwd mm4,mm2
398
	movq      mm1,mm6
399
	movq      mm5,mm4
400
	pmaddwd   mm6,[GOTOFF(eax,PW_F0114_F0250)] ; mm6=BEL*FIX(0.114)+GEL*FIX(0.250)
401
	pmaddwd   mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BEH*FIX(0.114)+GEH*FIX(0.250)
402
	pmaddwd   mm1,[GOTOFF(eax,PW_MF008_MF041)] ; mm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
403
	pmaddwd   mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
404
405
	movq      mm2,[GOTOFF(eax,PD_ONEHALF)]	; mm2=[PD_ONEHALF]
406
407
	paddd     mm6, MMWORD [wk(6)]
408
	paddd     mm4, MMWORD [wk(7)]
409
	paddd     mm6,mm2
410
	paddd     mm4,mm2
411
	psrld     mm6,SCALEBITS		; mm6=YEL
412
	psrld     mm4,SCALEBITS		; mm4=YEH
413
	packssdw  mm6,mm4		; mm6=YE
414
415
	psllw     mm0,BYTE_BIT
416
	por       mm6,mm0		; mm6=Y
417
	movq      MMWORD [edi], mm6	; Save Y
418
419
	pxor      mm2,mm2
420
	pxor      mm4,mm4
421
	punpcklwd mm2,mm3		; mm2=REL
422
	punpckhwd mm4,mm3		; mm4=REH
423
	psrld     mm2,1			; mm2=REL*FIX(0.500)
424
	psrld     mm4,1			; mm4=REH*FIX(0.500)
425
426
	movq      mm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm0=[PD_ONEHALFM1_CJ]
427
428
	paddd     mm1,mm2
429
	paddd     mm5,mm4
430
	paddd     mm1,mm0
431
	paddd     mm5,mm0
432
	psrld     mm1,SCALEBITS		; mm1=CrEL
433
	psrld     mm5,SCALEBITS		; mm5=CrEH
434
	packssdw  mm1,mm5		; mm1=CrE
435
436
	psllw     mm7,BYTE_BIT
437
	por       mm1,mm7		; mm1=Cr
438
	movq      MMWORD [edx], mm1	; Save Cr
439
440
	sub	ecx, byte SIZEOF_MMWORD
441
	add	esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD	; inptr
442
	add	edi, byte SIZEOF_MMWORD			; outptr0
443
	add	ebx, byte SIZEOF_MMWORD			; outptr1
444
	add	edx, byte SIZEOF_MMWORD			; outptr2
445
	cmp	ecx, byte SIZEOF_MMWORD
446
	jae	near .columnloop
447
	test	ecx,ecx
448
	jnz	near .column_ld1
449
450
	pop	ecx			; col
451
	pop	esi
452
	pop	edi
453
	pop	ebx
454
	pop	edx
455
	poppic	eax
456
457
	add	esi, byte SIZEOF_JSAMPROW	; input_buf
458
	add	edi, byte SIZEOF_JSAMPROW
459
	add	ebx, byte SIZEOF_JSAMPROW
460
	add	edx, byte SIZEOF_JSAMPROW
461
	dec	eax				; num_rows
462
	jg	near .rowloop
463
464
	emms		; empty MMX state
465
466
.return:
467
	pop	edi
468
	pop	esi
469
;	pop	edx		; need not be preserved
470
;	pop	ecx		; need not be preserved
471
	pop	ebx
472
	mov	esp,ebp		; esp <- aligned ebp
473
	pop	esp		; esp <- original ebp
474
	pop	ebp
475
	ret
476
477
; For some reason, the OS X linker does not honor the request to align the
478
; segment unless we do this.
479
	align	16
(-)a/jpeg/simd/jcclrss2-64.asm (+487 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcclrss2-64.asm - colorspace conversion (64-bit SSE2)
3
;
4
; x86 SIMD extension for IJG JPEG library
5
; Copyright (C) 1999-2006, MIYASAKA Masaru.
6
; Copyright (C) 2009, D. R. Commander.
7
; For conditions of distribution and use, see copyright notice in jsimdext.inc
8
;
9
; This file should be assembled with NASM (Netwide Assembler),
10
; can *not* be assembled with Microsoft's MASM or any compatible
11
; assembler (including Borland's Turbo Assembler).
12
; NASM is available from http://nasm.sourceforge.net/ or
13
; http://sourceforge.net/project/showfiles.php?group_id=6208
14
;
15
; [TAB8]
16
17
%include "jcolsamp.inc"
18
19
; --------------------------------------------------------------------------
20
	SECTION	SEG_TEXT
21
	BITS	64
22
;
23
; Convert some rows of samples to the output colorspace.
24
;
25
; GLOBAL(void)
26
; jsimd_rgb_ycc_convert_sse2 (JDIMENSION img_width,
27
;                             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
28
;                             JDIMENSION output_row, int num_rows);
29
;
30
31
; r10 = JDIMENSION img_width
32
; r11 = JSAMPARRAY input_buf
33
; r12 = JSAMPIMAGE output_buf
34
; r13 = JDIMENSION output_row
35
; r14 = int num_rows
36
37
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
38
%define WK_NUM		8
39
40
	align	16
41
42
	global	EXTN(jsimd_rgb_ycc_convert_sse2)
43
44
EXTN(jsimd_rgb_ycc_convert_sse2):
45
	push	rbp
46
	mov	rax,rsp				; rax = original rbp
47
	sub	rsp, byte 4
48
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
49
	mov	[rsp],rax
50
	mov	rbp,rsp				; rbp = aligned rbp
51
	lea	rsp, [wk(0)]
52
	collect_args
53
	push	rbx
54
55
	mov	rcx, r10
56
	test	rcx,rcx
57
	jz	near .return
58
59
	push	rcx
60
61
	mov rsi, r12
62
	mov rcx, r13
63
	mov	rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
64
	mov	rbx, JSAMPARRAY [rsi+1*SIZEOF_JSAMPARRAY]
65
	mov	rdx, JSAMPARRAY [rsi+2*SIZEOF_JSAMPARRAY]
66
	lea	rdi, [rdi+rcx*SIZEOF_JSAMPROW]
67
	lea	rbx, [rbx+rcx*SIZEOF_JSAMPROW]
68
	lea	rdx, [rdx+rcx*SIZEOF_JSAMPROW]
69
70
	pop	rcx
71
72
	mov rsi, r11
73
	mov	eax, r14d
74
	test	rax,rax
75
	jle	near .return
76
.rowloop:
77
	push	rdx
78
	push	rbx
79
	push	rdi
80
	push	rsi
81
	push	rcx			; col
82
83
	mov	rsi, JSAMPROW [rsi]	; inptr
84
	mov	rdi, JSAMPROW [rdi]	; outptr0
85
	mov	rbx, JSAMPROW [rbx]	; outptr1
86
	mov	rdx, JSAMPROW [rdx]	; outptr2
87
88
	cmp	rcx, byte SIZEOF_XMMWORD
89
	jae	near .columnloop
90
91
%if RGB_PIXELSIZE == 3 ; ---------------
92
93
.column_ld1:
94
	push	rax
95
	push	rdx
96
	lea	rcx,[rcx+rcx*2]		; imul ecx,RGB_PIXELSIZE
97
	test	cl, SIZEOF_BYTE
98
	jz	short .column_ld2
99
	sub	rcx, byte SIZEOF_BYTE
100
	movzx	rax, BYTE [rsi+rcx]
101
.column_ld2:
102
	test	cl, SIZEOF_WORD
103
	jz	short .column_ld4
104
	sub	rcx, byte SIZEOF_WORD
105
	movzx	rdx, WORD [rsi+rcx]
106
	shl	rax, WORD_BIT
107
	or	rax,rdx
108
.column_ld4:
109
	movd	xmmA,eax
110
	pop	rdx
111
	pop	rax
112
	test	cl, SIZEOF_DWORD
113
	jz	short .column_ld8
114
	sub	rcx, byte SIZEOF_DWORD
115
	movd	xmmF, XMM_DWORD [rsi+rcx]
116
	pslldq	xmmA, SIZEOF_DWORD
117
	por	xmmA,xmmF
118
.column_ld8:
119
	test	cl, SIZEOF_MMWORD
120
	jz	short .column_ld16
121
	sub	rcx, byte SIZEOF_MMWORD
122
	movq	xmmB, XMM_MMWORD [rsi+rcx]
123
	pslldq	xmmA, SIZEOF_MMWORD
124
	por	xmmA,xmmB
125
.column_ld16:
126
	test	cl, SIZEOF_XMMWORD
127
	jz	short .column_ld32
128
	movdqa	xmmF,xmmA
129
	movdqu	xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
130
	mov	rcx, SIZEOF_XMMWORD
131
	jmp	short .rgb_ycc_cnv
132
.column_ld32:
133
	test	cl, 2*SIZEOF_XMMWORD
134
	mov	rcx, SIZEOF_XMMWORD
135
	jz	short .rgb_ycc_cnv
136
	movdqa	xmmB,xmmA
137
	movdqu	xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
138
	movdqu	xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
139
	jmp	short .rgb_ycc_cnv
140
141
.columnloop:
142
	movdqu	xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
143
	movdqu	xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
144
	movdqu	xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
145
146
.rgb_ycc_cnv:
147
	; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
148
	; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
149
	; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
150
151
	movdqa    xmmG,xmmA
152
	pslldq    xmmA,8	; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
153
	psrldq    xmmG,8	; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
154
155
	punpckhbw xmmA,xmmF	; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
156
	pslldq    xmmF,8	; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
157
158
	punpcklbw xmmG,xmmB	; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
159
	punpckhbw xmmF,xmmB	; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
160
161
	movdqa    xmmD,xmmA
162
	pslldq    xmmA,8	; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
163
	psrldq    xmmD,8	; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
164
165
	punpckhbw xmmA,xmmG	; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
166
	pslldq    xmmG,8	; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
167
168
	punpcklbw xmmD,xmmF	; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
169
	punpckhbw xmmG,xmmF	; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
170
171
	movdqa    xmmE,xmmA
172
	pslldq    xmmA,8	; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
173
	psrldq    xmmE,8	; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
174
175
	punpckhbw xmmA,xmmD	; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
176
	pslldq    xmmD,8	; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
177
178
	punpcklbw xmmE,xmmG	; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
179
	punpckhbw xmmD,xmmG	; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
180
181
	pxor      xmmH,xmmH
182
183
	movdqa    xmmC,xmmA
184
	punpcklbw xmmA,xmmH	; xmmA=(00 02 04 06 08 0A 0C 0E)
185
	punpckhbw xmmC,xmmH	; xmmC=(10 12 14 16 18 1A 1C 1E)
186
187
	movdqa    xmmB,xmmE
188
	punpcklbw xmmE,xmmH	; xmmE=(20 22 24 26 28 2A 2C 2E)
189
	punpckhbw xmmB,xmmH	; xmmB=(01 03 05 07 09 0B 0D 0F)
190
191
	movdqa    xmmF,xmmD
192
	punpcklbw xmmD,xmmH	; xmmD=(11 13 15 17 19 1B 1D 1F)
193
	punpckhbw xmmF,xmmH	; xmmF=(21 23 25 27 29 2B 2D 2F)
194
195
%else ; RGB_PIXELSIZE == 4 ; -----------
196
197
.column_ld1:
198
	test	cl, SIZEOF_XMMWORD/16
199
	jz	short .column_ld2
200
	sub	rcx, byte SIZEOF_XMMWORD/16
201
	movd	xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
202
.column_ld2:
203
	test	cl, SIZEOF_XMMWORD/8
204
	jz	short .column_ld4
205
	sub	rcx, byte SIZEOF_XMMWORD/8
206
	movq	xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
207
	pslldq	xmmA, SIZEOF_MMWORD
208
	por	xmmA,xmmE
209
.column_ld4:
210
	test	cl, SIZEOF_XMMWORD/4
211
	jz	short .column_ld8
212
	sub	rcx, byte SIZEOF_XMMWORD/4
213
	movdqa	xmmE,xmmA
214
	movdqu	xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
215
.column_ld8:
216
	test	cl, SIZEOF_XMMWORD/2
217
	mov	rcx, SIZEOF_XMMWORD
218
	jz	short .rgb_ycc_cnv
219
	movdqa	xmmF,xmmA
220
	movdqa	xmmH,xmmE
221
	movdqu	xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
222
	movdqu	xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
223
	jmp	short .rgb_ycc_cnv
224
225
.columnloop:
226
	movdqu	xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
227
	movdqu	xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
228
	movdqu	xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
229
	movdqu	xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
230
231
.rgb_ycc_cnv:
232
	; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
233
	; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
234
	; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
235
	; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
236
237
	movdqa    xmmD,xmmA
238
	punpcklbw xmmA,xmmE	; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
239
	punpckhbw xmmD,xmmE	; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
240
241
	movdqa    xmmC,xmmF
242
	punpcklbw xmmF,xmmH	; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
243
	punpckhbw xmmC,xmmH	; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
244
245
	movdqa    xmmB,xmmA
246
	punpcklwd xmmA,xmmF	; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
247
	punpckhwd xmmB,xmmF	; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
248
249
	movdqa    xmmG,xmmD
250
	punpcklwd xmmD,xmmC	; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
251
	punpckhwd xmmG,xmmC	; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
252
253
	movdqa    xmmE,xmmA
254
	punpcklbw xmmA,xmmD	; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
255
	punpckhbw xmmE,xmmD	; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
256
257
	movdqa    xmmH,xmmB
258
	punpcklbw xmmB,xmmG	; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
259
	punpckhbw xmmH,xmmG	; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
260
261
	pxor      xmmF,xmmF
262
263
	movdqa    xmmC,xmmA
264
	punpcklbw xmmA,xmmF	; xmmA=(00 02 04 06 08 0A 0C 0E)
265
	punpckhbw xmmC,xmmF	; xmmC=(10 12 14 16 18 1A 1C 1E)
266
267
	movdqa    xmmD,xmmB
268
	punpcklbw xmmB,xmmF	; xmmB=(01 03 05 07 09 0B 0D 0F)
269
	punpckhbw xmmD,xmmF	; xmmD=(11 13 15 17 19 1B 1D 1F)
270
271
	movdqa    xmmG,xmmE
272
	punpcklbw xmmE,xmmF	; xmmE=(20 22 24 26 28 2A 2C 2E)
273
	punpckhbw xmmG,xmmF	; xmmG=(30 32 34 36 38 3A 3C 3E)
274
275
	punpcklbw xmmF,xmmH
276
	punpckhbw xmmH,xmmH
277
	psrlw     xmmF,BYTE_BIT	; xmmF=(21 23 25 27 29 2B 2D 2F)
278
	psrlw     xmmH,BYTE_BIT	; xmmH=(31 33 35 37 39 3B 3D 3F)
279
280
%endif ; RGB_PIXELSIZE ; ---------------
281
282
	; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
283
	; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
284
285
	; (Original)
286
	; Y  =  0.29900 * R + 0.58700 * G + 0.11400 * B
287
	; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
288
	; Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
289
	;
290
	; (This implementation)
291
	; Y  =  0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
292
	; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
293
	; Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
294
295
	movdqa    XMMWORD [wk(0)], xmm0	; wk(0)=RE
296
	movdqa    XMMWORD [wk(1)], xmm1	; wk(1)=RO
297
	movdqa    XMMWORD [wk(2)], xmm4	; wk(2)=BE
298
	movdqa    XMMWORD [wk(3)], xmm5	; wk(3)=BO
299
300
	movdqa    xmm6,xmm1
301
	punpcklwd xmm1,xmm3
302
	punpckhwd xmm6,xmm3
303
	movdqa    xmm7,xmm1
304
	movdqa    xmm4,xmm6
305
	pmaddwd   xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
306
	pmaddwd   xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
307
	pmaddwd   xmm7,[rel PW_MF016_MF033] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
308
	pmaddwd   xmm4,[rel PW_MF016_MF033] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
309
310
	movdqa    XMMWORD [wk(4)], xmm1	; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
311
	movdqa    XMMWORD [wk(5)], xmm6	; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
312
313
	pxor      xmm1,xmm1
314
	pxor      xmm6,xmm6
315
	punpcklwd xmm1,xmm5		; xmm1=BOL
316
	punpckhwd xmm6,xmm5		; xmm6=BOH
317
	psrld     xmm1,1		; xmm1=BOL*FIX(0.500)
318
	psrld     xmm6,1		; xmm6=BOH*FIX(0.500)
319
320
	movdqa    xmm5,[rel PD_ONEHALFM1_CJ] ; xmm5=[PD_ONEHALFM1_CJ]
321
322
	paddd     xmm7,xmm1
323
	paddd     xmm4,xmm6
324
	paddd     xmm7,xmm5
325
	paddd     xmm4,xmm5
326
	psrld     xmm7,SCALEBITS	; xmm7=CbOL
327
	psrld     xmm4,SCALEBITS	; xmm4=CbOH
328
	packssdw  xmm7,xmm4		; xmm7=CbO
329
330
	movdqa    xmm1, XMMWORD [wk(2)]	; xmm1=BE
331
332
	movdqa    xmm6,xmm0
333
	punpcklwd xmm0,xmm2
334
	punpckhwd xmm6,xmm2
335
	movdqa    xmm5,xmm0
336
	movdqa    xmm4,xmm6
337
	pmaddwd   xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
338
	pmaddwd   xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
339
	pmaddwd   xmm5,[rel PW_MF016_MF033] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
340
	pmaddwd   xmm4,[rel PW_MF016_MF033] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
341
342
	movdqa    XMMWORD [wk(6)], xmm0	; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
343
	movdqa    XMMWORD [wk(7)], xmm6	; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
344
345
	pxor      xmm0,xmm0
346
	pxor      xmm6,xmm6
347
	punpcklwd xmm0,xmm1		; xmm0=BEL
348
	punpckhwd xmm6,xmm1		; xmm6=BEH
349
	psrld     xmm0,1		; xmm0=BEL*FIX(0.500)
350
	psrld     xmm6,1		; xmm6=BEH*FIX(0.500)
351
352
	movdqa    xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
353
354
	paddd     xmm5,xmm0
355
	paddd     xmm4,xmm6
356
	paddd     xmm5,xmm1
357
	paddd     xmm4,xmm1
358
	psrld     xmm5,SCALEBITS	; xmm5=CbEL
359
	psrld     xmm4,SCALEBITS	; xmm4=CbEH
360
	packssdw  xmm5,xmm4		; xmm5=CbE
361
362
	psllw     xmm7,BYTE_BIT
363
	por       xmm5,xmm7		; xmm5=Cb
364
	movdqa    XMMWORD [rbx], xmm5	; Save Cb
365
366
	movdqa    xmm0, XMMWORD [wk(3)]	; xmm0=BO
367
	movdqa    xmm6, XMMWORD [wk(2)]	; xmm6=BE
368
	movdqa    xmm1, XMMWORD [wk(1)]	; xmm1=RO
369
370
	movdqa    xmm4,xmm0
371
	punpcklwd xmm0,xmm3
372
	punpckhwd xmm4,xmm3
373
	movdqa    xmm7,xmm0
374
	movdqa    xmm5,xmm4
375
	pmaddwd   xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
376
	pmaddwd   xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
377
	pmaddwd   xmm7,[rel PW_MF008_MF041] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
378
	pmaddwd   xmm5,[rel PW_MF008_MF041] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
379
380
	movdqa    xmm3,[rel PD_ONEHALF]	; xmm3=[PD_ONEHALF]
381
382
	paddd     xmm0, XMMWORD [wk(4)]
383
	paddd     xmm4, XMMWORD [wk(5)]
384
	paddd     xmm0,xmm3
385
	paddd     xmm4,xmm3
386
	psrld     xmm0,SCALEBITS	; xmm0=YOL
387
	psrld     xmm4,SCALEBITS	; xmm4=YOH
388
	packssdw  xmm0,xmm4		; xmm0=YO
389
390
	pxor      xmm3,xmm3
391
	pxor      xmm4,xmm4
392
	punpcklwd xmm3,xmm1		; xmm3=ROL
393
	punpckhwd xmm4,xmm1		; xmm4=ROH
394
	psrld     xmm3,1		; xmm3=ROL*FIX(0.500)
395
	psrld     xmm4,1		; xmm4=ROH*FIX(0.500)
396
397
	movdqa    xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
398
399
	paddd     xmm7,xmm3
400
	paddd     xmm5,xmm4
401
	paddd     xmm7,xmm1
402
	paddd     xmm5,xmm1
403
	psrld     xmm7,SCALEBITS	; xmm7=CrOL
404
	psrld     xmm5,SCALEBITS	; xmm5=CrOH
405
	packssdw  xmm7,xmm5		; xmm7=CrO
406
407
	movdqa    xmm3, XMMWORD [wk(0)]	; xmm3=RE
408
409
	movdqa    xmm4,xmm6
410
	punpcklwd xmm6,xmm2
411
	punpckhwd xmm4,xmm2
412
	movdqa    xmm1,xmm6
413
	movdqa    xmm5,xmm4
414
	pmaddwd   xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
415
	pmaddwd   xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
416
	pmaddwd   xmm1,[rel PW_MF008_MF041] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
417
	pmaddwd   xmm5,[rel PW_MF008_MF041] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
418
419
	movdqa    xmm2,[rel PD_ONEHALF]	; xmm2=[PD_ONEHALF]
420
421
	paddd     xmm6, XMMWORD [wk(6)]
422
	paddd     xmm4, XMMWORD [wk(7)]
423
	paddd     xmm6,xmm2
424
	paddd     xmm4,xmm2
425
	psrld     xmm6,SCALEBITS	; xmm6=YEL
426
	psrld     xmm4,SCALEBITS	; xmm4=YEH
427
	packssdw  xmm6,xmm4		; xmm6=YE
428
429
	psllw     xmm0,BYTE_BIT
430
	por       xmm6,xmm0		; xmm6=Y
431
	movdqa    XMMWORD [rdi], xmm6	; Save Y
432
433
	pxor      xmm2,xmm2
434
	pxor      xmm4,xmm4
435
	punpcklwd xmm2,xmm3		; xmm2=REL
436
	punpckhwd xmm4,xmm3		; xmm4=REH
437
	psrld     xmm2,1		; xmm2=REL*FIX(0.500)
438
	psrld     xmm4,1		; xmm4=REH*FIX(0.500)
439
440
	movdqa    xmm0,[rel PD_ONEHALFM1_CJ] ; xmm0=[PD_ONEHALFM1_CJ]
441
442
	paddd     xmm1,xmm2
443
	paddd     xmm5,xmm4
444
	paddd     xmm1,xmm0
445
	paddd     xmm5,xmm0
446
	psrld     xmm1,SCALEBITS	; xmm1=CrEL
447
	psrld     xmm5,SCALEBITS	; xmm5=CrEH
448
	packssdw  xmm1,xmm5		; xmm1=CrE
449
450
	psllw     xmm7,BYTE_BIT
451
	por       xmm1,xmm7		; xmm1=Cr
452
	movdqa    XMMWORD [rdx], xmm1	; Save Cr
453
454
	sub	rcx, byte SIZEOF_XMMWORD
455
	add	rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; inptr
456
	add	rdi, byte SIZEOF_XMMWORD		; outptr0
457
	add	rbx, byte SIZEOF_XMMWORD		; outptr1
458
	add	rdx, byte SIZEOF_XMMWORD		; outptr2
459
	cmp	rcx, byte SIZEOF_XMMWORD
460
	jae	near .columnloop
461
	test	rcx,rcx
462
	jnz	near .column_ld1
463
464
	pop	rcx			; col
465
	pop	rsi
466
	pop	rdi
467
	pop	rbx
468
	pop	rdx
469
470
	add	rsi, byte SIZEOF_JSAMPROW	; input_buf
471
	add	rdi, byte SIZEOF_JSAMPROW
472
	add	rbx, byte SIZEOF_JSAMPROW
473
	add	rdx, byte SIZEOF_JSAMPROW
474
	dec	rax				; num_rows
475
	jg	near .rowloop
476
477
.return:
478
	pop	rbx
479
	uncollect_args
480
	mov	rsp,rbp		; rsp <- aligned rbp
481
	pop	rsp		; rsp <- original rbp
482
	pop	rbp
483
	ret
484
485
; For some reason, the OS X linker does not honor the request to align the
486
; segment unless we do this.
487
	align	16
(-)a/jpeg/simd/jcclrss2.asm (+505 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcclrss2.asm - colorspace conversion (SSE2)
3
;
4
; x86 SIMD extension for IJG JPEG library
5
; Copyright (C) 1999-2006, MIYASAKA Masaru.
6
; For conditions of distribution and use, see copyright notice in jsimdext.inc
7
;
8
; This file should be assembled with NASM (Netwide Assembler),
9
; can *not* be assembled with Microsoft's MASM or any compatible
10
; assembler (including Borland's Turbo Assembler).
11
; NASM is available from http://nasm.sourceforge.net/ or
12
; http://sourceforge.net/project/showfiles.php?group_id=6208
13
;
14
; [TAB8]
15
16
%include "jcolsamp.inc"
17
18
; --------------------------------------------------------------------------
19
	SECTION	SEG_TEXT
20
	BITS	32
21
;
22
; Convert some rows of samples to the output colorspace.
23
;
24
; GLOBAL(void)
25
; jsimd_rgb_ycc_convert_sse2 (JDIMENSION img_width,
26
;                             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
27
;                             JDIMENSION output_row, int num_rows);
28
;
29
30
%define img_width(b)	(b)+8			; JDIMENSION img_width
31
%define input_buf(b)	(b)+12		; JSAMPARRAY input_buf
32
%define output_buf(b)	(b)+16		; JSAMPIMAGE output_buf
33
%define output_row(b)	(b)+20		; JDIMENSION output_row
34
%define num_rows(b)	(b)+24		; int num_rows
35
36
%define original_ebp	ebp+0
37
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
38
%define WK_NUM		8
39
%define gotptr		wk(0)-SIZEOF_POINTER	; void * gotptr
40
41
	align	16
42
43
	global	EXTN(jsimd_rgb_ycc_convert_sse2)
44
45
EXTN(jsimd_rgb_ycc_convert_sse2):
46
	push	ebp
47
	mov	eax,esp				; eax = original ebp
48
	sub	esp, byte 4
49
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
50
	mov	[esp],eax
51
	mov	ebp,esp				; ebp = aligned ebp
52
	lea	esp, [wk(0)]
53
	pushpic	eax		; make a room for GOT address
54
	push	ebx
55
;	push	ecx		; need not be preserved
56
;	push	edx		; need not be preserved
57
	push	esi
58
	push	edi
59
60
	get_GOT	ebx			; get GOT address
61
	movpic	POINTER [gotptr], ebx	; save GOT address
62
63
	mov	ecx, JDIMENSION [img_width(eax)]
64
	test	ecx,ecx
65
	jz	near .return
66
67
	push	ecx
68
69
	mov	esi, JSAMPIMAGE [output_buf(eax)]
70
	mov	ecx, JDIMENSION [output_row(eax)]
71
	mov	edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY]
72
	mov	ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY]
73
	mov	edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY]
74
	lea	edi, [edi+ecx*SIZEOF_JSAMPROW]
75
	lea	ebx, [ebx+ecx*SIZEOF_JSAMPROW]
76
	lea	edx, [edx+ecx*SIZEOF_JSAMPROW]
77
78
	pop	ecx
79
80
	mov	esi, JSAMPARRAY [input_buf(eax)]
81
	mov	eax, INT [num_rows(eax)]
82
	test	eax,eax
83
	jle	near .return
84
	alignx	16,7
85
.rowloop:
86
	pushpic	eax
87
	push	edx
88
	push	ebx
89
	push	edi
90
	push	esi
91
	push	ecx			; col
92
93
	mov	esi, JSAMPROW [esi]	; inptr
94
	mov	edi, JSAMPROW [edi]	; outptr0
95
	mov	ebx, JSAMPROW [ebx]	; outptr1
96
	mov	edx, JSAMPROW [edx]	; outptr2
97
	movpic	eax, POINTER [gotptr]	; load GOT address (eax)
98
99
	cmp	ecx, byte SIZEOF_XMMWORD
100
	jae	near .columnloop
101
	alignx	16,7
102
103
%if RGB_PIXELSIZE == 3 ; ---------------
104
105
.column_ld1:
106
	push	eax
107
	push	edx
108
	lea	ecx,[ecx+ecx*2]		; imul ecx,RGB_PIXELSIZE
109
	test	cl, SIZEOF_BYTE
110
	jz	short .column_ld2
111
	sub	ecx, byte SIZEOF_BYTE
112
	movzx	eax, BYTE [esi+ecx]
113
.column_ld2:
114
	test	cl, SIZEOF_WORD
115
	jz	short .column_ld4
116
	sub	ecx, byte SIZEOF_WORD
117
	movzx	edx, WORD [esi+ecx]
118
	shl	eax, WORD_BIT
119
	or	eax,edx
120
.column_ld4:
121
	movd	xmmA,eax
122
	pop	edx
123
	pop	eax
124
	test	cl, SIZEOF_DWORD
125
	jz	short .column_ld8
126
	sub	ecx, byte SIZEOF_DWORD
127
	movd	xmmF, XMM_DWORD [esi+ecx]
128
	pslldq	xmmA, SIZEOF_DWORD
129
	por	xmmA,xmmF
130
.column_ld8:
131
	test	cl, SIZEOF_MMWORD
132
	jz	short .column_ld16
133
	sub	ecx, byte SIZEOF_MMWORD
134
	movq	xmmB, XMM_MMWORD [esi+ecx]
135
	pslldq	xmmA, SIZEOF_MMWORD
136
	por	xmmA,xmmB
137
.column_ld16:
138
	test	cl, SIZEOF_XMMWORD
139
	jz	short .column_ld32
140
	movdqa	xmmF,xmmA
141
	movdqu	xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
142
	mov	ecx, SIZEOF_XMMWORD
143
	jmp	short .rgb_ycc_cnv
144
.column_ld32:
145
	test	cl, 2*SIZEOF_XMMWORD
146
	mov	ecx, SIZEOF_XMMWORD
147
	jz	short .rgb_ycc_cnv
148
	movdqa	xmmB,xmmA
149
	movdqu	xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
150
	movdqu	xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
151
	jmp	short .rgb_ycc_cnv
152
	alignx	16,7
153
154
.columnloop:
155
	movdqu	xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
156
	movdqu	xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
157
	movdqu	xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD]
158
159
.rgb_ycc_cnv:
160
	; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
161
	; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
162
	; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
163
164
	movdqa    xmmG,xmmA
165
	pslldq    xmmA,8	; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
166
	psrldq    xmmG,8	; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
167
168
	punpckhbw xmmA,xmmF	; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
169
	pslldq    xmmF,8	; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
170
171
	punpcklbw xmmG,xmmB	; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
172
	punpckhbw xmmF,xmmB	; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
173
174
	movdqa    xmmD,xmmA
175
	pslldq    xmmA,8	; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
176
	psrldq    xmmD,8	; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
177
178
	punpckhbw xmmA,xmmG	; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
179
	pslldq    xmmG,8	; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
180
181
	punpcklbw xmmD,xmmF	; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
182
	punpckhbw xmmG,xmmF	; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
183
184
	movdqa    xmmE,xmmA
185
	pslldq    xmmA,8	; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
186
	psrldq    xmmE,8	; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
187
188
	punpckhbw xmmA,xmmD	; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
189
	pslldq    xmmD,8	; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
190
191
	punpcklbw xmmE,xmmG	; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
192
	punpckhbw xmmD,xmmG	; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
193
194
	pxor      xmmH,xmmH
195
196
	movdqa    xmmC,xmmA
197
	punpcklbw xmmA,xmmH	; xmmA=(00 02 04 06 08 0A 0C 0E)
198
	punpckhbw xmmC,xmmH	; xmmC=(10 12 14 16 18 1A 1C 1E)
199
200
	movdqa    xmmB,xmmE
201
	punpcklbw xmmE,xmmH	; xmmE=(20 22 24 26 28 2A 2C 2E)
202
	punpckhbw xmmB,xmmH	; xmmB=(01 03 05 07 09 0B 0D 0F)
203
204
	movdqa    xmmF,xmmD
205
	punpcklbw xmmD,xmmH	; xmmD=(11 13 15 17 19 1B 1D 1F)
206
	punpckhbw xmmF,xmmH	; xmmF=(21 23 25 27 29 2B 2D 2F)
207
208
%else ; RGB_PIXELSIZE == 4 ; -----------
209
210
.column_ld1:
211
	test	cl, SIZEOF_XMMWORD/16
212
	jz	short .column_ld2
213
	sub	ecx, byte SIZEOF_XMMWORD/16
214
	movd	xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE]
215
.column_ld2:
216
	test	cl, SIZEOF_XMMWORD/8
217
	jz	short .column_ld4
218
	sub	ecx, byte SIZEOF_XMMWORD/8
219
	movq	xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE]
220
	pslldq	xmmA, SIZEOF_MMWORD
221
	por	xmmA,xmmE
222
.column_ld4:
223
	test	cl, SIZEOF_XMMWORD/4
224
	jz	short .column_ld8
225
	sub	ecx, byte SIZEOF_XMMWORD/4
226
	movdqa	xmmE,xmmA
227
	movdqu	xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE]
228
.column_ld8:
229
	test	cl, SIZEOF_XMMWORD/2
230
	mov	ecx, SIZEOF_XMMWORD
231
	jz	short .rgb_ycc_cnv
232
	movdqa	xmmF,xmmA
233
	movdqa	xmmH,xmmE
234
	movdqu	xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
235
	movdqu	xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
236
	jmp	short .rgb_ycc_cnv
237
	alignx	16,7
238
239
.columnloop:
240
	movdqu	xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
241
	movdqu	xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
242
	movdqu	xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD]
243
	movdqu	xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD]
244
245
.rgb_ycc_cnv:
246
	; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
247
	; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
248
	; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
249
	; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
250
251
	movdqa    xmmD,xmmA
252
	punpcklbw xmmA,xmmE	; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
253
	punpckhbw xmmD,xmmE	; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
254
255
	movdqa    xmmC,xmmF
256
	punpcklbw xmmF,xmmH	; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
257
	punpckhbw xmmC,xmmH	; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
258
259
	movdqa    xmmB,xmmA
260
	punpcklwd xmmA,xmmF	; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
261
	punpckhwd xmmB,xmmF	; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
262
263
	movdqa    xmmG,xmmD
264
	punpcklwd xmmD,xmmC	; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
265
	punpckhwd xmmG,xmmC	; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
266
267
	movdqa    xmmE,xmmA
268
	punpcklbw xmmA,xmmD	; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
269
	punpckhbw xmmE,xmmD	; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
270
271
	movdqa    xmmH,xmmB
272
	punpcklbw xmmB,xmmG	; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
273
	punpckhbw xmmH,xmmG	; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
274
275
	pxor      xmmF,xmmF
276
277
	movdqa    xmmC,xmmA
278
	punpcklbw xmmA,xmmF	; xmmA=(00 02 04 06 08 0A 0C 0E)
279
	punpckhbw xmmC,xmmF	; xmmC=(10 12 14 16 18 1A 1C 1E)
280
281
	movdqa    xmmD,xmmB
282
	punpcklbw xmmB,xmmF	; xmmB=(01 03 05 07 09 0B 0D 0F)
283
	punpckhbw xmmD,xmmF	; xmmD=(11 13 15 17 19 1B 1D 1F)
284
285
	movdqa    xmmG,xmmE
286
	punpcklbw xmmE,xmmF	; xmmE=(20 22 24 26 28 2A 2C 2E)
287
	punpckhbw xmmG,xmmF	; xmmG=(30 32 34 36 38 3A 3C 3E)
288
289
	punpcklbw xmmF,xmmH
290
	punpckhbw xmmH,xmmH
291
	psrlw     xmmF,BYTE_BIT	; xmmF=(21 23 25 27 29 2B 2D 2F)
292
	psrlw     xmmH,BYTE_BIT	; xmmH=(31 33 35 37 39 3B 3D 3F)
293
294
%endif ; RGB_PIXELSIZE ; ---------------
295
296
	; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
297
	; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
298
299
	; (Original)
300
	; Y  =  0.29900 * R + 0.58700 * G + 0.11400 * B
301
	; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
302
	; Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
303
	;
304
	; (This implementation)
305
	; Y  =  0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
306
	; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
307
	; Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
308
309
	movdqa    XMMWORD [wk(0)], xmm0	; wk(0)=RE
310
	movdqa    XMMWORD [wk(1)], xmm1	; wk(1)=RO
311
	movdqa    XMMWORD [wk(2)], xmm4	; wk(2)=BE
312
	movdqa    XMMWORD [wk(3)], xmm5	; wk(3)=BO
313
314
	movdqa    xmm6,xmm1
315
	punpcklwd xmm1,xmm3
316
	punpckhwd xmm6,xmm3
317
	movdqa    xmm7,xmm1
318
	movdqa    xmm4,xmm6
319
	pmaddwd   xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
320
	pmaddwd   xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
321
	pmaddwd   xmm7,[GOTOFF(eax,PW_MF016_MF033)] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
322
	pmaddwd   xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
323
324
	movdqa    XMMWORD [wk(4)], xmm1	; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
325
	movdqa    XMMWORD [wk(5)], xmm6	; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
326
327
	pxor      xmm1,xmm1
328
	pxor      xmm6,xmm6
329
	punpcklwd xmm1,xmm5		; xmm1=BOL
330
	punpckhwd xmm6,xmm5		; xmm6=BOH
331
	psrld     xmm1,1		; xmm1=BOL*FIX(0.500)
332
	psrld     xmm6,1		; xmm6=BOH*FIX(0.500)
333
334
	movdqa    xmm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm5=[PD_ONEHALFM1_CJ]
335
336
	paddd     xmm7,xmm1
337
	paddd     xmm4,xmm6
338
	paddd     xmm7,xmm5
339
	paddd     xmm4,xmm5
340
	psrld     xmm7,SCALEBITS	; xmm7=CbOL
341
	psrld     xmm4,SCALEBITS	; xmm4=CbOH
342
	packssdw  xmm7,xmm4		; xmm7=CbO
343
344
	movdqa    xmm1, XMMWORD [wk(2)]	; xmm1=BE
345
346
	movdqa    xmm6,xmm0
347
	punpcklwd xmm0,xmm2
348
	punpckhwd xmm6,xmm2
349
	movdqa    xmm5,xmm0
350
	movdqa    xmm4,xmm6
351
	pmaddwd   xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
352
	pmaddwd   xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
353
	pmaddwd   xmm5,[GOTOFF(eax,PW_MF016_MF033)] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
354
	pmaddwd   xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
355
356
	movdqa    XMMWORD [wk(6)], xmm0	; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
357
	movdqa    XMMWORD [wk(7)], xmm6	; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
358
359
	pxor      xmm0,xmm0
360
	pxor      xmm6,xmm6
361
	punpcklwd xmm0,xmm1		; xmm0=BEL
362
	punpckhwd xmm6,xmm1		; xmm6=BEH
363
	psrld     xmm0,1		; xmm0=BEL*FIX(0.500)
364
	psrld     xmm6,1		; xmm6=BEH*FIX(0.500)
365
366
	movdqa    xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ]
367
368
	paddd     xmm5,xmm0
369
	paddd     xmm4,xmm6
370
	paddd     xmm5,xmm1
371
	paddd     xmm4,xmm1
372
	psrld     xmm5,SCALEBITS	; xmm5=CbEL
373
	psrld     xmm4,SCALEBITS	; xmm4=CbEH
374
	packssdw  xmm5,xmm4		; xmm5=CbE
375
376
	psllw     xmm7,BYTE_BIT
377
	por       xmm5,xmm7		; xmm5=Cb
378
	movdqa    XMMWORD [ebx], xmm5	; Save Cb
379
380
	movdqa    xmm0, XMMWORD [wk(3)]	; xmm0=BO
381
	movdqa    xmm6, XMMWORD [wk(2)]	; xmm6=BE
382
	movdqa    xmm1, XMMWORD [wk(1)]	; xmm1=RO
383
384
	movdqa    xmm4,xmm0
385
	punpcklwd xmm0,xmm3
386
	punpckhwd xmm4,xmm3
387
	movdqa    xmm7,xmm0
388
	movdqa    xmm5,xmm4
389
	pmaddwd   xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
390
	pmaddwd   xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
391
	pmaddwd   xmm7,[GOTOFF(eax,PW_MF008_MF041)] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
392
	pmaddwd   xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
393
394
	movdqa    xmm3,[GOTOFF(eax,PD_ONEHALF)]	; xmm3=[PD_ONEHALF]
395
396
	paddd     xmm0, XMMWORD [wk(4)]
397
	paddd     xmm4, XMMWORD [wk(5)]
398
	paddd     xmm0,xmm3
399
	paddd     xmm4,xmm3
400
	psrld     xmm0,SCALEBITS	; xmm0=YOL
401
	psrld     xmm4,SCALEBITS	; xmm4=YOH
402
	packssdw  xmm0,xmm4		; xmm0=YO
403
404
	pxor      xmm3,xmm3
405
	pxor      xmm4,xmm4
406
	punpcklwd xmm3,xmm1		; xmm3=ROL
407
	punpckhwd xmm4,xmm1		; xmm4=ROH
408
	psrld     xmm3,1		; xmm3=ROL*FIX(0.500)
409
	psrld     xmm4,1		; xmm4=ROH*FIX(0.500)
410
411
	movdqa    xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ]
412
413
	paddd     xmm7,xmm3
414
	paddd     xmm5,xmm4
415
	paddd     xmm7,xmm1
416
	paddd     xmm5,xmm1
417
	psrld     xmm7,SCALEBITS	; xmm7=CrOL
418
	psrld     xmm5,SCALEBITS	; xmm5=CrOH
419
	packssdw  xmm7,xmm5		; xmm7=CrO
420
421
	movdqa    xmm3, XMMWORD [wk(0)]	; xmm3=RE
422
423
	movdqa    xmm4,xmm6
424
	punpcklwd xmm6,xmm2
425
	punpckhwd xmm4,xmm2
426
	movdqa    xmm1,xmm6
427
	movdqa    xmm5,xmm4
428
	pmaddwd   xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
429
	pmaddwd   xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
430
	pmaddwd   xmm1,[GOTOFF(eax,PW_MF008_MF041)] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
431
	pmaddwd   xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
432
433
	movdqa    xmm2,[GOTOFF(eax,PD_ONEHALF)]	; xmm2=[PD_ONEHALF]
434
435
	paddd     xmm6, XMMWORD [wk(6)]
436
	paddd     xmm4, XMMWORD [wk(7)]
437
	paddd     xmm6,xmm2
438
	paddd     xmm4,xmm2
439
	psrld     xmm6,SCALEBITS	; xmm6=YEL
440
	psrld     xmm4,SCALEBITS	; xmm4=YEH
441
	packssdw  xmm6,xmm4		; xmm6=YE
442
443
	psllw     xmm0,BYTE_BIT
444
	por       xmm6,xmm0		; xmm6=Y
445
	movdqa    XMMWORD [edi], xmm6	; Save Y
446
447
	pxor      xmm2,xmm2
448
	pxor      xmm4,xmm4
449
	punpcklwd xmm2,xmm3		; xmm2=REL
450
	punpckhwd xmm4,xmm3		; xmm4=REH
451
	psrld     xmm2,1		; xmm2=REL*FIX(0.500)
452
	psrld     xmm4,1		; xmm4=REH*FIX(0.500)
453
454
	movdqa    xmm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm0=[PD_ONEHALFM1_CJ]
455
456
	paddd     xmm1,xmm2
457
	paddd     xmm5,xmm4
458
	paddd     xmm1,xmm0
459
	paddd     xmm5,xmm0
460
	psrld     xmm1,SCALEBITS	; xmm1=CrEL
461
	psrld     xmm5,SCALEBITS	; xmm5=CrEH
462
	packssdw  xmm1,xmm5		; xmm1=CrE
463
464
	psllw     xmm7,BYTE_BIT
465
	por       xmm1,xmm7		; xmm1=Cr
466
	movdqa    XMMWORD [edx], xmm1	; Save Cr
467
468
	sub	ecx, byte SIZEOF_XMMWORD
469
	add	esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; inptr
470
	add	edi, byte SIZEOF_XMMWORD		; outptr0
471
	add	ebx, byte SIZEOF_XMMWORD		; outptr1
472
	add	edx, byte SIZEOF_XMMWORD		; outptr2
473
	cmp	ecx, byte SIZEOF_XMMWORD
474
	jae	near .columnloop
475
	test	ecx,ecx
476
	jnz	near .column_ld1
477
478
	pop	ecx			; col
479
	pop	esi
480
	pop	edi
481
	pop	ebx
482
	pop	edx
483
	poppic	eax
484
485
	add	esi, byte SIZEOF_JSAMPROW	; input_buf
486
	add	edi, byte SIZEOF_JSAMPROW
487
	add	ebx, byte SIZEOF_JSAMPROW
488
	add	edx, byte SIZEOF_JSAMPROW
489
	dec	eax				; num_rows
490
	jg	near .rowloop
491
492
.return:
493
	pop	edi
494
	pop	esi
495
;	pop	edx		; need not be preserved
496
;	pop	ecx		; need not be preserved
497
	pop	ebx
498
	mov	esp,ebp		; esp <- aligned ebp
499
	pop	esp		; esp <- original ebp
500
	pop	ebp
501
	ret
502
503
; For some reason, the OS X linker does not honor the request to align the
504
; segment unless we do this.
505
	align	16
(-)a/jpeg/simd/jccolmmx.asm (+120 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jccolmmx.asm - colorspace conversion (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
22
; --------------------------------------------------------------------------
23
24
%define SCALEBITS	16
25
26
F_0_081	equ	 5329			; FIX(0.08131)
27
F_0_114	equ	 7471			; FIX(0.11400)
28
F_0_168	equ	11059			; FIX(0.16874)
29
F_0_250	equ	16384			; FIX(0.25000)
30
F_0_299	equ	19595			; FIX(0.29900)
31
F_0_331	equ	21709			; FIX(0.33126)
32
F_0_418	equ	27439			; FIX(0.41869)
33
F_0_587	equ	38470			; FIX(0.58700)
34
F_0_337	equ	(F_0_587 - F_0_250)	; FIX(0.58700) - FIX(0.25000)
35
36
; --------------------------------------------------------------------------
37
	SECTION	SEG_CONST
38
39
	alignz	16
40
	global	EXTN(jconst_rgb_ycc_convert_mmx)
41
42
EXTN(jconst_rgb_ycc_convert_mmx):
43
44
PW_F0299_F0337	times 2 dw  F_0_299, F_0_337
45
PW_F0114_F0250	times 2 dw  F_0_114, F_0_250
46
PW_MF016_MF033	times 2 dw -F_0_168,-F_0_331
47
PW_MF008_MF041	times 2 dw -F_0_081,-F_0_418
48
PD_ONEHALFM1_CJ	times 2 dd  (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS)
49
PD_ONEHALF	times 2 dd  (1 << (SCALEBITS-1))
50
51
	alignz	16
52
53
; --------------------------------------------------------------------------
54
%include "jcclrmmx.asm"
55
56
%undef RGB_RED
57
%undef RGB_GREEN
58
%undef RGB_BLUE
59
%undef RGB_PIXELSIZE
60
%define RGB_RED 0
61
%define RGB_GREEN 1
62
%define RGB_BLUE 2
63
%define RGB_PIXELSIZE 3
64
%define jsimd_rgb_ycc_convert_mmx jsimd_extrgb_ycc_convert_mmx
65
%include "jcclrmmx.asm"
66
67
%undef RGB_RED
68
%undef RGB_GREEN
69
%undef RGB_BLUE
70
%undef RGB_PIXELSIZE
71
%define RGB_RED 0
72
%define RGB_GREEN 1
73
%define RGB_BLUE 2
74
%define RGB_PIXELSIZE 4
75
%define jsimd_rgb_ycc_convert_mmx jsimd_extrgbx_ycc_convert_mmx
76
%include "jcclrmmx.asm"
77
78
%undef RGB_RED
79
%undef RGB_GREEN
80
%undef RGB_BLUE
81
%undef RGB_PIXELSIZE
82
%define RGB_RED 2
83
%define RGB_GREEN 1
84
%define RGB_BLUE 0
85
%define RGB_PIXELSIZE 3
86
%define jsimd_rgb_ycc_convert_mmx jsimd_extbgr_ycc_convert_mmx
87
%include "jcclrmmx.asm"
88
89
%undef RGB_RED
90
%undef RGB_GREEN
91
%undef RGB_BLUE
92
%undef RGB_PIXELSIZE
93
%define RGB_RED 2
94
%define RGB_GREEN 1
95
%define RGB_BLUE 0
96
%define RGB_PIXELSIZE 4
97
%define jsimd_rgb_ycc_convert_mmx jsimd_extbgrx_ycc_convert_mmx
98
%include "jcclrmmx.asm"
99
100
%undef RGB_RED
101
%undef RGB_GREEN
102
%undef RGB_BLUE
103
%undef RGB_PIXELSIZE
104
%define RGB_RED 3
105
%define RGB_GREEN 2
106
%define RGB_BLUE 1
107
%define RGB_PIXELSIZE 4
108
%define jsimd_rgb_ycc_convert_mmx jsimd_extxbgr_ycc_convert_mmx
109
%include "jcclrmmx.asm"
110
111
%undef RGB_RED
112
%undef RGB_GREEN
113
%undef RGB_BLUE
114
%undef RGB_PIXELSIZE
115
%define RGB_RED 1
116
%define RGB_GREEN 2
117
%define RGB_BLUE 3
118
%define RGB_PIXELSIZE 4
119
%define jsimd_rgb_ycc_convert_mmx jsimd_extxrgb_ycc_convert_mmx
120
%include "jcclrmmx.asm"
(-)a/jpeg/simd/jccolss2-64.asm (+117 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jccolss2-64.asm - colorspace conversion (64-bit SSE2)
3
;
4
; x86 SIMD extension for IJG JPEG library
5
; Copyright (C) 1999-2006, MIYASAKA Masaru.
6
; Copyright (C) 2009, D. R. Commander.
7
; For conditions of distribution and use, see copyright notice in jsimdext.inc
8
;
9
; This file should be assembled with NASM (Netwide Assembler),
10
; can *not* be assembled with Microsoft's MASM or any compatible
11
; assembler (including Borland's Turbo Assembler).
12
; NASM is available from http://nasm.sourceforge.net/ or
13
; http://sourceforge.net/project/showfiles.php?group_id=6208
14
;
15
; [TAB8]
16
17
%include "jsimdext.inc"
18
19
; --------------------------------------------------------------------------
20
21
%define SCALEBITS	16
22
23
F_0_081	equ	 5329			; FIX(0.08131)
24
F_0_114	equ	 7471			; FIX(0.11400)
25
F_0_168	equ	11059			; FIX(0.16874)
26
F_0_250	equ	16384			; FIX(0.25000)
27
F_0_299	equ	19595			; FIX(0.29900)
28
F_0_331	equ	21709			; FIX(0.33126)
29
F_0_418	equ	27439			; FIX(0.41869)
30
F_0_587	equ	38470			; FIX(0.58700)
31
F_0_337	equ	(F_0_587 - F_0_250)	; FIX(0.58700) - FIX(0.25000)
32
33
; --------------------------------------------------------------------------
34
	SECTION	SEG_CONST
35
36
	alignz	16
37
	global	EXTN(jconst_rgb_ycc_convert_sse2)
38
39
EXTN(jconst_rgb_ycc_convert_sse2):
40
41
PW_F0299_F0337	times 4 dw  F_0_299, F_0_337
42
PW_F0114_F0250	times 4 dw  F_0_114, F_0_250
43
PW_MF016_MF033	times 4 dw -F_0_168,-F_0_331
44
PW_MF008_MF041	times 4 dw -F_0_081,-F_0_418
45
PD_ONEHALFM1_CJ	times 4 dd  (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS)
46
PD_ONEHALF	times 4 dd  (1 << (SCALEBITS-1))
47
48
	alignz	16
49
50
; --------------------------------------------------------------------------
51
%include "jcclrss2-64.asm"
52
53
%undef RGB_RED
54
%undef RGB_GREEN
55
%undef RGB_BLUE
56
%undef RGB_PIXELSIZE
57
%define RGB_RED 0
58
%define RGB_GREEN 1
59
%define RGB_BLUE 2
60
%define RGB_PIXELSIZE 3
61
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2
62
%include "jcclrss2-64.asm"
63
64
%undef RGB_RED
65
%undef RGB_GREEN
66
%undef RGB_BLUE
67
%undef RGB_PIXELSIZE
68
%define RGB_RED 0
69
%define RGB_GREEN 1
70
%define RGB_BLUE 2
71
%define RGB_PIXELSIZE 4
72
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2
73
%include "jcclrss2-64.asm"
74
75
%undef RGB_RED
76
%undef RGB_GREEN
77
%undef RGB_BLUE
78
%undef RGB_PIXELSIZE
79
%define RGB_RED 2
80
%define RGB_GREEN 1
81
%define RGB_BLUE 0
82
%define RGB_PIXELSIZE 3
83
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2
84
%include "jcclrss2-64.asm"
85
86
%undef RGB_RED
87
%undef RGB_GREEN
88
%undef RGB_BLUE
89
%undef RGB_PIXELSIZE
90
%define RGB_RED 2
91
%define RGB_GREEN 1
92
%define RGB_BLUE 0
93
%define RGB_PIXELSIZE 4
94
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2
95
%include "jcclrss2-64.asm"
96
97
%undef RGB_RED
98
%undef RGB_GREEN
99
%undef RGB_BLUE
100
%undef RGB_PIXELSIZE
101
%define RGB_RED 3
102
%define RGB_GREEN 2
103
%define RGB_BLUE 1
104
%define RGB_PIXELSIZE 4
105
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2
106
%include "jcclrss2-64.asm"
107
108
%undef RGB_RED
109
%undef RGB_GREEN
110
%undef RGB_BLUE
111
%undef RGB_PIXELSIZE
112
%define RGB_RED 1
113
%define RGB_GREEN 2
114
%define RGB_BLUE 3
115
%define RGB_PIXELSIZE 4
116
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2
117
%include "jcclrss2-64.asm"
(-)a/jpeg/simd/jccolss2.asm (+117 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jccolss2.asm - colorspace conversion (SSE2)
3
;
4
; x86 SIMD extension for IJG JPEG library
5
; Copyright (C) 1999-2006, MIYASAKA Masaru.
6
; Copyright (C) 2009, D. R. Commander.
7
; For conditions of distribution and use, see copyright notice in jsimdext.inc
8
;
9
; This file should be assembled with NASM (Netwide Assembler),
10
; can *not* be assembled with Microsoft's MASM or any compatible
11
; assembler (including Borland's Turbo Assembler).
12
; NASM is available from http://nasm.sourceforge.net/ or
13
; http://sourceforge.net/project/showfiles.php?group_id=6208
14
;
15
; [TAB8]
16
17
%include "jsimdext.inc"
18
19
; --------------------------------------------------------------------------
20
21
%define SCALEBITS	16
22
23
F_0_081	equ	 5329			; FIX(0.08131)
24
F_0_114	equ	 7471			; FIX(0.11400)
25
F_0_168	equ	11059			; FIX(0.16874)
26
F_0_250	equ	16384			; FIX(0.25000)
27
F_0_299	equ	19595			; FIX(0.29900)
28
F_0_331	equ	21709			; FIX(0.33126)
29
F_0_418	equ	27439			; FIX(0.41869)
30
F_0_587	equ	38470			; FIX(0.58700)
31
F_0_337	equ	(F_0_587 - F_0_250)	; FIX(0.58700) - FIX(0.25000)
32
33
; --------------------------------------------------------------------------
34
	SECTION	SEG_CONST
35
36
	alignz	16
37
	global	EXTN(jconst_rgb_ycc_convert_sse2)
38
39
EXTN(jconst_rgb_ycc_convert_sse2):
40
41
PW_F0299_F0337	times 4 dw  F_0_299, F_0_337
42
PW_F0114_F0250	times 4 dw  F_0_114, F_0_250
43
PW_MF016_MF033	times 4 dw -F_0_168,-F_0_331
44
PW_MF008_MF041	times 4 dw -F_0_081,-F_0_418
45
PD_ONEHALFM1_CJ	times 4 dd  (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS)
46
PD_ONEHALF	times 4 dd  (1 << (SCALEBITS-1))
47
48
	alignz	16
49
50
; --------------------------------------------------------------------------
51
%include "jcclrss2.asm"
52
53
%undef RGB_RED
54
%undef RGB_GREEN
55
%undef RGB_BLUE
56
%undef RGB_PIXELSIZE
57
%define RGB_RED 0
58
%define RGB_GREEN 1
59
%define RGB_BLUE 2
60
%define RGB_PIXELSIZE 3
61
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2
62
%include "jcclrss2.asm"
63
64
%undef RGB_RED
65
%undef RGB_GREEN
66
%undef RGB_BLUE
67
%undef RGB_PIXELSIZE
68
%define RGB_RED 0
69
%define RGB_GREEN 1
70
%define RGB_BLUE 2
71
%define RGB_PIXELSIZE 4
72
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2
73
%include "jcclrss2.asm"
74
75
%undef RGB_RED
76
%undef RGB_GREEN
77
%undef RGB_BLUE
78
%undef RGB_PIXELSIZE
79
%define RGB_RED 2
80
%define RGB_GREEN 1
81
%define RGB_BLUE 0
82
%define RGB_PIXELSIZE 3
83
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2
84
%include "jcclrss2.asm"
85
86
%undef RGB_RED
87
%undef RGB_GREEN
88
%undef RGB_BLUE
89
%undef RGB_PIXELSIZE
90
%define RGB_RED 2
91
%define RGB_GREEN 1
92
%define RGB_BLUE 0
93
%define RGB_PIXELSIZE 4
94
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2
95
%include "jcclrss2.asm"
96
97
%undef RGB_RED
98
%undef RGB_GREEN
99
%undef RGB_BLUE
100
%undef RGB_PIXELSIZE
101
%define RGB_RED 3
102
%define RGB_GREEN 2
103
%define RGB_BLUE 1
104
%define RGB_PIXELSIZE 4
105
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2
106
%include "jcclrss2.asm"
107
108
%undef RGB_RED
109
%undef RGB_GREEN
110
%undef RGB_BLUE
111
%undef RGB_PIXELSIZE
112
%define RGB_RED 1
113
%define RGB_GREEN 2
114
%define RGB_BLUE 3
115
%define RGB_PIXELSIZE 4
116
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2
117
%include "jcclrss2.asm"
(-)a/jpeg/simd/jcolsamp.inc (+105 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcolsamp.inc - private declarations for color conversion & up/downsampling
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; [TAB8]
12
13
; --------------------------------------------------------------------------
14
15
; pseudo-resisters to make ordering of RGB configurable
16
;
17
%if RGB_RED == 0
18
%define  mmA  mm0
19
%define  mmB  mm1
20
%define xmmA xmm0
21
%define xmmB xmm1
22
%elif RGB_GREEN == 0
23
%define  mmA  mm2
24
%define  mmB  mm3
25
%define xmmA xmm2
26
%define xmmB xmm3
27
%elif RGB_BLUE == 0
28
%define  mmA  mm4
29
%define  mmB  mm5
30
%define xmmA xmm4
31
%define xmmB xmm5
32
%else
33
%define  mmA  mm6
34
%define  mmB  mm7
35
%define xmmA xmm6
36
%define xmmB xmm7
37
%endif
38
39
%if RGB_RED == 1
40
%define  mmC  mm0
41
%define  mmD  mm1
42
%define xmmC xmm0
43
%define xmmD xmm1
44
%elif RGB_GREEN == 1
45
%define  mmC  mm2
46
%define  mmD  mm3
47
%define xmmC xmm2
48
%define xmmD xmm3
49
%elif RGB_BLUE == 1
50
%define  mmC  mm4
51
%define  mmD  mm5
52
%define xmmC xmm4
53
%define xmmD xmm5
54
%else
55
%define  mmC  mm6
56
%define  mmD  mm7
57
%define xmmC xmm6
58
%define xmmD xmm7
59
%endif
60
61
%if RGB_RED == 2
62
%define  mmE  mm0
63
%define  mmF  mm1
64
%define xmmE xmm0
65
%define xmmF xmm1
66
%elif RGB_GREEN == 2
67
%define  mmE  mm2
68
%define  mmF  mm3
69
%define xmmE xmm2
70
%define xmmF xmm3
71
%elif RGB_BLUE == 2
72
%define  mmE  mm4
73
%define  mmF  mm5
74
%define xmmE xmm4
75
%define xmmF xmm5
76
%else
77
%define  mmE  mm6
78
%define  mmF  mm7
79
%define xmmE xmm6
80
%define xmmF xmm7
81
%endif
82
83
%if RGB_RED == 3
84
%define  mmG  mm0
85
%define  mmH  mm1
86
%define xmmG xmm0
87
%define xmmH xmm1
88
%elif RGB_GREEN == 3
89
%define  mmG  mm2
90
%define  mmH  mm3
91
%define xmmG xmm2
92
%define xmmH xmm3
93
%elif RGB_BLUE == 3
94
%define  mmG  mm4
95
%define  mmH  mm5
96
%define xmmG xmm4
97
%define xmmH xmm5
98
%else
99
%define  mmG  mm6
100
%define  mmH  mm7
101
%define xmmG xmm6
102
%define xmmH xmm7
103
%endif
104
105
; --------------------------------------------------------------------------
(-)a/jpeg/simd/jcqnt3dn.asm (+233 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcqnt3dn.asm - sample data conversion and quantization (3DNow! & MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
%include "jdct.inc"
21
22
; --------------------------------------------------------------------------
23
	SECTION	SEG_TEXT
24
	BITS	32
25
;
26
; Load data into workspace, applying unsigned->signed conversion
27
;
28
; GLOBAL(void)
29
; jsimd_convsamp_float_3dnow (JSAMPARRAY sample_data, JDIMENSION start_col,
30
;                             FAST_FLOAT * workspace);
31
;
32
33
%define sample_data	ebp+8		; JSAMPARRAY sample_data
34
%define start_col	ebp+12		; JDIMENSION start_col
35
%define workspace	ebp+16		; FAST_FLOAT * workspace
36
37
	align	16
38
	global	EXTN(jsimd_convsamp_float_3dnow)
39
40
EXTN(jsimd_convsamp_float_3dnow):
41
	push	ebp
42
	mov	ebp,esp
43
	push	ebx
44
;	push	ecx		; need not be preserved
45
;	push	edx		; need not be preserved
46
	push	esi
47
	push	edi
48
49
	pcmpeqw  mm7,mm7
50
	psllw    mm7,7
51
	packsswb mm7,mm7		; mm7 = PB_CENTERJSAMPLE (0x808080..)
52
53
	mov	esi, JSAMPARRAY [sample_data]	; (JSAMPROW *)
54
	mov	eax, JDIMENSION [start_col]
55
	mov	edi, POINTER [workspace]	; (DCTELEM *)
56
	mov	ecx, DCTSIZE/2
57
	alignx	16,7
58
.convloop:
59
	mov	ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]	; (JSAMPLE *)
60
	mov	edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW]	; (JSAMPLE *)
61
62
	movq	mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE]
63
	movq	mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE]
64
65
	psubb	mm0,mm7				; mm0=(01234567)
66
	psubb	mm1,mm7				; mm1=(89ABCDEF)
67
68
	punpcklbw mm2,mm0			; mm2=(*0*1*2*3)
69
	punpckhbw mm0,mm0			; mm0=(*4*5*6*7)
70
	punpcklbw mm3,mm1			; mm3=(*8*9*A*B)
71
	punpckhbw mm1,mm1			; mm1=(*C*D*E*F)
72
73
	punpcklwd mm4,mm2			; mm4=(***0***1)
74
	punpckhwd mm2,mm2			; mm2=(***2***3)
75
	punpcklwd mm5,mm0			; mm5=(***4***5)
76
	punpckhwd mm0,mm0			; mm0=(***6***7)
77
78
	psrad	mm4,(DWORD_BIT-BYTE_BIT)	; mm4=(01)
79
	psrad	mm2,(DWORD_BIT-BYTE_BIT)	; mm2=(23)
80
	pi2fd	mm4,mm4
81
	pi2fd	mm2,mm2
82
	psrad	mm5,(DWORD_BIT-BYTE_BIT)	; mm5=(45)
83
	psrad	mm0,(DWORD_BIT-BYTE_BIT)	; mm0=(67)
84
	pi2fd	mm5,mm5
85
	pi2fd	mm0,mm0
86
87
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], mm4
88
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], mm2
89
	movq	MMWORD [MMBLOCK(0,2,edi,SIZEOF_FAST_FLOAT)], mm5
90
	movq	MMWORD [MMBLOCK(0,3,edi,SIZEOF_FAST_FLOAT)], mm0
91
92
	punpcklwd mm6,mm3			; mm6=(***8***9)
93
	punpckhwd mm3,mm3			; mm3=(***A***B)
94
	punpcklwd mm4,mm1			; mm4=(***C***D)
95
	punpckhwd mm1,mm1			; mm1=(***E***F)
96
97
	psrad	mm6,(DWORD_BIT-BYTE_BIT)	; mm6=(89)
98
	psrad	mm3,(DWORD_BIT-BYTE_BIT)	; mm3=(AB)
99
	pi2fd	mm6,mm6
100
	pi2fd	mm3,mm3
101
	psrad	mm4,(DWORD_BIT-BYTE_BIT)	; mm4=(CD)
102
	psrad	mm1,(DWORD_BIT-BYTE_BIT)	; mm1=(EF)
103
	pi2fd	mm4,mm4
104
	pi2fd	mm1,mm1
105
106
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], mm6
107
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], mm3
108
	movq	MMWORD [MMBLOCK(1,2,edi,SIZEOF_FAST_FLOAT)], mm4
109
	movq	MMWORD [MMBLOCK(1,3,edi,SIZEOF_FAST_FLOAT)], mm1
110
111
	add	esi, byte 2*SIZEOF_JSAMPROW
112
	add	edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
113
	dec	ecx
114
	jnz	near .convloop
115
116
	femms		; empty MMX/3DNow! state
117
118
	pop	edi
119
	pop	esi
120
;	pop	edx		; need not be preserved
121
;	pop	ecx		; need not be preserved
122
	pop	ebx
123
	pop	ebp
124
	ret
125
126
127
; --------------------------------------------------------------------------
128
;
129
; Quantize/descale the coefficients, and store into coef_block
130
;
131
; GLOBAL(void)
132
; jsimd_quantize_float_3dnow (JCOEFPTR coef_block, FAST_FLOAT * divisors,
133
;                             FAST_FLOAT * workspace);
134
;
135
136
%define coef_block	ebp+8		; JCOEFPTR coef_block
137
%define divisors	ebp+12		; FAST_FLOAT * divisors
138
%define workspace	ebp+16		; FAST_FLOAT * workspace
139
140
	align	16
141
	global	EXTN(jsimd_quantize_float_3dnow)
142
143
EXTN(jsimd_quantize_float_3dnow):
144
	push	ebp
145
	mov	ebp,esp
146
;	push	ebx		; unused
147
;	push	ecx		; unused
148
;	push	edx		; need not be preserved
149
	push	esi
150
	push	edi
151
152
	mov       eax, 0x4B400000	; (float)0x00C00000 (rndint_magic)
153
	movd      mm7,eax
154
	punpckldq mm7,mm7		; mm7={12582912.0F 12582912.0F}
155
156
	mov	esi, POINTER [workspace]
157
	mov	edx, POINTER [divisors]
158
	mov	edi, JCOEFPTR [coef_block]
159
	mov	eax, DCTSIZE2/16
160
	alignx	16,7
161
.quantloop:
162
	movq	mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
163
	movq	mm1, MMWORD [MMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)]
164
	pfmul	mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
165
	pfmul	mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
166
	movq	mm2, MMWORD [MMBLOCK(0,2,esi,SIZEOF_FAST_FLOAT)]
167
	movq	mm3, MMWORD [MMBLOCK(0,3,esi,SIZEOF_FAST_FLOAT)]
168
	pfmul	mm2, MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)]
169
	pfmul	mm3, MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)]
170
171
	pfadd	mm0,mm7			; mm0=(00 ** 01 **)
172
	pfadd	mm1,mm7			; mm1=(02 ** 03 **)
173
	pfadd	mm2,mm7			; mm0=(04 ** 05 **)
174
	pfadd	mm3,mm7			; mm1=(06 ** 07 **)
175
176
	movq      mm4,mm0
177
	punpcklwd mm0,mm1		; mm0=(00 02 ** **)
178
	punpckhwd mm4,mm1		; mm4=(01 03 ** **)
179
	movq      mm5,mm2
180
	punpcklwd mm2,mm3		; mm2=(04 06 ** **)
181
	punpckhwd mm5,mm3		; mm5=(05 07 ** **)
182
183
	punpcklwd mm0,mm4		; mm0=(00 01 02 03)
184
	punpcklwd mm2,mm5		; mm2=(04 05 06 07)
185
186
	movq	mm6, MMWORD [MMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
187
	movq	mm1, MMWORD [MMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)]
188
	pfmul	mm6, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
189
	pfmul	mm1, MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
190
	movq	mm3, MMWORD [MMBLOCK(1,2,esi,SIZEOF_FAST_FLOAT)]
191
	movq	mm4, MMWORD [MMBLOCK(1,3,esi,SIZEOF_FAST_FLOAT)]
192
	pfmul	mm3, MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)]
193
	pfmul	mm4, MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)]
194
195
	pfadd	mm6,mm7			; mm0=(10 ** 11 **)
196
	pfadd	mm1,mm7			; mm4=(12 ** 13 **)
197
	pfadd	mm3,mm7			; mm0=(14 ** 15 **)
198
	pfadd	mm4,mm7			; mm4=(16 ** 17 **)
199
200
	movq      mm5,mm6
201
	punpcklwd mm6,mm1		; mm6=(10 12 ** **)
202
	punpckhwd mm5,mm1		; mm5=(11 13 ** **)
203
	movq      mm1,mm3
204
	punpcklwd mm3,mm4		; mm3=(14 16 ** **)
205
	punpckhwd mm1,mm4		; mm1=(15 17 ** **)
206
207
	punpcklwd mm6,mm5		; mm6=(10 11 12 13)
208
	punpcklwd mm3,mm1		; mm3=(14 15 16 17)
209
210
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
211
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm2
212
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm6
213
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm3
214
215
	add	esi, byte 16*SIZEOF_FAST_FLOAT
216
	add	edx, byte 16*SIZEOF_FAST_FLOAT
217
	add	edi, byte 16*SIZEOF_JCOEF
218
	dec	eax
219
	jnz	near .quantloop
220
221
	femms		; empty MMX/3DNow! state
222
223
	pop	edi
224
	pop	esi
225
;	pop	edx		; need not be preserved
226
;	pop	ecx		; unused
227
;	pop	ebx		; unused
228
	pop	ebp
229
	ret
230
231
; For some reason, the OS X linker does not honor the request to align the
232
; segment unless we do this.
233
	align	16
(-)a/jpeg/simd/jcqntmmx.asm (+274 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcqntmmx.asm - sample data conversion and quantization (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
%include "jdct.inc"
21
22
; --------------------------------------------------------------------------
23
	SECTION	SEG_TEXT
24
	BITS	32
25
;
26
; Load data into workspace, applying unsigned->signed conversion
27
;
28
; GLOBAL(void)
29
; jsimd_convsamp_mmx (JSAMPARRAY sample_data, JDIMENSION start_col,
30
;                     DCTELEM * workspace);
31
;
32
33
%define sample_data	ebp+8		; JSAMPARRAY sample_data
34
%define start_col	ebp+12		; JDIMENSION start_col
35
%define workspace	ebp+16		; DCTELEM * workspace
36
37
	align	16
38
	global	EXTN(jsimd_convsamp_mmx)
39
40
EXTN(jsimd_convsamp_mmx):
41
	push	ebp
42
	mov	ebp,esp
43
	push	ebx
44
;	push	ecx		; need not be preserved
45
;	push	edx		; need not be preserved
46
	push	esi
47
	push	edi
48
49
	pxor	mm6,mm6			; mm6=(all 0's)
50
	pcmpeqw	mm7,mm7
51
	psllw	mm7,7			; mm7={0xFF80 0xFF80 0xFF80 0xFF80}
52
53
	mov	esi, JSAMPARRAY [sample_data]	; (JSAMPROW *)
54
	mov	eax, JDIMENSION [start_col]
55
	mov	edi, POINTER [workspace]	; (DCTELEM *)
56
	mov	ecx, DCTSIZE/4
57
	alignx	16,7
58
.convloop:
59
	mov	ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]	; (JSAMPLE *)
60
	mov	edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW]	; (JSAMPLE *)
61
62
	movq	mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE]	; mm0=(01234567)
63
	movq	mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE]	; mm1=(89ABCDEF)
64
65
	mov	ebx, JSAMPROW [esi+2*SIZEOF_JSAMPROW]	; (JSAMPLE *)
66
	mov	edx, JSAMPROW [esi+3*SIZEOF_JSAMPROW]	; (JSAMPLE *)
67
68
	movq	mm2, MMWORD [ebx+eax*SIZEOF_JSAMPLE]	; mm2=(GHIJKLMN)
69
	movq	mm3, MMWORD [edx+eax*SIZEOF_JSAMPLE]	; mm3=(OPQRSTUV)
70
71
	movq      mm4,mm0
72
	punpcklbw mm0,mm6		; mm0=(0123)
73
	punpckhbw mm4,mm6		; mm4=(4567)
74
	movq      mm5,mm1
75
	punpcklbw mm1,mm6		; mm1=(89AB)
76
	punpckhbw mm5,mm6		; mm5=(CDEF)
77
78
	paddw	mm0,mm7
79
	paddw	mm4,mm7
80
	paddw	mm1,mm7
81
	paddw	mm5,mm7
82
83
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_DCTELEM)], mm0
84
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_DCTELEM)], mm4
85
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_DCTELEM)], mm1
86
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_DCTELEM)], mm5
87
88
	movq      mm0,mm2
89
	punpcklbw mm2,mm6		; mm2=(GHIJ)
90
	punpckhbw mm0,mm6		; mm0=(KLMN)
91
	movq      mm4,mm3
92
	punpcklbw mm3,mm6		; mm3=(OPQR)
93
	punpckhbw mm4,mm6		; mm4=(STUV)
94
95
	paddw	mm2,mm7
96
	paddw	mm0,mm7
97
	paddw	mm3,mm7
98
	paddw	mm4,mm7
99
100
	movq	MMWORD [MMBLOCK(2,0,edi,SIZEOF_DCTELEM)], mm2
101
	movq	MMWORD [MMBLOCK(2,1,edi,SIZEOF_DCTELEM)], mm0
102
	movq	MMWORD [MMBLOCK(3,0,edi,SIZEOF_DCTELEM)], mm3
103
	movq	MMWORD [MMBLOCK(3,1,edi,SIZEOF_DCTELEM)], mm4
104
105
	add	esi, byte 4*SIZEOF_JSAMPROW
106
	add	edi, byte 4*DCTSIZE*SIZEOF_DCTELEM
107
	dec	ecx
108
	jnz	short .convloop
109
110
	emms		; empty MMX state
111
112
	pop	edi
113
	pop	esi
114
;	pop	edx		; need not be preserved
115
;	pop	ecx		; need not be preserved
116
	pop	ebx
117
	pop	ebp
118
	ret
119
120
; --------------------------------------------------------------------------
121
;
122
; Quantize/descale the coefficients, and store into coef_block
123
;
124
; This implementation is based on an algorithm described in
125
;   "How to optimize for the Pentium family of microprocessors"
126
;   (http://www.agner.org/assem/).
127
;
128
; GLOBAL(void)
129
; jsimd_quantize_mmx (JCOEFPTR coef_block, DCTELEM * divisors,
130
;                     DCTELEM * workspace);
131
;
132
133
%define RECIPROCAL(m,n,b) MMBLOCK(DCTSIZE*0+(m),(n),(b),SIZEOF_DCTELEM)
134
%define CORRECTION(m,n,b) MMBLOCK(DCTSIZE*1+(m),(n),(b),SIZEOF_DCTELEM)
135
%define SCALE(m,n,b)      MMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM)
136
%define SHIFT(m,n,b)      MMBLOCK(DCTSIZE*3+(m),(n),(b),SIZEOF_DCTELEM)
137
138
%define coef_block	ebp+8		; JCOEFPTR coef_block
139
%define divisors	ebp+12		; DCTELEM * divisors
140
%define workspace	ebp+16		; DCTELEM * workspace
141
142
	align	16
143
	global	EXTN(jsimd_quantize_mmx)
144
145
EXTN(jsimd_quantize_mmx):
146
	push	ebp
147
	mov	ebp,esp
148
;	push	ebx		; unused
149
;	push	ecx		; unused
150
;	push	edx		; need not be preserved
151
	push	esi
152
	push	edi
153
154
	mov	esi, POINTER [workspace]
155
	mov	edx, POINTER [divisors]
156
	mov	edi, JCOEFPTR [coef_block]
157
	mov	ah, 2
158
	alignx	16,7
159
.quantloop1:
160
	mov	al, DCTSIZE2/8/2
161
	alignx	16,7
162
.quantloop2:
163
	movq	mm2, MMWORD [MMBLOCK(0,0,esi,SIZEOF_DCTELEM)]
164
	movq	mm3, MMWORD [MMBLOCK(0,1,esi,SIZEOF_DCTELEM)]
165
166
	movq	mm0,mm2
167
	movq	mm1,mm3
168
169
	psraw	mm2,(WORD_BIT-1)  ; -1 if value < 0, 0 otherwise
170
	psraw	mm3,(WORD_BIT-1)
171
172
	pxor	mm0,mm2   ; val = -val
173
	pxor	mm1,mm3
174
	psubw	mm0,mm2
175
	psubw	mm1,mm3
176
177
	;
178
	; MMX is an annoyingly crappy instruction set. It has two
179
	; misfeatures that are causing problems here:
180
	;
181
	; - All multiplications are signed.
182
	;
183
	; - The second operand for the shifts is not treated as packed.
184
	;
185
	;
186
	; We work around the first problem by implementing this algorithm:
187
	;
188
	; unsigned long unsigned_multiply(unsigned short x, unsigned short y)
189
	; {
190
	;   enum { SHORT_BIT = 16 };
191
	;   signed short sx = (signed short) x;
192
	;   signed short sy = (signed short) y;
193
	;   signed long sz;
194
	; 
195
	;   sz = (long) sx * (long) sy;     /* signed multiply */
196
	; 
197
	;   if (sx < 0) sz += (long) sy << SHORT_BIT;
198
	;   if (sy < 0) sz += (long) sx << SHORT_BIT;
199
	; 
200
	;   return (unsigned long) sz;
201
	; }
202
	;
203
	; (note that a negative sx adds _sy_ and vice versa)
204
	;
205
	; For the second problem, we replace the shift by a multiplication.
206
	; Unfortunately that means we have to deal with the signed issue again.
207
	;
208
209
	paddw	mm0, MMWORD [CORRECTION(0,0,edx)]   ; correction + roundfactor
210
	paddw	mm1, MMWORD [CORRECTION(0,1,edx)]
211
212
	movq	mm4,mm0   ; store current value for later
213
	movq	mm5,mm1
214
	pmulhw	mm0, MMWORD [RECIPROCAL(0,0,edx)]   ; reciprocal
215
	pmulhw	mm1, MMWORD [RECIPROCAL(0,1,edx)]
216
	paddw	mm0,mm4		; reciprocal is always negative (MSB=1),
217
	paddw	mm1,mm5   ; so we always need to add the initial value
218
	                ; (input value is never negative as we
219
	                ; inverted it at the start of this routine)
220
221
	; here it gets a bit tricky as both scale
222
	; and mm0/mm1 can be negative
223
	movq	mm6, MMWORD [SCALE(0,0,edx)]	; scale
224
	movq	mm7, MMWORD [SCALE(0,1,edx)]
225
	movq	mm4,mm0
226
	movq	mm5,mm1
227
	pmulhw	mm0,mm6
228
	pmulhw	mm1,mm7
229
230
	psraw	mm6,(WORD_BIT-1)    ; determine if scale is negative
231
	psraw	mm7,(WORD_BIT-1)
232
233
	pand	mm6,mm4             ; and add input if it is
234
	pand	mm7,mm5
235
	paddw	mm0,mm6
236
	paddw	mm1,mm7
237
238
	psraw	mm4,(WORD_BIT-1)    ; then check if negative input 
239
	psraw	mm5,(WORD_BIT-1)
240
241
	pand	mm4, MMWORD [SCALE(0,0,edx)]	; and add scale if it is
242
	pand	mm5, MMWORD [SCALE(0,1,edx)]
243
	paddw	mm0,mm4
244
	paddw	mm1,mm5
245
246
	pxor	mm0,mm2   ; val = -val
247
	pxor	mm1,mm3
248
	psubw	mm0,mm2
249
	psubw	mm1,mm3
250
251
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_DCTELEM)], mm0
252
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_DCTELEM)], mm1
253
254
	add	esi, byte 8*SIZEOF_DCTELEM
255
	add	edx, byte 8*SIZEOF_DCTELEM
256
	add	edi, byte 8*SIZEOF_JCOEF
257
	dec	al
258
	jnz	near .quantloop2
259
	dec	ah
260
	jnz	near .quantloop1	; to avoid branch misprediction
261
262
	emms		; empty MMX state
263
264
	pop	edi
265
	pop	esi
266
;	pop	edx		; need not be preserved
267
;	pop	ecx		; unused
268
;	pop	ebx		; unused
269
	pop	ebp
270
	ret
271
272
; For some reason, the OS X linker does not honor the request to align the
273
; segment unless we do this.
274
	align	16
(-)a/jpeg/simd/jcqnts2f-64.asm (+158 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcqnts2f-64.asm - sample data conversion and quantization (64-bit SSE & SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
%include "jdct.inc"
22
23
; --------------------------------------------------------------------------
24
	SECTION	SEG_TEXT
25
	BITS	64
26
;
27
; Load data into workspace, applying unsigned->signed conversion
28
;
29
; GLOBAL(void)
30
; jsimd_convsamp_float_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col,
31
;                            FAST_FLOAT * workspace);
32
;
33
34
; r10 = JSAMPARRAY sample_data
35
; r11 = JDIMENSION start_col
36
; r12 = FAST_FLOAT * workspace
37
38
	align	16
39
	global	EXTN(jsimd_convsamp_float_sse2)
40
41
EXTN(jsimd_convsamp_float_sse2):
42
	push	rbp
43
	mov	rax,rsp
44
	mov	rbp,rsp
45
	collect_args
46
	push	rbx
47
48
	pcmpeqw  xmm7,xmm7
49
	psllw    xmm7,7
50
	packsswb xmm7,xmm7		; xmm7 = PB_CENTERJSAMPLE (0x808080..)
51
52
	mov rsi, r10
53
	mov	rax, r11
54
	mov rdi, r12
55
	mov	rcx, DCTSIZE/2
56
.convloop:
57
	mov	rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW]	; (JSAMPLE *)
58
	mov rdx, JSAMPROW [rsi+1*SIZEOF_JSAMPROW]	; (JSAMPLE *)
59
60
	movq	xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE]
61
	movq	xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE]
62
63
	psubb	xmm0,xmm7			; xmm0=(01234567)
64
	psubb	xmm1,xmm7			; xmm1=(89ABCDEF)
65
66
	punpcklbw xmm0,xmm0			; xmm0=(*0*1*2*3*4*5*6*7)
67
	punpcklbw xmm1,xmm1			; xmm1=(*8*9*A*B*C*D*E*F)
68
69
	punpcklwd xmm2,xmm0			; xmm2=(***0***1***2***3)
70
	punpckhwd xmm0,xmm0			; xmm0=(***4***5***6***7)
71
	punpcklwd xmm3,xmm1			; xmm3=(***8***9***A***B)
72
	punpckhwd xmm1,xmm1			; xmm1=(***C***D***E***F)
73
74
	psrad     xmm2,(DWORD_BIT-BYTE_BIT)	; xmm2=(0123)
75
	psrad     xmm0,(DWORD_BIT-BYTE_BIT)	; xmm0=(4567)
76
	cvtdq2ps  xmm2,xmm2			; xmm2=(0123)
77
	cvtdq2ps  xmm0,xmm0			; xmm0=(4567)
78
	psrad     xmm3,(DWORD_BIT-BYTE_BIT)	; xmm3=(89AB)
79
	psrad     xmm1,(DWORD_BIT-BYTE_BIT)	; xmm1=(CDEF)
80
	cvtdq2ps  xmm3,xmm3			; xmm3=(89AB)
81
	cvtdq2ps  xmm1,xmm1			; xmm1=(CDEF)
82
83
	movaps	XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm2
84
	movaps	XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm0
85
	movaps	XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm3
86
	movaps	XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm1
87
88
	add	rsi, byte 2*SIZEOF_JSAMPROW
89
	add	rdi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
90
	dec	rcx
91
	jnz	short .convloop
92
93
	pop	rbx
94
	uncollect_args
95
	pop	rbp
96
	ret
97
98
99
; --------------------------------------------------------------------------
100
;
101
; Quantize/descale the coefficients, and store into coef_block
102
;
103
; GLOBAL(void)
104
; jsimd_quantize_float_sse2 (JCOEFPTR coef_block, FAST_FLOAT * divisors,
105
;                         FAST_FLOAT * workspace);
106
;
107
108
; r10 = JCOEFPTR coef_block
109
; r11 = FAST_FLOAT * divisors
110
; r12 = FAST_FLOAT * workspace
111
112
	align	16
113
	global	EXTN(jsimd_quantize_float_sse2)
114
115
EXTN(jsimd_quantize_float_sse2):
116
	push	rbp
117
	mov	rax,rsp
118
	mov	rbp,rsp
119
	collect_args
120
121
	mov rsi, r12
122
	mov rdx, r11
123
	mov rdi, r10
124
	mov	rax, DCTSIZE2/16
125
.quantloop:
126
	movaps	xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_FAST_FLOAT)]
127
	movaps	xmm1, XMMWORD [XMMBLOCK(0,1,rsi,SIZEOF_FAST_FLOAT)]
128
	mulps	xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)]
129
	mulps	xmm1, XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)]
130
	movaps	xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_FAST_FLOAT)]
131
	movaps	xmm3, XMMWORD [XMMBLOCK(1,1,rsi,SIZEOF_FAST_FLOAT)]
132
	mulps	xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)]
133
	mulps	xmm3, XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)]
134
135
	cvtps2dq xmm0,xmm0
136
	cvtps2dq xmm1,xmm1
137
	cvtps2dq xmm2,xmm2
138
	cvtps2dq xmm3,xmm3
139
140
	packssdw xmm0,xmm1
141
	packssdw xmm2,xmm3
142
143
	movdqa	XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_JCOEF)], xmm0
144
	movdqa	XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_JCOEF)], xmm2
145
146
	add	rsi, byte 16*SIZEOF_FAST_FLOAT
147
	add	rdx, byte 16*SIZEOF_FAST_FLOAT
148
	add	rdi, byte 16*SIZEOF_JCOEF
149
	dec	rax
150
	jnz	short .quantloop
151
152
	uncollect_args
153
	pop	rbp
154
	ret
155
156
; For some reason, the OS X linker does not honor the request to align the
157
; segment unless we do this.
158
	align	16
(-)a/jpeg/simd/jcqnts2f.asm (+171 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcqnts2f.asm - sample data conversion and quantization (SSE & SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
%include "jdct.inc"
21
22
; --------------------------------------------------------------------------
23
	SECTION	SEG_TEXT
24
	BITS	32
25
;
26
; Load data into workspace, applying unsigned->signed conversion
27
;
28
; GLOBAL(void)
29
; jsimd_convsamp_float_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col,
30
;                            FAST_FLOAT * workspace);
31
;
32
33
%define sample_data	ebp+8		; JSAMPARRAY sample_data
34
%define start_col	ebp+12		; JDIMENSION start_col
35
%define workspace	ebp+16		; FAST_FLOAT * workspace
36
37
	align	16
38
	global	EXTN(jsimd_convsamp_float_sse2)
39
40
EXTN(jsimd_convsamp_float_sse2):
41
	push	ebp
42
	mov	ebp,esp
43
	push	ebx
44
;	push	ecx		; need not be preserved
45
;	push	edx		; need not be preserved
46
	push	esi
47
	push	edi
48
49
	pcmpeqw  xmm7,xmm7
50
	psllw    xmm7,7
51
	packsswb xmm7,xmm7		; xmm7 = PB_CENTERJSAMPLE (0x808080..)
52
53
	mov	esi, JSAMPARRAY [sample_data]	; (JSAMPROW *)
54
	mov	eax, JDIMENSION [start_col]
55
	mov	edi, POINTER [workspace]	; (DCTELEM *)
56
	mov	ecx, DCTSIZE/2
57
	alignx	16,7
58
.convloop:
59
	mov	ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]	; (JSAMPLE *)
60
	mov	edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW]	; (JSAMPLE *)
61
62
	movq	xmm0, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE]
63
	movq	xmm1, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE]
64
65
	psubb	xmm0,xmm7			; xmm0=(01234567)
66
	psubb	xmm1,xmm7			; xmm1=(89ABCDEF)
67
68
	punpcklbw xmm0,xmm0			; xmm0=(*0*1*2*3*4*5*6*7)
69
	punpcklbw xmm1,xmm1			; xmm1=(*8*9*A*B*C*D*E*F)
70
71
	punpcklwd xmm2,xmm0			; xmm2=(***0***1***2***3)
72
	punpckhwd xmm0,xmm0			; xmm0=(***4***5***6***7)
73
	punpcklwd xmm3,xmm1			; xmm3=(***8***9***A***B)
74
	punpckhwd xmm1,xmm1			; xmm1=(***C***D***E***F)
75
76
	psrad     xmm2,(DWORD_BIT-BYTE_BIT)	; xmm2=(0123)
77
	psrad     xmm0,(DWORD_BIT-BYTE_BIT)	; xmm0=(4567)
78
	cvtdq2ps  xmm2,xmm2			; xmm2=(0123)
79
	cvtdq2ps  xmm0,xmm0			; xmm0=(4567)
80
	psrad     xmm3,(DWORD_BIT-BYTE_BIT)	; xmm3=(89AB)
81
	psrad     xmm1,(DWORD_BIT-BYTE_BIT)	; xmm1=(CDEF)
82
	cvtdq2ps  xmm3,xmm3			; xmm3=(89AB)
83
	cvtdq2ps  xmm1,xmm1			; xmm1=(CDEF)
84
85
	movaps	XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm2
86
	movaps	XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0
87
	movaps	XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3
88
	movaps	XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1
89
90
	add	esi, byte 2*SIZEOF_JSAMPROW
91
	add	edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
92
	dec	ecx
93
	jnz	short .convloop
94
95
	pop	edi
96
	pop	esi
97
;	pop	edx		; need not be preserved
98
;	pop	ecx		; need not be preserved
99
	pop	ebx
100
	pop	ebp
101
	ret
102
103
104
; --------------------------------------------------------------------------
105
;
106
; Quantize/descale the coefficients, and store into coef_block
107
;
108
; GLOBAL(void)
109
; jsimd_quantize_float_sse2 (JCOEFPTR coef_block, FAST_FLOAT * divisors,
110
;                         FAST_FLOAT * workspace);
111
;
112
113
%define coef_block	ebp+8		; JCOEFPTR coef_block
114
%define divisors	ebp+12		; FAST_FLOAT * divisors
115
%define workspace	ebp+16		; FAST_FLOAT * workspace
116
117
	align	16
118
	global	EXTN(jsimd_quantize_float_sse2)
119
120
EXTN(jsimd_quantize_float_sse2):
121
	push	ebp
122
	mov	ebp,esp
123
;	push	ebx		; unused
124
;	push	ecx		; unused
125
;	push	edx		; need not be preserved
126
	push	esi
127
	push	edi
128
129
	mov	esi, POINTER [workspace]
130
	mov	edx, POINTER [divisors]
131
	mov	edi, JCOEFPTR [coef_block]
132
	mov	eax, DCTSIZE2/16
133
	alignx	16,7
134
.quantloop:
135
	movaps	xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
136
	movaps	xmm1, XMMWORD [XMMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)]
137
	mulps	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
138
	mulps	xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
139
	movaps	xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
140
	movaps	xmm3, XMMWORD [XMMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)]
141
	mulps	xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
142
	mulps	xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
143
144
	cvtps2dq xmm0,xmm0
145
	cvtps2dq xmm1,xmm1
146
	cvtps2dq xmm2,xmm2
147
	cvtps2dq xmm3,xmm3
148
149
	packssdw xmm0,xmm1
150
	packssdw xmm2,xmm3
151
152
	movdqa	XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_JCOEF)], xmm0
153
	movdqa	XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_JCOEF)], xmm2
154
155
	add	esi, byte 16*SIZEOF_FAST_FLOAT
156
	add	edx, byte 16*SIZEOF_FAST_FLOAT
157
	add	edi, byte 16*SIZEOF_JCOEF
158
	dec	eax
159
	jnz	short .quantloop
160
161
	pop	edi
162
	pop	esi
163
;	pop	edx		; need not be preserved
164
;	pop	ecx		; unused
165
;	pop	ebx		; unused
166
	pop	ebp
167
	ret
168
169
; For some reason, the OS X linker does not honor the request to align the
170
; segment unless we do this.
171
	align	16
(-)a/jpeg/simd/jcqnts2i-64.asm (+187 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcqnts2i-64.asm - sample data conversion and quantization (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
%include "jdct.inc"
22
23
; --------------------------------------------------------------------------
24
	SECTION	SEG_TEXT
25
	BITS	64
26
;
27
; Load data into workspace, applying unsigned->signed conversion
28
;
29
; GLOBAL(void)
30
; jsimd_convsamp_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col,
31
;                      DCTELEM * workspace);
32
;
33
34
; r10 = JSAMPARRAY sample_data
35
; r11 = JDIMENSION start_col
36
; r12 = DCTELEM * workspace
37
38
	align	16
39
	global	EXTN(jsimd_convsamp_sse2)
40
41
EXTN(jsimd_convsamp_sse2):
42
	push	rbp
43
	mov	rax,rsp
44
	mov	rbp,rsp
45
	collect_args
46
	push	rbx
47
48
	pxor	xmm6,xmm6		; xmm6=(all 0's)
49
	pcmpeqw	xmm7,xmm7
50
	psllw	xmm7,7			; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
51
52
	mov rsi, r10
53
	mov rax, r11
54
	mov rdi, r12
55
	mov	rcx, DCTSIZE/4
56
.convloop:
57
	mov	rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW]	; (JSAMPLE *)
58
	mov rdx, JSAMPROW [rsi+1*SIZEOF_JSAMPROW]	; (JSAMPLE *)
59
60
	movq	xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE]	; xmm0=(01234567)
61
	movq	xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE]	; xmm1=(89ABCDEF)
62
63
	mov	rbx, JSAMPROW [rsi+2*SIZEOF_JSAMPROW]	; (JSAMPLE *)
64
	mov	rdx, JSAMPROW [rsi+3*SIZEOF_JSAMPROW]	; (JSAMPLE *)
65
66
	movq	xmm2, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE]	; xmm2=(GHIJKLMN)
67
	movq	xmm3, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE]	; xmm3=(OPQRSTUV)
68
69
	punpcklbw xmm0,xmm6		; xmm0=(01234567)
70
	punpcklbw xmm1,xmm6		; xmm1=(89ABCDEF)
71
	paddw     xmm0,xmm7
72
	paddw     xmm1,xmm7
73
	punpcklbw xmm2,xmm6		; xmm2=(GHIJKLMN)
74
	punpcklbw xmm3,xmm6		; xmm3=(OPQRSTUV)
75
	paddw     xmm2,xmm7
76
	paddw     xmm3,xmm7
77
78
	movdqa	XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_DCTELEM)], xmm0
79
	movdqa	XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_DCTELEM)], xmm1
80
	movdqa	XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_DCTELEM)], xmm2
81
	movdqa	XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_DCTELEM)], xmm3
82
83
	add	rsi, byte 4*SIZEOF_JSAMPROW
84
	add	rdi, byte 4*DCTSIZE*SIZEOF_DCTELEM
85
	dec	rcx
86
	jnz	short .convloop
87
88
	pop	rbx
89
	uncollect_args
90
	pop	rbp
91
	ret
92
93
; --------------------------------------------------------------------------
94
;
95
; Quantize/descale the coefficients, and store into coef_block
96
;
97
; This implementation is based on an algorithm described in
98
;   "How to optimize for the Pentium family of microprocessors"
99
;   (http://www.agner.org/assem/).
100
;
101
; GLOBAL(void)
102
; jsimd_quantize_sse2 (JCOEFPTR coef_block, DCTELEM * divisors,
103
;                      DCTELEM * workspace);
104
;
105
106
%define RECIPROCAL(m,n,b) XMMBLOCK(DCTSIZE*0+(m),(n),(b),SIZEOF_DCTELEM)
107
%define CORRECTION(m,n,b) XMMBLOCK(DCTSIZE*1+(m),(n),(b),SIZEOF_DCTELEM)
108
%define SCALE(m,n,b)      XMMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM)
109
110
; r10 = JCOEFPTR coef_block
111
; r11 = DCTELEM * divisors
112
; r12 = DCTELEM * workspace
113
114
	align	16
115
	global	EXTN(jsimd_quantize_sse2)
116
117
EXTN(jsimd_quantize_sse2):
118
	push	rbp
119
	mov	rax,rsp
120
	mov	rbp,rsp
121
	collect_args
122
123
	mov rsi, r12
124
	mov rdx, r11
125
	mov rdi, r10
126
	mov	rax, DCTSIZE2/32
127
.quantloop:
128
	movdqa	xmm4, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_DCTELEM)]
129
	movdqa	xmm5, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_DCTELEM)]
130
	movdqa	xmm6, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_DCTELEM)]
131
	movdqa	xmm7, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_DCTELEM)]
132
	movdqa	xmm0,xmm4
133
	movdqa	xmm1,xmm5
134
	movdqa	xmm2,xmm6
135
	movdqa	xmm3,xmm7
136
	psraw	xmm4,(WORD_BIT-1)
137
	psraw	xmm5,(WORD_BIT-1)
138
	psraw	xmm6,(WORD_BIT-1)
139
	psraw	xmm7,(WORD_BIT-1)
140
	pxor	xmm0,xmm4
141
	pxor	xmm1,xmm5
142
	pxor	xmm2,xmm6
143
	pxor	xmm3,xmm7
144
	psubw	xmm0,xmm4		; if (xmm0 < 0) xmm0 = -xmm0;
145
	psubw	xmm1,xmm5		; if (xmm1 < 0) xmm1 = -xmm1;
146
	psubw	xmm2,xmm6		; if (xmm2 < 0) xmm2 = -xmm2;
147
	psubw	xmm3,xmm7		; if (xmm3 < 0) xmm3 = -xmm3;
148
149
	paddw	xmm0, XMMWORD [CORRECTION(0,0,rdx)]  ; correction + roundfactor
150
	paddw	xmm1, XMMWORD [CORRECTION(1,0,rdx)]
151
	paddw	xmm2, XMMWORD [CORRECTION(2,0,rdx)]
152
	paddw	xmm3, XMMWORD [CORRECTION(3,0,rdx)]
153
	pmulhuw	xmm0, XMMWORD [RECIPROCAL(0,0,rdx)]  ; reciprocal
154
	pmulhuw	xmm1, XMMWORD [RECIPROCAL(1,0,rdx)]
155
	pmulhuw	xmm2, XMMWORD [RECIPROCAL(2,0,rdx)]
156
	pmulhuw	xmm3, XMMWORD [RECIPROCAL(3,0,rdx)]
157
	pmulhuw	xmm0, XMMWORD [SCALE(0,0,rdx)]	; scale
158
	pmulhuw	xmm1, XMMWORD [SCALE(1,0,rdx)]
159
	pmulhuw	xmm2, XMMWORD [SCALE(2,0,rdx)]
160
	pmulhuw	xmm3, XMMWORD [SCALE(3,0,rdx)]
161
162
	pxor	xmm0,xmm4
163
	pxor	xmm1,xmm5
164
	pxor	xmm2,xmm6
165
	pxor	xmm3,xmm7
166
	psubw	xmm0,xmm4
167
	psubw	xmm1,xmm5
168
	psubw	xmm2,xmm6
169
	psubw	xmm3,xmm7
170
	movdqa	XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_DCTELEM)], xmm0
171
	movdqa	XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_DCTELEM)], xmm1
172
	movdqa	XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_DCTELEM)], xmm2
173
	movdqa	XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_DCTELEM)], xmm3
174
175
	add	rsi, byte 32*SIZEOF_DCTELEM
176
	add	rdx, byte 32*SIZEOF_DCTELEM
177
	add	rdi, byte 32*SIZEOF_JCOEF
178
	dec	rax
179
	jnz	near .quantloop
180
181
	uncollect_args
182
	pop	rbp
183
	ret
184
185
; For some reason, the OS X linker does not honor the request to align the
186
; segment unless we do this.
187
	align	16
(-)a/jpeg/simd/jcqnts2i.asm (+200 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcqnts2i.asm - sample data conversion and quantization (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
%include "jdct.inc"
21
22
; --------------------------------------------------------------------------
23
	SECTION	SEG_TEXT
24
	BITS	32
25
;
26
; Load data into workspace, applying unsigned->signed conversion
27
;
28
; GLOBAL(void)
29
; jsimd_convsamp_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col,
30
;                      DCTELEM * workspace);
31
;
32
33
%define sample_data	ebp+8		; JSAMPARRAY sample_data
34
%define start_col	ebp+12		; JDIMENSION start_col
35
%define workspace	ebp+16		; DCTELEM * workspace
36
37
	align	16
38
	global	EXTN(jsimd_convsamp_sse2)
39
40
EXTN(jsimd_convsamp_sse2):
41
	push	ebp
42
	mov	ebp,esp
43
	push	ebx
44
;	push	ecx		; need not be preserved
45
;	push	edx		; need not be preserved
46
	push	esi
47
	push	edi
48
49
	pxor	xmm6,xmm6		; xmm6=(all 0's)
50
	pcmpeqw	xmm7,xmm7
51
	psllw	xmm7,7			; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
52
53
	mov	esi, JSAMPARRAY [sample_data]	; (JSAMPROW *)
54
	mov	eax, JDIMENSION [start_col]
55
	mov	edi, POINTER [workspace]	; (DCTELEM *)
56
	mov	ecx, DCTSIZE/4
57
	alignx	16,7
58
.convloop:
59
	mov	ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]	; (JSAMPLE *)
60
	mov	edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW]	; (JSAMPLE *)
61
62
	movq	xmm0, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE]	; xmm0=(01234567)
63
	movq	xmm1, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE]	; xmm1=(89ABCDEF)
64
65
	mov	ebx, JSAMPROW [esi+2*SIZEOF_JSAMPROW]	; (JSAMPLE *)
66
	mov	edx, JSAMPROW [esi+3*SIZEOF_JSAMPROW]	; (JSAMPLE *)
67
68
	movq	xmm2, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE]	; xmm2=(GHIJKLMN)
69
	movq	xmm3, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE]	; xmm3=(OPQRSTUV)
70
71
	punpcklbw xmm0,xmm6		; xmm0=(01234567)
72
	punpcklbw xmm1,xmm6		; xmm1=(89ABCDEF)
73
	paddw     xmm0,xmm7
74
	paddw     xmm1,xmm7
75
	punpcklbw xmm2,xmm6		; xmm2=(GHIJKLMN)
76
	punpcklbw xmm3,xmm6		; xmm3=(OPQRSTUV)
77
	paddw     xmm2,xmm7
78
	paddw     xmm3,xmm7
79
80
	movdqa	XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_DCTELEM)], xmm0
81
	movdqa	XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_DCTELEM)], xmm1
82
	movdqa	XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_DCTELEM)], xmm2
83
	movdqa	XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_DCTELEM)], xmm3
84
85
	add	esi, byte 4*SIZEOF_JSAMPROW
86
	add	edi, byte 4*DCTSIZE*SIZEOF_DCTELEM
87
	dec	ecx
88
	jnz	short .convloop
89
90
	pop	edi
91
	pop	esi
92
;	pop	edx		; need not be preserved
93
;	pop	ecx		; need not be preserved
94
	pop	ebx
95
	pop	ebp
96
	ret
97
98
; --------------------------------------------------------------------------
99
;
100
; Quantize/descale the coefficients, and store into coef_block
101
;
102
; This implementation is based on an algorithm described in
103
;   "How to optimize for the Pentium family of microprocessors"
104
;   (http://www.agner.org/assem/).
105
;
106
; GLOBAL(void)
107
; jsimd_quantize_sse2 (JCOEFPTR coef_block, DCTELEM * divisors,
108
;                      DCTELEM * workspace);
109
;
110
111
%define RECIPROCAL(m,n,b) XMMBLOCK(DCTSIZE*0+(m),(n),(b),SIZEOF_DCTELEM)
112
%define CORRECTION(m,n,b) XMMBLOCK(DCTSIZE*1+(m),(n),(b),SIZEOF_DCTELEM)
113
%define SCALE(m,n,b)      XMMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM)
114
115
%define coef_block	ebp+8		; JCOEFPTR coef_block
116
%define divisors	ebp+12		; DCTELEM * divisors
117
%define workspace	ebp+16		; DCTELEM * workspace
118
119
	align	16
120
	global	EXTN(jsimd_quantize_sse2)
121
122
EXTN(jsimd_quantize_sse2):
123
	push	ebp
124
	mov	ebp,esp
125
;	push	ebx		; unused
126
;	push	ecx		; unused
127
;	push	edx		; need not be preserved
128
	push	esi
129
	push	edi
130
131
	mov	esi, POINTER [workspace]
132
	mov	edx, POINTER [divisors]
133
	mov	edi, JCOEFPTR [coef_block]
134
	mov	eax, DCTSIZE2/32
135
	alignx	16,7
136
.quantloop:
137
	movdqa	xmm4, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_DCTELEM)]
138
	movdqa	xmm5, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_DCTELEM)]
139
	movdqa	xmm6, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_DCTELEM)]
140
	movdqa	xmm7, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_DCTELEM)]
141
	movdqa	xmm0,xmm4
142
	movdqa	xmm1,xmm5
143
	movdqa	xmm2,xmm6
144
	movdqa	xmm3,xmm7
145
	psraw	xmm4,(WORD_BIT-1)
146
	psraw	xmm5,(WORD_BIT-1)
147
	psraw	xmm6,(WORD_BIT-1)
148
	psraw	xmm7,(WORD_BIT-1)
149
	pxor	xmm0,xmm4
150
	pxor	xmm1,xmm5
151
	pxor	xmm2,xmm6
152
	pxor	xmm3,xmm7
153
	psubw	xmm0,xmm4		; if (xmm0 < 0) xmm0 = -xmm0;
154
	psubw	xmm1,xmm5		; if (xmm1 < 0) xmm1 = -xmm1;
155
	psubw	xmm2,xmm6		; if (xmm2 < 0) xmm2 = -xmm2;
156
	psubw	xmm3,xmm7		; if (xmm3 < 0) xmm3 = -xmm3;
157
158
	paddw	xmm0, XMMWORD [CORRECTION(0,0,edx)]  ; correction + roundfactor
159
	paddw	xmm1, XMMWORD [CORRECTION(1,0,edx)]
160
	paddw	xmm2, XMMWORD [CORRECTION(2,0,edx)]
161
	paddw	xmm3, XMMWORD [CORRECTION(3,0,edx)]
162
	pmulhuw	xmm0, XMMWORD [RECIPROCAL(0,0,edx)]  ; reciprocal
163
	pmulhuw	xmm1, XMMWORD [RECIPROCAL(1,0,edx)]
164
	pmulhuw	xmm2, XMMWORD [RECIPROCAL(2,0,edx)]
165
	pmulhuw	xmm3, XMMWORD [RECIPROCAL(3,0,edx)]
166
	pmulhuw	xmm0, XMMWORD [SCALE(0,0,edx)]	; scale
167
	pmulhuw	xmm1, XMMWORD [SCALE(1,0,edx)]
168
	pmulhuw	xmm2, XMMWORD [SCALE(2,0,edx)]
169
	pmulhuw	xmm3, XMMWORD [SCALE(3,0,edx)]
170
171
	pxor	xmm0,xmm4
172
	pxor	xmm1,xmm5
173
	pxor	xmm2,xmm6
174
	pxor	xmm3,xmm7
175
	psubw	xmm0,xmm4
176
	psubw	xmm1,xmm5
177
	psubw	xmm2,xmm6
178
	psubw	xmm3,xmm7
179
	movdqa	XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_DCTELEM)], xmm0
180
	movdqa	XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_DCTELEM)], xmm1
181
	movdqa	XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_DCTELEM)], xmm2
182
	movdqa	XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_DCTELEM)], xmm3
183
184
	add	esi, byte 32*SIZEOF_DCTELEM
185
	add	edx, byte 32*SIZEOF_DCTELEM
186
	add	edi, byte 32*SIZEOF_JCOEF
187
	dec	eax
188
	jnz	near .quantloop
189
190
	pop	edi
191
	pop	esi
192
;	pop	edx		; need not be preserved
193
;	pop	ecx		; unused
194
;	pop	ebx		; unused
195
	pop	ebp
196
	ret
197
198
; For some reason, the OS X linker does not honor the request to align the
199
; segment unless we do this.
200
	align	16
(-)a/jpeg/simd/jcqntsse.asm (+211 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcqntsse.asm - sample data conversion and quantization (SSE & MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
%include "jdct.inc"
21
22
; --------------------------------------------------------------------------
23
	SECTION	SEG_TEXT
24
	BITS	32
25
;
26
; Load data into workspace, applying unsigned->signed conversion
27
;
28
; GLOBAL(void)
29
; jsimd_convsamp_float_sse (JSAMPARRAY sample_data, JDIMENSION start_col,
30
;                           FAST_FLOAT * workspace);
31
;
32
33
%define sample_data	ebp+8		; JSAMPARRAY sample_data
34
%define start_col	ebp+12		; JDIMENSION start_col
35
%define workspace	ebp+16		; FAST_FLOAT * workspace
36
37
	align	16
38
	global	EXTN(jsimd_convsamp_float_sse)
39
40
EXTN(jsimd_convsamp_float_sse):
41
	push	ebp
42
	mov	ebp,esp
43
	push	ebx
44
;	push	ecx		; need not be preserved
45
;	push	edx		; need not be preserved
46
	push	esi
47
	push	edi
48
49
	pcmpeqw  mm7,mm7
50
	psllw    mm7,7
51
	packsswb mm7,mm7		; mm7 = PB_CENTERJSAMPLE (0x808080..)
52
53
	mov	esi, JSAMPARRAY [sample_data]	; (JSAMPROW *)
54
	mov	eax, JDIMENSION [start_col]
55
	mov	edi, POINTER [workspace]	; (DCTELEM *)
56
	mov	ecx, DCTSIZE/2
57
	alignx	16,7
58
.convloop:
59
	mov	ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]	; (JSAMPLE *)
60
	mov	edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW]	; (JSAMPLE *)
61
62
	movq	mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE]
63
	movq	mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE]
64
65
	psubb	mm0,mm7				; mm0=(01234567)
66
	psubb	mm1,mm7				; mm1=(89ABCDEF)
67
68
	punpcklbw mm2,mm0			; mm2=(*0*1*2*3)
69
	punpckhbw mm0,mm0			; mm0=(*4*5*6*7)
70
	punpcklbw mm3,mm1			; mm3=(*8*9*A*B)
71
	punpckhbw mm1,mm1			; mm1=(*C*D*E*F)
72
73
	punpcklwd mm4,mm2			; mm4=(***0***1)
74
	punpckhwd mm2,mm2			; mm2=(***2***3)
75
	punpcklwd mm5,mm0			; mm5=(***4***5)
76
	punpckhwd mm0,mm0			; mm0=(***6***7)
77
78
	psrad     mm4,(DWORD_BIT-BYTE_BIT)	; mm4=(01)
79
	psrad     mm2,(DWORD_BIT-BYTE_BIT)	; mm2=(23)
80
	cvtpi2ps  xmm0,mm4			; xmm0=(01**)
81
	cvtpi2ps  xmm1,mm2			; xmm1=(23**)
82
	psrad     mm5,(DWORD_BIT-BYTE_BIT)	; mm5=(45)
83
	psrad     mm0,(DWORD_BIT-BYTE_BIT)	; mm0=(67)
84
	cvtpi2ps  xmm2,mm5			; xmm2=(45**)
85
	cvtpi2ps  xmm3,mm0			; xmm3=(67**)
86
87
	punpcklwd mm6,mm3			; mm6=(***8***9)
88
	punpckhwd mm3,mm3			; mm3=(***A***B)
89
	punpcklwd mm4,mm1			; mm4=(***C***D)
90
	punpckhwd mm1,mm1			; mm1=(***E***F)
91
92
	psrad     mm6,(DWORD_BIT-BYTE_BIT)	; mm6=(89)
93
	psrad     mm3,(DWORD_BIT-BYTE_BIT)	; mm3=(AB)
94
	cvtpi2ps  xmm4,mm6			; xmm4=(89**)
95
	cvtpi2ps  xmm5,mm3			; xmm5=(AB**)
96
	psrad     mm4,(DWORD_BIT-BYTE_BIT)	; mm4=(CD)
97
	psrad     mm1,(DWORD_BIT-BYTE_BIT)	; mm1=(EF)
98
	cvtpi2ps  xmm6,mm4			; xmm6=(CD**)
99
	cvtpi2ps  xmm7,mm1			; xmm7=(EF**)
100
101
	movlhps   xmm0,xmm1			; xmm0=(0123)
102
	movlhps   xmm2,xmm3			; xmm2=(4567)
103
	movlhps   xmm4,xmm5			; xmm4=(89AB)
104
	movlhps   xmm6,xmm7			; xmm6=(CDEF)
105
106
	movaps	XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm0
107
	movaps	XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm2
108
	movaps	XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm4
109
	movaps	XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm6
110
111
	add	esi, byte 2*SIZEOF_JSAMPROW
112
	add	edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
113
	dec	ecx
114
	jnz	near .convloop
115
116
	emms		; empty MMX state
117
118
	pop	edi
119
	pop	esi
120
;	pop	edx		; need not be preserved
121
;	pop	ecx		; need not be preserved
122
	pop	ebx
123
	pop	ebp
124
	ret
125
126
127
; --------------------------------------------------------------------------
128
;
129
; Quantize/descale the coefficients, and store into coef_block
130
;
131
; GLOBAL(void)
132
; jsimd_quantize_float_sse (JCOEFPTR coef_block, FAST_FLOAT * divisors,
133
;                           FAST_FLOAT * workspace);
134
;
135
136
%define coef_block	ebp+8		; JCOEFPTR coef_block
137
%define divisors	ebp+12		; FAST_FLOAT * divisors
138
%define workspace	ebp+16		; FAST_FLOAT * workspace
139
140
	align	16
141
	global	EXTN(jsimd_quantize_float_sse)
142
143
EXTN(jsimd_quantize_float_sse):
144
	push	ebp
145
	mov	ebp,esp
146
;	push	ebx		; unused
147
;	push	ecx		; unused
148
;	push	edx		; need not be preserved
149
	push	esi
150
	push	edi
151
152
	mov	esi, POINTER [workspace]
153
	mov	edx, POINTER [divisors]
154
	mov	edi, JCOEFPTR [coef_block]
155
	mov	eax, DCTSIZE2/16
156
	alignx	16,7
157
.quantloop:
158
	movaps	xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
159
	movaps	xmm1, XMMWORD [XMMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)]
160
	mulps	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
161
	mulps	xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
162
	movaps	xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
163
	movaps	xmm3, XMMWORD [XMMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)]
164
	mulps	xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
165
	mulps	xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
166
167
	movhlps  xmm4,xmm0
168
	movhlps  xmm5,xmm1
169
170
	cvtps2pi mm0,xmm0
171
	cvtps2pi mm1,xmm1
172
	cvtps2pi mm4,xmm4
173
	cvtps2pi mm5,xmm5
174
175
	movhlps  xmm6,xmm2
176
	movhlps  xmm7,xmm3
177
178
	cvtps2pi mm2,xmm2
179
	cvtps2pi mm3,xmm3
180
	cvtps2pi mm6,xmm6
181
	cvtps2pi mm7,xmm7
182
183
	packssdw mm0,mm4
184
	packssdw mm1,mm5
185
	packssdw mm2,mm6
186
	packssdw mm3,mm7
187
188
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
189
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm1
190
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm2
191
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm3
192
193
	add	esi, byte 16*SIZEOF_FAST_FLOAT
194
	add	edx, byte 16*SIZEOF_FAST_FLOAT
195
	add	edi, byte 16*SIZEOF_JCOEF
196
	dec	eax
197
	jnz	short .quantloop
198
199
	emms		; empty MMX state
200
201
	pop	edi
202
	pop	esi
203
;	pop	edx		; need not be preserved
204
;	pop	ecx		; unused
205
;	pop	ebx		; unused
206
	pop	ebp
207
	ret
208
209
; For some reason, the OS X linker does not honor the request to align the
210
; segment unless we do this.
211
	align	16
(-)a/jpeg/simd/jcsammmx.asm (+324 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcsammmx.asm - downsampling (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_TEXT
23
	BITS	32
24
;
25
; Downsample pixel values of a single component.
26
; This version handles the common case of 2:1 horizontal and 1:1 vertical,
27
; without smoothing.
28
;
29
; GLOBAL(void)
30
; jsimd_h2v1_downsample_mmx (JDIMENSION image_width, int max_v_samp_factor,
31
;                            JDIMENSION v_samp_factor, JDIMENSION width_blocks,
32
;                            JSAMPARRAY input_data, JSAMPARRAY output_data);
33
;
34
35
%define img_width(b)	(b)+8			; JDIMENSION image_width
36
%define max_v_samp(b)	(b)+12		; int max_v_samp_factor
37
%define v_samp(b)			(b)+16		; JDIMENSION v_samp_factor
38
%define width_blks(b)	(b)+20		; JDIMENSION width_blocks
39
%define input_data(b)	(b)+24		; JSAMPARRAY input_data
40
%define output_data(b)	(b)+28	; JSAMPARRAY output_data
41
42
	align	16
43
	global	EXTN(jsimd_h2v1_downsample_mmx)
44
45
EXTN(jsimd_h2v1_downsample_mmx):
46
	push	ebp
47
	mov	ebp,esp
48
;	push	ebx		; unused
49
;	push	ecx		; need not be preserved
50
;	push	edx		; need not be preserved
51
	push	esi
52
	push	edi
53
54
	mov	ecx, JDIMENSION [width_blks(ebp)]
55
	shl	ecx,3			; imul ecx,DCTSIZE (ecx = output_cols)
56
	jz	near .return
57
58
	mov	edx, JDIMENSION [img_width(ebp)]
59
60
	; -- expand_right_edge
61
62
	push	ecx
63
	shl	ecx,1				; output_cols * 2
64
	sub	ecx,edx
65
	jle	short .expand_end
66
67
	mov	eax, INT [max_v_samp(ebp)]
68
	test	eax,eax
69
	jle	short .expand_end
70
71
	cld
72
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
73
	alignx	16,7
74
.expandloop:
75
	push	eax
76
	push	ecx
77
78
	mov	edi, JSAMPROW [esi]
79
	add	edi,edx
80
	mov	al, JSAMPLE [edi-1]
81
82
	rep stosb
83
84
	pop	ecx
85
	pop	eax
86
87
	add	esi, byte SIZEOF_JSAMPROW
88
	dec	eax
89
	jg	short .expandloop
90
91
.expand_end:
92
	pop	ecx				; output_cols
93
94
	; -- h2v1_downsample
95
96
	mov	eax, JDIMENSION [v_samp(ebp)]	; rowctr
97
	test	eax,eax
98
	jle	near .return
99
100
	mov       edx, 0x00010000	; bias pattern
101
	movd      mm7,edx
102
	pcmpeqw   mm6,mm6
103
	punpckldq mm7,mm7		; mm7={0, 1, 0, 1}
104
	psrlw     mm6,BYTE_BIT		; mm6={0xFF 0x00 0xFF 0x00 ..}
105
106
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
107
	mov	edi, JSAMPARRAY [output_data(ebp)]	; output_data
108
	alignx	16,7
109
.rowloop:
110
	push	ecx
111
	push	edi
112
	push	esi
113
114
	mov	esi, JSAMPROW [esi]		; inptr
115
	mov	edi, JSAMPROW [edi]		; outptr
116
	alignx	16,7
117
.columnloop:
118
119
	movq	mm0, MMWORD [esi+0*SIZEOF_MMWORD]
120
	movq	mm1, MMWORD [esi+1*SIZEOF_MMWORD]
121
	movq	mm2,mm0
122
	movq	mm3,mm1
123
124
	pand	mm0,mm6
125
	psrlw	mm2,BYTE_BIT
126
	pand	mm1,mm6
127
	psrlw	mm3,BYTE_BIT
128
129
	paddw	mm0,mm2
130
	paddw	mm1,mm3
131
	paddw	mm0,mm7
132
	paddw	mm1,mm7
133
	psrlw	mm0,1
134
	psrlw	mm1,1
135
136
	packuswb mm0,mm1
137
138
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mm0
139
140
	add	esi, byte 2*SIZEOF_MMWORD	; inptr
141
	add	edi, byte 1*SIZEOF_MMWORD	; outptr
142
	sub	ecx, byte SIZEOF_MMWORD		; outcol
143
	jnz	short .columnloop
144
145
	pop	esi
146
	pop	edi
147
	pop	ecx
148
149
	add	esi, byte SIZEOF_JSAMPROW	; input_data
150
	add	edi, byte SIZEOF_JSAMPROW	; output_data
151
	dec	eax				; rowctr
152
	jg	short .rowloop
153
154
	emms		; empty MMX state
155
156
.return:
157
	pop	edi
158
	pop	esi
159
;	pop	edx		; need not be preserved
160
;	pop	ecx		; need not be preserved
161
;	pop	ebx		; unused
162
	pop	ebp
163
	ret
164
165
; --------------------------------------------------------------------------
166
;
167
; Downsample pixel values of a single component.
168
; This version handles the standard case of 2:1 horizontal and 2:1 vertical,
169
; without smoothing.
170
;
171
; GLOBAL(void)
172
; jsimd_h2v2_downsample_mmx (JDIMENSION image_width, int max_v_samp_factor,
173
;                            JDIMENSION v_samp_factor, JDIMENSION width_blocks,
174
;                            JSAMPARRAY input_data, JSAMPARRAY output_data);
175
;
176
177
%define img_width(b)	(b)+8			; JDIMENSION image_width
178
%define max_v_samp(b)	(b)+12		; int max_v_samp_factor
179
%define v_samp(b)			(b)+16		; JDIMENSION v_samp_factor
180
%define width_blks(b)	(b)+20		; JDIMENSION width_blocks
181
%define input_data(b)	(b)+24		; JSAMPARRAY input_data
182
%define output_data(b)	(b)+28	; JSAMPARRAY output_data
183
184
	align	16
185
	global	EXTN(jsimd_h2v2_downsample_mmx)
186
187
EXTN(jsimd_h2v2_downsample_mmx):
188
	push	ebp
189
	mov	ebp,esp
190
;	push	ebx		; unused
191
;	push	ecx		; need not be preserved
192
;	push	edx		; need not be preserved
193
	push	esi
194
	push	edi
195
196
	mov	ecx, JDIMENSION [width_blks(ebp)]
197
	shl	ecx,3			; imul ecx,DCTSIZE (ecx = output_cols)
198
	jz	near .return
199
200
	mov	edx, JDIMENSION [img_width(ebp)]
201
202
	; -- expand_right_edge
203
204
	push	ecx
205
	shl	ecx,1				; output_cols * 2
206
	sub	ecx,edx
207
	jle	short .expand_end
208
209
	mov	eax, INT [max_v_samp(ebp)]
210
	test	eax,eax
211
	jle	short .expand_end
212
213
	cld
214
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
215
	alignx	16,7
216
.expandloop:
217
	push	eax
218
	push	ecx
219
220
	mov	edi, JSAMPROW [esi]
221
	add	edi,edx
222
	mov	al, JSAMPLE [edi-1]
223
224
	rep stosb
225
226
	pop	ecx
227
	pop	eax
228
229
	add	esi, byte SIZEOF_JSAMPROW
230
	dec	eax
231
	jg	short .expandloop
232
233
.expand_end:
234
	pop	ecx				; output_cols
235
236
	; -- h2v2_downsample
237
238
	mov	eax, JDIMENSION [v_samp(ebp)]	; rowctr
239
	test	eax,eax
240
	jle	near .return
241
242
	mov       edx, 0x00020001	; bias pattern
243
	movd      mm7,edx
244
	pcmpeqw   mm6,mm6
245
	punpckldq mm7,mm7		; mm7={1, 2, 1, 2}
246
	psrlw     mm6,BYTE_BIT		; mm6={0xFF 0x00 0xFF 0x00 ..}
247
248
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
249
	mov	edi, JSAMPARRAY [output_data(ebp)]	; output_data
250
	alignx	16,7
251
.rowloop:
252
	push	ecx
253
	push	edi
254
	push	esi
255
256
	mov	edx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]	; inptr0
257
	mov	esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW]	; inptr1
258
	mov	edi, JSAMPROW [edi]			; outptr
259
	alignx	16,7
260
.columnloop:
261
262
	movq	mm0, MMWORD [edx+0*SIZEOF_MMWORD]
263
	movq	mm1, MMWORD [esi+0*SIZEOF_MMWORD]
264
	movq	mm2, MMWORD [edx+1*SIZEOF_MMWORD]
265
	movq	mm3, MMWORD [esi+1*SIZEOF_MMWORD]
266
267
	movq	mm4,mm0
268
	movq	mm5,mm1
269
	pand	mm0,mm6
270
	psrlw	mm4,BYTE_BIT
271
	pand	mm1,mm6
272
	psrlw	mm5,BYTE_BIT
273
	paddw	mm0,mm4
274
	paddw	mm1,mm5
275
276
	movq	mm4,mm2
277
	movq	mm5,mm3
278
	pand	mm2,mm6
279
	psrlw	mm4,BYTE_BIT
280
	pand	mm3,mm6
281
	psrlw	mm5,BYTE_BIT
282
	paddw	mm2,mm4
283
	paddw	mm3,mm5
284
285
	paddw	mm0,mm1
286
	paddw	mm2,mm3
287
	paddw	mm0,mm7
288
	paddw	mm2,mm7
289
	psrlw	mm0,2
290
	psrlw	mm2,2
291
292
	packuswb mm0,mm2
293
294
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mm0
295
296
	add	edx, byte 2*SIZEOF_MMWORD	; inptr0
297
	add	esi, byte 2*SIZEOF_MMWORD	; inptr1
298
	add	edi, byte 1*SIZEOF_MMWORD	; outptr
299
	sub	ecx, byte SIZEOF_MMWORD		; outcol
300
	jnz	near .columnloop
301
302
	pop	esi
303
	pop	edi
304
	pop	ecx
305
306
	add	esi, byte 2*SIZEOF_JSAMPROW	; input_data
307
	add	edi, byte 1*SIZEOF_JSAMPROW	; output_data
308
	dec	eax				; rowctr
309
	jg	near .rowloop
310
311
	emms		; empty MMX state
312
313
.return:
314
	pop	edi
315
	pop	esi
316
;	pop	edx		; need not be preserved
317
;	pop	ecx		; need not be preserved
318
;	pop	ebx		; unused
319
	pop	ebp
320
	ret
321
322
; For some reason, the OS X linker does not honor the request to align the
323
; segment unless we do this.
324
	align	16
(-)a/jpeg/simd/jcsamss2-64.asm (+330 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcsamss2-64.asm - downsampling (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
22
; --------------------------------------------------------------------------
23
	SECTION	SEG_TEXT
24
	BITS	64
25
;
26
; Downsample pixel values of a single component.
27
; This version handles the common case of 2:1 horizontal and 1:1 vertical,
28
; without smoothing.
29
;
30
; GLOBAL(void)
31
; jsimd_h2v1_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor,
32
;                             JDIMENSION v_samp_factor, JDIMENSION width_blocks,
33
;                             JSAMPARRAY input_data, JSAMPARRAY output_data);
34
;
35
36
; r10 = JDIMENSION image_width
37
; r11 = int max_v_samp_factor
38
; r12 = JDIMENSION v_samp_factor
39
; r13 = JDIMENSION width_blocks
40
; r14 = JSAMPARRAY input_data
41
; r15 = JSAMPARRAY output_data
42
43
	align	16
44
	global	EXTN(jsimd_h2v1_downsample_sse2)
45
46
EXTN(jsimd_h2v1_downsample_sse2):
47
	push	rbp
48
	mov	rax,rsp
49
	mov	rbp,rsp
50
	collect_args
51
52
	mov rcx, r13
53
	shl	rcx,3			; imul rcx,DCTSIZE (rcx = output_cols)
54
	jz	near .return
55
56
	mov rdx, r10
57
58
	; -- expand_right_edge
59
60
	push	rcx
61
	shl	rcx,1				; output_cols * 2
62
	sub	rcx,rdx
63
	jle	short .expand_end
64
65
	mov	rax, r11
66
	test	rax,rax
67
	jle	short .expand_end
68
69
	cld
70
	mov	rsi, r14	; input_data
71
.expandloop:
72
	push	rax
73
	push	rcx
74
75
	mov	rdi, JSAMPROW [rsi]
76
	add	rdi,rdx
77
	mov	al, JSAMPLE [rdi-1]
78
79
	rep stosb
80
81
	pop	rcx
82
	pop	rax
83
84
	add	rsi, byte SIZEOF_JSAMPROW
85
	dec	rax
86
	jg	short .expandloop
87
88
.expand_end:
89
	pop	rcx				; output_cols
90
91
	; -- h2v1_downsample
92
93
	mov	rax, r12	; rowctr
94
	test	eax,eax
95
	jle	near .return
96
97
	mov	rdx, 0x00010000		; bias pattern
98
	movd	xmm7,edx
99
	pcmpeqw	xmm6,xmm6
100
	pshufd	xmm7,xmm7,0x00		; xmm7={0, 1, 0, 1, 0, 1, 0, 1}
101
	psrlw	xmm6,BYTE_BIT		; xmm6={0xFF 0x00 0xFF 0x00 ..}
102
103
	mov	rsi, r14	; input_data
104
	mov	rdi, r15	; output_data
105
.rowloop:
106
	push	rcx
107
	push	rdi
108
	push	rsi
109
110
	mov	rsi, JSAMPROW [rsi]		; inptr
111
	mov rdi, JSAMPROW [rdi]		; outptr
112
113
	cmp	rcx, byte SIZEOF_XMMWORD
114
	jae	short .columnloop
115
116
.columnloop_r8:
117
	movdqa	xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD]
118
	pxor	xmm1,xmm1
119
	mov	rcx, SIZEOF_XMMWORD
120
	jmp	short .downsample
121
122
.columnloop:
123
	movdqa	xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD]
124
	movdqa	xmm1, XMMWORD [rsi+1*SIZEOF_XMMWORD]
125
126
.downsample:
127
	movdqa	xmm2,xmm0
128
	movdqa	xmm3,xmm1
129
130
	pand	xmm0,xmm6
131
	psrlw	xmm2,BYTE_BIT
132
	pand	xmm1,xmm6
133
	psrlw	xmm3,BYTE_BIT
134
135
	paddw	xmm0,xmm2
136
	paddw	xmm1,xmm3
137
	paddw	xmm0,xmm7
138
	paddw	xmm1,xmm7
139
	psrlw	xmm0,1
140
	psrlw	xmm1,1
141
142
	packuswb xmm0,xmm1
143
144
	movdqa	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0
145
146
	sub	rcx, byte SIZEOF_XMMWORD	; outcol
147
	add	rsi, byte 2*SIZEOF_XMMWORD	; inptr
148
	add	rdi, byte 1*SIZEOF_XMMWORD	; outptr
149
	cmp	rcx, byte SIZEOF_XMMWORD
150
	jae	short .columnloop
151
	test	rcx,rcx
152
	jnz	short .columnloop_r8
153
154
	pop	rsi
155
	pop	rdi
156
	pop	rcx
157
158
	add	rsi, byte SIZEOF_JSAMPROW	; input_data
159
	add	rdi, byte SIZEOF_JSAMPROW	; output_data
160
	dec	rax				; rowctr
161
	jg	near .rowloop
162
163
.return:
164
	uncollect_args
165
	pop	rbp
166
	ret
167
168
; --------------------------------------------------------------------------
169
;
170
; Downsample pixel values of a single component.
171
; This version handles the standard case of 2:1 horizontal and 2:1 vertical,
172
; without smoothing.
173
;
174
; GLOBAL(void)
175
; jsimd_h2v2_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor,
176
;                             JDIMENSION v_samp_factor, JDIMENSION width_blocks,
177
;                             JSAMPARRAY input_data, JSAMPARRAY output_data);
178
;
179
180
; r10 = JDIMENSION image_width
181
; r11 = int max_v_samp_factor
182
; r12 = JDIMENSION v_samp_factor
183
; r13 = JDIMENSION width_blocks
184
; r14 = JSAMPARRAY input_data
185
; r15 = JSAMPARRAY output_data
186
187
	align	16
188
	global	EXTN(jsimd_h2v2_downsample_sse2)
189
190
EXTN(jsimd_h2v2_downsample_sse2):
191
	push	rbp
192
	mov	rax,rsp
193
	mov	rbp,rsp
194
	collect_args
195
196
	mov	rcx, r13
197
	shl	rcx,3			; imul rcx,DCTSIZE (rcx = output_cols)
198
	jz	near .return
199
200
	mov	rdx, r10
201
202
	; -- expand_right_edge
203
204
	push	rcx
205
	shl	rcx,1				; output_cols * 2
206
	sub	rcx,rdx
207
	jle	short .expand_end
208
209
	mov	rax, r11
210
	test	rax,rax
211
	jle	short .expand_end
212
213
	cld
214
	mov	rsi, r14	; input_data
215
.expandloop:
216
	push	rax
217
	push	rcx
218
219
	mov	rdi, JSAMPROW [rsi]
220
	add	rdi,rdx
221
	mov	al, JSAMPLE [rdi-1]
222
223
	rep stosb
224
225
	pop	rcx
226
	pop	rax
227
228
	add	rsi, byte SIZEOF_JSAMPROW
229
	dec	rax
230
	jg	short .expandloop
231
232
.expand_end:
233
	pop	rcx				; output_cols
234
235
	; -- h2v2_downsample
236
237
	mov	rax, r12	; rowctr
238
	test	rax,rax
239
	jle	near .return
240
241
	mov	rdx, 0x00020001		; bias pattern
242
	movd	xmm7,edx
243
	pcmpeqw	xmm6,xmm6
244
	pshufd	xmm7,xmm7,0x00		; xmm7={1, 2, 1, 2, 1, 2, 1, 2}
245
	psrlw	xmm6,BYTE_BIT		; xmm6={0xFF 0x00 0xFF 0x00 ..}
246
247
	mov	rsi, r14	; input_data
248
	mov	rdi, r15	; output_data
249
.rowloop:
250
	push	rcx
251
	push	rdi
252
	push	rsi
253
254
	mov	rdx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW]	; inptr0
255
	mov	rsi, JSAMPROW [rsi+1*SIZEOF_JSAMPROW]	; inptr1
256
	mov	rdi, JSAMPROW [rdi]			; outptr
257
258
	cmp	rcx, byte SIZEOF_XMMWORD
259
	jae	short .columnloop
260
261
.columnloop_r8:
262
	movdqa	xmm0, XMMWORD [rdx+0*SIZEOF_XMMWORD]
263
	movdqa	xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD]
264
	pxor	xmm2,xmm2
265
	pxor	xmm3,xmm3
266
	mov	rcx, SIZEOF_XMMWORD
267
	jmp	short .downsample
268
269
.columnloop:
270
	movdqa	xmm0, XMMWORD [rdx+0*SIZEOF_XMMWORD]
271
	movdqa	xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD]
272
	movdqa	xmm2, XMMWORD [rdx+1*SIZEOF_XMMWORD]
273
	movdqa	xmm3, XMMWORD [rsi+1*SIZEOF_XMMWORD]
274
275
.downsample:
276
	movdqa	xmm4,xmm0
277
	movdqa	xmm5,xmm1
278
	pand	xmm0,xmm6
279
	psrlw	xmm4,BYTE_BIT
280
	pand	xmm1,xmm6
281
	psrlw	xmm5,BYTE_BIT
282
	paddw	xmm0,xmm4
283
	paddw	xmm1,xmm5
284
285
	movdqa	xmm4,xmm2
286
	movdqa	xmm5,xmm3
287
	pand	xmm2,xmm6
288
	psrlw	xmm4,BYTE_BIT
289
	pand	xmm3,xmm6
290
	psrlw	xmm5,BYTE_BIT
291
	paddw	xmm2,xmm4
292
	paddw	xmm3,xmm5
293
294
	paddw	xmm0,xmm1
295
	paddw	xmm2,xmm3
296
	paddw	xmm0,xmm7
297
	paddw	xmm2,xmm7
298
	psrlw	xmm0,2
299
	psrlw	xmm2,2
300
301
	packuswb xmm0,xmm2
302
303
	movdqa	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0
304
305
	sub	rcx, byte SIZEOF_XMMWORD	; outcol
306
	add	rdx, byte 2*SIZEOF_XMMWORD	; inptr0
307
	add	rsi, byte 2*SIZEOF_XMMWORD	; inptr1
308
	add	rdi, byte 1*SIZEOF_XMMWORD	; outptr
309
	cmp	rcx, byte SIZEOF_XMMWORD
310
	jae	near .columnloop
311
	test	rcx,rcx
312
	jnz	near .columnloop_r8
313
314
	pop	rsi
315
	pop	rdi
316
	pop	rcx
317
318
	add	rsi, byte 2*SIZEOF_JSAMPROW	; input_data
319
	add	rdi, byte 1*SIZEOF_JSAMPROW	; output_data
320
	dec	rax				; rowctr
321
	jg	near .rowloop
322
323
.return:
324
	uncollect_args
325
	pop	rbp
326
	ret
327
328
; For some reason, the OS X linker does not honor the request to align the
329
; segment unless we do this.
330
	align	16
(-)a/jpeg/simd/jcsamss2.asm (+351 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jcsamss2.asm - downsampling (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_TEXT
23
	BITS	32
24
;
25
; Downsample pixel values of a single component.
26
; This version handles the common case of 2:1 horizontal and 1:1 vertical,
27
; without smoothing.
28
;
29
; GLOBAL(void)
30
; jsimd_h2v1_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor,
31
;                             JDIMENSION v_samp_factor, JDIMENSION width_blocks,
32
;                             JSAMPARRAY input_data, JSAMPARRAY output_data);
33
;
34
35
%define img_width(b)	(b)+8			; JDIMENSION image_width
36
%define max_v_samp(b)	(b)+12		; int max_v_samp_factor
37
%define v_samp(b)			(b)+16		; JDIMENSION v_samp_factor
38
%define width_blks(b)	(b)+20		; JDIMENSION width_blocks
39
%define input_data(b)	(b)+24		; JSAMPARRAY input_data
40
%define output_data(b)	(b)+28		; JSAMPARRAY output_data
41
42
	align	16
43
	global	EXTN(jsimd_h2v1_downsample_sse2)
44
45
EXTN(jsimd_h2v1_downsample_sse2):
46
	push	ebp
47
	mov	ebp,esp
48
;	push	ebx		; unused
49
;	push	ecx		; need not be preserved
50
;	push	edx		; need not be preserved
51
	push	esi
52
	push	edi
53
54
	mov	ecx, JDIMENSION [width_blks(ebp)]
55
	shl	ecx,3			; imul ecx,DCTSIZE (ecx = output_cols)
56
	jz	near .return
57
58
	mov	edx, JDIMENSION [img_width(ebp)]
59
60
	; -- expand_right_edge
61
62
	push	ecx
63
	shl	ecx,1				; output_cols * 2
64
	sub	ecx,edx
65
	jle	short .expand_end
66
67
	mov	eax, INT [max_v_samp(ebp)]
68
	test	eax,eax
69
	jle	short .expand_end
70
71
	cld
72
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
73
	alignx	16,7
74
.expandloop:
75
	push	eax
76
	push	ecx
77
78
	mov	edi, JSAMPROW [esi]
79
	add	edi,edx
80
	mov	al, JSAMPLE [edi-1]
81
82
	rep stosb
83
84
	pop	ecx
85
	pop	eax
86
87
	add	esi, byte SIZEOF_JSAMPROW
88
	dec	eax
89
	jg	short .expandloop
90
91
.expand_end:
92
	pop	ecx				; output_cols
93
94
	; -- h2v1_downsample
95
96
	mov	eax, JDIMENSION [v_samp(ebp)]	; rowctr
97
	test	eax,eax
98
	jle	near .return
99
100
	mov	edx, 0x00010000		; bias pattern
101
	movd	xmm7,edx
102
	pcmpeqw	xmm6,xmm6
103
	pshufd	xmm7,xmm7,0x00		; xmm7={0, 1, 0, 1, 0, 1, 0, 1}
104
	psrlw	xmm6,BYTE_BIT		; xmm6={0xFF 0x00 0xFF 0x00 ..}
105
106
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
107
	mov	edi, JSAMPARRAY [output_data(ebp)]	; output_data
108
	alignx	16,7
109
.rowloop:
110
	push	ecx
111
	push	edi
112
	push	esi
113
114
	mov	esi, JSAMPROW [esi]		; inptr
115
	mov	edi, JSAMPROW [edi]		; outptr
116
117
	cmp	ecx, byte SIZEOF_XMMWORD
118
	jae	short .columnloop
119
	alignx	16,7
120
121
.columnloop_r8:
122
	movdqa	xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD]
123
	pxor	xmm1,xmm1
124
	mov	ecx, SIZEOF_XMMWORD
125
	jmp	short .downsample
126
	alignx	16,7
127
128
.columnloop:
129
	movdqa	xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD]
130
	movdqa	xmm1, XMMWORD [esi+1*SIZEOF_XMMWORD]
131
132
.downsample:
133
	movdqa	xmm2,xmm0
134
	movdqa	xmm3,xmm1
135
136
	pand	xmm0,xmm6
137
	psrlw	xmm2,BYTE_BIT
138
	pand	xmm1,xmm6
139
	psrlw	xmm3,BYTE_BIT
140
141
	paddw	xmm0,xmm2
142
	paddw	xmm1,xmm3
143
	paddw	xmm0,xmm7
144
	paddw	xmm1,xmm7
145
	psrlw	xmm0,1
146
	psrlw	xmm1,1
147
148
	packuswb xmm0,xmm1
149
150
	movdqa	XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0
151
152
	sub	ecx, byte SIZEOF_XMMWORD	; outcol
153
	add	esi, byte 2*SIZEOF_XMMWORD	; inptr
154
	add	edi, byte 1*SIZEOF_XMMWORD	; outptr
155
	cmp	ecx, byte SIZEOF_XMMWORD
156
	jae	short .columnloop
157
	test	ecx,ecx
158
	jnz	short .columnloop_r8
159
160
	pop	esi
161
	pop	edi
162
	pop	ecx
163
164
	add	esi, byte SIZEOF_JSAMPROW	; input_data
165
	add	edi, byte SIZEOF_JSAMPROW	; output_data
166
	dec	eax				; rowctr
167
	jg	near .rowloop
168
169
.return:
170
	pop	edi
171
	pop	esi
172
;	pop	edx		; need not be preserved
173
;	pop	ecx		; need not be preserved
174
;	pop	ebx		; unused
175
	pop	ebp
176
	ret
177
178
; --------------------------------------------------------------------------
179
;
180
; Downsample pixel values of a single component.
181
; This version handles the standard case of 2:1 horizontal and 2:1 vertical,
182
; without smoothing.
183
;
184
; GLOBAL(void)
185
; jsimd_h2v2_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor,
186
;                             JDIMENSION v_samp_factor, JDIMENSION width_blocks,
187
;                             JSAMPARRAY input_data, JSAMPARRAY output_data);
188
;
189
190
%define img_width(b)	(b)+8			; JDIMENSION image_width
191
%define max_v_samp(b)	(b)+12		; int max_v_samp_factor
192
%define v_samp(b)			(b)+16		; JDIMENSION v_samp_factor
193
%define width_blks(b)	(b)+20		; JDIMENSION width_blocks
194
%define input_data(b)	(b)+24		; JSAMPARRAY input_data
195
%define output_data(b)	(b)+28	; JSAMPARRAY output_data
196
197
	align	16
198
	global	EXTN(jsimd_h2v2_downsample_sse2)
199
200
EXTN(jsimd_h2v2_downsample_sse2):
201
	push	ebp
202
	mov	ebp,esp
203
;	push	ebx		; unused
204
;	push	ecx		; need not be preserved
205
;	push	edx		; need not be preserved
206
	push	esi
207
	push	edi
208
209
	mov	ecx, JDIMENSION [width_blks(ebp)]
210
	shl	ecx,3			; imul ecx,DCTSIZE (ecx = output_cols)
211
	jz	near .return
212
213
	mov	edx, JDIMENSION [img_width(ebp)]
214
215
	; -- expand_right_edge
216
217
	push	ecx
218
	shl	ecx,1				; output_cols * 2
219
	sub	ecx,edx
220
	jle	short .expand_end
221
222
	mov	eax, INT [max_v_samp(ebp)]
223
	test	eax,eax
224
	jle	short .expand_end
225
226
	cld
227
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
228
	alignx	16,7
229
.expandloop:
230
	push	eax
231
	push	ecx
232
233
	mov	edi, JSAMPROW [esi]
234
	add	edi,edx
235
	mov	al, JSAMPLE [edi-1]
236
237
	rep stosb
238
239
	pop	ecx
240
	pop	eax
241
242
	add	esi, byte SIZEOF_JSAMPROW
243
	dec	eax
244
	jg	short .expandloop
245
246
.expand_end:
247
	pop	ecx				; output_cols
248
249
	; -- h2v2_downsample
250
251
	mov	eax, JDIMENSION [v_samp(ebp)]	; rowctr
252
	test	eax,eax
253
	jle	near .return
254
255
	mov	edx, 0x00020001		; bias pattern
256
	movd	xmm7,edx
257
	pcmpeqw	xmm6,xmm6
258
	pshufd	xmm7,xmm7,0x00		; xmm7={1, 2, 1, 2, 1, 2, 1, 2}
259
	psrlw	xmm6,BYTE_BIT		; xmm6={0xFF 0x00 0xFF 0x00 ..}
260
261
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
262
	mov	edi, JSAMPARRAY [output_data(ebp)]	; output_data
263
	alignx	16,7
264
.rowloop:
265
	push	ecx
266
	push	edi
267
	push	esi
268
269
	mov	edx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]	; inptr0
270
	mov	esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW]	; inptr1
271
	mov	edi, JSAMPROW [edi]			; outptr
272
273
	cmp	ecx, byte SIZEOF_XMMWORD
274
	jae	short .columnloop
275
	alignx	16,7
276
277
.columnloop_r8:
278
	movdqa	xmm0, XMMWORD [edx+0*SIZEOF_XMMWORD]
279
	movdqa	xmm1, XMMWORD [esi+0*SIZEOF_XMMWORD]
280
	pxor	xmm2,xmm2
281
	pxor	xmm3,xmm3
282
	mov	ecx, SIZEOF_XMMWORD
283
	jmp	short .downsample
284
	alignx	16,7
285
286
.columnloop:
287
	movdqa	xmm0, XMMWORD [edx+0*SIZEOF_XMMWORD]
288
	movdqa	xmm1, XMMWORD [esi+0*SIZEOF_XMMWORD]
289
	movdqa	xmm2, XMMWORD [edx+1*SIZEOF_XMMWORD]
290
	movdqa	xmm3, XMMWORD [esi+1*SIZEOF_XMMWORD]
291
292
.downsample:
293
	movdqa	xmm4,xmm0
294
	movdqa	xmm5,xmm1
295
	pand	xmm0,xmm6
296
	psrlw	xmm4,BYTE_BIT
297
	pand	xmm1,xmm6
298
	psrlw	xmm5,BYTE_BIT
299
	paddw	xmm0,xmm4
300
	paddw	xmm1,xmm5
301
302
	movdqa	xmm4,xmm2
303
	movdqa	xmm5,xmm3
304
	pand	xmm2,xmm6
305
	psrlw	xmm4,BYTE_BIT
306
	pand	xmm3,xmm6
307
	psrlw	xmm5,BYTE_BIT
308
	paddw	xmm2,xmm4
309
	paddw	xmm3,xmm5
310
311
	paddw	xmm0,xmm1
312
	paddw	xmm2,xmm3
313
	paddw	xmm0,xmm7
314
	paddw	xmm2,xmm7
315
	psrlw	xmm0,2
316
	psrlw	xmm2,2
317
318
	packuswb xmm0,xmm2
319
320
	movdqa	XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0
321
322
	sub	ecx, byte SIZEOF_XMMWORD	; outcol
323
	add	edx, byte 2*SIZEOF_XMMWORD	; inptr0
324
	add	esi, byte 2*SIZEOF_XMMWORD	; inptr1
325
	add	edi, byte 1*SIZEOF_XMMWORD	; outptr
326
	cmp	ecx, byte SIZEOF_XMMWORD
327
	jae	near .columnloop
328
	test	ecx,ecx
329
	jnz	near .columnloop_r8
330
331
	pop	esi
332
	pop	edi
333
	pop	ecx
334
335
	add	esi, byte 2*SIZEOF_JSAMPROW	; input_data
336
	add	edi, byte 1*SIZEOF_JSAMPROW	; output_data
337
	dec	eax				; rowctr
338
	jg	near .rowloop
339
340
.return:
341
	pop	edi
342
	pop	esi
343
;	pop	edx		; need not be preserved
344
;	pop	ecx		; need not be preserved
345
;	pop	ebx		; unused
346
	pop	ebp
347
	ret
348
349
; For some reason, the OS X linker does not honor the request to align the
350
; segment unless we do this.
351
	align	16
(-)a/jpeg/simd/jdclrmmx.asm (+407 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdclrmmx.asm - colorspace conversion (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jcolsamp.inc"
20
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_TEXT
23
	BITS	32
24
;
25
; Convert some rows of samples to the output colorspace.
26
;
27
; GLOBAL(void)
28
; jsimd_ycc_rgb_convert_mmx (JDIMENSION out_width,
29
;                            JSAMPIMAGE input_buf, JDIMENSION input_row,
30
;                            JSAMPARRAY output_buf, int num_rows)
31
;
32
33
%define out_width(b)	(b)+8			; JDIMENSION out_width
34
%define input_buf(b)	(b)+12		; JSAMPIMAGE input_buf
35
%define input_row(b)	(b)+16		; JDIMENSION input_row
36
%define output_buf(b)	(b)+20		; JSAMPARRAY output_buf
37
%define num_rows(b)	(b)+24		; int num_rows
38
39
%define original_ebp	ebp+0
40
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
41
%define WK_NUM		2
42
%define gotptr		wk(0)-SIZEOF_POINTER	; void * gotptr
43
44
	align	16
45
	global	EXTN(jsimd_ycc_rgb_convert_mmx)
46
47
EXTN(jsimd_ycc_rgb_convert_mmx):
48
	push	ebp
49
	mov	eax,esp				; eax = original ebp
50
	sub	esp, byte 4
51
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
52
	mov	[esp],eax
53
	mov	ebp,esp				; ebp = aligned ebp
54
	lea	esp, [wk(0)]
55
	pushpic	eax		; make a room for GOT address
56
	push	ebx
57
;	push	ecx		; need not be preserved
58
;	push	edx		; need not be preserved
59
	push	esi
60
	push	edi
61
62
	get_GOT	ebx			; get GOT address
63
	movpic	POINTER [gotptr], ebx	; save GOT address
64
65
	mov	ecx, JDIMENSION [out_width(eax)]	; num_cols
66
	test	ecx,ecx
67
	jz	near .return
68
69
	push	ecx
70
71
	mov	edi, JSAMPIMAGE [input_buf(eax)]
72
	mov	ecx, JDIMENSION [input_row(eax)]
73
	mov	esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
74
	mov	ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
75
	mov	edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
76
	lea	esi, [esi+ecx*SIZEOF_JSAMPROW]
77
	lea	ebx, [ebx+ecx*SIZEOF_JSAMPROW]
78
	lea	edx, [edx+ecx*SIZEOF_JSAMPROW]
79
80
	pop	ecx
81
82
	mov	edi, JSAMPARRAY [output_buf(eax)]
83
	mov	eax, INT [num_rows(eax)]
84
	test	eax,eax
85
	jle	near .return
86
	alignx	16,7
87
.rowloop:
88
	push	eax
89
	push	edi
90
	push	edx
91
	push	ebx
92
	push	esi
93
	push	ecx			; col
94
95
	mov	esi, JSAMPROW [esi]	; inptr0
96
	mov	ebx, JSAMPROW [ebx]	; inptr1
97
	mov	edx, JSAMPROW [edx]	; inptr2
98
	mov	edi, JSAMPROW [edi]	; outptr
99
	movpic	eax, POINTER [gotptr]	; load GOT address (eax)
100
	alignx	16,7
101
.columnloop:
102
103
	movq	mm5, MMWORD [ebx]	; mm5=Cb(01234567)
104
	movq	mm1, MMWORD [edx]	; mm1=Cr(01234567)
105
106
	pcmpeqw	mm4,mm4
107
	pcmpeqw	mm7,mm7
108
	psrlw	mm4,BYTE_BIT
109
	psllw	mm7,7			; mm7={0xFF80 0xFF80 0xFF80 0xFF80}
110
	movq	mm0,mm4			; mm0=mm4={0xFF 0x00 0xFF 0x00 ..}
111
112
	pand	mm4,mm5			; mm4=Cb(0246)=CbE
113
	psrlw	mm5,BYTE_BIT		; mm5=Cb(1357)=CbO
114
	pand	mm0,mm1			; mm0=Cr(0246)=CrE
115
	psrlw	mm1,BYTE_BIT		; mm1=Cr(1357)=CrO
116
117
	paddw	mm4,mm7
118
	paddw	mm5,mm7
119
	paddw	mm0,mm7
120
	paddw	mm1,mm7
121
122
	; (Original)
123
	; R = Y                + 1.40200 * Cr
124
	; G = Y - 0.34414 * Cb - 0.71414 * Cr
125
	; B = Y + 1.77200 * Cb
126
	;
127
	; (This implementation)
128
	; R = Y                + 0.40200 * Cr + Cr
129
	; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
130
	; B = Y - 0.22800 * Cb + Cb + Cb
131
132
	movq	mm2,mm4			; mm2=CbE
133
	movq	mm3,mm5			; mm3=CbO
134
	paddw	mm4,mm4			; mm4=2*CbE
135
	paddw	mm5,mm5			; mm5=2*CbO
136
	movq	mm6,mm0			; mm6=CrE
137
	movq	mm7,mm1			; mm7=CrO
138
	paddw	mm0,mm0			; mm0=2*CrE
139
	paddw	mm1,mm1			; mm1=2*CrO
140
141
	pmulhw	mm4,[GOTOFF(eax,PW_MF0228)]	; mm4=(2*CbE * -FIX(0.22800))
142
	pmulhw	mm5,[GOTOFF(eax,PW_MF0228)]	; mm5=(2*CbO * -FIX(0.22800))
143
	pmulhw	mm0,[GOTOFF(eax,PW_F0402)]	; mm0=(2*CrE * FIX(0.40200))
144
	pmulhw	mm1,[GOTOFF(eax,PW_F0402)]	; mm1=(2*CrO * FIX(0.40200))
145
146
	paddw	mm4,[GOTOFF(eax,PW_ONE)]
147
	paddw	mm5,[GOTOFF(eax,PW_ONE)]
148
	psraw	mm4,1			; mm4=(CbE * -FIX(0.22800))
149
	psraw	mm5,1			; mm5=(CbO * -FIX(0.22800))
150
	paddw	mm0,[GOTOFF(eax,PW_ONE)]
151
	paddw	mm1,[GOTOFF(eax,PW_ONE)]
152
	psraw	mm0,1			; mm0=(CrE * FIX(0.40200))
153
	psraw	mm1,1			; mm1=(CrO * FIX(0.40200))
154
155
	paddw	mm4,mm2
156
	paddw	mm5,mm3
157
	paddw	mm4,mm2			; mm4=(CbE * FIX(1.77200))=(B-Y)E
158
	paddw	mm5,mm3			; mm5=(CbO * FIX(1.77200))=(B-Y)O
159
	paddw	mm0,mm6			; mm0=(CrE * FIX(1.40200))=(R-Y)E
160
	paddw	mm1,mm7			; mm1=(CrO * FIX(1.40200))=(R-Y)O
161
162
	movq	MMWORD [wk(0)], mm4	; wk(0)=(B-Y)E
163
	movq	MMWORD [wk(1)], mm5	; wk(1)=(B-Y)O
164
165
	movq      mm4,mm2
166
	movq      mm5,mm3
167
	punpcklwd mm2,mm6
168
	punpckhwd mm4,mm6
169
	pmaddwd   mm2,[GOTOFF(eax,PW_MF0344_F0285)]
170
	pmaddwd   mm4,[GOTOFF(eax,PW_MF0344_F0285)]
171
	punpcklwd mm3,mm7
172
	punpckhwd mm5,mm7
173
	pmaddwd   mm3,[GOTOFF(eax,PW_MF0344_F0285)]
174
	pmaddwd   mm5,[GOTOFF(eax,PW_MF0344_F0285)]
175
176
	paddd     mm2,[GOTOFF(eax,PD_ONEHALF)]
177
	paddd     mm4,[GOTOFF(eax,PD_ONEHALF)]
178
	psrad     mm2,SCALEBITS
179
	psrad     mm4,SCALEBITS
180
	paddd     mm3,[GOTOFF(eax,PD_ONEHALF)]
181
	paddd     mm5,[GOTOFF(eax,PD_ONEHALF)]
182
	psrad     mm3,SCALEBITS
183
	psrad     mm5,SCALEBITS
184
185
	packssdw  mm2,mm4	; mm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
186
	packssdw  mm3,mm5	; mm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
187
	psubw     mm2,mm6	; mm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
188
	psubw     mm3,mm7	; mm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
189
190
	movq      mm5, MMWORD [esi]	; mm5=Y(01234567)
191
192
	pcmpeqw   mm4,mm4
193
	psrlw     mm4,BYTE_BIT		; mm4={0xFF 0x00 0xFF 0x00 ..}
194
	pand      mm4,mm5		; mm4=Y(0246)=YE
195
	psrlw     mm5,BYTE_BIT		; mm5=Y(1357)=YO
196
197
	paddw     mm0,mm4		; mm0=((R-Y)E+YE)=RE=(R0 R2 R4 R6)
198
	paddw     mm1,mm5		; mm1=((R-Y)O+YO)=RO=(R1 R3 R5 R7)
199
	packuswb  mm0,mm0		; mm0=(R0 R2 R4 R6 ** ** ** **)
200
	packuswb  mm1,mm1		; mm1=(R1 R3 R5 R7 ** ** ** **)
201
202
	paddw     mm2,mm4		; mm2=((G-Y)E+YE)=GE=(G0 G2 G4 G6)
203
	paddw     mm3,mm5		; mm3=((G-Y)O+YO)=GO=(G1 G3 G5 G7)
204
	packuswb  mm2,mm2		; mm2=(G0 G2 G4 G6 ** ** ** **)
205
	packuswb  mm3,mm3		; mm3=(G1 G3 G5 G7 ** ** ** **)
206
207
	paddw     mm4, MMWORD [wk(0)]	; mm4=(YE+(B-Y)E)=BE=(B0 B2 B4 B6)
208
	paddw     mm5, MMWORD [wk(1)]	; mm5=(YO+(B-Y)O)=BO=(B1 B3 B5 B7)
209
	packuswb  mm4,mm4		; mm4=(B0 B2 B4 B6 ** ** ** **)
210
	packuswb  mm5,mm5		; mm5=(B1 B3 B5 B7 ** ** ** **)
211
212
%if RGB_PIXELSIZE == 3 ; ---------------
213
214
	; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **)
215
	; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **)
216
	; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **)
217
	; mmG=(** ** ** ** ** ** ** **), mmH=(** ** ** ** ** ** ** **)
218
219
	punpcklbw mmA,mmC		; mmA=(00 10 02 12 04 14 06 16)
220
	punpcklbw mmE,mmB		; mmE=(20 01 22 03 24 05 26 07)
221
	punpcklbw mmD,mmF		; mmD=(11 21 13 23 15 25 17 27)
222
223
	movq      mmG,mmA
224
	movq      mmH,mmA
225
	punpcklwd mmA,mmE		; mmA=(00 10 20 01 02 12 22 03)
226
	punpckhwd mmG,mmE		; mmG=(04 14 24 05 06 16 26 07)
227
228
	psrlq     mmH,2*BYTE_BIT	; mmH=(02 12 04 14 06 16 -- --)
229
	psrlq     mmE,2*BYTE_BIT	; mmE=(22 03 24 05 26 07 -- --)
230
231
	movq      mmC,mmD
232
	movq      mmB,mmD
233
	punpcklwd mmD,mmH		; mmD=(11 21 02 12 13 23 04 14)
234
	punpckhwd mmC,mmH		; mmC=(15 25 06 16 17 27 -- --)
235
236
	psrlq     mmB,2*BYTE_BIT	; mmB=(13 23 15 25 17 27 -- --)
237
238
	movq      mmF,mmE
239
	punpcklwd mmE,mmB		; mmE=(22 03 13 23 24 05 15 25)
240
	punpckhwd mmF,mmB		; mmF=(26 07 17 27 -- -- -- --)
241
242
	punpckldq mmA,mmD		; mmA=(00 10 20 01 11 21 02 12)
243
	punpckldq mmE,mmG		; mmE=(22 03 13 23 04 14 24 05)
244
	punpckldq mmC,mmF		; mmC=(15 25 06 16 26 07 17 27)
245
246
	cmp	ecx, byte SIZEOF_MMWORD
247
	jb	short .column_st16
248
249
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
250
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mmE
251
	movq	MMWORD [edi+2*SIZEOF_MMWORD], mmC
252
253
	sub	ecx, byte SIZEOF_MMWORD
254
	jz	short .nextrow
255
256
	add	esi, byte SIZEOF_MMWORD			; inptr0
257
	add	ebx, byte SIZEOF_MMWORD			; inptr1
258
	add	edx, byte SIZEOF_MMWORD			; inptr2
259
	add	edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD	; outptr
260
	jmp	near .columnloop
261
	alignx	16,7
262
263
.column_st16:
264
	lea	ecx, [ecx+ecx*2]	; imul ecx, RGB_PIXELSIZE
265
	cmp	ecx, byte 2*SIZEOF_MMWORD
266
	jb	short .column_st8
267
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
268
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mmE
269
	movq	mmA,mmC
270
	sub	ecx, byte 2*SIZEOF_MMWORD
271
	add	edi, byte 2*SIZEOF_MMWORD
272
	jmp	short .column_st4
273
.column_st8:
274
	cmp	ecx, byte SIZEOF_MMWORD
275
	jb	short .column_st4
276
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
277
	movq	mmA,mmE
278
	sub	ecx, byte SIZEOF_MMWORD
279
	add	edi, byte SIZEOF_MMWORD
280
.column_st4:
281
	movd	eax,mmA
282
	cmp	ecx, byte SIZEOF_DWORD
283
	jb	short .column_st2
284
	mov	DWORD [edi+0*SIZEOF_DWORD], eax
285
	psrlq	mmA,DWORD_BIT
286
	movd	eax,mmA
287
	sub	ecx, byte SIZEOF_DWORD
288
	add	edi, byte SIZEOF_DWORD
289
.column_st2:
290
	cmp	ecx, byte SIZEOF_WORD
291
	jb	short .column_st1
292
	mov	WORD [edi+0*SIZEOF_WORD], ax
293
	shr	eax,WORD_BIT
294
	sub	ecx, byte SIZEOF_WORD
295
	add	edi, byte SIZEOF_WORD
296
.column_st1:
297
	cmp	ecx, byte SIZEOF_BYTE
298
	jb	short .nextrow
299
	mov	BYTE [edi+0*SIZEOF_BYTE], al
300
301
%else ; RGB_PIXELSIZE == 4 ; -----------
302
303
%ifdef RGBX_FILLER_0XFF
304
	pcmpeqb   mm6,mm6		; mm6=(X0 X2 X4 X6 ** ** ** **)
305
	pcmpeqb   mm7,mm7		; mm7=(X1 X3 X5 X7 ** ** ** **)
306
%else
307
	pxor      mm6,mm6		; mm6=(X0 X2 X4 X6 ** ** ** **)
308
	pxor      mm7,mm7		; mm7=(X1 X3 X5 X7 ** ** ** **)
309
%endif
310
	; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **)
311
	; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **)
312
	; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **)
313
	; mmG=(30 32 34 36 ** ** ** **), mmH=(31 33 35 37 ** ** ** **)
314
315
	punpcklbw mmA,mmC		; mmA=(00 10 02 12 04 14 06 16)
316
	punpcklbw mmE,mmG		; mmE=(20 30 22 32 24 34 26 36)
317
	punpcklbw mmB,mmD		; mmB=(01 11 03 13 05 15 07 17)
318
	punpcklbw mmF,mmH		; mmF=(21 31 23 33 25 35 27 37)
319
320
	movq      mmC,mmA
321
	punpcklwd mmA,mmE		; mmA=(00 10 20 30 02 12 22 32)
322
	punpckhwd mmC,mmE		; mmC=(04 14 24 34 06 16 26 36)
323
	movq      mmG,mmB
324
	punpcklwd mmB,mmF		; mmB=(01 11 21 31 03 13 23 33)
325
	punpckhwd mmG,mmF		; mmG=(05 15 25 35 07 17 27 37)
326
327
	movq      mmD,mmA
328
	punpckldq mmA,mmB		; mmA=(00 10 20 30 01 11 21 31)
329
	punpckhdq mmD,mmB		; mmD=(02 12 22 32 03 13 23 33)
330
	movq      mmH,mmC
331
	punpckldq mmC,mmG		; mmC=(04 14 24 34 05 15 25 35)
332
	punpckhdq mmH,mmG		; mmH=(06 16 26 36 07 17 27 37)
333
334
	cmp	ecx, byte SIZEOF_MMWORD
335
	jb	short .column_st16
336
337
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
338
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mmD
339
	movq	MMWORD [edi+2*SIZEOF_MMWORD], mmC
340
	movq	MMWORD [edi+3*SIZEOF_MMWORD], mmH
341
342
	sub	ecx, byte SIZEOF_MMWORD
343
	jz	short .nextrow
344
345
	add	esi, byte SIZEOF_MMWORD			; inptr0
346
	add	ebx, byte SIZEOF_MMWORD			; inptr1
347
	add	edx, byte SIZEOF_MMWORD			; inptr2
348
	add	edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD	; outptr
349
	jmp	near .columnloop
350
	alignx	16,7
351
352
.column_st16:
353
	cmp	ecx, byte SIZEOF_MMWORD/2
354
	jb	short .column_st8
355
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
356
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mmD
357
	movq	mmA,mmC
358
	movq	mmD,mmH
359
	sub	ecx, byte SIZEOF_MMWORD/2
360
	add	edi, byte 2*SIZEOF_MMWORD
361
.column_st8:
362
	cmp	ecx, byte SIZEOF_MMWORD/4
363
	jb	short .column_st4
364
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
365
	movq	mmA,mmD
366
	sub	ecx, byte SIZEOF_MMWORD/4
367
	add	edi, byte 1*SIZEOF_MMWORD
368
.column_st4:
369
	cmp	ecx, byte SIZEOF_MMWORD/8
370
	jb	short .nextrow
371
	movd	DWORD [edi+0*SIZEOF_DWORD], mmA
372
373
%endif ; RGB_PIXELSIZE ; ---------------
374
375
	alignx	16,7
376
377
.nextrow:
378
	pop	ecx
379
	pop	esi
380
	pop	ebx
381
	pop	edx
382
	pop	edi
383
	pop	eax
384
385
	add	esi, byte SIZEOF_JSAMPROW
386
	add	ebx, byte SIZEOF_JSAMPROW
387
	add	edx, byte SIZEOF_JSAMPROW
388
	add	edi, byte SIZEOF_JSAMPROW	; output_buf
389
	dec	eax				; num_rows
390
	jg	near .rowloop
391
392
	emms		; empty MMX state
393
394
.return:
395
	pop	edi
396
	pop	esi
397
;	pop	edx		; need not be preserved
398
;	pop	ecx		; need not be preserved
399
	pop	ebx
400
	mov	esp,ebp		; esp <- aligned ebp
401
	pop	esp		; esp <- original ebp
402
	pop	ebp
403
	ret
404
405
; For some reason, the OS X linker does not honor the request to align the
406
; segment unless we do this.
407
	align	16
(-)a/jpeg/simd/jdclrss2-64.asm (+487 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdclrss2-64.asm - colorspace conversion (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jcolsamp.inc"
21
				
22
; --------------------------------------------------------------------------
23
	SECTION	SEG_TEXT
24
	BITS	64
25
;
26
; Convert some rows of samples to the output colorspace.
27
;
28
; GLOBAL(void)
29
; jsimd_ycc_rgb_convert_sse2 (JDIMENSION out_width,
30
;                             JSAMPIMAGE input_buf, JDIMENSION input_row,
31
;                             JSAMPARRAY output_buf, int num_rows)
32
;
33
34
; r10 = JDIMENSION out_width
35
; r11 = JSAMPIMAGE input_buf
36
; r12 = JDIMENSION input_row
37
; r13 = JSAMPARRAY output_buf
38
; r14 = int num_rows
39
40
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
41
%define WK_NUM		2
42
43
	align	16
44
	global	EXTN(jsimd_ycc_rgb_convert_sse2)
45
46
EXTN(jsimd_ycc_rgb_convert_sse2):
47
	push	rbp
48
	mov	rax,rsp				; rax = original rbp
49
	sub	rsp, byte 4
50
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
51
	mov	[rsp],rax
52
	mov	rbp,rsp				; rbp = aligned rbp
53
	lea	rsp, [wk(0)]
54
	collect_args
55
	push	rbx
56
57
	mov	rcx, r10	; num_cols
58
	test	rcx,rcx
59
	jz	near .return
60
61
	push	rcx
62
63
	mov	rdi, r11
64
	mov	rcx, r12
65
	mov	rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
66
	mov	rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
67
	mov	rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
68
	lea	rsi, [rsi+rcx*SIZEOF_JSAMPROW]
69
	lea	rbx, [rbx+rcx*SIZEOF_JSAMPROW]
70
	lea	rdx, [rdx+rcx*SIZEOF_JSAMPROW]
71
72
	pop	rcx
73
74
	mov	rdi, r13
75
	mov	eax, r14d
76
	test	rax,rax
77
	jle	near .return
78
.rowloop:
79
	push	rax
80
	push	rdi
81
	push	rdx
82
	push	rbx
83
	push	rsi
84
	push	rcx			; col
85
86
	mov	rsi, JSAMPROW [rsi]	; inptr0
87
	mov	rbx, JSAMPROW [rbx]	; inptr1
88
	mov	rdx, JSAMPROW [rdx]	; inptr2
89
	mov	rdi, JSAMPROW [rdi]	; outptr
90
.columnloop:
91
92
	movdqa	xmm5, XMMWORD [rbx]	; xmm5=Cb(0123456789ABCDEF)
93
	movdqa	xmm1, XMMWORD [rdx]	; xmm1=Cr(0123456789ABCDEF)
94
95
	pcmpeqw	xmm4,xmm4
96
	pcmpeqw	xmm7,xmm7
97
	psrlw	xmm4,BYTE_BIT
98
	psllw	xmm7,7			; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
99
	movdqa	xmm0,xmm4		; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..}
100
101
	pand	xmm4,xmm5		; xmm4=Cb(02468ACE)=CbE
102
	psrlw	xmm5,BYTE_BIT		; xmm5=Cb(13579BDF)=CbO
103
	pand	xmm0,xmm1		; xmm0=Cr(02468ACE)=CrE
104
	psrlw	xmm1,BYTE_BIT		; xmm1=Cr(13579BDF)=CrO
105
106
	paddw	xmm4,xmm7
107
	paddw	xmm5,xmm7
108
	paddw	xmm0,xmm7
109
	paddw	xmm1,xmm7
110
111
	; (Original)
112
	; R = Y                + 1.40200 * Cr
113
	; G = Y - 0.34414 * Cb - 0.71414 * Cr
114
	; B = Y + 1.77200 * Cb
115
	;
116
	; (This implementation)
117
	; R = Y                + 0.40200 * Cr + Cr
118
	; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
119
	; B = Y - 0.22800 * Cb + Cb + Cb
120
121
	movdqa	xmm2,xmm4		; xmm2=CbE
122
	movdqa	xmm3,xmm5		; xmm3=CbO
123
	paddw	xmm4,xmm4		; xmm4=2*CbE
124
	paddw	xmm5,xmm5		; xmm5=2*CbO
125
	movdqa	xmm6,xmm0		; xmm6=CrE
126
	movdqa	xmm7,xmm1		; xmm7=CrO
127
	paddw	xmm0,xmm0		; xmm0=2*CrE
128
	paddw	xmm1,xmm1		; xmm1=2*CrO
129
130
	pmulhw	xmm4,[rel PW_MF0228]	; xmm4=(2*CbE * -FIX(0.22800))
131
	pmulhw	xmm5,[rel PW_MF0228]	; xmm5=(2*CbO * -FIX(0.22800))
132
	pmulhw	xmm0,[rel PW_F0402]	; xmm0=(2*CrE * FIX(0.40200))
133
	pmulhw	xmm1,[rel PW_F0402]	; xmm1=(2*CrO * FIX(0.40200))
134
135
	paddw	xmm4,[rel PW_ONE]
136
	paddw	xmm5,[rel PW_ONE]
137
	psraw	xmm4,1			; xmm4=(CbE * -FIX(0.22800))
138
	psraw	xmm5,1			; xmm5=(CbO * -FIX(0.22800))
139
	paddw	xmm0,[rel PW_ONE]
140
	paddw	xmm1,[rel PW_ONE]
141
	psraw	xmm0,1			; xmm0=(CrE * FIX(0.40200))
142
	psraw	xmm1,1			; xmm1=(CrO * FIX(0.40200))
143
144
	paddw	xmm4,xmm2
145
	paddw	xmm5,xmm3
146
	paddw	xmm4,xmm2		; xmm4=(CbE * FIX(1.77200))=(B-Y)E
147
	paddw	xmm5,xmm3		; xmm5=(CbO * FIX(1.77200))=(B-Y)O
148
	paddw	xmm0,xmm6		; xmm0=(CrE * FIX(1.40200))=(R-Y)E
149
	paddw	xmm1,xmm7		; xmm1=(CrO * FIX(1.40200))=(R-Y)O
150
151
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=(B-Y)E
152
	movdqa	XMMWORD [wk(1)], xmm5	; wk(1)=(B-Y)O
153
154
	movdqa    xmm4,xmm2
155
	movdqa    xmm5,xmm3
156
	punpcklwd xmm2,xmm6
157
	punpckhwd xmm4,xmm6
158
	pmaddwd   xmm2,[rel PW_MF0344_F0285]
159
	pmaddwd   xmm4,[rel PW_MF0344_F0285]
160
	punpcklwd xmm3,xmm7
161
	punpckhwd xmm5,xmm7
162
	pmaddwd   xmm3,[rel PW_MF0344_F0285]
163
	pmaddwd   xmm5,[rel PW_MF0344_F0285]
164
165
	paddd     xmm2,[rel PD_ONEHALF]
166
	paddd     xmm4,[rel PD_ONEHALF]
167
	psrad     xmm2,SCALEBITS
168
	psrad     xmm4,SCALEBITS
169
	paddd     xmm3,[rel PD_ONEHALF]
170
	paddd     xmm5,[rel PD_ONEHALF]
171
	psrad     xmm3,SCALEBITS
172
	psrad     xmm5,SCALEBITS
173
174
	packssdw  xmm2,xmm4	; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
175
	packssdw  xmm3,xmm5	; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
176
	psubw     xmm2,xmm6	; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
177
	psubw     xmm3,xmm7	; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
178
179
	movdqa    xmm5, XMMWORD [rsi]	; xmm5=Y(0123456789ABCDEF)
180
181
	pcmpeqw   xmm4,xmm4
182
	psrlw     xmm4,BYTE_BIT		; xmm4={0xFF 0x00 0xFF 0x00 ..}
183
	pand      xmm4,xmm5		; xmm4=Y(02468ACE)=YE
184
	psrlw     xmm5,BYTE_BIT		; xmm5=Y(13579BDF)=YO
185
186
	paddw     xmm0,xmm4		; xmm0=((R-Y)E+YE)=RE=R(02468ACE)
187
	paddw     xmm1,xmm5		; xmm1=((R-Y)O+YO)=RO=R(13579BDF)
188
	packuswb  xmm0,xmm0		; xmm0=R(02468ACE********)
189
	packuswb  xmm1,xmm1		; xmm1=R(13579BDF********)
190
191
	paddw     xmm2,xmm4		; xmm2=((G-Y)E+YE)=GE=G(02468ACE)
192
	paddw     xmm3,xmm5		; xmm3=((G-Y)O+YO)=GO=G(13579BDF)
193
	packuswb  xmm2,xmm2		; xmm2=G(02468ACE********)
194
	packuswb  xmm3,xmm3		; xmm3=G(13579BDF********)
195
196
	paddw     xmm4, XMMWORD [wk(0)]	; xmm4=(YE+(B-Y)E)=BE=B(02468ACE)
197
	paddw     xmm5, XMMWORD [wk(1)]	; xmm5=(YO+(B-Y)O)=BO=B(13579BDF)
198
	packuswb  xmm4,xmm4		; xmm4=B(02468ACE********)
199
	packuswb  xmm5,xmm5		; xmm5=B(13579BDF********)
200
201
%if RGB_PIXELSIZE == 3 ; ---------------
202
203
	; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
204
	; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
205
	; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
206
	; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
207
208
	punpcklbw xmmA,xmmC	; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
209
	punpcklbw xmmE,xmmB	; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
210
	punpcklbw xmmD,xmmF	; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
211
212
	movdqa    xmmG,xmmA
213
	movdqa    xmmH,xmmA
214
	punpcklwd xmmA,xmmE	; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
215
	punpckhwd xmmG,xmmE	; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
216
217
	psrldq    xmmH,2	; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
218
	psrldq    xmmE,2	; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
219
220
	movdqa    xmmC,xmmD
221
	movdqa    xmmB,xmmD
222
	punpcklwd xmmD,xmmH	; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
223
	punpckhwd xmmC,xmmH	; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
224
225
	psrldq    xmmB,2	; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
226
227
	movdqa    xmmF,xmmE
228
	punpcklwd xmmE,xmmB	; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
229
	punpckhwd xmmF,xmmB	; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
230
231
	pshufd    xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
232
	movdqa    xmmB,xmmE
233
	punpckldq xmmA,xmmD	; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
234
	punpckldq xmmE,xmmH	; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
235
	punpckhdq xmmD,xmmB	; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
236
237
	pshufd    xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
238
	movdqa    xmmB,xmmF
239
	punpckldq xmmG,xmmC	; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
240
	punpckldq xmmF,xmmH	; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
241
	punpckhdq xmmC,xmmB	; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
242
243
	punpcklqdq xmmA,xmmE	; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
244
	punpcklqdq xmmD,xmmG	; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
245
	punpcklqdq xmmF,xmmC	; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
246
247
	cmp	rcx, byte SIZEOF_XMMWORD
248
	jb	short .column_st32
249
250
	test	rdi, SIZEOF_XMMWORD-1
251
	jnz	short .out1
252
	; --(aligned)-------------------
253
	movntdq	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
254
	movntdq	XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
255
	movntdq	XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
256
	add	rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; outptr
257
	jmp	short .out0
258
.out1:	; --(unaligned)-----------------
259
	pcmpeqb    xmmH,xmmH			; xmmH=(all 1's)
260
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [rdi], xmmA
261
	add	rdi, byte SIZEOF_XMMWORD	; outptr
262
	maskmovdqu xmmD,xmmH			; movntdqu XMMWORD [rdi], xmmD
263
	add	rdi, byte SIZEOF_XMMWORD	; outptr
264
	maskmovdqu xmmF,xmmH			; movntdqu XMMWORD [rdi], xmmF
265
	add	rdi, byte SIZEOF_XMMWORD	; outptr
266
.out0:
267
	sub	rcx, byte SIZEOF_XMMWORD
268
	jz	near .nextrow
269
270
	add	rsi, byte SIZEOF_XMMWORD	; inptr0
271
	add	rbx, byte SIZEOF_XMMWORD	; inptr1
272
	add	rdx, byte SIZEOF_XMMWORD	; inptr2
273
	jmp	near .columnloop
274
275
.column_st32:
276
	pcmpeqb	xmmH,xmmH			; xmmH=(all 1's)
277
	lea	rcx, [rcx+rcx*2]		; imul ecx, RGB_PIXELSIZE
278
	cmp	rcx, byte 2*SIZEOF_XMMWORD
279
	jb	short .column_st16
280
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [rdi], xmmA
281
	add	rdi, byte SIZEOF_XMMWORD	; outptr
282
	maskmovdqu xmmD,xmmH			; movntdqu XMMWORD [rdi], xmmD
283
	add	rdi, byte SIZEOF_XMMWORD	; outptr
284
	movdqa	xmmA,xmmF
285
	sub	rcx, byte 2*SIZEOF_XMMWORD
286
	jmp	short .column_st15
287
.column_st16:
288
	cmp	rcx, byte SIZEOF_XMMWORD
289
	jb	short .column_st15
290
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [rdi], xmmA
291
	add	rdi, byte SIZEOF_XMMWORD	; outptr
292
	movdqa	xmmA,xmmD
293
	sub	rcx, byte SIZEOF_XMMWORD
294
.column_st15:
295
	mov	rax,rcx
296
	xor	rcx, byte 0x0F
297
	shl	rcx, 2
298
	movd	xmmB,ecx
299
	psrlq	xmmH,4
300
	pcmpeqb	xmmE,xmmE
301
	psrlq	xmmH,xmmB
302
	psrlq	xmmE,xmmB
303
	punpcklbw xmmE,xmmH
304
	; ----------------
305
	mov	rcx,rdi
306
	and	rcx, byte SIZEOF_XMMWORD-1
307
	jz	short .adj0
308
	add	rax,rcx
309
	cmp	rax, byte SIZEOF_XMMWORD
310
	ja	short .adj0
311
	and	rdi, byte (-SIZEOF_XMMWORD)	; align to 16-byte boundary
312
	shl	rcx, 3			; pslldq xmmA,ecx & pslldq xmmE,rcx
313
	movdqa	xmmG,xmmA
314
	movdqa	xmmC,xmmE
315
	pslldq	xmmA, SIZEOF_XMMWORD/2
316
	pslldq	xmmE, SIZEOF_XMMWORD/2
317
	movd	xmmD,ecx
318
	sub	rcx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT
319
	jb	short .adj1
320
	movd	xmmF,ecx
321
	psllq	xmmA,xmmF
322
	psllq	xmmE,xmmF
323
	jmp	short .adj0
324
.adj1:	neg	ecx
325
	movd	xmmF,ecx
326
	psrlq	xmmA,xmmF
327
	psrlq	xmmE,xmmF
328
	psllq	xmmG,xmmD
329
	psllq	xmmC,xmmD
330
	por	xmmA,xmmG
331
	por	xmmE,xmmC
332
.adj0:	; ----------------
333
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [rdi], xmmA
334
335
%else ; RGB_PIXELSIZE == 4 ; -----------
336
337
%ifdef RGBX_FILLER_0XFF
338
	pcmpeqb   xmm6,xmm6		; xmm6=XE=X(02468ACE********)
339
	pcmpeqb   xmm7,xmm7		; xmm7=XO=X(13579BDF********)
340
%else
341
	pxor      xmm6,xmm6		; xmm6=XE=X(02468ACE********)
342
	pxor      xmm7,xmm7		; xmm7=XO=X(13579BDF********)
343
%endif
344
	; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
345
	; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
346
	; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
347
	; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
348
349
	punpcklbw xmmA,xmmC	; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
350
	punpcklbw xmmE,xmmG	; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
351
	punpcklbw xmmB,xmmD	; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
352
	punpcklbw xmmF,xmmH	; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
353
354
	movdqa    xmmC,xmmA
355
	punpcklwd xmmA,xmmE	; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
356
	punpckhwd xmmC,xmmE	; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
357
	movdqa    xmmG,xmmB
358
	punpcklwd xmmB,xmmF	; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
359
	punpckhwd xmmG,xmmF	; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
360
361
	movdqa    xmmD,xmmA
362
	punpckldq xmmA,xmmB	; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
363
	punpckhdq xmmD,xmmB	; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
364
	movdqa    xmmH,xmmC
365
	punpckldq xmmC,xmmG	; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
366
	punpckhdq xmmH,xmmG	; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
367
368
	cmp	rcx, byte SIZEOF_XMMWORD
369
	jb	short .column_st32
370
371
	test	rdi, SIZEOF_XMMWORD-1
372
	jnz	short .out1
373
	; --(aligned)-------------------
374
	movntdq	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
375
	movntdq	XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
376
	movntdq	XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
377
	movntdq	XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
378
	add	rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; outptr
379
	jmp	short .out0
380
.out1:	; --(unaligned)-----------------
381
	pcmpeqb    xmmE,xmmE			; xmmE=(all 1's)
382
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [rdi], xmmA
383
	add	rdi, byte SIZEOF_XMMWORD	; outptr
384
	maskmovdqu xmmD,xmmE			; movntdqu XMMWORD [rdi], xmmD
385
	add	rdi, byte SIZEOF_XMMWORD	; outptr
386
	maskmovdqu xmmC,xmmE			; movntdqu XMMWORD [rdi], xmmC
387
	add	rdi, byte SIZEOF_XMMWORD	; outptr
388
	maskmovdqu xmmH,xmmE			; movntdqu XMMWORD [rdi], xmmH
389
	add	rdi, byte SIZEOF_XMMWORD	; outptr
390
.out0:
391
	sub	rcx, byte SIZEOF_XMMWORD
392
	jz	near .nextrow
393
394
	add	rsi, byte SIZEOF_XMMWORD	; inptr0
395
	add	rbx, byte SIZEOF_XMMWORD	; inptr1
396
	add	rdx, byte SIZEOF_XMMWORD	; inptr2
397
	jmp	near .columnloop
398
399
.column_st32:
400
	pcmpeqb	xmmE,xmmE			; xmmE=(all 1's)
401
	cmp	rcx, byte SIZEOF_XMMWORD/2
402
	jb	short .column_st16
403
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [rdi], xmmA
404
	add	rdi, byte SIZEOF_XMMWORD	; outptr
405
	maskmovdqu xmmD,xmmE			; movntdqu XMMWORD [rdi], xmmD
406
	add	rdi, byte SIZEOF_XMMWORD	; outptr
407
	movdqa	xmmA,xmmC
408
	movdqa	xmmD,xmmH
409
	sub	rcx, byte SIZEOF_XMMWORD/2
410
.column_st16:
411
	cmp	rcx, byte SIZEOF_XMMWORD/4
412
	jb	short .column_st15
413
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [rdi], xmmA
414
	add	rdi, byte SIZEOF_XMMWORD	; outptr
415
	movdqa	xmmA,xmmD
416
	sub	rcx, byte SIZEOF_XMMWORD/4
417
.column_st15:
418
	cmp	rcx, byte SIZEOF_XMMWORD/16
419
	jb	near .nextrow
420
	mov	rax,rcx
421
	xor	rcx, byte 0x03
422
	inc	rcx
423
	shl	rcx, 4
424
	movd	xmmF,ecx
425
	psrlq	xmmE,xmmF
426
	punpcklbw xmmE,xmmE
427
	; ----------------
428
	mov	rcx,rdi
429
	and	rcx, byte SIZEOF_XMMWORD-1
430
	jz	short .adj0
431
	lea	rax, [rcx+rax*4]	; RGB_PIXELSIZE
432
	cmp	rax, byte SIZEOF_XMMWORD
433
	ja	short .adj0
434
	and	rdi, byte (-SIZEOF_XMMWORD)	; align to 16-byte boundary
435
	shl	rcx, 3			; pslldq xmmA,ecx & pslldq xmmE,ecx
436
	movdqa	xmmB,xmmA
437
	movdqa	xmmG,xmmE
438
	pslldq	xmmA, SIZEOF_XMMWORD/2
439
	pslldq	xmmE, SIZEOF_XMMWORD/2
440
	movd	xmmC,ecx
441
	sub	rcx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT
442
	jb	short .adj1
443
	movd	xmmH,ecx
444
	psllq	xmmA,xmmH
445
	psllq	xmmE,xmmH
446
	jmp	short .adj0
447
.adj1:	neg	rcx
448
	movd	xmmH,ecx
449
	psrlq	xmmA,xmmH
450
	psrlq	xmmE,xmmH
451
	psllq	xmmB,xmmC
452
	psllq	xmmG,xmmC
453
	por	xmmA,xmmB
454
	por	xmmE,xmmG
455
.adj0:	; ----------------
456
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [rdi], xmmA
457
458
%endif ; RGB_PIXELSIZE ; ---------------
459
460
.nextrow:
461
	pop	rcx
462
	pop	rsi
463
	pop	rbx
464
	pop	rdx
465
	pop	rdi
466
	pop	rax
467
468
	add	rsi, byte SIZEOF_JSAMPROW
469
	add	rbx, byte SIZEOF_JSAMPROW
470
	add	rdx, byte SIZEOF_JSAMPROW
471
	add	rdi, byte SIZEOF_JSAMPROW	; output_buf
472
	dec	rax				; num_rows
473
	jg	near .rowloop
474
475
	sfence		; flush the write buffer
476
477
.return:
478
	pop	rbx
479
	uncollect_args
480
	mov	rsp,rbp		; rsp <- aligned rbp
481
	pop	rsp		; rsp <- original rbp
482
	pop	rbp
483
	ret
484
485
; For some reason, the OS X linker does not honor the request to align the
486
; segment unless we do this.
487
	align	16
(-)a/jpeg/simd/jdclrss2.asm (+505 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdclrss2.asm - colorspace conversion (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jcolsamp.inc"
20
				
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_TEXT
23
	BITS	32
24
;
25
; Convert some rows of samples to the output colorspace.
26
;
27
; GLOBAL(void)
28
; jsimd_ycc_rgb_convert_sse2 (JDIMENSION out_width,
29
;                             JSAMPIMAGE input_buf, JDIMENSION input_row,
30
;                             JSAMPARRAY output_buf, int num_rows)
31
;
32
33
%define out_width(b)	(b)+8			; JDIMENSION out_width
34
%define input_buf(b)	(b)+12		; JSAMPIMAGE input_buf
35
%define input_row(b)	(b)+16		; JDIMENSION input_row
36
%define output_buf(b)	(b)+20		; JSAMPARRAY output_buf
37
%define num_rows(b)	(b)+24		; int num_rows
38
39
%define original_ebp	ebp+0
40
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
41
%define WK_NUM		2
42
%define gotptr		wk(0)-SIZEOF_POINTER	; void * gotptr
43
44
	align	16
45
	global	EXTN(jsimd_ycc_rgb_convert_sse2)
46
47
EXTN(jsimd_ycc_rgb_convert_sse2):
48
	push	ebp
49
	mov	eax,esp				; eax = original ebp
50
	sub	esp, byte 4
51
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
52
	mov	[esp],eax
53
	mov	ebp,esp				; ebp = aligned ebp
54
	lea	esp, [wk(0)]
55
	pushpic	eax		; make a room for GOT address
56
	push	ebx
57
;	push	ecx		; need not be preserved
58
;	push	edx		; need not be preserved
59
	push	esi
60
	push	edi
61
62
	get_GOT	ebx			; get GOT address
63
	movpic	POINTER [gotptr], ebx	; save GOT address
64
65
	mov	ecx, JDIMENSION [out_width(eax)]	; num_cols
66
	test	ecx,ecx
67
	jz	near .return
68
69
	push	ecx
70
71
	mov	edi, JSAMPIMAGE [input_buf(eax)]
72
	mov	ecx, JDIMENSION [input_row(eax)]
73
	mov	esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
74
	mov	ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
75
	mov	edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
76
	lea	esi, [esi+ecx*SIZEOF_JSAMPROW]
77
	lea	ebx, [ebx+ecx*SIZEOF_JSAMPROW]
78
	lea	edx, [edx+ecx*SIZEOF_JSAMPROW]
79
80
	pop	ecx
81
82
	mov	edi, JSAMPARRAY [output_buf(eax)]
83
	mov	eax, INT [num_rows(eax)]
84
	test	eax,eax
85
	jle	near .return
86
	alignx	16,7
87
.rowloop:
88
	push	eax
89
	push	edi
90
	push	edx
91
	push	ebx
92
	push	esi
93
	push	ecx			; col
94
95
	mov	esi, JSAMPROW [esi]	; inptr0
96
	mov	ebx, JSAMPROW [ebx]	; inptr1
97
	mov	edx, JSAMPROW [edx]	; inptr2
98
	mov	edi, JSAMPROW [edi]	; outptr
99
	movpic	eax, POINTER [gotptr]	; load GOT address (eax)
100
	alignx	16,7
101
.columnloop:
102
103
	movdqa	xmm5, XMMWORD [ebx]	; xmm5=Cb(0123456789ABCDEF)
104
	movdqa	xmm1, XMMWORD [edx]	; xmm1=Cr(0123456789ABCDEF)
105
106
	pcmpeqw	xmm4,xmm4
107
	pcmpeqw	xmm7,xmm7
108
	psrlw	xmm4,BYTE_BIT
109
	psllw	xmm7,7			; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
110
	movdqa	xmm0,xmm4		; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..}
111
112
	pand	xmm4,xmm5		; xmm4=Cb(02468ACE)=CbE
113
	psrlw	xmm5,BYTE_BIT		; xmm5=Cb(13579BDF)=CbO
114
	pand	xmm0,xmm1		; xmm0=Cr(02468ACE)=CrE
115
	psrlw	xmm1,BYTE_BIT		; xmm1=Cr(13579BDF)=CrO
116
117
	paddw	xmm4,xmm7
118
	paddw	xmm5,xmm7
119
	paddw	xmm0,xmm7
120
	paddw	xmm1,xmm7
121
122
	; (Original)
123
	; R = Y                + 1.40200 * Cr
124
	; G = Y - 0.34414 * Cb - 0.71414 * Cr
125
	; B = Y + 1.77200 * Cb
126
	;
127
	; (This implementation)
128
	; R = Y                + 0.40200 * Cr + Cr
129
	; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
130
	; B = Y - 0.22800 * Cb + Cb + Cb
131
132
	movdqa	xmm2,xmm4		; xmm2=CbE
133
	movdqa	xmm3,xmm5		; xmm3=CbO
134
	paddw	xmm4,xmm4		; xmm4=2*CbE
135
	paddw	xmm5,xmm5		; xmm5=2*CbO
136
	movdqa	xmm6,xmm0		; xmm6=CrE
137
	movdqa	xmm7,xmm1		; xmm7=CrO
138
	paddw	xmm0,xmm0		; xmm0=2*CrE
139
	paddw	xmm1,xmm1		; xmm1=2*CrO
140
141
	pmulhw	xmm4,[GOTOFF(eax,PW_MF0228)]	; xmm4=(2*CbE * -FIX(0.22800))
142
	pmulhw	xmm5,[GOTOFF(eax,PW_MF0228)]	; xmm5=(2*CbO * -FIX(0.22800))
143
	pmulhw	xmm0,[GOTOFF(eax,PW_F0402)]	; xmm0=(2*CrE * FIX(0.40200))
144
	pmulhw	xmm1,[GOTOFF(eax,PW_F0402)]	; xmm1=(2*CrO * FIX(0.40200))
145
146
	paddw	xmm4,[GOTOFF(eax,PW_ONE)]
147
	paddw	xmm5,[GOTOFF(eax,PW_ONE)]
148
	psraw	xmm4,1			; xmm4=(CbE * -FIX(0.22800))
149
	psraw	xmm5,1			; xmm5=(CbO * -FIX(0.22800))
150
	paddw	xmm0,[GOTOFF(eax,PW_ONE)]
151
	paddw	xmm1,[GOTOFF(eax,PW_ONE)]
152
	psraw	xmm0,1			; xmm0=(CrE * FIX(0.40200))
153
	psraw	xmm1,1			; xmm1=(CrO * FIX(0.40200))
154
155
	paddw	xmm4,xmm2
156
	paddw	xmm5,xmm3
157
	paddw	xmm4,xmm2		; xmm4=(CbE * FIX(1.77200))=(B-Y)E
158
	paddw	xmm5,xmm3		; xmm5=(CbO * FIX(1.77200))=(B-Y)O
159
	paddw	xmm0,xmm6		; xmm0=(CrE * FIX(1.40200))=(R-Y)E
160
	paddw	xmm1,xmm7		; xmm1=(CrO * FIX(1.40200))=(R-Y)O
161
162
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=(B-Y)E
163
	movdqa	XMMWORD [wk(1)], xmm5	; wk(1)=(B-Y)O
164
165
	movdqa    xmm4,xmm2
166
	movdqa    xmm5,xmm3
167
	punpcklwd xmm2,xmm6
168
	punpckhwd xmm4,xmm6
169
	pmaddwd   xmm2,[GOTOFF(eax,PW_MF0344_F0285)]
170
	pmaddwd   xmm4,[GOTOFF(eax,PW_MF0344_F0285)]
171
	punpcklwd xmm3,xmm7
172
	punpckhwd xmm5,xmm7
173
	pmaddwd   xmm3,[GOTOFF(eax,PW_MF0344_F0285)]
174
	pmaddwd   xmm5,[GOTOFF(eax,PW_MF0344_F0285)]
175
176
	paddd     xmm2,[GOTOFF(eax,PD_ONEHALF)]
177
	paddd     xmm4,[GOTOFF(eax,PD_ONEHALF)]
178
	psrad     xmm2,SCALEBITS
179
	psrad     xmm4,SCALEBITS
180
	paddd     xmm3,[GOTOFF(eax,PD_ONEHALF)]
181
	paddd     xmm5,[GOTOFF(eax,PD_ONEHALF)]
182
	psrad     xmm3,SCALEBITS
183
	psrad     xmm5,SCALEBITS
184
185
	packssdw  xmm2,xmm4	; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
186
	packssdw  xmm3,xmm5	; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
187
	psubw     xmm2,xmm6	; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
188
	psubw     xmm3,xmm7	; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
189
190
	movdqa    xmm5, XMMWORD [esi]	; xmm5=Y(0123456789ABCDEF)
191
192
	pcmpeqw   xmm4,xmm4
193
	psrlw     xmm4,BYTE_BIT		; xmm4={0xFF 0x00 0xFF 0x00 ..}
194
	pand      xmm4,xmm5		; xmm4=Y(02468ACE)=YE
195
	psrlw     xmm5,BYTE_BIT		; xmm5=Y(13579BDF)=YO
196
197
	paddw     xmm0,xmm4		; xmm0=((R-Y)E+YE)=RE=R(02468ACE)
198
	paddw     xmm1,xmm5		; xmm1=((R-Y)O+YO)=RO=R(13579BDF)
199
	packuswb  xmm0,xmm0		; xmm0=R(02468ACE********)
200
	packuswb  xmm1,xmm1		; xmm1=R(13579BDF********)
201
202
	paddw     xmm2,xmm4		; xmm2=((G-Y)E+YE)=GE=G(02468ACE)
203
	paddw     xmm3,xmm5		; xmm3=((G-Y)O+YO)=GO=G(13579BDF)
204
	packuswb  xmm2,xmm2		; xmm2=G(02468ACE********)
205
	packuswb  xmm3,xmm3		; xmm3=G(13579BDF********)
206
207
	paddw     xmm4, XMMWORD [wk(0)]	; xmm4=(YE+(B-Y)E)=BE=B(02468ACE)
208
	paddw     xmm5, XMMWORD [wk(1)]	; xmm5=(YO+(B-Y)O)=BO=B(13579BDF)
209
	packuswb  xmm4,xmm4		; xmm4=B(02468ACE********)
210
	packuswb  xmm5,xmm5		; xmm5=B(13579BDF********)
211
212
%if RGB_PIXELSIZE == 3 ; ---------------
213
214
	; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
215
	; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
216
	; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
217
	; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
218
219
	punpcklbw xmmA,xmmC	; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
220
	punpcklbw xmmE,xmmB	; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
221
	punpcklbw xmmD,xmmF	; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
222
223
	movdqa    xmmG,xmmA
224
	movdqa    xmmH,xmmA
225
	punpcklwd xmmA,xmmE	; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
226
	punpckhwd xmmG,xmmE	; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
227
228
	psrldq    xmmH,2	; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
229
	psrldq    xmmE,2	; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
230
231
	movdqa    xmmC,xmmD
232
	movdqa    xmmB,xmmD
233
	punpcklwd xmmD,xmmH	; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
234
	punpckhwd xmmC,xmmH	; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
235
236
	psrldq    xmmB,2	; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
237
238
	movdqa    xmmF,xmmE
239
	punpcklwd xmmE,xmmB	; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
240
	punpckhwd xmmF,xmmB	; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
241
242
	pshufd    xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
243
	movdqa    xmmB,xmmE
244
	punpckldq xmmA,xmmD	; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
245
	punpckldq xmmE,xmmH	; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
246
	punpckhdq xmmD,xmmB	; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
247
248
	pshufd    xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
249
	movdqa    xmmB,xmmF
250
	punpckldq xmmG,xmmC	; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
251
	punpckldq xmmF,xmmH	; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
252
	punpckhdq xmmC,xmmB	; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
253
254
	punpcklqdq xmmA,xmmE	; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
255
	punpcklqdq xmmD,xmmG	; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
256
	punpcklqdq xmmF,xmmC	; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
257
258
	cmp	ecx, byte SIZEOF_XMMWORD
259
	jb	short .column_st32
260
261
	test	edi, SIZEOF_XMMWORD-1
262
	jnz	short .out1
263
	; --(aligned)-------------------
264
	movntdq	XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
265
	movntdq	XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
266
	movntdq	XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF
267
	add	edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; outptr
268
	jmp	short .out0
269
.out1:	; --(unaligned)-----------------
270
	pcmpeqb    xmmH,xmmH			; xmmH=(all 1's)
271
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [edi], xmmA
272
	add	edi, byte SIZEOF_XMMWORD	; outptr
273
	maskmovdqu xmmD,xmmH			; movntdqu XMMWORD [edi], xmmD
274
	add	edi, byte SIZEOF_XMMWORD	; outptr
275
	maskmovdqu xmmF,xmmH			; movntdqu XMMWORD [edi], xmmF
276
	add	edi, byte SIZEOF_XMMWORD	; outptr
277
.out0:
278
	sub	ecx, byte SIZEOF_XMMWORD
279
	jz	near .nextrow
280
281
	add	esi, byte SIZEOF_XMMWORD	; inptr0
282
	add	ebx, byte SIZEOF_XMMWORD	; inptr1
283
	add	edx, byte SIZEOF_XMMWORD	; inptr2
284
	jmp	near .columnloop
285
	alignx	16,7
286
287
.column_st32:
288
	pcmpeqb	xmmH,xmmH			; xmmH=(all 1's)
289
	lea	ecx, [ecx+ecx*2]		; imul ecx, RGB_PIXELSIZE
290
	cmp	ecx, byte 2*SIZEOF_XMMWORD
291
	jb	short .column_st16
292
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [edi], xmmA
293
	add	edi, byte SIZEOF_XMMWORD	; outptr
294
	maskmovdqu xmmD,xmmH			; movntdqu XMMWORD [edi], xmmD
295
	add	edi, byte SIZEOF_XMMWORD	; outptr
296
	movdqa	xmmA,xmmF
297
	sub	ecx, byte 2*SIZEOF_XMMWORD
298
	jmp	short .column_st15
299
.column_st16:
300
	cmp	ecx, byte SIZEOF_XMMWORD
301
	jb	short .column_st15
302
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [edi], xmmA
303
	add	edi, byte SIZEOF_XMMWORD	; outptr
304
	movdqa	xmmA,xmmD
305
	sub	ecx, byte SIZEOF_XMMWORD
306
.column_st15:
307
	mov	eax,ecx
308
	xor	ecx, byte 0x0F
309
	shl	ecx, 2
310
	movd	xmmB,ecx
311
	psrlq	xmmH,4
312
	pcmpeqb	xmmE,xmmE
313
	psrlq	xmmH,xmmB
314
	psrlq	xmmE,xmmB
315
	punpcklbw xmmE,xmmH
316
	; ----------------
317
	mov	ecx,edi
318
	and	ecx, byte SIZEOF_XMMWORD-1
319
	jz	short .adj0
320
	add	eax,ecx
321
	cmp	eax, byte SIZEOF_XMMWORD
322
	ja	short .adj0
323
	and	edi, byte (-SIZEOF_XMMWORD)	; align to 16-byte boundary
324
	shl	ecx, 3			; pslldq xmmA,ecx & pslldq xmmE,ecx
325
	movdqa	xmmG,xmmA
326
	movdqa	xmmC,xmmE
327
	pslldq	xmmA, SIZEOF_XMMWORD/2
328
	pslldq	xmmE, SIZEOF_XMMWORD/2
329
	movd	xmmD,ecx
330
	sub	ecx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT
331
	jb	short .adj1
332
	movd	xmmF,ecx
333
	psllq	xmmA,xmmF
334
	psllq	xmmE,xmmF
335
	jmp	short .adj0
336
.adj1:	neg	ecx
337
	movd	xmmF,ecx
338
	psrlq	xmmA,xmmF
339
	psrlq	xmmE,xmmF
340
	psllq	xmmG,xmmD
341
	psllq	xmmC,xmmD
342
	por	xmmA,xmmG
343
	por	xmmE,xmmC
344
.adj0:	; ----------------
345
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
346
347
%else ; RGB_PIXELSIZE == 4 ; -----------
348
349
%ifdef RGBX_FILLER_0XFF
350
	pcmpeqb   xmm6,xmm6		; xmm6=XE=X(02468ACE********)
351
	pcmpeqb   xmm7,xmm7		; xmm7=XO=X(13579BDF********)
352
%else
353
	pxor      xmm6,xmm6		; xmm6=XE=X(02468ACE********)
354
	pxor      xmm7,xmm7		; xmm7=XO=X(13579BDF********)
355
%endif
356
	; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
357
	; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
358
	; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
359
	; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
360
361
	punpcklbw xmmA,xmmC	; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
362
	punpcklbw xmmE,xmmG	; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
363
	punpcklbw xmmB,xmmD	; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
364
	punpcklbw xmmF,xmmH	; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
365
366
	movdqa    xmmC,xmmA
367
	punpcklwd xmmA,xmmE	; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
368
	punpckhwd xmmC,xmmE	; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
369
	movdqa    xmmG,xmmB
370
	punpcklwd xmmB,xmmF	; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
371
	punpckhwd xmmG,xmmF	; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
372
373
	movdqa    xmmD,xmmA
374
	punpckldq xmmA,xmmB	; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
375
	punpckhdq xmmD,xmmB	; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
376
	movdqa    xmmH,xmmC
377
	punpckldq xmmC,xmmG	; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
378
	punpckhdq xmmH,xmmG	; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
379
380
	cmp	ecx, byte SIZEOF_XMMWORD
381
	jb	short .column_st32
382
383
	test	edi, SIZEOF_XMMWORD-1
384
	jnz	short .out1
385
	; --(aligned)-------------------
386
	movntdq	XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
387
	movntdq	XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
388
	movntdq	XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC
389
	movntdq	XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH
390
	add	edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; outptr
391
	jmp	short .out0
392
.out1:	; --(unaligned)-----------------
393
	pcmpeqb    xmmE,xmmE			; xmmE=(all 1's)
394
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
395
	add	edi, byte SIZEOF_XMMWORD	; outptr
396
	maskmovdqu xmmD,xmmE			; movntdqu XMMWORD [edi], xmmD
397
	add	edi, byte SIZEOF_XMMWORD	; outptr
398
	maskmovdqu xmmC,xmmE			; movntdqu XMMWORD [edi], xmmC
399
	add	edi, byte SIZEOF_XMMWORD	; outptr
400
	maskmovdqu xmmH,xmmE			; movntdqu XMMWORD [edi], xmmH
401
	add	edi, byte SIZEOF_XMMWORD	; outptr
402
.out0:
403
	sub	ecx, byte SIZEOF_XMMWORD
404
	jz	near .nextrow
405
406
	add	esi, byte SIZEOF_XMMWORD	; inptr0
407
	add	ebx, byte SIZEOF_XMMWORD	; inptr1
408
	add	edx, byte SIZEOF_XMMWORD	; inptr2
409
	jmp	near .columnloop
410
	alignx	16,7
411
412
.column_st32:
413
	pcmpeqb	xmmE,xmmE			; xmmE=(all 1's)
414
	cmp	ecx, byte SIZEOF_XMMWORD/2
415
	jb	short .column_st16
416
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
417
	add	edi, byte SIZEOF_XMMWORD	; outptr
418
	maskmovdqu xmmD,xmmE			; movntdqu XMMWORD [edi], xmmD
419
	add	edi, byte SIZEOF_XMMWORD	; outptr
420
	movdqa	xmmA,xmmC
421
	movdqa	xmmD,xmmH
422
	sub	ecx, byte SIZEOF_XMMWORD/2
423
.column_st16:
424
	cmp	ecx, byte SIZEOF_XMMWORD/4
425
	jb	short .column_st15
426
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
427
	add	edi, byte SIZEOF_XMMWORD	; outptr
428
	movdqa	xmmA,xmmD
429
	sub	ecx, byte SIZEOF_XMMWORD/4
430
.column_st15:
431
	cmp	ecx, byte SIZEOF_XMMWORD/16
432
	jb	short .nextrow
433
	mov	eax,ecx
434
	xor	ecx, byte 0x03
435
	inc	ecx
436
	shl	ecx, 4
437
	movd	xmmF,ecx
438
	psrlq	xmmE,xmmF
439
	punpcklbw xmmE,xmmE
440
	; ----------------
441
	mov	ecx,edi
442
	and	ecx, byte SIZEOF_XMMWORD-1
443
	jz	short .adj0
444
	lea	eax, [ecx+eax*4]	; RGB_PIXELSIZE
445
	cmp	eax, byte SIZEOF_XMMWORD
446
	ja	short .adj0
447
	and	edi, byte (-SIZEOF_XMMWORD)	; align to 16-byte boundary
448
	shl	ecx, 3			; pslldq xmmA,ecx & pslldq xmmE,ecx
449
	movdqa	xmmB,xmmA
450
	movdqa	xmmG,xmmE
451
	pslldq	xmmA, SIZEOF_XMMWORD/2
452
	pslldq	xmmE, SIZEOF_XMMWORD/2
453
	movd	xmmC,ecx
454
	sub	ecx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT
455
	jb	short .adj1
456
	movd	xmmH,ecx
457
	psllq	xmmA,xmmH
458
	psllq	xmmE,xmmH
459
	jmp	short .adj0
460
.adj1:	neg	ecx
461
	movd	xmmH,ecx
462
	psrlq	xmmA,xmmH
463
	psrlq	xmmE,xmmH
464
	psllq	xmmB,xmmC
465
	psllq	xmmG,xmmC
466
	por	xmmA,xmmB
467
	por	xmmE,xmmG
468
.adj0:	; ----------------
469
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
470
471
%endif ; RGB_PIXELSIZE ; ---------------
472
473
	alignx	16,7
474
475
.nextrow:
476
	pop	ecx
477
	pop	esi
478
	pop	ebx
479
	pop	edx
480
	pop	edi
481
	pop	eax
482
483
	add	esi, byte SIZEOF_JSAMPROW
484
	add	ebx, byte SIZEOF_JSAMPROW
485
	add	edx, byte SIZEOF_JSAMPROW
486
	add	edi, byte SIZEOF_JSAMPROW	; output_buf
487
	dec	eax				; num_rows
488
	jg	near .rowloop
489
490
	sfence		; flush the write buffer
491
492
.return:
493
	pop	edi
494
	pop	esi
495
;	pop	edx		; need not be preserved
496
;	pop	ecx		; need not be preserved
497
	pop	ebx
498
	mov	esp,ebp		; esp <- aligned ebp
499
	pop	esp		; esp <- original ebp
500
	pop	ebp
501
	ret
502
503
; For some reason, the OS X linker does not honor the request to align the
504
; segment unless we do this.
505
	align	16
(-)a/jpeg/simd/jdcolmmx.asm (+117 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdcolmmx.asm - colorspace conversion (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
22
; --------------------------------------------------------------------------
23
24
%define SCALEBITS	16
25
26
F_0_344	equ	 22554			; FIX(0.34414)
27
F_0_714	equ	 46802			; FIX(0.71414)
28
F_1_402	equ	 91881			; FIX(1.40200)
29
F_1_772	equ	116130			; FIX(1.77200)
30
F_0_402	equ	(F_1_402 - 65536)	; FIX(1.40200) - FIX(1)
31
F_0_285	equ	( 65536 - F_0_714)	; FIX(1) - FIX(0.71414)
32
F_0_228	equ	(131072 - F_1_772)	; FIX(2) - FIX(1.77200)
33
34
; --------------------------------------------------------------------------
35
	SECTION	SEG_CONST
36
37
	alignz	16
38
	global	EXTN(jconst_ycc_rgb_convert_mmx)
39
40
EXTN(jconst_ycc_rgb_convert_mmx):
41
42
PW_F0402	times 4 dw  F_0_402
43
PW_MF0228	times 4 dw -F_0_228
44
PW_MF0344_F0285	times 2 dw -F_0_344, F_0_285
45
PW_ONE		times 4 dw  1
46
PD_ONEHALF	times 2 dd  1 << (SCALEBITS-1)
47
48
	alignz	16
49
50
; --------------------------------------------------------------------------
51
%include "jdclrmmx.asm"
52
53
%undef RGB_RED
54
%undef RGB_GREEN
55
%undef RGB_BLUE
56
%undef RGB_PIXELSIZE
57
%define RGB_RED 0
58
%define RGB_GREEN 1
59
%define RGB_BLUE 2
60
%define RGB_PIXELSIZE 3
61
%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extrgb_convert_mmx
62
%include "jdclrmmx.asm"
63
64
%undef RGB_RED
65
%undef RGB_GREEN
66
%undef RGB_BLUE
67
%undef RGB_PIXELSIZE
68
%define RGB_RED 0
69
%define RGB_GREEN 1
70
%define RGB_BLUE 2
71
%define RGB_PIXELSIZE 4
72
%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extrgbx_convert_mmx
73
%include "jdclrmmx.asm"
74
75
%undef RGB_RED
76
%undef RGB_GREEN
77
%undef RGB_BLUE
78
%undef RGB_PIXELSIZE
79
%define RGB_RED 2
80
%define RGB_GREEN 1
81
%define RGB_BLUE 0
82
%define RGB_PIXELSIZE 3
83
%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extbgr_convert_mmx
84
%include "jdclrmmx.asm"
85
86
%undef RGB_RED
87
%undef RGB_GREEN
88
%undef RGB_BLUE
89
%undef RGB_PIXELSIZE
90
%define RGB_RED 2
91
%define RGB_GREEN 1
92
%define RGB_BLUE 0
93
%define RGB_PIXELSIZE 4
94
%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extbgrx_convert_mmx
95
%include "jdclrmmx.asm"
96
97
%undef RGB_RED
98
%undef RGB_GREEN
99
%undef RGB_BLUE
100
%undef RGB_PIXELSIZE
101
%define RGB_RED 3
102
%define RGB_GREEN 2
103
%define RGB_BLUE 1
104
%define RGB_PIXELSIZE 4
105
%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extxbgr_convert_mmx
106
%include "jdclrmmx.asm"
107
108
%undef RGB_RED
109
%undef RGB_GREEN
110
%undef RGB_BLUE
111
%undef RGB_PIXELSIZE
112
%define RGB_RED 1
113
%define RGB_GREEN 2
114
%define RGB_BLUE 3
115
%define RGB_PIXELSIZE 4
116
%define jsimd_ycc_rgb_convert_mmx jsimd_ycc_extxrgb_convert_mmx
117
%include "jdclrmmx.asm"
(-)a/jpeg/simd/jdcolss2-64.asm (+117 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdcolss2-64.asm - colorspace conversion (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
22
; --------------------------------------------------------------------------
23
24
%define SCALEBITS	16
25
26
F_0_344	equ	 22554			; FIX(0.34414)
27
F_0_714	equ	 46802			; FIX(0.71414)
28
F_1_402	equ	 91881			; FIX(1.40200)
29
F_1_772	equ	116130			; FIX(1.77200)
30
F_0_402	equ	(F_1_402 - 65536)	; FIX(1.40200) - FIX(1)
31
F_0_285	equ	( 65536 - F_0_714)	; FIX(1) - FIX(0.71414)
32
F_0_228	equ	(131072 - F_1_772)	; FIX(2) - FIX(1.77200)
33
34
; --------------------------------------------------------------------------
35
	SECTION	SEG_CONST
36
37
	alignz	16
38
	global	EXTN(jconst_ycc_rgb_convert_sse2)
39
40
EXTN(jconst_ycc_rgb_convert_sse2):
41
42
PW_F0402	times 8 dw  F_0_402
43
PW_MF0228	times 8 dw -F_0_228
44
PW_MF0344_F0285	times 4 dw -F_0_344, F_0_285
45
PW_ONE		times 8 dw  1
46
PD_ONEHALF	times 4 dd  1 << (SCALEBITS-1)
47
48
	alignz	16
49
50
; --------------------------------------------------------------------------
51
%include "jdclrss2-64.asm"
52
53
%undef RGB_RED
54
%undef RGB_GREEN
55
%undef RGB_BLUE
56
%undef RGB_PIXELSIZE
57
%define RGB_RED 0
58
%define RGB_GREEN 1
59
%define RGB_BLUE 2
60
%define RGB_PIXELSIZE 3
61
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgb_convert_sse2
62
%include "jdclrss2-64.asm"
63
64
%undef RGB_RED
65
%undef RGB_GREEN
66
%undef RGB_BLUE
67
%undef RGB_PIXELSIZE
68
%define RGB_RED 0
69
%define RGB_GREEN 1
70
%define RGB_BLUE 2
71
%define RGB_PIXELSIZE 4
72
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgbx_convert_sse2
73
%include "jdclrss2-64.asm"
74
75
%undef RGB_RED
76
%undef RGB_GREEN
77
%undef RGB_BLUE
78
%undef RGB_PIXELSIZE
79
%define RGB_RED 2
80
%define RGB_GREEN 1
81
%define RGB_BLUE 0
82
%define RGB_PIXELSIZE 3
83
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgr_convert_sse2
84
%include "jdclrss2-64.asm"
85
86
%undef RGB_RED
87
%undef RGB_GREEN
88
%undef RGB_BLUE
89
%undef RGB_PIXELSIZE
90
%define RGB_RED 2
91
%define RGB_GREEN 1
92
%define RGB_BLUE 0
93
%define RGB_PIXELSIZE 4
94
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgrx_convert_sse2
95
%include "jdclrss2-64.asm"
96
97
%undef RGB_RED
98
%undef RGB_GREEN
99
%undef RGB_BLUE
100
%undef RGB_PIXELSIZE
101
%define RGB_RED 3
102
%define RGB_GREEN 2
103
%define RGB_BLUE 1
104
%define RGB_PIXELSIZE 4
105
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxbgr_convert_sse2
106
%include "jdclrss2-64.asm"
107
108
%undef RGB_RED
109
%undef RGB_GREEN
110
%undef RGB_BLUE
111
%undef RGB_PIXELSIZE
112
%define RGB_RED 1
113
%define RGB_GREEN 2
114
%define RGB_BLUE 3
115
%define RGB_PIXELSIZE 4
116
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxrgb_convert_sse2
117
%include "jdclrss2-64.asm"
(-)a/jpeg/simd/jdcolss2.asm (+117 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdcolss2.asm - colorspace conversion (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
22
; --------------------------------------------------------------------------
23
24
%define SCALEBITS	16
25
26
F_0_344	equ	 22554			; FIX(0.34414)
27
F_0_714	equ	 46802			; FIX(0.71414)
28
F_1_402	equ	 91881			; FIX(1.40200)
29
F_1_772	equ	116130			; FIX(1.77200)
30
F_0_402	equ	(F_1_402 - 65536)	; FIX(1.40200) - FIX(1)
31
F_0_285	equ	( 65536 - F_0_714)	; FIX(1) - FIX(0.71414)
32
F_0_228	equ	(131072 - F_1_772)	; FIX(2) - FIX(1.77200)
33
34
; --------------------------------------------------------------------------
35
	SECTION	SEG_CONST
36
37
	alignz	16
38
	global	EXTN(jconst_ycc_rgb_convert_sse2)
39
40
EXTN(jconst_ycc_rgb_convert_sse2):
41
42
PW_F0402	times 8 dw  F_0_402
43
PW_MF0228	times 8 dw -F_0_228
44
PW_MF0344_F0285	times 4 dw -F_0_344, F_0_285
45
PW_ONE		times 8 dw  1
46
PD_ONEHALF	times 4 dd  1 << (SCALEBITS-1)
47
48
	alignz	16
49
50
; --------------------------------------------------------------------------
51
%include "jdclrss2.asm"
52
53
%undef RGB_RED
54
%undef RGB_GREEN
55
%undef RGB_BLUE
56
%undef RGB_PIXELSIZE
57
%define RGB_RED 0
58
%define RGB_GREEN 1
59
%define RGB_BLUE 2
60
%define RGB_PIXELSIZE 3
61
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgb_convert_sse2
62
%include "jdclrss2.asm"
63
64
%undef RGB_RED
65
%undef RGB_GREEN
66
%undef RGB_BLUE
67
%undef RGB_PIXELSIZE
68
%define RGB_RED 0
69
%define RGB_GREEN 1
70
%define RGB_BLUE 2
71
%define RGB_PIXELSIZE 4
72
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extrgbx_convert_sse2
73
%include "jdclrss2.asm"
74
75
%undef RGB_RED
76
%undef RGB_GREEN
77
%undef RGB_BLUE
78
%undef RGB_PIXELSIZE
79
%define RGB_RED 2
80
%define RGB_GREEN 1
81
%define RGB_BLUE 0
82
%define RGB_PIXELSIZE 3
83
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgr_convert_sse2
84
%include "jdclrss2.asm"
85
86
%undef RGB_RED
87
%undef RGB_GREEN
88
%undef RGB_BLUE
89
%undef RGB_PIXELSIZE
90
%define RGB_RED 2
91
%define RGB_GREEN 1
92
%define RGB_BLUE 0
93
%define RGB_PIXELSIZE 4
94
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extbgrx_convert_sse2
95
%include "jdclrss2.asm"
96
97
%undef RGB_RED
98
%undef RGB_GREEN
99
%undef RGB_BLUE
100
%undef RGB_PIXELSIZE
101
%define RGB_RED 3
102
%define RGB_GREEN 2
103
%define RGB_BLUE 1
104
%define RGB_PIXELSIZE 4
105
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxbgr_convert_sse2
106
%include "jdclrss2.asm"
107
108
%undef RGB_RED
109
%undef RGB_GREEN
110
%undef RGB_BLUE
111
%undef RGB_PIXELSIZE
112
%define RGB_RED 1
113
%define RGB_GREEN 2
114
%define RGB_BLUE 3
115
%define RGB_PIXELSIZE 4
116
%define jsimd_ycc_rgb_convert_sse2 jsimd_ycc_extxrgb_convert_sse2
117
%include "jdclrss2.asm"
(-)a/jpeg/simd/jdct.inc (+28 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdct.inc - private declarations for forward & reverse DCT subsystems
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; [TAB8]
12
13
; Each IDCT routine is responsible for range-limiting its results and
14
; converting them to unsigned form (0..MAXJSAMPLE).  The raw outputs could
15
; be quite far out of range if the input data is corrupt, so a bulletproof
16
; range-limiting step is required.  We use a mask-and-table-lookup method
17
; to do the combined operations quickly.
18
;
19
%define RANGE_MASK  (MAXJSAMPLE * 4 + 3)  ; 2 bits wider than legal samples
20
21
%define ROW(n,b,s)		((b)+(n)*(s))
22
%define COL(n,b,s)		((b)+(n)*(s)*DCTSIZE)
23
24
%define DWBLOCK(m,n,b,s)	((b)+(m)*DCTSIZE*(s)+(n)*SIZEOF_DWORD)
25
%define MMBLOCK(m,n,b,s)	((b)+(m)*DCTSIZE*(s)+(n)*SIZEOF_MMWORD)
26
%define XMMBLOCK(m,n,b,s)	((b)+(m)*DCTSIZE*(s)+(n)*SIZEOF_XMMWORD)
27
28
; --------------------------------------------------------------------------
(-)a/jpeg/simd/jdmermmx.asm (+123 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdmermmx.asm - merged upsampling/color conversion (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
22
; --------------------------------------------------------------------------
23
24
%define SCALEBITS	16
25
26
F_0_344	equ	 22554			; FIX(0.34414)
27
F_0_714	equ	 46802			; FIX(0.71414)
28
F_1_402	equ	 91881			; FIX(1.40200)
29
F_1_772	equ	116130			; FIX(1.77200)
30
F_0_402	equ	(F_1_402 - 65536)	; FIX(1.40200) - FIX(1)
31
F_0_285	equ	( 65536 - F_0_714)	; FIX(1) - FIX(0.71414)
32
F_0_228	equ	(131072 - F_1_772)	; FIX(2) - FIX(1.77200)
33
34
; --------------------------------------------------------------------------
35
	SECTION	SEG_CONST
36
37
	alignz	16
38
	global	EXTN(jconst_merged_upsample_mmx)
39
40
EXTN(jconst_merged_upsample_mmx):
41
42
PW_F0402	times 4 dw  F_0_402
43
PW_MF0228	times 4 dw -F_0_228
44
PW_MF0344_F0285	times 2 dw -F_0_344, F_0_285
45
PW_ONE		times 4 dw  1
46
PD_ONEHALF	times 2 dd  1 << (SCALEBITS-1)
47
48
	alignz	16
49
50
; --------------------------------------------------------------------------
51
%include "jdmrgmmx.asm"
52
53
%undef RGB_RED
54
%undef RGB_GREEN
55
%undef RGB_BLUE
56
%undef RGB_PIXELSIZE
57
%define RGB_RED 0
58
%define RGB_GREEN 1
59
%define RGB_BLUE 2
60
%define RGB_PIXELSIZE 3
61
%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extrgb_merged_upsample_mmx
62
%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extrgb_merged_upsample_mmx
63
%include "jdmrgmmx.asm"
64
65
%undef RGB_RED
66
%undef RGB_GREEN
67
%undef RGB_BLUE
68
%undef RGB_PIXELSIZE
69
%define RGB_RED 0
70
%define RGB_GREEN 1
71
%define RGB_BLUE 2
72
%define RGB_PIXELSIZE 4
73
%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extrgbx_merged_upsample_mmx
74
%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extrgbx_merged_upsample_mmx
75
%include "jdmrgmmx.asm"
76
77
%undef RGB_RED
78
%undef RGB_GREEN
79
%undef RGB_BLUE
80
%undef RGB_PIXELSIZE
81
%define RGB_RED 2
82
%define RGB_GREEN 1
83
%define RGB_BLUE 0
84
%define RGB_PIXELSIZE 3
85
%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extbgr_merged_upsample_mmx
86
%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extbgr_merged_upsample_mmx
87
%include "jdmrgmmx.asm"
88
89
%undef RGB_RED
90
%undef RGB_GREEN
91
%undef RGB_BLUE
92
%undef RGB_PIXELSIZE
93
%define RGB_RED 2
94
%define RGB_GREEN 1
95
%define RGB_BLUE 0
96
%define RGB_PIXELSIZE 4
97
%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extbgrx_merged_upsample_mmx
98
%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extbgrx_merged_upsample_mmx
99
%include "jdmrgmmx.asm"
100
101
%undef RGB_RED
102
%undef RGB_GREEN
103
%undef RGB_BLUE
104
%undef RGB_PIXELSIZE
105
%define RGB_RED 3
106
%define RGB_GREEN 2
107
%define RGB_BLUE 1
108
%define RGB_PIXELSIZE 4
109
%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extxbgr_merged_upsample_mmx
110
%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extxbgr_merged_upsample_mmx
111
%include "jdmrgmmx.asm"
112
113
%undef RGB_RED
114
%undef RGB_GREEN
115
%undef RGB_BLUE
116
%undef RGB_PIXELSIZE
117
%define RGB_RED 1
118
%define RGB_GREEN 2
119
%define RGB_BLUE 3
120
%define RGB_PIXELSIZE 4
121
%define jsimd_h2v1_merged_upsample_mmx jsimd_h2v1_extxrgb_merged_upsample_mmx
122
%define jsimd_h2v2_merged_upsample_mmx jsimd_h2v2_extxrgb_merged_upsample_mmx
123
%include "jdmrgmmx.asm"
(-)a/jpeg/simd/jdmerss2-64.asm (+123 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdmerss2-64.asm - merged upsampling/color conversion (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
22
; --------------------------------------------------------------------------
23
24
%define SCALEBITS	16
25
26
F_0_344	equ	 22554			; FIX(0.34414)
27
F_0_714	equ	 46802			; FIX(0.71414)
28
F_1_402	equ	 91881			; FIX(1.40200)
29
F_1_772	equ	116130			; FIX(1.77200)
30
F_0_402	equ	(F_1_402 - 65536)	; FIX(1.40200) - FIX(1)
31
F_0_285	equ	( 65536 - F_0_714)	; FIX(1) - FIX(0.71414)
32
F_0_228	equ	(131072 - F_1_772)	; FIX(2) - FIX(1.77200)
33
34
; --------------------------------------------------------------------------
35
	SECTION	SEG_CONST
36
37
	alignz	16
38
	global	EXTN(jconst_merged_upsample_sse2)
39
40
EXTN(jconst_merged_upsample_sse2):
41
42
PW_F0402	times 8 dw  F_0_402
43
PW_MF0228	times 8 dw -F_0_228
44
PW_MF0344_F0285	times 4 dw -F_0_344, F_0_285
45
PW_ONE		times 8 dw  1
46
PD_ONEHALF	times 4 dd  1 << (SCALEBITS-1)
47
48
	alignz	16
49
50
; --------------------------------------------------------------------------
51
%include "jdmrgss2-64.asm"
52
53
%undef RGB_RED
54
%undef RGB_GREEN
55
%undef RGB_BLUE
56
%undef RGB_PIXELSIZE
57
%define RGB_RED 0
58
%define RGB_GREEN 1
59
%define RGB_BLUE 2
60
%define RGB_PIXELSIZE 3
61
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgb_merged_upsample_sse2
62
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgb_merged_upsample_sse2
63
%include "jdmrgss2-64.asm"
64
65
%undef RGB_RED
66
%undef RGB_GREEN
67
%undef RGB_BLUE
68
%undef RGB_PIXELSIZE
69
%define RGB_RED 0
70
%define RGB_GREEN 1
71
%define RGB_BLUE 2
72
%define RGB_PIXELSIZE 4
73
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgbx_merged_upsample_sse2
74
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgbx_merged_upsample_sse2
75
%include "jdmrgss2-64.asm"
76
77
%undef RGB_RED
78
%undef RGB_GREEN
79
%undef RGB_BLUE
80
%undef RGB_PIXELSIZE
81
%define RGB_RED 2
82
%define RGB_GREEN 1
83
%define RGB_BLUE 0
84
%define RGB_PIXELSIZE 3
85
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgr_merged_upsample_sse2
86
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgr_merged_upsample_sse2
87
%include "jdmrgss2-64.asm"
88
89
%undef RGB_RED
90
%undef RGB_GREEN
91
%undef RGB_BLUE
92
%undef RGB_PIXELSIZE
93
%define RGB_RED 2
94
%define RGB_GREEN 1
95
%define RGB_BLUE 0
96
%define RGB_PIXELSIZE 4
97
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgrx_merged_upsample_sse2
98
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgrx_merged_upsample_sse2
99
%include "jdmrgss2-64.asm"
100
101
%undef RGB_RED
102
%undef RGB_GREEN
103
%undef RGB_BLUE
104
%undef RGB_PIXELSIZE
105
%define RGB_RED 3
106
%define RGB_GREEN 2
107
%define RGB_BLUE 1
108
%define RGB_PIXELSIZE 4
109
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxbgr_merged_upsample_sse2
110
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxbgr_merged_upsample_sse2
111
%include "jdmrgss2-64.asm"
112
113
%undef RGB_RED
114
%undef RGB_GREEN
115
%undef RGB_BLUE
116
%undef RGB_PIXELSIZE
117
%define RGB_RED 1
118
%define RGB_GREEN 2
119
%define RGB_BLUE 3
120
%define RGB_PIXELSIZE 4
121
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxrgb_merged_upsample_sse2
122
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxrgb_merged_upsample_sse2
123
%include "jdmrgss2-64.asm"
(-)a/jpeg/simd/jdmerss2.asm (+123 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdmerss2.asm - merged upsampling/color conversion (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
22
; --------------------------------------------------------------------------
23
24
%define SCALEBITS	16
25
26
F_0_344	equ	 22554			; FIX(0.34414)
27
F_0_714	equ	 46802			; FIX(0.71414)
28
F_1_402	equ	 91881			; FIX(1.40200)
29
F_1_772	equ	116130			; FIX(1.77200)
30
F_0_402	equ	(F_1_402 - 65536)	; FIX(1.40200) - FIX(1)
31
F_0_285	equ	( 65536 - F_0_714)	; FIX(1) - FIX(0.71414)
32
F_0_228	equ	(131072 - F_1_772)	; FIX(2) - FIX(1.77200)
33
34
; --------------------------------------------------------------------------
35
	SECTION	SEG_CONST
36
37
	alignz	16
38
	global	EXTN(jconst_merged_upsample_sse2)
39
40
EXTN(jconst_merged_upsample_sse2):
41
42
PW_F0402	times 8 dw  F_0_402
43
PW_MF0228	times 8 dw -F_0_228
44
PW_MF0344_F0285	times 4 dw -F_0_344, F_0_285
45
PW_ONE		times 8 dw  1
46
PD_ONEHALF	times 4 dd  1 << (SCALEBITS-1)
47
48
	alignz	16
49
50
; --------------------------------------------------------------------------
51
%include "jdmrgss2.asm"
52
53
%undef RGB_RED
54
%undef RGB_GREEN
55
%undef RGB_BLUE
56
%undef RGB_PIXELSIZE
57
%define RGB_RED 0
58
%define RGB_GREEN 1
59
%define RGB_BLUE 2
60
%define RGB_PIXELSIZE 3
61
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgb_merged_upsample_sse2
62
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgb_merged_upsample_sse2
63
%include "jdmrgss2.asm"
64
65
%undef RGB_RED
66
%undef RGB_GREEN
67
%undef RGB_BLUE
68
%undef RGB_PIXELSIZE
69
%define RGB_RED 0
70
%define RGB_GREEN 1
71
%define RGB_BLUE 2
72
%define RGB_PIXELSIZE 4
73
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extrgbx_merged_upsample_sse2
74
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extrgbx_merged_upsample_sse2
75
%include "jdmrgss2.asm"
76
77
%undef RGB_RED
78
%undef RGB_GREEN
79
%undef RGB_BLUE
80
%undef RGB_PIXELSIZE
81
%define RGB_RED 2
82
%define RGB_GREEN 1
83
%define RGB_BLUE 0
84
%define RGB_PIXELSIZE 3
85
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgr_merged_upsample_sse2
86
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgr_merged_upsample_sse2
87
%include "jdmrgss2.asm"
88
89
%undef RGB_RED
90
%undef RGB_GREEN
91
%undef RGB_BLUE
92
%undef RGB_PIXELSIZE
93
%define RGB_RED 2
94
%define RGB_GREEN 1
95
%define RGB_BLUE 0
96
%define RGB_PIXELSIZE 4
97
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extbgrx_merged_upsample_sse2
98
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extbgrx_merged_upsample_sse2
99
%include "jdmrgss2.asm"
100
101
%undef RGB_RED
102
%undef RGB_GREEN
103
%undef RGB_BLUE
104
%undef RGB_PIXELSIZE
105
%define RGB_RED 3
106
%define RGB_GREEN 2
107
%define RGB_BLUE 1
108
%define RGB_PIXELSIZE 4
109
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxbgr_merged_upsample_sse2
110
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxbgr_merged_upsample_sse2
111
%include "jdmrgss2.asm"
112
113
%undef RGB_RED
114
%undef RGB_GREEN
115
%undef RGB_BLUE
116
%undef RGB_PIXELSIZE
117
%define RGB_RED 1
118
%define RGB_GREEN 2
119
%define RGB_BLUE 3
120
%define RGB_PIXELSIZE 4
121
%define jsimd_h2v1_merged_upsample_sse2 jsimd_h2v1_extxrgb_merged_upsample_sse2
122
%define jsimd_h2v2_merged_upsample_sse2 jsimd_h2v2_extxrgb_merged_upsample_sse2
123
%include "jdmrgss2.asm"
(-)a/jpeg/simd/jdmrgmmx.asm (+466 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdmrgmmx.asm - merged upsampling/color conversion (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jcolsamp.inc"
20
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_TEXT
23
	BITS	32
24
;
25
; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
26
;
27
; GLOBAL(void)
28
; jsimd_h2v1_merged_upsample_mmx (JDIMENSION output_width,
29
;                                 JSAMPIMAGE input_buf,
30
;                                 JDIMENSION in_row_group_ctr,
31
;                                 JSAMPARRAY output_buf);
32
;
33
34
%define output_width(b)	(b)+8			; JDIMENSION output_width
35
%define input_buf(b)		(b)+12		; JSAMPIMAGE input_buf
36
%define in_row_group_ctr(b)	(b)+16		; JDIMENSION in_row_group_ctr
37
%define output_buf(b)		(b)+20		; JSAMPARRAY output_buf
38
39
%define original_ebp	ebp+0
40
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
41
%define WK_NUM		3
42
%define gotptr		wk(0)-SIZEOF_POINTER	; void * gotptr
43
44
	align	16
45
	global	EXTN(jsimd_h2v1_merged_upsample_mmx)
46
47
EXTN(jsimd_h2v1_merged_upsample_mmx):
48
	push	ebp
49
	mov	eax,esp				; eax = original ebp
50
	sub	esp, byte 4
51
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
52
	mov	[esp],eax
53
	mov	ebp,esp				; ebp = aligned ebp
54
	lea	esp, [wk(0)]
55
	pushpic	eax		; make a room for GOT address
56
	push	ebx
57
;	push	ecx		; need not be preserved
58
;	push	edx		; need not be preserved
59
	push	esi
60
	push	edi
61
62
	get_GOT	ebx			; get GOT address
63
	movpic	POINTER [gotptr], ebx	; save GOT address
64
65
	mov	ecx, JDIMENSION [output_width(eax)]	; col
66
	test	ecx,ecx
67
	jz	near .return
68
69
	push	ecx
70
71
	mov	edi, JSAMPIMAGE [input_buf(eax)]
72
	mov	ecx, JDIMENSION [in_row_group_ctr(eax)]
73
	mov	esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
74
	mov	ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
75
	mov	edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
76
	mov	edi, JSAMPARRAY [output_buf(eax)]
77
	mov	esi, JSAMPROW [esi+ecx*SIZEOF_JSAMPROW]		; inptr0
78
	mov	ebx, JSAMPROW [ebx+ecx*SIZEOF_JSAMPROW]		; inptr1
79
	mov	edx, JSAMPROW [edx+ecx*SIZEOF_JSAMPROW]		; inptr2
80
	mov	edi, JSAMPROW [edi]				; outptr
81
82
	pop	ecx			; col
83
84
	alignx	16,7
85
.columnloop:
86
	movpic	eax, POINTER [gotptr]	; load GOT address (eax)
87
88
	movq      mm6, MMWORD [ebx]	; mm6=Cb(01234567)
89
	movq      mm7, MMWORD [edx]	; mm7=Cr(01234567)
90
91
	pxor      mm1,mm1		; mm1=(all 0's)
92
	pcmpeqw   mm3,mm3
93
	psllw     mm3,7			; mm3={0xFF80 0xFF80 0xFF80 0xFF80}
94
95
	movq      mm4,mm6
96
	punpckhbw mm6,mm1		; mm6=Cb(4567)=CbH
97
	punpcklbw mm4,mm1		; mm4=Cb(0123)=CbL
98
	movq      mm0,mm7
99
	punpckhbw mm7,mm1		; mm7=Cr(4567)=CrH
100
	punpcklbw mm0,mm1		; mm0=Cr(0123)=CrL
101
102
	paddw     mm6,mm3
103
	paddw     mm4,mm3
104
	paddw     mm7,mm3
105
	paddw     mm0,mm3
106
107
	; (Original)
108
	; R = Y                + 1.40200 * Cr
109
	; G = Y - 0.34414 * Cb - 0.71414 * Cr
110
	; B = Y + 1.77200 * Cb
111
	;
112
	; (This implementation)
113
	; R = Y                + 0.40200 * Cr + Cr
114
	; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
115
	; B = Y - 0.22800 * Cb + Cb + Cb
116
117
	movq	mm5,mm6			; mm5=CbH
118
	movq	mm2,mm4			; mm2=CbL
119
	paddw	mm6,mm6			; mm6=2*CbH
120
	paddw	mm4,mm4			; mm4=2*CbL
121
	movq	mm1,mm7			; mm1=CrH
122
	movq	mm3,mm0			; mm3=CrL
123
	paddw	mm7,mm7			; mm7=2*CrH
124
	paddw	mm0,mm0			; mm0=2*CrL
125
126
	pmulhw	mm6,[GOTOFF(eax,PW_MF0228)]	; mm6=(2*CbH * -FIX(0.22800))
127
	pmulhw	mm4,[GOTOFF(eax,PW_MF0228)]	; mm4=(2*CbL * -FIX(0.22800))
128
	pmulhw	mm7,[GOTOFF(eax,PW_F0402)]	; mm7=(2*CrH * FIX(0.40200))
129
	pmulhw	mm0,[GOTOFF(eax,PW_F0402)]	; mm0=(2*CrL * FIX(0.40200))
130
131
	paddw	mm6,[GOTOFF(eax,PW_ONE)]
132
	paddw	mm4,[GOTOFF(eax,PW_ONE)]
133
	psraw	mm6,1			; mm6=(CbH * -FIX(0.22800))
134
	psraw	mm4,1			; mm4=(CbL * -FIX(0.22800))
135
	paddw	mm7,[GOTOFF(eax,PW_ONE)]
136
	paddw	mm0,[GOTOFF(eax,PW_ONE)]
137
	psraw	mm7,1			; mm7=(CrH * FIX(0.40200))
138
	psraw	mm0,1			; mm0=(CrL * FIX(0.40200))
139
140
	paddw	mm6,mm5
141
	paddw	mm4,mm2
142
	paddw	mm6,mm5			; mm6=(CbH * FIX(1.77200))=(B-Y)H
143
	paddw	mm4,mm2			; mm4=(CbL * FIX(1.77200))=(B-Y)L
144
	paddw	mm7,mm1			; mm7=(CrH * FIX(1.40200))=(R-Y)H
145
	paddw	mm0,mm3			; mm0=(CrL * FIX(1.40200))=(R-Y)L
146
147
	movq	MMWORD [wk(0)], mm6	; wk(0)=(B-Y)H
148
	movq	MMWORD [wk(1)], mm7	; wk(1)=(R-Y)H
149
150
	movq      mm6,mm5
151
	movq      mm7,mm2
152
	punpcklwd mm5,mm1
153
	punpckhwd mm6,mm1
154
	pmaddwd   mm5,[GOTOFF(eax,PW_MF0344_F0285)]
155
	pmaddwd   mm6,[GOTOFF(eax,PW_MF0344_F0285)]
156
	punpcklwd mm2,mm3
157
	punpckhwd mm7,mm3
158
	pmaddwd   mm2,[GOTOFF(eax,PW_MF0344_F0285)]
159
	pmaddwd   mm7,[GOTOFF(eax,PW_MF0344_F0285)]
160
161
	paddd     mm5,[GOTOFF(eax,PD_ONEHALF)]
162
	paddd     mm6,[GOTOFF(eax,PD_ONEHALF)]
163
	psrad     mm5,SCALEBITS
164
	psrad     mm6,SCALEBITS
165
	paddd     mm2,[GOTOFF(eax,PD_ONEHALF)]
166
	paddd     mm7,[GOTOFF(eax,PD_ONEHALF)]
167
	psrad     mm2,SCALEBITS
168
	psrad     mm7,SCALEBITS
169
170
	packssdw  mm5,mm6	; mm5=CbH*-FIX(0.344)+CrH*FIX(0.285)
171
	packssdw  mm2,mm7	; mm2=CbL*-FIX(0.344)+CrL*FIX(0.285)
172
	psubw     mm5,mm1	; mm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H
173
	psubw     mm2,mm3	; mm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L
174
175
	movq	MMWORD [wk(2)], mm5	; wk(2)=(G-Y)H
176
177
	mov	al,2			; Yctr
178
	jmp	short .Yloop_1st
179
	alignx	16,7
180
181
.Yloop_2nd:
182
	movq	mm0, MMWORD [wk(1)]	; mm0=(R-Y)H
183
	movq	mm2, MMWORD [wk(2)]	; mm2=(G-Y)H
184
	movq	mm4, MMWORD [wk(0)]	; mm4=(B-Y)H
185
	alignx	16,7
186
187
.Yloop_1st:
188
	movq	mm7, MMWORD [esi]	; mm7=Y(01234567)
189
190
	pcmpeqw	mm6,mm6
191
	psrlw	mm6,BYTE_BIT		; mm6={0xFF 0x00 0xFF 0x00 ..}
192
	pand	mm6,mm7			; mm6=Y(0246)=YE
193
	psrlw	mm7,BYTE_BIT		; mm7=Y(1357)=YO
194
195
	movq	mm1,mm0			; mm1=mm0=(R-Y)(L/H)
196
	movq	mm3,mm2			; mm3=mm2=(G-Y)(L/H)
197
	movq	mm5,mm4			; mm5=mm4=(B-Y)(L/H)
198
199
	paddw     mm0,mm6		; mm0=((R-Y)+YE)=RE=(R0 R2 R4 R6)
200
	paddw     mm1,mm7		; mm1=((R-Y)+YO)=RO=(R1 R3 R5 R7)
201
	packuswb  mm0,mm0		; mm0=(R0 R2 R4 R6 ** ** ** **)
202
	packuswb  mm1,mm1		; mm1=(R1 R3 R5 R7 ** ** ** **)
203
204
	paddw     mm2,mm6		; mm2=((G-Y)+YE)=GE=(G0 G2 G4 G6)
205
	paddw     mm3,mm7		; mm3=((G-Y)+YO)=GO=(G1 G3 G5 G7)
206
	packuswb  mm2,mm2		; mm2=(G0 G2 G4 G6 ** ** ** **)
207
	packuswb  mm3,mm3		; mm3=(G1 G3 G5 G7 ** ** ** **)
208
209
	paddw     mm4,mm6		; mm4=((B-Y)+YE)=BE=(B0 B2 B4 B6)
210
	paddw     mm5,mm7		; mm5=((B-Y)+YO)=BO=(B1 B3 B5 B7)
211
	packuswb  mm4,mm4		; mm4=(B0 B2 B4 B6 ** ** ** **)
212
	packuswb  mm5,mm5		; mm5=(B1 B3 B5 B7 ** ** ** **)
213
214
%if RGB_PIXELSIZE == 3 ; ---------------
215
216
	; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **)
217
	; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **)
218
	; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **)
219
	; mmG=(** ** ** ** ** ** ** **), mmH=(** ** ** ** ** ** ** **)
220
221
	punpcklbw mmA,mmC		; mmA=(00 10 02 12 04 14 06 16)
222
	punpcklbw mmE,mmB		; mmE=(20 01 22 03 24 05 26 07)
223
	punpcklbw mmD,mmF		; mmD=(11 21 13 23 15 25 17 27)
224
225
	movq      mmG,mmA
226
	movq      mmH,mmA
227
	punpcklwd mmA,mmE		; mmA=(00 10 20 01 02 12 22 03)
228
	punpckhwd mmG,mmE		; mmG=(04 14 24 05 06 16 26 07)
229
230
	psrlq     mmH,2*BYTE_BIT	; mmH=(02 12 04 14 06 16 -- --)
231
	psrlq     mmE,2*BYTE_BIT	; mmE=(22 03 24 05 26 07 -- --)
232
233
	movq      mmC,mmD
234
	movq      mmB,mmD
235
	punpcklwd mmD,mmH		; mmD=(11 21 02 12 13 23 04 14)
236
	punpckhwd mmC,mmH		; mmC=(15 25 06 16 17 27 -- --)
237
238
	psrlq     mmB,2*BYTE_BIT	; mmB=(13 23 15 25 17 27 -- --)
239
240
	movq      mmF,mmE
241
	punpcklwd mmE,mmB		; mmE=(22 03 13 23 24 05 15 25)
242
	punpckhwd mmF,mmB		; mmF=(26 07 17 27 -- -- -- --)
243
244
	punpckldq mmA,mmD		; mmA=(00 10 20 01 11 21 02 12)
245
	punpckldq mmE,mmG		; mmE=(22 03 13 23 04 14 24 05)
246
	punpckldq mmC,mmF		; mmC=(15 25 06 16 26 07 17 27)
247
248
	cmp	ecx, byte SIZEOF_MMWORD
249
	jb	short .column_st16
250
251
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
252
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mmE
253
	movq	MMWORD [edi+2*SIZEOF_MMWORD], mmC
254
255
	sub	ecx, byte SIZEOF_MMWORD
256
	jz	near .endcolumn
257
258
	add	edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD	; outptr
259
	add	esi, byte SIZEOF_MMWORD			; inptr0
260
	dec	al			; Yctr
261
	jnz	near .Yloop_2nd
262
263
	add	ebx, byte SIZEOF_MMWORD			; inptr1
264
	add	edx, byte SIZEOF_MMWORD			; inptr2
265
	jmp	near .columnloop
266
	alignx	16,7
267
268
.column_st16:
269
	lea	ecx, [ecx+ecx*2]	; imul ecx, RGB_PIXELSIZE
270
	cmp	ecx, byte 2*SIZEOF_MMWORD
271
	jb	short .column_st8
272
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
273
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mmE
274
	movq	mmA,mmC
275
	sub	ecx, byte 2*SIZEOF_MMWORD
276
	add	edi, byte 2*SIZEOF_MMWORD
277
	jmp	short .column_st4
278
.column_st8:
279
	cmp	ecx, byte SIZEOF_MMWORD
280
	jb	short .column_st4
281
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
282
	movq	mmA,mmE
283
	sub	ecx, byte SIZEOF_MMWORD
284
	add	edi, byte SIZEOF_MMWORD
285
.column_st4:
286
	movd	eax,mmA
287
	cmp	ecx, byte SIZEOF_DWORD
288
	jb	short .column_st2
289
	mov	DWORD [edi+0*SIZEOF_DWORD], eax
290
	psrlq	mmA,DWORD_BIT
291
	movd	eax,mmA
292
	sub	ecx, byte SIZEOF_DWORD
293
	add	edi, byte SIZEOF_DWORD
294
.column_st2:
295
	cmp	ecx, byte SIZEOF_WORD
296
	jb	short .column_st1
297
	mov	WORD [edi+0*SIZEOF_WORD], ax
298
	shr	eax,WORD_BIT
299
	sub	ecx, byte SIZEOF_WORD
300
	add	edi, byte SIZEOF_WORD
301
.column_st1:
302
	cmp	ecx, byte SIZEOF_BYTE
303
	jb	short .endcolumn
304
	mov	BYTE [edi+0*SIZEOF_BYTE], al
305
306
%else ; RGB_PIXELSIZE == 4 ; -----------
307
308
%ifdef RGBX_FILLER_0XFF
309
	pcmpeqb   mm6,mm6		; mm6=(X0 X2 X4 X6 ** ** ** **)
310
	pcmpeqb   mm7,mm7		; mm7=(X1 X3 X5 X7 ** ** ** **)
311
%else
312
	pxor      mm6,mm6		; mm6=(X0 X2 X4 X6 ** ** ** **)
313
	pxor      mm7,mm7		; mm7=(X1 X3 X5 X7 ** ** ** **)
314
%endif
315
	; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **)
316
	; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **)
317
	; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **)
318
	; mmG=(30 32 34 36 ** ** ** **), mmH=(31 33 35 37 ** ** ** **)
319
320
	punpcklbw mmA,mmC		; mmA=(00 10 02 12 04 14 06 16)
321
	punpcklbw mmE,mmG		; mmE=(20 30 22 32 24 34 26 36)
322
	punpcklbw mmB,mmD		; mmB=(01 11 03 13 05 15 07 17)
323
	punpcklbw mmF,mmH		; mmF=(21 31 23 33 25 35 27 37)
324
325
	movq      mmC,mmA
326
	punpcklwd mmA,mmE		; mmA=(00 10 20 30 02 12 22 32)
327
	punpckhwd mmC,mmE		; mmC=(04 14 24 34 06 16 26 36)
328
	movq      mmG,mmB
329
	punpcklwd mmB,mmF		; mmB=(01 11 21 31 03 13 23 33)
330
	punpckhwd mmG,mmF		; mmG=(05 15 25 35 07 17 27 37)
331
332
	movq      mmD,mmA
333
	punpckldq mmA,mmB		; mmA=(00 10 20 30 01 11 21 31)
334
	punpckhdq mmD,mmB		; mmD=(02 12 22 32 03 13 23 33)
335
	movq      mmH,mmC
336
	punpckldq mmC,mmG		; mmC=(04 14 24 34 05 15 25 35)
337
	punpckhdq mmH,mmG		; mmH=(06 16 26 36 07 17 27 37)
338
339
	cmp	ecx, byte SIZEOF_MMWORD
340
	jb	short .column_st16
341
342
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
343
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mmD
344
	movq	MMWORD [edi+2*SIZEOF_MMWORD], mmC
345
	movq	MMWORD [edi+3*SIZEOF_MMWORD], mmH
346
347
	sub	ecx, byte SIZEOF_MMWORD
348
	jz	short .endcolumn
349
350
	add	edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD	; outptr
351
	add	esi, byte SIZEOF_MMWORD			; inptr0
352
	dec	al			; Yctr
353
	jnz	near .Yloop_2nd
354
355
	add	ebx, byte SIZEOF_MMWORD			; inptr1
356
	add	edx, byte SIZEOF_MMWORD			; inptr2
357
	jmp	near .columnloop
358
	alignx	16,7
359
360
.column_st16:
361
	cmp	ecx, byte SIZEOF_MMWORD/2
362
	jb	short .column_st8
363
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
364
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mmD
365
	movq	mmA,mmC
366
	movq	mmD,mmH
367
	sub	ecx, byte SIZEOF_MMWORD/2
368
	add	edi, byte 2*SIZEOF_MMWORD
369
.column_st8:
370
	cmp	ecx, byte SIZEOF_MMWORD/4
371
	jb	short .column_st4
372
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mmA
373
	movq	mmA,mmD
374
	sub	ecx, byte SIZEOF_MMWORD/4
375
	add	edi, byte 1*SIZEOF_MMWORD
376
.column_st4:
377
	cmp	ecx, byte SIZEOF_MMWORD/8
378
	jb	short .endcolumn
379
	movd	DWORD [edi+0*SIZEOF_DWORD], mmA
380
381
%endif ; RGB_PIXELSIZE ; ---------------
382
383
.endcolumn:
384
	emms		; empty MMX state
385
386
.return:
387
	pop	edi
388
	pop	esi
389
;	pop	edx		; need not be preserved
390
;	pop	ecx		; need not be preserved
391
	pop	ebx
392
	mov	esp,ebp		; esp <- aligned ebp
393
	pop	esp		; esp <- original ebp
394
	pop	ebp
395
	ret
396
397
; --------------------------------------------------------------------------
398
;
399
; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
400
;
401
; GLOBAL(void)
402
; jsimd_h2v2_merged_upsample_mmx (JDIMENSION output_width,
403
;                                 JSAMPIMAGE input_buf,
404
;                                 JDIMENSION in_row_group_ctr,
405
;                                 JSAMPARRAY output_buf);
406
;
407
408
%define output_width(b)	(b)+8			; JDIMENSION output_width
409
%define input_buf(b)		(b)+12		; JSAMPIMAGE input_buf
410
%define in_row_group_ctr(b)	(b)+16		; JDIMENSION in_row_group_ctr
411
%define output_buf(b)		(b)+20		; JSAMPARRAY output_buf
412
413
	align	16
414
	global	EXTN(jsimd_h2v2_merged_upsample_mmx)
415
416
EXTN(jsimd_h2v2_merged_upsample_mmx):
417
	push	ebp
418
	mov	ebp,esp
419
	push	ebx
420
;	push	ecx		; need not be preserved
421
;	push	edx		; need not be preserved
422
	push	esi
423
	push	edi
424
425
	mov	eax, JDIMENSION [output_width(ebp)]
426
427
	mov	edi, JSAMPIMAGE [input_buf(ebp)]
428
	mov	ecx, JDIMENSION [in_row_group_ctr(ebp)]
429
	mov	esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
430
	mov	ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
431
	mov	edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
432
	mov	edi, JSAMPARRAY [output_buf(ebp)]
433
	lea	esi, [esi+ecx*SIZEOF_JSAMPROW]
434
435
	push	edx			; inptr2
436
	push	ebx			; inptr1
437
	push	esi			; inptr00
438
	mov	ebx,esp
439
440
	push	edi			; output_buf (outptr0)
441
	push	ecx			; in_row_group_ctr
442
	push	ebx			; input_buf
443
	push	eax			; output_width
444
445
	call	near EXTN(jsimd_h2v1_merged_upsample_mmx)
446
447
	add	esi, byte SIZEOF_JSAMPROW	; inptr01
448
	add	edi, byte SIZEOF_JSAMPROW	; outptr1
449
	mov	POINTER [ebx+0*SIZEOF_POINTER], esi
450
	mov	POINTER [ebx-1*SIZEOF_POINTER], edi
451
452
	call	near EXTN(jsimd_h2v1_merged_upsample_mmx)
453
454
	add	esp, byte 7*SIZEOF_DWORD
455
456
	pop	edi
457
	pop	esi
458
;	pop	edx		; need not be preserved
459
;	pop	ecx		; need not be preserved
460
	pop	ebx
461
	pop	ebp
462
	ret
463
464
; For some reason, the OS X linker does not honor the request to align the
465
; segment unless we do this.
466
	align	16
(-)a/jpeg/simd/jdmrgss2-64.asm (+584 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdmrgss2-64.asm - merged upsampling/color conversion (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ for
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jcolsamp.inc"
21
				
22
; --------------------------------------------------------------------------
23
	SECTION	SEG_TEXT
24
	BITS	64
25
;
26
; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
27
;
28
; GLOBAL(void)
29
; jsimd_h2v1_merged_upsample_sse2 (JDIMENSION output_width,
30
;                                  JSAMPIMAGE input_buf,
31
;                                  JDIMENSION in_row_group_ctr,
32
;                                  JSAMPARRAY output_buf);
33
;
34
35
; r10 = JDIMENSION output_width
36
; r11 = JSAMPIMAGE input_buf
37
; r12 = JDIMENSION in_row_group_ctr
38
; r13 = JSAMPARRAY output_buf
39
40
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
41
%define WK_NUM		3
42
43
	align	16
44
	global	EXTN(jsimd_h2v1_merged_upsample_sse2)
45
46
EXTN(jsimd_h2v1_merged_upsample_sse2):
47
	push	rbp
48
	mov	rax,rsp				; rax = original rbp
49
	sub	rsp, byte 4
50
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
51
	mov	[rsp],rax
52
	mov	rbp,rsp				; rbp = aligned rbp
53
	lea	rsp, [wk(0)]
54
	collect_args
55
	push	rbx
56
57
	mov	rcx, r10	; col
58
	test	rcx,rcx
59
	jz	near .return
60
61
	push	rcx
62
63
	mov	rdi, r11
64
	mov	rcx, r12
65
	mov	rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
66
	mov	rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
67
	mov	rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
68
	mov	rdi, r13
69
	mov	rsi, JSAMPROW [rsi+rcx*SIZEOF_JSAMPROW]		; inptr0
70
	mov	rbx, JSAMPROW [rbx+rcx*SIZEOF_JSAMPROW]		; inptr1
71
	mov	rdx, JSAMPROW [rdx+rcx*SIZEOF_JSAMPROW]		; inptr2
72
	mov	rdi, JSAMPROW [rdi]				; outptr
73
74
	pop	rcx			; col
75
76
.columnloop:
77
78
	movdqa    xmm6, XMMWORD [rbx]	; xmm6=Cb(0123456789ABCDEF)
79
	movdqa    xmm7, XMMWORD [rdx]	; xmm7=Cr(0123456789ABCDEF)
80
81
	pxor      xmm1,xmm1		; xmm1=(all 0's)
82
	pcmpeqw   xmm3,xmm3
83
	psllw     xmm3,7		; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..}
84
85
	movdqa    xmm4,xmm6
86
	punpckhbw xmm6,xmm1		; xmm6=Cb(89ABCDEF)=CbH
87
	punpcklbw xmm4,xmm1		; xmm4=Cb(01234567)=CbL
88
	movdqa    xmm0,xmm7
89
	punpckhbw xmm7,xmm1		; xmm7=Cr(89ABCDEF)=CrH
90
	punpcklbw xmm0,xmm1		; xmm0=Cr(01234567)=CrL
91
92
	paddw     xmm6,xmm3
93
	paddw     xmm4,xmm3
94
	paddw     xmm7,xmm3
95
	paddw     xmm0,xmm3
96
97
	; (Original)
98
	; R = Y                + 1.40200 * Cr
99
	; G = Y - 0.34414 * Cb - 0.71414 * Cr
100
	; B = Y + 1.77200 * Cb
101
	;
102
	; (This implementation)
103
	; R = Y                + 0.40200 * Cr + Cr
104
	; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
105
	; B = Y - 0.22800 * Cb + Cb + Cb
106
107
	movdqa	xmm5,xmm6		; xmm5=CbH
108
	movdqa	xmm2,xmm4		; xmm2=CbL
109
	paddw	xmm6,xmm6		; xmm6=2*CbH
110
	paddw	xmm4,xmm4		; xmm4=2*CbL
111
	movdqa	xmm1,xmm7		; xmm1=CrH
112
	movdqa	xmm3,xmm0		; xmm3=CrL
113
	paddw	xmm7,xmm7		; xmm7=2*CrH
114
	paddw	xmm0,xmm0		; xmm0=2*CrL
115
116
	pmulhw	xmm6,[rel PW_MF0228]	; xmm6=(2*CbH * -FIX(0.22800))
117
	pmulhw	xmm4,[rel PW_MF0228]	; xmm4=(2*CbL * -FIX(0.22800))
118
	pmulhw	xmm7,[rel PW_F0402]	; xmm7=(2*CrH * FIX(0.40200))
119
	pmulhw	xmm0,[rel PW_F0402]	; xmm0=(2*CrL * FIX(0.40200))
120
121
	paddw	xmm6,[rel PW_ONE]
122
	paddw	xmm4,[rel PW_ONE]
123
	psraw	xmm6,1			; xmm6=(CbH * -FIX(0.22800))
124
	psraw	xmm4,1			; xmm4=(CbL * -FIX(0.22800))
125
	paddw	xmm7,[rel PW_ONE]
126
	paddw	xmm0,[rel PW_ONE]
127
	psraw	xmm7,1			; xmm7=(CrH * FIX(0.40200))
128
	psraw	xmm0,1			; xmm0=(CrL * FIX(0.40200))
129
130
	paddw	xmm6,xmm5
131
	paddw	xmm4,xmm2
132
	paddw	xmm6,xmm5		; xmm6=(CbH * FIX(1.77200))=(B-Y)H
133
	paddw	xmm4,xmm2		; xmm4=(CbL * FIX(1.77200))=(B-Y)L
134
	paddw	xmm7,xmm1		; xmm7=(CrH * FIX(1.40200))=(R-Y)H
135
	paddw	xmm0,xmm3		; xmm0=(CrL * FIX(1.40200))=(R-Y)L
136
137
	movdqa	XMMWORD [wk(0)], xmm6	; wk(0)=(B-Y)H
138
	movdqa	XMMWORD [wk(1)], xmm7	; wk(1)=(R-Y)H
139
140
	movdqa    xmm6,xmm5
141
	movdqa    xmm7,xmm2
142
	punpcklwd xmm5,xmm1
143
	punpckhwd xmm6,xmm1
144
	pmaddwd   xmm5,[rel PW_MF0344_F0285]
145
	pmaddwd   xmm6,[rel PW_MF0344_F0285]
146
	punpcklwd xmm2,xmm3
147
	punpckhwd xmm7,xmm3
148
	pmaddwd   xmm2,[rel PW_MF0344_F0285]
149
	pmaddwd   xmm7,[rel PW_MF0344_F0285]
150
151
	paddd     xmm5,[rel PD_ONEHALF]
152
	paddd     xmm6,[rel PD_ONEHALF]
153
	psrad     xmm5,SCALEBITS
154
	psrad     xmm6,SCALEBITS
155
	paddd     xmm2,[rel PD_ONEHALF]
156
	paddd     xmm7,[rel PD_ONEHALF]
157
	psrad     xmm2,SCALEBITS
158
	psrad     xmm7,SCALEBITS
159
160
	packssdw  xmm5,xmm6	; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285)
161
	packssdw  xmm2,xmm7	; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285)
162
	psubw     xmm5,xmm1	; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H
163
	psubw     xmm2,xmm3	; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L
164
165
	movdqa	XMMWORD [wk(2)], xmm5	; wk(2)=(G-Y)H
166
167
	mov	al,2			; Yctr
168
	jmp	short .Yloop_1st
169
170
.Yloop_2nd:
171
	movdqa	xmm0, XMMWORD [wk(1)]	; xmm0=(R-Y)H
172
	movdqa	xmm2, XMMWORD [wk(2)]	; xmm2=(G-Y)H
173
	movdqa	xmm4, XMMWORD [wk(0)]	; xmm4=(B-Y)H
174
175
.Yloop_1st:
176
	movdqa	xmm7, XMMWORD [rsi]	; xmm7=Y(0123456789ABCDEF)
177
178
	pcmpeqw	xmm6,xmm6
179
	psrlw	xmm6,BYTE_BIT		; xmm6={0xFF 0x00 0xFF 0x00 ..}
180
	pand	xmm6,xmm7		; xmm6=Y(02468ACE)=YE
181
	psrlw	xmm7,BYTE_BIT		; xmm7=Y(13579BDF)=YO
182
183
	movdqa	xmm1,xmm0		; xmm1=xmm0=(R-Y)(L/H)
184
	movdqa	xmm3,xmm2		; xmm3=xmm2=(G-Y)(L/H)
185
	movdqa	xmm5,xmm4		; xmm5=xmm4=(B-Y)(L/H)
186
187
	paddw     xmm0,xmm6		; xmm0=((R-Y)+YE)=RE=R(02468ACE)
188
	paddw     xmm1,xmm7		; xmm1=((R-Y)+YO)=RO=R(13579BDF)
189
	packuswb  xmm0,xmm0		; xmm0=R(02468ACE********)
190
	packuswb  xmm1,xmm1		; xmm1=R(13579BDF********)
191
192
	paddw     xmm2,xmm6		; xmm2=((G-Y)+YE)=GE=G(02468ACE)
193
	paddw     xmm3,xmm7		; xmm3=((G-Y)+YO)=GO=G(13579BDF)
194
	packuswb  xmm2,xmm2		; xmm2=G(02468ACE********)
195
	packuswb  xmm3,xmm3		; xmm3=G(13579BDF********)
196
197
	paddw     xmm4,xmm6		; xmm4=((B-Y)+YE)=BE=B(02468ACE)
198
	paddw     xmm5,xmm7		; xmm5=((B-Y)+YO)=BO=B(13579BDF)
199
	packuswb  xmm4,xmm4		; xmm4=B(02468ACE********)
200
	packuswb  xmm5,xmm5		; xmm5=B(13579BDF********)
201
202
%if RGB_PIXELSIZE == 3 ; ---------------
203
204
	; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
205
	; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
206
	; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
207
	; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
208
209
	punpcklbw xmmA,xmmC	; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
210
	punpcklbw xmmE,xmmB	; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
211
	punpcklbw xmmD,xmmF	; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
212
213
	movdqa    xmmG,xmmA
214
	movdqa    xmmH,xmmA
215
	punpcklwd xmmA,xmmE	; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
216
	punpckhwd xmmG,xmmE	; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
217
218
	psrldq    xmmH,2	; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
219
	psrldq    xmmE,2	; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
220
221
	movdqa    xmmC,xmmD
222
	movdqa    xmmB,xmmD
223
	punpcklwd xmmD,xmmH	; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
224
	punpckhwd xmmC,xmmH	; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
225
226
	psrldq    xmmB,2	; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
227
228
	movdqa    xmmF,xmmE
229
	punpcklwd xmmE,xmmB	; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
230
	punpckhwd xmmF,xmmB	; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
231
232
	pshufd    xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
233
	movdqa    xmmB,xmmE
234
	punpckldq xmmA,xmmD	; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
235
	punpckldq xmmE,xmmH	; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
236
	punpckhdq xmmD,xmmB	; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
237
238
	pshufd    xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
239
	movdqa    xmmB,xmmF
240
	punpckldq xmmG,xmmC	; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
241
	punpckldq xmmF,xmmH	; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
242
	punpckhdq xmmC,xmmB	; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
243
244
	punpcklqdq xmmA,xmmE	; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
245
	punpcklqdq xmmD,xmmG	; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
246
	punpcklqdq xmmF,xmmC	; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
247
248
	cmp	rcx, byte SIZEOF_XMMWORD
249
	jb	short .column_st32
250
251
	test	rdi, SIZEOF_XMMWORD-1
252
	jnz	short .out1
253
	; --(aligned)-------------------
254
	movntdq	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
255
	movntdq	XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
256
	movntdq	XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
257
	add	rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; outptr
258
	jmp	short .out0
259
.out1:	; --(unaligned)-----------------
260
	pcmpeqb    xmmH,xmmH			; xmmH=(all 1's)
261
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [rdi], xmmA
262
	add	rdi, byte SIZEOF_XMMWORD	; outptr
263
	maskmovdqu xmmD,xmmH			; movntdqu XMMWORD [rdi], xmmD
264
	add	rdi, byte SIZEOF_XMMWORD	; outptr
265
	maskmovdqu xmmF,xmmH			; movntdqu XMMWORD [rdi], xmmF
266
	add	rdi, byte SIZEOF_XMMWORD	; outptr
267
.out0:
268
	sub	rcx, byte SIZEOF_XMMWORD
269
	jz	near .endcolumn
270
271
	add	rsi, byte SIZEOF_XMMWORD	; inptr0
272
	dec	al			; Yctr
273
	jnz	near .Yloop_2nd
274
275
	add	rbx, byte SIZEOF_XMMWORD	; inptr1
276
	add	rdx, byte SIZEOF_XMMWORD	; inptr2
277
	jmp	near .columnloop
278
279
.column_st32:
280
	pcmpeqb	xmmH,xmmH			; xmmH=(all 1's)
281
	lea	rcx, [rcx+rcx*2]		; imul ecx, RGB_PIXELSIZE
282
	cmp	rcx, byte 2*SIZEOF_XMMWORD
283
	jb	short .column_st16
284
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [rdi], xmmA
285
	add	rdi, byte SIZEOF_XMMWORD	; outptr
286
	maskmovdqu xmmD,xmmH			; movntdqu XMMWORD [rdi], xmmD
287
	add	rdi, byte SIZEOF_XMMWORD	; outptr
288
	movdqa	xmmA,xmmF
289
	sub	rcx, byte 2*SIZEOF_XMMWORD
290
	jmp	short .column_st15
291
.column_st16:
292
	cmp	rcx, byte SIZEOF_XMMWORD
293
	jb	short .column_st15
294
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [rdi], xmmA
295
	add	rdi, byte SIZEOF_XMMWORD	; outptr
296
	movdqa	xmmA,xmmD
297
	sub	rcx, byte SIZEOF_XMMWORD
298
.column_st15:
299
	mov	rax,rcx
300
	xor	rcx, byte 0x0F
301
	shl	rcx, 2
302
	movd	xmmB,ecx
303
	psrlq	xmmH,4
304
	pcmpeqb	xmmE,xmmE
305
	psrlq	xmmH,xmmB
306
	psrlq	xmmE,xmmB
307
	punpcklbw xmmE,xmmH
308
	; ----------------
309
	mov	rcx,rdi
310
	and	rcx, byte SIZEOF_XMMWORD-1
311
	jz	short .adj0
312
	add	rax,rcx
313
	cmp	rax, byte SIZEOF_XMMWORD
314
	ja	short .adj0
315
	and	rdi, byte (-SIZEOF_XMMWORD)	; align to 16-byte boundary
316
	shl	rcx, 3			; pslldq xmmA,ecx & pslldq xmmE,ecx
317
	movdqa	xmmG,xmmA
318
	movdqa	xmmC,xmmE
319
	pslldq	xmmA, SIZEOF_XMMWORD/2
320
	pslldq	xmmE, SIZEOF_XMMWORD/2
321
	movd	xmmD,ecx
322
	sub	rcx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT
323
	jb	short .adj1
324
	movd	xmmF,ecx
325
	psllq	xmmA,xmmF
326
	psllq	xmmE,xmmF
327
	jmp	short .adj0
328
.adj1:	neg	rcx
329
	movd	xmmF,ecx
330
	psrlq	xmmA,xmmF
331
	psrlq	xmmE,xmmF
332
	psllq	xmmG,xmmD
333
	psllq	xmmC,xmmD
334
	por	xmmA,xmmG
335
	por	xmmE,xmmC
336
.adj0:	; ----------------
337
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
338
339
%else ; RGB_PIXELSIZE == 4 ; -----------
340
341
%ifdef RGBX_FILLER_0XFF
342
	pcmpeqb   xmm6,xmm6		; xmm6=XE=X(02468ACE********)
343
	pcmpeqb   xmm7,xmm7		; xmm7=XO=X(13579BDF********)
344
%else
345
	pxor      xmm6,xmm6		; xmm6=XE=X(02468ACE********)
346
	pxor      xmm7,xmm7		; xmm7=XO=X(13579BDF********)
347
%endif
348
	; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
349
	; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
350
	; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
351
	; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
352
353
	punpcklbw xmmA,xmmC	; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
354
	punpcklbw xmmE,xmmG	; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
355
	punpcklbw xmmB,xmmD	; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
356
	punpcklbw xmmF,xmmH	; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
357
358
	movdqa    xmmC,xmmA
359
	punpcklwd xmmA,xmmE	; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
360
	punpckhwd xmmC,xmmE	; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
361
	movdqa    xmmG,xmmB
362
	punpcklwd xmmB,xmmF	; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
363
	punpckhwd xmmG,xmmF	; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
364
365
	movdqa    xmmD,xmmA
366
	punpckldq xmmA,xmmB	; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
367
	punpckhdq xmmD,xmmB	; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
368
	movdqa    xmmH,xmmC
369
	punpckldq xmmC,xmmG	; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
370
	punpckhdq xmmH,xmmG	; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
371
372
	cmp	rcx, byte SIZEOF_XMMWORD
373
	jb	short .column_st32
374
375
	test	rdi, SIZEOF_XMMWORD-1
376
	jnz	short .out1
377
	; --(aligned)-------------------
378
	movntdq	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
379
	movntdq	XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
380
	movntdq	XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
381
	movntdq	XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
382
	add	rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; outptr
383
	jmp	short .out0
384
.out1:	; --(unaligned)-----------------
385
	pcmpeqb    xmmE,xmmE			; xmmE=(all 1's)
386
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [rdi], xmmA
387
	add	rdi, byte SIZEOF_XMMWORD	; outptr
388
	maskmovdqu xmmD,xmmE			; movntdqu XMMWORD [rdi], xmmD
389
	add	rdi, byte SIZEOF_XMMWORD	; outptr
390
	maskmovdqu xmmC,xmmE			; movntdqu XMMWORD [rdi], xmmC
391
	add	rdi, byte SIZEOF_XMMWORD	; outptr
392
	maskmovdqu xmmH,xmmE			; movntdqu XMMWORD [rdi], xmmH
393
	add	rdi, byte SIZEOF_XMMWORD	; outptr
394
.out0:
395
	sub	rcx, byte SIZEOF_XMMWORD
396
	jz	near .endcolumn
397
398
	add	rsi, byte SIZEOF_XMMWORD	; inptr0
399
	dec	al			; Yctr
400
	jnz	near .Yloop_2nd
401
402
	add	rbx, byte SIZEOF_XMMWORD	; inptr1
403
	add	rdx, byte SIZEOF_XMMWORD	; inptr2
404
	jmp	near .columnloop
405
406
.column_st32:
407
	pcmpeqb	xmmE,xmmE			; xmmE=(all 1's)
408
	cmp	rcx, byte SIZEOF_XMMWORD/2
409
	jb	short .column_st16
410
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [rdi], xmmA
411
	add	rdi, byte SIZEOF_XMMWORD	; outptr
412
	maskmovdqu xmmD,xmmE			; movntdqu XMMWORD [rdi], xmmD
413
	add	rdi, byte SIZEOF_XMMWORD	; outptr
414
	movdqa	xmmA,xmmC
415
	movdqa	xmmD,xmmH
416
	sub	rcx, byte SIZEOF_XMMWORD/2
417
.column_st16:
418
	cmp	rcx, byte SIZEOF_XMMWORD/4
419
	jb	short .column_st15
420
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
421
	add	rdi, byte SIZEOF_XMMWORD	; outptr
422
	movdqa	xmmA,xmmD
423
	sub	rcx, byte SIZEOF_XMMWORD/4
424
.column_st15:
425
	cmp	rcx, byte SIZEOF_XMMWORD/16
426
	jb	near .endcolumn
427
	mov	rax,rcx
428
	xor	rcx, byte 0x03
429
	inc	rcx
430
	shl	rcx, 4
431
	movd	xmmF,ecx
432
	psrlq	xmmE,xmmF
433
	punpcklbw xmmE,xmmE
434
	; ----------------
435
	mov	rcx,rdi
436
	and	rcx, byte SIZEOF_XMMWORD-1
437
	jz	short .adj0
438
	lea	rax, [rcx+rax*4]	; RGB_PIXELSIZE
439
	cmp	rax, byte SIZEOF_XMMWORD
440
	ja	short .adj0
441
	and	rdi, byte (-SIZEOF_XMMWORD)	; align to 16-byte boundary
442
	shl	rcx, 3			; pslldq xmmA,ecx & pslldq xmmE,ecx
443
	movdqa	xmmB,xmmA
444
	movdqa	xmmG,xmmE
445
	pslldq	xmmA, SIZEOF_XMMWORD/2
446
	pslldq	xmmE, SIZEOF_XMMWORD/2
447
	movd	xmmC,ecx
448
	sub	rcx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT
449
	jb	short .adj1
450
	movd	xmmH,ecx
451
	psllq	xmmA,xmmH
452
	psllq	xmmE,xmmH
453
	jmp	short .adj0
454
.adj1:	neg	rcx
455
	movd	xmmH,ecx
456
	psrlq	xmmA,xmmH
457
	psrlq	xmmE,xmmH
458
	psllq	xmmB,xmmC
459
	psllq	xmmG,xmmC
460
	por	xmmA,xmmB
461
	por	xmmE,xmmG
462
.adj0:	; ----------------
463
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
464
465
%endif ; RGB_PIXELSIZE ; ---------------
466
467
.endcolumn:
468
	sfence		; flush the write buffer
469
470
.return:
471
	pop	rbx
472
	uncollect_args
473
	mov	rsp,rbp		; rsp <- aligned rbp
474
	pop	rsp		; rsp <- original rbp
475
	pop	rbp
476
	ret
477
478
; --------------------------------------------------------------------------
479
;
480
; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
481
;
482
; GLOBAL(void)
483
; jsimd_h2v2_merged_upsample_sse2 (JDIMENSION output_width,
484
;                                  JSAMPIMAGE input_buf,
485
;                                  JDIMENSION in_row_group_ctr,
486
;                                  JSAMPARRAY output_buf);
487
;
488
489
; r10 = JDIMENSION output_width
490
; r11 = JSAMPIMAGE input_buf
491
; r12 = JDIMENSION in_row_group_ctr
492
; r13 = JSAMPARRAY output_buf
493
494
	align	16
495
	global	EXTN(jsimd_h2v2_merged_upsample_sse2)
496
497
EXTN(jsimd_h2v2_merged_upsample_sse2):
498
	push	rbp
499
	mov	rax,rsp
500
	mov	rbp,rsp
501
	collect_args
502
	push	rbx
503
504
	mov	rax, r10
505
506
	mov	rdi, r11
507
	mov	rcx, r12
508
	mov	rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
509
	mov	rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
510
	mov	rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
511
	mov	rdi, r13
512
	lea	rsi, [rsi+rcx*SIZEOF_JSAMPROW]
513
514
	push	rdx			; inptr2
515
	push	rbx			; inptr1
516
	push	rsi			; inptr00
517
	mov	rbx,rsp
518
519
	push	rdi
520
	push	rcx
521
	push	rax
522
523
	%ifdef WIN64
524
	mov r8, rcx
525
	mov r9, rdi
526
	mov rcx, rax
527
	mov rdx, rbx
528
	%else
529
	mov rdx, rcx
530
	mov rcx, rdi
531
	mov	rdi, rax
532
	mov rsi, rbx
533
	%endif
534
535
	call	EXTN(jsimd_h2v1_merged_upsample_sse2)
536
537
	pop rax
538
	pop rcx
539
	pop rdi
540
	pop rsi
541
	pop rbx
542
	pop rdx
543
544
	add	rdi, byte SIZEOF_JSAMPROW	; outptr1
545
	add	rsi, byte SIZEOF_JSAMPROW	; inptr01
546
547
	push	rdx			; inptr2
548
	push	rbx			; inptr1
549
	push	rsi			; inptr00
550
	mov	rbx,rsp
551
552
	push	rdi
553
	push	rcx
554
	push	rax
555
556
	%ifdef WIN64
557
	mov r8, rcx
558
	mov r9, rdi
559
	mov rcx, rax
560
	mov rdx, rbx
561
	%else
562
	mov rdx, rcx
563
	mov rcx, rdi
564
	mov	rdi, rax
565
	mov rsi, rbx
566
	%endif
567
568
	call	EXTN(jsimd_h2v1_merged_upsample_sse2)
569
570
	pop rax
571
	pop rcx
572
	pop rdi
573
	pop rsi
574
	pop rbx
575
	pop rdx
576
577
	pop	rbx
578
	uncollect_args
579
	pop	rbp
580
	ret
581
582
; For some reason, the OS X linker does not honor the request to align the
583
; segment unless we do this.
584
	align	16
(-)a/jpeg/simd/jdmrgss2.asm (+564 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdmrgss2.asm - merged upsampling/color conversion (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jcolsamp.inc"
20
				
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_TEXT
23
	BITS	32
24
;
25
; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
26
;
27
; GLOBAL(void)
28
; jsimd_h2v1_merged_upsample_sse2 (JDIMENSION output_width,
29
;                                  JSAMPIMAGE input_buf,
30
;                                  JDIMENSION in_row_group_ctr,
31
;                                  JSAMPARRAY output_buf);
32
;
33
34
%define output_width(b)	(b)+8			; JDIMENSION output_width
35
%define input_buf(b)		(b)+12		; JSAMPIMAGE input_buf
36
%define in_row_group_ctr(b)	(b)+16		; JDIMENSION in_row_group_ctr
37
%define output_buf(b)		(b)+20		; JSAMPARRAY output_buf
38
39
%define original_ebp	ebp+0
40
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
41
%define WK_NUM		3
42
%define gotptr		wk(0)-SIZEOF_POINTER	; void * gotptr
43
44
	align	16
45
	global	EXTN(jsimd_h2v1_merged_upsample_sse2)
46
47
EXTN(jsimd_h2v1_merged_upsample_sse2):
48
	push	ebp
49
	mov	eax,esp				; eax = original ebp
50
	sub	esp, byte 4
51
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
52
	mov	[esp],eax
53
	mov	ebp,esp				; ebp = aligned ebp
54
	lea	esp, [wk(0)]
55
	pushpic	eax		; make a room for GOT address
56
	push	ebx
57
;	push	ecx		; need not be preserved
58
;	push	edx		; need not be preserved
59
	push	esi
60
	push	edi
61
62
	get_GOT	ebx			; get GOT address
63
	movpic	POINTER [gotptr], ebx	; save GOT address
64
65
	mov	ecx, JDIMENSION [output_width(eax)]	; col
66
	test	ecx,ecx
67
	jz	near .return
68
69
	push	ecx
70
71
	mov	edi, JSAMPIMAGE [input_buf(eax)]
72
	mov	ecx, JDIMENSION [in_row_group_ctr(eax)]
73
	mov	esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
74
	mov	ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
75
	mov	edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
76
	mov	edi, JSAMPARRAY [output_buf(eax)]
77
	mov	esi, JSAMPROW [esi+ecx*SIZEOF_JSAMPROW]		; inptr0
78
	mov	ebx, JSAMPROW [ebx+ecx*SIZEOF_JSAMPROW]		; inptr1
79
	mov	edx, JSAMPROW [edx+ecx*SIZEOF_JSAMPROW]		; inptr2
80
	mov	edi, JSAMPROW [edi]				; outptr
81
82
	pop	ecx			; col
83
84
	alignx	16,7
85
.columnloop:
86
	movpic	eax, POINTER [gotptr]	; load GOT address (eax)
87
88
	movdqa    xmm6, XMMWORD [ebx]	; xmm6=Cb(0123456789ABCDEF)
89
	movdqa    xmm7, XMMWORD [edx]	; xmm7=Cr(0123456789ABCDEF)
90
91
	pxor      xmm1,xmm1		; xmm1=(all 0's)
92
	pcmpeqw   xmm3,xmm3
93
	psllw     xmm3,7		; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..}
94
95
	movdqa    xmm4,xmm6
96
	punpckhbw xmm6,xmm1		; xmm6=Cb(89ABCDEF)=CbH
97
	punpcklbw xmm4,xmm1		; xmm4=Cb(01234567)=CbL
98
	movdqa    xmm0,xmm7
99
	punpckhbw xmm7,xmm1		; xmm7=Cr(89ABCDEF)=CrH
100
	punpcklbw xmm0,xmm1		; xmm0=Cr(01234567)=CrL
101
102
	paddw     xmm6,xmm3
103
	paddw     xmm4,xmm3
104
	paddw     xmm7,xmm3
105
	paddw     xmm0,xmm3
106
107
	; (Original)
108
	; R = Y                + 1.40200 * Cr
109
	; G = Y - 0.34414 * Cb - 0.71414 * Cr
110
	; B = Y + 1.77200 * Cb
111
	;
112
	; (This implementation)
113
	; R = Y                + 0.40200 * Cr + Cr
114
	; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
115
	; B = Y - 0.22800 * Cb + Cb + Cb
116
117
	movdqa	xmm5,xmm6		; xmm5=CbH
118
	movdqa	xmm2,xmm4		; xmm2=CbL
119
	paddw	xmm6,xmm6		; xmm6=2*CbH
120
	paddw	xmm4,xmm4		; xmm4=2*CbL
121
	movdqa	xmm1,xmm7		; xmm1=CrH
122
	movdqa	xmm3,xmm0		; xmm3=CrL
123
	paddw	xmm7,xmm7		; xmm7=2*CrH
124
	paddw	xmm0,xmm0		; xmm0=2*CrL
125
126
	pmulhw	xmm6,[GOTOFF(eax,PW_MF0228)]	; xmm6=(2*CbH * -FIX(0.22800))
127
	pmulhw	xmm4,[GOTOFF(eax,PW_MF0228)]	; xmm4=(2*CbL * -FIX(0.22800))
128
	pmulhw	xmm7,[GOTOFF(eax,PW_F0402)]	; xmm7=(2*CrH * FIX(0.40200))
129
	pmulhw	xmm0,[GOTOFF(eax,PW_F0402)]	; xmm0=(2*CrL * FIX(0.40200))
130
131
	paddw	xmm6,[GOTOFF(eax,PW_ONE)]
132
	paddw	xmm4,[GOTOFF(eax,PW_ONE)]
133
	psraw	xmm6,1			; xmm6=(CbH * -FIX(0.22800))
134
	psraw	xmm4,1			; xmm4=(CbL * -FIX(0.22800))
135
	paddw	xmm7,[GOTOFF(eax,PW_ONE)]
136
	paddw	xmm0,[GOTOFF(eax,PW_ONE)]
137
	psraw	xmm7,1			; xmm7=(CrH * FIX(0.40200))
138
	psraw	xmm0,1			; xmm0=(CrL * FIX(0.40200))
139
140
	paddw	xmm6,xmm5
141
	paddw	xmm4,xmm2
142
	paddw	xmm6,xmm5		; xmm6=(CbH * FIX(1.77200))=(B-Y)H
143
	paddw	xmm4,xmm2		; xmm4=(CbL * FIX(1.77200))=(B-Y)L
144
	paddw	xmm7,xmm1		; xmm7=(CrH * FIX(1.40200))=(R-Y)H
145
	paddw	xmm0,xmm3		; xmm0=(CrL * FIX(1.40200))=(R-Y)L
146
147
	movdqa	XMMWORD [wk(0)], xmm6	; wk(0)=(B-Y)H
148
	movdqa	XMMWORD [wk(1)], xmm7	; wk(1)=(R-Y)H
149
150
	movdqa    xmm6,xmm5
151
	movdqa    xmm7,xmm2
152
	punpcklwd xmm5,xmm1
153
	punpckhwd xmm6,xmm1
154
	pmaddwd   xmm5,[GOTOFF(eax,PW_MF0344_F0285)]
155
	pmaddwd   xmm6,[GOTOFF(eax,PW_MF0344_F0285)]
156
	punpcklwd xmm2,xmm3
157
	punpckhwd xmm7,xmm3
158
	pmaddwd   xmm2,[GOTOFF(eax,PW_MF0344_F0285)]
159
	pmaddwd   xmm7,[GOTOFF(eax,PW_MF0344_F0285)]
160
161
	paddd     xmm5,[GOTOFF(eax,PD_ONEHALF)]
162
	paddd     xmm6,[GOTOFF(eax,PD_ONEHALF)]
163
	psrad     xmm5,SCALEBITS
164
	psrad     xmm6,SCALEBITS
165
	paddd     xmm2,[GOTOFF(eax,PD_ONEHALF)]
166
	paddd     xmm7,[GOTOFF(eax,PD_ONEHALF)]
167
	psrad     xmm2,SCALEBITS
168
	psrad     xmm7,SCALEBITS
169
170
	packssdw  xmm5,xmm6	; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285)
171
	packssdw  xmm2,xmm7	; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285)
172
	psubw     xmm5,xmm1	; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H
173
	psubw     xmm2,xmm3	; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L
174
175
	movdqa	XMMWORD [wk(2)], xmm5	; wk(2)=(G-Y)H
176
177
	mov	al,2			; Yctr
178
	jmp	short .Yloop_1st
179
	alignx	16,7
180
181
.Yloop_2nd:
182
	movdqa	xmm0, XMMWORD [wk(1)]	; xmm0=(R-Y)H
183
	movdqa	xmm2, XMMWORD [wk(2)]	; xmm2=(G-Y)H
184
	movdqa	xmm4, XMMWORD [wk(0)]	; xmm4=(B-Y)H
185
	alignx	16,7
186
187
.Yloop_1st:
188
	movdqa	xmm7, XMMWORD [esi]	; xmm7=Y(0123456789ABCDEF)
189
190
	pcmpeqw	xmm6,xmm6
191
	psrlw	xmm6,BYTE_BIT		; xmm6={0xFF 0x00 0xFF 0x00 ..}
192
	pand	xmm6,xmm7		; xmm6=Y(02468ACE)=YE
193
	psrlw	xmm7,BYTE_BIT		; xmm7=Y(13579BDF)=YO
194
195
	movdqa	xmm1,xmm0		; xmm1=xmm0=(R-Y)(L/H)
196
	movdqa	xmm3,xmm2		; xmm3=xmm2=(G-Y)(L/H)
197
	movdqa	xmm5,xmm4		; xmm5=xmm4=(B-Y)(L/H)
198
199
	paddw     xmm0,xmm6		; xmm0=((R-Y)+YE)=RE=R(02468ACE)
200
	paddw     xmm1,xmm7		; xmm1=((R-Y)+YO)=RO=R(13579BDF)
201
	packuswb  xmm0,xmm0		; xmm0=R(02468ACE********)
202
	packuswb  xmm1,xmm1		; xmm1=R(13579BDF********)
203
204
	paddw     xmm2,xmm6		; xmm2=((G-Y)+YE)=GE=G(02468ACE)
205
	paddw     xmm3,xmm7		; xmm3=((G-Y)+YO)=GO=G(13579BDF)
206
	packuswb  xmm2,xmm2		; xmm2=G(02468ACE********)
207
	packuswb  xmm3,xmm3		; xmm3=G(13579BDF********)
208
209
	paddw     xmm4,xmm6		; xmm4=((B-Y)+YE)=BE=B(02468ACE)
210
	paddw     xmm5,xmm7		; xmm5=((B-Y)+YO)=BO=B(13579BDF)
211
	packuswb  xmm4,xmm4		; xmm4=B(02468ACE********)
212
	packuswb  xmm5,xmm5		; xmm5=B(13579BDF********)
213
214
%if RGB_PIXELSIZE == 3 ; ---------------
215
216
	; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
217
	; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
218
	; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
219
	; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
220
221
	punpcklbw xmmA,xmmC	; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
222
	punpcklbw xmmE,xmmB	; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
223
	punpcklbw xmmD,xmmF	; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
224
225
	movdqa    xmmG,xmmA
226
	movdqa    xmmH,xmmA
227
	punpcklwd xmmA,xmmE	; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
228
	punpckhwd xmmG,xmmE	; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
229
230
	psrldq    xmmH,2	; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
231
	psrldq    xmmE,2	; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
232
233
	movdqa    xmmC,xmmD
234
	movdqa    xmmB,xmmD
235
	punpcklwd xmmD,xmmH	; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
236
	punpckhwd xmmC,xmmH	; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
237
238
	psrldq    xmmB,2	; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
239
240
	movdqa    xmmF,xmmE
241
	punpcklwd xmmE,xmmB	; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
242
	punpckhwd xmmF,xmmB	; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
243
244
	pshufd    xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
245
	movdqa    xmmB,xmmE
246
	punpckldq xmmA,xmmD	; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
247
	punpckldq xmmE,xmmH	; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
248
	punpckhdq xmmD,xmmB	; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
249
250
	pshufd    xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
251
	movdqa    xmmB,xmmF
252
	punpckldq xmmG,xmmC	; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
253
	punpckldq xmmF,xmmH	; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
254
	punpckhdq xmmC,xmmB	; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
255
256
	punpcklqdq xmmA,xmmE	; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
257
	punpcklqdq xmmD,xmmG	; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
258
	punpcklqdq xmmF,xmmC	; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
259
260
	cmp	ecx, byte SIZEOF_XMMWORD
261
	jb	short .column_st32
262
263
	test	edi, SIZEOF_XMMWORD-1
264
	jnz	short .out1
265
	; --(aligned)-------------------
266
	movntdq	XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
267
	movntdq	XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
268
	movntdq	XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF
269
	add	edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; outptr
270
	jmp	short .out0
271
.out1:	; --(unaligned)-----------------
272
	pcmpeqb    xmmH,xmmH			; xmmH=(all 1's)
273
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [edi], xmmA
274
	add	edi, byte SIZEOF_XMMWORD	; outptr
275
	maskmovdqu xmmD,xmmH			; movntdqu XMMWORD [edi], xmmD
276
	add	edi, byte SIZEOF_XMMWORD	; outptr
277
	maskmovdqu xmmF,xmmH			; movntdqu XMMWORD [edi], xmmF
278
	add	edi, byte SIZEOF_XMMWORD	; outptr
279
.out0:
280
	sub	ecx, byte SIZEOF_XMMWORD
281
	jz	near .endcolumn
282
283
	add	esi, byte SIZEOF_XMMWORD	; inptr0
284
	dec	al			; Yctr
285
	jnz	near .Yloop_2nd
286
287
	add	ebx, byte SIZEOF_XMMWORD	; inptr1
288
	add	edx, byte SIZEOF_XMMWORD	; inptr2
289
	jmp	near .columnloop
290
	alignx	16,7
291
292
.column_st32:
293
	pcmpeqb	xmmH,xmmH			; xmmH=(all 1's)
294
	lea	ecx, [ecx+ecx*2]		; imul ecx, RGB_PIXELSIZE
295
	cmp	ecx, byte 2*SIZEOF_XMMWORD
296
	jb	short .column_st16
297
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [edi], xmmA
298
	add	edi, byte SIZEOF_XMMWORD	; outptr
299
	maskmovdqu xmmD,xmmH			; movntdqu XMMWORD [edi], xmmD
300
	add	edi, byte SIZEOF_XMMWORD	; outptr
301
	movdqa	xmmA,xmmF
302
	sub	ecx, byte 2*SIZEOF_XMMWORD
303
	jmp	short .column_st15
304
.column_st16:
305
	cmp	ecx, byte SIZEOF_XMMWORD
306
	jb	short .column_st15
307
	maskmovdqu xmmA,xmmH			; movntdqu XMMWORD [edi], xmmA
308
	add	edi, byte SIZEOF_XMMWORD	; outptr
309
	movdqa	xmmA,xmmD
310
	sub	ecx, byte SIZEOF_XMMWORD
311
.column_st15:
312
	mov	eax,ecx
313
	xor	ecx, byte 0x0F
314
	shl	ecx, 2
315
	movd	xmmB,ecx
316
	psrlq	xmmH,4
317
	pcmpeqb	xmmE,xmmE
318
	psrlq	xmmH,xmmB
319
	psrlq	xmmE,xmmB
320
	punpcklbw xmmE,xmmH
321
	; ----------------
322
	mov	ecx,edi
323
	and	ecx, byte SIZEOF_XMMWORD-1
324
	jz	short .adj0
325
	add	eax,ecx
326
	cmp	eax, byte SIZEOF_XMMWORD
327
	ja	short .adj0
328
	and	edi, byte (-SIZEOF_XMMWORD)	; align to 16-byte boundary
329
	shl	ecx, 3			; pslldq xmmA,ecx & pslldq xmmE,ecx
330
	movdqa	xmmG,xmmA
331
	movdqa	xmmC,xmmE
332
	pslldq	xmmA, SIZEOF_XMMWORD/2
333
	pslldq	xmmE, SIZEOF_XMMWORD/2
334
	movd	xmmD,ecx
335
	sub	ecx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT
336
	jb	short .adj1
337
	movd	xmmF,ecx
338
	psllq	xmmA,xmmF
339
	psllq	xmmE,xmmF
340
	jmp	short .adj0
341
.adj1:	neg	ecx
342
	movd	xmmF,ecx
343
	psrlq	xmmA,xmmF
344
	psrlq	xmmE,xmmF
345
	psllq	xmmG,xmmD
346
	psllq	xmmC,xmmD
347
	por	xmmA,xmmG
348
	por	xmmE,xmmC
349
.adj0:	; ----------------
350
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
351
352
%else ; RGB_PIXELSIZE == 4 ; -----------
353
354
%ifdef RGBX_FILLER_0XFF
355
	pcmpeqb   xmm6,xmm6		; xmm6=XE=X(02468ACE********)
356
	pcmpeqb   xmm7,xmm7		; xmm7=XO=X(13579BDF********)
357
%else
358
	pxor      xmm6,xmm6		; xmm6=XE=X(02468ACE********)
359
	pxor      xmm7,xmm7		; xmm7=XO=X(13579BDF********)
360
%endif
361
	; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
362
	; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
363
	; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
364
	; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
365
366
	punpcklbw xmmA,xmmC	; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
367
	punpcklbw xmmE,xmmG	; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
368
	punpcklbw xmmB,xmmD	; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
369
	punpcklbw xmmF,xmmH	; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
370
371
	movdqa    xmmC,xmmA
372
	punpcklwd xmmA,xmmE	; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
373
	punpckhwd xmmC,xmmE	; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
374
	movdqa    xmmG,xmmB
375
	punpcklwd xmmB,xmmF	; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
376
	punpckhwd xmmG,xmmF	; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
377
378
	movdqa    xmmD,xmmA
379
	punpckldq xmmA,xmmB	; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
380
	punpckhdq xmmD,xmmB	; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
381
	movdqa    xmmH,xmmC
382
	punpckldq xmmC,xmmG	; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
383
	punpckhdq xmmH,xmmG	; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
384
385
	cmp	ecx, byte SIZEOF_XMMWORD
386
	jb	short .column_st32
387
388
	test	edi, SIZEOF_XMMWORD-1
389
	jnz	short .out1
390
	; --(aligned)-------------------
391
	movntdq	XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
392
	movntdq	XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
393
	movntdq	XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC
394
	movntdq	XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH
395
	add	edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD	; outptr
396
	jmp	short .out0
397
.out1:	; --(unaligned)-----------------
398
	pcmpeqb    xmmE,xmmE			; xmmE=(all 1's)
399
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
400
	add	edi, byte SIZEOF_XMMWORD	; outptr
401
	maskmovdqu xmmD,xmmE			; movntdqu XMMWORD [edi], xmmD
402
	add	edi, byte SIZEOF_XMMWORD	; outptr
403
	maskmovdqu xmmC,xmmE			; movntdqu XMMWORD [edi], xmmC
404
	add	edi, byte SIZEOF_XMMWORD	; outptr
405
	maskmovdqu xmmH,xmmE			; movntdqu XMMWORD [edi], xmmH
406
	add	edi, byte SIZEOF_XMMWORD	; outptr
407
.out0:
408
	sub	ecx, byte SIZEOF_XMMWORD
409
	jz	near .endcolumn
410
411
	add	esi, byte SIZEOF_XMMWORD	; inptr0
412
	dec	al			; Yctr
413
	jnz	near .Yloop_2nd
414
415
	add	ebx, byte SIZEOF_XMMWORD	; inptr1
416
	add	edx, byte SIZEOF_XMMWORD	; inptr2
417
	jmp	near .columnloop
418
	alignx	16,7
419
420
.column_st32:
421
	pcmpeqb	xmmE,xmmE			; xmmE=(all 1's)
422
	cmp	ecx, byte SIZEOF_XMMWORD/2
423
	jb	short .column_st16
424
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
425
	add	edi, byte SIZEOF_XMMWORD	; outptr
426
	maskmovdqu xmmD,xmmE			; movntdqu XMMWORD [edi], xmmD
427
	add	edi, byte SIZEOF_XMMWORD	; outptr
428
	movdqa	xmmA,xmmC
429
	movdqa	xmmD,xmmH
430
	sub	ecx, byte SIZEOF_XMMWORD/2
431
.column_st16:
432
	cmp	ecx, byte SIZEOF_XMMWORD/4
433
	jb	short .column_st15
434
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
435
	add	edi, byte SIZEOF_XMMWORD	; outptr
436
	movdqa	xmmA,xmmD
437
	sub	ecx, byte SIZEOF_XMMWORD/4
438
.column_st15:
439
	cmp	ecx, byte SIZEOF_XMMWORD/16
440
	jb	short .endcolumn
441
	mov	eax,ecx
442
	xor	ecx, byte 0x03
443
	inc	ecx
444
	shl	ecx, 4
445
	movd	xmmF,ecx
446
	psrlq	xmmE,xmmF
447
	punpcklbw xmmE,xmmE
448
	; ----------------
449
	mov	ecx,edi
450
	and	ecx, byte SIZEOF_XMMWORD-1
451
	jz	short .adj0
452
	lea	eax, [ecx+eax*4]	; RGB_PIXELSIZE
453
	cmp	eax, byte SIZEOF_XMMWORD
454
	ja	short .adj0
455
	and	edi, byte (-SIZEOF_XMMWORD)	; align to 16-byte boundary
456
	shl	ecx, 3			; pslldq xmmA,ecx & pslldq xmmE,ecx
457
	movdqa	xmmB,xmmA
458
	movdqa	xmmG,xmmE
459
	pslldq	xmmA, SIZEOF_XMMWORD/2
460
	pslldq	xmmE, SIZEOF_XMMWORD/2
461
	movd	xmmC,ecx
462
	sub	ecx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT
463
	jb	short .adj1
464
	movd	xmmH,ecx
465
	psllq	xmmA,xmmH
466
	psllq	xmmE,xmmH
467
	jmp	short .adj0
468
.adj1:	neg	ecx
469
	movd	xmmH,ecx
470
	psrlq	xmmA,xmmH
471
	psrlq	xmmE,xmmH
472
	psllq	xmmB,xmmC
473
	psllq	xmmG,xmmC
474
	por	xmmA,xmmB
475
	por	xmmE,xmmG
476
.adj0:	; ----------------
477
	maskmovdqu xmmA,xmmE			; movntdqu XMMWORD [edi], xmmA
478
479
%endif ; RGB_PIXELSIZE ; ---------------
480
481
.endcolumn:
482
	sfence		; flush the write buffer
483
484
.return:
485
	pop	edi
486
	pop	esi
487
;	pop	edx		; need not be preserved
488
;	pop	ecx		; need not be preserved
489
	pop	ebx
490
	mov	esp,ebp		; esp <- aligned ebp
491
	pop	esp		; esp <- original ebp
492
	pop	ebp
493
	ret
494
495
; --------------------------------------------------------------------------
496
;
497
; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
498
;
499
; GLOBAL(void)
500
; jsimd_h2v2_merged_upsample_sse2 (JDIMENSION output_width,
501
;                                  JSAMPIMAGE input_buf,
502
;                                  JDIMENSION in_row_group_ctr,
503
;                                  JSAMPARRAY output_buf);
504
;
505
506
%define output_width(b)	(b)+8			; JDIMENSION output_width
507
%define input_buf(b)		(b)+12		; JSAMPIMAGE input_buf
508
%define in_row_group_ctr(b)	(b)+16		; JDIMENSION in_row_group_ctr
509
%define output_buf(b)		(b)+20		; JSAMPARRAY output_buf
510
511
	align	16
512
	global	EXTN(jsimd_h2v2_merged_upsample_sse2)
513
514
EXTN(jsimd_h2v2_merged_upsample_sse2):
515
	push	ebp
516
	mov	ebp,esp
517
	push	ebx
518
;	push	ecx		; need not be preserved
519
;	push	edx		; need not be preserved
520
	push	esi
521
	push	edi
522
523
	mov	eax, POINTER [output_width(ebp)]
524
525
	mov	edi, JSAMPIMAGE [input_buf(ebp)]
526
	mov	ecx, JDIMENSION [in_row_group_ctr(ebp)]
527
	mov	esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
528
	mov	ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
529
	mov	edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
530
	mov	edi, JSAMPARRAY [output_buf(ebp)]
531
	lea	esi, [esi+ecx*SIZEOF_JSAMPROW]
532
533
	push	edx			; inptr2
534
	push	ebx			; inptr1
535
	push	esi			; inptr00
536
	mov	ebx,esp
537
538
	push	edi			; output_buf (outptr0)
539
	push	ecx			; in_row_group_ctr
540
	push	ebx			; input_buf
541
	push	eax			; output_width
542
543
	call	near EXTN(jsimd_h2v1_merged_upsample_sse2)
544
545
	add	esi, byte SIZEOF_JSAMPROW	; inptr01
546
	add	edi, byte SIZEOF_JSAMPROW	; outptr1
547
	mov	POINTER [ebx+0*SIZEOF_POINTER], esi
548
	mov	POINTER [ebx-1*SIZEOF_POINTER], edi
549
550
	call	near EXTN(jsimd_h2v1_merged_upsample_sse2)
551
552
	add	esp, byte 7*SIZEOF_DWORD
553
554
	pop	edi
555
	pop	esi
556
;	pop	edx		; need not be preserved
557
;	pop	ecx		; need not be preserved
558
	pop	ebx
559
	pop	ebp
560
	ret
561
562
; For some reason, the OS X linker does not honor the request to align the
563
; segment unless we do this.
564
	align	16
(-)a/jpeg/simd/jdsammmx.asm (+737 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdsammmx.asm - upsampling (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_CONST
23
24
	alignz	16
25
	global	EXTN(jconst_fancy_upsample_mmx)
26
27
EXTN(jconst_fancy_upsample_mmx):
28
29
PW_ONE		times 4 dw  1
30
PW_TWO		times 4 dw  2
31
PW_THREE	times 4 dw  3
32
PW_SEVEN	times 4 dw  7
33
PW_EIGHT	times 4 dw  8
34
35
	alignz	16
36
37
; --------------------------------------------------------------------------
38
	SECTION	SEG_TEXT
39
	BITS	32
40
;
41
; Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
42
;
43
; The upsampling algorithm is linear interpolation between pixel centers,
44
; also known as a "triangle filter".  This is a good compromise between
45
; speed and visual quality.  The centers of the output pixels are 1/4 and 3/4
46
; of the way between input pixel centers.
47
;
48
; GLOBAL(void)
49
; jsimd_h2v1_fancy_upsample_mmx (int max_v_samp_factor,
50
;                                JDIMENSION downsampled_width,
51
;                                JSAMPARRAY input_data,
52
;                                JSAMPARRAY * output_data_ptr);
53
;
54
55
%define max_v_samp(b)		(b)+8			; int max_v_samp_factor
56
%define downsamp_width(b)	(b)+12	; JDIMENSION downsampled_width
57
%define input_data(b)		(b)+16		; JSAMPARRAY input_data
58
%define output_data_ptr(b)	(b)+20		; JSAMPARRAY * output_data_ptr
59
60
	align	16
61
	global	EXTN(jsimd_h2v1_fancy_upsample_mmx)
62
63
EXTN(jsimd_h2v1_fancy_upsample_mmx):
64
	push	ebp
65
	mov	ebp,esp
66
	pushpic	ebx
67
;	push	ecx		; need not be preserved
68
;	push	edx		; need not be preserved
69
	push	esi
70
	push	edi
71
72
	get_GOT	ebx		; get GOT address
73
74
	mov	eax, JDIMENSION [downsamp_width(ebp)]  ; colctr
75
	test	eax,eax
76
	jz	near .return
77
78
	mov	ecx, INT [max_v_samp(ebp)]	; rowctr
79
	test	ecx,ecx
80
	jz	near .return
81
82
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
83
	mov	edi, POINTER [output_data_ptr(ebp)]
84
	mov	edi, JSAMPARRAY [edi]			; output_data
85
	alignx	16,7
86
.rowloop:
87
	push	eax			; colctr
88
	push	edi
89
	push	esi
90
91
	mov	esi, JSAMPROW [esi]	; inptr
92
	mov	edi, JSAMPROW [edi]	; outptr
93
94
	test	eax, SIZEOF_MMWORD-1
95
	jz	short .skip
96
	mov	dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE]
97
	mov	JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl	; insert a dummy sample
98
.skip:
99
	pxor	mm0,mm0			; mm0=(all 0's)
100
	pcmpeqb	mm7,mm7
101
	psrlq	mm7,(SIZEOF_MMWORD-1)*BYTE_BIT
102
	pand	mm7, MMWORD [esi+0*SIZEOF_MMWORD]
103
104
	add	eax, byte SIZEOF_MMWORD-1
105
	and	eax, byte -SIZEOF_MMWORD
106
	cmp	eax, byte SIZEOF_MMWORD
107
	ja	short .columnloop
108
	alignx	16,7
109
110
.columnloop_last:
111
	pcmpeqb	mm6,mm6
112
	psllq	mm6,(SIZEOF_MMWORD-1)*BYTE_BIT
113
	pand	mm6, MMWORD [esi+0*SIZEOF_MMWORD]
114
	jmp	short .upsample
115
	alignx	16,7
116
117
.columnloop:
118
	movq	mm6, MMWORD [esi+1*SIZEOF_MMWORD]
119
	psllq	mm6,(SIZEOF_MMWORD-1)*BYTE_BIT
120
121
.upsample:
122
	movq	mm1, MMWORD [esi+0*SIZEOF_MMWORD]
123
	movq	mm2,mm1
124
	movq	mm3,mm1			; mm1=( 0 1 2 3 4 5 6 7)
125
	psllq	mm2,BYTE_BIT		; mm2=( - 0 1 2 3 4 5 6)
126
	psrlq	mm3,BYTE_BIT		; mm3=( 1 2 3 4 5 6 7 -)
127
128
	por	mm2,mm7			; mm2=(-1 0 1 2 3 4 5 6)
129
	por	mm3,mm6			; mm3=( 1 2 3 4 5 6 7 8)
130
131
	movq	mm7,mm1
132
	psrlq	mm7,(SIZEOF_MMWORD-1)*BYTE_BIT	; mm7=( 7 - - - - - - -)
133
134
	movq      mm4,mm1
135
	punpcklbw mm1,mm0		; mm1=( 0 1 2 3)
136
	punpckhbw mm4,mm0		; mm4=( 4 5 6 7)
137
	movq      mm5,mm2
138
	punpcklbw mm2,mm0		; mm2=(-1 0 1 2)
139
	punpckhbw mm5,mm0		; mm5=( 3 4 5 6)
140
	movq      mm6,mm3
141
	punpcklbw mm3,mm0		; mm3=( 1 2 3 4)
142
	punpckhbw mm6,mm0		; mm6=( 5 6 7 8)
143
144
	pmullw	mm1,[GOTOFF(ebx,PW_THREE)]
145
	pmullw	mm4,[GOTOFF(ebx,PW_THREE)]
146
	paddw	mm2,[GOTOFF(ebx,PW_ONE)]
147
	paddw	mm5,[GOTOFF(ebx,PW_ONE)]
148
	paddw	mm3,[GOTOFF(ebx,PW_TWO)]
149
	paddw	mm6,[GOTOFF(ebx,PW_TWO)]
150
151
	paddw	mm2,mm1
152
	paddw	mm5,mm4
153
	psrlw	mm2,2			; mm2=OutLE=( 0  2  4  6)
154
	psrlw	mm5,2			; mm5=OutHE=( 8 10 12 14)
155
	paddw	mm3,mm1
156
	paddw	mm6,mm4
157
	psrlw	mm3,2			; mm3=OutLO=( 1  3  5  7)
158
	psrlw	mm6,2			; mm6=OutHO=( 9 11 13 15)
159
160
	psllw	mm3,BYTE_BIT
161
	psllw	mm6,BYTE_BIT
162
	por	mm2,mm3			; mm2=OutL=( 0  1  2  3  4  5  6  7)
163
	por	mm5,mm6			; mm5=OutH=( 8  9 10 11 12 13 14 15)
164
165
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mm2
166
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mm5
167
168
	sub	eax, byte SIZEOF_MMWORD
169
	add	esi, byte 1*SIZEOF_MMWORD	; inptr
170
	add	edi, byte 2*SIZEOF_MMWORD	; outptr
171
	cmp	eax, byte SIZEOF_MMWORD
172
	ja	near .columnloop
173
	test	eax,eax
174
	jnz	near .columnloop_last
175
176
	pop	esi
177
	pop	edi
178
	pop	eax
179
180
	add	esi, byte SIZEOF_JSAMPROW	; input_data
181
	add	edi, byte SIZEOF_JSAMPROW	; output_data
182
	dec	ecx				; rowctr
183
	jg	near .rowloop
184
185
	emms		; empty MMX state
186
187
.return:
188
	pop	edi
189
	pop	esi
190
;	pop	edx		; need not be preserved
191
;	pop	ecx		; need not be preserved
192
	poppic	ebx
193
	pop	ebp
194
	ret
195
196
; --------------------------------------------------------------------------
197
;
198
; Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
199
; Again a triangle filter; see comments for h2v1 case, above.
200
;
201
; GLOBAL(void)
202
; jsimd_h2v2_fancy_upsample_mmx (int max_v_samp_factor,
203
;                                JDIMENSION downsampled_width,
204
;                                JSAMPARRAY input_data,
205
;                                JSAMPARRAY * output_data_ptr);
206
;
207
208
%define max_v_samp(b)		(b)+8			; int max_v_samp_factor
209
%define downsamp_width(b)	(b)+12	; JDIMENSION downsampled_width
210
%define input_data(b)		(b)+16		; JSAMPARRAY input_data
211
%define output_data_ptr(b)	(b)+20		; JSAMPARRAY * output_data_ptr
212
213
%define original_ebp	ebp+0
214
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
215
%define WK_NUM		4
216
%define gotptr		wk(0)-SIZEOF_POINTER	; void * gotptr
217
218
	align	16
219
	global	EXTN(jsimd_h2v2_fancy_upsample_mmx)
220
221
EXTN(jsimd_h2v2_fancy_upsample_mmx):
222
	push	ebp
223
	mov	eax,esp				; eax = original ebp
224
	sub	esp, byte 4
225
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
226
	mov	[esp],eax
227
	mov	ebp,esp				; ebp = aligned ebp
228
	lea	esp, [wk(0)]
229
	pushpic	eax		; make a room for GOT address
230
	push	ebx
231
;	push	ecx		; need not be preserved
232
;	push	edx		; need not be preserved
233
	push	esi
234
	push	edi
235
236
	get_GOT	ebx			; get GOT address
237
	movpic	POINTER [gotptr], ebx	; save GOT address
238
239
	mov	edx,eax				; edx = original ebp
240
	mov	eax, JDIMENSION [downsamp_width(edx)]  ; colctr
241
	test	eax,eax
242
	jz	near .return
243
244
	mov	ecx, INT [max_v_samp(edx)]	; rowctr
245
	test	ecx,ecx
246
	jz	near .return
247
248
	mov	esi, JSAMPARRAY [input_data(edx)]	; input_data
249
	mov	edi, POINTER [output_data_ptr(edx)]
250
	mov	edi, JSAMPARRAY [edi]			; output_data
251
	alignx	16,7
252
.rowloop:
253
	push	eax					; colctr
254
	push	ecx
255
	push	edi
256
	push	esi
257
258
	mov	ecx, JSAMPROW [esi-1*SIZEOF_JSAMPROW]	; inptr1(above)
259
	mov	ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]	; inptr0
260
	mov	esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW]	; inptr1(below)
261
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]	; outptr0
262
	mov	edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]	; outptr1
263
264
	test	eax, SIZEOF_MMWORD-1
265
	jz	short .skip
266
	push	edx
267
	mov	dl, JSAMPLE [ecx+(eax-1)*SIZEOF_JSAMPLE]
268
	mov	JSAMPLE [ecx+eax*SIZEOF_JSAMPLE], dl
269
	mov	dl, JSAMPLE [ebx+(eax-1)*SIZEOF_JSAMPLE]
270
	mov	JSAMPLE [ebx+eax*SIZEOF_JSAMPLE], dl
271
	mov	dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE]
272
	mov	JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl	; insert a dummy sample
273
	pop	edx
274
.skip:
275
	; -- process the first column block
276
277
	movq	mm0, MMWORD [ebx+0*SIZEOF_MMWORD]	; mm0=row[ 0][0]
278
	movq	mm1, MMWORD [ecx+0*SIZEOF_MMWORD]	; mm1=row[-1][0]
279
	movq	mm2, MMWORD [esi+0*SIZEOF_MMWORD]	; mm2=row[+1][0]
280
281
	pushpic	ebx
282
	movpic	ebx, POINTER [gotptr]	; load GOT address
283
284
	pxor      mm3,mm3		; mm3=(all 0's)
285
	movq      mm4,mm0
286
	punpcklbw mm0,mm3		; mm0=row[ 0][0]( 0 1 2 3)
287
	punpckhbw mm4,mm3		; mm4=row[ 0][0]( 4 5 6 7)
288
	movq      mm5,mm1
289
	punpcklbw mm1,mm3		; mm1=row[-1][0]( 0 1 2 3)
290
	punpckhbw mm5,mm3		; mm5=row[-1][0]( 4 5 6 7)
291
	movq      mm6,mm2
292
	punpcklbw mm2,mm3		; mm2=row[+1][0]( 0 1 2 3)
293
	punpckhbw mm6,mm3		; mm6=row[+1][0]( 4 5 6 7)
294
295
	pmullw	mm0,[GOTOFF(ebx,PW_THREE)]
296
	pmullw	mm4,[GOTOFF(ebx,PW_THREE)]
297
298
	pcmpeqb	mm7,mm7
299
	psrlq	mm7,(SIZEOF_MMWORD-2)*BYTE_BIT
300
301
	paddw	mm1,mm0			; mm1=Int0L=( 0 1 2 3)
302
	paddw	mm5,mm4			; mm5=Int0H=( 4 5 6 7)
303
	paddw	mm2,mm0			; mm2=Int1L=( 0 1 2 3)
304
	paddw	mm6,mm4			; mm6=Int1H=( 4 5 6 7)
305
306
	movq	MMWORD [edx+0*SIZEOF_MMWORD], mm1	; temporarily save
307
	movq	MMWORD [edx+1*SIZEOF_MMWORD], mm5	; the intermediate data
308
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mm2
309
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mm6
310
311
	pand	mm1,mm7			; mm1=( 0 - - -)
312
	pand	mm2,mm7			; mm2=( 0 - - -)
313
314
	movq	MMWORD [wk(0)], mm1
315
	movq	MMWORD [wk(1)], mm2
316
317
	poppic	ebx
318
319
	add	eax, byte SIZEOF_MMWORD-1
320
	and	eax, byte -SIZEOF_MMWORD
321
	cmp	eax, byte SIZEOF_MMWORD
322
	ja	short .columnloop
323
	alignx	16,7
324
325
.columnloop_last:
326
	; -- process the last column block
327
328
	pushpic	ebx
329
	movpic	ebx, POINTER [gotptr]	; load GOT address
330
331
	pcmpeqb	mm1,mm1
332
	psllq	mm1,(SIZEOF_MMWORD-2)*BYTE_BIT
333
	movq	mm2,mm1
334
335
	pand	mm1, MMWORD [edx+1*SIZEOF_MMWORD]	; mm1=( - - - 7)
336
	pand	mm2, MMWORD [edi+1*SIZEOF_MMWORD]	; mm2=( - - - 7)
337
338
	movq	MMWORD [wk(2)], mm1
339
	movq	MMWORD [wk(3)], mm2
340
341
	jmp	short .upsample
342
	alignx	16,7
343
344
.columnloop:
345
	; -- process the next column block
346
347
	movq	mm0, MMWORD [ebx+1*SIZEOF_MMWORD]	; mm0=row[ 0][1]
348
	movq	mm1, MMWORD [ecx+1*SIZEOF_MMWORD]	; mm1=row[-1][1]
349
	movq	mm2, MMWORD [esi+1*SIZEOF_MMWORD]	; mm2=row[+1][1]
350
351
	pushpic	ebx
352
	movpic	ebx, POINTER [gotptr]	; load GOT address
353
354
	pxor      mm3,mm3		; mm3=(all 0's)
355
	movq      mm4,mm0
356
	punpcklbw mm0,mm3		; mm0=row[ 0][1]( 0 1 2 3)
357
	punpckhbw mm4,mm3		; mm4=row[ 0][1]( 4 5 6 7)
358
	movq      mm5,mm1
359
	punpcklbw mm1,mm3		; mm1=row[-1][1]( 0 1 2 3)
360
	punpckhbw mm5,mm3		; mm5=row[-1][1]( 4 5 6 7)
361
	movq      mm6,mm2
362
	punpcklbw mm2,mm3		; mm2=row[+1][1]( 0 1 2 3)
363
	punpckhbw mm6,mm3		; mm6=row[+1][1]( 4 5 6 7)
364
365
	pmullw	mm0,[GOTOFF(ebx,PW_THREE)]
366
	pmullw	mm4,[GOTOFF(ebx,PW_THREE)]
367
368
	paddw	mm1,mm0			; mm1=Int0L=( 0 1 2 3)
369
	paddw	mm5,mm4			; mm5=Int0H=( 4 5 6 7)
370
	paddw	mm2,mm0			; mm2=Int1L=( 0 1 2 3)
371
	paddw	mm6,mm4			; mm6=Int1H=( 4 5 6 7)
372
373
	movq	MMWORD [edx+2*SIZEOF_MMWORD], mm1	; temporarily save
374
	movq	MMWORD [edx+3*SIZEOF_MMWORD], mm5	; the intermediate data
375
	movq	MMWORD [edi+2*SIZEOF_MMWORD], mm2
376
	movq	MMWORD [edi+3*SIZEOF_MMWORD], mm6
377
378
	psllq	mm1,(SIZEOF_MMWORD-2)*BYTE_BIT	; mm1=( - - - 0)
379
	psllq	mm2,(SIZEOF_MMWORD-2)*BYTE_BIT	; mm2=( - - - 0)
380
381
	movq	MMWORD [wk(2)], mm1
382
	movq	MMWORD [wk(3)], mm2
383
384
.upsample:
385
	; -- process the upper row
386
387
	movq	mm7, MMWORD [edx+0*SIZEOF_MMWORD]	; mm7=Int0L=( 0 1 2 3)
388
	movq	mm3, MMWORD [edx+1*SIZEOF_MMWORD]	; mm3=Int0H=( 4 5 6 7)
389
390
	movq	mm0,mm7
391
	movq	mm4,mm3
392
	psrlq	mm0,2*BYTE_BIT			; mm0=( 1 2 3 -)
393
	psllq	mm4,(SIZEOF_MMWORD-2)*BYTE_BIT	; mm4=( - - - 4)
394
	movq	mm5,mm7
395
	movq	mm6,mm3
396
	psrlq	mm5,(SIZEOF_MMWORD-2)*BYTE_BIT	; mm5=( 3 - - -)
397
	psllq	mm6,2*BYTE_BIT			; mm6=( - 4 5 6)
398
399
	por	mm0,mm4				; mm0=( 1 2 3 4)
400
	por	mm5,mm6				; mm5=( 3 4 5 6)
401
402
	movq	mm1,mm7
403
	movq	mm2,mm3
404
	psllq	mm1,2*BYTE_BIT			; mm1=( - 0 1 2)
405
	psrlq	mm2,2*BYTE_BIT			; mm2=( 5 6 7 -)
406
	movq	mm4,mm3
407
	psrlq	mm4,(SIZEOF_MMWORD-2)*BYTE_BIT	; mm4=( 7 - - -)
408
409
	por	mm1, MMWORD [wk(0)]		; mm1=(-1 0 1 2)
410
	por	mm2, MMWORD [wk(2)]		; mm2=( 5 6 7 8)
411
412
	movq	MMWORD [wk(0)], mm4
413
414
	pmullw	mm7,[GOTOFF(ebx,PW_THREE)]
415
	pmullw	mm3,[GOTOFF(ebx,PW_THREE)]
416
	paddw	mm1,[GOTOFF(ebx,PW_EIGHT)]
417
	paddw	mm5,[GOTOFF(ebx,PW_EIGHT)]
418
	paddw	mm0,[GOTOFF(ebx,PW_SEVEN)]
419
	paddw	mm2,[GOTOFF(ebx,PW_SEVEN)]
420
421
	paddw	mm1,mm7
422
	paddw	mm5,mm3
423
	psrlw	mm1,4			; mm1=Out0LE=( 0  2  4  6)
424
	psrlw	mm5,4			; mm5=Out0HE=( 8 10 12 14)
425
	paddw	mm0,mm7
426
	paddw	mm2,mm3
427
	psrlw	mm0,4			; mm0=Out0LO=( 1  3  5  7)
428
	psrlw	mm2,4			; mm2=Out0HO=( 9 11 13 15)
429
430
	psllw	mm0,BYTE_BIT
431
	psllw	mm2,BYTE_BIT
432
	por	mm1,mm0			; mm1=Out0L=( 0  1  2  3  4  5  6  7)
433
	por	mm5,mm2			; mm5=Out0H=( 8  9 10 11 12 13 14 15)
434
435
	movq	MMWORD [edx+0*SIZEOF_MMWORD], mm1
436
	movq	MMWORD [edx+1*SIZEOF_MMWORD], mm5
437
438
	; -- process the lower row
439
440
	movq	mm6, MMWORD [edi+0*SIZEOF_MMWORD]	; mm6=Int1L=( 0 1 2 3)
441
	movq	mm4, MMWORD [edi+1*SIZEOF_MMWORD]	; mm4=Int1H=( 4 5 6 7)
442
443
	movq	mm7,mm6
444
	movq	mm3,mm4
445
	psrlq	mm7,2*BYTE_BIT			; mm7=( 1 2 3 -)
446
	psllq	mm3,(SIZEOF_MMWORD-2)*BYTE_BIT	; mm3=( - - - 4)
447
	movq	mm0,mm6
448
	movq	mm2,mm4
449
	psrlq	mm0,(SIZEOF_MMWORD-2)*BYTE_BIT	; mm0=( 3 - - -)
450
	psllq	mm2,2*BYTE_BIT			; mm2=( - 4 5 6)
451
452
	por	mm7,mm3				; mm7=( 1 2 3 4)
453
	por	mm0,mm2				; mm0=( 3 4 5 6)
454
455
	movq	mm1,mm6
456
	movq	mm5,mm4
457
	psllq	mm1,2*BYTE_BIT			; mm1=( - 0 1 2)
458
	psrlq	mm5,2*BYTE_BIT			; mm5=( 5 6 7 -)
459
	movq	mm3,mm4
460
	psrlq	mm3,(SIZEOF_MMWORD-2)*BYTE_BIT	; mm3=( 7 - - -)
461
462
	por	mm1, MMWORD [wk(1)]		; mm1=(-1 0 1 2)
463
	por	mm5, MMWORD [wk(3)]		; mm5=( 5 6 7 8)
464
465
	movq	MMWORD [wk(1)], mm3
466
467
	pmullw	mm6,[GOTOFF(ebx,PW_THREE)]
468
	pmullw	mm4,[GOTOFF(ebx,PW_THREE)]
469
	paddw	mm1,[GOTOFF(ebx,PW_EIGHT)]
470
	paddw	mm0,[GOTOFF(ebx,PW_EIGHT)]
471
	paddw	mm7,[GOTOFF(ebx,PW_SEVEN)]
472
	paddw	mm5,[GOTOFF(ebx,PW_SEVEN)]
473
474
	paddw	mm1,mm6
475
	paddw	mm0,mm4
476
	psrlw	mm1,4			; mm1=Out1LE=( 0  2  4  6)
477
	psrlw	mm0,4			; mm0=Out1HE=( 8 10 12 14)
478
	paddw	mm7,mm6
479
	paddw	mm5,mm4
480
	psrlw	mm7,4			; mm7=Out1LO=( 1  3  5  7)
481
	psrlw	mm5,4			; mm5=Out1HO=( 9 11 13 15)
482
483
	psllw	mm7,BYTE_BIT
484
	psllw	mm5,BYTE_BIT
485
	por	mm1,mm7			; mm1=Out1L=( 0  1  2  3  4  5  6  7)
486
	por	mm0,mm5			; mm0=Out1H=( 8  9 10 11 12 13 14 15)
487
488
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mm1
489
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mm0
490
491
	poppic	ebx
492
493
	sub	eax, byte SIZEOF_MMWORD
494
	add	ecx, byte 1*SIZEOF_MMWORD	; inptr1(above)
495
	add	ebx, byte 1*SIZEOF_MMWORD	; inptr0
496
	add	esi, byte 1*SIZEOF_MMWORD	; inptr1(below)
497
	add	edx, byte 2*SIZEOF_MMWORD	; outptr0
498
	add	edi, byte 2*SIZEOF_MMWORD	; outptr1
499
	cmp	eax, byte SIZEOF_MMWORD
500
	ja	near .columnloop
501
	test	eax,eax
502
	jnz	near .columnloop_last
503
504
	pop	esi
505
	pop	edi
506
	pop	ecx
507
	pop	eax
508
509
	add	esi, byte 1*SIZEOF_JSAMPROW	; input_data
510
	add	edi, byte 2*SIZEOF_JSAMPROW	; output_data
511
	sub	ecx, byte 2			; rowctr
512
	jg	near .rowloop
513
514
	emms		; empty MMX state
515
516
.return:
517
	pop	edi
518
	pop	esi
519
;	pop	edx		; need not be preserved
520
;	pop	ecx		; need not be preserved
521
	pop	ebx
522
	mov	esp,ebp		; esp <- aligned ebp
523
	pop	esp		; esp <- original ebp
524
	pop	ebp
525
	ret
526
527
; --------------------------------------------------------------------------
528
;
529
; Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
530
; It's still a box filter.
531
;
532
; GLOBAL(void)
533
; jsimd_h2v1_upsample_mmx (int max_v_samp_factor,
534
;                          JDIMENSION output_width,
535
;                          JSAMPARRAY input_data,
536
;                          JSAMPARRAY * output_data_ptr);
537
;
538
539
%define max_v_samp(b)		(b)+8			; int max_v_samp_factor
540
%define output_width(b)	(b)+12		; JDIMENSION output_width
541
%define input_data(b)		(b)+16		; JSAMPARRAY input_data
542
%define output_data_ptr(b)	(b)+20		; JSAMPARRAY * output_data_ptr
543
544
	align	16
545
	global	EXTN(jsimd_h2v1_upsample_mmx)
546
547
EXTN(jsimd_h2v1_upsample_mmx):
548
	push	ebp
549
	mov	ebp,esp
550
;	push	ebx		; unused
551
;	push	ecx		; need not be preserved
552
;	push	edx		; need not be preserved
553
	push	esi
554
	push	edi
555
556
	mov	edx, JDIMENSION [output_width(ebp)]
557
	add	edx, byte (2*SIZEOF_MMWORD)-1
558
	and	edx, byte -(2*SIZEOF_MMWORD)
559
	jz	short .return
560
561
	mov	ecx, INT [max_v_samp(ebp)]	; rowctr
562
	test	ecx,ecx
563
	jz	short .return
564
565
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
566
	mov	edi, POINTER [output_data_ptr(ebp)]
567
	mov	edi, JSAMPARRAY [edi]			; output_data
568
	alignx	16,7
569
.rowloop:
570
	push	edi
571
	push	esi
572
573
	mov	esi, JSAMPROW [esi]		; inptr
574
	mov	edi, JSAMPROW [edi]		; outptr
575
	mov	eax,edx				; colctr
576
	alignx	16,7
577
.columnloop:
578
579
	movq	mm0, MMWORD [esi+0*SIZEOF_MMWORD]
580
581
	movq      mm1,mm0
582
	punpcklbw mm0,mm0
583
	punpckhbw mm1,mm1
584
585
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mm0
586
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mm1
587
588
	sub	eax, byte 2*SIZEOF_MMWORD
589
	jz	short .nextrow
590
591
	movq	mm2, MMWORD [esi+1*SIZEOF_MMWORD]
592
593
	movq      mm3,mm2
594
	punpcklbw mm2,mm2
595
	punpckhbw mm3,mm3
596
597
	movq	MMWORD [edi+2*SIZEOF_MMWORD], mm2
598
	movq	MMWORD [edi+3*SIZEOF_MMWORD], mm3
599
600
	sub	eax, byte 2*SIZEOF_MMWORD
601
	jz	short .nextrow
602
603
	add	esi, byte 2*SIZEOF_MMWORD	; inptr
604
	add	edi, byte 4*SIZEOF_MMWORD	; outptr
605
	jmp	short .columnloop
606
	alignx	16,7
607
608
.nextrow:
609
	pop	esi
610
	pop	edi
611
612
	add	esi, byte SIZEOF_JSAMPROW	; input_data
613
	add	edi, byte SIZEOF_JSAMPROW	; output_data
614
	dec	ecx				; rowctr
615
	jg	short .rowloop
616
617
	emms		; empty MMX state
618
619
.return:
620
	pop	edi
621
	pop	esi
622
;	pop	edx		; need not be preserved
623
;	pop	ecx		; need not be preserved
624
;	pop	ebx		; unused
625
	pop	ebp
626
	ret
627
628
; --------------------------------------------------------------------------
629
;
630
; Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
631
; It's still a box filter.
632
;
633
; GLOBAL(void)
634
; jsimd_h2v2_upsample_mmx (int max_v_samp_factor,
635
;                          JDIMENSION output_width,
636
;                          JSAMPARRAY input_data,
637
;                          JSAMPARRAY * output_data_ptr);
638
;
639
640
%define max_v_samp(b)		(b)+8			; int max_v_samp_factor
641
%define output_width(b)	(b)+12		; JDIMENSION output_width
642
%define input_data(b)		(b)+16		; JSAMPARRAY input_data
643
%define output_data_ptr(b)	(b)+20		; JSAMPARRAY * output_data_ptr
644
645
	align	16
646
	global	EXTN(jsimd_h2v2_upsample_mmx)
647
648
EXTN(jsimd_h2v2_upsample_mmx):
649
	push	ebp
650
	mov	ebp,esp
651
	push	ebx
652
;	push	ecx		; need not be preserved
653
;	push	edx		; need not be preserved
654
	push	esi
655
	push	edi
656
657
	mov	edx, JDIMENSION [output_width(ebp)]
658
	add	edx, byte (2*SIZEOF_MMWORD)-1
659
	and	edx, byte -(2*SIZEOF_MMWORD)
660
	jz	near .return
661
662
	mov	ecx, INT [max_v_samp(ebp)]	; rowctr
663
	test	ecx,ecx
664
	jz	short .return
665
666
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
667
	mov	edi, POINTER [output_data_ptr(ebp)]
668
	mov	edi, JSAMPARRAY [edi]			; output_data
669
	alignx	16,7
670
.rowloop:
671
	push	edi
672
	push	esi
673
674
	mov	esi, JSAMPROW [esi]			; inptr
675
	mov	ebx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]	; outptr0
676
	mov	edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]	; outptr1
677
	mov	eax,edx					; colctr
678
	alignx	16,7
679
.columnloop:
680
681
	movq	mm0, MMWORD [esi+0*SIZEOF_MMWORD]
682
683
	movq      mm1,mm0
684
	punpcklbw mm0,mm0
685
	punpckhbw mm1,mm1
686
687
	movq	MMWORD [ebx+0*SIZEOF_MMWORD], mm0
688
	movq	MMWORD [ebx+1*SIZEOF_MMWORD], mm1
689
	movq	MMWORD [edi+0*SIZEOF_MMWORD], mm0
690
	movq	MMWORD [edi+1*SIZEOF_MMWORD], mm1
691
692
	sub	eax, byte 2*SIZEOF_MMWORD
693
	jz	short .nextrow
694
695
	movq	mm2, MMWORD [esi+1*SIZEOF_MMWORD]
696
697
	movq      mm3,mm2
698
	punpcklbw mm2,mm2
699
	punpckhbw mm3,mm3
700
701
	movq	MMWORD [ebx+2*SIZEOF_MMWORD], mm2
702
	movq	MMWORD [ebx+3*SIZEOF_MMWORD], mm3
703
	movq	MMWORD [edi+2*SIZEOF_MMWORD], mm2
704
	movq	MMWORD [edi+3*SIZEOF_MMWORD], mm3
705
706
	sub	eax, byte 2*SIZEOF_MMWORD
707
	jz	short .nextrow
708
709
	add	esi, byte 2*SIZEOF_MMWORD	; inptr
710
	add	ebx, byte 4*SIZEOF_MMWORD	; outptr0
711
	add	edi, byte 4*SIZEOF_MMWORD	; outptr1
712
	jmp	short .columnloop
713
	alignx	16,7
714
715
.nextrow:
716
	pop	esi
717
	pop	edi
718
719
	add	esi, byte 1*SIZEOF_JSAMPROW	; input_data
720
	add	edi, byte 2*SIZEOF_JSAMPROW	; output_data
721
	sub	ecx, byte 2			; rowctr
722
	jg	short .rowloop
723
724
	emms		; empty MMX state
725
726
.return:
727
	pop	edi
728
	pop	esi
729
;	pop	edx		; need not be preserved
730
;	pop	ecx		; need not be preserved
731
	pop	ebx
732
	pop	ebp
733
	ret
734
735
; For some reason, the OS X linker does not honor the request to align the
736
; segment unless we do this.
737
	align	16
(-)a/jpeg/simd/jdsamss2-64.asm (+671 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdsamss2-64.asm - upsampling (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; [TAB8]
19
20
%include "jsimdext.inc"
21
22
; --------------------------------------------------------------------------
23
	SECTION	SEG_CONST
24
25
	alignz	16
26
	global	EXTN(jconst_fancy_upsample_sse2)
27
28
EXTN(jconst_fancy_upsample_sse2):
29
30
PW_ONE		times 8 dw  1
31
PW_TWO		times 8 dw  2
32
PW_THREE	times 8 dw  3
33
PW_SEVEN	times 8 dw  7
34
PW_EIGHT	times 8 dw  8
35
36
	alignz	16
37
38
; --------------------------------------------------------------------------
39
	SECTION	SEG_TEXT
40
	BITS	64
41
;
42
; Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
43
;
44
; The upsampling algorithm is linear interpolation between pixel centers,
45
; also known as a "triangle filter".  This is a good compromise between
46
; speed and visual quality.  The centers of the output pixels are 1/4 and 3/4
47
; of the way between input pixel centers.
48
;
49
; GLOBAL(void)
50
; jsimd_h2v1_fancy_upsample_sse2 (int max_v_samp_factor,
51
;                                 JDIMENSION downsampled_width,
52
;                                 JSAMPARRAY input_data,
53
;                                 JSAMPARRAY * output_data_ptr);
54
;
55
56
; r10 = int max_v_samp_factor
57
; r11 = JDIMENSION downsampled_width
58
; r12 = JSAMPARRAY input_data
59
; r13 = JSAMPARRAY * output_data_ptr
60
61
	align	16
62
	global	EXTN(jsimd_h2v1_fancy_upsample_sse2)
63
64
EXTN(jsimd_h2v1_fancy_upsample_sse2):
65
	push	rbp
66
	mov	rax,rsp
67
	mov	rbp,rsp
68
	collect_args
69
70
	mov	rax, r11  ; colctr
71
	test	rax,rax
72
	jz	near .return
73
74
	mov	rcx, r10	; rowctr
75
	test	rcx,rcx
76
	jz	near .return
77
78
	mov	rsi, r12	; input_data
79
	mov	rdi, r13
80
	mov	rdi, JSAMPARRAY [rdi]			; output_data
81
.rowloop:
82
	push	rax			; colctr
83
	push	rdi
84
	push	rsi
85
86
	mov	rsi, JSAMPROW [rsi]	; inptr
87
	mov	rdi, JSAMPROW [rdi]	; outptr
88
89
	test	rax, SIZEOF_XMMWORD-1
90
	jz	short .skip
91
	mov	dl, JSAMPLE [rsi+(rax-1)*SIZEOF_JSAMPLE]
92
	mov	JSAMPLE [rsi+rax*SIZEOF_JSAMPLE], dl	; insert a dummy sample
93
.skip:
94
	pxor	xmm0,xmm0		; xmm0=(all 0's)
95
	pcmpeqb	xmm7,xmm7
96
	psrldq	xmm7,(SIZEOF_XMMWORD-1)
97
	pand	xmm7, XMMWORD [rsi+0*SIZEOF_XMMWORD]
98
99
	add	rax, byte SIZEOF_XMMWORD-1
100
	and	rax, byte -SIZEOF_XMMWORD
101
	cmp	rax, byte SIZEOF_XMMWORD
102
	ja	short .columnloop
103
104
.columnloop_last:
105
	pcmpeqb	xmm6,xmm6
106
	pslldq	xmm6,(SIZEOF_XMMWORD-1)
107
	pand	xmm6, XMMWORD [rsi+0*SIZEOF_XMMWORD]
108
	jmp	short .upsample
109
110
.columnloop:
111
	movdqa	xmm6, XMMWORD [rsi+1*SIZEOF_XMMWORD]
112
	pslldq	xmm6,(SIZEOF_XMMWORD-1)
113
114
.upsample:
115
	movdqa	xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD]
116
	movdqa	xmm2,xmm1
117
	movdqa	xmm3,xmm1		; xmm1=( 0  1  2 ... 13 14 15)
118
	pslldq	xmm2,1			; xmm2=(--  0  1 ... 12 13 14)
119
	psrldq	xmm3,1			; xmm3=( 1  2  3 ... 14 15 --)
120
121
	por	xmm2,xmm7		; xmm2=(-1  0  1 ... 12 13 14)
122
	por	xmm3,xmm6		; xmm3=( 1  2  3 ... 14 15 16)
123
124
	movdqa	xmm7,xmm1
125
	psrldq	xmm7,(SIZEOF_XMMWORD-1)	; xmm7=(15 -- -- ... -- -- --)
126
127
	movdqa    xmm4,xmm1
128
	punpcklbw xmm1,xmm0		; xmm1=( 0  1  2  3  4  5  6  7)
129
	punpckhbw xmm4,xmm0		; xmm4=( 8  9 10 11 12 13 14 15)
130
	movdqa    xmm5,xmm2
131
	punpcklbw xmm2,xmm0		; xmm2=(-1  0  1  2  3  4  5  6)
132
	punpckhbw xmm5,xmm0		; xmm5=( 7  8  9 10 11 12 13 14)
133
	movdqa    xmm6,xmm3
134
	punpcklbw xmm3,xmm0		; xmm3=( 1  2  3  4  5  6  7  8)
135
	punpckhbw xmm6,xmm0		; xmm6=( 9 10 11 12 13 14 15 16)
136
137
	pmullw	xmm1,[rel PW_THREE]
138
	pmullw	xmm4,[rel PW_THREE]
139
	paddw	xmm2,[rel PW_ONE]
140
	paddw	xmm5,[rel PW_ONE]
141
	paddw	xmm3,[rel PW_TWO]
142
	paddw	xmm6,[rel PW_TWO]
143
144
	paddw	xmm2,xmm1
145
	paddw	xmm5,xmm4
146
	psrlw	xmm2,2			; xmm2=OutLE=( 0  2  4  6  8 10 12 14)
147
	psrlw	xmm5,2			; xmm5=OutHE=(16 18 20 22 24 26 28 30)
148
	paddw	xmm3,xmm1
149
	paddw	xmm6,xmm4
150
	psrlw	xmm3,2			; xmm3=OutLO=( 1  3  5  7  9 11 13 15)
151
	psrlw	xmm6,2			; xmm6=OutHO=(17 19 21 23 25 27 29 31)
152
153
	psllw	xmm3,BYTE_BIT
154
	psllw	xmm6,BYTE_BIT
155
	por	xmm2,xmm3		; xmm2=OutL=( 0  1  2 ... 13 14 15)
156
	por	xmm5,xmm6		; xmm5=OutH=(16 17 18 ... 29 30 31)
157
158
	movdqa	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm2
159
	movdqa	XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm5
160
161
	sub	rax, byte SIZEOF_XMMWORD
162
	add	rsi, byte 1*SIZEOF_XMMWORD	; inptr
163
	add	rdi, byte 2*SIZEOF_XMMWORD	; outptr
164
	cmp	rax, byte SIZEOF_XMMWORD
165
	ja	near .columnloop
166
	test	eax,eax
167
	jnz	near .columnloop_last
168
169
	pop	rsi
170
	pop	rdi
171
	pop	rax
172
173
	add	rsi, byte SIZEOF_JSAMPROW	; input_data
174
	add	rdi, byte SIZEOF_JSAMPROW	; output_data
175
	dec	rcx				; rowctr
176
	jg	near .rowloop
177
178
.return:
179
	uncollect_args
180
	pop	rbp
181
	ret
182
183
; --------------------------------------------------------------------------
184
;
185
; Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
186
; Again a triangle filter; see comments for h2v1 case, above.
187
;
188
; GLOBAL(void)
189
; jsimd_h2v2_fancy_upsample_sse2 (int max_v_samp_factor,
190
;                                 JDIMENSION downsampled_width,
191
;                                 JSAMPARRAY input_data,
192
;                                 JSAMPARRAY * output_data_ptr);
193
;
194
195
; r10 = int max_v_samp_factor
196
; r11 = JDIMENSION downsampled_width
197
; r12 = JSAMPARRAY input_data
198
; r13 = JSAMPARRAY * output_data_ptr
199
200
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
201
%define WK_NUM		4
202
203
	align	16
204
	global	EXTN(jsimd_h2v2_fancy_upsample_sse2)
205
206
EXTN(jsimd_h2v2_fancy_upsample_sse2):
207
	push	rbp
208
	mov	rax,rsp				; rax = original rbp
209
	sub	rsp, byte 4
210
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
211
	mov	[rsp],rax
212
	mov	rbp,rsp				; rbp = aligned rbp
213
	lea	rsp, [wk(0)]
214
	collect_args
215
	push	rbx
216
217
	mov	rax, r11  ; colctr
218
	test	rax,rax
219
	jz	near .return
220
221
	mov	rcx, r10	; rowctr
222
	test	rcx,rcx
223
	jz	near .return
224
225
	mov	rsi, r12	; input_data
226
	mov	rdi, r13
227
	mov	rdi, JSAMPARRAY [rdi]			; output_data
228
.rowloop:
229
	push	rax					; colctr
230
	push	rcx
231
	push	rdi
232
	push	rsi
233
234
	mov	rcx, JSAMPROW [rsi-1*SIZEOF_JSAMPROW]	; inptr1(above)
235
	mov	rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW]	; inptr0
236
	mov	rsi, JSAMPROW [rsi+1*SIZEOF_JSAMPROW]	; inptr1(below)
237
	mov	rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]	; outptr0
238
	mov	rdi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]	; outptr1
239
240
	test	rax, SIZEOF_XMMWORD-1
241
	jz	short .skip
242
	push	rdx
243
	mov	dl, JSAMPLE [rcx+(rax-1)*SIZEOF_JSAMPLE]
244
	mov	JSAMPLE [rcx+rax*SIZEOF_JSAMPLE], dl
245
	mov	dl, JSAMPLE [rbx+(rax-1)*SIZEOF_JSAMPLE]
246
	mov	JSAMPLE [rbx+rax*SIZEOF_JSAMPLE], dl
247
	mov	dl, JSAMPLE [rsi+(rax-1)*SIZEOF_JSAMPLE]
248
	mov	JSAMPLE [rsi+rax*SIZEOF_JSAMPLE], dl	; insert a dummy sample
249
	pop	rdx
250
.skip:
251
	; -- process the first column block
252
253
	movdqa	xmm0, XMMWORD [rbx+0*SIZEOF_XMMWORD]	; xmm0=row[ 0][0]
254
	movdqa	xmm1, XMMWORD [rcx+0*SIZEOF_XMMWORD]	; xmm1=row[-1][0]
255
	movdqa	xmm2, XMMWORD [rsi+0*SIZEOF_XMMWORD]	; xmm2=row[+1][0]
256
257
	pxor      xmm3,xmm3		; xmm3=(all 0's)
258
	movdqa    xmm4,xmm0
259
	punpcklbw xmm0,xmm3		; xmm0=row[ 0]( 0  1  2  3  4  5  6  7)
260
	punpckhbw xmm4,xmm3		; xmm4=row[ 0]( 8  9 10 11 12 13 14 15)
261
	movdqa    xmm5,xmm1
262
	punpcklbw xmm1,xmm3		; xmm1=row[-1]( 0  1  2  3  4  5  6  7)
263
	punpckhbw xmm5,xmm3		; xmm5=row[-1]( 8  9 10 11 12 13 14 15)
264
	movdqa    xmm6,xmm2
265
	punpcklbw xmm2,xmm3		; xmm2=row[+1]( 0  1  2  3  4  5  6  7)
266
	punpckhbw xmm6,xmm3		; xmm6=row[+1]( 8  9 10 11 12 13 14 15)
267
268
	pmullw	xmm0,[rel PW_THREE]
269
	pmullw	xmm4,[rel PW_THREE]
270
271
	pcmpeqb	xmm7,xmm7
272
	psrldq	xmm7,(SIZEOF_XMMWORD-2)
273
274
	paddw	xmm1,xmm0		; xmm1=Int0L=( 0  1  2  3  4  5  6  7)
275
	paddw	xmm5,xmm4		; xmm5=Int0H=( 8  9 10 11 12 13 14 15)
276
	paddw	xmm2,xmm0		; xmm2=Int1L=( 0  1  2  3  4  5  6  7)
277
	paddw	xmm6,xmm4		; xmm6=Int1H=( 8  9 10 11 12 13 14 15)
278
279
	movdqa	XMMWORD [rdx+0*SIZEOF_XMMWORD], xmm1	; temporarily save
280
	movdqa	XMMWORD [rdx+1*SIZEOF_XMMWORD], xmm5	; the intermediate data
281
	movdqa	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm2
282
	movdqa	XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm6
283
284
	pand	xmm1,xmm7		; xmm1=( 0 -- -- -- -- -- -- --)
285
	pand	xmm2,xmm7		; xmm2=( 0 -- -- -- -- -- -- --)
286
287
	movdqa	XMMWORD [wk(0)], xmm1
288
	movdqa	XMMWORD [wk(1)], xmm2
289
290
	add	rax, byte SIZEOF_XMMWORD-1
291
	and	rax, byte -SIZEOF_XMMWORD
292
	cmp	rax, byte SIZEOF_XMMWORD
293
	ja	short .columnloop
294
295
.columnloop_last:
296
	; -- process the last column block
297
298
	pcmpeqb	xmm1,xmm1
299
	pslldq	xmm1,(SIZEOF_XMMWORD-2)
300
	movdqa	xmm2,xmm1
301
302
	pand	xmm1, XMMWORD [rdx+1*SIZEOF_XMMWORD]
303
	pand	xmm2, XMMWORD [rdi+1*SIZEOF_XMMWORD]
304
305
	movdqa	XMMWORD [wk(2)], xmm1	; xmm1=(-- -- -- -- -- -- -- 15)
306
	movdqa	XMMWORD [wk(3)], xmm2	; xmm2=(-- -- -- -- -- -- -- 15)
307
308
	jmp	near .upsample
309
310
.columnloop:
311
	; -- process the next column block
312
313
	movdqa	xmm0, XMMWORD [rbx+1*SIZEOF_XMMWORD]	; xmm0=row[ 0][1]
314
	movdqa	xmm1, XMMWORD [rcx+1*SIZEOF_XMMWORD]	; xmm1=row[-1][1]
315
	movdqa	xmm2, XMMWORD [rsi+1*SIZEOF_XMMWORD]	; xmm2=row[+1][1]
316
317
	pxor      xmm3,xmm3		; xmm3=(all 0's)
318
	movdqa    xmm4,xmm0
319
	punpcklbw xmm0,xmm3		; xmm0=row[ 0]( 0  1  2  3  4  5  6  7)
320
	punpckhbw xmm4,xmm3		; xmm4=row[ 0]( 8  9 10 11 12 13 14 15)
321
	movdqa    xmm5,xmm1
322
	punpcklbw xmm1,xmm3		; xmm1=row[-1]( 0  1  2  3  4  5  6  7)
323
	punpckhbw xmm5,xmm3		; xmm5=row[-1]( 8  9 10 11 12 13 14 15)
324
	movdqa    xmm6,xmm2
325
	punpcklbw xmm2,xmm3		; xmm2=row[+1]( 0  1  2  3  4  5  6  7)
326
	punpckhbw xmm6,xmm3		; xmm6=row[+1]( 8  9 10 11 12 13 14 15)
327
328
	pmullw	xmm0,[rel PW_THREE]
329
	pmullw	xmm4,[rel PW_THREE]
330
331
	paddw	xmm1,xmm0		; xmm1=Int0L=( 0  1  2  3  4  5  6  7)
332
	paddw	xmm5,xmm4		; xmm5=Int0H=( 8  9 10 11 12 13 14 15)
333
	paddw	xmm2,xmm0		; xmm2=Int1L=( 0  1  2  3  4  5  6  7)
334
	paddw	xmm6,xmm4		; xmm6=Int1H=( 8  9 10 11 12 13 14 15)
335
336
	movdqa	XMMWORD [rdx+2*SIZEOF_XMMWORD], xmm1	; temporarily save
337
	movdqa	XMMWORD [rdx+3*SIZEOF_XMMWORD], xmm5	; the intermediate data
338
	movdqa	XMMWORD [rdi+2*SIZEOF_XMMWORD], xmm2
339
	movdqa	XMMWORD [rdi+3*SIZEOF_XMMWORD], xmm6
340
341
	pslldq	xmm1,(SIZEOF_XMMWORD-2)	; xmm1=(-- -- -- -- -- -- --  0)
342
	pslldq	xmm2,(SIZEOF_XMMWORD-2)	; xmm2=(-- -- -- -- -- -- --  0)
343
344
	movdqa	XMMWORD [wk(2)], xmm1
345
	movdqa	XMMWORD [wk(3)], xmm2
346
347
.upsample:
348
	; -- process the upper row
349
350
	movdqa	xmm7, XMMWORD [rdx+0*SIZEOF_XMMWORD]
351
	movdqa	xmm3, XMMWORD [rdx+1*SIZEOF_XMMWORD]
352
353
	movdqa	xmm0,xmm7		; xmm7=Int0L=( 0  1  2  3  4  5  6  7)
354
	movdqa	xmm4,xmm3		; xmm3=Int0H=( 8  9 10 11 12 13 14 15)
355
	psrldq	xmm0,2			; xmm0=( 1  2  3  4  5  6  7 --)
356
	pslldq	xmm4,(SIZEOF_XMMWORD-2)	; xmm4=(-- -- -- -- -- -- --  8)
357
	movdqa	xmm5,xmm7
358
	movdqa	xmm6,xmm3
359
	psrldq	xmm5,(SIZEOF_XMMWORD-2)	; xmm5=( 7 -- -- -- -- -- -- --)
360
	pslldq	xmm6,2			; xmm6=(--  8  9 10 11 12 13 14)
361
362
	por	xmm0,xmm4		; xmm0=( 1  2  3  4  5  6  7  8)
363
	por	xmm5,xmm6		; xmm5=( 7  8  9 10 11 12 13 14)
364
365
	movdqa	xmm1,xmm7
366
	movdqa	xmm2,xmm3
367
	pslldq	xmm1,2			; xmm1=(--  0  1  2  3  4  5  6)
368
	psrldq	xmm2,2			; xmm2=( 9 10 11 12 13 14 15 --)
369
	movdqa	xmm4,xmm3
370
	psrldq	xmm4,(SIZEOF_XMMWORD-2)	; xmm4=(15 -- -- -- -- -- -- --)
371
372
	por	xmm1, XMMWORD [wk(0)]	; xmm1=(-1  0  1  2  3  4  5  6)
373
	por	xmm2, XMMWORD [wk(2)]	; xmm2=( 9 10 11 12 13 14 15 16)
374
375
	movdqa	XMMWORD [wk(0)], xmm4
376
377
	pmullw	xmm7,[rel PW_THREE]
378
	pmullw	xmm3,[rel PW_THREE]
379
	paddw	xmm1,[rel PW_EIGHT]
380
	paddw	xmm5,[rel PW_EIGHT]
381
	paddw	xmm0,[rel PW_SEVEN]
382
	paddw	xmm2,[rel PW_SEVEN]
383
384
	paddw	xmm1,xmm7
385
	paddw	xmm5,xmm3
386
	psrlw	xmm1,4			; xmm1=Out0LE=( 0  2  4  6  8 10 12 14)
387
	psrlw	xmm5,4			; xmm5=Out0HE=(16 18 20 22 24 26 28 30)
388
	paddw	xmm0,xmm7
389
	paddw	xmm2,xmm3
390
	psrlw	xmm0,4			; xmm0=Out0LO=( 1  3  5  7  9 11 13 15)
391
	psrlw	xmm2,4			; xmm2=Out0HO=(17 19 21 23 25 27 29 31)
392
393
	psllw	xmm0,BYTE_BIT
394
	psllw	xmm2,BYTE_BIT
395
	por	xmm1,xmm0		; xmm1=Out0L=( 0  1  2 ... 13 14 15)
396
	por	xmm5,xmm2		; xmm5=Out0H=(16 17 18 ... 29 30 31)
397
398
	movdqa	XMMWORD [rdx+0*SIZEOF_XMMWORD], xmm1
399
	movdqa	XMMWORD [rdx+1*SIZEOF_XMMWORD], xmm5
400
401
	; -- process the lower row
402
403
	movdqa	xmm6, XMMWORD [rdi+0*SIZEOF_XMMWORD]
404
	movdqa	xmm4, XMMWORD [rdi+1*SIZEOF_XMMWORD]
405
406
	movdqa	xmm7,xmm6		; xmm6=Int1L=( 0  1  2  3  4  5  6  7)
407
	movdqa	xmm3,xmm4		; xmm4=Int1H=( 8  9 10 11 12 13 14 15)
408
	psrldq	xmm7,2			; xmm7=( 1  2  3  4  5  6  7 --)
409
	pslldq	xmm3,(SIZEOF_XMMWORD-2)	; xmm3=(-- -- -- -- -- -- --  8)
410
	movdqa	xmm0,xmm6
411
	movdqa	xmm2,xmm4
412
	psrldq	xmm0,(SIZEOF_XMMWORD-2)	; xmm0=( 7 -- -- -- -- -- -- --)
413
	pslldq	xmm2,2			; xmm2=(--  8  9 10 11 12 13 14)
414
415
	por	xmm7,xmm3		; xmm7=( 1  2  3  4  5  6  7  8)
416
	por	xmm0,xmm2		; xmm0=( 7  8  9 10 11 12 13 14)
417
418
	movdqa	xmm1,xmm6
419
	movdqa	xmm5,xmm4
420
	pslldq	xmm1,2			; xmm1=(--  0  1  2  3  4  5  6)
421
	psrldq	xmm5,2			; xmm5=( 9 10 11 12 13 14 15 --)
422
	movdqa	xmm3,xmm4
423
	psrldq	xmm3,(SIZEOF_XMMWORD-2)	; xmm3=(15 -- -- -- -- -- -- --)
424
425
	por	xmm1, XMMWORD [wk(1)]	; xmm1=(-1  0  1  2  3  4  5  6)
426
	por	xmm5, XMMWORD [wk(3)]	; xmm5=( 9 10 11 12 13 14 15 16)
427
428
	movdqa	XMMWORD [wk(1)], xmm3
429
430
	pmullw	xmm6,[rel PW_THREE]
431
	pmullw	xmm4,[rel PW_THREE]
432
	paddw	xmm1,[rel PW_EIGHT]
433
	paddw	xmm0,[rel PW_EIGHT]
434
	paddw	xmm7,[rel PW_SEVEN]
435
	paddw	xmm5,[rel PW_SEVEN]
436
437
	paddw	xmm1,xmm6
438
	paddw	xmm0,xmm4
439
	psrlw	xmm1,4			; xmm1=Out1LE=( 0  2  4  6  8 10 12 14)
440
	psrlw	xmm0,4			; xmm0=Out1HE=(16 18 20 22 24 26 28 30)
441
	paddw	xmm7,xmm6
442
	paddw	xmm5,xmm4
443
	psrlw	xmm7,4			; xmm7=Out1LO=( 1  3  5  7  9 11 13 15)
444
	psrlw	xmm5,4			; xmm5=Out1HO=(17 19 21 23 25 27 29 31)
445
446
	psllw	xmm7,BYTE_BIT
447
	psllw	xmm5,BYTE_BIT
448
	por	xmm1,xmm7		; xmm1=Out1L=( 0  1  2 ... 13 14 15)
449
	por	xmm0,xmm5		; xmm0=Out1H=(16 17 18 ... 29 30 31)
450
451
	movdqa	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm1
452
	movdqa	XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm0
453
454
	sub	rax, byte SIZEOF_XMMWORD
455
	add	rcx, byte 1*SIZEOF_XMMWORD	; inptr1(above)
456
	add	rbx, byte 1*SIZEOF_XMMWORD	; inptr0
457
	add	rsi, byte 1*SIZEOF_XMMWORD	; inptr1(below)
458
	add	rdx, byte 2*SIZEOF_XMMWORD	; outptr0
459
	add	rdi, byte 2*SIZEOF_XMMWORD	; outptr1
460
	cmp	rax, byte SIZEOF_XMMWORD
461
	ja	near .columnloop
462
	test	rax,rax
463
	jnz	near .columnloop_last
464
465
	pop	rsi
466
	pop	rdi
467
	pop	rcx
468
	pop	rax
469
470
	add	rsi, byte 1*SIZEOF_JSAMPROW	; input_data
471
	add	rdi, byte 2*SIZEOF_JSAMPROW	; output_data
472
	sub	rcx, byte 2			; rowctr
473
	jg	near .rowloop
474
475
.return:
476
	pop	rbx
477
	uncollect_args
478
	mov	rsp,rbp		; rsp <- aligned rbp
479
	pop	rsp		; rsp <- original rbp
480
	pop	rbp
481
	ret
482
483
; --------------------------------------------------------------------------
484
;
485
; Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
486
; It's still a box filter.
487
;
488
; GLOBAL(void)
489
; jsimd_h2v1_upsample_sse2 (int max_v_samp_factor,
490
;                           JDIMENSION output_width,
491
;                           JSAMPARRAY input_data,
492
;                           JSAMPARRAY * output_data_ptr);
493
;
494
495
; r10 = int max_v_samp_factor
496
; r11 = JDIMENSION output_width
497
; r12 = JSAMPARRAY input_data
498
; r13 = JSAMPARRAY * output_data_ptr
499
500
	align	16
501
	global	EXTN(jsimd_h2v1_upsample_sse2)
502
503
EXTN(jsimd_h2v1_upsample_sse2):
504
	push	rbp
505
	mov	rax,rsp
506
	mov	rbp,rsp
507
	collect_args
508
509
	mov	rdx, r11
510
	add	rdx, byte (2*SIZEOF_XMMWORD)-1
511
	and	rdx, byte -(2*SIZEOF_XMMWORD)
512
	jz	near .return
513
514
	mov	rcx, r10	; rowctr
515
	test	rcx,rcx
516
	jz	short .return
517
518
	mov	rsi, r12 ; input_data
519
	mov	rdi, r13
520
	mov	rdi, JSAMPARRAY [rdi]			; output_data
521
.rowloop:
522
	push	rdi
523
	push	rsi
524
525
	mov	rsi, JSAMPROW [rsi]		; inptr
526
	mov	rdi, JSAMPROW [rdi]		; outptr
527
	mov	rax,rdx				; colctr
528
.columnloop:
529
530
	movdqa	xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD]
531
532
	movdqa    xmm1,xmm0
533
	punpcklbw xmm0,xmm0
534
	punpckhbw xmm1,xmm1
535
536
	movdqa	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0
537
	movdqa	XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm1
538
539
	sub	rax, byte 2*SIZEOF_XMMWORD
540
	jz	short .nextrow
541
542
	movdqa	xmm2, XMMWORD [rsi+1*SIZEOF_XMMWORD]
543
544
	movdqa    xmm3,xmm2
545
	punpcklbw xmm2,xmm2
546
	punpckhbw xmm3,xmm3
547
548
	movdqa	XMMWORD [rdi+2*SIZEOF_XMMWORD], xmm2
549
	movdqa	XMMWORD [rdi+3*SIZEOF_XMMWORD], xmm3
550
551
	sub	rax, byte 2*SIZEOF_XMMWORD
552
	jz	short .nextrow
553
554
	add	rsi, byte 2*SIZEOF_XMMWORD	; inptr
555
	add	rdi, byte 4*SIZEOF_XMMWORD	; outptr
556
	jmp	short .columnloop
557
558
.nextrow:
559
	pop	rsi
560
	pop	rdi
561
562
	add	rsi, byte SIZEOF_JSAMPROW	; input_data
563
	add	rdi, byte SIZEOF_JSAMPROW	; output_data
564
	dec	rcx				; rowctr
565
	jg	short .rowloop
566
567
.return:
568
	uncollect_args
569
	pop	rbp
570
	ret
571
572
; --------------------------------------------------------------------------
573
;
574
; Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
575
; It's still a box filter.
576
;
577
; GLOBAL(void)
578
; jsimd_h2v2_upsample_sse2 (nt max_v_samp_factor,
579
;                           JDIMENSION output_width,
580
;                           JSAMPARRAY input_data,
581
;                           JSAMPARRAY * output_data_ptr);
582
;
583
584
; r10 = int max_v_samp_factor
585
; r11 = JDIMENSION output_width
586
; r12 = JSAMPARRAY input_data
587
; r13 = JSAMPARRAY * output_data_ptr
588
589
	align	16
590
	global	EXTN(jsimd_h2v2_upsample_sse2)
591
592
EXTN(jsimd_h2v2_upsample_sse2):
593
	push	rbp
594
	mov	rax,rsp
595
	mov	rbp,rsp
596
	collect_args
597
	push	rbx
598
599
	mov	rdx, r11
600
	add	rdx, byte (2*SIZEOF_XMMWORD)-1
601
	and	rdx, byte -(2*SIZEOF_XMMWORD)
602
	jz	near .return
603
604
	mov	rcx, r10	; rowctr
605
	test	rcx,rcx
606
	jz	near .return
607
608
	mov	rsi, r12	; input_data
609
	mov	rdi, r13
610
	mov	rdi, JSAMPARRAY [rdi]			; output_data
611
.rowloop:
612
	push	rdi
613
	push	rsi
614
615
	mov	rsi, JSAMPROW [rsi]			; inptr
616
	mov	rbx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]	; outptr0
617
	mov	rdi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]	; outptr1
618
	mov	rax,rdx					; colctr
619
.columnloop:
620
621
	movdqa	xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD]
622
623
	movdqa    xmm1,xmm0
624
	punpcklbw xmm0,xmm0
625
	punpckhbw xmm1,xmm1
626
627
	movdqa	XMMWORD [rbx+0*SIZEOF_XMMWORD], xmm0
628
	movdqa	XMMWORD [rbx+1*SIZEOF_XMMWORD], xmm1
629
	movdqa	XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0
630
	movdqa	XMMWORD [rdi+1*SIZEOF_XMMWORD], xmm1
631
632
	sub	rax, byte 2*SIZEOF_XMMWORD
633
	jz	short .nextrow
634
635
	movdqa	xmm2, XMMWORD [rsi+1*SIZEOF_XMMWORD]
636
637
	movdqa    xmm3,xmm2
638
	punpcklbw xmm2,xmm2
639
	punpckhbw xmm3,xmm3
640
641
	movdqa	XMMWORD [rbx+2*SIZEOF_XMMWORD], xmm2
642
	movdqa	XMMWORD [rbx+3*SIZEOF_XMMWORD], xmm3
643
	movdqa	XMMWORD [rdi+2*SIZEOF_XMMWORD], xmm2
644
	movdqa	XMMWORD [rdi+3*SIZEOF_XMMWORD], xmm3
645
646
	sub	rax, byte 2*SIZEOF_XMMWORD
647
	jz	short .nextrow
648
649
	add	rsi, byte 2*SIZEOF_XMMWORD	; inptr
650
	add	rbx, byte 4*SIZEOF_XMMWORD	; outptr0
651
	add	rdi, byte 4*SIZEOF_XMMWORD	; outptr1
652
	jmp	short .columnloop
653
654
.nextrow:
655
	pop	rsi
656
	pop	rdi
657
658
	add	rsi, byte 1*SIZEOF_JSAMPROW	; input_data
659
	add	rdi, byte 2*SIZEOF_JSAMPROW	; output_data
660
	sub	rcx, byte 2			; rowctr
661
	jg	near .rowloop
662
663
.return:
664
	pop	rbx
665
	uncollect_args
666
	pop	rbp
667
	ret
668
669
; For some reason, the OS X linker does not honor the request to align the
670
; segment unless we do this.
671
	align	16
(-)a/jpeg/simd/jdsamss2.asm (+729 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jdsamss2.asm - upsampling (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_CONST
23
24
	alignz	16
25
	global	EXTN(jconst_fancy_upsample_sse2)
26
27
EXTN(jconst_fancy_upsample_sse2):
28
29
PW_ONE		times 8 dw  1
30
PW_TWO		times 8 dw  2
31
PW_THREE	times 8 dw  3
32
PW_SEVEN	times 8 dw  7
33
PW_EIGHT	times 8 dw  8
34
35
	alignz	16
36
37
; --------------------------------------------------------------------------
38
	SECTION	SEG_TEXT
39
	BITS	32
40
;
41
; Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
42
;
43
; The upsampling algorithm is linear interpolation between pixel centers,
44
; also known as a "triangle filter".  This is a good compromise between
45
; speed and visual quality.  The centers of the output pixels are 1/4 and 3/4
46
; of the way between input pixel centers.
47
;
48
; GLOBAL(void)
49
; jsimd_h2v1_fancy_upsample_sse2 (int max_v_samp_factor,
50
;                                 JDIMENSION downsampled_width,
51
;                                 JSAMPARRAY input_data,
52
;                                 JSAMPARRAY * output_data_ptr);
53
;
54
55
%define max_v_samp(b)		(b)+8			; int max_v_samp_factor
56
%define downsamp_width(b)	(b)+12	; JDIMENSION downsampled_width
57
%define input_data(b)		(b)+16		; JSAMPARRAY input_data
58
%define output_data_ptr(b)	(b)+20		; JSAMPARRAY * output_data_ptr
59
60
	align	16
61
	global	EXTN(jsimd_h2v1_fancy_upsample_sse2)
62
63
EXTN(jsimd_h2v1_fancy_upsample_sse2):
64
	push	ebp
65
	mov	ebp,esp
66
	pushpic	ebx
67
;	push	ecx		; need not be preserved
68
;	push	edx		; need not be preserved
69
	push	esi
70
	push	edi
71
72
	get_GOT	ebx		; get GOT address
73
74
	mov	eax, JDIMENSION [downsamp_width(ebp)]  ; colctr
75
	test	eax,eax
76
	jz	near .return
77
78
	mov	ecx, INT [max_v_samp(ebp)]	; rowctr
79
	test	ecx,ecx
80
	jz	near .return
81
82
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
83
	mov	edi, POINTER [output_data_ptr(ebp)]
84
	mov	edi, JSAMPARRAY [edi]			; output_data
85
	alignx	16,7
86
.rowloop:
87
	push	eax			; colctr
88
	push	edi
89
	push	esi
90
91
	mov	esi, JSAMPROW [esi]	; inptr
92
	mov	edi, JSAMPROW [edi]	; outptr
93
94
	test	eax, SIZEOF_XMMWORD-1
95
	jz	short .skip
96
	mov	dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE]
97
	mov	JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl	; insert a dummy sample
98
.skip:
99
	pxor	xmm0,xmm0		; xmm0=(all 0's)
100
	pcmpeqb	xmm7,xmm7
101
	psrldq	xmm7,(SIZEOF_XMMWORD-1)
102
	pand	xmm7, XMMWORD [esi+0*SIZEOF_XMMWORD]
103
104
	add	eax, byte SIZEOF_XMMWORD-1
105
	and	eax, byte -SIZEOF_XMMWORD
106
	cmp	eax, byte SIZEOF_XMMWORD
107
	ja	short .columnloop
108
	alignx	16,7
109
110
.columnloop_last:
111
	pcmpeqb	xmm6,xmm6
112
	pslldq	xmm6,(SIZEOF_XMMWORD-1)
113
	pand	xmm6, XMMWORD [esi+0*SIZEOF_XMMWORD]
114
	jmp	short .upsample
115
	alignx	16,7
116
117
.columnloop:
118
	movdqa	xmm6, XMMWORD [esi+1*SIZEOF_XMMWORD]
119
	pslldq	xmm6,(SIZEOF_XMMWORD-1)
120
121
.upsample:
122
	movdqa	xmm1, XMMWORD [esi+0*SIZEOF_XMMWORD]
123
	movdqa	xmm2,xmm1
124
	movdqa	xmm3,xmm1		; xmm1=( 0  1  2 ... 13 14 15)
125
	pslldq	xmm2,1			; xmm2=(--  0  1 ... 12 13 14)
126
	psrldq	xmm3,1			; xmm3=( 1  2  3 ... 14 15 --)
127
128
	por	xmm2,xmm7		; xmm2=(-1  0  1 ... 12 13 14)
129
	por	xmm3,xmm6		; xmm3=( 1  2  3 ... 14 15 16)
130
131
	movdqa	xmm7,xmm1
132
	psrldq	xmm7,(SIZEOF_XMMWORD-1)	; xmm7=(15 -- -- ... -- -- --)
133
134
	movdqa    xmm4,xmm1
135
	punpcklbw xmm1,xmm0		; xmm1=( 0  1  2  3  4  5  6  7)
136
	punpckhbw xmm4,xmm0		; xmm4=( 8  9 10 11 12 13 14 15)
137
	movdqa    xmm5,xmm2
138
	punpcklbw xmm2,xmm0		; xmm2=(-1  0  1  2  3  4  5  6)
139
	punpckhbw xmm5,xmm0		; xmm5=( 7  8  9 10 11 12 13 14)
140
	movdqa    xmm6,xmm3
141
	punpcklbw xmm3,xmm0		; xmm3=( 1  2  3  4  5  6  7  8)
142
	punpckhbw xmm6,xmm0		; xmm6=( 9 10 11 12 13 14 15 16)
143
144
	pmullw	xmm1,[GOTOFF(ebx,PW_THREE)]
145
	pmullw	xmm4,[GOTOFF(ebx,PW_THREE)]
146
	paddw	xmm2,[GOTOFF(ebx,PW_ONE)]
147
	paddw	xmm5,[GOTOFF(ebx,PW_ONE)]
148
	paddw	xmm3,[GOTOFF(ebx,PW_TWO)]
149
	paddw	xmm6,[GOTOFF(ebx,PW_TWO)]
150
151
	paddw	xmm2,xmm1
152
	paddw	xmm5,xmm4
153
	psrlw	xmm2,2			; xmm2=OutLE=( 0  2  4  6  8 10 12 14)
154
	psrlw	xmm5,2			; xmm5=OutHE=(16 18 20 22 24 26 28 30)
155
	paddw	xmm3,xmm1
156
	paddw	xmm6,xmm4
157
	psrlw	xmm3,2			; xmm3=OutLO=( 1  3  5  7  9 11 13 15)
158
	psrlw	xmm6,2			; xmm6=OutHO=(17 19 21 23 25 27 29 31)
159
160
	psllw	xmm3,BYTE_BIT
161
	psllw	xmm6,BYTE_BIT
162
	por	xmm2,xmm3		; xmm2=OutL=( 0  1  2 ... 13 14 15)
163
	por	xmm5,xmm6		; xmm5=OutH=(16 17 18 ... 29 30 31)
164
165
	movdqa	XMMWORD [edi+0*SIZEOF_XMMWORD], xmm2
166
	movdqa	XMMWORD [edi+1*SIZEOF_XMMWORD], xmm5
167
168
	sub	eax, byte SIZEOF_XMMWORD
169
	add	esi, byte 1*SIZEOF_XMMWORD	; inptr
170
	add	edi, byte 2*SIZEOF_XMMWORD	; outptr
171
	cmp	eax, byte SIZEOF_XMMWORD
172
	ja	near .columnloop
173
	test	eax,eax
174
	jnz	near .columnloop_last
175
176
	pop	esi
177
	pop	edi
178
	pop	eax
179
180
	add	esi, byte SIZEOF_JSAMPROW	; input_data
181
	add	edi, byte SIZEOF_JSAMPROW	; output_data
182
	dec	ecx				; rowctr
183
	jg	near .rowloop
184
185
.return:
186
	pop	edi
187
	pop	esi
188
;	pop	edx		; need not be preserved
189
;	pop	ecx		; need not be preserved
190
	poppic	ebx
191
	pop	ebp
192
	ret
193
194
; --------------------------------------------------------------------------
195
;
196
; Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
197
; Again a triangle filter; see comments for h2v1 case, above.
198
;
199
; GLOBAL(void)
200
; jsimd_h2v2_fancy_upsample_sse2 (int max_v_samp_factor,
201
;                                 JDIMENSION downsampled_width,
202
;                                 JSAMPARRAY input_data,
203
;                                 JSAMPARRAY * output_data_ptr);
204
;
205
206
%define max_v_samp(b)		(b)+8			; int max_v_samp_factor
207
%define downsamp_width(b)	(b)+12	; JDIMENSION downsampled_width
208
%define input_data(b)		(b)+16		; JSAMPARRAY input_data
209
%define output_data_ptr(b)	(b)+20		; JSAMPARRAY * output_data_ptr
210
211
%define original_ebp	ebp+0
212
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
213
%define WK_NUM		4
214
%define gotptr		wk(0)-SIZEOF_POINTER	; void * gotptr
215
216
	align	16
217
	global	EXTN(jsimd_h2v2_fancy_upsample_sse2)
218
219
EXTN(jsimd_h2v2_fancy_upsample_sse2):
220
	push	ebp
221
	mov	eax,esp				; eax = original ebp
222
	sub	esp, byte 4
223
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
224
	mov	[esp],eax
225
	mov	ebp,esp				; ebp = aligned ebp
226
	lea	esp, [wk(0)]
227
	pushpic	eax		; make a room for GOT address
228
	push	ebx
229
;	push	ecx		; need not be preserved
230
;	push	edx		; need not be preserved
231
	push	esi
232
	push	edi
233
234
	get_GOT	ebx			; get GOT address
235
	movpic	POINTER [gotptr], ebx	; save GOT address
236
237
	mov	edx,eax				; edx = original ebp
238
	mov	eax, JDIMENSION [downsamp_width(edx)]  ; colctr
239
	test	eax,eax
240
	jz	near .return
241
242
	mov	ecx, INT [max_v_samp(edx)]	; rowctr
243
	test	ecx,ecx
244
	jz	near .return
245
246
	mov	esi, JSAMPARRAY [input_data(edx)]	; input_data
247
	mov	edi, POINTER [output_data_ptr(edx)]
248
	mov	edi, JSAMPARRAY [edi]			; output_data
249
	alignx	16,7
250
.rowloop:
251
	push	eax					; colctr
252
	push	ecx
253
	push	edi
254
	push	esi
255
256
	mov	ecx, JSAMPROW [esi-1*SIZEOF_JSAMPROW]	; inptr1(above)
257
	mov	ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]	; inptr0
258
	mov	esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW]	; inptr1(below)
259
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]	; outptr0
260
	mov	edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]	; outptr1
261
262
	test	eax, SIZEOF_XMMWORD-1
263
	jz	short .skip
264
	push	edx
265
	mov	dl, JSAMPLE [ecx+(eax-1)*SIZEOF_JSAMPLE]
266
	mov	JSAMPLE [ecx+eax*SIZEOF_JSAMPLE], dl
267
	mov	dl, JSAMPLE [ebx+(eax-1)*SIZEOF_JSAMPLE]
268
	mov	JSAMPLE [ebx+eax*SIZEOF_JSAMPLE], dl
269
	mov	dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE]
270
	mov	JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl	; insert a dummy sample
271
	pop	edx
272
.skip:
273
	; -- process the first column block
274
275
	movdqa	xmm0, XMMWORD [ebx+0*SIZEOF_XMMWORD]	; xmm0=row[ 0][0]
276
	movdqa	xmm1, XMMWORD [ecx+0*SIZEOF_XMMWORD]	; xmm1=row[-1][0]
277
	movdqa	xmm2, XMMWORD [esi+0*SIZEOF_XMMWORD]	; xmm2=row[+1][0]
278
279
	pushpic	ebx
280
	movpic	ebx, POINTER [gotptr]	; load GOT address
281
282
	pxor      xmm3,xmm3		; xmm3=(all 0's)
283
	movdqa    xmm4,xmm0
284
	punpcklbw xmm0,xmm3		; xmm0=row[ 0]( 0  1  2  3  4  5  6  7)
285
	punpckhbw xmm4,xmm3		; xmm4=row[ 0]( 8  9 10 11 12 13 14 15)
286
	movdqa    xmm5,xmm1
287
	punpcklbw xmm1,xmm3		; xmm1=row[-1]( 0  1  2  3  4  5  6  7)
288
	punpckhbw xmm5,xmm3		; xmm5=row[-1]( 8  9 10 11 12 13 14 15)
289
	movdqa    xmm6,xmm2
290
	punpcklbw xmm2,xmm3		; xmm2=row[+1]( 0  1  2  3  4  5  6  7)
291
	punpckhbw xmm6,xmm3		; xmm6=row[+1]( 8  9 10 11 12 13 14 15)
292
293
	pmullw	xmm0,[GOTOFF(ebx,PW_THREE)]
294
	pmullw	xmm4,[GOTOFF(ebx,PW_THREE)]
295
296
	pcmpeqb	xmm7,xmm7
297
	psrldq	xmm7,(SIZEOF_XMMWORD-2)
298
299
	paddw	xmm1,xmm0		; xmm1=Int0L=( 0  1  2  3  4  5  6  7)
300
	paddw	xmm5,xmm4		; xmm5=Int0H=( 8  9 10 11 12 13 14 15)
301
	paddw	xmm2,xmm0		; xmm2=Int1L=( 0  1  2  3  4  5  6  7)
302
	paddw	xmm6,xmm4		; xmm6=Int1H=( 8  9 10 11 12 13 14 15)
303
304
	movdqa	XMMWORD [edx+0*SIZEOF_XMMWORD], xmm1	; temporarily save
305
	movdqa	XMMWORD [edx+1*SIZEOF_XMMWORD], xmm5	; the intermediate data
306
	movdqa	XMMWORD [edi+0*SIZEOF_XMMWORD], xmm2
307
	movdqa	XMMWORD [edi+1*SIZEOF_XMMWORD], xmm6
308
309
	pand	xmm1,xmm7		; xmm1=( 0 -- -- -- -- -- -- --)
310
	pand	xmm2,xmm7		; xmm2=( 0 -- -- -- -- -- -- --)
311
312
	movdqa	XMMWORD [wk(0)], xmm1
313
	movdqa	XMMWORD [wk(1)], xmm2
314
315
	poppic	ebx
316
317
	add	eax, byte SIZEOF_XMMWORD-1
318
	and	eax, byte -SIZEOF_XMMWORD
319
	cmp	eax, byte SIZEOF_XMMWORD
320
	ja	short .columnloop
321
	alignx	16,7
322
323
.columnloop_last:
324
	; -- process the last column block
325
326
	pushpic	ebx
327
	movpic	ebx, POINTER [gotptr]	; load GOT address
328
329
	pcmpeqb	xmm1,xmm1
330
	pslldq	xmm1,(SIZEOF_XMMWORD-2)
331
	movdqa	xmm2,xmm1
332
333
	pand	xmm1, XMMWORD [edx+1*SIZEOF_XMMWORD]
334
	pand	xmm2, XMMWORD [edi+1*SIZEOF_XMMWORD]
335
336
	movdqa	XMMWORD [wk(2)], xmm1	; xmm1=(-- -- -- -- -- -- -- 15)
337
	movdqa	XMMWORD [wk(3)], xmm2	; xmm2=(-- -- -- -- -- -- -- 15)
338
339
	jmp	near .upsample
340
	alignx	16,7
341
342
.columnloop:
343
	; -- process the next column block
344
345
	movdqa	xmm0, XMMWORD [ebx+1*SIZEOF_XMMWORD]	; xmm0=row[ 0][1]
346
	movdqa	xmm1, XMMWORD [ecx+1*SIZEOF_XMMWORD]	; xmm1=row[-1][1]
347
	movdqa	xmm2, XMMWORD [esi+1*SIZEOF_XMMWORD]	; xmm2=row[+1][1]
348
349
	pushpic	ebx
350
	movpic	ebx, POINTER [gotptr]	; load GOT address
351
352
	pxor      xmm3,xmm3		; xmm3=(all 0's)
353
	movdqa    xmm4,xmm0
354
	punpcklbw xmm0,xmm3		; xmm0=row[ 0]( 0  1  2  3  4  5  6  7)
355
	punpckhbw xmm4,xmm3		; xmm4=row[ 0]( 8  9 10 11 12 13 14 15)
356
	movdqa    xmm5,xmm1
357
	punpcklbw xmm1,xmm3		; xmm1=row[-1]( 0  1  2  3  4  5  6  7)
358
	punpckhbw xmm5,xmm3		; xmm5=row[-1]( 8  9 10 11 12 13 14 15)
359
	movdqa    xmm6,xmm2
360
	punpcklbw xmm2,xmm3		; xmm2=row[+1]( 0  1  2  3  4  5  6  7)
361
	punpckhbw xmm6,xmm3		; xmm6=row[+1]( 8  9 10 11 12 13 14 15)
362
363
	pmullw	xmm0,[GOTOFF(ebx,PW_THREE)]
364
	pmullw	xmm4,[GOTOFF(ebx,PW_THREE)]
365
366
	paddw	xmm1,xmm0		; xmm1=Int0L=( 0  1  2  3  4  5  6  7)
367
	paddw	xmm5,xmm4		; xmm5=Int0H=( 8  9 10 11 12 13 14 15)
368
	paddw	xmm2,xmm0		; xmm2=Int1L=( 0  1  2  3  4  5  6  7)
369
	paddw	xmm6,xmm4		; xmm6=Int1H=( 8  9 10 11 12 13 14 15)
370
371
	movdqa	XMMWORD [edx+2*SIZEOF_XMMWORD], xmm1	; temporarily save
372
	movdqa	XMMWORD [edx+3*SIZEOF_XMMWORD], xmm5	; the intermediate data
373
	movdqa	XMMWORD [edi+2*SIZEOF_XMMWORD], xmm2
374
	movdqa	XMMWORD [edi+3*SIZEOF_XMMWORD], xmm6
375
376
	pslldq	xmm1,(SIZEOF_XMMWORD-2)	; xmm1=(-- -- -- -- -- -- --  0)
377
	pslldq	xmm2,(SIZEOF_XMMWORD-2)	; xmm2=(-- -- -- -- -- -- --  0)
378
379
	movdqa	XMMWORD [wk(2)], xmm1
380
	movdqa	XMMWORD [wk(3)], xmm2
381
382
.upsample:
383
	; -- process the upper row
384
385
	movdqa	xmm7, XMMWORD [edx+0*SIZEOF_XMMWORD]
386
	movdqa	xmm3, XMMWORD [edx+1*SIZEOF_XMMWORD]
387
388
	movdqa	xmm0,xmm7		; xmm7=Int0L=( 0  1  2  3  4  5  6  7)
389
	movdqa	xmm4,xmm3		; xmm3=Int0H=( 8  9 10 11 12 13 14 15)
390
	psrldq	xmm0,2			; xmm0=( 1  2  3  4  5  6  7 --)
391
	pslldq	xmm4,(SIZEOF_XMMWORD-2)	; xmm4=(-- -- -- -- -- -- --  8)
392
	movdqa	xmm5,xmm7
393
	movdqa	xmm6,xmm3
394
	psrldq	xmm5,(SIZEOF_XMMWORD-2)	; xmm5=( 7 -- -- -- -- -- -- --)
395
	pslldq	xmm6,2			; xmm6=(--  8  9 10 11 12 13 14)
396
397
	por	xmm0,xmm4		; xmm0=( 1  2  3  4  5  6  7  8)
398
	por	xmm5,xmm6		; xmm5=( 7  8  9 10 11 12 13 14)
399
400
	movdqa	xmm1,xmm7
401
	movdqa	xmm2,xmm3
402
	pslldq	xmm1,2			; xmm1=(--  0  1  2  3  4  5  6)
403
	psrldq	xmm2,2			; xmm2=( 9 10 11 12 13 14 15 --)
404
	movdqa	xmm4,xmm3
405
	psrldq	xmm4,(SIZEOF_XMMWORD-2)	; xmm4=(15 -- -- -- -- -- -- --)
406
407
	por	xmm1, XMMWORD [wk(0)]	; xmm1=(-1  0  1  2  3  4  5  6)
408
	por	xmm2, XMMWORD [wk(2)]	; xmm2=( 9 10 11 12 13 14 15 16)
409
410
	movdqa	XMMWORD [wk(0)], xmm4
411
412
	pmullw	xmm7,[GOTOFF(ebx,PW_THREE)]
413
	pmullw	xmm3,[GOTOFF(ebx,PW_THREE)]
414
	paddw	xmm1,[GOTOFF(ebx,PW_EIGHT)]
415
	paddw	xmm5,[GOTOFF(ebx,PW_EIGHT)]
416
	paddw	xmm0,[GOTOFF(ebx,PW_SEVEN)]
417
	paddw	xmm2,[GOTOFF(ebx,PW_SEVEN)]
418
419
	paddw	xmm1,xmm7
420
	paddw	xmm5,xmm3
421
	psrlw	xmm1,4			; xmm1=Out0LE=( 0  2  4  6  8 10 12 14)
422
	psrlw	xmm5,4			; xmm5=Out0HE=(16 18 20 22 24 26 28 30)
423
	paddw	xmm0,xmm7
424
	paddw	xmm2,xmm3
425
	psrlw	xmm0,4			; xmm0=Out0LO=( 1  3  5  7  9 11 13 15)
426
	psrlw	xmm2,4			; xmm2=Out0HO=(17 19 21 23 25 27 29 31)
427
428
	psllw	xmm0,BYTE_BIT
429
	psllw	xmm2,BYTE_BIT
430
	por	xmm1,xmm0		; xmm1=Out0L=( 0  1  2 ... 13 14 15)
431
	por	xmm5,xmm2		; xmm5=Out0H=(16 17 18 ... 29 30 31)
432
433
	movdqa	XMMWORD [edx+0*SIZEOF_XMMWORD], xmm1
434
	movdqa	XMMWORD [edx+1*SIZEOF_XMMWORD], xmm5
435
436
	; -- process the lower row
437
438
	movdqa	xmm6, XMMWORD [edi+0*SIZEOF_XMMWORD]
439
	movdqa	xmm4, XMMWORD [edi+1*SIZEOF_XMMWORD]
440
441
	movdqa	xmm7,xmm6		; xmm6=Int1L=( 0  1  2  3  4  5  6  7)
442
	movdqa	xmm3,xmm4		; xmm4=Int1H=( 8  9 10 11 12 13 14 15)
443
	psrldq	xmm7,2			; xmm7=( 1  2  3  4  5  6  7 --)
444
	pslldq	xmm3,(SIZEOF_XMMWORD-2)	; xmm3=(-- -- -- -- -- -- --  8)
445
	movdqa	xmm0,xmm6
446
	movdqa	xmm2,xmm4
447
	psrldq	xmm0,(SIZEOF_XMMWORD-2)	; xmm0=( 7 -- -- -- -- -- -- --)
448
	pslldq	xmm2,2			; xmm2=(--  8  9 10 11 12 13 14)
449
450
	por	xmm7,xmm3		; xmm7=( 1  2  3  4  5  6  7  8)
451
	por	xmm0,xmm2		; xmm0=( 7  8  9 10 11 12 13 14)
452
453
	movdqa	xmm1,xmm6
454
	movdqa	xmm5,xmm4
455
	pslldq	xmm1,2			; xmm1=(--  0  1  2  3  4  5  6)
456
	psrldq	xmm5,2			; xmm5=( 9 10 11 12 13 14 15 --)
457
	movdqa	xmm3,xmm4
458
	psrldq	xmm3,(SIZEOF_XMMWORD-2)	; xmm3=(15 -- -- -- -- -- -- --)
459
460
	por	xmm1, XMMWORD [wk(1)]	; xmm1=(-1  0  1  2  3  4  5  6)
461
	por	xmm5, XMMWORD [wk(3)]	; xmm5=( 9 10 11 12 13 14 15 16)
462
463
	movdqa	XMMWORD [wk(1)], xmm3
464
465
	pmullw	xmm6,[GOTOFF(ebx,PW_THREE)]
466
	pmullw	xmm4,[GOTOFF(ebx,PW_THREE)]
467
	paddw	xmm1,[GOTOFF(ebx,PW_EIGHT)]
468
	paddw	xmm0,[GOTOFF(ebx,PW_EIGHT)]
469
	paddw	xmm7,[GOTOFF(ebx,PW_SEVEN)]
470
	paddw	xmm5,[GOTOFF(ebx,PW_SEVEN)]
471
472
	paddw	xmm1,xmm6
473
	paddw	xmm0,xmm4
474
	psrlw	xmm1,4			; xmm1=Out1LE=( 0  2  4  6  8 10 12 14)
475
	psrlw	xmm0,4			; xmm0=Out1HE=(16 18 20 22 24 26 28 30)
476
	paddw	xmm7,xmm6
477
	paddw	xmm5,xmm4
478
	psrlw	xmm7,4			; xmm7=Out1LO=( 1  3  5  7  9 11 13 15)
479
	psrlw	xmm5,4			; xmm5=Out1HO=(17 19 21 23 25 27 29 31)
480
481
	psllw	xmm7,BYTE_BIT
482
	psllw	xmm5,BYTE_BIT
483
	por	xmm1,xmm7		; xmm1=Out1L=( 0  1  2 ... 13 14 15)
484
	por	xmm0,xmm5		; xmm0=Out1H=(16 17 18 ... 29 30 31)
485
486
	movdqa	XMMWORD [edi+0*SIZEOF_XMMWORD], xmm1
487
	movdqa	XMMWORD [edi+1*SIZEOF_XMMWORD], xmm0
488
489
	poppic	ebx
490
491
	sub	eax, byte SIZEOF_XMMWORD
492
	add	ecx, byte 1*SIZEOF_XMMWORD	; inptr1(above)
493
	add	ebx, byte 1*SIZEOF_XMMWORD	; inptr0
494
	add	esi, byte 1*SIZEOF_XMMWORD	; inptr1(below)
495
	add	edx, byte 2*SIZEOF_XMMWORD	; outptr0
496
	add	edi, byte 2*SIZEOF_XMMWORD	; outptr1
497
	cmp	eax, byte SIZEOF_XMMWORD
498
	ja	near .columnloop
499
	test	eax,eax
500
	jnz	near .columnloop_last
501
502
	pop	esi
503
	pop	edi
504
	pop	ecx
505
	pop	eax
506
507
	add	esi, byte 1*SIZEOF_JSAMPROW	; input_data
508
	add	edi, byte 2*SIZEOF_JSAMPROW	; output_data
509
	sub	ecx, byte 2			; rowctr
510
	jg	near .rowloop
511
512
.return:
513
	pop	edi
514
	pop	esi
515
;	pop	edx		; need not be preserved
516
;	pop	ecx		; need not be preserved
517
	pop	ebx
518
	mov	esp,ebp		; esp <- aligned ebp
519
	pop	esp		; esp <- original ebp
520
	pop	ebp
521
	ret
522
523
; --------------------------------------------------------------------------
524
;
525
; Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
526
; It's still a box filter.
527
;
528
; GLOBAL(void)
529
; jsimd_h2v1_upsample_sse2 (int max_v_samp_factor,
530
;                           JDIMENSION output_width,
531
;                           JSAMPARRAY input_data,
532
;                           JSAMPARRAY * output_data_ptr);
533
;
534
535
%define max_v_samp(b)		(b)+8			; int max_v_samp_factor
536
%define output_width(b)	(b)+12		; JDIMENSION output_width
537
%define input_data(b)		(b)+16		; JSAMPARRAY input_data
538
%define output_data_ptr(b)	(b)+20		; JSAMPARRAY * output_data_ptr
539
540
	align	16
541
	global	EXTN(jsimd_h2v1_upsample_sse2)
542
543
EXTN(jsimd_h2v1_upsample_sse2):
544
	push	ebp
545
	mov	ebp,esp
546
;	push	ebx		; unused
547
;	push	ecx		; need not be preserved
548
;	push	edx		; need not be preserved
549
	push	esi
550
	push	edi
551
552
	mov	edx, JDIMENSION [output_width(ebp)]
553
	add	edx, byte (2*SIZEOF_XMMWORD)-1
554
	and	edx, byte -(2*SIZEOF_XMMWORD)
555
	jz	short .return
556
557
	mov	ecx, INT [max_v_samp(ebp)]	; rowctr
558
	test	ecx,ecx
559
	jz	short .return
560
561
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
562
	mov	edi, POINTER [output_data_ptr(ebp)]
563
	mov	edi, JSAMPARRAY [edi]			; output_data
564
	alignx	16,7
565
.rowloop:
566
	push	edi
567
	push	esi
568
569
	mov	esi, JSAMPROW [esi]		; inptr
570
	mov	edi, JSAMPROW [edi]		; outptr
571
	mov	eax,edx				; colctr
572
	alignx	16,7
573
.columnloop:
574
575
	movdqa	xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD]
576
577
	movdqa    xmm1,xmm0
578
	punpcklbw xmm0,xmm0
579
	punpckhbw xmm1,xmm1
580
581
	movdqa	XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0
582
	movdqa	XMMWORD [edi+1*SIZEOF_XMMWORD], xmm1
583
584
	sub	eax, byte 2*SIZEOF_XMMWORD
585
	jz	short .nextrow
586
587
	movdqa	xmm2, XMMWORD [esi+1*SIZEOF_XMMWORD]
588
589
	movdqa    xmm3,xmm2
590
	punpcklbw xmm2,xmm2
591
	punpckhbw xmm3,xmm3
592
593
	movdqa	XMMWORD [edi+2*SIZEOF_XMMWORD], xmm2
594
	movdqa	XMMWORD [edi+3*SIZEOF_XMMWORD], xmm3
595
596
	sub	eax, byte 2*SIZEOF_XMMWORD
597
	jz	short .nextrow
598
599
	add	esi, byte 2*SIZEOF_XMMWORD	; inptr
600
	add	edi, byte 4*SIZEOF_XMMWORD	; outptr
601
	jmp	short .columnloop
602
	alignx	16,7
603
604
.nextrow:
605
	pop	esi
606
	pop	edi
607
608
	add	esi, byte SIZEOF_JSAMPROW	; input_data
609
	add	edi, byte SIZEOF_JSAMPROW	; output_data
610
	dec	ecx				; rowctr
611
	jg	short .rowloop
612
613
.return:
614
	pop	edi
615
	pop	esi
616
;	pop	edx		; need not be preserved
617
;	pop	ecx		; need not be preserved
618
;	pop	ebx		; unused
619
	pop	ebp
620
	ret
621
622
; --------------------------------------------------------------------------
623
;
624
; Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
625
; It's still a box filter.
626
;
627
; GLOBAL(void)
628
; jsimd_h2v2_upsample_sse2 (nt max_v_samp_factor,
629
;                           JDIMENSION output_width,
630
;                           JSAMPARRAY input_data,
631
;                           JSAMPARRAY * output_data_ptr);
632
;
633
634
%define max_v_samp(b)		(b)+8			; int max_v_samp_factor
635
%define output_width(b)	(b)+12		; JDIMENSION output_width
636
%define input_data(b)		(b)+16		; JSAMPARRAY input_data
637
%define output_data_ptr(b)	(b)+20		; JSAMPARRAY * output_data_ptr
638
639
	align	16
640
	global	EXTN(jsimd_h2v2_upsample_sse2)
641
642
EXTN(jsimd_h2v2_upsample_sse2):
643
	push	ebp
644
	mov	ebp,esp
645
	push	ebx
646
;	push	ecx		; need not be preserved
647
;	push	edx		; need not be preserved
648
	push	esi
649
	push	edi
650
651
	mov	edx, JDIMENSION [output_width(ebp)]
652
	add	edx, byte (2*SIZEOF_XMMWORD)-1
653
	and	edx, byte -(2*SIZEOF_XMMWORD)
654
	jz	near .return
655
656
	mov	ecx, INT [max_v_samp(ebp)]	; rowctr
657
	test	ecx,ecx
658
	jz	near .return
659
660
	mov	esi, JSAMPARRAY [input_data(ebp)]	; input_data
661
	mov	edi, POINTER [output_data_ptr(ebp)]
662
	mov	edi, JSAMPARRAY [edi]			; output_data
663
	alignx	16,7
664
.rowloop:
665
	push	edi
666
	push	esi
667
668
	mov	esi, JSAMPROW [esi]			; inptr
669
	mov	ebx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]	; outptr0
670
	mov	edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]	; outptr1
671
	mov	eax,edx					; colctr
672
	alignx	16,7
673
.columnloop:
674
675
	movdqa	xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD]
676
677
	movdqa    xmm1,xmm0
678
	punpcklbw xmm0,xmm0
679
	punpckhbw xmm1,xmm1
680
681
	movdqa	XMMWORD [ebx+0*SIZEOF_XMMWORD], xmm0
682
	movdqa	XMMWORD [ebx+1*SIZEOF_XMMWORD], xmm1
683
	movdqa	XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0
684
	movdqa	XMMWORD [edi+1*SIZEOF_XMMWORD], xmm1
685
686
	sub	eax, byte 2*SIZEOF_XMMWORD
687
	jz	short .nextrow
688
689
	movdqa	xmm2, XMMWORD [esi+1*SIZEOF_XMMWORD]
690
691
	movdqa    xmm3,xmm2
692
	punpcklbw xmm2,xmm2
693
	punpckhbw xmm3,xmm3
694
695
	movdqa	XMMWORD [ebx+2*SIZEOF_XMMWORD], xmm2
696
	movdqa	XMMWORD [ebx+3*SIZEOF_XMMWORD], xmm3
697
	movdqa	XMMWORD [edi+2*SIZEOF_XMMWORD], xmm2
698
	movdqa	XMMWORD [edi+3*SIZEOF_XMMWORD], xmm3
699
700
	sub	eax, byte 2*SIZEOF_XMMWORD
701
	jz	short .nextrow
702
703
	add	esi, byte 2*SIZEOF_XMMWORD	; inptr
704
	add	ebx, byte 4*SIZEOF_XMMWORD	; outptr0
705
	add	edi, byte 4*SIZEOF_XMMWORD	; outptr1
706
	jmp	short .columnloop
707
	alignx	16,7
708
709
.nextrow:
710
	pop	esi
711
	pop	edi
712
713
	add	esi, byte 1*SIZEOF_JSAMPROW	; input_data
714
	add	edi, byte 2*SIZEOF_JSAMPROW	; output_data
715
	sub	ecx, byte 2			; rowctr
716
	jg	short .rowloop
717
718
.return:
719
	pop	edi
720
	pop	esi
721
;	pop	edx		; need not be preserved
722
;	pop	ecx		; need not be preserved
723
	pop	ebx
724
	pop	ebp
725
	ret
726
727
; For some reason, the OS X linker does not honor the request to align the
728
; segment unless we do this.
729
	align	16
(-)a/jpeg/simd/jf3dnflt.asm (+320 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jf3dnflt.asm - floating-point FDCT (3DNow!)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a floating-point implementation of the forward DCT
18
; (Discrete Cosine Transform). The following code is based directly on
19
; the IJG's original jfdctflt.c; see the jfdctflt.c for more details.
20
;
21
; [TAB8]
22
23
%include "jsimdext.inc"
24
%include "jdct.inc"
25
26
; --------------------------------------------------------------------------
27
	SECTION	SEG_CONST
28
29
	alignz	16
30
	global	EXTN(jconst_fdct_float_3dnow)
31
32
EXTN(jconst_fdct_float_3dnow):
33
34
PD_0_382	times 2 dd  0.382683432365089771728460
35
PD_0_707	times 2 dd  0.707106781186547524400844
36
PD_0_541	times 2 dd  0.541196100146196984399723
37
PD_1_306	times 2 dd  1.306562964876376527856643
38
39
	alignz	16
40
41
; --------------------------------------------------------------------------
42
	SECTION	SEG_TEXT
43
	BITS	32
44
;
45
; Perform the forward DCT on one block of samples.
46
;
47
; GLOBAL(void)
48
; jsimd_fdct_float_3dnow (FAST_FLOAT * data)
49
;
50
51
%define data(b)		(b)+8		; FAST_FLOAT * data
52
53
%define original_ebp	ebp+0
54
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
55
%define WK_NUM		2
56
57
	align	16
58
	global	EXTN(jsimd_fdct_float_3dnow)
59
60
EXTN(jsimd_fdct_float_3dnow):
61
	push	ebp
62
	mov	eax,esp				; eax = original ebp
63
	sub	esp, byte 4
64
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
65
	mov	[esp],eax
66
	mov	ebp,esp				; ebp = aligned ebp
67
	lea	esp, [wk(0)]
68
	pushpic	ebx
69
;	push	ecx		; need not be preserved
70
;	push	edx		; need not be preserved
71
;	push	esi		; unused
72
;	push	edi		; unused
73
74
	get_GOT	ebx		; get GOT address
75
76
	; ---- Pass 1: process rows.
77
78
	mov	edx, POINTER [data(eax)]	; (FAST_FLOAT *)
79
	mov	ecx, DCTSIZE/2
80
	alignx	16,7
81
.rowloop:
82
83
	movq	mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
84
	movq	mm1, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
85
	movq	mm2, MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)]
86
	movq	mm3, MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)]
87
88
	; mm0=(00 01), mm1=(10 11), mm2=(06 07), mm3=(16 17)
89
90
	movq      mm4,mm0		; transpose coefficients
91
	punpckldq mm0,mm1		; mm0=(00 10)=data0
92
	punpckhdq mm4,mm1		; mm4=(01 11)=data1
93
	movq      mm5,mm2		; transpose coefficients
94
	punpckldq mm2,mm3		; mm2=(06 16)=data6
95
	punpckhdq mm5,mm3		; mm5=(07 17)=data7
96
97
	movq	mm6,mm4
98
	movq	mm7,mm0
99
	pfsub	mm4,mm2			; mm4=data1-data6=tmp6
100
	pfsub	mm0,mm5			; mm0=data0-data7=tmp7
101
	pfadd	mm6,mm2			; mm6=data1+data6=tmp1
102
	pfadd	mm7,mm5			; mm7=data0+data7=tmp0
103
104
	movq	mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
105
	movq	mm3, MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
106
	movq	mm2, MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)]
107
	movq	mm5, MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)]
108
109
	; mm1=(02 03), mm3=(12 13), mm2=(04 05), mm5=(14 15)
110
111
	movq	MMWORD [wk(0)], mm4	; wk(0)=tmp6
112
	movq	MMWORD [wk(1)], mm0	; wk(1)=tmp7
113
114
	movq      mm4,mm1		; transpose coefficients
115
	punpckldq mm1,mm3		; mm1=(02 12)=data2
116
	punpckhdq mm4,mm3		; mm4=(03 13)=data3
117
	movq      mm0,mm2		; transpose coefficients
118
	punpckldq mm2,mm5		; mm2=(04 14)=data4
119
	punpckhdq mm0,mm5		; mm0=(05 15)=data5
120
121
	movq	mm3,mm4
122
	movq	mm5,mm1
123
	pfadd	mm4,mm2			; mm4=data3+data4=tmp3
124
	pfadd	mm1,mm0			; mm1=data2+data5=tmp2
125
	pfsub	mm3,mm2			; mm3=data3-data4=tmp4
126
	pfsub	mm5,mm0			; mm5=data2-data5=tmp5
127
128
	; -- Even part
129
130
	movq	mm2,mm7
131
	movq	mm0,mm6
132
	pfsub	mm7,mm4			; mm7=tmp13
133
	pfsub	mm6,mm1			; mm6=tmp12
134
	pfadd	mm2,mm4			; mm2=tmp10
135
	pfadd	mm0,mm1			; mm0=tmp11
136
137
	pfadd	mm6,mm7
138
	pfmul	mm6,[GOTOFF(ebx,PD_0_707)] ; mm6=z1
139
140
	movq	mm4,mm2
141
	movq	mm1,mm7
142
	pfsub	mm2,mm0			; mm2=data4
143
	pfsub	mm7,mm6			; mm7=data6
144
	pfadd	mm4,mm0			; mm4=data0
145
	pfadd	mm1,mm6			; mm1=data2
146
147
	movq	MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)], mm2
148
	movq	MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)], mm7
149
	movq	MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], mm4
150
	movq	MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)], mm1
151
152
	; -- Odd part
153
154
	movq	mm0, MMWORD [wk(0)]	; mm0=tmp6
155
	movq	mm6, MMWORD [wk(1)]	; mm6=tmp7
156
157
	pfadd	mm3,mm5			; mm3=tmp10
158
	pfadd	mm5,mm0			; mm5=tmp11
159
	pfadd	mm0,mm6			; mm0=tmp12, mm6=tmp7
160
161
	pfmul	mm5,[GOTOFF(ebx,PD_0_707)] ; mm5=z3
162
163
	movq	mm2,mm3			; mm2=tmp10
164
	pfsub	mm3,mm0
165
	pfmul	mm3,[GOTOFF(ebx,PD_0_382)] ; mm3=z5
166
	pfmul	mm2,[GOTOFF(ebx,PD_0_541)] ; mm2=MULTIPLY(tmp10,FIX_0_54119610)
167
	pfmul	mm0,[GOTOFF(ebx,PD_1_306)] ; mm0=MULTIPLY(tmp12,FIX_1_30656296)
168
	pfadd	mm2,mm3			; mm2=z2
169
	pfadd	mm0,mm3			; mm0=z4
170
171
	movq	mm7,mm6
172
	pfsub	mm6,mm5			; mm6=z13
173
	pfadd	mm7,mm5			; mm7=z11
174
175
	movq	mm4,mm6
176
	movq	mm1,mm7
177
	pfsub	mm6,mm2			; mm6=data3
178
	pfsub	mm7,mm0			; mm7=data7
179
	pfadd	mm4,mm2			; mm4=data5
180
	pfadd	mm1,mm0			; mm1=data1
181
182
	movq	MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)], mm6
183
	movq	MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)], mm7
184
	movq	MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)], mm4
185
	movq	MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], mm1
186
187
	add	edx, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
188
	dec	ecx
189
	jnz	near .rowloop
190
191
	; ---- Pass 2: process columns.
192
193
	mov	edx, POINTER [data(eax)]	; (FAST_FLOAT *)
194
	mov	ecx, DCTSIZE/2
195
	alignx	16,7
196
.columnloop:
197
198
	movq	mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
199
	movq	mm1, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
200
	movq	mm2, MMWORD [MMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)]
201
	movq	mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)]
202
203
	; mm0=(00 10), mm1=(01 11), mm2=(60 70), mm3=(61 71)
204
205
	movq      mm4,mm0		; transpose coefficients
206
	punpckldq mm0,mm1		; mm0=(00 01)=data0
207
	punpckhdq mm4,mm1		; mm4=(10 11)=data1
208
	movq      mm5,mm2		; transpose coefficients
209
	punpckldq mm2,mm3		; mm2=(60 61)=data6
210
	punpckhdq mm5,mm3		; mm5=(70 71)=data7
211
212
	movq	mm6,mm4
213
	movq	mm7,mm0
214
	pfsub	mm4,mm2			; mm4=data1-data6=tmp6
215
	pfsub	mm0,mm5			; mm0=data0-data7=tmp7
216
	pfadd	mm6,mm2			; mm6=data1+data6=tmp1
217
	pfadd	mm7,mm5			; mm7=data0+data7=tmp0
218
219
	movq	mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)]
220
	movq	mm3, MMWORD [MMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)]
221
	movq	mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)]
222
	movq	mm5, MMWORD [MMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)]
223
224
	; mm1=(20 30), mm3=(21 31), mm2=(40 50), mm5=(41 51)
225
226
	movq	MMWORD [wk(0)], mm4	; wk(0)=tmp6
227
	movq	MMWORD [wk(1)], mm0	; wk(1)=tmp7
228
229
	movq      mm4,mm1		; transpose coefficients
230
	punpckldq mm1,mm3		; mm1=(20 21)=data2
231
	punpckhdq mm4,mm3		; mm4=(30 31)=data3
232
	movq      mm0,mm2		; transpose coefficients
233
	punpckldq mm2,mm5		; mm2=(40 41)=data4
234
	punpckhdq mm0,mm5		; mm0=(50 51)=data5
235
236
	movq	mm3,mm4
237
	movq	mm5,mm1
238
	pfadd	mm4,mm2			; mm4=data3+data4=tmp3
239
	pfadd	mm1,mm0			; mm1=data2+data5=tmp2
240
	pfsub	mm3,mm2			; mm3=data3-data4=tmp4
241
	pfsub	mm5,mm0			; mm5=data2-data5=tmp5
242
243
	; -- Even part
244
245
	movq	mm2,mm7
246
	movq	mm0,mm6
247
	pfsub	mm7,mm4			; mm7=tmp13
248
	pfsub	mm6,mm1			; mm6=tmp12
249
	pfadd	mm2,mm4			; mm2=tmp10
250
	pfadd	mm0,mm1			; mm0=tmp11
251
252
	pfadd	mm6,mm7
253
	pfmul	mm6,[GOTOFF(ebx,PD_0_707)] ; mm6=z1
254
255
	movq	mm4,mm2
256
	movq	mm1,mm7
257
	pfsub	mm2,mm0			; mm2=data4
258
	pfsub	mm7,mm6			; mm7=data6
259
	pfadd	mm4,mm0			; mm4=data0
260
	pfadd	mm1,mm6			; mm1=data2
261
262
	movq	MMWORD [MMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)], mm2
263
	movq	MMWORD [MMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)], mm7
264
	movq	MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], mm4
265
	movq	MMWORD [MMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], mm1
266
267
	; -- Odd part
268
269
	movq	mm0, MMWORD [wk(0)]	; mm0=tmp6
270
	movq	mm6, MMWORD [wk(1)]	; mm6=tmp7
271
272
	pfadd	mm3,mm5			; mm3=tmp10
273
	pfadd	mm5,mm0			; mm5=tmp11
274
	pfadd	mm0,mm6			; mm0=tmp12, mm6=tmp7
275
276
	pfmul	mm5,[GOTOFF(ebx,PD_0_707)] ; mm5=z3
277
278
	movq	mm2,mm3			; mm2=tmp10
279
	pfsub	mm3,mm0
280
	pfmul	mm3,[GOTOFF(ebx,PD_0_382)] ; mm3=z5
281
	pfmul	mm2,[GOTOFF(ebx,PD_0_541)] ; mm2=MULTIPLY(tmp10,FIX_0_54119610)
282
	pfmul	mm0,[GOTOFF(ebx,PD_1_306)] ; mm0=MULTIPLY(tmp12,FIX_1_30656296)
283
	pfadd	mm2,mm3			; mm2=z2
284
	pfadd	mm0,mm3			; mm0=z4
285
286
	movq	mm7,mm6
287
	pfsub	mm6,mm5			; mm6=z13
288
	pfadd	mm7,mm5			; mm7=z11
289
290
	movq	mm4,mm6
291
	movq	mm1,mm7
292
	pfsub	mm6,mm2			; mm6=data3
293
	pfsub	mm7,mm0			; mm7=data7
294
	pfadd	mm4,mm2			; mm4=data5
295
	pfadd	mm1,mm0			; mm1=data1
296
297
	movq	MMWORD [MMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], mm6
298
	movq	MMWORD [MMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)], mm7
299
	movq	MMWORD [MMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)], mm4
300
	movq	MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], mm1
301
302
	add	edx, byte 2*SIZEOF_FAST_FLOAT
303
	dec	ecx
304
	jnz	near .columnloop
305
306
	femms		; empty MMX/3DNow! state
307
308
;	pop	edi		; unused
309
;	pop	esi		; unused
310
;	pop	edx		; need not be preserved
311
;	pop	ecx		; need not be preserved
312
	poppic	ebx
313
	mov	esp,ebp		; esp <- aligned ebp
314
	pop	esp		; esp <- original ebp
315
	pop	ebp
316
	ret
317
318
; For some reason, the OS X linker does not honor the request to align the
319
; segment unless we do this.
320
	align	16
(-)a/jpeg/simd/jfmmxfst.asm (+397 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jfmmxfst.asm - fast integer FDCT (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a fast, not so accurate integer implementation of
18
; the forward DCT (Discrete Cosine Transform). The following code is
19
; based directly on the IJG's original jfdctfst.c; see the jfdctfst.c
20
; for more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	8	; 14 is also OK.
30
31
%if CONST_BITS == 8
32
F_0_382	equ	 98		; FIX(0.382683433)
33
F_0_541	equ	139		; FIX(0.541196100)
34
F_0_707	equ	181		; FIX(0.707106781)
35
F_1_306	equ	334		; FIX(1.306562965)
36
%else
37
; NASM cannot do compile-time arithmetic on floating-point constants.
38
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
39
F_0_382	equ	DESCALE( 410903207,30-CONST_BITS)	; FIX(0.382683433)
40
F_0_541	equ	DESCALE( 581104887,30-CONST_BITS)	; FIX(0.541196100)
41
F_0_707	equ	DESCALE( 759250124,30-CONST_BITS)	; FIX(0.707106781)
42
F_1_306	equ	DESCALE(1402911301,30-CONST_BITS)	; FIX(1.306562965)
43
%endif
44
45
; --------------------------------------------------------------------------
46
	SECTION	SEG_CONST
47
48
; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
49
; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
50
51
%define PRE_MULTIPLY_SCALE_BITS   2
52
%define CONST_SHIFT     (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
53
54
	alignz	16
55
	global	EXTN(jconst_fdct_ifast_mmx)
56
57
EXTN(jconst_fdct_ifast_mmx):
58
59
PW_F0707	times 4 dw  F_0_707 << CONST_SHIFT
60
PW_F0382	times 4 dw  F_0_382 << CONST_SHIFT
61
PW_F0541	times 4 dw  F_0_541 << CONST_SHIFT
62
PW_F1306	times 4 dw  F_1_306 << CONST_SHIFT
63
64
	alignz	16
65
66
; --------------------------------------------------------------------------
67
	SECTION	SEG_TEXT
68
	BITS	32
69
;
70
; Perform the forward DCT on one block of samples.
71
;
72
; GLOBAL(void)
73
; jsimd_fdct_ifast_mmx (DCTELEM * data)
74
;
75
76
%define data(b)		(b)+8		; DCTELEM * data
77
78
%define original_ebp	ebp+0
79
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
80
%define WK_NUM		2
81
82
	align	16
83
	global	EXTN(jsimd_fdct_ifast_mmx)
84
85
EXTN(jsimd_fdct_ifast_mmx):
86
	push	ebp
87
	mov	eax,esp				; eax = original ebp
88
	sub	esp, byte 4
89
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
90
	mov	[esp],eax
91
	mov	ebp,esp				; ebp = aligned ebp
92
	lea	esp, [wk(0)]
93
	pushpic	ebx
94
;	push	ecx		; need not be preserved
95
;	push	edx		; need not be preserved
96
;	push	esi		; unused
97
;	push	edi		; unused
98
99
	get_GOT	ebx		; get GOT address
100
101
	; ---- Pass 1: process rows.
102
103
	mov	edx, POINTER [data(eax)]	; (DCTELEM *)
104
	mov	ecx, DCTSIZE/4
105
	alignx	16,7
106
.rowloop:
107
108
	movq	mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
109
	movq	mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
110
	movq	mm2, MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)]
111
	movq	mm3, MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)]
112
113
	; mm0=(20 21 22 23), mm2=(24 25 26 27)
114
	; mm1=(30 31 32 33), mm3=(34 35 36 37)
115
116
	movq      mm4,mm0		; transpose coefficients(phase 1)
117
	punpcklwd mm0,mm1		; mm0=(20 30 21 31)
118
	punpckhwd mm4,mm1		; mm4=(22 32 23 33)
119
	movq      mm5,mm2		; transpose coefficients(phase 1)
120
	punpcklwd mm2,mm3		; mm2=(24 34 25 35)
121
	punpckhwd mm5,mm3		; mm5=(26 36 27 37)
122
123
	movq	mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
124
	movq	mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
125
	movq	mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)]
126
	movq	mm3, MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)]
127
128
	; mm6=(00 01 02 03), mm1=(04 05 06 07)
129
	; mm7=(10 11 12 13), mm3=(14 15 16 17)
130
131
	movq	MMWORD [wk(0)], mm4	; wk(0)=(22 32 23 33)
132
	movq	MMWORD [wk(1)], mm2	; wk(1)=(24 34 25 35)
133
134
	movq      mm4,mm6		; transpose coefficients(phase 1)
135
	punpcklwd mm6,mm7		; mm6=(00 10 01 11)
136
	punpckhwd mm4,mm7		; mm4=(02 12 03 13)
137
	movq      mm2,mm1		; transpose coefficients(phase 1)
138
	punpcklwd mm1,mm3		; mm1=(04 14 05 15)
139
	punpckhwd mm2,mm3		; mm2=(06 16 07 17)
140
141
	movq      mm7,mm6		; transpose coefficients(phase 2)
142
	punpckldq mm6,mm0		; mm6=(00 10 20 30)=data0
143
	punpckhdq mm7,mm0		; mm7=(01 11 21 31)=data1
144
	movq      mm3,mm2		; transpose coefficients(phase 2)
145
	punpckldq mm2,mm5		; mm2=(06 16 26 36)=data6
146
	punpckhdq mm3,mm5		; mm3=(07 17 27 37)=data7
147
148
	movq	mm0,mm7
149
	movq	mm5,mm6
150
	psubw	mm7,mm2			; mm7=data1-data6=tmp6
151
	psubw	mm6,mm3			; mm6=data0-data7=tmp7
152
	paddw	mm0,mm2			; mm0=data1+data6=tmp1
153
	paddw	mm5,mm3			; mm5=data0+data7=tmp0
154
155
	movq	mm2, MMWORD [wk(0)]	; mm2=(22 32 23 33)
156
	movq	mm3, MMWORD [wk(1)]	; mm3=(24 34 25 35)
157
	movq	MMWORD [wk(0)], mm7	; wk(0)=tmp6
158
	movq	MMWORD [wk(1)], mm6	; wk(1)=tmp7
159
160
	movq      mm7,mm4		; transpose coefficients(phase 2)
161
	punpckldq mm4,mm2		; mm4=(02 12 22 32)=data2
162
	punpckhdq mm7,mm2		; mm7=(03 13 23 33)=data3
163
	movq      mm6,mm1		; transpose coefficients(phase 2)
164
	punpckldq mm1,mm3		; mm1=(04 14 24 34)=data4
165
	punpckhdq mm6,mm3		; mm6=(05 15 25 35)=data5
166
167
	movq	mm2,mm7
168
	movq	mm3,mm4
169
	paddw	mm7,mm1			; mm7=data3+data4=tmp3
170
	paddw	mm4,mm6			; mm4=data2+data5=tmp2
171
	psubw	mm2,mm1			; mm2=data3-data4=tmp4
172
	psubw	mm3,mm6			; mm3=data2-data5=tmp5
173
174
	; -- Even part
175
176
	movq	mm1,mm5
177
	movq	mm6,mm0
178
	psubw	mm5,mm7			; mm5=tmp13
179
	psubw	mm0,mm4			; mm0=tmp12
180
	paddw	mm1,mm7			; mm1=tmp10
181
	paddw	mm6,mm4			; mm6=tmp11
182
183
	paddw	mm0,mm5
184
	psllw	mm0,PRE_MULTIPLY_SCALE_BITS
185
	pmulhw	mm0,[GOTOFF(ebx,PW_F0707)] ; mm0=z1
186
187
	movq	mm7,mm1
188
	movq	mm4,mm5
189
	psubw	mm1,mm6			; mm1=data4
190
	psubw	mm5,mm0			; mm5=data6
191
	paddw	mm7,mm6			; mm7=data0
192
	paddw	mm4,mm0			; mm4=data2
193
194
	movq	MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)], mm1
195
	movq	MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)], mm5
196
	movq	MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm7
197
	movq	MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4
198
199
	; -- Odd part
200
201
	movq	mm6, MMWORD [wk(0)]	; mm6=tmp6
202
	movq	mm0, MMWORD [wk(1)]	; mm0=tmp7
203
204
	paddw	mm2,mm3			; mm2=tmp10
205
	paddw	mm3,mm6			; mm3=tmp11
206
	paddw	mm6,mm0			; mm6=tmp12, mm0=tmp7
207
208
	psllw	mm2,PRE_MULTIPLY_SCALE_BITS
209
	psllw	mm6,PRE_MULTIPLY_SCALE_BITS
210
211
	psllw	mm3,PRE_MULTIPLY_SCALE_BITS
212
	pmulhw	mm3,[GOTOFF(ebx,PW_F0707)] ; mm3=z3
213
214
	movq	mm1,mm2			; mm1=tmp10
215
	psubw	mm2,mm6
216
	pmulhw	mm2,[GOTOFF(ebx,PW_F0382)] ; mm2=z5
217
	pmulhw	mm1,[GOTOFF(ebx,PW_F0541)] ; mm1=MULTIPLY(tmp10,FIX_0_54119610)
218
	pmulhw	mm6,[GOTOFF(ebx,PW_F1306)] ; mm6=MULTIPLY(tmp12,FIX_1_30656296)
219
	paddw	mm1,mm2			; mm1=z2
220
	paddw	mm6,mm2			; mm6=z4
221
222
	movq	mm5,mm0
223
	psubw	mm0,mm3			; mm0=z13
224
	paddw	mm5,mm3			; mm5=z11
225
226
	movq	mm7,mm0
227
	movq	mm4,mm5
228
	psubw	mm0,mm1			; mm0=data3
229
	psubw	mm5,mm6			; mm5=data7
230
	paddw	mm7,mm1			; mm7=data5
231
	paddw	mm4,mm6			; mm4=data1
232
233
	movq	MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm0
234
	movq	MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)], mm5
235
	movq	MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)], mm7
236
	movq	MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm4
237
238
	add	edx, byte 4*DCTSIZE*SIZEOF_DCTELEM
239
	dec	ecx
240
	jnz	near .rowloop
241
242
	; ---- Pass 2: process columns.
243
244
	mov	edx, POINTER [data(eax)]	; (DCTELEM *)
245
	mov	ecx, DCTSIZE/4
246
	alignx	16,7
247
.columnloop:
248
249
	movq	mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
250
	movq	mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
251
	movq	mm2, MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)]
252
	movq	mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)]
253
254
	; mm0=(02 12 22 32), mm2=(42 52 62 72)
255
	; mm1=(03 13 23 33), mm3=(43 53 63 73)
256
257
	movq      mm4,mm0		; transpose coefficients(phase 1)
258
	punpcklwd mm0,mm1		; mm0=(02 03 12 13)
259
	punpckhwd mm4,mm1		; mm4=(22 23 32 33)
260
	movq      mm5,mm2		; transpose coefficients(phase 1)
261
	punpcklwd mm2,mm3		; mm2=(42 43 52 53)
262
	punpckhwd mm5,mm3		; mm5=(62 63 72 73)
263
264
	movq	mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
265
	movq	mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
266
	movq	mm1, MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)]
267
	movq	mm3, MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)]
268
269
	; mm6=(00 10 20 30), mm1=(40 50 60 70)
270
	; mm7=(01 11 21 31), mm3=(41 51 61 71)
271
272
	movq	MMWORD [wk(0)], mm4	; wk(0)=(22 23 32 33)
273
	movq	MMWORD [wk(1)], mm2	; wk(1)=(42 43 52 53)
274
275
	movq      mm4,mm6		; transpose coefficients(phase 1)
276
	punpcklwd mm6,mm7		; mm6=(00 01 10 11)
277
	punpckhwd mm4,mm7		; mm4=(20 21 30 31)
278
	movq      mm2,mm1		; transpose coefficients(phase 1)
279
	punpcklwd mm1,mm3		; mm1=(40 41 50 51)
280
	punpckhwd mm2,mm3		; mm2=(60 61 70 71)
281
282
	movq      mm7,mm6		; transpose coefficients(phase 2)
283
	punpckldq mm6,mm0		; mm6=(00 01 02 03)=data0
284
	punpckhdq mm7,mm0		; mm7=(10 11 12 13)=data1
285
	movq      mm3,mm2		; transpose coefficients(phase 2)
286
	punpckldq mm2,mm5		; mm2=(60 61 62 63)=data6
287
	punpckhdq mm3,mm5		; mm3=(70 71 72 73)=data7
288
289
	movq	mm0,mm7
290
	movq	mm5,mm6
291
	psubw	mm7,mm2			; mm7=data1-data6=tmp6
292
	psubw	mm6,mm3			; mm6=data0-data7=tmp7
293
	paddw	mm0,mm2			; mm0=data1+data6=tmp1
294
	paddw	mm5,mm3			; mm5=data0+data7=tmp0
295
296
	movq	mm2, MMWORD [wk(0)]	; mm2=(22 23 32 33)
297
	movq	mm3, MMWORD [wk(1)]	; mm3=(42 43 52 53)
298
	movq	MMWORD [wk(0)], mm7	; wk(0)=tmp6
299
	movq	MMWORD [wk(1)], mm6	; wk(1)=tmp7
300
301
	movq      mm7,mm4		; transpose coefficients(phase 2)
302
	punpckldq mm4,mm2		; mm4=(20 21 22 23)=data2
303
	punpckhdq mm7,mm2		; mm7=(30 31 32 33)=data3
304
	movq      mm6,mm1		; transpose coefficients(phase 2)
305
	punpckldq mm1,mm3		; mm1=(40 41 42 43)=data4
306
	punpckhdq mm6,mm3		; mm6=(50 51 52 53)=data5
307
308
	movq	mm2,mm7
309
	movq	mm3,mm4
310
	paddw	mm7,mm1			; mm7=data3+data4=tmp3
311
	paddw	mm4,mm6			; mm4=data2+data5=tmp2
312
	psubw	mm2,mm1			; mm2=data3-data4=tmp4
313
	psubw	mm3,mm6			; mm3=data2-data5=tmp5
314
315
	; -- Even part
316
317
	movq	mm1,mm5
318
	movq	mm6,mm0
319
	psubw	mm5,mm7			; mm5=tmp13
320
	psubw	mm0,mm4			; mm0=tmp12
321
	paddw	mm1,mm7			; mm1=tmp10
322
	paddw	mm6,mm4			; mm6=tmp11
323
324
	paddw	mm0,mm5
325
	psllw	mm0,PRE_MULTIPLY_SCALE_BITS
326
	pmulhw	mm0,[GOTOFF(ebx,PW_F0707)] ; mm0=z1
327
328
	movq	mm7,mm1
329
	movq	mm4,mm5
330
	psubw	mm1,mm6			; mm1=data4
331
	psubw	mm5,mm0			; mm5=data6
332
	paddw	mm7,mm6			; mm7=data0
333
	paddw	mm4,mm0			; mm4=data2
334
335
	movq	MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)], mm1
336
	movq	MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)], mm5
337
	movq	MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm7
338
	movq	MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4
339
340
	; -- Odd part
341
342
	movq	mm6, MMWORD [wk(0)]	; mm6=tmp6
343
	movq	mm0, MMWORD [wk(1)]	; mm0=tmp7
344
345
	paddw	mm2,mm3			; mm2=tmp10
346
	paddw	mm3,mm6			; mm3=tmp11
347
	paddw	mm6,mm0			; mm6=tmp12, mm0=tmp7
348
349
	psllw	mm2,PRE_MULTIPLY_SCALE_BITS
350
	psllw	mm6,PRE_MULTIPLY_SCALE_BITS
351
352
	psllw	mm3,PRE_MULTIPLY_SCALE_BITS
353
	pmulhw	mm3,[GOTOFF(ebx,PW_F0707)] ; mm3=z3
354
355
	movq	mm1,mm2			; mm1=tmp10
356
	psubw	mm2,mm6
357
	pmulhw	mm2,[GOTOFF(ebx,PW_F0382)] ; mm2=z5
358
	pmulhw	mm1,[GOTOFF(ebx,PW_F0541)] ; mm1=MULTIPLY(tmp10,FIX_0_54119610)
359
	pmulhw	mm6,[GOTOFF(ebx,PW_F1306)] ; mm6=MULTIPLY(tmp12,FIX_1_30656296)
360
	paddw	mm1,mm2			; mm1=z2
361
	paddw	mm6,mm2			; mm6=z4
362
363
	movq	mm5,mm0
364
	psubw	mm0,mm3			; mm0=z13
365
	paddw	mm5,mm3			; mm5=z11
366
367
	movq	mm7,mm0
368
	movq	mm4,mm5
369
	psubw	mm0,mm1			; mm0=data3
370
	psubw	mm5,mm6			; mm5=data7
371
	paddw	mm7,mm1			; mm7=data5
372
	paddw	mm4,mm6			; mm4=data1
373
374
	movq	MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm0
375
	movq	MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)], mm5
376
	movq	MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)], mm7
377
	movq	MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm4
378
379
	add	edx, byte 4*SIZEOF_DCTELEM
380
	dec	ecx
381
	jnz	near .columnloop
382
383
	emms		; empty MMX state
384
385
;	pop	edi		; unused
386
;	pop	esi		; unused
387
;	pop	edx		; need not be preserved
388
;	pop	ecx		; need not be preserved
389
	poppic	ebx
390
	mov	esp,ebp		; esp <- aligned ebp
391
	pop	esp		; esp <- original ebp
392
	pop	ebp
393
	ret
394
395
; For some reason, the OS X linker does not honor the request to align the
396
; segment unless we do this.
397
	align	16
(-)a/jpeg/simd/jfmmxint.asm (+622 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jfmmxint.asm - accurate integer FDCT (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a slow-but-accurate integer implementation of the
18
; forward DCT (Discrete Cosine Transform). The following code is based
19
; directly on the IJG's original jfdctint.c; see the jfdctint.c for
20
; more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	13
30
%define PASS1_BITS	2
31
32
%define DESCALE_P1	(CONST_BITS-PASS1_BITS)
33
%define DESCALE_P2	(CONST_BITS+PASS1_BITS)
34
35
%if CONST_BITS == 13
36
F_0_298	equ	 2446		; FIX(0.298631336)
37
F_0_390	equ	 3196		; FIX(0.390180644)
38
F_0_541	equ	 4433		; FIX(0.541196100)
39
F_0_765	equ	 6270		; FIX(0.765366865)
40
F_0_899	equ	 7373		; FIX(0.899976223)
41
F_1_175	equ	 9633		; FIX(1.175875602)
42
F_1_501	equ	12299		; FIX(1.501321110)
43
F_1_847	equ	15137		; FIX(1.847759065)
44
F_1_961	equ	16069		; FIX(1.961570560)
45
F_2_053	equ	16819		; FIX(2.053119869)
46
F_2_562	equ	20995		; FIX(2.562915447)
47
F_3_072	equ	25172		; FIX(3.072711026)
48
%else
49
; NASM cannot do compile-time arithmetic on floating-point constants.
50
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
51
F_0_298	equ	DESCALE( 320652955,30-CONST_BITS)	; FIX(0.298631336)
52
F_0_390	equ	DESCALE( 418953276,30-CONST_BITS)	; FIX(0.390180644)
53
F_0_541	equ	DESCALE( 581104887,30-CONST_BITS)	; FIX(0.541196100)
54
F_0_765	equ	DESCALE( 821806413,30-CONST_BITS)	; FIX(0.765366865)
55
F_0_899	equ	DESCALE( 966342111,30-CONST_BITS)	; FIX(0.899976223)
56
F_1_175	equ	DESCALE(1262586813,30-CONST_BITS)	; FIX(1.175875602)
57
F_1_501	equ	DESCALE(1612031267,30-CONST_BITS)	; FIX(1.501321110)
58
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
59
F_1_961	equ	DESCALE(2106220350,30-CONST_BITS)	; FIX(1.961570560)
60
F_2_053	equ	DESCALE(2204520673,30-CONST_BITS)	; FIX(2.053119869)
61
F_2_562	equ	DESCALE(2751909506,30-CONST_BITS)	; FIX(2.562915447)
62
F_3_072	equ	DESCALE(3299298341,30-CONST_BITS)	; FIX(3.072711026)
63
%endif
64
65
; --------------------------------------------------------------------------
66
	SECTION	SEG_CONST
67
68
	alignz	16
69
	global	EXTN(jconst_fdct_islow_mmx)
70
71
EXTN(jconst_fdct_islow_mmx):
72
73
PW_F130_F054	times 2 dw  (F_0_541+F_0_765), F_0_541
74
PW_F054_MF130	times 2 dw  F_0_541, (F_0_541-F_1_847)
75
PW_MF078_F117	times 2 dw  (F_1_175-F_1_961), F_1_175
76
PW_F117_F078	times 2 dw  F_1_175, (F_1_175-F_0_390)
77
PW_MF060_MF089	times 2 dw  (F_0_298-F_0_899),-F_0_899
78
PW_MF089_F060	times 2 dw -F_0_899, (F_1_501-F_0_899)
79
PW_MF050_MF256	times 2 dw  (F_2_053-F_2_562),-F_2_562
80
PW_MF256_F050	times 2 dw -F_2_562, (F_3_072-F_2_562)
81
PD_DESCALE_P1	times 2 dd  1 << (DESCALE_P1-1)
82
PD_DESCALE_P2	times 2 dd  1 << (DESCALE_P2-1)
83
PW_DESCALE_P2X	times 4 dw  1 << (PASS1_BITS-1)
84
85
	alignz	16
86
87
; --------------------------------------------------------------------------
88
	SECTION	SEG_TEXT
89
	BITS	32
90
;
91
; Perform the forward DCT on one block of samples.
92
;
93
; GLOBAL(void)
94
; jsimd_fdct_islow_mmx (DCTELEM * data)
95
;
96
97
%define data(b)		(b)+8		; DCTELEM * data
98
99
%define original_ebp	ebp+0
100
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
101
%define WK_NUM		2
102
103
	align	16
104
	global	EXTN(jsimd_fdct_islow_mmx)
105
106
EXTN(jsimd_fdct_islow_mmx):
107
	push	ebp
108
	mov	eax,esp				; eax = original ebp
109
	sub	esp, byte 4
110
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
111
	mov	[esp],eax
112
	mov	ebp,esp				; ebp = aligned ebp
113
	lea	esp, [wk(0)]
114
	pushpic	ebx
115
;	push	ecx		; need not be preserved
116
;	push	edx		; need not be preserved
117
;	push	esi		; unused
118
;	push	edi		; unused
119
120
	get_GOT	ebx		; get GOT address
121
122
	; ---- Pass 1: process rows.
123
124
	mov	edx, POINTER [data(eax)]	; (DCTELEM *)
125
	mov	ecx, DCTSIZE/4
126
	alignx	16,7
127
.rowloop:
128
129
	movq	mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
130
	movq	mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
131
	movq	mm2, MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)]
132
	movq	mm3, MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)]
133
134
	; mm0=(20 21 22 23), mm2=(24 25 26 27)
135
	; mm1=(30 31 32 33), mm3=(34 35 36 37)
136
137
	movq      mm4,mm0		; transpose coefficients(phase 1)
138
	punpcklwd mm0,mm1		; mm0=(20 30 21 31)
139
	punpckhwd mm4,mm1		; mm4=(22 32 23 33)
140
	movq      mm5,mm2		; transpose coefficients(phase 1)
141
	punpcklwd mm2,mm3		; mm2=(24 34 25 35)
142
	punpckhwd mm5,mm3		; mm5=(26 36 27 37)
143
144
	movq	mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
145
	movq	mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
146
	movq	mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)]
147
	movq	mm3, MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)]
148
149
	; mm6=(00 01 02 03), mm1=(04 05 06 07)
150
	; mm7=(10 11 12 13), mm3=(14 15 16 17)
151
152
	movq	MMWORD [wk(0)], mm4	; wk(0)=(22 32 23 33)
153
	movq	MMWORD [wk(1)], mm2	; wk(1)=(24 34 25 35)
154
155
	movq      mm4,mm6		; transpose coefficients(phase 1)
156
	punpcklwd mm6,mm7		; mm6=(00 10 01 11)
157
	punpckhwd mm4,mm7		; mm4=(02 12 03 13)
158
	movq      mm2,mm1		; transpose coefficients(phase 1)
159
	punpcklwd mm1,mm3		; mm1=(04 14 05 15)
160
	punpckhwd mm2,mm3		; mm2=(06 16 07 17)
161
162
	movq      mm7,mm6		; transpose coefficients(phase 2)
163
	punpckldq mm6,mm0		; mm6=(00 10 20 30)=data0
164
	punpckhdq mm7,mm0		; mm7=(01 11 21 31)=data1
165
	movq      mm3,mm2		; transpose coefficients(phase 2)
166
	punpckldq mm2,mm5		; mm2=(06 16 26 36)=data6
167
	punpckhdq mm3,mm5		; mm3=(07 17 27 37)=data7
168
169
	movq	mm0,mm7
170
	movq	mm5,mm6
171
	psubw	mm7,mm2			; mm7=data1-data6=tmp6
172
	psubw	mm6,mm3			; mm6=data0-data7=tmp7
173
	paddw	mm0,mm2			; mm0=data1+data6=tmp1
174
	paddw	mm5,mm3			; mm5=data0+data7=tmp0
175
176
	movq	mm2, MMWORD [wk(0)]	; mm2=(22 32 23 33)
177
	movq	mm3, MMWORD [wk(1)]	; mm3=(24 34 25 35)
178
	movq	MMWORD [wk(0)], mm7	; wk(0)=tmp6
179
	movq	MMWORD [wk(1)], mm6	; wk(1)=tmp7
180
181
	movq      mm7,mm4		; transpose coefficients(phase 2)
182
	punpckldq mm4,mm2		; mm4=(02 12 22 32)=data2
183
	punpckhdq mm7,mm2		; mm7=(03 13 23 33)=data3
184
	movq      mm6,mm1		; transpose coefficients(phase 2)
185
	punpckldq mm1,mm3		; mm1=(04 14 24 34)=data4
186
	punpckhdq mm6,mm3		; mm6=(05 15 25 35)=data5
187
188
	movq	mm2,mm7
189
	movq	mm3,mm4
190
	paddw	mm7,mm1			; mm7=data3+data4=tmp3
191
	paddw	mm4,mm6			; mm4=data2+data5=tmp2
192
	psubw	mm2,mm1			; mm2=data3-data4=tmp4
193
	psubw	mm3,mm6			; mm3=data2-data5=tmp5
194
195
	; -- Even part
196
197
	movq	mm1,mm5
198
	movq	mm6,mm0
199
	paddw	mm5,mm7			; mm5=tmp10
200
	paddw	mm0,mm4			; mm0=tmp11
201
	psubw	mm1,mm7			; mm1=tmp13
202
	psubw	mm6,mm4			; mm6=tmp12
203
204
	movq	mm7,mm5
205
	paddw	mm5,mm0			; mm5=tmp10+tmp11
206
	psubw	mm7,mm0			; mm7=tmp10-tmp11
207
208
	psllw	mm5,PASS1_BITS		; mm5=data0
209
	psllw	mm7,PASS1_BITS		; mm7=data4
210
211
	movq	MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm5
212
	movq	MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)], mm7
213
214
	; (Original)
215
	; z1 = (tmp12 + tmp13) * 0.541196100;
216
	; data2 = z1 + tmp13 * 0.765366865;
217
	; data6 = z1 + tmp12 * -1.847759065;
218
	;
219
	; (This implementation)
220
	; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
221
	; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
222
223
	movq      mm4,mm1		; mm1=tmp13
224
	movq      mm0,mm1
225
	punpcklwd mm4,mm6		; mm6=tmp12
226
	punpckhwd mm0,mm6
227
	movq      mm1,mm4
228
	movq      mm6,mm0
229
	pmaddwd   mm4,[GOTOFF(ebx,PW_F130_F054)]	; mm4=data2L
230
	pmaddwd   mm0,[GOTOFF(ebx,PW_F130_F054)]	; mm0=data2H
231
	pmaddwd   mm1,[GOTOFF(ebx,PW_F054_MF130)]	; mm1=data6L
232
	pmaddwd   mm6,[GOTOFF(ebx,PW_F054_MF130)]	; mm6=data6H
233
234
	paddd	mm4,[GOTOFF(ebx,PD_DESCALE_P1)]
235
	paddd	mm0,[GOTOFF(ebx,PD_DESCALE_P1)]
236
	psrad	mm4,DESCALE_P1
237
	psrad	mm0,DESCALE_P1
238
	paddd	mm1,[GOTOFF(ebx,PD_DESCALE_P1)]
239
	paddd	mm6,[GOTOFF(ebx,PD_DESCALE_P1)]
240
	psrad	mm1,DESCALE_P1
241
	psrad	mm6,DESCALE_P1
242
243
	packssdw  mm4,mm0		; mm4=data2
244
	packssdw  mm1,mm6		; mm1=data6
245
246
	movq	MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4
247
	movq	MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)], mm1
248
249
	; -- Odd part
250
251
	movq	mm5, MMWORD [wk(0)]	; mm5=tmp6
252
	movq	mm7, MMWORD [wk(1)]	; mm7=tmp7
253
254
	movq	mm0,mm2			; mm2=tmp4
255
	movq	mm6,mm3			; mm3=tmp5
256
	paddw	mm0,mm5			; mm0=z3
257
	paddw	mm6,mm7			; mm6=z4
258
259
	; (Original)
260
	; z5 = (z3 + z4) * 1.175875602;
261
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
262
	; z3 += z5;  z4 += z5;
263
	;
264
	; (This implementation)
265
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
266
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
267
268
	movq      mm4,mm0
269
	movq      mm1,mm0
270
	punpcklwd mm4,mm6
271
	punpckhwd mm1,mm6
272
	movq      mm0,mm4
273
	movq      mm6,mm1
274
	pmaddwd   mm4,[GOTOFF(ebx,PW_MF078_F117)]	; mm4=z3L
275
	pmaddwd   mm1,[GOTOFF(ebx,PW_MF078_F117)]	; mm1=z3H
276
	pmaddwd   mm0,[GOTOFF(ebx,PW_F117_F078)]	; mm0=z4L
277
	pmaddwd   mm6,[GOTOFF(ebx,PW_F117_F078)]	; mm6=z4H
278
279
	movq	MMWORD [wk(0)], mm4	; wk(0)=z3L
280
	movq	MMWORD [wk(1)], mm1	; wk(1)=z3H
281
282
	; (Original)
283
	; z1 = tmp4 + tmp7;  z2 = tmp5 + tmp6;
284
	; tmp4 = tmp4 * 0.298631336;  tmp5 = tmp5 * 2.053119869;
285
	; tmp6 = tmp6 * 3.072711026;  tmp7 = tmp7 * 1.501321110;
286
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
287
	; data7 = tmp4 + z1 + z3;  data5 = tmp5 + z2 + z4;
288
	; data3 = tmp6 + z2 + z3;  data1 = tmp7 + z1 + z4;
289
	;
290
	; (This implementation)
291
	; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
292
	; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
293
	; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
294
	; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
295
	; data7 = tmp4 + z3;  data5 = tmp5 + z4;
296
	; data3 = tmp6 + z3;  data1 = tmp7 + z4;
297
298
	movq      mm4,mm2
299
	movq      mm1,mm2
300
	punpcklwd mm4,mm7
301
	punpckhwd mm1,mm7
302
	movq      mm2,mm4
303
	movq      mm7,mm1
304
	pmaddwd   mm4,[GOTOFF(ebx,PW_MF060_MF089)]	; mm4=tmp4L
305
	pmaddwd   mm1,[GOTOFF(ebx,PW_MF060_MF089)]	; mm1=tmp4H
306
	pmaddwd   mm2,[GOTOFF(ebx,PW_MF089_F060)]	; mm2=tmp7L
307
	pmaddwd   mm7,[GOTOFF(ebx,PW_MF089_F060)]	; mm7=tmp7H
308
309
	paddd	mm4, MMWORD [wk(0)]	; mm4=data7L
310
	paddd	mm1, MMWORD [wk(1)]	; mm1=data7H
311
	paddd	mm2,mm0			; mm2=data1L
312
	paddd	mm7,mm6			; mm7=data1H
313
314
	paddd	mm4,[GOTOFF(ebx,PD_DESCALE_P1)]
315
	paddd	mm1,[GOTOFF(ebx,PD_DESCALE_P1)]
316
	psrad	mm4,DESCALE_P1
317
	psrad	mm1,DESCALE_P1
318
	paddd	mm2,[GOTOFF(ebx,PD_DESCALE_P1)]
319
	paddd	mm7,[GOTOFF(ebx,PD_DESCALE_P1)]
320
	psrad	mm2,DESCALE_P1
321
	psrad	mm7,DESCALE_P1
322
323
	packssdw  mm4,mm1		; mm4=data7
324
	packssdw  mm2,mm7		; mm2=data1
325
326
	movq	MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)], mm4
327
	movq	MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm2
328
329
	movq      mm1,mm3
330
	movq      mm7,mm3
331
	punpcklwd mm1,mm5
332
	punpckhwd mm7,mm5
333
	movq      mm3,mm1
334
	movq      mm5,mm7
335
	pmaddwd   mm1,[GOTOFF(ebx,PW_MF050_MF256)]	; mm1=tmp5L
336
	pmaddwd   mm7,[GOTOFF(ebx,PW_MF050_MF256)]	; mm7=tmp5H
337
	pmaddwd   mm3,[GOTOFF(ebx,PW_MF256_F050)]	; mm3=tmp6L
338
	pmaddwd   mm5,[GOTOFF(ebx,PW_MF256_F050)]	; mm5=tmp6H
339
340
	paddd	mm1,mm0			; mm1=data5L
341
	paddd	mm7,mm6			; mm7=data5H
342
	paddd	mm3, MMWORD [wk(0)]	; mm3=data3L
343
	paddd	mm5, MMWORD [wk(1)]	; mm5=data3H
344
345
	paddd	mm1,[GOTOFF(ebx,PD_DESCALE_P1)]
346
	paddd	mm7,[GOTOFF(ebx,PD_DESCALE_P1)]
347
	psrad	mm1,DESCALE_P1
348
	psrad	mm7,DESCALE_P1
349
	paddd	mm3,[GOTOFF(ebx,PD_DESCALE_P1)]
350
	paddd	mm5,[GOTOFF(ebx,PD_DESCALE_P1)]
351
	psrad	mm3,DESCALE_P1
352
	psrad	mm5,DESCALE_P1
353
354
	packssdw  mm1,mm7		; mm1=data5
355
	packssdw  mm3,mm5		; mm3=data3
356
357
	movq	MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)], mm1
358
	movq	MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm3
359
360
	add	edx, byte 4*DCTSIZE*SIZEOF_DCTELEM
361
	dec	ecx
362
	jnz	near .rowloop
363
364
	; ---- Pass 2: process columns.
365
366
	mov	edx, POINTER [data(eax)]	; (DCTELEM *)
367
	mov	ecx, DCTSIZE/4
368
	alignx	16,7
369
.columnloop:
370
371
	movq	mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
372
	movq	mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
373
	movq	mm2, MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)]
374
	movq	mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)]
375
376
	; mm0=(02 12 22 32), mm2=(42 52 62 72)
377
	; mm1=(03 13 23 33), mm3=(43 53 63 73)
378
379
	movq      mm4,mm0		; transpose coefficients(phase 1)
380
	punpcklwd mm0,mm1		; mm0=(02 03 12 13)
381
	punpckhwd mm4,mm1		; mm4=(22 23 32 33)
382
	movq      mm5,mm2		; transpose coefficients(phase 1)
383
	punpcklwd mm2,mm3		; mm2=(42 43 52 53)
384
	punpckhwd mm5,mm3		; mm5=(62 63 72 73)
385
386
	movq	mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
387
	movq	mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
388
	movq	mm1, MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)]
389
	movq	mm3, MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)]
390
391
	; mm6=(00 10 20 30), mm1=(40 50 60 70)
392
	; mm7=(01 11 21 31), mm3=(41 51 61 71)
393
394
	movq	MMWORD [wk(0)], mm4	; wk(0)=(22 23 32 33)
395
	movq	MMWORD [wk(1)], mm2	; wk(1)=(42 43 52 53)
396
397
	movq      mm4,mm6		; transpose coefficients(phase 1)
398
	punpcklwd mm6,mm7		; mm6=(00 01 10 11)
399
	punpckhwd mm4,mm7		; mm4=(20 21 30 31)
400
	movq      mm2,mm1		; transpose coefficients(phase 1)
401
	punpcklwd mm1,mm3		; mm1=(40 41 50 51)
402
	punpckhwd mm2,mm3		; mm2=(60 61 70 71)
403
404
	movq      mm7,mm6		; transpose coefficients(phase 2)
405
	punpckldq mm6,mm0		; mm6=(00 01 02 03)=data0
406
	punpckhdq mm7,mm0		; mm7=(10 11 12 13)=data1
407
	movq      mm3,mm2		; transpose coefficients(phase 2)
408
	punpckldq mm2,mm5		; mm2=(60 61 62 63)=data6
409
	punpckhdq mm3,mm5		; mm3=(70 71 72 73)=data7
410
411
	movq	mm0,mm7
412
	movq	mm5,mm6
413
	psubw	mm7,mm2			; mm7=data1-data6=tmp6
414
	psubw	mm6,mm3			; mm6=data0-data7=tmp7
415
	paddw	mm0,mm2			; mm0=data1+data6=tmp1
416
	paddw	mm5,mm3			; mm5=data0+data7=tmp0
417
418
	movq	mm2, MMWORD [wk(0)]	; mm2=(22 23 32 33)
419
	movq	mm3, MMWORD [wk(1)]	; mm3=(42 43 52 53)
420
	movq	MMWORD [wk(0)], mm7	; wk(0)=tmp6
421
	movq	MMWORD [wk(1)], mm6	; wk(1)=tmp7
422
423
	movq      mm7,mm4		; transpose coefficients(phase 2)
424
	punpckldq mm4,mm2		; mm4=(20 21 22 23)=data2
425
	punpckhdq mm7,mm2		; mm7=(30 31 32 33)=data3
426
	movq      mm6,mm1		; transpose coefficients(phase 2)
427
	punpckldq mm1,mm3		; mm1=(40 41 42 43)=data4
428
	punpckhdq mm6,mm3		; mm6=(50 51 52 53)=data5
429
430
	movq	mm2,mm7
431
	movq	mm3,mm4
432
	paddw	mm7,mm1			; mm7=data3+data4=tmp3
433
	paddw	mm4,mm6			; mm4=data2+data5=tmp2
434
	psubw	mm2,mm1			; mm2=data3-data4=tmp4
435
	psubw	mm3,mm6			; mm3=data2-data5=tmp5
436
437
	; -- Even part
438
439
	movq	mm1,mm5
440
	movq	mm6,mm0
441
	paddw	mm5,mm7			; mm5=tmp10
442
	paddw	mm0,mm4			; mm0=tmp11
443
	psubw	mm1,mm7			; mm1=tmp13
444
	psubw	mm6,mm4			; mm6=tmp12
445
446
	movq	mm7,mm5
447
	paddw	mm5,mm0			; mm5=tmp10+tmp11
448
	psubw	mm7,mm0			; mm7=tmp10-tmp11
449
450
	paddw	mm5,[GOTOFF(ebx,PW_DESCALE_P2X)]
451
	paddw	mm7,[GOTOFF(ebx,PW_DESCALE_P2X)]
452
	psraw	mm5,PASS1_BITS		; mm5=data0
453
	psraw	mm7,PASS1_BITS		; mm7=data4
454
455
	movq	MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm5
456
	movq	MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)], mm7
457
458
	; (Original)
459
	; z1 = (tmp12 + tmp13) * 0.541196100;
460
	; data2 = z1 + tmp13 * 0.765366865;
461
	; data6 = z1 + tmp12 * -1.847759065;
462
	;
463
	; (This implementation)
464
	; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
465
	; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
466
467
	movq      mm4,mm1		; mm1=tmp13
468
	movq      mm0,mm1
469
	punpcklwd mm4,mm6		; mm6=tmp12
470
	punpckhwd mm0,mm6
471
	movq      mm1,mm4
472
	movq      mm6,mm0
473
	pmaddwd   mm4,[GOTOFF(ebx,PW_F130_F054)]	; mm4=data2L
474
	pmaddwd   mm0,[GOTOFF(ebx,PW_F130_F054)]	; mm0=data2H
475
	pmaddwd   mm1,[GOTOFF(ebx,PW_F054_MF130)]	; mm1=data6L
476
	pmaddwd   mm6,[GOTOFF(ebx,PW_F054_MF130)]	; mm6=data6H
477
478
	paddd	mm4,[GOTOFF(ebx,PD_DESCALE_P2)]
479
	paddd	mm0,[GOTOFF(ebx,PD_DESCALE_P2)]
480
	psrad	mm4,DESCALE_P2
481
	psrad	mm0,DESCALE_P2
482
	paddd	mm1,[GOTOFF(ebx,PD_DESCALE_P2)]
483
	paddd	mm6,[GOTOFF(ebx,PD_DESCALE_P2)]
484
	psrad	mm1,DESCALE_P2
485
	psrad	mm6,DESCALE_P2
486
487
	packssdw  mm4,mm0		; mm4=data2
488
	packssdw  mm1,mm6		; mm1=data6
489
490
	movq	MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4
491
	movq	MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)], mm1
492
493
	; -- Odd part
494
495
	movq	mm5, MMWORD [wk(0)]	; mm5=tmp6
496
	movq	mm7, MMWORD [wk(1)]	; mm7=tmp7
497
498
	movq	mm0,mm2			; mm2=tmp4
499
	movq	mm6,mm3			; mm3=tmp5
500
	paddw	mm0,mm5			; mm0=z3
501
	paddw	mm6,mm7			; mm6=z4
502
503
	; (Original)
504
	; z5 = (z3 + z4) * 1.175875602;
505
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
506
	; z3 += z5;  z4 += z5;
507
	;
508
	; (This implementation)
509
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
510
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
511
512
	movq      mm4,mm0
513
	movq      mm1,mm0
514
	punpcklwd mm4,mm6
515
	punpckhwd mm1,mm6
516
	movq      mm0,mm4
517
	movq      mm6,mm1
518
	pmaddwd   mm4,[GOTOFF(ebx,PW_MF078_F117)]	; mm4=z3L
519
	pmaddwd   mm1,[GOTOFF(ebx,PW_MF078_F117)]	; mm1=z3H
520
	pmaddwd   mm0,[GOTOFF(ebx,PW_F117_F078)]	; mm0=z4L
521
	pmaddwd   mm6,[GOTOFF(ebx,PW_F117_F078)]	; mm6=z4H
522
523
	movq	MMWORD [wk(0)], mm4	; wk(0)=z3L
524
	movq	MMWORD [wk(1)], mm1	; wk(1)=z3H
525
526
	; (Original)
527
	; z1 = tmp4 + tmp7;  z2 = tmp5 + tmp6;
528
	; tmp4 = tmp4 * 0.298631336;  tmp5 = tmp5 * 2.053119869;
529
	; tmp6 = tmp6 * 3.072711026;  tmp7 = tmp7 * 1.501321110;
530
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
531
	; data7 = tmp4 + z1 + z3;  data5 = tmp5 + z2 + z4;
532
	; data3 = tmp6 + z2 + z3;  data1 = tmp7 + z1 + z4;
533
	;
534
	; (This implementation)
535
	; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
536
	; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
537
	; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
538
	; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
539
	; data7 = tmp4 + z3;  data5 = tmp5 + z4;
540
	; data3 = tmp6 + z3;  data1 = tmp7 + z4;
541
542
	movq      mm4,mm2
543
	movq      mm1,mm2
544
	punpcklwd mm4,mm7
545
	punpckhwd mm1,mm7
546
	movq      mm2,mm4
547
	movq      mm7,mm1
548
	pmaddwd   mm4,[GOTOFF(ebx,PW_MF060_MF089)]	; mm4=tmp4L
549
	pmaddwd   mm1,[GOTOFF(ebx,PW_MF060_MF089)]	; mm1=tmp4H
550
	pmaddwd   mm2,[GOTOFF(ebx,PW_MF089_F060)]	; mm2=tmp7L
551
	pmaddwd   mm7,[GOTOFF(ebx,PW_MF089_F060)]	; mm7=tmp7H
552
553
	paddd	mm4, MMWORD [wk(0)]	; mm4=data7L
554
	paddd	mm1, MMWORD [wk(1)]	; mm1=data7H
555
	paddd	mm2,mm0			; mm2=data1L
556
	paddd	mm7,mm6			; mm7=data1H
557
558
	paddd	mm4,[GOTOFF(ebx,PD_DESCALE_P2)]
559
	paddd	mm1,[GOTOFF(ebx,PD_DESCALE_P2)]
560
	psrad	mm4,DESCALE_P2
561
	psrad	mm1,DESCALE_P2
562
	paddd	mm2,[GOTOFF(ebx,PD_DESCALE_P2)]
563
	paddd	mm7,[GOTOFF(ebx,PD_DESCALE_P2)]
564
	psrad	mm2,DESCALE_P2
565
	psrad	mm7,DESCALE_P2
566
567
	packssdw  mm4,mm1		; mm4=data7
568
	packssdw  mm2,mm7		; mm2=data1
569
570
	movq	MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)], mm4
571
	movq	MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm2
572
573
	movq      mm1,mm3
574
	movq      mm7,mm3
575
	punpcklwd mm1,mm5
576
	punpckhwd mm7,mm5
577
	movq      mm3,mm1
578
	movq      mm5,mm7
579
	pmaddwd   mm1,[GOTOFF(ebx,PW_MF050_MF256)]	; mm1=tmp5L
580
	pmaddwd   mm7,[GOTOFF(ebx,PW_MF050_MF256)]	; mm7=tmp5H
581
	pmaddwd   mm3,[GOTOFF(ebx,PW_MF256_F050)]	; mm3=tmp6L
582
	pmaddwd   mm5,[GOTOFF(ebx,PW_MF256_F050)]	; mm5=tmp6H
583
584
	paddd	mm1,mm0			; mm1=data5L
585
	paddd	mm7,mm6			; mm7=data5H
586
	paddd	mm3, MMWORD [wk(0)]	; mm3=data3L
587
	paddd	mm5, MMWORD [wk(1)]	; mm5=data3H
588
589
	paddd	mm1,[GOTOFF(ebx,PD_DESCALE_P2)]
590
	paddd	mm7,[GOTOFF(ebx,PD_DESCALE_P2)]
591
	psrad	mm1,DESCALE_P2
592
	psrad	mm7,DESCALE_P2
593
	paddd	mm3,[GOTOFF(ebx,PD_DESCALE_P2)]
594
	paddd	mm5,[GOTOFF(ebx,PD_DESCALE_P2)]
595
	psrad	mm3,DESCALE_P2
596
	psrad	mm5,DESCALE_P2
597
598
	packssdw  mm1,mm7		; mm1=data5
599
	packssdw  mm3,mm5		; mm3=data3
600
601
	movq	MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)], mm1
602
	movq	MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm3
603
604
	add	edx, byte 4*SIZEOF_DCTELEM
605
	dec	ecx
606
	jnz	near .columnloop
607
608
	emms		; empty MMX state
609
610
;	pop	edi		; unused
611
;	pop	esi		; unused
612
;	pop	edx		; need not be preserved
613
;	pop	ecx		; need not be preserved
614
	poppic	ebx
615
	mov	esp,ebp		; esp <- aligned ebp
616
	pop	esp		; esp <- original ebp
617
	pop	ebp
618
	ret
619
620
; For some reason, the OS X linker does not honor the request to align the
621
; segment unless we do this.
622
	align	16
(-)a/jpeg/simd/jfss2fst-64.asm (+392 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jfss2fst-64.asm - fast integer FDCT (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; This file contains a fast, not so accurate integer implementation of
19
; the forward DCT (Discrete Cosine Transform). The following code is
20
; based directly on the IJG's original jfdctfst.c; see the jfdctfst.c
21
; for more details.
22
;
23
; [TAB8]
24
25
%include "jsimdext.inc"
26
%include "jdct.inc"
27
28
; --------------------------------------------------------------------------
29
30
%define CONST_BITS	8	; 14 is also OK.
31
32
%if CONST_BITS == 8
33
F_0_382	equ	 98		; FIX(0.382683433)
34
F_0_541	equ	139		; FIX(0.541196100)
35
F_0_707	equ	181		; FIX(0.707106781)
36
F_1_306	equ	334		; FIX(1.306562965)
37
%else
38
; NASM cannot do compile-time arithmetic on floating-point constants.
39
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
40
F_0_382	equ	DESCALE( 410903207,30-CONST_BITS)	; FIX(0.382683433)
41
F_0_541	equ	DESCALE( 581104887,30-CONST_BITS)	; FIX(0.541196100)
42
F_0_707	equ	DESCALE( 759250124,30-CONST_BITS)	; FIX(0.707106781)
43
F_1_306	equ	DESCALE(1402911301,30-CONST_BITS)	; FIX(1.306562965)
44
%endif
45
46
; --------------------------------------------------------------------------
47
	SECTION	SEG_CONST
48
49
; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
50
; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
51
52
%define PRE_MULTIPLY_SCALE_BITS   2
53
%define CONST_SHIFT     (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
54
55
	alignz	16
56
	global	EXTN(jconst_fdct_ifast_sse2)
57
58
EXTN(jconst_fdct_ifast_sse2):
59
60
PW_F0707	times 8 dw  F_0_707 << CONST_SHIFT
61
PW_F0382	times 8 dw  F_0_382 << CONST_SHIFT
62
PW_F0541	times 8 dw  F_0_541 << CONST_SHIFT
63
PW_F1306	times 8 dw  F_1_306 << CONST_SHIFT
64
65
	alignz	16
66
67
; --------------------------------------------------------------------------
68
	SECTION	SEG_TEXT
69
	BITS	64
70
;
71
; Perform the forward DCT on one block of samples.
72
;
73
; GLOBAL(void)
74
; jsimd_fdct_ifast_sse2 (DCTELEM * data)
75
;
76
77
; r10 = DCTELEM * data
78
79
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
80
%define WK_NUM		2
81
82
	align	16
83
	global	EXTN(jsimd_fdct_ifast_sse2)
84
85
EXTN(jsimd_fdct_ifast_sse2):
86
	push	rbp
87
	mov	rax,rsp				; rax = original rbp
88
	sub	rsp, byte 4
89
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
90
	mov	[rsp],rax
91
	mov	rbp,rsp				; rbp = aligned rbp
92
	lea	rsp, [wk(0)]
93
	collect_args
94
95
	; ---- Pass 1: process rows.
96
97
	mov	rdx, r10	; (DCTELEM *)
98
99
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)]
100
	movdqa	xmm1, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)]
101
	movdqa	xmm2, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)]
102
	movdqa	xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)]
103
104
	; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27)
105
	; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37)
106
107
	movdqa    xmm4,xmm0		; transpose coefficients(phase 1)
108
	punpcklwd xmm0,xmm1		; xmm0=(00 10 01 11 02 12 03 13)
109
	punpckhwd xmm4,xmm1		; xmm4=(04 14 05 15 06 16 07 17)
110
	movdqa    xmm5,xmm2		; transpose coefficients(phase 1)
111
	punpcklwd xmm2,xmm3		; xmm2=(20 30 21 31 22 32 23 33)
112
	punpckhwd xmm5,xmm3		; xmm5=(24 34 25 35 26 36 27 37)
113
114
	movdqa	xmm6, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)]
115
	movdqa	xmm7, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)]
116
	movdqa	xmm1, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)]
117
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)]
118
119
	; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62)
120
	; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63)
121
122
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=(20 30 21 31 22 32 23 33)
123
	movdqa	XMMWORD [wk(1)], xmm5	; wk(1)=(24 34 25 35 26 36 27 37)
124
125
	movdqa    xmm2,xmm6		; transpose coefficients(phase 1)
126
	punpcklwd xmm6,xmm7		; xmm6=(40 50 41 51 42 52 43 53)
127
	punpckhwd xmm2,xmm7		; xmm2=(44 54 45 55 46 56 47 57)
128
	movdqa    xmm5,xmm1		; transpose coefficients(phase 1)
129
	punpcklwd xmm1,xmm3		; xmm1=(60 70 61 71 62 72 63 73)
130
	punpckhwd xmm5,xmm3		; xmm5=(64 74 65 75 66 76 67 77)
131
132
	movdqa    xmm7,xmm6		; transpose coefficients(phase 2)
133
	punpckldq xmm6,xmm1		; xmm6=(40 50 60 70 41 51 61 71)
134
	punpckhdq xmm7,xmm1		; xmm7=(42 52 62 72 43 53 63 73)
135
	movdqa    xmm3,xmm2		; transpose coefficients(phase 2)
136
	punpckldq xmm2,xmm5		; xmm2=(44 54 64 74 45 55 65 75)
137
	punpckhdq xmm3,xmm5		; xmm3=(46 56 66 76 47 57 67 77)
138
139
	movdqa	xmm1, XMMWORD [wk(0)]	; xmm1=(20 30 21 31 22 32 23 33)
140
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=(24 34 25 35 26 36 27 37)
141
	movdqa	XMMWORD [wk(0)], xmm7	; wk(0)=(42 52 62 72 43 53 63 73)
142
	movdqa	XMMWORD [wk(1)], xmm2	; wk(1)=(44 54 64 74 45 55 65 75)
143
144
	movdqa    xmm7,xmm0		; transpose coefficients(phase 2)
145
	punpckldq xmm0,xmm1		; xmm0=(00 10 20 30 01 11 21 31)
146
	punpckhdq xmm7,xmm1		; xmm7=(02 12 22 32 03 13 23 33)
147
	movdqa    xmm2,xmm4		; transpose coefficients(phase 2)
148
	punpckldq xmm4,xmm5		; xmm4=(04 14 24 34 05 15 25 35)
149
	punpckhdq xmm2,xmm5		; xmm2=(06 16 26 36 07 17 27 37)
150
151
	movdqa     xmm1,xmm0		; transpose coefficients(phase 3)
152
	punpcklqdq xmm0,xmm6		; xmm0=(00 10 20 30 40 50 60 70)=data0
153
	punpckhqdq xmm1,xmm6		; xmm1=(01 11 21 31 41 51 61 71)=data1
154
	movdqa     xmm5,xmm2		; transpose coefficients(phase 3)
155
	punpcklqdq xmm2,xmm3		; xmm2=(06 16 26 36 46 56 66 76)=data6
156
	punpckhqdq xmm5,xmm3		; xmm5=(07 17 27 37 47 57 67 77)=data7
157
158
	movdqa	xmm6,xmm1
159
	movdqa	xmm3,xmm0
160
	psubw	xmm1,xmm2		; xmm1=data1-data6=tmp6
161
	psubw	xmm0,xmm5		; xmm0=data0-data7=tmp7
162
	paddw	xmm6,xmm2		; xmm6=data1+data6=tmp1
163
	paddw	xmm3,xmm5		; xmm3=data0+data7=tmp0
164
165
	movdqa	xmm2, XMMWORD [wk(0)]	; xmm2=(42 52 62 72 43 53 63 73)
166
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=(44 54 64 74 45 55 65 75)
167
	movdqa	XMMWORD [wk(0)], xmm1	; wk(0)=tmp6
168
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=tmp7
169
170
	movdqa     xmm1,xmm7		; transpose coefficients(phase 3)
171
	punpcklqdq xmm7,xmm2		; xmm7=(02 12 22 32 42 52 62 72)=data2
172
	punpckhqdq xmm1,xmm2		; xmm1=(03 13 23 33 43 53 63 73)=data3
173
	movdqa     xmm0,xmm4		; transpose coefficients(phase 3)
174
	punpcklqdq xmm4,xmm5		; xmm4=(04 14 24 34 44 54 64 74)=data4
175
	punpckhqdq xmm0,xmm5		; xmm0=(05 15 25 35 45 55 65 75)=data5
176
177
	movdqa	xmm2,xmm1
178
	movdqa	xmm5,xmm7
179
	paddw	xmm1,xmm4		; xmm1=data3+data4=tmp3
180
	paddw	xmm7,xmm0		; xmm7=data2+data5=tmp2
181
	psubw	xmm2,xmm4		; xmm2=data3-data4=tmp4
182
	psubw	xmm5,xmm0		; xmm5=data2-data5=tmp5
183
184
	; -- Even part
185
186
	movdqa	xmm4,xmm3
187
	movdqa	xmm0,xmm6
188
	psubw	xmm3,xmm1		; xmm3=tmp13
189
	psubw	xmm6,xmm7		; xmm6=tmp12
190
	paddw	xmm4,xmm1		; xmm4=tmp10
191
	paddw	xmm0,xmm7		; xmm0=tmp11
192
193
	paddw	xmm6,xmm3
194
	psllw	xmm6,PRE_MULTIPLY_SCALE_BITS
195
	pmulhw	xmm6,[rel PW_F0707] ; xmm6=z1
196
197
	movdqa	xmm1,xmm4
198
	movdqa	xmm7,xmm3
199
	psubw	xmm4,xmm0		; xmm4=data4
200
	psubw	xmm3,xmm6		; xmm3=data6
201
	paddw	xmm1,xmm0		; xmm1=data0
202
	paddw	xmm7,xmm6		; xmm7=data2
203
204
	movdqa	xmm0, XMMWORD [wk(0)]	; xmm0=tmp6
205
	movdqa	xmm6, XMMWORD [wk(1)]	; xmm6=tmp7
206
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=data4
207
	movdqa	XMMWORD [wk(1)], xmm3	; wk(1)=data6
208
209
	; -- Odd part
210
211
	paddw	xmm2,xmm5		; xmm2=tmp10
212
	paddw	xmm5,xmm0		; xmm5=tmp11
213
	paddw	xmm0,xmm6		; xmm0=tmp12, xmm6=tmp7
214
215
	psllw	xmm2,PRE_MULTIPLY_SCALE_BITS
216
	psllw	xmm0,PRE_MULTIPLY_SCALE_BITS
217
218
	psllw	xmm5,PRE_MULTIPLY_SCALE_BITS
219
	pmulhw	xmm5,[rel PW_F0707] ; xmm5=z3
220
221
	movdqa	xmm4,xmm2		; xmm4=tmp10
222
	psubw	xmm2,xmm0
223
	pmulhw	xmm2,[rel PW_F0382] ; xmm2=z5
224
	pmulhw	xmm4,[rel PW_F0541] ; xmm4=MULTIPLY(tmp10,FIX_0_541196)
225
	pmulhw	xmm0,[rel PW_F1306] ; xmm0=MULTIPLY(tmp12,FIX_1_306562)
226
	paddw	xmm4,xmm2		; xmm4=z2
227
	paddw	xmm0,xmm2		; xmm0=z4
228
229
	movdqa	xmm3,xmm6
230
	psubw	xmm6,xmm5		; xmm6=z13
231
	paddw	xmm3,xmm5		; xmm3=z11
232
233
	movdqa	xmm2,xmm6
234
	movdqa	xmm5,xmm3
235
	psubw	xmm6,xmm4		; xmm6=data3
236
	psubw	xmm3,xmm0		; xmm3=data7
237
	paddw	xmm2,xmm4		; xmm2=data5
238
	paddw	xmm5,xmm0		; xmm5=data1
239
240
	; ---- Pass 2: process columns.
241
242
	; xmm1=(00 10 20 30 40 50 60 70), xmm7=(02 12 22 32 42 52 62 72)
243
	; xmm5=(01 11 21 31 41 51 61 71), xmm6=(03 13 23 33 43 53 63 73)
244
245
	movdqa    xmm4,xmm1		; transpose coefficients(phase 1)
246
	punpcklwd xmm1,xmm5		; xmm1=(00 01 10 11 20 21 30 31)
247
	punpckhwd xmm4,xmm5		; xmm4=(40 41 50 51 60 61 70 71)
248
	movdqa    xmm0,xmm7		; transpose coefficients(phase 1)
249
	punpcklwd xmm7,xmm6		; xmm7=(02 03 12 13 22 23 32 33)
250
	punpckhwd xmm0,xmm6		; xmm0=(42 43 52 53 62 63 72 73)
251
252
	movdqa	xmm5, XMMWORD [wk(0)]	; xmm5=col4
253
	movdqa	xmm6, XMMWORD [wk(1)]	; xmm6=col6
254
255
	; xmm5=(04 14 24 34 44 54 64 74), xmm6=(06 16 26 36 46 56 66 76)
256
	; xmm2=(05 15 25 35 45 55 65 75), xmm3=(07 17 27 37 47 57 67 77)
257
258
	movdqa	XMMWORD [wk(0)], xmm7	; wk(0)=(02 03 12 13 22 23 32 33)
259
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=(42 43 52 53 62 63 72 73)
260
261
	movdqa    xmm7,xmm5		; transpose coefficients(phase 1)
262
	punpcklwd xmm5,xmm2		; xmm5=(04 05 14 15 24 25 34 35)
263
	punpckhwd xmm7,xmm2		; xmm7=(44 45 54 55 64 65 74 75)
264
	movdqa    xmm0,xmm6		; transpose coefficients(phase 1)
265
	punpcklwd xmm6,xmm3		; xmm6=(06 07 16 17 26 27 36 37)
266
	punpckhwd xmm0,xmm3		; xmm0=(46 47 56 57 66 67 76 77)
267
268
	movdqa    xmm2,xmm5		; transpose coefficients(phase 2)
269
	punpckldq xmm5,xmm6		; xmm5=(04 05 06 07 14 15 16 17)
270
	punpckhdq xmm2,xmm6		; xmm2=(24 25 26 27 34 35 36 37)
271
	movdqa    xmm3,xmm7		; transpose coefficients(phase 2)
272
	punpckldq xmm7,xmm0		; xmm7=(44 45 46 47 54 55 56 57)
273
	punpckhdq xmm3,xmm0		; xmm3=(64 65 66 67 74 75 76 77)
274
275
	movdqa	xmm6, XMMWORD [wk(0)]	; xmm6=(02 03 12 13 22 23 32 33)
276
	movdqa	xmm0, XMMWORD [wk(1)]	; xmm0=(42 43 52 53 62 63 72 73)
277
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=(24 25 26 27 34 35 36 37)
278
	movdqa	XMMWORD [wk(1)], xmm7	; wk(1)=(44 45 46 47 54 55 56 57)
279
280
	movdqa    xmm2,xmm1		; transpose coefficients(phase 2)
281
	punpckldq xmm1,xmm6		; xmm1=(00 01 02 03 10 11 12 13)
282
	punpckhdq xmm2,xmm6		; xmm2=(20 21 22 23 30 31 32 33)
283
	movdqa    xmm7,xmm4		; transpose coefficients(phase 2)
284
	punpckldq xmm4,xmm0		; xmm4=(40 41 42 43 50 51 52 53)
285
	punpckhdq xmm7,xmm0		; xmm7=(60 61 62 63 70 71 72 73)
286
287
	movdqa     xmm6,xmm1		; transpose coefficients(phase 3)
288
	punpcklqdq xmm1,xmm5		; xmm1=(00 01 02 03 04 05 06 07)=data0
289
	punpckhqdq xmm6,xmm5		; xmm6=(10 11 12 13 14 15 16 17)=data1
290
	movdqa     xmm0,xmm7		; transpose coefficients(phase 3)
291
	punpcklqdq xmm7,xmm3		; xmm7=(60 61 62 63 64 65 66 67)=data6
292
	punpckhqdq xmm0,xmm3		; xmm0=(70 71 72 73 74 75 76 77)=data7
293
294
	movdqa	xmm5,xmm6
295
	movdqa	xmm3,xmm1
296
	psubw	xmm6,xmm7		; xmm6=data1-data6=tmp6
297
	psubw	xmm1,xmm0		; xmm1=data0-data7=tmp7
298
	paddw	xmm5,xmm7		; xmm5=data1+data6=tmp1
299
	paddw	xmm3,xmm0		; xmm3=data0+data7=tmp0
300
301
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=(24 25 26 27 34 35 36 37)
302
	movdqa	xmm0, XMMWORD [wk(1)]	; xmm0=(44 45 46 47 54 55 56 57)
303
	movdqa	XMMWORD [wk(0)], xmm6	; wk(0)=tmp6
304
	movdqa	XMMWORD [wk(1)], xmm1	; wk(1)=tmp7
305
306
	movdqa     xmm6,xmm2		; transpose coefficients(phase 3)
307
	punpcklqdq xmm2,xmm7		; xmm2=(20 21 22 23 24 25 26 27)=data2
308
	punpckhqdq xmm6,xmm7		; xmm6=(30 31 32 33 34 35 36 37)=data3
309
	movdqa     xmm1,xmm4		; transpose coefficients(phase 3)
310
	punpcklqdq xmm4,xmm0		; xmm4=(40 41 42 43 44 45 46 47)=data4
311
	punpckhqdq xmm1,xmm0		; xmm1=(50 51 52 53 54 55 56 57)=data5
312
313
	movdqa	xmm7,xmm6
314
	movdqa	xmm0,xmm2
315
	paddw	xmm6,xmm4		; xmm6=data3+data4=tmp3
316
	paddw	xmm2,xmm1		; xmm2=data2+data5=tmp2
317
	psubw	xmm7,xmm4		; xmm7=data3-data4=tmp4
318
	psubw	xmm0,xmm1		; xmm0=data2-data5=tmp5
319
320
	; -- Even part
321
322
	movdqa	xmm4,xmm3
323
	movdqa	xmm1,xmm5
324
	psubw	xmm3,xmm6		; xmm3=tmp13
325
	psubw	xmm5,xmm2		; xmm5=tmp12
326
	paddw	xmm4,xmm6		; xmm4=tmp10
327
	paddw	xmm1,xmm2		; xmm1=tmp11
328
329
	paddw	xmm5,xmm3
330
	psllw	xmm5,PRE_MULTIPLY_SCALE_BITS
331
	pmulhw	xmm5,[rel PW_F0707] ; xmm5=z1
332
333
	movdqa	xmm6,xmm4
334
	movdqa	xmm2,xmm3
335
	psubw	xmm4,xmm1		; xmm4=data4
336
	psubw	xmm3,xmm5		; xmm3=data6
337
	paddw	xmm6,xmm1		; xmm6=data0
338
	paddw	xmm2,xmm5		; xmm2=data2
339
340
	movdqa	XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)], xmm4
341
	movdqa	XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)], xmm3
342
	movdqa	XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)], xmm6
343
	movdqa	XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)], xmm2
344
345
	; -- Odd part
346
347
	movdqa	xmm1, XMMWORD [wk(0)]	; xmm1=tmp6
348
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=tmp7
349
350
	paddw	xmm7,xmm0		; xmm7=tmp10
351
	paddw	xmm0,xmm1		; xmm0=tmp11
352
	paddw	xmm1,xmm5		; xmm1=tmp12, xmm5=tmp7
353
354
	psllw	xmm7,PRE_MULTIPLY_SCALE_BITS
355
	psllw	xmm1,PRE_MULTIPLY_SCALE_BITS
356
357
	psllw	xmm0,PRE_MULTIPLY_SCALE_BITS
358
	pmulhw	xmm0,[rel PW_F0707] ; xmm0=z3
359
360
	movdqa	xmm4,xmm7		; xmm4=tmp10
361
	psubw	xmm7,xmm1
362
	pmulhw	xmm7,[rel PW_F0382] ; xmm7=z5
363
	pmulhw	xmm4,[rel PW_F0541] ; xmm4=MULTIPLY(tmp10,FIX_0_541196)
364
	pmulhw	xmm1,[rel PW_F1306] ; xmm1=MULTIPLY(tmp12,FIX_1_306562)
365
	paddw	xmm4,xmm7		; xmm4=z2
366
	paddw	xmm1,xmm7		; xmm1=z4
367
368
	movdqa	xmm3,xmm5
369
	psubw	xmm5,xmm0		; xmm5=z13
370
	paddw	xmm3,xmm0		; xmm3=z11
371
372
	movdqa	xmm6,xmm5
373
	movdqa	xmm2,xmm3
374
	psubw	xmm5,xmm4		; xmm5=data3
375
	psubw	xmm3,xmm1		; xmm3=data7
376
	paddw	xmm6,xmm4		; xmm6=data5
377
	paddw	xmm2,xmm1		; xmm2=data1
378
379
	movdqa	XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)], xmm5
380
	movdqa	XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)], xmm3
381
	movdqa	XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)], xmm6
382
	movdqa	XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)], xmm2
383
384
	uncollect_args
385
	mov	rsp,rbp		; rsp <- aligned rbp
386
	pop	rsp		; rsp <- original rbp
387
	pop	rbp
388
	ret
389
390
; For some reason, the OS X linker does not honor the request to align the
391
; segment unless we do this.
392
	align	16
(-)a/jpeg/simd/jfss2fst.asm (+404 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jfss2fst.asm - fast integer FDCT (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a fast, not so accurate integer implementation of
18
; the forward DCT (Discrete Cosine Transform). The following code is
19
; based directly on the IJG's original jfdctfst.c; see the jfdctfst.c
20
; for more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	8	; 14 is also OK.
30
31
%if CONST_BITS == 8
32
F_0_382	equ	 98		; FIX(0.382683433)
33
F_0_541	equ	139		; FIX(0.541196100)
34
F_0_707	equ	181		; FIX(0.707106781)
35
F_1_306	equ	334		; FIX(1.306562965)
36
%else
37
; NASM cannot do compile-time arithmetic on floating-point constants.
38
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
39
F_0_382	equ	DESCALE( 410903207,30-CONST_BITS)	; FIX(0.382683433)
40
F_0_541	equ	DESCALE( 581104887,30-CONST_BITS)	; FIX(0.541196100)
41
F_0_707	equ	DESCALE( 759250124,30-CONST_BITS)	; FIX(0.707106781)
42
F_1_306	equ	DESCALE(1402911301,30-CONST_BITS)	; FIX(1.306562965)
43
%endif
44
45
; --------------------------------------------------------------------------
46
	SECTION	SEG_CONST
47
48
; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
49
; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
50
51
%define PRE_MULTIPLY_SCALE_BITS   2
52
%define CONST_SHIFT     (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
53
54
	alignz	16
55
	global	EXTN(jconst_fdct_ifast_sse2)
56
57
EXTN(jconst_fdct_ifast_sse2):
58
59
PW_F0707	times 8 dw  F_0_707 << CONST_SHIFT
60
PW_F0382	times 8 dw  F_0_382 << CONST_SHIFT
61
PW_F0541	times 8 dw  F_0_541 << CONST_SHIFT
62
PW_F1306	times 8 dw  F_1_306 << CONST_SHIFT
63
64
	alignz	16
65
66
; --------------------------------------------------------------------------
67
	SECTION	SEG_TEXT
68
	BITS	32
69
;
70
; Perform the forward DCT on one block of samples.
71
;
72
; GLOBAL(void)
73
; jsimd_fdct_ifast_sse2 (DCTELEM * data)
74
;
75
76
%define data(b)		(b)+8		; DCTELEM * data
77
78
%define original_ebp	ebp+0
79
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
80
%define WK_NUM		2
81
82
	align	16
83
	global	EXTN(jsimd_fdct_ifast_sse2)
84
85
EXTN(jsimd_fdct_ifast_sse2):
86
	push	ebp
87
	mov	eax,esp				; eax = original ebp
88
	sub	esp, byte 4
89
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
90
	mov	[esp],eax
91
	mov	ebp,esp				; ebp = aligned ebp
92
	lea	esp, [wk(0)]
93
	pushpic	ebx
94
;	push	ecx		; unused
95
;	push	edx		; need not be preserved
96
;	push	esi		; unused
97
;	push	edi		; unused
98
99
	get_GOT	ebx		; get GOT address
100
101
	; ---- Pass 1: process rows.
102
103
	mov	edx, POINTER [data(eax)]	; (DCTELEM *)
104
105
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
106
	movdqa	xmm1, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
107
	movdqa	xmm2, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
108
	movdqa	xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
109
110
	; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27)
111
	; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37)
112
113
	movdqa    xmm4,xmm0		; transpose coefficients(phase 1)
114
	punpcklwd xmm0,xmm1		; xmm0=(00 10 01 11 02 12 03 13)
115
	punpckhwd xmm4,xmm1		; xmm4=(04 14 05 15 06 16 07 17)
116
	movdqa    xmm5,xmm2		; transpose coefficients(phase 1)
117
	punpcklwd xmm2,xmm3		; xmm2=(20 30 21 31 22 32 23 33)
118
	punpckhwd xmm5,xmm3		; xmm5=(24 34 25 35 26 36 27 37)
119
120
	movdqa	xmm6, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)]
121
	movdqa	xmm7, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)]
122
	movdqa	xmm1, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)]
123
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)]
124
125
	; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62)
126
	; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63)
127
128
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=(20 30 21 31 22 32 23 33)
129
	movdqa	XMMWORD [wk(1)], xmm5	; wk(1)=(24 34 25 35 26 36 27 37)
130
131
	movdqa    xmm2,xmm6		; transpose coefficients(phase 1)
132
	punpcklwd xmm6,xmm7		; xmm6=(40 50 41 51 42 52 43 53)
133
	punpckhwd xmm2,xmm7		; xmm2=(44 54 45 55 46 56 47 57)
134
	movdqa    xmm5,xmm1		; transpose coefficients(phase 1)
135
	punpcklwd xmm1,xmm3		; xmm1=(60 70 61 71 62 72 63 73)
136
	punpckhwd xmm5,xmm3		; xmm5=(64 74 65 75 66 76 67 77)
137
138
	movdqa    xmm7,xmm6		; transpose coefficients(phase 2)
139
	punpckldq xmm6,xmm1		; xmm6=(40 50 60 70 41 51 61 71)
140
	punpckhdq xmm7,xmm1		; xmm7=(42 52 62 72 43 53 63 73)
141
	movdqa    xmm3,xmm2		; transpose coefficients(phase 2)
142
	punpckldq xmm2,xmm5		; xmm2=(44 54 64 74 45 55 65 75)
143
	punpckhdq xmm3,xmm5		; xmm3=(46 56 66 76 47 57 67 77)
144
145
	movdqa	xmm1, XMMWORD [wk(0)]	; xmm1=(20 30 21 31 22 32 23 33)
146
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=(24 34 25 35 26 36 27 37)
147
	movdqa	XMMWORD [wk(0)], xmm7	; wk(0)=(42 52 62 72 43 53 63 73)
148
	movdqa	XMMWORD [wk(1)], xmm2	; wk(1)=(44 54 64 74 45 55 65 75)
149
150
	movdqa    xmm7,xmm0		; transpose coefficients(phase 2)
151
	punpckldq xmm0,xmm1		; xmm0=(00 10 20 30 01 11 21 31)
152
	punpckhdq xmm7,xmm1		; xmm7=(02 12 22 32 03 13 23 33)
153
	movdqa    xmm2,xmm4		; transpose coefficients(phase 2)
154
	punpckldq xmm4,xmm5		; xmm4=(04 14 24 34 05 15 25 35)
155
	punpckhdq xmm2,xmm5		; xmm2=(06 16 26 36 07 17 27 37)
156
157
	movdqa     xmm1,xmm0		; transpose coefficients(phase 3)
158
	punpcklqdq xmm0,xmm6		; xmm0=(00 10 20 30 40 50 60 70)=data0
159
	punpckhqdq xmm1,xmm6		; xmm1=(01 11 21 31 41 51 61 71)=data1
160
	movdqa     xmm5,xmm2		; transpose coefficients(phase 3)
161
	punpcklqdq xmm2,xmm3		; xmm2=(06 16 26 36 46 56 66 76)=data6
162
	punpckhqdq xmm5,xmm3		; xmm5=(07 17 27 37 47 57 67 77)=data7
163
164
	movdqa	xmm6,xmm1
165
	movdqa	xmm3,xmm0
166
	psubw	xmm1,xmm2		; xmm1=data1-data6=tmp6
167
	psubw	xmm0,xmm5		; xmm0=data0-data7=tmp7
168
	paddw	xmm6,xmm2		; xmm6=data1+data6=tmp1
169
	paddw	xmm3,xmm5		; xmm3=data0+data7=tmp0
170
171
	movdqa	xmm2, XMMWORD [wk(0)]	; xmm2=(42 52 62 72 43 53 63 73)
172
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=(44 54 64 74 45 55 65 75)
173
	movdqa	XMMWORD [wk(0)], xmm1	; wk(0)=tmp6
174
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=tmp7
175
176
	movdqa     xmm1,xmm7		; transpose coefficients(phase 3)
177
	punpcklqdq xmm7,xmm2		; xmm7=(02 12 22 32 42 52 62 72)=data2
178
	punpckhqdq xmm1,xmm2		; xmm1=(03 13 23 33 43 53 63 73)=data3
179
	movdqa     xmm0,xmm4		; transpose coefficients(phase 3)
180
	punpcklqdq xmm4,xmm5		; xmm4=(04 14 24 34 44 54 64 74)=data4
181
	punpckhqdq xmm0,xmm5		; xmm0=(05 15 25 35 45 55 65 75)=data5
182
183
	movdqa	xmm2,xmm1
184
	movdqa	xmm5,xmm7
185
	paddw	xmm1,xmm4		; xmm1=data3+data4=tmp3
186
	paddw	xmm7,xmm0		; xmm7=data2+data5=tmp2
187
	psubw	xmm2,xmm4		; xmm2=data3-data4=tmp4
188
	psubw	xmm5,xmm0		; xmm5=data2-data5=tmp5
189
190
	; -- Even part
191
192
	movdqa	xmm4,xmm3
193
	movdqa	xmm0,xmm6
194
	psubw	xmm3,xmm1		; xmm3=tmp13
195
	psubw	xmm6,xmm7		; xmm6=tmp12
196
	paddw	xmm4,xmm1		; xmm4=tmp10
197
	paddw	xmm0,xmm7		; xmm0=tmp11
198
199
	paddw	xmm6,xmm3
200
	psllw	xmm6,PRE_MULTIPLY_SCALE_BITS
201
	pmulhw	xmm6,[GOTOFF(ebx,PW_F0707)] ; xmm6=z1
202
203
	movdqa	xmm1,xmm4
204
	movdqa	xmm7,xmm3
205
	psubw	xmm4,xmm0		; xmm4=data4
206
	psubw	xmm3,xmm6		; xmm3=data6
207
	paddw	xmm1,xmm0		; xmm1=data0
208
	paddw	xmm7,xmm6		; xmm7=data2
209
210
	movdqa	xmm0, XMMWORD [wk(0)]	; xmm0=tmp6
211
	movdqa	xmm6, XMMWORD [wk(1)]	; xmm6=tmp7
212
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=data4
213
	movdqa	XMMWORD [wk(1)], xmm3	; wk(1)=data6
214
215
	; -- Odd part
216
217
	paddw	xmm2,xmm5		; xmm2=tmp10
218
	paddw	xmm5,xmm0		; xmm5=tmp11
219
	paddw	xmm0,xmm6		; xmm0=tmp12, xmm6=tmp7
220
221
	psllw	xmm2,PRE_MULTIPLY_SCALE_BITS
222
	psllw	xmm0,PRE_MULTIPLY_SCALE_BITS
223
224
	psllw	xmm5,PRE_MULTIPLY_SCALE_BITS
225
	pmulhw	xmm5,[GOTOFF(ebx,PW_F0707)] ; xmm5=z3
226
227
	movdqa	xmm4,xmm2		; xmm4=tmp10
228
	psubw	xmm2,xmm0
229
	pmulhw	xmm2,[GOTOFF(ebx,PW_F0382)] ; xmm2=z5
230
	pmulhw	xmm4,[GOTOFF(ebx,PW_F0541)] ; xmm4=MULTIPLY(tmp10,FIX_0_541196)
231
	pmulhw	xmm0,[GOTOFF(ebx,PW_F1306)] ; xmm0=MULTIPLY(tmp12,FIX_1_306562)
232
	paddw	xmm4,xmm2		; xmm4=z2
233
	paddw	xmm0,xmm2		; xmm0=z4
234
235
	movdqa	xmm3,xmm6
236
	psubw	xmm6,xmm5		; xmm6=z13
237
	paddw	xmm3,xmm5		; xmm3=z11
238
239
	movdqa	xmm2,xmm6
240
	movdqa	xmm5,xmm3
241
	psubw	xmm6,xmm4		; xmm6=data3
242
	psubw	xmm3,xmm0		; xmm3=data7
243
	paddw	xmm2,xmm4		; xmm2=data5
244
	paddw	xmm5,xmm0		; xmm5=data1
245
246
	; ---- Pass 2: process columns.
247
248
;	mov	edx, POINTER [data(eax)]	; (DCTELEM *)
249
250
	; xmm1=(00 10 20 30 40 50 60 70), xmm7=(02 12 22 32 42 52 62 72)
251
	; xmm5=(01 11 21 31 41 51 61 71), xmm6=(03 13 23 33 43 53 63 73)
252
253
	movdqa    xmm4,xmm1		; transpose coefficients(phase 1)
254
	punpcklwd xmm1,xmm5		; xmm1=(00 01 10 11 20 21 30 31)
255
	punpckhwd xmm4,xmm5		; xmm4=(40 41 50 51 60 61 70 71)
256
	movdqa    xmm0,xmm7		; transpose coefficients(phase 1)
257
	punpcklwd xmm7,xmm6		; xmm7=(02 03 12 13 22 23 32 33)
258
	punpckhwd xmm0,xmm6		; xmm0=(42 43 52 53 62 63 72 73)
259
260
	movdqa	xmm5, XMMWORD [wk(0)]	; xmm5=col4
261
	movdqa	xmm6, XMMWORD [wk(1)]	; xmm6=col6
262
263
	; xmm5=(04 14 24 34 44 54 64 74), xmm6=(06 16 26 36 46 56 66 76)
264
	; xmm2=(05 15 25 35 45 55 65 75), xmm3=(07 17 27 37 47 57 67 77)
265
266
	movdqa	XMMWORD [wk(0)], xmm7	; wk(0)=(02 03 12 13 22 23 32 33)
267
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=(42 43 52 53 62 63 72 73)
268
269
	movdqa    xmm7,xmm5		; transpose coefficients(phase 1)
270
	punpcklwd xmm5,xmm2		; xmm5=(04 05 14 15 24 25 34 35)
271
	punpckhwd xmm7,xmm2		; xmm7=(44 45 54 55 64 65 74 75)
272
	movdqa    xmm0,xmm6		; transpose coefficients(phase 1)
273
	punpcklwd xmm6,xmm3		; xmm6=(06 07 16 17 26 27 36 37)
274
	punpckhwd xmm0,xmm3		; xmm0=(46 47 56 57 66 67 76 77)
275
276
	movdqa    xmm2,xmm5		; transpose coefficients(phase 2)
277
	punpckldq xmm5,xmm6		; xmm5=(04 05 06 07 14 15 16 17)
278
	punpckhdq xmm2,xmm6		; xmm2=(24 25 26 27 34 35 36 37)
279
	movdqa    xmm3,xmm7		; transpose coefficients(phase 2)
280
	punpckldq xmm7,xmm0		; xmm7=(44 45 46 47 54 55 56 57)
281
	punpckhdq xmm3,xmm0		; xmm3=(64 65 66 67 74 75 76 77)
282
283
	movdqa	xmm6, XMMWORD [wk(0)]	; xmm6=(02 03 12 13 22 23 32 33)
284
	movdqa	xmm0, XMMWORD [wk(1)]	; xmm0=(42 43 52 53 62 63 72 73)
285
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=(24 25 26 27 34 35 36 37)
286
	movdqa	XMMWORD [wk(1)], xmm7	; wk(1)=(44 45 46 47 54 55 56 57)
287
288
	movdqa    xmm2,xmm1		; transpose coefficients(phase 2)
289
	punpckldq xmm1,xmm6		; xmm1=(00 01 02 03 10 11 12 13)
290
	punpckhdq xmm2,xmm6		; xmm2=(20 21 22 23 30 31 32 33)
291
	movdqa    xmm7,xmm4		; transpose coefficients(phase 2)
292
	punpckldq xmm4,xmm0		; xmm4=(40 41 42 43 50 51 52 53)
293
	punpckhdq xmm7,xmm0		; xmm7=(60 61 62 63 70 71 72 73)
294
295
	movdqa     xmm6,xmm1		; transpose coefficients(phase 3)
296
	punpcklqdq xmm1,xmm5		; xmm1=(00 01 02 03 04 05 06 07)=data0
297
	punpckhqdq xmm6,xmm5		; xmm6=(10 11 12 13 14 15 16 17)=data1
298
	movdqa     xmm0,xmm7		; transpose coefficients(phase 3)
299
	punpcklqdq xmm7,xmm3		; xmm7=(60 61 62 63 64 65 66 67)=data6
300
	punpckhqdq xmm0,xmm3		; xmm0=(70 71 72 73 74 75 76 77)=data7
301
302
	movdqa	xmm5,xmm6
303
	movdqa	xmm3,xmm1
304
	psubw	xmm6,xmm7		; xmm6=data1-data6=tmp6
305
	psubw	xmm1,xmm0		; xmm1=data0-data7=tmp7
306
	paddw	xmm5,xmm7		; xmm5=data1+data6=tmp1
307
	paddw	xmm3,xmm0		; xmm3=data0+data7=tmp0
308
309
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=(24 25 26 27 34 35 36 37)
310
	movdqa	xmm0, XMMWORD [wk(1)]	; xmm0=(44 45 46 47 54 55 56 57)
311
	movdqa	XMMWORD [wk(0)], xmm6	; wk(0)=tmp6
312
	movdqa	XMMWORD [wk(1)], xmm1	; wk(1)=tmp7
313
314
	movdqa     xmm6,xmm2		; transpose coefficients(phase 3)
315
	punpcklqdq xmm2,xmm7		; xmm2=(20 21 22 23 24 25 26 27)=data2
316
	punpckhqdq xmm6,xmm7		; xmm6=(30 31 32 33 34 35 36 37)=data3
317
	movdqa     xmm1,xmm4		; transpose coefficients(phase 3)
318
	punpcklqdq xmm4,xmm0		; xmm4=(40 41 42 43 44 45 46 47)=data4
319
	punpckhqdq xmm1,xmm0		; xmm1=(50 51 52 53 54 55 56 57)=data5
320
321
	movdqa	xmm7,xmm6
322
	movdqa	xmm0,xmm2
323
	paddw	xmm6,xmm4		; xmm6=data3+data4=tmp3
324
	paddw	xmm2,xmm1		; xmm2=data2+data5=tmp2
325
	psubw	xmm7,xmm4		; xmm7=data3-data4=tmp4
326
	psubw	xmm0,xmm1		; xmm0=data2-data5=tmp5
327
328
	; -- Even part
329
330
	movdqa	xmm4,xmm3
331
	movdqa	xmm1,xmm5
332
	psubw	xmm3,xmm6		; xmm3=tmp13
333
	psubw	xmm5,xmm2		; xmm5=tmp12
334
	paddw	xmm4,xmm6		; xmm4=tmp10
335
	paddw	xmm1,xmm2		; xmm1=tmp11
336
337
	paddw	xmm5,xmm3
338
	psllw	xmm5,PRE_MULTIPLY_SCALE_BITS
339
	pmulhw	xmm5,[GOTOFF(ebx,PW_F0707)] ; xmm5=z1
340
341
	movdqa	xmm6,xmm4
342
	movdqa	xmm2,xmm3
343
	psubw	xmm4,xmm1		; xmm4=data4
344
	psubw	xmm3,xmm5		; xmm3=data6
345
	paddw	xmm6,xmm1		; xmm6=data0
346
	paddw	xmm2,xmm5		; xmm2=data2
347
348
	movdqa	XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)], xmm4
349
	movdqa	XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)], xmm3
350
	movdqa	XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)], xmm6
351
	movdqa	XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)], xmm2
352
353
	; -- Odd part
354
355
	movdqa	xmm1, XMMWORD [wk(0)]	; xmm1=tmp6
356
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=tmp7
357
358
	paddw	xmm7,xmm0		; xmm7=tmp10
359
	paddw	xmm0,xmm1		; xmm0=tmp11
360
	paddw	xmm1,xmm5		; xmm1=tmp12, xmm5=tmp7
361
362
	psllw	xmm7,PRE_MULTIPLY_SCALE_BITS
363
	psllw	xmm1,PRE_MULTIPLY_SCALE_BITS
364
365
	psllw	xmm0,PRE_MULTIPLY_SCALE_BITS
366
	pmulhw	xmm0,[GOTOFF(ebx,PW_F0707)] ; xmm0=z3
367
368
	movdqa	xmm4,xmm7		; xmm4=tmp10
369
	psubw	xmm7,xmm1
370
	pmulhw	xmm7,[GOTOFF(ebx,PW_F0382)] ; xmm7=z5
371
	pmulhw	xmm4,[GOTOFF(ebx,PW_F0541)] ; xmm4=MULTIPLY(tmp10,FIX_0_541196)
372
	pmulhw	xmm1,[GOTOFF(ebx,PW_F1306)] ; xmm1=MULTIPLY(tmp12,FIX_1_306562)
373
	paddw	xmm4,xmm7		; xmm4=z2
374
	paddw	xmm1,xmm7		; xmm1=z4
375
376
	movdqa	xmm3,xmm5
377
	psubw	xmm5,xmm0		; xmm5=z13
378
	paddw	xmm3,xmm0		; xmm3=z11
379
380
	movdqa	xmm6,xmm5
381
	movdqa	xmm2,xmm3
382
	psubw	xmm5,xmm4		; xmm5=data3
383
	psubw	xmm3,xmm1		; xmm3=data7
384
	paddw	xmm6,xmm4		; xmm6=data5
385
	paddw	xmm2,xmm1		; xmm2=data1
386
387
	movdqa	XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)], xmm5
388
	movdqa	XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)], xmm3
389
	movdqa	XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)], xmm6
390
	movdqa	XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)], xmm2
391
392
;	pop	edi		; unused
393
;	pop	esi		; unused
394
;	pop	edx		; need not be preserved
395
;	pop	ecx		; unused
396
	poppic	ebx
397
	mov	esp,ebp		; esp <- aligned ebp
398
	pop	esp		; esp <- original ebp
399
	pop	ebp
400
	ret
401
402
; For some reason, the OS X linker does not honor the request to align the
403
; segment unless we do this.
404
	align	16
(-)a/jpeg/simd/jfss2int-64.asm (+622 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jfss2int-64.asm - accurate integer FDCT (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; This file contains a slow-but-accurate integer implementation of the
19
; forward DCT (Discrete Cosine Transform). The following code is based
20
; directly on the IJG's original jfdctint.c; see the jfdctint.c for
21
; more details.
22
;
23
; [TAB8]
24
25
%include "jsimdext.inc"
26
%include "jdct.inc"
27
28
; --------------------------------------------------------------------------
29
30
%define CONST_BITS	13
31
%define PASS1_BITS	2
32
33
%define DESCALE_P1	(CONST_BITS-PASS1_BITS)
34
%define DESCALE_P2	(CONST_BITS+PASS1_BITS)
35
36
%if CONST_BITS == 13
37
F_0_298	equ	 2446		; FIX(0.298631336)
38
F_0_390	equ	 3196		; FIX(0.390180644)
39
F_0_541	equ	 4433		; FIX(0.541196100)
40
F_0_765	equ	 6270		; FIX(0.765366865)
41
F_0_899	equ	 7373		; FIX(0.899976223)
42
F_1_175	equ	 9633		; FIX(1.175875602)
43
F_1_501	equ	12299		; FIX(1.501321110)
44
F_1_847	equ	15137		; FIX(1.847759065)
45
F_1_961	equ	16069		; FIX(1.961570560)
46
F_2_053	equ	16819		; FIX(2.053119869)
47
F_2_562	equ	20995		; FIX(2.562915447)
48
F_3_072	equ	25172		; FIX(3.072711026)
49
%else
50
; NASM cannot do compile-time arithmetic on floating-point constants.
51
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
52
F_0_298	equ	DESCALE( 320652955,30-CONST_BITS)	; FIX(0.298631336)
53
F_0_390	equ	DESCALE( 418953276,30-CONST_BITS)	; FIX(0.390180644)
54
F_0_541	equ	DESCALE( 581104887,30-CONST_BITS)	; FIX(0.541196100)
55
F_0_765	equ	DESCALE( 821806413,30-CONST_BITS)	; FIX(0.765366865)
56
F_0_899	equ	DESCALE( 966342111,30-CONST_BITS)	; FIX(0.899976223)
57
F_1_175	equ	DESCALE(1262586813,30-CONST_BITS)	; FIX(1.175875602)
58
F_1_501	equ	DESCALE(1612031267,30-CONST_BITS)	; FIX(1.501321110)
59
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
60
F_1_961	equ	DESCALE(2106220350,30-CONST_BITS)	; FIX(1.961570560)
61
F_2_053	equ	DESCALE(2204520673,30-CONST_BITS)	; FIX(2.053119869)
62
F_2_562	equ	DESCALE(2751909506,30-CONST_BITS)	; FIX(2.562915447)
63
F_3_072	equ	DESCALE(3299298341,30-CONST_BITS)	; FIX(3.072711026)
64
%endif
65
66
; --------------------------------------------------------------------------
67
	SECTION	SEG_CONST
68
69
	alignz	16
70
	global	EXTN(jconst_fdct_islow_sse2)
71
72
EXTN(jconst_fdct_islow_sse2):
73
74
PW_F130_F054	times 4 dw  (F_0_541+F_0_765), F_0_541
75
PW_F054_MF130	times 4 dw  F_0_541, (F_0_541-F_1_847)
76
PW_MF078_F117	times 4 dw  (F_1_175-F_1_961), F_1_175
77
PW_F117_F078	times 4 dw  F_1_175, (F_1_175-F_0_390)
78
PW_MF060_MF089	times 4 dw  (F_0_298-F_0_899),-F_0_899
79
PW_MF089_F060	times 4 dw -F_0_899, (F_1_501-F_0_899)
80
PW_MF050_MF256	times 4 dw  (F_2_053-F_2_562),-F_2_562
81
PW_MF256_F050	times 4 dw -F_2_562, (F_3_072-F_2_562)
82
PD_DESCALE_P1	times 4 dd  1 << (DESCALE_P1-1)
83
PD_DESCALE_P2	times 4 dd  1 << (DESCALE_P2-1)
84
PW_DESCALE_P2X	times 8 dw  1 << (PASS1_BITS-1)
85
86
	alignz	16
87
88
; --------------------------------------------------------------------------
89
	SECTION	SEG_TEXT
90
	BITS	64
91
;
92
; Perform the forward DCT on one block of samples.
93
;
94
; GLOBAL(void)
95
; jsimd_fdct_islow_sse2 (DCTELEM * data)
96
;
97
98
; r10 = DCTELEM * data
99
100
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
101
%define WK_NUM		6
102
103
	align	16
104
	global	EXTN(jsimd_fdct_islow_sse2)
105
106
EXTN(jsimd_fdct_islow_sse2):
107
	push	rbp
108
	mov	rax,rsp				; rax = original rbp
109
	sub	rsp, byte 4
110
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
111
	mov	[rsp],rax
112
	mov	rbp,rsp				; rbp = aligned rbp
113
	lea	rsp, [wk(0)]
114
	collect_args
115
116
	; ---- Pass 1: process rows.
117
118
	mov	rdx, r10	; (DCTELEM *)
119
120
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)]
121
	movdqa	xmm1, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)]
122
	movdqa	xmm2, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)]
123
	movdqa	xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)]
124
125
	; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27)
126
	; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37)
127
128
	movdqa    xmm4,xmm0		; transpose coefficients(phase 1)
129
	punpcklwd xmm0,xmm1		; xmm0=(00 10 01 11 02 12 03 13)
130
	punpckhwd xmm4,xmm1		; xmm4=(04 14 05 15 06 16 07 17)
131
	movdqa    xmm5,xmm2		; transpose coefficients(phase 1)
132
	punpcklwd xmm2,xmm3		; xmm2=(20 30 21 31 22 32 23 33)
133
	punpckhwd xmm5,xmm3		; xmm5=(24 34 25 35 26 36 27 37)
134
135
	movdqa	xmm6, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)]
136
	movdqa	xmm7, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)]
137
	movdqa	xmm1, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)]
138
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)]
139
140
	; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62)
141
	; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63)
142
143
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=(20 30 21 31 22 32 23 33)
144
	movdqa	XMMWORD [wk(1)], xmm5	; wk(1)=(24 34 25 35 26 36 27 37)
145
146
	movdqa    xmm2,xmm6		; transpose coefficients(phase 1)
147
	punpcklwd xmm6,xmm7		; xmm6=(40 50 41 51 42 52 43 53)
148
	punpckhwd xmm2,xmm7		; xmm2=(44 54 45 55 46 56 47 57)
149
	movdqa    xmm5,xmm1		; transpose coefficients(phase 1)
150
	punpcklwd xmm1,xmm3		; xmm1=(60 70 61 71 62 72 63 73)
151
	punpckhwd xmm5,xmm3		; xmm5=(64 74 65 75 66 76 67 77)
152
153
	movdqa    xmm7,xmm6		; transpose coefficients(phase 2)
154
	punpckldq xmm6,xmm1		; xmm6=(40 50 60 70 41 51 61 71)
155
	punpckhdq xmm7,xmm1		; xmm7=(42 52 62 72 43 53 63 73)
156
	movdqa    xmm3,xmm2		; transpose coefficients(phase 2)
157
	punpckldq xmm2,xmm5		; xmm2=(44 54 64 74 45 55 65 75)
158
	punpckhdq xmm3,xmm5		; xmm3=(46 56 66 76 47 57 67 77)
159
160
	movdqa	xmm1, XMMWORD [wk(0)]	; xmm1=(20 30 21 31 22 32 23 33)
161
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=(24 34 25 35 26 36 27 37)
162
	movdqa	XMMWORD [wk(2)], xmm7	; wk(2)=(42 52 62 72 43 53 63 73)
163
	movdqa	XMMWORD [wk(3)], xmm2	; wk(3)=(44 54 64 74 45 55 65 75)
164
165
	movdqa    xmm7,xmm0		; transpose coefficients(phase 2)
166
	punpckldq xmm0,xmm1		; xmm0=(00 10 20 30 01 11 21 31)
167
	punpckhdq xmm7,xmm1		; xmm7=(02 12 22 32 03 13 23 33)
168
	movdqa    xmm2,xmm4		; transpose coefficients(phase 2)
169
	punpckldq xmm4,xmm5		; xmm4=(04 14 24 34 05 15 25 35)
170
	punpckhdq xmm2,xmm5		; xmm2=(06 16 26 36 07 17 27 37)
171
172
	movdqa     xmm1,xmm0		; transpose coefficients(phase 3)
173
	punpcklqdq xmm0,xmm6		; xmm0=(00 10 20 30 40 50 60 70)=data0
174
	punpckhqdq xmm1,xmm6		; xmm1=(01 11 21 31 41 51 61 71)=data1
175
	movdqa     xmm5,xmm2		; transpose coefficients(phase 3)
176
	punpcklqdq xmm2,xmm3		; xmm2=(06 16 26 36 46 56 66 76)=data6
177
	punpckhqdq xmm5,xmm3		; xmm5=(07 17 27 37 47 57 67 77)=data7
178
179
	movdqa	xmm6,xmm1
180
	movdqa	xmm3,xmm0
181
	psubw	xmm1,xmm2		; xmm1=data1-data6=tmp6
182
	psubw	xmm0,xmm5		; xmm0=data0-data7=tmp7
183
	paddw	xmm6,xmm2		; xmm6=data1+data6=tmp1
184
	paddw	xmm3,xmm5		; xmm3=data0+data7=tmp0
185
186
	movdqa	xmm2, XMMWORD [wk(2)]	; xmm2=(42 52 62 72 43 53 63 73)
187
	movdqa	xmm5, XMMWORD [wk(3)]	; xmm5=(44 54 64 74 45 55 65 75)
188
	movdqa	XMMWORD [wk(0)], xmm1	; wk(0)=tmp6
189
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=tmp7
190
191
	movdqa     xmm1,xmm7		; transpose coefficients(phase 3)
192
	punpcklqdq xmm7,xmm2		; xmm7=(02 12 22 32 42 52 62 72)=data2
193
	punpckhqdq xmm1,xmm2		; xmm1=(03 13 23 33 43 53 63 73)=data3
194
	movdqa     xmm0,xmm4		; transpose coefficients(phase 3)
195
	punpcklqdq xmm4,xmm5		; xmm4=(04 14 24 34 44 54 64 74)=data4
196
	punpckhqdq xmm0,xmm5		; xmm0=(05 15 25 35 45 55 65 75)=data5
197
198
	movdqa	xmm2,xmm1
199
	movdqa	xmm5,xmm7
200
	paddw	xmm1,xmm4		; xmm1=data3+data4=tmp3
201
	paddw	xmm7,xmm0		; xmm7=data2+data5=tmp2
202
	psubw	xmm2,xmm4		; xmm2=data3-data4=tmp4
203
	psubw	xmm5,xmm0		; xmm5=data2-data5=tmp5
204
205
	; -- Even part
206
207
	movdqa	xmm4,xmm3
208
	movdqa	xmm0,xmm6
209
	paddw	xmm3,xmm1		; xmm3=tmp10
210
	paddw	xmm6,xmm7		; xmm6=tmp11
211
	psubw	xmm4,xmm1		; xmm4=tmp13
212
	psubw	xmm0,xmm7		; xmm0=tmp12
213
214
	movdqa	xmm1,xmm3
215
	paddw	xmm3,xmm6		; xmm3=tmp10+tmp11
216
	psubw	xmm1,xmm6		; xmm1=tmp10-tmp11
217
218
	psllw	xmm3,PASS1_BITS		; xmm3=data0
219
	psllw	xmm1,PASS1_BITS		; xmm1=data4
220
221
	movdqa	XMMWORD [wk(2)], xmm3	; wk(2)=data0
222
	movdqa	XMMWORD [wk(3)], xmm1	; wk(3)=data4
223
224
	; (Original)
225
	; z1 = (tmp12 + tmp13) * 0.541196100;
226
	; data2 = z1 + tmp13 * 0.765366865;
227
	; data6 = z1 + tmp12 * -1.847759065;
228
	;
229
	; (This implementation)
230
	; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
231
	; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
232
233
	movdqa    xmm7,xmm4		; xmm4=tmp13
234
	movdqa    xmm6,xmm4
235
	punpcklwd xmm7,xmm0		; xmm0=tmp12
236
	punpckhwd xmm6,xmm0
237
	movdqa    xmm4,xmm7
238
	movdqa    xmm0,xmm6
239
	pmaddwd   xmm7,[rel PW_F130_F054]	; xmm7=data2L
240
	pmaddwd   xmm6,[rel PW_F130_F054]	; xmm6=data2H
241
	pmaddwd   xmm4,[rel PW_F054_MF130]	; xmm4=data6L
242
	pmaddwd   xmm0,[rel PW_F054_MF130]	; xmm0=data6H
243
244
	paddd	xmm7,[rel PD_DESCALE_P1]
245
	paddd	xmm6,[rel PD_DESCALE_P1]
246
	psrad	xmm7,DESCALE_P1
247
	psrad	xmm6,DESCALE_P1
248
	paddd	xmm4,[rel PD_DESCALE_P1]
249
	paddd	xmm0,[rel PD_DESCALE_P1]
250
	psrad	xmm4,DESCALE_P1
251
	psrad	xmm0,DESCALE_P1
252
253
	packssdw  xmm7,xmm6		; xmm7=data2
254
	packssdw  xmm4,xmm0		; xmm4=data6
255
256
	movdqa	XMMWORD [wk(4)], xmm7	; wk(4)=data2
257
	movdqa	XMMWORD [wk(5)], xmm4	; wk(5)=data6
258
259
	; -- Odd part
260
261
	movdqa	xmm3, XMMWORD [wk(0)]	; xmm3=tmp6
262
	movdqa	xmm1, XMMWORD [wk(1)]	; xmm1=tmp7
263
264
	movdqa	xmm6,xmm2		; xmm2=tmp4
265
	movdqa	xmm0,xmm5		; xmm5=tmp5
266
	paddw	xmm6,xmm3		; xmm6=z3
267
	paddw	xmm0,xmm1		; xmm0=z4
268
269
	; (Original)
270
	; z5 = (z3 + z4) * 1.175875602;
271
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
272
	; z3 += z5;  z4 += z5;
273
	;
274
	; (This implementation)
275
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
276
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
277
278
	movdqa    xmm7,xmm6
279
	movdqa    xmm4,xmm6
280
	punpcklwd xmm7,xmm0
281
	punpckhwd xmm4,xmm0
282
	movdqa    xmm6,xmm7
283
	movdqa    xmm0,xmm4
284
	pmaddwd   xmm7,[rel PW_MF078_F117]	; xmm7=z3L
285
	pmaddwd   xmm4,[rel PW_MF078_F117]	; xmm4=z3H
286
	pmaddwd   xmm6,[rel PW_F117_F078]	; xmm6=z4L
287
	pmaddwd   xmm0,[rel PW_F117_F078]	; xmm0=z4H
288
289
	movdqa	XMMWORD [wk(0)], xmm7	; wk(0)=z3L
290
	movdqa	XMMWORD [wk(1)], xmm4	; wk(1)=z3H
291
292
	; (Original)
293
	; z1 = tmp4 + tmp7;  z2 = tmp5 + tmp6;
294
	; tmp4 = tmp4 * 0.298631336;  tmp5 = tmp5 * 2.053119869;
295
	; tmp6 = tmp6 * 3.072711026;  tmp7 = tmp7 * 1.501321110;
296
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
297
	; data7 = tmp4 + z1 + z3;  data5 = tmp5 + z2 + z4;
298
	; data3 = tmp6 + z2 + z3;  data1 = tmp7 + z1 + z4;
299
	;
300
	; (This implementation)
301
	; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
302
	; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
303
	; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
304
	; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
305
	; data7 = tmp4 + z3;  data5 = tmp5 + z4;
306
	; data3 = tmp6 + z3;  data1 = tmp7 + z4;
307
308
	movdqa    xmm7,xmm2
309
	movdqa    xmm4,xmm2
310
	punpcklwd xmm7,xmm1
311
	punpckhwd xmm4,xmm1
312
	movdqa    xmm2,xmm7
313
	movdqa    xmm1,xmm4
314
	pmaddwd   xmm7,[rel PW_MF060_MF089]	; xmm7=tmp4L
315
	pmaddwd   xmm4,[rel PW_MF060_MF089]	; xmm4=tmp4H
316
	pmaddwd   xmm2,[rel PW_MF089_F060]	; xmm2=tmp7L
317
	pmaddwd   xmm1,[rel PW_MF089_F060]	; xmm1=tmp7H
318
319
	paddd	xmm7, XMMWORD [wk(0)]	; xmm7=data7L
320
	paddd	xmm4, XMMWORD [wk(1)]	; xmm4=data7H
321
	paddd	xmm2,xmm6		; xmm2=data1L
322
	paddd	xmm1,xmm0		; xmm1=data1H
323
324
	paddd	xmm7,[rel PD_DESCALE_P1]
325
	paddd	xmm4,[rel PD_DESCALE_P1]
326
	psrad	xmm7,DESCALE_P1
327
	psrad	xmm4,DESCALE_P1
328
	paddd	xmm2,[rel PD_DESCALE_P1]
329
	paddd	xmm1,[rel PD_DESCALE_P1]
330
	psrad	xmm2,DESCALE_P1
331
	psrad	xmm1,DESCALE_P1
332
333
	packssdw  xmm7,xmm4		; xmm7=data7
334
	packssdw  xmm2,xmm1		; xmm2=data1
335
336
	movdqa    xmm4,xmm5
337
	movdqa    xmm1,xmm5
338
	punpcklwd xmm4,xmm3
339
	punpckhwd xmm1,xmm3
340
	movdqa    xmm5,xmm4
341
	movdqa    xmm3,xmm1
342
	pmaddwd   xmm4,[rel PW_MF050_MF256]	; xmm4=tmp5L
343
	pmaddwd   xmm1,[rel PW_MF050_MF256]	; xmm1=tmp5H
344
	pmaddwd   xmm5,[rel PW_MF256_F050]	; xmm5=tmp6L
345
	pmaddwd   xmm3,[rel PW_MF256_F050]	; xmm3=tmp6H
346
347
	paddd	xmm4,xmm6		; xmm4=data5L
348
	paddd	xmm1,xmm0		; xmm1=data5H
349
	paddd	xmm5, XMMWORD [wk(0)]	; xmm5=data3L
350
	paddd	xmm3, XMMWORD [wk(1)]	; xmm3=data3H
351
352
	paddd	xmm4,[rel PD_DESCALE_P1]
353
	paddd	xmm1,[rel PD_DESCALE_P1]
354
	psrad	xmm4,DESCALE_P1
355
	psrad	xmm1,DESCALE_P1
356
	paddd	xmm5,[rel PD_DESCALE_P1]
357
	paddd	xmm3,[rel PD_DESCALE_P1]
358
	psrad	xmm5,DESCALE_P1
359
	psrad	xmm3,DESCALE_P1
360
361
	packssdw  xmm4,xmm1		; xmm4=data5
362
	packssdw  xmm5,xmm3		; xmm5=data3
363
364
	; ---- Pass 2: process columns.
365
366
	movdqa	xmm6, XMMWORD [wk(2)]	; xmm6=col0
367
	movdqa	xmm0, XMMWORD [wk(4)]	; xmm0=col2
368
369
	; xmm6=(00 10 20 30 40 50 60 70), xmm0=(02 12 22 32 42 52 62 72)
370
	; xmm2=(01 11 21 31 41 51 61 71), xmm5=(03 13 23 33 43 53 63 73)
371
372
	movdqa    xmm1,xmm6		; transpose coefficients(phase 1)
373
	punpcklwd xmm6,xmm2		; xmm6=(00 01 10 11 20 21 30 31)
374
	punpckhwd xmm1,xmm2		; xmm1=(40 41 50 51 60 61 70 71)
375
	movdqa    xmm3,xmm0		; transpose coefficients(phase 1)
376
	punpcklwd xmm0,xmm5		; xmm0=(02 03 12 13 22 23 32 33)
377
	punpckhwd xmm3,xmm5		; xmm3=(42 43 52 53 62 63 72 73)
378
379
	movdqa	xmm2, XMMWORD [wk(3)]	; xmm2=col4
380
	movdqa	xmm5, XMMWORD [wk(5)]	; xmm5=col6
381
382
	; xmm2=(04 14 24 34 44 54 64 74), xmm5=(06 16 26 36 46 56 66 76)
383
	; xmm4=(05 15 25 35 45 55 65 75), xmm7=(07 17 27 37 47 57 67 77)
384
385
	movdqa	XMMWORD [wk(0)], xmm0	; wk(0)=(02 03 12 13 22 23 32 33)
386
	movdqa	XMMWORD [wk(1)], xmm3	; wk(1)=(42 43 52 53 62 63 72 73)
387
388
	movdqa    xmm0,xmm2		; transpose coefficients(phase 1)
389
	punpcklwd xmm2,xmm4		; xmm2=(04 05 14 15 24 25 34 35)
390
	punpckhwd xmm0,xmm4		; xmm0=(44 45 54 55 64 65 74 75)
391
	movdqa    xmm3,xmm5		; transpose coefficients(phase 1)
392
	punpcklwd xmm5,xmm7		; xmm5=(06 07 16 17 26 27 36 37)
393
	punpckhwd xmm3,xmm7		; xmm3=(46 47 56 57 66 67 76 77)
394
395
	movdqa    xmm4,xmm2		; transpose coefficients(phase 2)
396
	punpckldq xmm2,xmm5		; xmm2=(04 05 06 07 14 15 16 17)
397
	punpckhdq xmm4,xmm5		; xmm4=(24 25 26 27 34 35 36 37)
398
	movdqa    xmm7,xmm0		; transpose coefficients(phase 2)
399
	punpckldq xmm0,xmm3		; xmm0=(44 45 46 47 54 55 56 57)
400
	punpckhdq xmm7,xmm3		; xmm7=(64 65 66 67 74 75 76 77)
401
402
	movdqa	xmm5, XMMWORD [wk(0)]	; xmm5=(02 03 12 13 22 23 32 33)
403
	movdqa	xmm3, XMMWORD [wk(1)]	; xmm3=(42 43 52 53 62 63 72 73)
404
	movdqa	XMMWORD [wk(2)], xmm4	; wk(2)=(24 25 26 27 34 35 36 37)
405
	movdqa	XMMWORD [wk(3)], xmm0	; wk(3)=(44 45 46 47 54 55 56 57)
406
407
	movdqa    xmm4,xmm6		; transpose coefficients(phase 2)
408
	punpckldq xmm6,xmm5		; xmm6=(00 01 02 03 10 11 12 13)
409
	punpckhdq xmm4,xmm5		; xmm4=(20 21 22 23 30 31 32 33)
410
	movdqa    xmm0,xmm1		; transpose coefficients(phase 2)
411
	punpckldq xmm1,xmm3		; xmm1=(40 41 42 43 50 51 52 53)
412
	punpckhdq xmm0,xmm3		; xmm0=(60 61 62 63 70 71 72 73)
413
414
	movdqa     xmm5,xmm6		; transpose coefficients(phase 3)
415
	punpcklqdq xmm6,xmm2		; xmm6=(00 01 02 03 04 05 06 07)=data0
416
	punpckhqdq xmm5,xmm2		; xmm5=(10 11 12 13 14 15 16 17)=data1
417
	movdqa     xmm3,xmm0		; transpose coefficients(phase 3)
418
	punpcklqdq xmm0,xmm7		; xmm0=(60 61 62 63 64 65 66 67)=data6
419
	punpckhqdq xmm3,xmm7		; xmm3=(70 71 72 73 74 75 76 77)=data7
420
421
	movdqa	xmm2,xmm5
422
	movdqa	xmm7,xmm6
423
	psubw	xmm5,xmm0		; xmm5=data1-data6=tmp6
424
	psubw	xmm6,xmm3		; xmm6=data0-data7=tmp7
425
	paddw	xmm2,xmm0		; xmm2=data1+data6=tmp1
426
	paddw	xmm7,xmm3		; xmm7=data0+data7=tmp0
427
428
	movdqa	xmm0, XMMWORD [wk(2)]	; xmm0=(24 25 26 27 34 35 36 37)
429
	movdqa	xmm3, XMMWORD [wk(3)]	; xmm3=(44 45 46 47 54 55 56 57)
430
	movdqa	XMMWORD [wk(0)], xmm5	; wk(0)=tmp6
431
	movdqa	XMMWORD [wk(1)], xmm6	; wk(1)=tmp7
432
433
	movdqa     xmm5,xmm4		; transpose coefficients(phase 3)
434
	punpcklqdq xmm4,xmm0		; xmm4=(20 21 22 23 24 25 26 27)=data2
435
	punpckhqdq xmm5,xmm0		; xmm5=(30 31 32 33 34 35 36 37)=data3
436
	movdqa     xmm6,xmm1		; transpose coefficients(phase 3)
437
	punpcklqdq xmm1,xmm3		; xmm1=(40 41 42 43 44 45 46 47)=data4
438
	punpckhqdq xmm6,xmm3		; xmm6=(50 51 52 53 54 55 56 57)=data5
439
440
	movdqa	xmm0,xmm5
441
	movdqa	xmm3,xmm4
442
	paddw	xmm5,xmm1		; xmm5=data3+data4=tmp3
443
	paddw	xmm4,xmm6		; xmm4=data2+data5=tmp2
444
	psubw	xmm0,xmm1		; xmm0=data3-data4=tmp4
445
	psubw	xmm3,xmm6		; xmm3=data2-data5=tmp5
446
447
	; -- Even part
448
449
	movdqa	xmm1,xmm7
450
	movdqa	xmm6,xmm2
451
	paddw	xmm7,xmm5		; xmm7=tmp10
452
	paddw	xmm2,xmm4		; xmm2=tmp11
453
	psubw	xmm1,xmm5		; xmm1=tmp13
454
	psubw	xmm6,xmm4		; xmm6=tmp12
455
456
	movdqa	xmm5,xmm7
457
	paddw	xmm7,xmm2		; xmm7=tmp10+tmp11
458
	psubw	xmm5,xmm2		; xmm5=tmp10-tmp11
459
460
	paddw	xmm7,[rel PW_DESCALE_P2X]
461
	paddw	xmm5,[rel PW_DESCALE_P2X]
462
	psraw	xmm7,PASS1_BITS		; xmm7=data0
463
	psraw	xmm5,PASS1_BITS		; xmm5=data4
464
465
	movdqa	XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_DCTELEM)], xmm7
466
	movdqa	XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_DCTELEM)], xmm5
467
468
	; (Original)
469
	; z1 = (tmp12 + tmp13) * 0.541196100;
470
	; data2 = z1 + tmp13 * 0.765366865;
471
	; data6 = z1 + tmp12 * -1.847759065;
472
	;
473
	; (This implementation)
474
	; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
475
	; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
476
477
	movdqa    xmm4,xmm1		; xmm1=tmp13
478
	movdqa    xmm2,xmm1
479
	punpcklwd xmm4,xmm6		; xmm6=tmp12
480
	punpckhwd xmm2,xmm6
481
	movdqa    xmm1,xmm4
482
	movdqa    xmm6,xmm2
483
	pmaddwd   xmm4,[rel PW_F130_F054]	; xmm4=data2L
484
	pmaddwd   xmm2,[rel PW_F130_F054]	; xmm2=data2H
485
	pmaddwd   xmm1,[rel PW_F054_MF130]	; xmm1=data6L
486
	pmaddwd   xmm6,[rel PW_F054_MF130]	; xmm6=data6H
487
488
	paddd	xmm4,[rel PD_DESCALE_P2]
489
	paddd	xmm2,[rel PD_DESCALE_P2]
490
	psrad	xmm4,DESCALE_P2
491
	psrad	xmm2,DESCALE_P2
492
	paddd	xmm1,[rel PD_DESCALE_P2]
493
	paddd	xmm6,[rel PD_DESCALE_P2]
494
	psrad	xmm1,DESCALE_P2
495
	psrad	xmm6,DESCALE_P2
496
497
	packssdw  xmm4,xmm2		; xmm4=data2
498
	packssdw  xmm1,xmm6		; xmm1=data6
499
500
	movdqa	XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_DCTELEM)], xmm4
501
	movdqa	XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_DCTELEM)], xmm1
502
503
	; -- Odd part
504
505
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=tmp6
506
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=tmp7
507
508
	movdqa	xmm2,xmm0		; xmm0=tmp4
509
	movdqa	xmm6,xmm3		; xmm3=tmp5
510
	paddw	xmm2,xmm7		; xmm2=z3
511
	paddw	xmm6,xmm5		; xmm6=z4
512
513
	; (Original)
514
	; z5 = (z3 + z4) * 1.175875602;
515
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
516
	; z3 += z5;  z4 += z5;
517
	;
518
	; (This implementation)
519
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
520
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
521
522
	movdqa    xmm4,xmm2
523
	movdqa    xmm1,xmm2
524
	punpcklwd xmm4,xmm6
525
	punpckhwd xmm1,xmm6
526
	movdqa    xmm2,xmm4
527
	movdqa    xmm6,xmm1
528
	pmaddwd   xmm4,[rel PW_MF078_F117]	; xmm4=z3L
529
	pmaddwd   xmm1,[rel PW_MF078_F117]	; xmm1=z3H
530
	pmaddwd   xmm2,[rel PW_F117_F078]	; xmm2=z4L
531
	pmaddwd   xmm6,[rel PW_F117_F078]	; xmm6=z4H
532
533
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=z3L
534
	movdqa	XMMWORD [wk(1)], xmm1	; wk(1)=z3H
535
536
	; (Original)
537
	; z1 = tmp4 + tmp7;  z2 = tmp5 + tmp6;
538
	; tmp4 = tmp4 * 0.298631336;  tmp5 = tmp5 * 2.053119869;
539
	; tmp6 = tmp6 * 3.072711026;  tmp7 = tmp7 * 1.501321110;
540
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
541
	; data7 = tmp4 + z1 + z3;  data5 = tmp5 + z2 + z4;
542
	; data3 = tmp6 + z2 + z3;  data1 = tmp7 + z1 + z4;
543
	;
544
	; (This implementation)
545
	; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
546
	; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
547
	; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
548
	; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
549
	; data7 = tmp4 + z3;  data5 = tmp5 + z4;
550
	; data3 = tmp6 + z3;  data1 = tmp7 + z4;
551
552
	movdqa    xmm4,xmm0
553
	movdqa    xmm1,xmm0
554
	punpcklwd xmm4,xmm5
555
	punpckhwd xmm1,xmm5
556
	movdqa    xmm0,xmm4
557
	movdqa    xmm5,xmm1
558
	pmaddwd   xmm4,[rel PW_MF060_MF089]	; xmm4=tmp4L
559
	pmaddwd   xmm1,[rel PW_MF060_MF089]	; xmm1=tmp4H
560
	pmaddwd   xmm0,[rel PW_MF089_F060]	; xmm0=tmp7L
561
	pmaddwd   xmm5,[rel PW_MF089_F060]	; xmm5=tmp7H
562
563
	paddd	xmm4, XMMWORD [wk(0)]	; xmm4=data7L
564
	paddd	xmm1, XMMWORD [wk(1)]	; xmm1=data7H
565
	paddd	xmm0,xmm2		; xmm0=data1L
566
	paddd	xmm5,xmm6		; xmm5=data1H
567
568
	paddd	xmm4,[rel PD_DESCALE_P2]
569
	paddd	xmm1,[rel PD_DESCALE_P2]
570
	psrad	xmm4,DESCALE_P2
571
	psrad	xmm1,DESCALE_P2
572
	paddd	xmm0,[rel PD_DESCALE_P2]
573
	paddd	xmm5,[rel PD_DESCALE_P2]
574
	psrad	xmm0,DESCALE_P2
575
	psrad	xmm5,DESCALE_P2
576
577
	packssdw  xmm4,xmm1		; xmm4=data7
578
	packssdw  xmm0,xmm5		; xmm0=data1
579
580
	movdqa	XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_DCTELEM)], xmm4
581
	movdqa	XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_DCTELEM)], xmm0
582
583
	movdqa    xmm1,xmm3
584
	movdqa    xmm5,xmm3
585
	punpcklwd xmm1,xmm7
586
	punpckhwd xmm5,xmm7
587
	movdqa    xmm3,xmm1
588
	movdqa    xmm7,xmm5
589
	pmaddwd   xmm1,[rel PW_MF050_MF256]	; xmm1=tmp5L
590
	pmaddwd   xmm5,[rel PW_MF050_MF256]	; xmm5=tmp5H
591
	pmaddwd   xmm3,[rel PW_MF256_F050]	; xmm3=tmp6L
592
	pmaddwd   xmm7,[rel PW_MF256_F050]	; xmm7=tmp6H
593
594
	paddd	xmm1,xmm2		; xmm1=data5L
595
	paddd	xmm5,xmm6		; xmm5=data5H
596
	paddd	xmm3, XMMWORD [wk(0)]	; xmm3=data3L
597
	paddd	xmm7, XMMWORD [wk(1)]	; xmm7=data3H
598
599
	paddd	xmm1,[rel PD_DESCALE_P2]
600
	paddd	xmm5,[rel PD_DESCALE_P2]
601
	psrad	xmm1,DESCALE_P2
602
	psrad	xmm5,DESCALE_P2
603
	paddd	xmm3,[rel PD_DESCALE_P2]
604
	paddd	xmm7,[rel PD_DESCALE_P2]
605
	psrad	xmm3,DESCALE_P2
606
	psrad	xmm7,DESCALE_P2
607
608
	packssdw  xmm1,xmm5		; xmm1=data5
609
	packssdw  xmm3,xmm7		; xmm3=data3
610
611
	movdqa	XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_DCTELEM)], xmm1
612
	movdqa	XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_DCTELEM)], xmm3
613
614
	uncollect_args
615
	mov	rsp,rbp		; rsp <- aligned rbp
616
	pop	rsp		; rsp <- original rbp
617
	pop	rbp
618
	ret
619
620
; For some reason, the OS X linker does not honor the request to align the
621
; segment unless we do this.
622
	align	16
(-)a/jpeg/simd/jfss2int.asm (+634 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jfss2int.asm - accurate integer FDCT (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a slow-but-accurate integer implementation of the
18
; forward DCT (Discrete Cosine Transform). The following code is based
19
; directly on the IJG's original jfdctint.c; see the jfdctint.c for
20
; more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	13
30
%define PASS1_BITS	2
31
32
%define DESCALE_P1	(CONST_BITS-PASS1_BITS)
33
%define DESCALE_P2	(CONST_BITS+PASS1_BITS)
34
35
%if CONST_BITS == 13
36
F_0_298	equ	 2446		; FIX(0.298631336)
37
F_0_390	equ	 3196		; FIX(0.390180644)
38
F_0_541	equ	 4433		; FIX(0.541196100)
39
F_0_765	equ	 6270		; FIX(0.765366865)
40
F_0_899	equ	 7373		; FIX(0.899976223)
41
F_1_175	equ	 9633		; FIX(1.175875602)
42
F_1_501	equ	12299		; FIX(1.501321110)
43
F_1_847	equ	15137		; FIX(1.847759065)
44
F_1_961	equ	16069		; FIX(1.961570560)
45
F_2_053	equ	16819		; FIX(2.053119869)
46
F_2_562	equ	20995		; FIX(2.562915447)
47
F_3_072	equ	25172		; FIX(3.072711026)
48
%else
49
; NASM cannot do compile-time arithmetic on floating-point constants.
50
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
51
F_0_298	equ	DESCALE( 320652955,30-CONST_BITS)	; FIX(0.298631336)
52
F_0_390	equ	DESCALE( 418953276,30-CONST_BITS)	; FIX(0.390180644)
53
F_0_541	equ	DESCALE( 581104887,30-CONST_BITS)	; FIX(0.541196100)
54
F_0_765	equ	DESCALE( 821806413,30-CONST_BITS)	; FIX(0.765366865)
55
F_0_899	equ	DESCALE( 966342111,30-CONST_BITS)	; FIX(0.899976223)
56
F_1_175	equ	DESCALE(1262586813,30-CONST_BITS)	; FIX(1.175875602)
57
F_1_501	equ	DESCALE(1612031267,30-CONST_BITS)	; FIX(1.501321110)
58
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
59
F_1_961	equ	DESCALE(2106220350,30-CONST_BITS)	; FIX(1.961570560)
60
F_2_053	equ	DESCALE(2204520673,30-CONST_BITS)	; FIX(2.053119869)
61
F_2_562	equ	DESCALE(2751909506,30-CONST_BITS)	; FIX(2.562915447)
62
F_3_072	equ	DESCALE(3299298341,30-CONST_BITS)	; FIX(3.072711026)
63
%endif
64
65
; --------------------------------------------------------------------------
66
	SECTION	SEG_CONST
67
68
	alignz	16
69
	global	EXTN(jconst_fdct_islow_sse2)
70
71
EXTN(jconst_fdct_islow_sse2):
72
73
PW_F130_F054	times 4 dw  (F_0_541+F_0_765), F_0_541
74
PW_F054_MF130	times 4 dw  F_0_541, (F_0_541-F_1_847)
75
PW_MF078_F117	times 4 dw  (F_1_175-F_1_961), F_1_175
76
PW_F117_F078	times 4 dw  F_1_175, (F_1_175-F_0_390)
77
PW_MF060_MF089	times 4 dw  (F_0_298-F_0_899),-F_0_899
78
PW_MF089_F060	times 4 dw -F_0_899, (F_1_501-F_0_899)
79
PW_MF050_MF256	times 4 dw  (F_2_053-F_2_562),-F_2_562
80
PW_MF256_F050	times 4 dw -F_2_562, (F_3_072-F_2_562)
81
PD_DESCALE_P1	times 4 dd  1 << (DESCALE_P1-1)
82
PD_DESCALE_P2	times 4 dd  1 << (DESCALE_P2-1)
83
PW_DESCALE_P2X	times 8 dw  1 << (PASS1_BITS-1)
84
85
	alignz	16
86
87
; --------------------------------------------------------------------------
88
	SECTION	SEG_TEXT
89
	BITS	32
90
;
91
; Perform the forward DCT on one block of samples.
92
;
93
; GLOBAL(void)
94
; jsimd_fdct_islow_sse2 (DCTELEM * data)
95
;
96
97
%define data(b)		(b)+8		; DCTELEM * data
98
99
%define original_ebp	ebp+0
100
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
101
%define WK_NUM		6
102
103
	align	16
104
	global	EXTN(jsimd_fdct_islow_sse2)
105
106
EXTN(jsimd_fdct_islow_sse2):
107
	push	ebp
108
	mov	eax,esp				; eax = original ebp
109
	sub	esp, byte 4
110
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
111
	mov	[esp],eax
112
	mov	ebp,esp				; ebp = aligned ebp
113
	lea	esp, [wk(0)]
114
	pushpic	ebx
115
;	push	ecx		; unused
116
;	push	edx		; need not be preserved
117
;	push	esi		; unused
118
;	push	edi		; unused
119
120
	get_GOT	ebx		; get GOT address
121
122
	; ---- Pass 1: process rows.
123
124
	mov	edx, POINTER [data(eax)]	; (DCTELEM *)
125
126
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
127
	movdqa	xmm1, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
128
	movdqa	xmm2, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
129
	movdqa	xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
130
131
	; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27)
132
	; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37)
133
134
	movdqa    xmm4,xmm0		; transpose coefficients(phase 1)
135
	punpcklwd xmm0,xmm1		; xmm0=(00 10 01 11 02 12 03 13)
136
	punpckhwd xmm4,xmm1		; xmm4=(04 14 05 15 06 16 07 17)
137
	movdqa    xmm5,xmm2		; transpose coefficients(phase 1)
138
	punpcklwd xmm2,xmm3		; xmm2=(20 30 21 31 22 32 23 33)
139
	punpckhwd xmm5,xmm3		; xmm5=(24 34 25 35 26 36 27 37)
140
141
	movdqa	xmm6, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)]
142
	movdqa	xmm7, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)]
143
	movdqa	xmm1, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)]
144
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)]
145
146
	; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62)
147
	; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63)
148
149
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=(20 30 21 31 22 32 23 33)
150
	movdqa	XMMWORD [wk(1)], xmm5	; wk(1)=(24 34 25 35 26 36 27 37)
151
152
	movdqa    xmm2,xmm6		; transpose coefficients(phase 1)
153
	punpcklwd xmm6,xmm7		; xmm6=(40 50 41 51 42 52 43 53)
154
	punpckhwd xmm2,xmm7		; xmm2=(44 54 45 55 46 56 47 57)
155
	movdqa    xmm5,xmm1		; transpose coefficients(phase 1)
156
	punpcklwd xmm1,xmm3		; xmm1=(60 70 61 71 62 72 63 73)
157
	punpckhwd xmm5,xmm3		; xmm5=(64 74 65 75 66 76 67 77)
158
159
	movdqa    xmm7,xmm6		; transpose coefficients(phase 2)
160
	punpckldq xmm6,xmm1		; xmm6=(40 50 60 70 41 51 61 71)
161
	punpckhdq xmm7,xmm1		; xmm7=(42 52 62 72 43 53 63 73)
162
	movdqa    xmm3,xmm2		; transpose coefficients(phase 2)
163
	punpckldq xmm2,xmm5		; xmm2=(44 54 64 74 45 55 65 75)
164
	punpckhdq xmm3,xmm5		; xmm3=(46 56 66 76 47 57 67 77)
165
166
	movdqa	xmm1, XMMWORD [wk(0)]	; xmm1=(20 30 21 31 22 32 23 33)
167
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=(24 34 25 35 26 36 27 37)
168
	movdqa	XMMWORD [wk(2)], xmm7	; wk(2)=(42 52 62 72 43 53 63 73)
169
	movdqa	XMMWORD [wk(3)], xmm2	; wk(3)=(44 54 64 74 45 55 65 75)
170
171
	movdqa    xmm7,xmm0		; transpose coefficients(phase 2)
172
	punpckldq xmm0,xmm1		; xmm0=(00 10 20 30 01 11 21 31)
173
	punpckhdq xmm7,xmm1		; xmm7=(02 12 22 32 03 13 23 33)
174
	movdqa    xmm2,xmm4		; transpose coefficients(phase 2)
175
	punpckldq xmm4,xmm5		; xmm4=(04 14 24 34 05 15 25 35)
176
	punpckhdq xmm2,xmm5		; xmm2=(06 16 26 36 07 17 27 37)
177
178
	movdqa     xmm1,xmm0		; transpose coefficients(phase 3)
179
	punpcklqdq xmm0,xmm6		; xmm0=(00 10 20 30 40 50 60 70)=data0
180
	punpckhqdq xmm1,xmm6		; xmm1=(01 11 21 31 41 51 61 71)=data1
181
	movdqa     xmm5,xmm2		; transpose coefficients(phase 3)
182
	punpcklqdq xmm2,xmm3		; xmm2=(06 16 26 36 46 56 66 76)=data6
183
	punpckhqdq xmm5,xmm3		; xmm5=(07 17 27 37 47 57 67 77)=data7
184
185
	movdqa	xmm6,xmm1
186
	movdqa	xmm3,xmm0
187
	psubw	xmm1,xmm2		; xmm1=data1-data6=tmp6
188
	psubw	xmm0,xmm5		; xmm0=data0-data7=tmp7
189
	paddw	xmm6,xmm2		; xmm6=data1+data6=tmp1
190
	paddw	xmm3,xmm5		; xmm3=data0+data7=tmp0
191
192
	movdqa	xmm2, XMMWORD [wk(2)]	; xmm2=(42 52 62 72 43 53 63 73)
193
	movdqa	xmm5, XMMWORD [wk(3)]	; xmm5=(44 54 64 74 45 55 65 75)
194
	movdqa	XMMWORD [wk(0)], xmm1	; wk(0)=tmp6
195
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=tmp7
196
197
	movdqa     xmm1,xmm7		; transpose coefficients(phase 3)
198
	punpcklqdq xmm7,xmm2		; xmm7=(02 12 22 32 42 52 62 72)=data2
199
	punpckhqdq xmm1,xmm2		; xmm1=(03 13 23 33 43 53 63 73)=data3
200
	movdqa     xmm0,xmm4		; transpose coefficients(phase 3)
201
	punpcklqdq xmm4,xmm5		; xmm4=(04 14 24 34 44 54 64 74)=data4
202
	punpckhqdq xmm0,xmm5		; xmm0=(05 15 25 35 45 55 65 75)=data5
203
204
	movdqa	xmm2,xmm1
205
	movdqa	xmm5,xmm7
206
	paddw	xmm1,xmm4		; xmm1=data3+data4=tmp3
207
	paddw	xmm7,xmm0		; xmm7=data2+data5=tmp2
208
	psubw	xmm2,xmm4		; xmm2=data3-data4=tmp4
209
	psubw	xmm5,xmm0		; xmm5=data2-data5=tmp5
210
211
	; -- Even part
212
213
	movdqa	xmm4,xmm3
214
	movdqa	xmm0,xmm6
215
	paddw	xmm3,xmm1		; xmm3=tmp10
216
	paddw	xmm6,xmm7		; xmm6=tmp11
217
	psubw	xmm4,xmm1		; xmm4=tmp13
218
	psubw	xmm0,xmm7		; xmm0=tmp12
219
220
	movdqa	xmm1,xmm3
221
	paddw	xmm3,xmm6		; xmm3=tmp10+tmp11
222
	psubw	xmm1,xmm6		; xmm1=tmp10-tmp11
223
224
	psllw	xmm3,PASS1_BITS		; xmm3=data0
225
	psllw	xmm1,PASS1_BITS		; xmm1=data4
226
227
	movdqa	XMMWORD [wk(2)], xmm3	; wk(2)=data0
228
	movdqa	XMMWORD [wk(3)], xmm1	; wk(3)=data4
229
230
	; (Original)
231
	; z1 = (tmp12 + tmp13) * 0.541196100;
232
	; data2 = z1 + tmp13 * 0.765366865;
233
	; data6 = z1 + tmp12 * -1.847759065;
234
	;
235
	; (This implementation)
236
	; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
237
	; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
238
239
	movdqa    xmm7,xmm4		; xmm4=tmp13
240
	movdqa    xmm6,xmm4
241
	punpcklwd xmm7,xmm0		; xmm0=tmp12
242
	punpckhwd xmm6,xmm0
243
	movdqa    xmm4,xmm7
244
	movdqa    xmm0,xmm6
245
	pmaddwd   xmm7,[GOTOFF(ebx,PW_F130_F054)]	; xmm7=data2L
246
	pmaddwd   xmm6,[GOTOFF(ebx,PW_F130_F054)]	; xmm6=data2H
247
	pmaddwd   xmm4,[GOTOFF(ebx,PW_F054_MF130)]	; xmm4=data6L
248
	pmaddwd   xmm0,[GOTOFF(ebx,PW_F054_MF130)]	; xmm0=data6H
249
250
	paddd	xmm7,[GOTOFF(ebx,PD_DESCALE_P1)]
251
	paddd	xmm6,[GOTOFF(ebx,PD_DESCALE_P1)]
252
	psrad	xmm7,DESCALE_P1
253
	psrad	xmm6,DESCALE_P1
254
	paddd	xmm4,[GOTOFF(ebx,PD_DESCALE_P1)]
255
	paddd	xmm0,[GOTOFF(ebx,PD_DESCALE_P1)]
256
	psrad	xmm4,DESCALE_P1
257
	psrad	xmm0,DESCALE_P1
258
259
	packssdw  xmm7,xmm6		; xmm7=data2
260
	packssdw  xmm4,xmm0		; xmm4=data6
261
262
	movdqa	XMMWORD [wk(4)], xmm7	; wk(4)=data2
263
	movdqa	XMMWORD [wk(5)], xmm4	; wk(5)=data6
264
265
	; -- Odd part
266
267
	movdqa	xmm3, XMMWORD [wk(0)]	; xmm3=tmp6
268
	movdqa	xmm1, XMMWORD [wk(1)]	; xmm1=tmp7
269
270
	movdqa	xmm6,xmm2		; xmm2=tmp4
271
	movdqa	xmm0,xmm5		; xmm5=tmp5
272
	paddw	xmm6,xmm3		; xmm6=z3
273
	paddw	xmm0,xmm1		; xmm0=z4
274
275
	; (Original)
276
	; z5 = (z3 + z4) * 1.175875602;
277
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
278
	; z3 += z5;  z4 += z5;
279
	;
280
	; (This implementation)
281
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
282
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
283
284
	movdqa    xmm7,xmm6
285
	movdqa    xmm4,xmm6
286
	punpcklwd xmm7,xmm0
287
	punpckhwd xmm4,xmm0
288
	movdqa    xmm6,xmm7
289
	movdqa    xmm0,xmm4
290
	pmaddwd   xmm7,[GOTOFF(ebx,PW_MF078_F117)]	; xmm7=z3L
291
	pmaddwd   xmm4,[GOTOFF(ebx,PW_MF078_F117)]	; xmm4=z3H
292
	pmaddwd   xmm6,[GOTOFF(ebx,PW_F117_F078)]	; xmm6=z4L
293
	pmaddwd   xmm0,[GOTOFF(ebx,PW_F117_F078)]	; xmm0=z4H
294
295
	movdqa	XMMWORD [wk(0)], xmm7	; wk(0)=z3L
296
	movdqa	XMMWORD [wk(1)], xmm4	; wk(1)=z3H
297
298
	; (Original)
299
	; z1 = tmp4 + tmp7;  z2 = tmp5 + tmp6;
300
	; tmp4 = tmp4 * 0.298631336;  tmp5 = tmp5 * 2.053119869;
301
	; tmp6 = tmp6 * 3.072711026;  tmp7 = tmp7 * 1.501321110;
302
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
303
	; data7 = tmp4 + z1 + z3;  data5 = tmp5 + z2 + z4;
304
	; data3 = tmp6 + z2 + z3;  data1 = tmp7 + z1 + z4;
305
	;
306
	; (This implementation)
307
	; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
308
	; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
309
	; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
310
	; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
311
	; data7 = tmp4 + z3;  data5 = tmp5 + z4;
312
	; data3 = tmp6 + z3;  data1 = tmp7 + z4;
313
314
	movdqa    xmm7,xmm2
315
	movdqa    xmm4,xmm2
316
	punpcklwd xmm7,xmm1
317
	punpckhwd xmm4,xmm1
318
	movdqa    xmm2,xmm7
319
	movdqa    xmm1,xmm4
320
	pmaddwd   xmm7,[GOTOFF(ebx,PW_MF060_MF089)]	; xmm7=tmp4L
321
	pmaddwd   xmm4,[GOTOFF(ebx,PW_MF060_MF089)]	; xmm4=tmp4H
322
	pmaddwd   xmm2,[GOTOFF(ebx,PW_MF089_F060)]	; xmm2=tmp7L
323
	pmaddwd   xmm1,[GOTOFF(ebx,PW_MF089_F060)]	; xmm1=tmp7H
324
325
	paddd	xmm7, XMMWORD [wk(0)]	; xmm7=data7L
326
	paddd	xmm4, XMMWORD [wk(1)]	; xmm4=data7H
327
	paddd	xmm2,xmm6		; xmm2=data1L
328
	paddd	xmm1,xmm0		; xmm1=data1H
329
330
	paddd	xmm7,[GOTOFF(ebx,PD_DESCALE_P1)]
331
	paddd	xmm4,[GOTOFF(ebx,PD_DESCALE_P1)]
332
	psrad	xmm7,DESCALE_P1
333
	psrad	xmm4,DESCALE_P1
334
	paddd	xmm2,[GOTOFF(ebx,PD_DESCALE_P1)]
335
	paddd	xmm1,[GOTOFF(ebx,PD_DESCALE_P1)]
336
	psrad	xmm2,DESCALE_P1
337
	psrad	xmm1,DESCALE_P1
338
339
	packssdw  xmm7,xmm4		; xmm7=data7
340
	packssdw  xmm2,xmm1		; xmm2=data1
341
342
	movdqa    xmm4,xmm5
343
	movdqa    xmm1,xmm5
344
	punpcklwd xmm4,xmm3
345
	punpckhwd xmm1,xmm3
346
	movdqa    xmm5,xmm4
347
	movdqa    xmm3,xmm1
348
	pmaddwd   xmm4,[GOTOFF(ebx,PW_MF050_MF256)]	; xmm4=tmp5L
349
	pmaddwd   xmm1,[GOTOFF(ebx,PW_MF050_MF256)]	; xmm1=tmp5H
350
	pmaddwd   xmm5,[GOTOFF(ebx,PW_MF256_F050)]	; xmm5=tmp6L
351
	pmaddwd   xmm3,[GOTOFF(ebx,PW_MF256_F050)]	; xmm3=tmp6H
352
353
	paddd	xmm4,xmm6		; xmm4=data5L
354
	paddd	xmm1,xmm0		; xmm1=data5H
355
	paddd	xmm5, XMMWORD [wk(0)]	; xmm5=data3L
356
	paddd	xmm3, XMMWORD [wk(1)]	; xmm3=data3H
357
358
	paddd	xmm4,[GOTOFF(ebx,PD_DESCALE_P1)]
359
	paddd	xmm1,[GOTOFF(ebx,PD_DESCALE_P1)]
360
	psrad	xmm4,DESCALE_P1
361
	psrad	xmm1,DESCALE_P1
362
	paddd	xmm5,[GOTOFF(ebx,PD_DESCALE_P1)]
363
	paddd	xmm3,[GOTOFF(ebx,PD_DESCALE_P1)]
364
	psrad	xmm5,DESCALE_P1
365
	psrad	xmm3,DESCALE_P1
366
367
	packssdw  xmm4,xmm1		; xmm4=data5
368
	packssdw  xmm5,xmm3		; xmm5=data3
369
370
	; ---- Pass 2: process columns.
371
372
;	mov	edx, POINTER [data(eax)]	; (DCTELEM *)
373
374
	movdqa	xmm6, XMMWORD [wk(2)]	; xmm6=col0
375
	movdqa	xmm0, XMMWORD [wk(4)]	; xmm0=col2
376
377
	; xmm6=(00 10 20 30 40 50 60 70), xmm0=(02 12 22 32 42 52 62 72)
378
	; xmm2=(01 11 21 31 41 51 61 71), xmm5=(03 13 23 33 43 53 63 73)
379
380
	movdqa    xmm1,xmm6		; transpose coefficients(phase 1)
381
	punpcklwd xmm6,xmm2		; xmm6=(00 01 10 11 20 21 30 31)
382
	punpckhwd xmm1,xmm2		; xmm1=(40 41 50 51 60 61 70 71)
383
	movdqa    xmm3,xmm0		; transpose coefficients(phase 1)
384
	punpcklwd xmm0,xmm5		; xmm0=(02 03 12 13 22 23 32 33)
385
	punpckhwd xmm3,xmm5		; xmm3=(42 43 52 53 62 63 72 73)
386
387
	movdqa	xmm2, XMMWORD [wk(3)]	; xmm2=col4
388
	movdqa	xmm5, XMMWORD [wk(5)]	; xmm5=col6
389
390
	; xmm2=(04 14 24 34 44 54 64 74), xmm5=(06 16 26 36 46 56 66 76)
391
	; xmm4=(05 15 25 35 45 55 65 75), xmm7=(07 17 27 37 47 57 67 77)
392
393
	movdqa	XMMWORD [wk(0)], xmm0	; wk(0)=(02 03 12 13 22 23 32 33)
394
	movdqa	XMMWORD [wk(1)], xmm3	; wk(1)=(42 43 52 53 62 63 72 73)
395
396
	movdqa    xmm0,xmm2		; transpose coefficients(phase 1)
397
	punpcklwd xmm2,xmm4		; xmm2=(04 05 14 15 24 25 34 35)
398
	punpckhwd xmm0,xmm4		; xmm0=(44 45 54 55 64 65 74 75)
399
	movdqa    xmm3,xmm5		; transpose coefficients(phase 1)
400
	punpcklwd xmm5,xmm7		; xmm5=(06 07 16 17 26 27 36 37)
401
	punpckhwd xmm3,xmm7		; xmm3=(46 47 56 57 66 67 76 77)
402
403
	movdqa    xmm4,xmm2		; transpose coefficients(phase 2)
404
	punpckldq xmm2,xmm5		; xmm2=(04 05 06 07 14 15 16 17)
405
	punpckhdq xmm4,xmm5		; xmm4=(24 25 26 27 34 35 36 37)
406
	movdqa    xmm7,xmm0		; transpose coefficients(phase 2)
407
	punpckldq xmm0,xmm3		; xmm0=(44 45 46 47 54 55 56 57)
408
	punpckhdq xmm7,xmm3		; xmm7=(64 65 66 67 74 75 76 77)
409
410
	movdqa	xmm5, XMMWORD [wk(0)]	; xmm5=(02 03 12 13 22 23 32 33)
411
	movdqa	xmm3, XMMWORD [wk(1)]	; xmm3=(42 43 52 53 62 63 72 73)
412
	movdqa	XMMWORD [wk(2)], xmm4	; wk(2)=(24 25 26 27 34 35 36 37)
413
	movdqa	XMMWORD [wk(3)], xmm0	; wk(3)=(44 45 46 47 54 55 56 57)
414
415
	movdqa    xmm4,xmm6		; transpose coefficients(phase 2)
416
	punpckldq xmm6,xmm5		; xmm6=(00 01 02 03 10 11 12 13)
417
	punpckhdq xmm4,xmm5		; xmm4=(20 21 22 23 30 31 32 33)
418
	movdqa    xmm0,xmm1		; transpose coefficients(phase 2)
419
	punpckldq xmm1,xmm3		; xmm1=(40 41 42 43 50 51 52 53)
420
	punpckhdq xmm0,xmm3		; xmm0=(60 61 62 63 70 71 72 73)
421
422
	movdqa     xmm5,xmm6		; transpose coefficients(phase 3)
423
	punpcklqdq xmm6,xmm2		; xmm6=(00 01 02 03 04 05 06 07)=data0
424
	punpckhqdq xmm5,xmm2		; xmm5=(10 11 12 13 14 15 16 17)=data1
425
	movdqa     xmm3,xmm0		; transpose coefficients(phase 3)
426
	punpcklqdq xmm0,xmm7		; xmm0=(60 61 62 63 64 65 66 67)=data6
427
	punpckhqdq xmm3,xmm7		; xmm3=(70 71 72 73 74 75 76 77)=data7
428
429
	movdqa	xmm2,xmm5
430
	movdqa	xmm7,xmm6
431
	psubw	xmm5,xmm0		; xmm5=data1-data6=tmp6
432
	psubw	xmm6,xmm3		; xmm6=data0-data7=tmp7
433
	paddw	xmm2,xmm0		; xmm2=data1+data6=tmp1
434
	paddw	xmm7,xmm3		; xmm7=data0+data7=tmp0
435
436
	movdqa	xmm0, XMMWORD [wk(2)]	; xmm0=(24 25 26 27 34 35 36 37)
437
	movdqa	xmm3, XMMWORD [wk(3)]	; xmm3=(44 45 46 47 54 55 56 57)
438
	movdqa	XMMWORD [wk(0)], xmm5	; wk(0)=tmp6
439
	movdqa	XMMWORD [wk(1)], xmm6	; wk(1)=tmp7
440
441
	movdqa     xmm5,xmm4		; transpose coefficients(phase 3)
442
	punpcklqdq xmm4,xmm0		; xmm4=(20 21 22 23 24 25 26 27)=data2
443
	punpckhqdq xmm5,xmm0		; xmm5=(30 31 32 33 34 35 36 37)=data3
444
	movdqa     xmm6,xmm1		; transpose coefficients(phase 3)
445
	punpcklqdq xmm1,xmm3		; xmm1=(40 41 42 43 44 45 46 47)=data4
446
	punpckhqdq xmm6,xmm3		; xmm6=(50 51 52 53 54 55 56 57)=data5
447
448
	movdqa	xmm0,xmm5
449
	movdqa	xmm3,xmm4
450
	paddw	xmm5,xmm1		; xmm5=data3+data4=tmp3
451
	paddw	xmm4,xmm6		; xmm4=data2+data5=tmp2
452
	psubw	xmm0,xmm1		; xmm0=data3-data4=tmp4
453
	psubw	xmm3,xmm6		; xmm3=data2-data5=tmp5
454
455
	; -- Even part
456
457
	movdqa	xmm1,xmm7
458
	movdqa	xmm6,xmm2
459
	paddw	xmm7,xmm5		; xmm7=tmp10
460
	paddw	xmm2,xmm4		; xmm2=tmp11
461
	psubw	xmm1,xmm5		; xmm1=tmp13
462
	psubw	xmm6,xmm4		; xmm6=tmp12
463
464
	movdqa	xmm5,xmm7
465
	paddw	xmm7,xmm2		; xmm7=tmp10+tmp11
466
	psubw	xmm5,xmm2		; xmm5=tmp10-tmp11
467
468
	paddw	xmm7,[GOTOFF(ebx,PW_DESCALE_P2X)]
469
	paddw	xmm5,[GOTOFF(ebx,PW_DESCALE_P2X)]
470
	psraw	xmm7,PASS1_BITS		; xmm7=data0
471
	psraw	xmm5,PASS1_BITS		; xmm5=data4
472
473
	movdqa	XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)], xmm7
474
	movdqa	XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)], xmm5
475
476
	; (Original)
477
	; z1 = (tmp12 + tmp13) * 0.541196100;
478
	; data2 = z1 + tmp13 * 0.765366865;
479
	; data6 = z1 + tmp12 * -1.847759065;
480
	;
481
	; (This implementation)
482
	; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
483
	; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
484
485
	movdqa    xmm4,xmm1		; xmm1=tmp13
486
	movdqa    xmm2,xmm1
487
	punpcklwd xmm4,xmm6		; xmm6=tmp12
488
	punpckhwd xmm2,xmm6
489
	movdqa    xmm1,xmm4
490
	movdqa    xmm6,xmm2
491
	pmaddwd   xmm4,[GOTOFF(ebx,PW_F130_F054)]	; xmm4=data2L
492
	pmaddwd   xmm2,[GOTOFF(ebx,PW_F130_F054)]	; xmm2=data2H
493
	pmaddwd   xmm1,[GOTOFF(ebx,PW_F054_MF130)]	; xmm1=data6L
494
	pmaddwd   xmm6,[GOTOFF(ebx,PW_F054_MF130)]	; xmm6=data6H
495
496
	paddd	xmm4,[GOTOFF(ebx,PD_DESCALE_P2)]
497
	paddd	xmm2,[GOTOFF(ebx,PD_DESCALE_P2)]
498
	psrad	xmm4,DESCALE_P2
499
	psrad	xmm2,DESCALE_P2
500
	paddd	xmm1,[GOTOFF(ebx,PD_DESCALE_P2)]
501
	paddd	xmm6,[GOTOFF(ebx,PD_DESCALE_P2)]
502
	psrad	xmm1,DESCALE_P2
503
	psrad	xmm6,DESCALE_P2
504
505
	packssdw  xmm4,xmm2		; xmm4=data2
506
	packssdw  xmm1,xmm6		; xmm1=data6
507
508
	movdqa	XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)], xmm4
509
	movdqa	XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)], xmm1
510
511
	; -- Odd part
512
513
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=tmp6
514
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=tmp7
515
516
	movdqa	xmm2,xmm0		; xmm0=tmp4
517
	movdqa	xmm6,xmm3		; xmm3=tmp5
518
	paddw	xmm2,xmm7		; xmm2=z3
519
	paddw	xmm6,xmm5		; xmm6=z4
520
521
	; (Original)
522
	; z5 = (z3 + z4) * 1.175875602;
523
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
524
	; z3 += z5;  z4 += z5;
525
	;
526
	; (This implementation)
527
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
528
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
529
530
	movdqa    xmm4,xmm2
531
	movdqa    xmm1,xmm2
532
	punpcklwd xmm4,xmm6
533
	punpckhwd xmm1,xmm6
534
	movdqa    xmm2,xmm4
535
	movdqa    xmm6,xmm1
536
	pmaddwd   xmm4,[GOTOFF(ebx,PW_MF078_F117)]	; xmm4=z3L
537
	pmaddwd   xmm1,[GOTOFF(ebx,PW_MF078_F117)]	; xmm1=z3H
538
	pmaddwd   xmm2,[GOTOFF(ebx,PW_F117_F078)]	; xmm2=z4L
539
	pmaddwd   xmm6,[GOTOFF(ebx,PW_F117_F078)]	; xmm6=z4H
540
541
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=z3L
542
	movdqa	XMMWORD [wk(1)], xmm1	; wk(1)=z3H
543
544
	; (Original)
545
	; z1 = tmp4 + tmp7;  z2 = tmp5 + tmp6;
546
	; tmp4 = tmp4 * 0.298631336;  tmp5 = tmp5 * 2.053119869;
547
	; tmp6 = tmp6 * 3.072711026;  tmp7 = tmp7 * 1.501321110;
548
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
549
	; data7 = tmp4 + z1 + z3;  data5 = tmp5 + z2 + z4;
550
	; data3 = tmp6 + z2 + z3;  data1 = tmp7 + z1 + z4;
551
	;
552
	; (This implementation)
553
	; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
554
	; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
555
	; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
556
	; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
557
	; data7 = tmp4 + z3;  data5 = tmp5 + z4;
558
	; data3 = tmp6 + z3;  data1 = tmp7 + z4;
559
560
	movdqa    xmm4,xmm0
561
	movdqa    xmm1,xmm0
562
	punpcklwd xmm4,xmm5
563
	punpckhwd xmm1,xmm5
564
	movdqa    xmm0,xmm4
565
	movdqa    xmm5,xmm1
566
	pmaddwd   xmm4,[GOTOFF(ebx,PW_MF060_MF089)]	; xmm4=tmp4L
567
	pmaddwd   xmm1,[GOTOFF(ebx,PW_MF060_MF089)]	; xmm1=tmp4H
568
	pmaddwd   xmm0,[GOTOFF(ebx,PW_MF089_F060)]	; xmm0=tmp7L
569
	pmaddwd   xmm5,[GOTOFF(ebx,PW_MF089_F060)]	; xmm5=tmp7H
570
571
	paddd	xmm4, XMMWORD [wk(0)]	; xmm4=data7L
572
	paddd	xmm1, XMMWORD [wk(1)]	; xmm1=data7H
573
	paddd	xmm0,xmm2		; xmm0=data1L
574
	paddd	xmm5,xmm6		; xmm5=data1H
575
576
	paddd	xmm4,[GOTOFF(ebx,PD_DESCALE_P2)]
577
	paddd	xmm1,[GOTOFF(ebx,PD_DESCALE_P2)]
578
	psrad	xmm4,DESCALE_P2
579
	psrad	xmm1,DESCALE_P2
580
	paddd	xmm0,[GOTOFF(ebx,PD_DESCALE_P2)]
581
	paddd	xmm5,[GOTOFF(ebx,PD_DESCALE_P2)]
582
	psrad	xmm0,DESCALE_P2
583
	psrad	xmm5,DESCALE_P2
584
585
	packssdw  xmm4,xmm1		; xmm4=data7
586
	packssdw  xmm0,xmm5		; xmm0=data1
587
588
	movdqa	XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)], xmm4
589
	movdqa	XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)], xmm0
590
591
	movdqa    xmm1,xmm3
592
	movdqa    xmm5,xmm3
593
	punpcklwd xmm1,xmm7
594
	punpckhwd xmm5,xmm7
595
	movdqa    xmm3,xmm1
596
	movdqa    xmm7,xmm5
597
	pmaddwd   xmm1,[GOTOFF(ebx,PW_MF050_MF256)]	; xmm1=tmp5L
598
	pmaddwd   xmm5,[GOTOFF(ebx,PW_MF050_MF256)]	; xmm5=tmp5H
599
	pmaddwd   xmm3,[GOTOFF(ebx,PW_MF256_F050)]	; xmm3=tmp6L
600
	pmaddwd   xmm7,[GOTOFF(ebx,PW_MF256_F050)]	; xmm7=tmp6H
601
602
	paddd	xmm1,xmm2		; xmm1=data5L
603
	paddd	xmm5,xmm6		; xmm5=data5H
604
	paddd	xmm3, XMMWORD [wk(0)]	; xmm3=data3L
605
	paddd	xmm7, XMMWORD [wk(1)]	; xmm7=data3H
606
607
	paddd	xmm1,[GOTOFF(ebx,PD_DESCALE_P2)]
608
	paddd	xmm5,[GOTOFF(ebx,PD_DESCALE_P2)]
609
	psrad	xmm1,DESCALE_P2
610
	psrad	xmm5,DESCALE_P2
611
	paddd	xmm3,[GOTOFF(ebx,PD_DESCALE_P2)]
612
	paddd	xmm7,[GOTOFF(ebx,PD_DESCALE_P2)]
613
	psrad	xmm3,DESCALE_P2
614
	psrad	xmm7,DESCALE_P2
615
616
	packssdw  xmm1,xmm5		; xmm1=data5
617
	packssdw  xmm3,xmm7		; xmm3=data3
618
619
	movdqa	XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)], xmm1
620
	movdqa	XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)], xmm3
621
622
;	pop	edi		; unused
623
;	pop	esi		; unused
624
;	pop	edx		; need not be preserved
625
;	pop	ecx		; unused
626
	poppic	ebx
627
	mov	esp,ebp		; esp <- aligned ebp
628
	pop	esp		; esp <- original ebp
629
	pop	ebp
630
	ret
631
632
; For some reason, the OS X linker does not honor the request to align the
633
; segment unless we do this.
634
	align	16
(-)a/jpeg/simd/jfsseflt-64.asm (+358 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jfsseflt-64.asm - floating-point FDCT (64-bit SSE)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; This file contains a floating-point implementation of the forward DCT
19
; (Discrete Cosine Transform). The following code is based directly on
20
; the IJG's original jfdctflt.c; see the jfdctflt.c for more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%macro	unpcklps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5)
30
	shufps	%1,%2,0x44
31
%endmacro
32
33
%macro	unpckhps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7)
34
	shufps	%1,%2,0xEE
35
%endmacro
36
37
; --------------------------------------------------------------------------
38
	SECTION	SEG_CONST
39
40
	alignz	16
41
	global	EXTN(jconst_fdct_float_sse)
42
43
EXTN(jconst_fdct_float_sse):
44
45
PD_0_382	times 4 dd  0.382683432365089771728460
46
PD_0_707	times 4 dd  0.707106781186547524400844
47
PD_0_541	times 4 dd  0.541196100146196984399723
48
PD_1_306	times 4 dd  1.306562964876376527856643
49
50
	alignz	16
51
52
; --------------------------------------------------------------------------
53
	SECTION	SEG_TEXT
54
	BITS	64
55
;
56
; Perform the forward DCT on one block of samples.
57
;
58
; GLOBAL(void)
59
; jsimd_fdct_float_sse (FAST_FLOAT * data)
60
;
61
62
; r10 = FAST_FLOAT * data
63
64
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
65
%define WK_NUM		2
66
67
	align	16
68
	global	EXTN(jsimd_fdct_float_sse)
69
70
EXTN(jsimd_fdct_float_sse):
71
	push	rbp
72
	mov	rax,rsp				; rax = original rbp
73
	sub	rsp, byte 4
74
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
75
	mov	[rsp],rax
76
	mov	rbp,rsp				; rbp = aligned rbp
77
	lea	rsp, [wk(0)]
78
	collect_args
79
80
	; ---- Pass 1: process rows.
81
82
	mov	rdx, r10	; (FAST_FLOAT *)
83
	mov	rcx, DCTSIZE/4
84
.rowloop:
85
86
	movaps	xmm0, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)]
87
	movaps	xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)]
88
	movaps	xmm2, XMMWORD [XMMBLOCK(2,1,rdx,SIZEOF_FAST_FLOAT)]
89
	movaps	xmm3, XMMWORD [XMMBLOCK(3,1,rdx,SIZEOF_FAST_FLOAT)]
90
91
	; xmm0=(20 21 22 23), xmm2=(24 25 26 27)
92
	; xmm1=(30 31 32 33), xmm3=(34 35 36 37)
93
94
	movaps   xmm4,xmm0		; transpose coefficients(phase 1)
95
	unpcklps xmm0,xmm1		; xmm0=(20 30 21 31)
96
	unpckhps xmm4,xmm1		; xmm4=(22 32 23 33)
97
	movaps   xmm5,xmm2		; transpose coefficients(phase 1)
98
	unpcklps xmm2,xmm3		; xmm2=(24 34 25 35)
99
	unpckhps xmm5,xmm3		; xmm5=(26 36 27 37)
100
101
	movaps	xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)]
102
	movaps	xmm7, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)]
103
	movaps	xmm1, XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)]
104
	movaps	xmm3, XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)]
105
106
	; xmm6=(00 01 02 03), xmm1=(04 05 06 07)
107
	; xmm7=(10 11 12 13), xmm3=(14 15 16 17)
108
109
	movaps	XMMWORD [wk(0)], xmm4	; wk(0)=(22 32 23 33)
110
	movaps	XMMWORD [wk(1)], xmm2	; wk(1)=(24 34 25 35)
111
112
	movaps   xmm4,xmm6		; transpose coefficients(phase 1)
113
	unpcklps xmm6,xmm7		; xmm6=(00 10 01 11)
114
	unpckhps xmm4,xmm7		; xmm4=(02 12 03 13)
115
	movaps   xmm2,xmm1		; transpose coefficients(phase 1)
116
	unpcklps xmm1,xmm3		; xmm1=(04 14 05 15)
117
	unpckhps xmm2,xmm3		; xmm2=(06 16 07 17)
118
119
	movaps    xmm7,xmm6		; transpose coefficients(phase 2)
120
	unpcklps2 xmm6,xmm0		; xmm6=(00 10 20 30)=data0
121
	unpckhps2 xmm7,xmm0		; xmm7=(01 11 21 31)=data1
122
	movaps    xmm3,xmm2		; transpose coefficients(phase 2)
123
	unpcklps2 xmm2,xmm5		; xmm2=(06 16 26 36)=data6
124
	unpckhps2 xmm3,xmm5		; xmm3=(07 17 27 37)=data7
125
126
	movaps	xmm0,xmm7
127
	movaps	xmm5,xmm6
128
	subps	xmm7,xmm2		; xmm7=data1-data6=tmp6
129
	subps	xmm6,xmm3		; xmm6=data0-data7=tmp7
130
	addps	xmm0,xmm2		; xmm0=data1+data6=tmp1
131
	addps	xmm5,xmm3		; xmm5=data0+data7=tmp0
132
133
	movaps	xmm2, XMMWORD [wk(0)]	; xmm2=(22 32 23 33)
134
	movaps	xmm3, XMMWORD [wk(1)]	; xmm3=(24 34 25 35)
135
	movaps	XMMWORD [wk(0)], xmm7	; wk(0)=tmp6
136
	movaps	XMMWORD [wk(1)], xmm6	; wk(1)=tmp7
137
138
	movaps    xmm7,xmm4		; transpose coefficients(phase 2)
139
	unpcklps2 xmm4,xmm2		; xmm4=(02 12 22 32)=data2
140
	unpckhps2 xmm7,xmm2		; xmm7=(03 13 23 33)=data3
141
	movaps    xmm6,xmm1		; transpose coefficients(phase 2)
142
	unpcklps2 xmm1,xmm3		; xmm1=(04 14 24 34)=data4
143
	unpckhps2 xmm6,xmm3		; xmm6=(05 15 25 35)=data5
144
145
	movaps	xmm2,xmm7
146
	movaps	xmm3,xmm4
147
	addps	xmm7,xmm1		; xmm7=data3+data4=tmp3
148
	addps	xmm4,xmm6		; xmm4=data2+data5=tmp2
149
	subps	xmm2,xmm1		; xmm2=data3-data4=tmp4
150
	subps	xmm3,xmm6		; xmm3=data2-data5=tmp5
151
152
	; -- Even part
153
154
	movaps	xmm1,xmm5
155
	movaps	xmm6,xmm0
156
	subps	xmm5,xmm7		; xmm5=tmp13
157
	subps	xmm0,xmm4		; xmm0=tmp12
158
	addps	xmm1,xmm7		; xmm1=tmp10
159
	addps	xmm6,xmm4		; xmm6=tmp11
160
161
	addps	xmm0,xmm5
162
	mulps	xmm0,[rel PD_0_707] ; xmm0=z1
163
164
	movaps	xmm7,xmm1
165
	movaps	xmm4,xmm5
166
	subps	xmm1,xmm6		; xmm1=data4
167
	subps	xmm5,xmm0		; xmm5=data6
168
	addps	xmm7,xmm6		; xmm7=data0
169
	addps	xmm4,xmm0		; xmm4=data2
170
171
	movaps	XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)], xmm1
172
	movaps	XMMWORD [XMMBLOCK(2,1,rdx,SIZEOF_FAST_FLOAT)], xmm5
173
	movaps	XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)], xmm7
174
	movaps	XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)], xmm4
175
176
	; -- Odd part
177
178
	movaps	xmm6, XMMWORD [wk(0)]	; xmm6=tmp6
179
	movaps	xmm0, XMMWORD [wk(1)]	; xmm0=tmp7
180
181
	addps	xmm2,xmm3		; xmm2=tmp10
182
	addps	xmm3,xmm6		; xmm3=tmp11
183
	addps	xmm6,xmm0		; xmm6=tmp12, xmm0=tmp7
184
185
	mulps	xmm3,[rel PD_0_707] ; xmm3=z3
186
187
	movaps	xmm1,xmm2		; xmm1=tmp10
188
	subps	xmm2,xmm6
189
	mulps	xmm2,[rel PD_0_382] ; xmm2=z5
190
	mulps	xmm1,[rel PD_0_541] ; xmm1=MULTIPLY(tmp10,FIX_0_541196)
191
	mulps	xmm6,[rel PD_1_306] ; xmm6=MULTIPLY(tmp12,FIX_1_306562)
192
	addps	xmm1,xmm2		; xmm1=z2
193
	addps	xmm6,xmm2		; xmm6=z4
194
195
	movaps	xmm5,xmm0
196
	subps	xmm0,xmm3		; xmm0=z13
197
	addps	xmm5,xmm3		; xmm5=z11
198
199
	movaps	xmm7,xmm0
200
	movaps	xmm4,xmm5
201
	subps	xmm0,xmm1		; xmm0=data3
202
	subps	xmm5,xmm6		; xmm5=data7
203
	addps	xmm7,xmm1		; xmm7=data5
204
	addps	xmm4,xmm6		; xmm4=data1
205
206
	movaps	XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)], xmm0
207
	movaps	XMMWORD [XMMBLOCK(3,1,rdx,SIZEOF_FAST_FLOAT)], xmm5
208
	movaps	XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)], xmm7
209
	movaps	XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)], xmm4
210
211
	add	rdx, 4*DCTSIZE*SIZEOF_FAST_FLOAT
212
	dec	rcx
213
	jnz	near .rowloop
214
215
	; ---- Pass 2: process columns.
216
217
	mov	rdx, r10	; (FAST_FLOAT *)
218
	mov	rcx, DCTSIZE/4
219
.columnloop:
220
221
	movaps	xmm0, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)]
222
	movaps	xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)]
223
	movaps	xmm2, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_FAST_FLOAT)]
224
	movaps	xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_FAST_FLOAT)]
225
226
	; xmm0=(02 12 22 32), xmm2=(42 52 62 72)
227
	; xmm1=(03 13 23 33), xmm3=(43 53 63 73)
228
229
	movaps   xmm4,xmm0		; transpose coefficients(phase 1)
230
	unpcklps xmm0,xmm1		; xmm0=(02 03 12 13)
231
	unpckhps xmm4,xmm1		; xmm4=(22 23 32 33)
232
	movaps   xmm5,xmm2		; transpose coefficients(phase 1)
233
	unpcklps xmm2,xmm3		; xmm2=(42 43 52 53)
234
	unpckhps xmm5,xmm3		; xmm5=(62 63 72 73)
235
236
	movaps	xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)]
237
	movaps	xmm7, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)]
238
	movaps	xmm1, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_FAST_FLOAT)]
239
	movaps	xmm3, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_FAST_FLOAT)]
240
241
	; xmm6=(00 10 20 30), xmm1=(40 50 60 70)
242
	; xmm7=(01 11 21 31), xmm3=(41 51 61 71)
243
244
	movaps	XMMWORD [wk(0)], xmm4	; wk(0)=(22 23 32 33)
245
	movaps	XMMWORD [wk(1)], xmm2	; wk(1)=(42 43 52 53)
246
247
	movaps   xmm4,xmm6		; transpose coefficients(phase 1)
248
	unpcklps xmm6,xmm7		; xmm6=(00 01 10 11)
249
	unpckhps xmm4,xmm7		; xmm4=(20 21 30 31)
250
	movaps   xmm2,xmm1		; transpose coefficients(phase 1)
251
	unpcklps xmm1,xmm3		; xmm1=(40 41 50 51)
252
	unpckhps xmm2,xmm3		; xmm2=(60 61 70 71)
253
254
	movaps    xmm7,xmm6		; transpose coefficients(phase 2)
255
	unpcklps2 xmm6,xmm0		; xmm6=(00 01 02 03)=data0
256
	unpckhps2 xmm7,xmm0		; xmm7=(10 11 12 13)=data1
257
	movaps    xmm3,xmm2		; transpose coefficients(phase 2)
258
	unpcklps2 xmm2,xmm5		; xmm2=(60 61 62 63)=data6
259
	unpckhps2 xmm3,xmm5		; xmm3=(70 71 72 73)=data7
260
261
	movaps	xmm0,xmm7
262
	movaps	xmm5,xmm6
263
	subps	xmm7,xmm2		; xmm7=data1-data6=tmp6
264
	subps	xmm6,xmm3		; xmm6=data0-data7=tmp7
265
	addps	xmm0,xmm2		; xmm0=data1+data6=tmp1
266
	addps	xmm5,xmm3		; xmm5=data0+data7=tmp0
267
268
	movaps	xmm2, XMMWORD [wk(0)]	; xmm2=(22 23 32 33)
269
	movaps	xmm3, XMMWORD [wk(1)]	; xmm3=(42 43 52 53)
270
	movaps	XMMWORD [wk(0)], xmm7	; wk(0)=tmp6
271
	movaps	XMMWORD [wk(1)], xmm6	; wk(1)=tmp7
272
273
	movaps    xmm7,xmm4		; transpose coefficients(phase 2)
274
	unpcklps2 xmm4,xmm2		; xmm4=(20 21 22 23)=data2
275
	unpckhps2 xmm7,xmm2		; xmm7=(30 31 32 33)=data3
276
	movaps    xmm6,xmm1		; transpose coefficients(phase 2)
277
	unpcklps2 xmm1,xmm3		; xmm1=(40 41 42 43)=data4
278
	unpckhps2 xmm6,xmm3		; xmm6=(50 51 52 53)=data5
279
280
	movaps	xmm2,xmm7
281
	movaps	xmm3,xmm4
282
	addps	xmm7,xmm1		; xmm7=data3+data4=tmp3
283
	addps	xmm4,xmm6		; xmm4=data2+data5=tmp2
284
	subps	xmm2,xmm1		; xmm2=data3-data4=tmp4
285
	subps	xmm3,xmm6		; xmm3=data2-data5=tmp5
286
287
	; -- Even part
288
289
	movaps	xmm1,xmm5
290
	movaps	xmm6,xmm0
291
	subps	xmm5,xmm7		; xmm5=tmp13
292
	subps	xmm0,xmm4		; xmm0=tmp12
293
	addps	xmm1,xmm7		; xmm1=tmp10
294
	addps	xmm6,xmm4		; xmm6=tmp11
295
296
	addps	xmm0,xmm5
297
	mulps	xmm0,[rel PD_0_707] ; xmm0=z1
298
299
	movaps	xmm7,xmm1
300
	movaps	xmm4,xmm5
301
	subps	xmm1,xmm6		; xmm1=data4
302
	subps	xmm5,xmm0		; xmm5=data6
303
	addps	xmm7,xmm6		; xmm7=data0
304
	addps	xmm4,xmm0		; xmm4=data2
305
306
	movaps	XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_FAST_FLOAT)], xmm1
307
	movaps	XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_FAST_FLOAT)], xmm5
308
	movaps	XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)], xmm7
309
	movaps	XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FAST_FLOAT)], xmm4
310
311
	; -- Odd part
312
313
	movaps	xmm6, XMMWORD [wk(0)]	; xmm6=tmp6
314
	movaps	xmm0, XMMWORD [wk(1)]	; xmm0=tmp7
315
316
	addps	xmm2,xmm3		; xmm2=tmp10
317
	addps	xmm3,xmm6		; xmm3=tmp11
318
	addps	xmm6,xmm0		; xmm6=tmp12, xmm0=tmp7
319
320
	mulps	xmm3,[rel PD_0_707] ; xmm3=z3
321
322
	movaps	xmm1,xmm2		; xmm1=tmp10
323
	subps	xmm2,xmm6
324
	mulps	xmm2,[rel PD_0_382] ; xmm2=z5
325
	mulps	xmm1,[rel PD_0_541] ; xmm1=MULTIPLY(tmp10,FIX_0_541196)
326
	mulps	xmm6,[rel PD_1_306] ; xmm6=MULTIPLY(tmp12,FIX_1_306562)
327
	addps	xmm1,xmm2		; xmm1=z2
328
	addps	xmm6,xmm2		; xmm6=z4
329
330
	movaps	xmm5,xmm0
331
	subps	xmm0,xmm3		; xmm0=z13
332
	addps	xmm5,xmm3		; xmm5=z11
333
334
	movaps	xmm7,xmm0
335
	movaps	xmm4,xmm5
336
	subps	xmm0,xmm1		; xmm0=data3
337
	subps	xmm5,xmm6		; xmm5=data7
338
	addps	xmm7,xmm1		; xmm7=data5
339
	addps	xmm4,xmm6		; xmm4=data1
340
341
	movaps	XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FAST_FLOAT)], xmm0
342
	movaps	XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_FAST_FLOAT)], xmm5
343
	movaps	XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_FAST_FLOAT)], xmm7
344
	movaps	XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)], xmm4
345
346
	add	rdx, byte 4*SIZEOF_FAST_FLOAT
347
	dec	rcx
348
	jnz	near .columnloop
349
350
	uncollect_args
351
	mov	rsp,rbp		; rsp <- aligned rbp
352
	pop	rsp		; rsp <- original rbp
353
	pop	rbp
354
	ret
355
356
; For some reason, the OS X linker does not honor the request to align the
357
; segment unless we do this.
358
	align	16
(-)a/jpeg/simd/jfsseflt.asm (+370 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jfsseflt.asm - floating-point FDCT (SSE)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a floating-point implementation of the forward DCT
18
; (Discrete Cosine Transform). The following code is based directly on
19
; the IJG's original jfdctflt.c; see the jfdctflt.c for more details.
20
;
21
; [TAB8]
22
23
%include "jsimdext.inc"
24
%include "jdct.inc"
25
26
; --------------------------------------------------------------------------
27
28
%macro	unpcklps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5)
29
	shufps	%1,%2,0x44
30
%endmacro
31
32
%macro	unpckhps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7)
33
	shufps	%1,%2,0xEE
34
%endmacro
35
36
; --------------------------------------------------------------------------
37
	SECTION	SEG_CONST
38
39
	alignz	16
40
	global	EXTN(jconst_fdct_float_sse)
41
42
EXTN(jconst_fdct_float_sse):
43
44
PD_0_382	times 4 dd  0.382683432365089771728460
45
PD_0_707	times 4 dd  0.707106781186547524400844
46
PD_0_541	times 4 dd  0.541196100146196984399723
47
PD_1_306	times 4 dd  1.306562964876376527856643
48
49
	alignz	16
50
51
; --------------------------------------------------------------------------
52
	SECTION	SEG_TEXT
53
	BITS	32
54
;
55
; Perform the forward DCT on one block of samples.
56
;
57
; GLOBAL(void)
58
; jsimd_fdct_float_sse (FAST_FLOAT * data)
59
;
60
61
%define data(b)		(b)+8		; FAST_FLOAT * data
62
63
%define original_ebp	ebp+0
64
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
65
%define WK_NUM		2
66
67
	align	16
68
	global	EXTN(jsimd_fdct_float_sse)
69
70
EXTN(jsimd_fdct_float_sse):
71
	push	ebp
72
	mov	eax,esp				; eax = original ebp
73
	sub	esp, byte 4
74
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
75
	mov	[esp],eax
76
	mov	ebp,esp				; ebp = aligned ebp
77
	lea	esp, [wk(0)]
78
	pushpic	ebx
79
;	push	ecx		; need not be preserved
80
;	push	edx		; need not be preserved
81
;	push	esi		; unused
82
;	push	edi		; unused
83
84
	get_GOT	ebx		; get GOT address
85
86
	; ---- Pass 1: process rows.
87
88
	mov	edx, POINTER [data(eax)]	; (FAST_FLOAT *)
89
	mov	ecx, DCTSIZE/4
90
	alignx	16,7
91
.rowloop:
92
93
	movaps	xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)]
94
	movaps	xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)]
95
	movaps	xmm2, XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)]
96
	movaps	xmm3, XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)]
97
98
	; xmm0=(20 21 22 23), xmm2=(24 25 26 27)
99
	; xmm1=(30 31 32 33), xmm3=(34 35 36 37)
100
101
	movaps   xmm4,xmm0		; transpose coefficients(phase 1)
102
	unpcklps xmm0,xmm1		; xmm0=(20 30 21 31)
103
	unpckhps xmm4,xmm1		; xmm4=(22 32 23 33)
104
	movaps   xmm5,xmm2		; transpose coefficients(phase 1)
105
	unpcklps xmm2,xmm3		; xmm2=(24 34 25 35)
106
	unpckhps xmm5,xmm3		; xmm5=(26 36 27 37)
107
108
	movaps	xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
109
	movaps	xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
110
	movaps	xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
111
	movaps	xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
112
113
	; xmm6=(00 01 02 03), xmm1=(04 05 06 07)
114
	; xmm7=(10 11 12 13), xmm3=(14 15 16 17)
115
116
	movaps	XMMWORD [wk(0)], xmm4	; wk(0)=(22 32 23 33)
117
	movaps	XMMWORD [wk(1)], xmm2	; wk(1)=(24 34 25 35)
118
119
	movaps   xmm4,xmm6		; transpose coefficients(phase 1)
120
	unpcklps xmm6,xmm7		; xmm6=(00 10 01 11)
121
	unpckhps xmm4,xmm7		; xmm4=(02 12 03 13)
122
	movaps   xmm2,xmm1		; transpose coefficients(phase 1)
123
	unpcklps xmm1,xmm3		; xmm1=(04 14 05 15)
124
	unpckhps xmm2,xmm3		; xmm2=(06 16 07 17)
125
126
	movaps    xmm7,xmm6		; transpose coefficients(phase 2)
127
	unpcklps2 xmm6,xmm0		; xmm6=(00 10 20 30)=data0
128
	unpckhps2 xmm7,xmm0		; xmm7=(01 11 21 31)=data1
129
	movaps    xmm3,xmm2		; transpose coefficients(phase 2)
130
	unpcklps2 xmm2,xmm5		; xmm2=(06 16 26 36)=data6
131
	unpckhps2 xmm3,xmm5		; xmm3=(07 17 27 37)=data7
132
133
	movaps	xmm0,xmm7
134
	movaps	xmm5,xmm6
135
	subps	xmm7,xmm2		; xmm7=data1-data6=tmp6
136
	subps	xmm6,xmm3		; xmm6=data0-data7=tmp7
137
	addps	xmm0,xmm2		; xmm0=data1+data6=tmp1
138
	addps	xmm5,xmm3		; xmm5=data0+data7=tmp0
139
140
	movaps	xmm2, XMMWORD [wk(0)]	; xmm2=(22 32 23 33)
141
	movaps	xmm3, XMMWORD [wk(1)]	; xmm3=(24 34 25 35)
142
	movaps	XMMWORD [wk(0)], xmm7	; wk(0)=tmp6
143
	movaps	XMMWORD [wk(1)], xmm6	; wk(1)=tmp7
144
145
	movaps    xmm7,xmm4		; transpose coefficients(phase 2)
146
	unpcklps2 xmm4,xmm2		; xmm4=(02 12 22 32)=data2
147
	unpckhps2 xmm7,xmm2		; xmm7=(03 13 23 33)=data3
148
	movaps    xmm6,xmm1		; transpose coefficients(phase 2)
149
	unpcklps2 xmm1,xmm3		; xmm1=(04 14 24 34)=data4
150
	unpckhps2 xmm6,xmm3		; xmm6=(05 15 25 35)=data5
151
152
	movaps	xmm2,xmm7
153
	movaps	xmm3,xmm4
154
	addps	xmm7,xmm1		; xmm7=data3+data4=tmp3
155
	addps	xmm4,xmm6		; xmm4=data2+data5=tmp2
156
	subps	xmm2,xmm1		; xmm2=data3-data4=tmp4
157
	subps	xmm3,xmm6		; xmm3=data2-data5=tmp5
158
159
	; -- Even part
160
161
	movaps	xmm1,xmm5
162
	movaps	xmm6,xmm0
163
	subps	xmm5,xmm7		; xmm5=tmp13
164
	subps	xmm0,xmm4		; xmm0=tmp12
165
	addps	xmm1,xmm7		; xmm1=tmp10
166
	addps	xmm6,xmm4		; xmm6=tmp11
167
168
	addps	xmm0,xmm5
169
	mulps	xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1
170
171
	movaps	xmm7,xmm1
172
	movaps	xmm4,xmm5
173
	subps	xmm1,xmm6		; xmm1=data4
174
	subps	xmm5,xmm0		; xmm5=data6
175
	addps	xmm7,xmm6		; xmm7=data0
176
	addps	xmm4,xmm0		; xmm4=data2
177
178
	movaps	XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)], xmm1
179
	movaps	XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)], xmm5
180
	movaps	XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7
181
	movaps	XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4
182
183
	; -- Odd part
184
185
	movaps	xmm6, XMMWORD [wk(0)]	; xmm6=tmp6
186
	movaps	xmm0, XMMWORD [wk(1)]	; xmm0=tmp7
187
188
	addps	xmm2,xmm3		; xmm2=tmp10
189
	addps	xmm3,xmm6		; xmm3=tmp11
190
	addps	xmm6,xmm0		; xmm6=tmp12, xmm0=tmp7
191
192
	mulps	xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3
193
194
	movaps	xmm1,xmm2		; xmm1=tmp10
195
	subps	xmm2,xmm6
196
	mulps	xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5
197
	mulps	xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196)
198
	mulps	xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562)
199
	addps	xmm1,xmm2		; xmm1=z2
200
	addps	xmm6,xmm2		; xmm6=z4
201
202
	movaps	xmm5,xmm0
203
	subps	xmm0,xmm3		; xmm0=z13
204
	addps	xmm5,xmm3		; xmm5=z11
205
206
	movaps	xmm7,xmm0
207
	movaps	xmm4,xmm5
208
	subps	xmm0,xmm1		; xmm0=data3
209
	subps	xmm5,xmm6		; xmm5=data7
210
	addps	xmm7,xmm1		; xmm7=data5
211
	addps	xmm4,xmm6		; xmm4=data1
212
213
	movaps	XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0
214
	movaps	XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)], xmm5
215
	movaps	XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)], xmm7
216
	movaps	XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4
217
218
	add	edx, 4*DCTSIZE*SIZEOF_FAST_FLOAT
219
	dec	ecx
220
	jnz	near .rowloop
221
222
	; ---- Pass 2: process columns.
223
224
	mov	edx, POINTER [data(eax)]	; (FAST_FLOAT *)
225
	mov	ecx, DCTSIZE/4
226
	alignx	16,7
227
.columnloop:
228
229
	movaps	xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)]
230
	movaps	xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)]
231
	movaps	xmm2, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)]
232
	movaps	xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)]
233
234
	; xmm0=(02 12 22 32), xmm2=(42 52 62 72)
235
	; xmm1=(03 13 23 33), xmm3=(43 53 63 73)
236
237
	movaps   xmm4,xmm0		; transpose coefficients(phase 1)
238
	unpcklps xmm0,xmm1		; xmm0=(02 03 12 13)
239
	unpckhps xmm4,xmm1		; xmm4=(22 23 32 33)
240
	movaps   xmm5,xmm2		; transpose coefficients(phase 1)
241
	unpcklps xmm2,xmm3		; xmm2=(42 43 52 53)
242
	unpckhps xmm5,xmm3		; xmm5=(62 63 72 73)
243
244
	movaps	xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
245
	movaps	xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
246
	movaps	xmm1, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)]
247
	movaps	xmm3, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)]
248
249
	; xmm6=(00 10 20 30), xmm1=(40 50 60 70)
250
	; xmm7=(01 11 21 31), xmm3=(41 51 61 71)
251
252
	movaps	XMMWORD [wk(0)], xmm4	; wk(0)=(22 23 32 33)
253
	movaps	XMMWORD [wk(1)], xmm2	; wk(1)=(42 43 52 53)
254
255
	movaps   xmm4,xmm6		; transpose coefficients(phase 1)
256
	unpcklps xmm6,xmm7		; xmm6=(00 01 10 11)
257
	unpckhps xmm4,xmm7		; xmm4=(20 21 30 31)
258
	movaps   xmm2,xmm1		; transpose coefficients(phase 1)
259
	unpcklps xmm1,xmm3		; xmm1=(40 41 50 51)
260
	unpckhps xmm2,xmm3		; xmm2=(60 61 70 71)
261
262
	movaps    xmm7,xmm6		; transpose coefficients(phase 2)
263
	unpcklps2 xmm6,xmm0		; xmm6=(00 01 02 03)=data0
264
	unpckhps2 xmm7,xmm0		; xmm7=(10 11 12 13)=data1
265
	movaps    xmm3,xmm2		; transpose coefficients(phase 2)
266
	unpcklps2 xmm2,xmm5		; xmm2=(60 61 62 63)=data6
267
	unpckhps2 xmm3,xmm5		; xmm3=(70 71 72 73)=data7
268
269
	movaps	xmm0,xmm7
270
	movaps	xmm5,xmm6
271
	subps	xmm7,xmm2		; xmm7=data1-data6=tmp6
272
	subps	xmm6,xmm3		; xmm6=data0-data7=tmp7
273
	addps	xmm0,xmm2		; xmm0=data1+data6=tmp1
274
	addps	xmm5,xmm3		; xmm5=data0+data7=tmp0
275
276
	movaps	xmm2, XMMWORD [wk(0)]	; xmm2=(22 23 32 33)
277
	movaps	xmm3, XMMWORD [wk(1)]	; xmm3=(42 43 52 53)
278
	movaps	XMMWORD [wk(0)], xmm7	; wk(0)=tmp6
279
	movaps	XMMWORD [wk(1)], xmm6	; wk(1)=tmp7
280
281
	movaps    xmm7,xmm4		; transpose coefficients(phase 2)
282
	unpcklps2 xmm4,xmm2		; xmm4=(20 21 22 23)=data2
283
	unpckhps2 xmm7,xmm2		; xmm7=(30 31 32 33)=data3
284
	movaps    xmm6,xmm1		; transpose coefficients(phase 2)
285
	unpcklps2 xmm1,xmm3		; xmm1=(40 41 42 43)=data4
286
	unpckhps2 xmm6,xmm3		; xmm6=(50 51 52 53)=data5
287
288
	movaps	xmm2,xmm7
289
	movaps	xmm3,xmm4
290
	addps	xmm7,xmm1		; xmm7=data3+data4=tmp3
291
	addps	xmm4,xmm6		; xmm4=data2+data5=tmp2
292
	subps	xmm2,xmm1		; xmm2=data3-data4=tmp4
293
	subps	xmm3,xmm6		; xmm3=data2-data5=tmp5
294
295
	; -- Even part
296
297
	movaps	xmm1,xmm5
298
	movaps	xmm6,xmm0
299
	subps	xmm5,xmm7		; xmm5=tmp13
300
	subps	xmm0,xmm4		; xmm0=tmp12
301
	addps	xmm1,xmm7		; xmm1=tmp10
302
	addps	xmm6,xmm4		; xmm6=tmp11
303
304
	addps	xmm0,xmm5
305
	mulps	xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1
306
307
	movaps	xmm7,xmm1
308
	movaps	xmm4,xmm5
309
	subps	xmm1,xmm6		; xmm1=data4
310
	subps	xmm5,xmm0		; xmm5=data6
311
	addps	xmm7,xmm6		; xmm7=data0
312
	addps	xmm4,xmm0		; xmm4=data2
313
314
	movaps	XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)], xmm1
315
	movaps	XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)], xmm5
316
	movaps	XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7
317
	movaps	XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4
318
319
	; -- Odd part
320
321
	movaps	xmm6, XMMWORD [wk(0)]	; xmm6=tmp6
322
	movaps	xmm0, XMMWORD [wk(1)]	; xmm0=tmp7
323
324
	addps	xmm2,xmm3		; xmm2=tmp10
325
	addps	xmm3,xmm6		; xmm3=tmp11
326
	addps	xmm6,xmm0		; xmm6=tmp12, xmm0=tmp7
327
328
	mulps	xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3
329
330
	movaps	xmm1,xmm2		; xmm1=tmp10
331
	subps	xmm2,xmm6
332
	mulps	xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5
333
	mulps	xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196)
334
	mulps	xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562)
335
	addps	xmm1,xmm2		; xmm1=z2
336
	addps	xmm6,xmm2		; xmm6=z4
337
338
	movaps	xmm5,xmm0
339
	subps	xmm0,xmm3		; xmm0=z13
340
	addps	xmm5,xmm3		; xmm5=z11
341
342
	movaps	xmm7,xmm0
343
	movaps	xmm4,xmm5
344
	subps	xmm0,xmm1		; xmm0=data3
345
	subps	xmm5,xmm6		; xmm5=data7
346
	addps	xmm7,xmm1		; xmm7=data5
347
	addps	xmm4,xmm6		; xmm4=data1
348
349
	movaps	XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0
350
	movaps	XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)], xmm5
351
	movaps	XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)], xmm7
352
	movaps	XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4
353
354
	add	edx, byte 4*SIZEOF_FAST_FLOAT
355
	dec	ecx
356
	jnz	near .columnloop
357
358
;	pop	edi		; unused
359
;	pop	esi		; unused
360
;	pop	edx		; need not be preserved
361
;	pop	ecx		; need not be preserved
362
	poppic	ebx
363
	mov	esp,ebp		; esp <- aligned ebp
364
	pop	esp		; esp <- original ebp
365
	pop	ebp
366
	ret
367
368
; For some reason, the OS X linker does not honor the request to align the
369
; segment unless we do this.
370
	align	16
(-)a/jpeg/simd/ji3dnflt.asm (+452 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; ji3dnflt.asm - floating-point IDCT (3DNow! & MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a floating-point implementation of the inverse DCT
18
; (Discrete Cosine Transform). The following code is based directly on
19
; the IJG's original jidctflt.c; see the jidctflt.c for more details.
20
;
21
; [TAB8]
22
23
%include "jsimdext.inc"
24
%include "jdct.inc"
25
26
; --------------------------------------------------------------------------
27
	SECTION	SEG_CONST
28
29
	alignz	16
30
	global	EXTN(jconst_idct_float_3dnow)
31
32
EXTN(jconst_idct_float_3dnow):
33
34
PD_1_414	times 2 dd  1.414213562373095048801689
35
PD_1_847	times 2 dd  1.847759065022573512256366
36
PD_1_082	times 2 dd  1.082392200292393968799446
37
PD_2_613	times 2 dd  2.613125929752753055713286
38
PD_RNDINT_MAGIC	times 2 dd  100663296.0	; (float)(0x00C00000 << 3)
39
PB_CENTERJSAMP	times 8 db  CENTERJSAMPLE
40
41
	alignz	16
42
43
; --------------------------------------------------------------------------
44
	SECTION	SEG_TEXT
45
	BITS	32
46
;
47
; Perform dequantization and inverse DCT on one block of coefficients.
48
;
49
; GLOBAL(void)
50
; jsimd_idct_float_3dnow (void * dct_table, JCOEFPTR coef_block,
51
;                         JSAMPARRAY output_buf, JDIMENSION output_col)
52
;
53
54
%define dct_table(b)	(b)+8			; void * dct_table
55
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
56
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
57
%define output_col(b)	(b)+20		; JDIMENSION output_col
58
59
%define original_ebp	ebp+0
60
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
61
%define WK_NUM		2
62
%define workspace	wk(0)-DCTSIZE2*SIZEOF_FAST_FLOAT
63
					; FAST_FLOAT workspace[DCTSIZE2]
64
65
	align	16
66
	global	EXTN(jsimd_idct_float_3dnow)
67
68
EXTN(jsimd_idct_float_3dnow):
69
	push	ebp
70
	mov	eax,esp				; eax = original ebp
71
	sub	esp, byte 4
72
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
73
	mov	[esp],eax
74
	mov	ebp,esp				; ebp = aligned ebp
75
	lea	esp, [workspace]
76
	push	ebx
77
;	push	ecx		; need not be preserved
78
;	push	edx		; need not be preserved
79
	push	esi
80
	push	edi
81
82
	get_GOT	ebx		; get GOT address
83
84
	; ---- Pass 1: process columns from input, store into work array.
85
86
;	mov	eax, [original_ebp]
87
	mov	edx, POINTER [dct_table(eax)]	; quantptr
88
	mov	esi, JCOEFPTR [coef_block(eax)]		; inptr
89
	lea	edi, [workspace]			; FAST_FLOAT * wsptr
90
	mov	ecx, DCTSIZE/2				; ctr
91
	alignx	16,7
92
.columnloop:
93
%ifndef NO_ZERO_COLUMN_TEST_FLOAT_3DNOW
94
	mov	eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
95
	or	eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
96
	jnz	short .columnDCT
97
98
	pushpic	ebx		; save GOT address
99
	mov	ebx, DWORD [DWBLOCK(3,0,esi,SIZEOF_JCOEF)]
100
	mov	eax, DWORD [DWBLOCK(4,0,esi,SIZEOF_JCOEF)]
101
	or	ebx, DWORD [DWBLOCK(5,0,esi,SIZEOF_JCOEF)]
102
	or	eax, DWORD [DWBLOCK(6,0,esi,SIZEOF_JCOEF)]
103
	or	ebx, DWORD [DWBLOCK(7,0,esi,SIZEOF_JCOEF)]
104
	or	eax,ebx
105
	poppic	ebx		; restore GOT address
106
	jnz	short .columnDCT
107
108
	; -- AC terms all zero
109
110
	movd      mm0, DWORD [DWBLOCK(0,0,esi,SIZEOF_JCOEF)]
111
112
	punpcklwd mm0,mm0
113
	psrad     mm0,(DWORD_BIT-WORD_BIT)
114
	pi2fd     mm0,mm0
115
116
	pfmul     mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
117
118
	movq      mm1,mm0
119
	punpckldq mm0,mm0
120
	punpckhdq mm1,mm1
121
122
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], mm0
123
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], mm0
124
	movq	MMWORD [MMBLOCK(0,2,edi,SIZEOF_FAST_FLOAT)], mm0
125
	movq	MMWORD [MMBLOCK(0,3,edi,SIZEOF_FAST_FLOAT)], mm0
126
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], mm1
127
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], mm1
128
	movq	MMWORD [MMBLOCK(1,2,edi,SIZEOF_FAST_FLOAT)], mm1
129
	movq	MMWORD [MMBLOCK(1,3,edi,SIZEOF_FAST_FLOAT)], mm1
130
	jmp	near .nextcolumn
131
	alignx	16,7
132
%endif
133
.columnDCT:
134
135
	; -- Even part
136
137
	movd      mm0, DWORD [DWBLOCK(0,0,esi,SIZEOF_JCOEF)]
138
	movd      mm1, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
139
	movd      mm2, DWORD [DWBLOCK(4,0,esi,SIZEOF_JCOEF)]
140
	movd      mm3, DWORD [DWBLOCK(6,0,esi,SIZEOF_JCOEF)]
141
142
	punpcklwd mm0,mm0
143
	punpcklwd mm1,mm1
144
	psrad     mm0,(DWORD_BIT-WORD_BIT)
145
	psrad     mm1,(DWORD_BIT-WORD_BIT)
146
	pi2fd     mm0,mm0
147
	pi2fd     mm1,mm1
148
149
	pfmul     mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
150
	pfmul     mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
151
152
	punpcklwd mm2,mm2
153
	punpcklwd mm3,mm3
154
	psrad     mm2,(DWORD_BIT-WORD_BIT)
155
	psrad     mm3,(DWORD_BIT-WORD_BIT)
156
	pi2fd     mm2,mm2
157
	pi2fd     mm3,mm3
158
159
	pfmul     mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
160
	pfmul     mm3, MMWORD [MMBLOCK(6,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
161
162
	movq	mm4,mm0
163
	movq	mm5,mm1
164
	pfsub	mm0,mm2			; mm0=tmp11
165
	pfsub	mm1,mm3
166
	pfadd	mm4,mm2			; mm4=tmp10
167
	pfadd	mm5,mm3			; mm5=tmp13
168
169
	pfmul	mm1,[GOTOFF(ebx,PD_1_414)]
170
	pfsub	mm1,mm5			; mm1=tmp12
171
172
	movq	mm6,mm4
173
	movq	mm7,mm0
174
	pfsub	mm4,mm5			; mm4=tmp3
175
	pfsub	mm0,mm1			; mm0=tmp2
176
	pfadd	mm6,mm5			; mm6=tmp0
177
	pfadd	mm7,mm1			; mm7=tmp1
178
179
	movq	MMWORD [wk(1)], mm4	; tmp3
180
	movq	MMWORD [wk(0)], mm0	; tmp2
181
182
	; -- Odd part
183
184
	movd      mm2, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
185
	movd      mm3, DWORD [DWBLOCK(3,0,esi,SIZEOF_JCOEF)]
186
	movd      mm5, DWORD [DWBLOCK(5,0,esi,SIZEOF_JCOEF)]
187
	movd      mm1, DWORD [DWBLOCK(7,0,esi,SIZEOF_JCOEF)]
188
189
	punpcklwd mm2,mm2
190
	punpcklwd mm3,mm3
191
	psrad     mm2,(DWORD_BIT-WORD_BIT)
192
	psrad     mm3,(DWORD_BIT-WORD_BIT)
193
	pi2fd     mm2,mm2
194
	pi2fd     mm3,mm3
195
196
	pfmul     mm2, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
197
	pfmul     mm3, MMWORD [MMBLOCK(3,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
198
199
	punpcklwd mm5,mm5
200
	punpcklwd mm1,mm1
201
	psrad     mm5,(DWORD_BIT-WORD_BIT)
202
	psrad     mm1,(DWORD_BIT-WORD_BIT)
203
	pi2fd     mm5,mm5
204
	pi2fd     mm1,mm1
205
206
	pfmul     mm5, MMWORD [MMBLOCK(5,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
207
	pfmul     mm1, MMWORD [MMBLOCK(7,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
208
209
	movq	mm4,mm2
210
	movq	mm0,mm5
211
	pfadd	mm2,mm1			; mm2=z11
212
	pfadd	mm5,mm3			; mm5=z13
213
	pfsub	mm4,mm1			; mm4=z12
214
	pfsub	mm0,mm3			; mm0=z10
215
216
	movq	mm1,mm2
217
	pfsub	mm2,mm5
218
	pfadd	mm1,mm5			; mm1=tmp7
219
220
	pfmul	mm2,[GOTOFF(ebx,PD_1_414)]	; mm2=tmp11
221
222
	movq	mm3,mm0
223
	pfadd	mm0,mm4
224
	pfmul	mm0,[GOTOFF(ebx,PD_1_847)]	; mm0=z5
225
	pfmul	mm3,[GOTOFF(ebx,PD_2_613)]	; mm3=(z10 * 2.613125930)
226
	pfmul	mm4,[GOTOFF(ebx,PD_1_082)]	; mm4=(z12 * 1.082392200)
227
	pfsubr	mm3,mm0			; mm3=tmp12
228
	pfsub	mm4,mm0			; mm4=tmp10
229
230
	; -- Final output stage
231
232
	pfsub	mm3,mm1			; mm3=tmp6
233
	movq	mm5,mm6
234
	movq	mm0,mm7
235
	pfadd	mm6,mm1			; mm6=data0=(00 01)
236
	pfadd	mm7,mm3			; mm7=data1=(10 11)
237
	pfsub	mm5,mm1			; mm5=data7=(70 71)
238
	pfsub	mm0,mm3			; mm0=data6=(60 61)
239
	pfsub	mm2,mm3			; mm2=tmp5
240
241
	movq      mm1,mm6		; transpose coefficients
242
	punpckldq mm6,mm7		; mm6=(00 10)
243
	punpckhdq mm1,mm7		; mm1=(01 11)
244
	movq      mm3,mm0		; transpose coefficients
245
	punpckldq mm0,mm5		; mm0=(60 70)
246
	punpckhdq mm3,mm5		; mm3=(61 71)
247
248
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], mm6
249
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], mm1
250
	movq	MMWORD [MMBLOCK(0,3,edi,SIZEOF_FAST_FLOAT)], mm0
251
	movq	MMWORD [MMBLOCK(1,3,edi,SIZEOF_FAST_FLOAT)], mm3
252
253
	movq	mm7, MMWORD [wk(0)]	; mm7=tmp2
254
	movq	mm5, MMWORD [wk(1)]	; mm5=tmp3
255
256
	pfadd	mm4,mm2			; mm4=tmp4
257
	movq	mm6,mm7
258
	movq	mm1,mm5
259
	pfadd	mm7,mm2			; mm7=data2=(20 21)
260
	pfadd	mm5,mm4			; mm5=data4=(40 41)
261
	pfsub	mm6,mm2			; mm6=data5=(50 51)
262
	pfsub	mm1,mm4			; mm1=data3=(30 31)
263
264
	movq      mm0,mm7		; transpose coefficients
265
	punpckldq mm7,mm1		; mm7=(20 30)
266
	punpckhdq mm0,mm1		; mm0=(21 31)
267
	movq      mm3,mm5		; transpose coefficients
268
	punpckldq mm5,mm6		; mm5=(40 50)
269
	punpckhdq mm3,mm6		; mm3=(41 51)
270
271
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], mm7
272
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], mm0
273
	movq	MMWORD [MMBLOCK(0,2,edi,SIZEOF_FAST_FLOAT)], mm5
274
	movq	MMWORD [MMBLOCK(1,2,edi,SIZEOF_FAST_FLOAT)], mm3
275
276
.nextcolumn:
277
	add	esi, byte 2*SIZEOF_JCOEF		; coef_block
278
	add	edx, byte 2*SIZEOF_FLOAT_MULT_TYPE	; quantptr
279
	add	edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT	; wsptr
280
	dec	ecx					; ctr
281
	jnz	near .columnloop
282
283
	; -- Prefetch the next coefficient block
284
285
	prefetch [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32]
286
	prefetch [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32]
287
	prefetch [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32]
288
	prefetch [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32]
289
290
	; ---- Pass 2: process rows from work array, store into output array.
291
292
	mov	eax, [original_ebp]
293
	lea	esi, [workspace]			; FAST_FLOAT * wsptr
294
	mov	edi, JSAMPARRAY [output_buf(eax)]	; (JSAMPROW *)
295
	mov	eax, JDIMENSION [output_col(eax)]
296
	mov	ecx, DCTSIZE/2				; ctr
297
	alignx	16,7
298
.rowloop:
299
300
	; -- Even part
301
302
	movq	mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
303
	movq	mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_FAST_FLOAT)]
304
	movq	mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_FAST_FLOAT)]
305
	movq	mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_FAST_FLOAT)]
306
307
	movq	mm4,mm0
308
	movq	mm5,mm1
309
	pfsub	mm0,mm2			; mm0=tmp11
310
	pfsub	mm1,mm3
311
	pfadd	mm4,mm2			; mm4=tmp10
312
	pfadd	mm5,mm3			; mm5=tmp13
313
314
	pfmul	mm1,[GOTOFF(ebx,PD_1_414)]
315
	pfsub	mm1,mm5			; mm1=tmp12
316
317
	movq	mm6,mm4
318
	movq	mm7,mm0
319
	pfsub	mm4,mm5			; mm4=tmp3
320
	pfsub	mm0,mm1			; mm0=tmp2
321
	pfadd	mm6,mm5			; mm6=tmp0
322
	pfadd	mm7,mm1			; mm7=tmp1
323
324
	movq	MMWORD [wk(1)], mm4	; tmp3
325
	movq	MMWORD [wk(0)], mm0	; tmp2
326
327
	; -- Odd part
328
329
	movq	mm2, MMWORD [MMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
330
	movq	mm3, MMWORD [MMBLOCK(3,0,esi,SIZEOF_FAST_FLOAT)]
331
	movq	mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_FAST_FLOAT)]
332
	movq	mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_FAST_FLOAT)]
333
334
	movq	mm4,mm2
335
	movq	mm0,mm5
336
	pfadd	mm2,mm1			; mm2=z11
337
	pfadd	mm5,mm3			; mm5=z13
338
	pfsub	mm4,mm1			; mm4=z12
339
	pfsub	mm0,mm3			; mm0=z10
340
341
	movq	mm1,mm2
342
	pfsub	mm2,mm5
343
	pfadd	mm1,mm5			; mm1=tmp7
344
345
	pfmul	mm2,[GOTOFF(ebx,PD_1_414)]	; mm2=tmp11
346
347
	movq	mm3,mm0
348
	pfadd	mm0,mm4
349
	pfmul	mm0,[GOTOFF(ebx,PD_1_847)]	; mm0=z5
350
	pfmul	mm3,[GOTOFF(ebx,PD_2_613)]	; mm3=(z10 * 2.613125930)
351
	pfmul	mm4,[GOTOFF(ebx,PD_1_082)]	; mm4=(z12 * 1.082392200)
352
	pfsubr	mm3,mm0			; mm3=tmp12
353
	pfsub	mm4,mm0			; mm4=tmp10
354
355
	; -- Final output stage
356
357
	pfsub	mm3,mm1			; mm3=tmp6
358
	movq	mm5,mm6
359
	movq	mm0,mm7
360
	pfadd	mm6,mm1			; mm6=data0=(00 10)
361
	pfadd	mm7,mm3			; mm7=data1=(01 11)
362
	pfsub	mm5,mm1			; mm5=data7=(07 17)
363
	pfsub	mm0,mm3			; mm0=data6=(06 16)
364
	pfsub	mm2,mm3			; mm2=tmp5
365
366
	movq	mm1,[GOTOFF(ebx,PD_RNDINT_MAGIC)]	; mm1=[PD_RNDINT_MAGIC]
367
	pcmpeqd	mm3,mm3
368
	psrld	mm3,WORD_BIT		; mm3={0xFFFF 0x0000 0xFFFF 0x0000}
369
370
	pfadd	mm6,mm1			; mm6=roundint(data0/8)=(00 ** 10 **)
371
	pfadd	mm7,mm1			; mm7=roundint(data1/8)=(01 ** 11 **)
372
	pfadd	mm0,mm1			; mm0=roundint(data6/8)=(06 ** 16 **)
373
	pfadd	mm5,mm1			; mm5=roundint(data7/8)=(07 ** 17 **)
374
375
	pand	mm6,mm3			; mm6=(00 -- 10 --)
376
	pslld	mm7,WORD_BIT		; mm7=(-- 01 -- 11)
377
	pand	mm0,mm3			; mm0=(06 -- 16 --)
378
	pslld	mm5,WORD_BIT		; mm5=(-- 07 -- 17)
379
	por	mm6,mm7			; mm6=(00 01 10 11)
380
	por	mm0,mm5			; mm0=(06 07 16 17)
381
382
	movq	mm1, MMWORD [wk(0)]	; mm1=tmp2
383
	movq	mm3, MMWORD [wk(1)]	; mm3=tmp3
384
385
	pfadd	mm4,mm2			; mm4=tmp4
386
	movq	mm7,mm1
387
	movq	mm5,mm3
388
	pfadd	mm1,mm2			; mm1=data2=(02 12)
389
	pfadd	mm3,mm4			; mm3=data4=(04 14)
390
	pfsub	mm7,mm2			; mm7=data5=(05 15)
391
	pfsub	mm5,mm4			; mm5=data3=(03 13)
392
393
	movq	mm2,[GOTOFF(ebx,PD_RNDINT_MAGIC)]	; mm2=[PD_RNDINT_MAGIC]
394
	pcmpeqd	mm4,mm4
395
	psrld	mm4,WORD_BIT		; mm4={0xFFFF 0x0000 0xFFFF 0x0000}
396
397
	pfadd	mm3,mm2			; mm3=roundint(data4/8)=(04 ** 14 **)
398
	pfadd	mm7,mm2			; mm7=roundint(data5/8)=(05 ** 15 **)
399
	pfadd	mm1,mm2			; mm1=roundint(data2/8)=(02 ** 12 **)
400
	pfadd	mm5,mm2			; mm5=roundint(data3/8)=(03 ** 13 **)
401
402
	pand	mm3,mm4			; mm3=(04 -- 14 --)
403
	pslld	mm7,WORD_BIT		; mm7=(-- 05 -- 15)
404
	pand	mm1,mm4			; mm1=(02 -- 12 --)
405
	pslld	mm5,WORD_BIT		; mm5=(-- 03 -- 13)
406
	por	mm3,mm7			; mm3=(04 05 14 15)
407
	por	mm1,mm5			; mm1=(02 03 12 13)
408
409
	movq      mm2,[GOTOFF(ebx,PB_CENTERJSAMP)]	; mm2=[PB_CENTERJSAMP]
410
411
	packsswb  mm6,mm3		; mm6=(00 01 10 11 04 05 14 15)
412
	packsswb  mm1,mm0		; mm1=(02 03 12 13 06 07 16 17)
413
	paddb     mm6,mm2
414
	paddb     mm1,mm2
415
416
	movq      mm4,mm6		; transpose coefficients(phase 2)
417
	punpcklwd mm6,mm1		; mm6=(00 01 02 03 10 11 12 13)
418
	punpckhwd mm4,mm1		; mm4=(04 05 06 07 14 15 16 17)
419
420
	movq      mm7,mm6		; transpose coefficients(phase 3)
421
	punpckldq mm6,mm4		; mm6=(00 01 02 03 04 05 06 07)
422
	punpckhdq mm7,mm4		; mm7=(10 11 12 13 14 15 16 17)
423
424
	pushpic	ebx			; save GOT address
425
426
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
427
	mov	ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
428
	movq	MMWORD [edx+eax*SIZEOF_JSAMPLE], mm6
429
	movq	MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm7
430
431
	poppic	ebx			; restore GOT address
432
433
	add	esi, byte 2*SIZEOF_FAST_FLOAT	; wsptr
434
	add	edi, byte 2*SIZEOF_JSAMPROW
435
	dec	ecx				; ctr
436
	jnz	near .rowloop
437
438
	femms		; empty MMX/3DNow! state
439
440
	pop	edi
441
	pop	esi
442
;	pop	edx		; need not be preserved
443
;	pop	ecx		; need not be preserved
444
	pop	ebx
445
	mov	esp,ebp		; esp <- aligned ebp
446
	pop	esp		; esp <- original ebp
447
	pop	ebp
448
	ret
449
450
; For some reason, the OS X linker does not honor the request to align the
451
; segment unless we do this.
452
	align	16
(-)a/jpeg/simd/jimmxfst.asm (+500 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jimmxfst.asm - fast integer IDCT (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a fast, not so accurate integer implementation of
18
; the inverse DCT (Discrete Cosine Transform). The following code is
19
; based directly on the IJG's original jidctfst.c; see the jidctfst.c
20
; for more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	8	; 14 is also OK.
30
%define PASS1_BITS	2
31
32
%if IFAST_SCALE_BITS != PASS1_BITS
33
%error "'IFAST_SCALE_BITS' must be equal to 'PASS1_BITS'."
34
%endif
35
36
%if CONST_BITS == 8
37
F_1_082	equ	277		; FIX(1.082392200)
38
F_1_414	equ	362		; FIX(1.414213562)
39
F_1_847	equ	473		; FIX(1.847759065)
40
F_2_613	equ	669		; FIX(2.613125930)
41
F_1_613	equ	(F_2_613 - 256)	; FIX(2.613125930) - FIX(1)
42
%else
43
; NASM cannot do compile-time arithmetic on floating-point constants.
44
%define	DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
45
F_1_082	equ	DESCALE(1162209775,30-CONST_BITS)	; FIX(1.082392200)
46
F_1_414	equ	DESCALE(1518500249,30-CONST_BITS)	; FIX(1.414213562)
47
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
48
F_2_613	equ	DESCALE(2805822602,30-CONST_BITS)	; FIX(2.613125930)
49
F_1_613	equ	(F_2_613 - (1 << CONST_BITS))	; FIX(2.613125930) - FIX(1)
50
%endif
51
52
; --------------------------------------------------------------------------
53
	SECTION	SEG_CONST
54
55
; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
56
; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
57
58
%define PRE_MULTIPLY_SCALE_BITS   2
59
%define CONST_SHIFT     (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
60
61
	alignz	16
62
	global	EXTN(jconst_idct_ifast_mmx)
63
64
EXTN(jconst_idct_ifast_mmx):
65
66
PW_F1414	times 4 dw  F_1_414 << CONST_SHIFT
67
PW_F1847	times 4 dw  F_1_847 << CONST_SHIFT
68
PW_MF1613	times 4 dw -F_1_613 << CONST_SHIFT
69
PW_F1082	times 4 dw  F_1_082 << CONST_SHIFT
70
PB_CENTERJSAMP	times 8 db  CENTERJSAMPLE
71
72
	alignz	16
73
74
; --------------------------------------------------------------------------
75
	SECTION	SEG_TEXT
76
	BITS	32
77
;
78
; Perform dequantization and inverse DCT on one block of coefficients.
79
;
80
; GLOBAL(void)
81
; jsimd_idct_ifast_mmx (void * dct_table, JCOEFPTR coef_block,
82
;                       JSAMPARRAY output_buf, JDIMENSION output_col)
83
;
84
85
%define dct_table(b)	(b)+8			; jpeg_component_info * compptr
86
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
87
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
88
%define output_col(b)	(b)+20		; JDIMENSION output_col
89
90
%define original_ebp	ebp+0
91
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
92
%define WK_NUM		2
93
%define workspace	wk(0)-DCTSIZE2*SIZEOF_JCOEF
94
					; JCOEF workspace[DCTSIZE2]
95
96
	align	16
97
	global	EXTN(jsimd_idct_ifast_mmx)
98
99
EXTN(jsimd_idct_ifast_mmx):
100
	push	ebp
101
	mov	eax,esp				; eax = original ebp
102
	sub	esp, byte 4
103
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
104
	mov	[esp],eax
105
	mov	ebp,esp				; ebp = aligned ebp
106
	lea	esp, [workspace]
107
	push	ebx
108
;	push	ecx		; need not be preserved
109
;	push	edx		; need not be preserved
110
	push	esi
111
	push	edi
112
113
	get_GOT	ebx		; get GOT address
114
115
	; ---- Pass 1: process columns from input, store into work array.
116
117
;	mov	eax, [original_ebp]
118
	mov	edx, POINTER [dct_table(eax)]	; quantptr
119
	mov	esi, JCOEFPTR [coef_block(eax)]		; inptr
120
	lea	edi, [workspace]			; JCOEF * wsptr
121
	mov	ecx, DCTSIZE/4				; ctr
122
	alignx	16,7
123
.columnloop:
124
%ifndef NO_ZERO_COLUMN_TEST_IFAST_MMX
125
	mov	eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
126
	or	eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
127
	jnz	short .columnDCT
128
129
	movq	mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
130
	movq	mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
131
	por	mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
132
	por	mm1, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
133
	por	mm0, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
134
	por	mm1, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
135
	por	mm0, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
136
	por	mm1,mm0
137
	packsswb mm1,mm1
138
	movd	eax,mm1
139
	test	eax,eax
140
	jnz	short .columnDCT
141
142
	; -- AC terms all zero
143
144
	movq	mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
145
	pmullw	mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_IFAST_MULT_TYPE)]
146
147
	movq      mm2,mm0		; mm0=in0=(00 01 02 03)
148
	punpcklwd mm0,mm0		; mm0=(00 00 01 01)
149
	punpckhwd mm2,mm2		; mm2=(02 02 03 03)
150
151
	movq      mm1,mm0
152
	punpckldq mm0,mm0		; mm0=(00 00 00 00)
153
	punpckhdq mm1,mm1		; mm1=(01 01 01 01)
154
	movq      mm3,mm2
155
	punpckldq mm2,mm2		; mm2=(02 02 02 02)
156
	punpckhdq mm3,mm3		; mm3=(03 03 03 03)
157
158
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
159
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm0
160
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1
161
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm1
162
	movq	MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2
163
	movq	MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm2
164
	movq	MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3
165
	movq	MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm3
166
	jmp	near .nextcolumn
167
	alignx	16,7
168
%endif
169
.columnDCT:
170
171
	; -- Even part
172
173
	movq	mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
174
	movq	mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
175
	pmullw	mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_IFAST_MULT_TYPE)]
176
	pmullw	mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_IFAST_MULT_TYPE)]
177
	movq	mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
178
	movq	mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
179
	pmullw	mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_IFAST_MULT_TYPE)]
180
	pmullw	mm3, MMWORD [MMBLOCK(6,0,edx,SIZEOF_IFAST_MULT_TYPE)]
181
182
	movq	mm4,mm0
183
	movq	mm5,mm1
184
	psubw	mm0,mm2			; mm0=tmp11
185
	psubw	mm1,mm3
186
	paddw	mm4,mm2			; mm4=tmp10
187
	paddw	mm5,mm3			; mm5=tmp13
188
189
	psllw	mm1,PRE_MULTIPLY_SCALE_BITS
190
	pmulhw	mm1,[GOTOFF(ebx,PW_F1414)]
191
	psubw	mm1,mm5			; mm1=tmp12
192
193
	movq	mm6,mm4
194
	movq	mm7,mm0
195
	psubw	mm4,mm5			; mm4=tmp3
196
	psubw	mm0,mm1			; mm0=tmp2
197
	paddw	mm6,mm5			; mm6=tmp0
198
	paddw	mm7,mm1			; mm7=tmp1
199
200
	movq	MMWORD [wk(1)], mm4	; wk(1)=tmp3
201
	movq	MMWORD [wk(0)], mm0	; wk(0)=tmp2
202
203
	; -- Odd part
204
205
	movq	mm2, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
206
	movq	mm3, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
207
	pmullw	mm2, MMWORD [MMBLOCK(1,0,edx,SIZEOF_IFAST_MULT_TYPE)]
208
	pmullw	mm3, MMWORD [MMBLOCK(3,0,edx,SIZEOF_IFAST_MULT_TYPE)]
209
	movq	mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
210
	movq	mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
211
	pmullw	mm5, MMWORD [MMBLOCK(5,0,edx,SIZEOF_IFAST_MULT_TYPE)]
212
	pmullw	mm1, MMWORD [MMBLOCK(7,0,edx,SIZEOF_IFAST_MULT_TYPE)]
213
214
	movq	mm4,mm2
215
	movq	mm0,mm5
216
	psubw	mm2,mm1			; mm2=z12
217
	psubw	mm5,mm3			; mm5=z10
218
	paddw	mm4,mm1			; mm4=z11
219
	paddw	mm0,mm3			; mm0=z13
220
221
	movq	mm1,mm5			; mm1=z10(unscaled)
222
	psllw	mm2,PRE_MULTIPLY_SCALE_BITS
223
	psllw	mm5,PRE_MULTIPLY_SCALE_BITS
224
225
	movq	mm3,mm4
226
	psubw	mm4,mm0
227
	paddw	mm3,mm0			; mm3=tmp7
228
229
	psllw	mm4,PRE_MULTIPLY_SCALE_BITS
230
	pmulhw	mm4,[GOTOFF(ebx,PW_F1414)]	; mm4=tmp11
231
232
	; To avoid overflow...
233
	;
234
	; (Original)
235
	; tmp12 = -2.613125930 * z10 + z5;
236
	;
237
	; (This implementation)
238
	; tmp12 = (-1.613125930 - 1) * z10 + z5;
239
	;       = -1.613125930 * z10 - z10 + z5;
240
241
	movq	mm0,mm5
242
	paddw	mm5,mm2
243
	pmulhw	mm5,[GOTOFF(ebx,PW_F1847)]	; mm5=z5
244
	pmulhw	mm0,[GOTOFF(ebx,PW_MF1613)]
245
	pmulhw	mm2,[GOTOFF(ebx,PW_F1082)]
246
	psubw	mm0,mm1
247
	psubw	mm2,mm5			; mm2=tmp10
248
	paddw	mm0,mm5			; mm0=tmp12
249
250
	; -- Final output stage
251
252
	psubw	mm0,mm3			; mm0=tmp6
253
	movq	mm1,mm6
254
	movq	mm5,mm7
255
	paddw	mm6,mm3			; mm6=data0=(00 01 02 03)
256
	paddw	mm7,mm0			; mm7=data1=(10 11 12 13)
257
	psubw	mm1,mm3			; mm1=data7=(70 71 72 73)
258
	psubw	mm5,mm0			; mm5=data6=(60 61 62 63)
259
	psubw	mm4,mm0			; mm4=tmp5
260
261
	movq      mm3,mm6		; transpose coefficients(phase 1)
262
	punpcklwd mm6,mm7		; mm6=(00 10 01 11)
263
	punpckhwd mm3,mm7		; mm3=(02 12 03 13)
264
	movq      mm0,mm5		; transpose coefficients(phase 1)
265
	punpcklwd mm5,mm1		; mm5=(60 70 61 71)
266
	punpckhwd mm0,mm1		; mm0=(62 72 63 73)
267
268
	movq	mm7, MMWORD [wk(0)]	; mm7=tmp2
269
	movq	mm1, MMWORD [wk(1)]	; mm1=tmp3
270
271
	movq	MMWORD [wk(0)], mm5	; wk(0)=(60 70 61 71)
272
	movq	MMWORD [wk(1)], mm0	; wk(1)=(62 72 63 73)
273
274
	paddw	mm2,mm4			; mm2=tmp4
275
	movq	mm5,mm7
276
	movq	mm0,mm1
277
	paddw	mm7,mm4			; mm7=data2=(20 21 22 23)
278
	paddw	mm1,mm2			; mm1=data4=(40 41 42 43)
279
	psubw	mm5,mm4			; mm5=data5=(50 51 52 53)
280
	psubw	mm0,mm2			; mm0=data3=(30 31 32 33)
281
282
	movq      mm4,mm7		; transpose coefficients(phase 1)
283
	punpcklwd mm7,mm0		; mm7=(20 30 21 31)
284
	punpckhwd mm4,mm0		; mm4=(22 32 23 33)
285
	movq      mm2,mm1		; transpose coefficients(phase 1)
286
	punpcklwd mm1,mm5		; mm1=(40 50 41 51)
287
	punpckhwd mm2,mm5		; mm2=(42 52 43 53)
288
289
	movq      mm0,mm6		; transpose coefficients(phase 2)
290
	punpckldq mm6,mm7		; mm6=(00 10 20 30)
291
	punpckhdq mm0,mm7		; mm0=(01 11 21 31)
292
	movq      mm5,mm3		; transpose coefficients(phase 2)
293
	punpckldq mm3,mm4		; mm3=(02 12 22 32)
294
	punpckhdq mm5,mm4		; mm5=(03 13 23 33)
295
296
	movq	mm7, MMWORD [wk(0)]	; mm7=(60 70 61 71)
297
	movq	mm4, MMWORD [wk(1)]	; mm4=(62 72 63 73)
298
299
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm6
300
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm0
301
	movq	MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm3
302
	movq	MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm5
303
304
	movq      mm6,mm1		; transpose coefficients(phase 2)
305
	punpckldq mm1,mm7		; mm1=(40 50 60 70)
306
	punpckhdq mm6,mm7		; mm6=(41 51 61 71)
307
	movq      mm0,mm2		; transpose coefficients(phase 2)
308
	punpckldq mm2,mm4		; mm2=(42 52 62 72)
309
	punpckhdq mm0,mm4		; mm0=(43 53 63 73)
310
311
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm1
312
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm6
313
	movq	MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm2
314
	movq	MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm0
315
316
.nextcolumn:
317
	add	esi, byte 4*SIZEOF_JCOEF		; coef_block
318
	add	edx, byte 4*SIZEOF_IFAST_MULT_TYPE	; quantptr
319
	add	edi, byte 4*DCTSIZE*SIZEOF_JCOEF	; wsptr
320
	dec	ecx					; ctr
321
	jnz	near .columnloop
322
323
	; ---- Pass 2: process rows from work array, store into output array.
324
325
	mov	eax, [original_ebp]
326
	lea	esi, [workspace]			; JCOEF * wsptr
327
	mov	edi, JSAMPARRAY [output_buf(eax)]	; (JSAMPROW *)
328
	mov	eax, JDIMENSION [output_col(eax)]
329
	mov	ecx, DCTSIZE/4				; ctr
330
	alignx	16,7
331
.rowloop:
332
333
	; -- Even part
334
335
	movq	mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
336
	movq	mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
337
	movq	mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
338
	movq	mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
339
340
	movq	mm4,mm0
341
	movq	mm5,mm1
342
	psubw	mm0,mm2			; mm0=tmp11
343
	psubw	mm1,mm3
344
	paddw	mm4,mm2			; mm4=tmp10
345
	paddw	mm5,mm3			; mm5=tmp13
346
347
	psllw	mm1,PRE_MULTIPLY_SCALE_BITS
348
	pmulhw	mm1,[GOTOFF(ebx,PW_F1414)]
349
	psubw	mm1,mm5			; mm1=tmp12
350
351
	movq	mm6,mm4
352
	movq	mm7,mm0
353
	psubw	mm4,mm5			; mm4=tmp3
354
	psubw	mm0,mm1			; mm0=tmp2
355
	paddw	mm6,mm5			; mm6=tmp0
356
	paddw	mm7,mm1			; mm7=tmp1
357
358
	movq	MMWORD [wk(1)], mm4	; wk(1)=tmp3
359
	movq	MMWORD [wk(0)], mm0	; wk(0)=tmp2
360
361
	; -- Odd part
362
363
	movq	mm2, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
364
	movq	mm3, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
365
	movq	mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
366
	movq	mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
367
368
	movq	mm4,mm2
369
	movq	mm0,mm5
370
	psubw	mm2,mm1			; mm2=z12
371
	psubw	mm5,mm3			; mm5=z10
372
	paddw	mm4,mm1			; mm4=z11
373
	paddw	mm0,mm3			; mm0=z13
374
375
	movq	mm1,mm5			; mm1=z10(unscaled)
376
	psllw	mm2,PRE_MULTIPLY_SCALE_BITS
377
	psllw	mm5,PRE_MULTIPLY_SCALE_BITS
378
379
	movq	mm3,mm4
380
	psubw	mm4,mm0
381
	paddw	mm3,mm0			; mm3=tmp7
382
383
	psllw	mm4,PRE_MULTIPLY_SCALE_BITS
384
	pmulhw	mm4,[GOTOFF(ebx,PW_F1414)]	; mm4=tmp11
385
386
	; To avoid overflow...
387
	;
388
	; (Original)
389
	; tmp12 = -2.613125930 * z10 + z5;
390
	;
391
	; (This implementation)
392
	; tmp12 = (-1.613125930 - 1) * z10 + z5;
393
	;       = -1.613125930 * z10 - z10 + z5;
394
395
	movq	mm0,mm5
396
	paddw	mm5,mm2
397
	pmulhw	mm5,[GOTOFF(ebx,PW_F1847)]	; mm5=z5
398
	pmulhw	mm0,[GOTOFF(ebx,PW_MF1613)]
399
	pmulhw	mm2,[GOTOFF(ebx,PW_F1082)]
400
	psubw	mm0,mm1
401
	psubw	mm2,mm5			; mm2=tmp10
402
	paddw	mm0,mm5			; mm0=tmp12
403
404
	; -- Final output stage
405
406
	psubw	mm0,mm3			; mm0=tmp6
407
	movq	mm1,mm6
408
	movq	mm5,mm7
409
	paddw	mm6,mm3			; mm6=data0=(00 10 20 30)
410
	paddw	mm7,mm0			; mm7=data1=(01 11 21 31)
411
	psraw	mm6,(PASS1_BITS+3)	; descale
412
	psraw	mm7,(PASS1_BITS+3)	; descale
413
	psubw	mm1,mm3			; mm1=data7=(07 17 27 37)
414
	psubw	mm5,mm0			; mm5=data6=(06 16 26 36)
415
	psraw	mm1,(PASS1_BITS+3)	; descale
416
	psraw	mm5,(PASS1_BITS+3)	; descale
417
	psubw	mm4,mm0			; mm4=tmp5
418
419
	packsswb  mm6,mm5		; mm6=(00 10 20 30 06 16 26 36)
420
	packsswb  mm7,mm1		; mm7=(01 11 21 31 07 17 27 37)
421
422
	movq	mm3, MMWORD [wk(0)]	; mm3=tmp2
423
	movq	mm0, MMWORD [wk(1)]	; mm0=tmp3
424
425
	paddw	mm2,mm4			; mm2=tmp4
426
	movq	mm5,mm3
427
	movq	mm1,mm0
428
	paddw	mm3,mm4			; mm3=data2=(02 12 22 32)
429
	paddw	mm0,mm2			; mm0=data4=(04 14 24 34)
430
	psraw	mm3,(PASS1_BITS+3)	; descale
431
	psraw	mm0,(PASS1_BITS+3)	; descale
432
	psubw	mm5,mm4			; mm5=data5=(05 15 25 35)
433
	psubw	mm1,mm2			; mm1=data3=(03 13 23 33)
434
	psraw	mm5,(PASS1_BITS+3)	; descale
435
	psraw	mm1,(PASS1_BITS+3)	; descale
436
437
	movq      mm4,[GOTOFF(ebx,PB_CENTERJSAMP)]	; mm4=[PB_CENTERJSAMP]
438
439
	packsswb  mm3,mm0		; mm3=(02 12 22 32 04 14 24 34)
440
	packsswb  mm1,mm5		; mm1=(03 13 23 33 05 15 25 35)
441
442
	paddb     mm6,mm4
443
	paddb     mm7,mm4
444
	paddb     mm3,mm4
445
	paddb     mm1,mm4
446
447
	movq      mm2,mm6		; transpose coefficients(phase 1)
448
	punpcklbw mm6,mm7		; mm6=(00 01 10 11 20 21 30 31)
449
	punpckhbw mm2,mm7		; mm2=(06 07 16 17 26 27 36 37)
450
	movq      mm0,mm3		; transpose coefficients(phase 1)
451
	punpcklbw mm3,mm1		; mm3=(02 03 12 13 22 23 32 33)
452
	punpckhbw mm0,mm1		; mm0=(04 05 14 15 24 25 34 35)
453
454
	movq      mm5,mm6		; transpose coefficients(phase 2)
455
	punpcklwd mm6,mm3		; mm6=(00 01 02 03 10 11 12 13)
456
	punpckhwd mm5,mm3		; mm5=(20 21 22 23 30 31 32 33)
457
	movq      mm4,mm0		; transpose coefficients(phase 2)
458
	punpcklwd mm0,mm2		; mm0=(04 05 06 07 14 15 16 17)
459
	punpckhwd mm4,mm2		; mm4=(24 25 26 27 34 35 36 37)
460
461
	movq      mm7,mm6		; transpose coefficients(phase 3)
462
	punpckldq mm6,mm0		; mm6=(00 01 02 03 04 05 06 07)
463
	punpckhdq mm7,mm0		; mm7=(10 11 12 13 14 15 16 17)
464
	movq      mm1,mm5		; transpose coefficients(phase 3)
465
	punpckldq mm5,mm4		; mm5=(20 21 22 23 24 25 26 27)
466
	punpckhdq mm1,mm4		; mm1=(30 31 32 33 34 35 36 37)
467
468
	pushpic	ebx			; save GOT address
469
470
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
471
	mov	ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
472
	movq	MMWORD [edx+eax*SIZEOF_JSAMPLE], mm6
473
	movq	MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm7
474
	mov	edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
475
	mov	ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
476
	movq	MMWORD [edx+eax*SIZEOF_JSAMPLE], mm5
477
	movq	MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm1
478
479
	poppic	ebx			; restore GOT address
480
481
	add	esi, byte 4*SIZEOF_JCOEF	; wsptr
482
	add	edi, byte 4*SIZEOF_JSAMPROW
483
	dec	ecx				; ctr
484
	jnz	near .rowloop
485
486
	emms		; empty MMX state
487
488
	pop	edi
489
	pop	esi
490
;	pop	edx		; need not be preserved
491
;	pop	ecx		; need not be preserved
492
	pop	ebx
493
	mov	esp,ebp		; esp <- aligned ebp
494
	pop	esp		; esp <- original ebp
495
	pop	ebp
496
	ret
497
498
; For some reason, the OS X linker does not honor the request to align the
499
; segment unless we do this.
500
	align	16
(-)a/jpeg/simd/jimmxint.asm (+852 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jimmxint.asm - accurate integer IDCT (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a slow-but-accurate integer implementation of the
18
; inverse DCT (Discrete Cosine Transform). The following code is based
19
; directly on the IJG's original jidctint.c; see the jidctint.c for
20
; more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	13
30
%define PASS1_BITS	2
31
32
%define DESCALE_P1	(CONST_BITS-PASS1_BITS)
33
%define DESCALE_P2	(CONST_BITS+PASS1_BITS+3)
34
35
%if CONST_BITS == 13
36
F_0_298	equ	 2446		; FIX(0.298631336)
37
F_0_390	equ	 3196		; FIX(0.390180644)
38
F_0_541	equ	 4433		; FIX(0.541196100)
39
F_0_765	equ	 6270		; FIX(0.765366865)
40
F_0_899	equ	 7373		; FIX(0.899976223)
41
F_1_175	equ	 9633		; FIX(1.175875602)
42
F_1_501	equ	12299		; FIX(1.501321110)
43
F_1_847	equ	15137		; FIX(1.847759065)
44
F_1_961	equ	16069		; FIX(1.961570560)
45
F_2_053	equ	16819		; FIX(2.053119869)
46
F_2_562	equ	20995		; FIX(2.562915447)
47
F_3_072	equ	25172		; FIX(3.072711026)
48
%else
49
; NASM cannot do compile-time arithmetic on floating-point constants.
50
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
51
F_0_298	equ	DESCALE( 320652955,30-CONST_BITS)	; FIX(0.298631336)
52
F_0_390	equ	DESCALE( 418953276,30-CONST_BITS)	; FIX(0.390180644)
53
F_0_541	equ	DESCALE( 581104887,30-CONST_BITS)	; FIX(0.541196100)
54
F_0_765	equ	DESCALE( 821806413,30-CONST_BITS)	; FIX(0.765366865)
55
F_0_899	equ	DESCALE( 966342111,30-CONST_BITS)	; FIX(0.899976223)
56
F_1_175	equ	DESCALE(1262586813,30-CONST_BITS)	; FIX(1.175875602)
57
F_1_501	equ	DESCALE(1612031267,30-CONST_BITS)	; FIX(1.501321110)
58
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
59
F_1_961	equ	DESCALE(2106220350,30-CONST_BITS)	; FIX(1.961570560)
60
F_2_053	equ	DESCALE(2204520673,30-CONST_BITS)	; FIX(2.053119869)
61
F_2_562	equ	DESCALE(2751909506,30-CONST_BITS)	; FIX(2.562915447)
62
F_3_072	equ	DESCALE(3299298341,30-CONST_BITS)	; FIX(3.072711026)
63
%endif
64
65
; --------------------------------------------------------------------------
66
	SECTION	SEG_CONST
67
68
	alignz	16
69
	global	EXTN(jconst_idct_islow_mmx)
70
71
EXTN(jconst_idct_islow_mmx):
72
73
PW_F130_F054	times 2 dw  (F_0_541+F_0_765), F_0_541
74
PW_F054_MF130	times 2 dw  F_0_541, (F_0_541-F_1_847)
75
PW_MF078_F117	times 2 dw  (F_1_175-F_1_961), F_1_175
76
PW_F117_F078	times 2 dw  F_1_175, (F_1_175-F_0_390)
77
PW_MF060_MF089	times 2 dw  (F_0_298-F_0_899),-F_0_899
78
PW_MF089_F060	times 2 dw -F_0_899, (F_1_501-F_0_899)
79
PW_MF050_MF256	times 2 dw  (F_2_053-F_2_562),-F_2_562
80
PW_MF256_F050	times 2 dw -F_2_562, (F_3_072-F_2_562)
81
PD_DESCALE_P1	times 2 dd  1 << (DESCALE_P1-1)
82
PD_DESCALE_P2	times 2 dd  1 << (DESCALE_P2-1)
83
PB_CENTERJSAMP	times 8 db  CENTERJSAMPLE
84
85
	alignz	16
86
87
; --------------------------------------------------------------------------
88
	SECTION	SEG_TEXT
89
	BITS	32
90
;
91
; Perform dequantization and inverse DCT on one block of coefficients.
92
;
93
; GLOBAL(void)
94
; jsimd_idct_islow_mmx (void * dct_table, JCOEFPTR coef_block,
95
;                       JSAMPARRAY output_buf, JDIMENSION output_col)
96
;
97
98
%define dct_table(b)	(b)+8			; jpeg_component_info * compptr
99
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
100
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
101
%define output_col(b)	(b)+20		; JDIMENSION output_col
102
103
%define original_ebp	ebp+0
104
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
105
%define WK_NUM		12
106
%define workspace	wk(0)-DCTSIZE2*SIZEOF_JCOEF
107
					; JCOEF workspace[DCTSIZE2]
108
109
	align	16
110
	global	EXTN(jsimd_idct_islow_mmx)
111
112
EXTN(jsimd_idct_islow_mmx):
113
	push	ebp
114
	mov	eax,esp				; eax = original ebp
115
	sub	esp, byte 4
116
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
117
	mov	[esp],eax
118
	mov	ebp,esp				; ebp = aligned ebp
119
	lea	esp, [workspace]
120
	push	ebx
121
;	push	ecx		; need not be preserved
122
;	push	edx		; need not be preserved
123
	push	esi
124
	push	edi
125
126
	get_GOT	ebx		; get GOT address
127
128
	; ---- Pass 1: process columns from input, store into work array.
129
130
;	mov	eax, [original_ebp]
131
	mov	edx, POINTER [dct_table(eax)]	; quantptr
132
	mov	esi, JCOEFPTR [coef_block(eax)]		; inptr
133
	lea	edi, [workspace]			; JCOEF * wsptr
134
	mov	ecx, DCTSIZE/4				; ctr
135
	alignx	16,7
136
.columnloop:
137
%ifndef NO_ZERO_COLUMN_TEST_ISLOW_MMX
138
	mov	eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
139
	or	eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
140
	jnz	short .columnDCT
141
142
	movq	mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
143
	movq	mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
144
	por	mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
145
	por	mm1, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
146
	por	mm0, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
147
	por	mm1, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
148
	por	mm0, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
149
	por	mm1,mm0
150
	packsswb mm1,mm1
151
	movd	eax,mm1
152
	test	eax,eax
153
	jnz	short .columnDCT
154
155
	; -- AC terms all zero
156
157
	movq	mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
158
	pmullw	mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
159
160
	psllw	mm0,PASS1_BITS
161
162
	movq      mm2,mm0		; mm0=in0=(00 01 02 03)
163
	punpcklwd mm0,mm0		; mm0=(00 00 01 01)
164
	punpckhwd mm2,mm2		; mm2=(02 02 03 03)
165
166
	movq      mm1,mm0
167
	punpckldq mm0,mm0		; mm0=(00 00 00 00)
168
	punpckhdq mm1,mm1		; mm1=(01 01 01 01)
169
	movq      mm3,mm2
170
	punpckldq mm2,mm2		; mm2=(02 02 02 02)
171
	punpckhdq mm3,mm3		; mm3=(03 03 03 03)
172
173
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
174
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm0
175
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1
176
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm1
177
	movq	MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2
178
	movq	MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm2
179
	movq	MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3
180
	movq	MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm3
181
	jmp	near .nextcolumn
182
	alignx	16,7
183
%endif
184
.columnDCT:
185
186
	; -- Even part
187
188
	movq	mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
189
	movq	mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
190
	pmullw	mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
191
	pmullw	mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
192
	movq	mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
193
	movq	mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
194
	pmullw	mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
195
	pmullw	mm3, MMWORD [MMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
196
197
	; (Original)
198
	; z1 = (z2 + z3) * 0.541196100;
199
	; tmp2 = z1 + z3 * -1.847759065;
200
	; tmp3 = z1 + z2 * 0.765366865;
201
	;
202
	; (This implementation)
203
	; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
204
	; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
205
206
	movq      mm4,mm1		; mm1=in2=z2
207
	movq      mm5,mm1
208
	punpcklwd mm4,mm3		; mm3=in6=z3
209
	punpckhwd mm5,mm3
210
	movq      mm1,mm4
211
	movq      mm3,mm5
212
	pmaddwd   mm4,[GOTOFF(ebx,PW_F130_F054)]	; mm4=tmp3L
213
	pmaddwd   mm5,[GOTOFF(ebx,PW_F130_F054)]	; mm5=tmp3H
214
	pmaddwd   mm1,[GOTOFF(ebx,PW_F054_MF130)]	; mm1=tmp2L
215
	pmaddwd   mm3,[GOTOFF(ebx,PW_F054_MF130)]	; mm3=tmp2H
216
217
	movq      mm6,mm0
218
	paddw     mm0,mm2		; mm0=in0+in4
219
	psubw     mm6,mm2		; mm6=in0-in4
220
221
	pxor      mm7,mm7
222
	pxor      mm2,mm2
223
	punpcklwd mm7,mm0		; mm7=tmp0L
224
	punpckhwd mm2,mm0		; mm2=tmp0H
225
	psrad     mm7,(16-CONST_BITS)	; psrad mm7,16 & pslld mm7,CONST_BITS
226
	psrad     mm2,(16-CONST_BITS)	; psrad mm2,16 & pslld mm2,CONST_BITS
227
228
	movq	mm0,mm7
229
	paddd	mm7,mm4			; mm7=tmp10L
230
	psubd	mm0,mm4			; mm0=tmp13L
231
	movq	mm4,mm2
232
	paddd	mm2,mm5			; mm2=tmp10H
233
	psubd	mm4,mm5			; mm4=tmp13H
234
235
	movq	MMWORD [wk(0)], mm7	; wk(0)=tmp10L
236
	movq	MMWORD [wk(1)], mm2	; wk(1)=tmp10H
237
	movq	MMWORD [wk(2)], mm0	; wk(2)=tmp13L
238
	movq	MMWORD [wk(3)], mm4	; wk(3)=tmp13H
239
240
	pxor      mm5,mm5
241
	pxor      mm7,mm7
242
	punpcklwd mm5,mm6		; mm5=tmp1L
243
	punpckhwd mm7,mm6		; mm7=tmp1H
244
	psrad     mm5,(16-CONST_BITS)	; psrad mm5,16 & pslld mm5,CONST_BITS
245
	psrad     mm7,(16-CONST_BITS)	; psrad mm7,16 & pslld mm7,CONST_BITS
246
247
	movq	mm2,mm5
248
	paddd	mm5,mm1			; mm5=tmp11L
249
	psubd	mm2,mm1			; mm2=tmp12L
250
	movq	mm0,mm7
251
	paddd	mm7,mm3			; mm7=tmp11H
252
	psubd	mm0,mm3			; mm0=tmp12H
253
254
	movq	MMWORD [wk(4)], mm5	; wk(4)=tmp11L
255
	movq	MMWORD [wk(5)], mm7	; wk(5)=tmp11H
256
	movq	MMWORD [wk(6)], mm2	; wk(6)=tmp12L
257
	movq	MMWORD [wk(7)], mm0	; wk(7)=tmp12H
258
259
	; -- Odd part
260
261
	movq	mm4, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
262
	movq	mm6, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
263
	pmullw	mm4, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
264
	pmullw	mm6, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
265
	movq	mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
266
	movq	mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
267
	pmullw	mm1, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
268
	pmullw	mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
269
270
	movq	mm5,mm6
271
	movq	mm7,mm4
272
	paddw	mm5,mm3			; mm5=z3
273
	paddw	mm7,mm1			; mm7=z4
274
275
	; (Original)
276
	; z5 = (z3 + z4) * 1.175875602;
277
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
278
	; z3 += z5;  z4 += z5;
279
	;
280
	; (This implementation)
281
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
282
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
283
284
	movq      mm2,mm5
285
	movq      mm0,mm5
286
	punpcklwd mm2,mm7
287
	punpckhwd mm0,mm7
288
	movq      mm5,mm2
289
	movq      mm7,mm0
290
	pmaddwd   mm2,[GOTOFF(ebx,PW_MF078_F117)]	; mm2=z3L
291
	pmaddwd   mm0,[GOTOFF(ebx,PW_MF078_F117)]	; mm0=z3H
292
	pmaddwd   mm5,[GOTOFF(ebx,PW_F117_F078)]	; mm5=z4L
293
	pmaddwd   mm7,[GOTOFF(ebx,PW_F117_F078)]	; mm7=z4H
294
295
	movq	MMWORD [wk(10)], mm2	; wk(10)=z3L
296
	movq	MMWORD [wk(11)], mm0	; wk(11)=z3H
297
298
	; (Original)
299
	; z1 = tmp0 + tmp3;  z2 = tmp1 + tmp2;
300
	; tmp0 = tmp0 * 0.298631336;  tmp1 = tmp1 * 2.053119869;
301
	; tmp2 = tmp2 * 3.072711026;  tmp3 = tmp3 * 1.501321110;
302
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
303
	; tmp0 += z1 + z3;  tmp1 += z2 + z4;
304
	; tmp2 += z2 + z3;  tmp3 += z1 + z4;
305
	;
306
	; (This implementation)
307
	; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
308
	; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
309
	; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
310
	; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
311
	; tmp0 += z3;  tmp1 += z4;
312
	; tmp2 += z3;  tmp3 += z4;
313
314
	movq      mm2,mm3
315
	movq      mm0,mm3
316
	punpcklwd mm2,mm4
317
	punpckhwd mm0,mm4
318
	movq      mm3,mm2
319
	movq      mm4,mm0
320
	pmaddwd   mm2,[GOTOFF(ebx,PW_MF060_MF089)]	; mm2=tmp0L
321
	pmaddwd   mm0,[GOTOFF(ebx,PW_MF060_MF089)]	; mm0=tmp0H
322
	pmaddwd   mm3,[GOTOFF(ebx,PW_MF089_F060)]	; mm3=tmp3L
323
	pmaddwd   mm4,[GOTOFF(ebx,PW_MF089_F060)]	; mm4=tmp3H
324
325
	paddd	mm2, MMWORD [wk(10)]	; mm2=tmp0L
326
	paddd	mm0, MMWORD [wk(11)]	; mm0=tmp0H
327
	paddd	mm3,mm5			; mm3=tmp3L
328
	paddd	mm4,mm7			; mm4=tmp3H
329
330
	movq	MMWORD [wk(8)], mm2	; wk(8)=tmp0L
331
	movq	MMWORD [wk(9)], mm0	; wk(9)=tmp0H
332
333
	movq      mm2,mm1
334
	movq      mm0,mm1
335
	punpcklwd mm2,mm6
336
	punpckhwd mm0,mm6
337
	movq      mm1,mm2
338
	movq      mm6,mm0
339
	pmaddwd   mm2,[GOTOFF(ebx,PW_MF050_MF256)]	; mm2=tmp1L
340
	pmaddwd   mm0,[GOTOFF(ebx,PW_MF050_MF256)]	; mm0=tmp1H
341
	pmaddwd   mm1,[GOTOFF(ebx,PW_MF256_F050)]	; mm1=tmp2L
342
	pmaddwd   mm6,[GOTOFF(ebx,PW_MF256_F050)]	; mm6=tmp2H
343
344
	paddd	mm2,mm5			; mm2=tmp1L
345
	paddd	mm0,mm7			; mm0=tmp1H
346
	paddd	mm1, MMWORD [wk(10)]	; mm1=tmp2L
347
	paddd	mm6, MMWORD [wk(11)]	; mm6=tmp2H
348
349
	movq	MMWORD [wk(10)], mm2	; wk(10)=tmp1L
350
	movq	MMWORD [wk(11)], mm0	; wk(11)=tmp1H
351
352
	; -- Final output stage
353
354
	movq	mm5, MMWORD [wk(0)]	; mm5=tmp10L
355
	movq	mm7, MMWORD [wk(1)]	; mm7=tmp10H
356
357
	movq	mm2,mm5
358
	movq	mm0,mm7
359
	paddd	mm5,mm3			; mm5=data0L
360
	paddd	mm7,mm4			; mm7=data0H
361
	psubd	mm2,mm3			; mm2=data7L
362
	psubd	mm0,mm4			; mm0=data7H
363
364
	movq	mm3,[GOTOFF(ebx,PD_DESCALE_P1)]	; mm3=[PD_DESCALE_P1]
365
366
	paddd	mm5,mm3
367
	paddd	mm7,mm3
368
	psrad	mm5,DESCALE_P1
369
	psrad	mm7,DESCALE_P1
370
	paddd	mm2,mm3
371
	paddd	mm0,mm3
372
	psrad	mm2,DESCALE_P1
373
	psrad	mm0,DESCALE_P1
374
375
	packssdw  mm5,mm7		; mm5=data0=(00 01 02 03)
376
	packssdw  mm2,mm0		; mm2=data7=(70 71 72 73)
377
378
	movq	mm4, MMWORD [wk(4)]	; mm4=tmp11L
379
	movq	mm3, MMWORD [wk(5)]	; mm3=tmp11H
380
381
	movq	mm7,mm4
382
	movq	mm0,mm3
383
	paddd	mm4,mm1			; mm4=data1L
384
	paddd	mm3,mm6			; mm3=data1H
385
	psubd	mm7,mm1			; mm7=data6L
386
	psubd	mm0,mm6			; mm0=data6H
387
388
	movq	mm1,[GOTOFF(ebx,PD_DESCALE_P1)]	; mm1=[PD_DESCALE_P1]
389
390
	paddd	mm4,mm1
391
	paddd	mm3,mm1
392
	psrad	mm4,DESCALE_P1
393
	psrad	mm3,DESCALE_P1
394
	paddd	mm7,mm1
395
	paddd	mm0,mm1
396
	psrad	mm7,DESCALE_P1
397
	psrad	mm0,DESCALE_P1
398
399
	packssdw  mm4,mm3		; mm4=data1=(10 11 12 13)
400
	packssdw  mm7,mm0		; mm7=data6=(60 61 62 63)
401
402
	movq      mm6,mm5		; transpose coefficients(phase 1)
403
	punpcklwd mm5,mm4		; mm5=(00 10 01 11)
404
	punpckhwd mm6,mm4		; mm6=(02 12 03 13)
405
	movq      mm1,mm7		; transpose coefficients(phase 1)
406
	punpcklwd mm7,mm2		; mm7=(60 70 61 71)
407
	punpckhwd mm1,mm2		; mm1=(62 72 63 73)
408
409
	movq	mm3, MMWORD [wk(6)]	; mm3=tmp12L
410
	movq	mm0, MMWORD [wk(7)]	; mm0=tmp12H
411
	movq	mm4, MMWORD [wk(10)]	; mm4=tmp1L
412
	movq	mm2, MMWORD [wk(11)]	; mm2=tmp1H
413
414
	movq	MMWORD [wk(0)], mm5	; wk(0)=(00 10 01 11)
415
	movq	MMWORD [wk(1)], mm6	; wk(1)=(02 12 03 13)
416
	movq	MMWORD [wk(4)], mm7	; wk(4)=(60 70 61 71)
417
	movq	MMWORD [wk(5)], mm1	; wk(5)=(62 72 63 73)
418
419
	movq	mm5,mm3
420
	movq	mm6,mm0
421
	paddd	mm3,mm4			; mm3=data2L
422
	paddd	mm0,mm2			; mm0=data2H
423
	psubd	mm5,mm4			; mm5=data5L
424
	psubd	mm6,mm2			; mm6=data5H
425
426
	movq	mm7,[GOTOFF(ebx,PD_DESCALE_P1)]	; mm7=[PD_DESCALE_P1]
427
428
	paddd	mm3,mm7
429
	paddd	mm0,mm7
430
	psrad	mm3,DESCALE_P1
431
	psrad	mm0,DESCALE_P1
432
	paddd	mm5,mm7
433
	paddd	mm6,mm7
434
	psrad	mm5,DESCALE_P1
435
	psrad	mm6,DESCALE_P1
436
437
	packssdw  mm3,mm0		; mm3=data2=(20 21 22 23)
438
	packssdw  mm5,mm6		; mm5=data5=(50 51 52 53)
439
440
	movq	mm1, MMWORD [wk(2)]	; mm1=tmp13L
441
	movq	mm4, MMWORD [wk(3)]	; mm4=tmp13H
442
	movq	mm2, MMWORD [wk(8)]	; mm2=tmp0L
443
	movq	mm7, MMWORD [wk(9)]	; mm7=tmp0H
444
445
	movq	mm0,mm1
446
	movq	mm6,mm4
447
	paddd	mm1,mm2			; mm1=data3L
448
	paddd	mm4,mm7			; mm4=data3H
449
	psubd	mm0,mm2			; mm0=data4L
450
	psubd	mm6,mm7			; mm6=data4H
451
452
	movq	mm2,[GOTOFF(ebx,PD_DESCALE_P1)]	; mm2=[PD_DESCALE_P1]
453
454
	paddd	mm1,mm2
455
	paddd	mm4,mm2
456
	psrad	mm1,DESCALE_P1
457
	psrad	mm4,DESCALE_P1
458
	paddd	mm0,mm2
459
	paddd	mm6,mm2
460
	psrad	mm0,DESCALE_P1
461
	psrad	mm6,DESCALE_P1
462
463
	packssdw  mm1,mm4		; mm1=data3=(30 31 32 33)
464
	packssdw  mm0,mm6		; mm0=data4=(40 41 42 43)
465
466
	movq	mm7, MMWORD [wk(0)]	; mm7=(00 10 01 11)
467
	movq	mm2, MMWORD [wk(1)]	; mm2=(02 12 03 13)
468
469
	movq      mm4,mm3		; transpose coefficients(phase 1)
470
	punpcklwd mm3,mm1		; mm3=(20 30 21 31)
471
	punpckhwd mm4,mm1		; mm4=(22 32 23 33)
472
	movq      mm6,mm0		; transpose coefficients(phase 1)
473
	punpcklwd mm0,mm5		; mm0=(40 50 41 51)
474
	punpckhwd mm6,mm5		; mm6=(42 52 43 53)
475
476
	movq      mm1,mm7		; transpose coefficients(phase 2)
477
	punpckldq mm7,mm3		; mm7=(00 10 20 30)
478
	punpckhdq mm1,mm3		; mm1=(01 11 21 31)
479
	movq      mm5,mm2		; transpose coefficients(phase 2)
480
	punpckldq mm2,mm4		; mm2=(02 12 22 32)
481
	punpckhdq mm5,mm4		; mm5=(03 13 23 33)
482
483
	movq	mm3, MMWORD [wk(4)]	; mm3=(60 70 61 71)
484
	movq	mm4, MMWORD [wk(5)]	; mm4=(62 72 63 73)
485
486
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm7
487
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1
488
	movq	MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2
489
	movq	MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm5
490
491
	movq      mm7,mm0		; transpose coefficients(phase 2)
492
	punpckldq mm0,mm3		; mm0=(40 50 60 70)
493
	punpckhdq mm7,mm3		; mm7=(41 51 61 71)
494
	movq      mm1,mm6		; transpose coefficients(phase 2)
495
	punpckldq mm6,mm4		; mm6=(42 52 62 72)
496
	punpckhdq mm1,mm4		; mm1=(43 53 63 73)
497
498
	movq	MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm0
499
	movq	MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm7
500
	movq	MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm6
501
	movq	MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm1
502
503
.nextcolumn:
504
	add	esi, byte 4*SIZEOF_JCOEF		; coef_block
505
	add	edx, byte 4*SIZEOF_ISLOW_MULT_TYPE	; quantptr
506
	add	edi, byte 4*DCTSIZE*SIZEOF_JCOEF	; wsptr
507
	dec	ecx					; ctr
508
	jnz	near .columnloop
509
510
	; ---- Pass 2: process rows from work array, store into output array.
511
512
	mov	eax, [original_ebp]
513
	lea	esi, [workspace]			; JCOEF * wsptr
514
	mov	edi, JSAMPARRAY [output_buf(eax)]	; (JSAMPROW *)
515
	mov	eax, JDIMENSION [output_col(eax)]
516
	mov	ecx, DCTSIZE/4				; ctr
517
	alignx	16,7
518
.rowloop:
519
520
	; -- Even part
521
522
	movq	mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
523
	movq	mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
524
	movq	mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
525
	movq	mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
526
527
	; (Original)
528
	; z1 = (z2 + z3) * 0.541196100;
529
	; tmp2 = z1 + z3 * -1.847759065;
530
	; tmp3 = z1 + z2 * 0.765366865;
531
	;
532
	; (This implementation)
533
	; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
534
	; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
535
536
	movq      mm4,mm1		; mm1=in2=z2
537
	movq      mm5,mm1
538
	punpcklwd mm4,mm3		; mm3=in6=z3
539
	punpckhwd mm5,mm3
540
	movq      mm1,mm4
541
	movq      mm3,mm5
542
	pmaddwd   mm4,[GOTOFF(ebx,PW_F130_F054)]	; mm4=tmp3L
543
	pmaddwd   mm5,[GOTOFF(ebx,PW_F130_F054)]	; mm5=tmp3H
544
	pmaddwd   mm1,[GOTOFF(ebx,PW_F054_MF130)]	; mm1=tmp2L
545
	pmaddwd   mm3,[GOTOFF(ebx,PW_F054_MF130)]	; mm3=tmp2H
546
547
	movq      mm6,mm0
548
	paddw     mm0,mm2		; mm0=in0+in4
549
	psubw     mm6,mm2		; mm6=in0-in4
550
551
	pxor      mm7,mm7
552
	pxor      mm2,mm2
553
	punpcklwd mm7,mm0		; mm7=tmp0L
554
	punpckhwd mm2,mm0		; mm2=tmp0H
555
	psrad     mm7,(16-CONST_BITS)	; psrad mm7,16 & pslld mm7,CONST_BITS
556
	psrad     mm2,(16-CONST_BITS)	; psrad mm2,16 & pslld mm2,CONST_BITS
557
558
	movq	mm0,mm7
559
	paddd	mm7,mm4			; mm7=tmp10L
560
	psubd	mm0,mm4			; mm0=tmp13L
561
	movq	mm4,mm2
562
	paddd	mm2,mm5			; mm2=tmp10H
563
	psubd	mm4,mm5			; mm4=tmp13H
564
565
	movq	MMWORD [wk(0)], mm7	; wk(0)=tmp10L
566
	movq	MMWORD [wk(1)], mm2	; wk(1)=tmp10H
567
	movq	MMWORD [wk(2)], mm0	; wk(2)=tmp13L
568
	movq	MMWORD [wk(3)], mm4	; wk(3)=tmp13H
569
570
	pxor      mm5,mm5
571
	pxor      mm7,mm7
572
	punpcklwd mm5,mm6		; mm5=tmp1L
573
	punpckhwd mm7,mm6		; mm7=tmp1H
574
	psrad     mm5,(16-CONST_BITS)	; psrad mm5,16 & pslld mm5,CONST_BITS
575
	psrad     mm7,(16-CONST_BITS)	; psrad mm7,16 & pslld mm7,CONST_BITS
576
577
	movq	mm2,mm5
578
	paddd	mm5,mm1			; mm5=tmp11L
579
	psubd	mm2,mm1			; mm2=tmp12L
580
	movq	mm0,mm7
581
	paddd	mm7,mm3			; mm7=tmp11H
582
	psubd	mm0,mm3			; mm0=tmp12H
583
584
	movq	MMWORD [wk(4)], mm5	; wk(4)=tmp11L
585
	movq	MMWORD [wk(5)], mm7	; wk(5)=tmp11H
586
	movq	MMWORD [wk(6)], mm2	; wk(6)=tmp12L
587
	movq	MMWORD [wk(7)], mm0	; wk(7)=tmp12H
588
589
	; -- Odd part
590
591
	movq	mm4, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
592
	movq	mm6, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
593
	movq	mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
594
	movq	mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
595
596
	movq	mm5,mm6
597
	movq	mm7,mm4
598
	paddw	mm5,mm3			; mm5=z3
599
	paddw	mm7,mm1			; mm7=z4
600
601
	; (Original)
602
	; z5 = (z3 + z4) * 1.175875602;
603
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
604
	; z3 += z5;  z4 += z5;
605
	;
606
	; (This implementation)
607
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
608
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
609
610
	movq      mm2,mm5
611
	movq      mm0,mm5
612
	punpcklwd mm2,mm7
613
	punpckhwd mm0,mm7
614
	movq      mm5,mm2
615
	movq      mm7,mm0
616
	pmaddwd   mm2,[GOTOFF(ebx,PW_MF078_F117)]	; mm2=z3L
617
	pmaddwd   mm0,[GOTOFF(ebx,PW_MF078_F117)]	; mm0=z3H
618
	pmaddwd   mm5,[GOTOFF(ebx,PW_F117_F078)]	; mm5=z4L
619
	pmaddwd   mm7,[GOTOFF(ebx,PW_F117_F078)]	; mm7=z4H
620
621
	movq	MMWORD [wk(10)], mm2	; wk(10)=z3L
622
	movq	MMWORD [wk(11)], mm0	; wk(11)=z3H
623
624
	; (Original)
625
	; z1 = tmp0 + tmp3;  z2 = tmp1 + tmp2;
626
	; tmp0 = tmp0 * 0.298631336;  tmp1 = tmp1 * 2.053119869;
627
	; tmp2 = tmp2 * 3.072711026;  tmp3 = tmp3 * 1.501321110;
628
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
629
	; tmp0 += z1 + z3;  tmp1 += z2 + z4;
630
	; tmp2 += z2 + z3;  tmp3 += z1 + z4;
631
	;
632
	; (This implementation)
633
	; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
634
	; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
635
	; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
636
	; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
637
	; tmp0 += z3;  tmp1 += z4;
638
	; tmp2 += z3;  tmp3 += z4;
639
640
	movq      mm2,mm3
641
	movq      mm0,mm3
642
	punpcklwd mm2,mm4
643
	punpckhwd mm0,mm4
644
	movq      mm3,mm2
645
	movq      mm4,mm0
646
	pmaddwd   mm2,[GOTOFF(ebx,PW_MF060_MF089)]	; mm2=tmp0L
647
	pmaddwd   mm0,[GOTOFF(ebx,PW_MF060_MF089)]	; mm0=tmp0H
648
	pmaddwd   mm3,[GOTOFF(ebx,PW_MF089_F060)]	; mm3=tmp3L
649
	pmaddwd   mm4,[GOTOFF(ebx,PW_MF089_F060)]	; mm4=tmp3H
650
651
	paddd	mm2, MMWORD [wk(10)]	; mm2=tmp0L
652
	paddd	mm0, MMWORD [wk(11)]	; mm0=tmp0H
653
	paddd	mm3,mm5			; mm3=tmp3L
654
	paddd	mm4,mm7			; mm4=tmp3H
655
656
	movq	MMWORD [wk(8)], mm2	; wk(8)=tmp0L
657
	movq	MMWORD [wk(9)], mm0	; wk(9)=tmp0H
658
659
	movq      mm2,mm1
660
	movq      mm0,mm1
661
	punpcklwd mm2,mm6
662
	punpckhwd mm0,mm6
663
	movq      mm1,mm2
664
	movq      mm6,mm0
665
	pmaddwd   mm2,[GOTOFF(ebx,PW_MF050_MF256)]	; mm2=tmp1L
666
	pmaddwd   mm0,[GOTOFF(ebx,PW_MF050_MF256)]	; mm0=tmp1H
667
	pmaddwd   mm1,[GOTOFF(ebx,PW_MF256_F050)]	; mm1=tmp2L
668
	pmaddwd   mm6,[GOTOFF(ebx,PW_MF256_F050)]	; mm6=tmp2H
669
670
	paddd	mm2,mm5			; mm2=tmp1L
671
	paddd	mm0,mm7			; mm0=tmp1H
672
	paddd	mm1, MMWORD [wk(10)]	; mm1=tmp2L
673
	paddd	mm6, MMWORD [wk(11)]	; mm6=tmp2H
674
675
	movq	MMWORD [wk(10)], mm2	; wk(10)=tmp1L
676
	movq	MMWORD [wk(11)], mm0	; wk(11)=tmp1H
677
678
	; -- Final output stage
679
680
	movq	mm5, MMWORD [wk(0)]	; mm5=tmp10L
681
	movq	mm7, MMWORD [wk(1)]	; mm7=tmp10H
682
683
	movq	mm2,mm5
684
	movq	mm0,mm7
685
	paddd	mm5,mm3			; mm5=data0L
686
	paddd	mm7,mm4			; mm7=data0H
687
	psubd	mm2,mm3			; mm2=data7L
688
	psubd	mm0,mm4			; mm0=data7H
689
690
	movq	mm3,[GOTOFF(ebx,PD_DESCALE_P2)]	; mm3=[PD_DESCALE_P2]
691
692
	paddd	mm5,mm3
693
	paddd	mm7,mm3
694
	psrad	mm5,DESCALE_P2
695
	psrad	mm7,DESCALE_P2
696
	paddd	mm2,mm3
697
	paddd	mm0,mm3
698
	psrad	mm2,DESCALE_P2
699
	psrad	mm0,DESCALE_P2
700
701
	packssdw  mm5,mm7		; mm5=data0=(00 10 20 30)
702
	packssdw  mm2,mm0		; mm2=data7=(07 17 27 37)
703
704
	movq	mm4, MMWORD [wk(4)]	; mm4=tmp11L
705
	movq	mm3, MMWORD [wk(5)]	; mm3=tmp11H
706
707
	movq	mm7,mm4
708
	movq	mm0,mm3
709
	paddd	mm4,mm1			; mm4=data1L
710
	paddd	mm3,mm6			; mm3=data1H
711
	psubd	mm7,mm1			; mm7=data6L
712
	psubd	mm0,mm6			; mm0=data6H
713
714
	movq	mm1,[GOTOFF(ebx,PD_DESCALE_P2)]	; mm1=[PD_DESCALE_P2]
715
716
	paddd	mm4,mm1
717
	paddd	mm3,mm1
718
	psrad	mm4,DESCALE_P2
719
	psrad	mm3,DESCALE_P2
720
	paddd	mm7,mm1
721
	paddd	mm0,mm1
722
	psrad	mm7,DESCALE_P2
723
	psrad	mm0,DESCALE_P2
724
725
	packssdw  mm4,mm3		; mm4=data1=(01 11 21 31)
726
	packssdw  mm7,mm0		; mm7=data6=(06 16 26 36)
727
728
	packsswb  mm5,mm7		; mm5=(00 10 20 30 06 16 26 36)
729
	packsswb  mm4,mm2		; mm4=(01 11 21 31 07 17 27 37)
730
731
	movq	mm6, MMWORD [wk(6)]	; mm6=tmp12L
732
	movq	mm1, MMWORD [wk(7)]	; mm1=tmp12H
733
	movq	mm3, MMWORD [wk(10)]	; mm3=tmp1L
734
	movq	mm0, MMWORD [wk(11)]	; mm0=tmp1H
735
736
	movq	MMWORD [wk(0)], mm5	; wk(0)=(00 10 20 30 06 16 26 36)
737
	movq	MMWORD [wk(1)], mm4	; wk(1)=(01 11 21 31 07 17 27 37)
738
739
	movq	mm7,mm6
740
	movq	mm2,mm1
741
	paddd	mm6,mm3			; mm6=data2L
742
	paddd	mm1,mm0			; mm1=data2H
743
	psubd	mm7,mm3			; mm7=data5L
744
	psubd	mm2,mm0			; mm2=data5H
745
746
	movq	mm5,[GOTOFF(ebx,PD_DESCALE_P2)]	; mm5=[PD_DESCALE_P2]
747
748
	paddd	mm6,mm5
749
	paddd	mm1,mm5
750
	psrad	mm6,DESCALE_P2
751
	psrad	mm1,DESCALE_P2
752
	paddd	mm7,mm5
753
	paddd	mm2,mm5
754
	psrad	mm7,DESCALE_P2
755
	psrad	mm2,DESCALE_P2
756
757
	packssdw  mm6,mm1		; mm6=data2=(02 12 22 32)
758
	packssdw  mm7,mm2		; mm7=data5=(05 15 25 35)
759
760
	movq	mm4, MMWORD [wk(2)]	; mm4=tmp13L
761
	movq	mm3, MMWORD [wk(3)]	; mm3=tmp13H
762
	movq	mm0, MMWORD [wk(8)]	; mm0=tmp0L
763
	movq	mm5, MMWORD [wk(9)]	; mm5=tmp0H
764
765
	movq	mm1,mm4
766
	movq	mm2,mm3
767
	paddd	mm4,mm0			; mm4=data3L
768
	paddd	mm3,mm5			; mm3=data3H
769
	psubd	mm1,mm0			; mm1=data4L
770
	psubd	mm2,mm5			; mm2=data4H
771
772
	movq	mm0,[GOTOFF(ebx,PD_DESCALE_P2)]	; mm0=[PD_DESCALE_P2]
773
774
	paddd	mm4,mm0
775
	paddd	mm3,mm0
776
	psrad	mm4,DESCALE_P2
777
	psrad	mm3,DESCALE_P2
778
	paddd	mm1,mm0
779
	paddd	mm2,mm0
780
	psrad	mm1,DESCALE_P2
781
	psrad	mm2,DESCALE_P2
782
783
	movq      mm5,[GOTOFF(ebx,PB_CENTERJSAMP)]	; mm5=[PB_CENTERJSAMP]
784
785
	packssdw  mm4,mm3		; mm4=data3=(03 13 23 33)
786
	packssdw  mm1,mm2		; mm1=data4=(04 14 24 34)
787
788
	movq      mm0, MMWORD [wk(0)]	; mm0=(00 10 20 30 06 16 26 36)
789
	movq      mm3, MMWORD [wk(1)]	; mm3=(01 11 21 31 07 17 27 37)
790
791
	packsswb  mm6,mm1		; mm6=(02 12 22 32 04 14 24 34)
792
	packsswb  mm4,mm7		; mm4=(03 13 23 33 05 15 25 35)
793
794
	paddb     mm0,mm5
795
	paddb     mm3,mm5
796
	paddb     mm6,mm5
797
	paddb     mm4,mm5
798
799
	movq      mm2,mm0		; transpose coefficients(phase 1)
800
	punpcklbw mm0,mm3		; mm0=(00 01 10 11 20 21 30 31)
801
	punpckhbw mm2,mm3		; mm2=(06 07 16 17 26 27 36 37)
802
	movq      mm1,mm6		; transpose coefficients(phase 1)
803
	punpcklbw mm6,mm4		; mm6=(02 03 12 13 22 23 32 33)
804
	punpckhbw mm1,mm4		; mm1=(04 05 14 15 24 25 34 35)
805
806
	movq      mm7,mm0		; transpose coefficients(phase 2)
807
	punpcklwd mm0,mm6		; mm0=(00 01 02 03 10 11 12 13)
808
	punpckhwd mm7,mm6		; mm7=(20 21 22 23 30 31 32 33)
809
	movq      mm5,mm1		; transpose coefficients(phase 2)
810
	punpcklwd mm1,mm2		; mm1=(04 05 06 07 14 15 16 17)
811
	punpckhwd mm5,mm2		; mm5=(24 25 26 27 34 35 36 37)
812
813
	movq      mm3,mm0		; transpose coefficients(phase 3)
814
	punpckldq mm0,mm1		; mm0=(00 01 02 03 04 05 06 07)
815
	punpckhdq mm3,mm1		; mm3=(10 11 12 13 14 15 16 17)
816
	movq      mm4,mm7		; transpose coefficients(phase 3)
817
	punpckldq mm7,mm5		; mm7=(20 21 22 23 24 25 26 27)
818
	punpckhdq mm4,mm5		; mm4=(30 31 32 33 34 35 36 37)
819
820
	pushpic	ebx			; save GOT address
821
822
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
823
	mov	ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
824
	movq	MMWORD [edx+eax*SIZEOF_JSAMPLE], mm0
825
	movq	MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm3
826
	mov	edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
827
	mov	ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
828
	movq	MMWORD [edx+eax*SIZEOF_JSAMPLE], mm7
829
	movq	MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm4
830
831
	poppic	ebx			; restore GOT address
832
833
	add	esi, byte 4*SIZEOF_JCOEF	; wsptr
834
	add	edi, byte 4*SIZEOF_JSAMPROW
835
	dec	ecx				; ctr
836
	jnz	near .rowloop
837
838
	emms		; empty MMX state
839
840
	pop	edi
841
	pop	esi
842
;	pop	edx		; need not be preserved
843
;	pop	ecx		; need not be preserved
844
	pop	ebx
845
	mov	esp,ebp		; esp <- aligned ebp
846
	pop	esp		; esp <- original ebp
847
	pop	ebp
848
	ret
849
850
; For some reason, the OS X linker does not honor the request to align the
851
; segment unless we do this.
852
	align	16
(-)a/jpeg/simd/jimmxred.asm (+706 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jimmxred.asm - reduced-size IDCT (MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains inverse-DCT routines that produce reduced-size
18
; output: either 4x4 or 2x2 pixels from an 8x8 DCT block.
19
; The following code is based directly on the IJG's original jidctred.c;
20
; see the jidctred.c for more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	13
30
%define PASS1_BITS	2
31
32
%define DESCALE_P1_4	(CONST_BITS-PASS1_BITS+1)
33
%define DESCALE_P2_4	(CONST_BITS+PASS1_BITS+3+1)
34
%define DESCALE_P1_2	(CONST_BITS-PASS1_BITS+2)
35
%define DESCALE_P2_2	(CONST_BITS+PASS1_BITS+3+2)
36
37
%if CONST_BITS == 13
38
F_0_211	equ	 1730		; FIX(0.211164243)
39
F_0_509	equ	 4176		; FIX(0.509795579)
40
F_0_601	equ	 4926		; FIX(0.601344887)
41
F_0_720	equ	 5906		; FIX(0.720959822)
42
F_0_765	equ	 6270		; FIX(0.765366865)
43
F_0_850	equ	 6967		; FIX(0.850430095)
44
F_0_899	equ	 7373		; FIX(0.899976223)
45
F_1_061	equ	 8697		; FIX(1.061594337)
46
F_1_272	equ	10426		; FIX(1.272758580)
47
F_1_451	equ	11893		; FIX(1.451774981)
48
F_1_847	equ	15137		; FIX(1.847759065)
49
F_2_172	equ	17799		; FIX(2.172734803)
50
F_2_562	equ	20995		; FIX(2.562915447)
51
F_3_624	equ	29692		; FIX(3.624509785)
52
%else
53
; NASM cannot do compile-time arithmetic on floating-point constants.
54
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
55
F_0_211	equ	DESCALE( 226735879,30-CONST_BITS)	; FIX(0.211164243)
56
F_0_509	equ	DESCALE( 547388834,30-CONST_BITS)	; FIX(0.509795579)
57
F_0_601	equ	DESCALE( 645689155,30-CONST_BITS)	; FIX(0.601344887)
58
F_0_720	equ	DESCALE( 774124714,30-CONST_BITS)	; FIX(0.720959822)
59
F_0_765	equ	DESCALE( 821806413,30-CONST_BITS)	; FIX(0.765366865)
60
F_0_850	equ	DESCALE( 913142361,30-CONST_BITS)	; FIX(0.850430095)
61
F_0_899	equ	DESCALE( 966342111,30-CONST_BITS)	; FIX(0.899976223)
62
F_1_061	equ	DESCALE(1139878239,30-CONST_BITS)	; FIX(1.061594337)
63
F_1_272	equ	DESCALE(1366614119,30-CONST_BITS)	; FIX(1.272758580)
64
F_1_451	equ	DESCALE(1558831516,30-CONST_BITS)	; FIX(1.451774981)
65
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
66
F_2_172	equ	DESCALE(2332956230,30-CONST_BITS)	; FIX(2.172734803)
67
F_2_562	equ	DESCALE(2751909506,30-CONST_BITS)	; FIX(2.562915447)
68
F_3_624	equ	DESCALE(3891787747,30-CONST_BITS)	; FIX(3.624509785)
69
%endif
70
71
; --------------------------------------------------------------------------
72
	SECTION	SEG_CONST
73
74
	alignz	16
75
	global	EXTN(jconst_idct_red_mmx)
76
77
EXTN(jconst_idct_red_mmx):
78
79
PW_F184_MF076	times 2 dw  F_1_847,-F_0_765
80
PW_F256_F089	times 2 dw  F_2_562, F_0_899
81
PW_F106_MF217	times 2 dw  F_1_061,-F_2_172
82
PW_MF060_MF050	times 2 dw -F_0_601,-F_0_509
83
PW_F145_MF021	times 2 dw  F_1_451,-F_0_211
84
PW_F362_MF127	times 2 dw  F_3_624,-F_1_272
85
PW_F085_MF072	times 2 dw  F_0_850,-F_0_720
86
PD_DESCALE_P1_4	times 2 dd  1 << (DESCALE_P1_4-1)
87
PD_DESCALE_P2_4	times 2 dd  1 << (DESCALE_P2_4-1)
88
PD_DESCALE_P1_2	times 2 dd  1 << (DESCALE_P1_2-1)
89
PD_DESCALE_P2_2	times 2 dd  1 << (DESCALE_P2_2-1)
90
PB_CENTERJSAMP	times 8 db  CENTERJSAMPLE
91
92
	alignz	16
93
94
; --------------------------------------------------------------------------
95
	SECTION	SEG_TEXT
96
	BITS	32
97
;
98
; Perform dequantization and inverse DCT on one block of coefficients,
99
; producing a reduced-size 4x4 output block.
100
;
101
; GLOBAL(void)
102
; jsimd_idct_4x4_mmx (void * dct_table, JCOEFPTR coef_block,
103
;                     JSAMPARRAY output_buf, JDIMENSION output_col)
104
;
105
106
%define dct_table(b)	(b)+8			; void * dct_table
107
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
108
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
109
%define output_col(b)	(b)+20		; JDIMENSION output_col
110
111
%define original_ebp	ebp+0
112
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_MMWORD	; mmword wk[WK_NUM]
113
%define WK_NUM		2
114
%define workspace	wk(0)-DCTSIZE2*SIZEOF_JCOEF
115
					; JCOEF workspace[DCTSIZE2]
116
117
	align	16
118
	global	EXTN(jsimd_idct_4x4_mmx)
119
120
EXTN(jsimd_idct_4x4_mmx):
121
	push	ebp
122
	mov	eax,esp				; eax = original ebp
123
	sub	esp, byte 4
124
	and	esp, byte (-SIZEOF_MMWORD)	; align to 64 bits
125
	mov	[esp],eax
126
	mov	ebp,esp				; ebp = aligned ebp
127
	lea	esp, [workspace]
128
	pushpic	ebx
129
;	push	ecx		; need not be preserved
130
;	push	edx		; need not be preserved
131
	push	esi
132
	push	edi
133
134
	get_GOT	ebx		; get GOT address
135
136
	; ---- Pass 1: process columns from input, store into work array.
137
138
;	mov	eax, [original_ebp]
139
	mov	edx, POINTER [dct_table(eax)]	; quantptr
140
	mov	esi, JCOEFPTR [coef_block(eax)]		; inptr
141
	lea	edi, [workspace]			; JCOEF * wsptr
142
	mov	ecx, DCTSIZE/4				; ctr
143
	alignx	16,7
144
.columnloop:
145
%ifndef NO_ZERO_COLUMN_TEST_4X4_MMX
146
	mov	eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
147
	or	eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
148
	jnz	short .columnDCT
149
150
	movq	mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
151
	movq	mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
152
	por	mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
153
	por	mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
154
	por	mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
155
	por	mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
156
	por	mm0,mm1
157
	packsswb mm0,mm0
158
	movd	eax,mm0
159
	test	eax,eax
160
	jnz	short .columnDCT
161
162
	; -- AC terms all zero
163
164
	movq	mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
165
	pmullw	mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
166
167
	psllw	mm0,PASS1_BITS
168
169
	movq      mm2,mm0		; mm0=in0=(00 01 02 03)
170
	punpcklwd mm0,mm0		; mm0=(00 00 01 01)
171
	punpckhwd mm2,mm2		; mm2=(02 02 03 03)
172
173
	movq      mm1,mm0
174
	punpckldq mm0,mm0		; mm0=(00 00 00 00)
175
	punpckhdq mm1,mm1		; mm1=(01 01 01 01)
176
	movq      mm3,mm2
177
	punpckldq mm2,mm2		; mm2=(02 02 02 02)
178
	punpckhdq mm3,mm3		; mm3=(03 03 03 03)
179
180
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
181
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1
182
	movq	MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2
183
	movq	MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3
184
	jmp	near .nextcolumn
185
	alignx	16,7
186
%endif
187
.columnDCT:
188
189
	; -- Odd part
190
191
	movq	mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
192
	movq	mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
193
	pmullw	mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
194
	pmullw	mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
195
	movq	mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
196
	movq	mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
197
	pmullw	mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
198
	pmullw	mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
199
200
	movq      mm4,mm0
201
	movq      mm5,mm0
202
	punpcklwd mm4,mm1
203
	punpckhwd mm5,mm1
204
	movq      mm0,mm4
205
	movq      mm1,mm5
206
	pmaddwd   mm4,[GOTOFF(ebx,PW_F256_F089)]	; mm4=(tmp2L)
207
	pmaddwd   mm5,[GOTOFF(ebx,PW_F256_F089)]	; mm5=(tmp2H)
208
	pmaddwd   mm0,[GOTOFF(ebx,PW_F106_MF217)]	; mm0=(tmp0L)
209
	pmaddwd   mm1,[GOTOFF(ebx,PW_F106_MF217)]	; mm1=(tmp0H)
210
211
	movq      mm6,mm2
212
	movq      mm7,mm2
213
	punpcklwd mm6,mm3
214
	punpckhwd mm7,mm3
215
	movq      mm2,mm6
216
	movq      mm3,mm7
217
	pmaddwd   mm6,[GOTOFF(ebx,PW_MF060_MF050)]	; mm6=(tmp2L)
218
	pmaddwd   mm7,[GOTOFF(ebx,PW_MF060_MF050)]	; mm7=(tmp2H)
219
	pmaddwd   mm2,[GOTOFF(ebx,PW_F145_MF021)]	; mm2=(tmp0L)
220
	pmaddwd   mm3,[GOTOFF(ebx,PW_F145_MF021)]	; mm3=(tmp0H)
221
222
	paddd	mm6,mm4			; mm6=tmp2L
223
	paddd	mm7,mm5			; mm7=tmp2H
224
	paddd	mm2,mm0			; mm2=tmp0L
225
	paddd	mm3,mm1			; mm3=tmp0H
226
227
	movq	MMWORD [wk(0)], mm2	; wk(0)=tmp0L
228
	movq	MMWORD [wk(1)], mm3	; wk(1)=tmp0H
229
230
	; -- Even part
231
232
	movq	mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
233
	movq	mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
234
	movq	mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
235
	pmullw	mm4, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
236
	pmullw	mm5, MMWORD [MMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
237
	pmullw	mm0, MMWORD [MMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
238
239
	pxor      mm1,mm1
240
	pxor      mm2,mm2
241
	punpcklwd mm1,mm4		; mm1=tmp0L
242
	punpckhwd mm2,mm4		; mm2=tmp0H
243
	psrad     mm1,(16-CONST_BITS-1)	; psrad mm1,16 & pslld mm1,CONST_BITS+1
244
	psrad     mm2,(16-CONST_BITS-1)	; psrad mm2,16 & pslld mm2,CONST_BITS+1
245
246
	movq      mm3,mm5		; mm5=in2=z2
247
	punpcklwd mm5,mm0		; mm0=in6=z3
248
	punpckhwd mm3,mm0
249
	pmaddwd   mm5,[GOTOFF(ebx,PW_F184_MF076)]	; mm5=tmp2L
250
	pmaddwd   mm3,[GOTOFF(ebx,PW_F184_MF076)]	; mm3=tmp2H
251
252
	movq	mm4,mm1
253
	movq	mm0,mm2
254
	paddd	mm1,mm5			; mm1=tmp10L
255
	paddd	mm2,mm3			; mm2=tmp10H
256
	psubd	mm4,mm5			; mm4=tmp12L
257
	psubd	mm0,mm3			; mm0=tmp12H
258
259
	; -- Final output stage
260
261
	movq	mm5,mm1
262
	movq	mm3,mm2
263
	paddd	mm1,mm6			; mm1=data0L
264
	paddd	mm2,mm7			; mm2=data0H
265
	psubd	mm5,mm6			; mm5=data3L
266
	psubd	mm3,mm7			; mm3=data3H
267
268
	movq	mm6,[GOTOFF(ebx,PD_DESCALE_P1_4)]	; mm6=[PD_DESCALE_P1_4]
269
270
	paddd	mm1,mm6
271
	paddd	mm2,mm6
272
	psrad	mm1,DESCALE_P1_4
273
	psrad	mm2,DESCALE_P1_4
274
	paddd	mm5,mm6
275
	paddd	mm3,mm6
276
	psrad	mm5,DESCALE_P1_4
277
	psrad	mm3,DESCALE_P1_4
278
279
	packssdw  mm1,mm2		; mm1=data0=(00 01 02 03)
280
	packssdw  mm5,mm3		; mm5=data3=(30 31 32 33)
281
282
	movq	mm7, MMWORD [wk(0)]	; mm7=tmp0L
283
	movq	mm6, MMWORD [wk(1)]	; mm6=tmp0H
284
285
	movq	mm2,mm4
286
	movq	mm3,mm0
287
	paddd	mm4,mm7			; mm4=data1L
288
	paddd	mm0,mm6			; mm0=data1H
289
	psubd	mm2,mm7			; mm2=data2L
290
	psubd	mm3,mm6			; mm3=data2H
291
292
	movq	mm7,[GOTOFF(ebx,PD_DESCALE_P1_4)]	; mm7=[PD_DESCALE_P1_4]
293
294
	paddd	mm4,mm7
295
	paddd	mm0,mm7
296
	psrad	mm4,DESCALE_P1_4
297
	psrad	mm0,DESCALE_P1_4
298
	paddd	mm2,mm7
299
	paddd	mm3,mm7
300
	psrad	mm2,DESCALE_P1_4
301
	psrad	mm3,DESCALE_P1_4
302
303
	packssdw  mm4,mm0		; mm4=data1=(10 11 12 13)
304
	packssdw  mm2,mm3		; mm2=data2=(20 21 22 23)
305
306
	movq      mm6,mm1		; transpose coefficients(phase 1)
307
	punpcklwd mm1,mm4		; mm1=(00 10 01 11)
308
	punpckhwd mm6,mm4		; mm6=(02 12 03 13)
309
	movq      mm7,mm2		; transpose coefficients(phase 1)
310
	punpcklwd mm2,mm5		; mm2=(20 30 21 31)
311
	punpckhwd mm7,mm5		; mm7=(22 32 23 33)
312
313
	movq      mm0,mm1		; transpose coefficients(phase 2)
314
	punpckldq mm1,mm2		; mm1=(00 10 20 30)
315
	punpckhdq mm0,mm2		; mm0=(01 11 21 31)
316
	movq      mm3,mm6		; transpose coefficients(phase 2)
317
	punpckldq mm6,mm7		; mm6=(02 12 22 32)
318
	punpckhdq mm3,mm7		; mm3=(03 13 23 33)
319
320
	movq	MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm1
321
	movq	MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm0
322
	movq	MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm6
323
	movq	MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3
324
325
.nextcolumn:
326
	add	esi, byte 4*SIZEOF_JCOEF		; coef_block
327
	add	edx, byte 4*SIZEOF_ISLOW_MULT_TYPE	; quantptr
328
	add	edi, byte 4*DCTSIZE*SIZEOF_JCOEF	; wsptr
329
	dec	ecx					; ctr
330
	jnz	near .columnloop
331
332
	; ---- Pass 2: process rows from work array, store into output array.
333
334
	mov	eax, [original_ebp]
335
	lea	esi, [workspace]			; JCOEF * wsptr
336
	mov	edi, JSAMPARRAY [output_buf(eax)]	; (JSAMPROW *)
337
	mov	eax, JDIMENSION [output_col(eax)]
338
339
	; -- Odd part
340
341
	movq	mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
342
	movq	mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
343
	movq	mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
344
	movq	mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
345
346
	movq      mm4,mm0
347
	movq      mm5,mm0
348
	punpcklwd mm4,mm1
349
	punpckhwd mm5,mm1
350
	movq      mm0,mm4
351
	movq      mm1,mm5
352
	pmaddwd   mm4,[GOTOFF(ebx,PW_F256_F089)]	; mm4=(tmp2L)
353
	pmaddwd   mm5,[GOTOFF(ebx,PW_F256_F089)]	; mm5=(tmp2H)
354
	pmaddwd   mm0,[GOTOFF(ebx,PW_F106_MF217)]	; mm0=(tmp0L)
355
	pmaddwd   mm1,[GOTOFF(ebx,PW_F106_MF217)]	; mm1=(tmp0H)
356
357
	movq      mm6,mm2
358
	movq      mm7,mm2
359
	punpcklwd mm6,mm3
360
	punpckhwd mm7,mm3
361
	movq      mm2,mm6
362
	movq      mm3,mm7
363
	pmaddwd   mm6,[GOTOFF(ebx,PW_MF060_MF050)]	; mm6=(tmp2L)
364
	pmaddwd   mm7,[GOTOFF(ebx,PW_MF060_MF050)]	; mm7=(tmp2H)
365
	pmaddwd   mm2,[GOTOFF(ebx,PW_F145_MF021)]	; mm2=(tmp0L)
366
	pmaddwd   mm3,[GOTOFF(ebx,PW_F145_MF021)]	; mm3=(tmp0H)
367
368
	paddd	mm6,mm4			; mm6=tmp2L
369
	paddd	mm7,mm5			; mm7=tmp2H
370
	paddd	mm2,mm0			; mm2=tmp0L
371
	paddd	mm3,mm1			; mm3=tmp0H
372
373
	movq	MMWORD [wk(0)], mm2	; wk(0)=tmp0L
374
	movq	MMWORD [wk(1)], mm3	; wk(1)=tmp0H
375
376
	; -- Even part
377
378
	movq	mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
379
	movq	mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
380
	movq	mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
381
382
	pxor      mm1,mm1
383
	pxor      mm2,mm2
384
	punpcklwd mm1,mm4		; mm1=tmp0L
385
	punpckhwd mm2,mm4		; mm2=tmp0H
386
	psrad     mm1,(16-CONST_BITS-1)	; psrad mm1,16 & pslld mm1,CONST_BITS+1
387
	psrad     mm2,(16-CONST_BITS-1)	; psrad mm2,16 & pslld mm2,CONST_BITS+1
388
389
	movq      mm3,mm5		; mm5=in2=z2
390
	punpcklwd mm5,mm0		; mm0=in6=z3
391
	punpckhwd mm3,mm0
392
	pmaddwd   mm5,[GOTOFF(ebx,PW_F184_MF076)]	; mm5=tmp2L
393
	pmaddwd   mm3,[GOTOFF(ebx,PW_F184_MF076)]	; mm3=tmp2H
394
395
	movq	mm4,mm1
396
	movq	mm0,mm2
397
	paddd	mm1,mm5			; mm1=tmp10L
398
	paddd	mm2,mm3			; mm2=tmp10H
399
	psubd	mm4,mm5			; mm4=tmp12L
400
	psubd	mm0,mm3			; mm0=tmp12H
401
402
	; -- Final output stage
403
404
	movq	mm5,mm1
405
	movq	mm3,mm2
406
	paddd	mm1,mm6			; mm1=data0L
407
	paddd	mm2,mm7			; mm2=data0H
408
	psubd	mm5,mm6			; mm5=data3L
409
	psubd	mm3,mm7			; mm3=data3H
410
411
	movq	mm6,[GOTOFF(ebx,PD_DESCALE_P2_4)]	; mm6=[PD_DESCALE_P2_4]
412
413
	paddd	mm1,mm6
414
	paddd	mm2,mm6
415
	psrad	mm1,DESCALE_P2_4
416
	psrad	mm2,DESCALE_P2_4
417
	paddd	mm5,mm6
418
	paddd	mm3,mm6
419
	psrad	mm5,DESCALE_P2_4
420
	psrad	mm3,DESCALE_P2_4
421
422
	packssdw  mm1,mm2		; mm1=data0=(00 10 20 30)
423
	packssdw  mm5,mm3		; mm5=data3=(03 13 23 33)
424
425
	movq	mm7, MMWORD [wk(0)]	; mm7=tmp0L
426
	movq	mm6, MMWORD [wk(1)]	; mm6=tmp0H
427
428
	movq	mm2,mm4
429
	movq	mm3,mm0
430
	paddd	mm4,mm7			; mm4=data1L
431
	paddd	mm0,mm6			; mm0=data1H
432
	psubd	mm2,mm7			; mm2=data2L
433
	psubd	mm3,mm6			; mm3=data2H
434
435
	movq	mm7,[GOTOFF(ebx,PD_DESCALE_P2_4)]	; mm7=[PD_DESCALE_P2_4]
436
437
	paddd	mm4,mm7
438
	paddd	mm0,mm7
439
	psrad	mm4,DESCALE_P2_4
440
	psrad	mm0,DESCALE_P2_4
441
	paddd	mm2,mm7
442
	paddd	mm3,mm7
443
	psrad	mm2,DESCALE_P2_4
444
	psrad	mm3,DESCALE_P2_4
445
446
	packssdw  mm4,mm0		; mm4=data1=(01 11 21 31)
447
	packssdw  mm2,mm3		; mm2=data2=(02 12 22 32)
448
449
	movq      mm6,[GOTOFF(ebx,PB_CENTERJSAMP)]	; mm6=[PB_CENTERJSAMP]
450
451
	packsswb  mm1,mm2		; mm1=(00 10 20 30 02 12 22 32)
452
	packsswb  mm4,mm5		; mm4=(01 11 21 31 03 13 23 33)
453
	paddb     mm1,mm6
454
	paddb     mm4,mm6
455
456
	movq      mm7,mm1		; transpose coefficients(phase 1)
457
	punpcklbw mm1,mm4		; mm1=(00 01 10 11 20 21 30 31)
458
	punpckhbw mm7,mm4		; mm7=(02 03 12 13 22 23 32 33)
459
460
	movq      mm0,mm1		; transpose coefficients(phase 2)
461
	punpcklwd mm1,mm7		; mm1=(00 01 02 03 10 11 12 13)
462
	punpckhwd mm0,mm7		; mm0=(20 21 22 23 30 31 32 33)
463
464
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
465
	mov	esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
466
	movd	DWORD [edx+eax*SIZEOF_JSAMPLE], mm1
467
	movd	DWORD [esi+eax*SIZEOF_JSAMPLE], mm0
468
469
	psrlq	mm1,4*BYTE_BIT
470
	psrlq	mm0,4*BYTE_BIT
471
472
	mov	edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
473
	mov	esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
474
	movd	DWORD [edx+eax*SIZEOF_JSAMPLE], mm1
475
	movd	DWORD [esi+eax*SIZEOF_JSAMPLE], mm0
476
477
	emms		; empty MMX state
478
479
	pop	edi
480
	pop	esi
481
;	pop	edx		; need not be preserved
482
;	pop	ecx		; need not be preserved
483
	poppic	ebx
484
	mov	esp,ebp		; esp <- aligned ebp
485
	pop	esp		; esp <- original ebp
486
	pop	ebp
487
	ret
488
489
490
; --------------------------------------------------------------------------
491
;
492
; Perform dequantization and inverse DCT on one block of coefficients,
493
; producing a reduced-size 2x2 output block.
494
;
495
; GLOBAL(void)
496
; jsimd_idct_2x2_mmx (void * dct_table, JCOEFPTR coef_block,
497
;                     JSAMPARRAY output_buf, JDIMENSION output_col)
498
;
499
500
%define dct_table(b)	(b)+8			; void * dct_table
501
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
502
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
503
%define output_col(b)	(b)+20		; JDIMENSION output_col
504
505
	align	16
506
	global	EXTN(jsimd_idct_2x2_mmx)
507
508
EXTN(jsimd_idct_2x2_mmx):
509
	push	ebp
510
	mov	ebp,esp
511
	push	ebx
512
;	push	ecx		; need not be preserved
513
;	push	edx		; need not be preserved
514
	push	esi
515
	push	edi
516
517
	get_GOT	ebx		; get GOT address
518
519
	; ---- Pass 1: process columns from input.
520
521
	mov	edx, POINTER [dct_table(ebp)]	; quantptr
522
	mov	esi, JCOEFPTR [coef_block(ebp)]		; inptr
523
524
	; | input:                  | result:        |
525
	; | 00 01 ** 03 ** 05 ** 07 |                |
526
	; | 10 11 ** 13 ** 15 ** 17 |                |
527
	; | ** ** ** ** ** ** ** ** |                |
528
	; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 |
529
	; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 |
530
	; | 50 51 ** 53 ** 55 ** 57 |                |
531
	; | ** ** ** ** ** ** ** ** |                |
532
	; | 70 71 ** 73 ** 75 ** 77 |                |
533
534
	; -- Odd part
535
536
	movq	mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
537
	movq	mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
538
	pmullw	mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
539
	pmullw	mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
540
	movq	mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
541
	movq	mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
542
	pmullw	mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
543
	pmullw	mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
544
545
	; mm0=(10 11 ** 13), mm1=(30 31 ** 33)
546
	; mm2=(50 51 ** 53), mm3=(70 71 ** 73)
547
548
	pcmpeqd   mm7,mm7
549
	pslld     mm7,WORD_BIT		; mm7={0x0000 0xFFFF 0x0000 0xFFFF}
550
551
	movq      mm4,mm0		; mm4=(10 11 ** 13)
552
	movq      mm5,mm2		; mm5=(50 51 ** 53)
553
	punpcklwd mm4,mm1		; mm4=(10 30 11 31)
554
	punpcklwd mm5,mm3		; mm5=(50 70 51 71)
555
	pmaddwd   mm4,[GOTOFF(ebx,PW_F362_MF127)]
556
	pmaddwd   mm5,[GOTOFF(ebx,PW_F085_MF072)]
557
558
	psrld	mm0,WORD_BIT		; mm0=(11 -- 13 --)
559
	pand	mm1,mm7			; mm1=(-- 31 -- 33)
560
	psrld	mm2,WORD_BIT		; mm2=(51 -- 53 --)
561
	pand	mm3,mm7			; mm3=(-- 71 -- 73)
562
	por	mm0,mm1			; mm0=(11 31 13 33)
563
	por	mm2,mm3			; mm2=(51 71 53 73)
564
	pmaddwd	mm0,[GOTOFF(ebx,PW_F362_MF127)]
565
	pmaddwd	mm2,[GOTOFF(ebx,PW_F085_MF072)]
566
567
	paddd	mm4,mm5			; mm4=tmp0[col0 col1]
568
569
	movq	mm6, MMWORD [MMBLOCK(1,1,esi,SIZEOF_JCOEF)]
570
	movq	mm1, MMWORD [MMBLOCK(3,1,esi,SIZEOF_JCOEF)]
571
	pmullw	mm6, MMWORD [MMBLOCK(1,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
572
	pmullw	mm1, MMWORD [MMBLOCK(3,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
573
	movq	mm3, MMWORD [MMBLOCK(5,1,esi,SIZEOF_JCOEF)]
574
	movq	mm5, MMWORD [MMBLOCK(7,1,esi,SIZEOF_JCOEF)]
575
	pmullw	mm3, MMWORD [MMBLOCK(5,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
576
	pmullw	mm5, MMWORD [MMBLOCK(7,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
577
578
	; mm6=(** 15 ** 17), mm1=(** 35 ** 37)
579
	; mm3=(** 55 ** 57), mm5=(** 75 ** 77)
580
581
	psrld	mm6,WORD_BIT		; mm6=(15 -- 17 --)
582
	pand	mm1,mm7			; mm1=(-- 35 -- 37)
583
	psrld	mm3,WORD_BIT		; mm3=(55 -- 57 --)
584
	pand	mm5,mm7			; mm5=(-- 75 -- 77)
585
	por	mm6,mm1			; mm6=(15 35 17 37)
586
	por	mm3,mm5			; mm3=(55 75 57 77)
587
	pmaddwd	mm6,[GOTOFF(ebx,PW_F362_MF127)]
588
	pmaddwd	mm3,[GOTOFF(ebx,PW_F085_MF072)]
589
590
	paddd	mm0,mm2			; mm0=tmp0[col1 col3]
591
	paddd	mm6,mm3			; mm6=tmp0[col5 col7]
592
593
	; -- Even part
594
595
	movq	mm1, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
596
	movq	mm5, MMWORD [MMBLOCK(0,1,esi,SIZEOF_JCOEF)]
597
	pmullw	mm1, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
598
	pmullw	mm5, MMWORD [MMBLOCK(0,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
599
600
	; mm1=(00 01 ** 03), mm5=(** 05 ** 07)
601
602
	movq	mm2,mm1				; mm2=(00 01 ** 03)
603
	pslld	mm1,WORD_BIT			; mm1=(-- 00 -- **)
604
	psrad	mm1,(WORD_BIT-CONST_BITS-2)	; mm1=tmp10[col0 ****]
605
606
	pand	mm2,mm7				; mm2=(-- 01 -- 03)
607
	pand	mm5,mm7				; mm5=(-- 05 -- 07)
608
	psrad	mm2,(WORD_BIT-CONST_BITS-2)	; mm2=tmp10[col1 col3]
609
	psrad	mm5,(WORD_BIT-CONST_BITS-2)	; mm5=tmp10[col5 col7]
610
611
	; -- Final output stage
612
613
	movq      mm3,mm1
614
	paddd     mm1,mm4		; mm1=data0[col0 ****]=(A0 **)
615
	psubd     mm3,mm4		; mm3=data1[col0 ****]=(B0 **)
616
	punpckldq mm1,mm3		; mm1=(A0 B0)
617
618
	movq	mm7,[GOTOFF(ebx,PD_DESCALE_P1_2)]	; mm7=[PD_DESCALE_P1_2]
619
620
	movq	mm4,mm2
621
	movq	mm3,mm5
622
	paddd	mm2,mm0			; mm2=data0[col1 col3]=(A1 A3)
623
	paddd	mm5,mm6			; mm5=data0[col5 col7]=(A5 A7)
624
	psubd	mm4,mm0			; mm4=data1[col1 col3]=(B1 B3)
625
	psubd	mm3,mm6			; mm3=data1[col5 col7]=(B5 B7)
626
627
	paddd	mm1,mm7
628
	psrad	mm1,DESCALE_P1_2
629
630
	paddd	mm2,mm7
631
	paddd	mm5,mm7
632
	psrad	mm2,DESCALE_P1_2
633
	psrad	mm5,DESCALE_P1_2
634
	paddd	mm4,mm7
635
	paddd	mm3,mm7
636
	psrad	mm4,DESCALE_P1_2
637
	psrad	mm3,DESCALE_P1_2
638
639
	; ---- Pass 2: process rows, store into output array.
640
641
	mov	edi, JSAMPARRAY [output_buf(ebp)]	; (JSAMPROW *)
642
	mov	eax, JDIMENSION [output_col(ebp)]
643
644
	; | input:| result:|
645
	; | A0 B0 |        |
646
	; | A1 B1 | C0 C1  |
647
	; | A3 B3 | D0 D1  |
648
	; | A5 B5 |        |
649
	; | A7 B7 |        |
650
651
	; -- Odd part
652
653
	packssdw  mm2,mm4		; mm2=(A1 A3 B1 B3)
654
	packssdw  mm5,mm3		; mm5=(A5 A7 B5 B7)
655
	pmaddwd   mm2,[GOTOFF(ebx,PW_F362_MF127)]
656
	pmaddwd   mm5,[GOTOFF(ebx,PW_F085_MF072)]
657
658
	paddd     mm2,mm5		; mm2=tmp0[row0 row1]
659
660
	; -- Even part
661
662
	pslld     mm1,(CONST_BITS+2)	; mm1=tmp10[row0 row1]
663
664
	; -- Final output stage
665
666
	movq      mm0,[GOTOFF(ebx,PD_DESCALE_P2_2)]	; mm0=[PD_DESCALE_P2_2]
667
668
	movq      mm6,mm1
669
	paddd     mm1,mm2		; mm1=data0[row0 row1]=(C0 C1)
670
	psubd     mm6,mm2		; mm6=data1[row0 row1]=(D0 D1)
671
672
	paddd     mm1,mm0
673
	paddd     mm6,mm0
674
	psrad     mm1,DESCALE_P2_2
675
	psrad     mm6,DESCALE_P2_2
676
677
	movq      mm7,mm1		; transpose coefficients
678
	punpckldq mm1,mm6		; mm1=(C0 D0)
679
	punpckhdq mm7,mm6		; mm7=(C1 D1)
680
681
	packssdw  mm1,mm7		; mm1=(C0 D0 C1 D1)
682
	packsswb  mm1,mm1		; mm1=(C0 D0 C1 D1 C0 D0 C1 D1)
683
	paddb     mm1,[GOTOFF(ebx,PB_CENTERJSAMP)]
684
685
	movd	ecx,mm1
686
	movd	ebx,mm1			; ebx=(C0 D0 C1 D1)
687
	shr	ecx,2*BYTE_BIT		; ecx=(C1 D1 -- --)
688
689
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
690
	mov	esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
691
	mov	WORD [edx+eax*SIZEOF_JSAMPLE], bx
692
	mov	WORD [esi+eax*SIZEOF_JSAMPLE], cx
693
694
	emms		; empty MMX state
695
696
	pop	edi
697
	pop	esi
698
;	pop	edx		; need not be preserved
699
;	pop	ecx		; need not be preserved
700
	pop	ebx
701
	pop	ebp
702
	ret
703
704
; For some reason, the OS X linker does not honor the request to align the
705
; segment unless we do this.
706
	align	16
(-)a/jpeg/simd/jiss2flt-64.asm (+483 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jiss2flt-64.asm - floating-point IDCT (64-bit SSE & SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; This file contains a floating-point implementation of the inverse DCT
19
; (Discrete Cosine Transform). The following code is based directly on
20
; the IJG's original jidctflt.c; see the jidctflt.c for more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%macro	unpcklps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5)
30
	shufps	%1,%2,0x44
31
%endmacro
32
33
%macro	unpckhps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7)
34
	shufps	%1,%2,0xEE
35
%endmacro
36
37
; --------------------------------------------------------------------------
38
	SECTION	SEG_CONST
39
40
	alignz	16
41
	global	EXTN(jconst_idct_float_sse2)
42
43
EXTN(jconst_idct_float_sse2):
44
45
PD_1_414	times 4 dd  1.414213562373095048801689
46
PD_1_847	times 4 dd  1.847759065022573512256366
47
PD_1_082	times 4 dd  1.082392200292393968799446
48
PD_M2_613	times 4 dd -2.613125929752753055713286
49
PD_RNDINT_MAGIC	times 4 dd  100663296.0	; (float)(0x00C00000 << 3)
50
PB_CENTERJSAMP	times 16 db CENTERJSAMPLE
51
52
	alignz	16
53
54
; --------------------------------------------------------------------------
55
	SECTION	SEG_TEXT
56
	BITS	64
57
;
58
; Perform dequantization and inverse DCT on one block of coefficients.
59
;
60
; GLOBAL(void)
61
; jsimd_idct_float_sse2 (void * dct_table, JCOEFPTR coef_block,
62
;                        JSAMPARRAY output_buf, JDIMENSION output_col)
63
;
64
65
; r10 = void * dct_table
66
; r11 = JCOEFPTR coef_block
67
; r12 = JSAMPARRAY output_buf
68
; r13 = JDIMENSION output_col
69
70
%define original_rbp	rbp+0
71
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
72
%define WK_NUM		2
73
%define workspace	wk(0)-DCTSIZE2*SIZEOF_FAST_FLOAT
74
					; FAST_FLOAT workspace[DCTSIZE2]
75
76
	align	16
77
	global	EXTN(jsimd_idct_float_sse2)
78
79
EXTN(jsimd_idct_float_sse2):
80
	push	rbp
81
	mov	rax,rsp				; rax = original rbp
82
	sub	rsp, byte 4
83
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
84
	mov	[rsp],rax
85
	mov	rbp,rsp				; rbp = aligned rbp
86
	lea	rsp, [workspace]
87
	collect_args
88
	push	rbx
89
90
	; ---- Pass 1: process columns from input, store into work array.
91
92
	mov	rdx, r10	; quantptr
93
	mov	rsi, r11		; inptr
94
	lea	rdi, [workspace]			; FAST_FLOAT * wsptr
95
	mov	rcx, DCTSIZE/4				; ctr
96
.columnloop:
97
%ifndef NO_ZERO_COLUMN_TEST_FLOAT_SSE
98
	mov	eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
99
	or	eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
100
	jnz	near .columnDCT
101
102
	movq	xmm1, XMM_MMWORD [MMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
103
	movq	xmm2, XMM_MMWORD [MMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
104
	movq	xmm3, XMM_MMWORD [MMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
105
	movq	xmm4, XMM_MMWORD [MMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
106
	movq	xmm5, XMM_MMWORD [MMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
107
	movq	xmm6, XMM_MMWORD [MMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
108
	movq	xmm7, XMM_MMWORD [MMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
109
	por	xmm1,xmm2
110
	por	xmm3,xmm4
111
	por	xmm5,xmm6
112
	por	xmm1,xmm3
113
	por	xmm5,xmm7
114
	por	xmm1,xmm5
115
	packsswb xmm1,xmm1
116
	movd	eax,xmm1
117
	test	rax,rax
118
	jnz	short .columnDCT
119
120
	; -- AC terms all zero
121
122
	movq      xmm0, XMM_MMWORD [MMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
123
124
	punpcklwd xmm0,xmm0		; xmm0=(00 00 01 01 02 02 03 03)
125
	psrad     xmm0,(DWORD_BIT-WORD_BIT)	; xmm0=in0=(00 01 02 03)
126
	cvtdq2ps  xmm0,xmm0			; xmm0=in0=(00 01 02 03)
127
128
	mulps	xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
129
130
	movaps	xmm1,xmm0
131
	movaps	xmm2,xmm0
132
	movaps	xmm3,xmm0
133
134
	shufps	xmm0,xmm0,0x00			; xmm0=(00 00 00 00)
135
	shufps	xmm1,xmm1,0x55			; xmm1=(01 01 01 01)
136
	shufps	xmm2,xmm2,0xAA			; xmm2=(02 02 02 02)
137
	shufps	xmm3,xmm3,0xFF			; xmm3=(03 03 03 03)
138
139
	movaps	XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm0
140
	movaps	XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm0
141
	movaps	XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm1
142
	movaps	XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm1
143
	movaps	XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_FAST_FLOAT)], xmm2
144
	movaps	XMMWORD [XMMBLOCK(2,1,rdi,SIZEOF_FAST_FLOAT)], xmm2
145
	movaps	XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_FAST_FLOAT)], xmm3
146
	movaps	XMMWORD [XMMBLOCK(3,1,rdi,SIZEOF_FAST_FLOAT)], xmm3
147
	jmp	near .nextcolumn
148
%endif
149
.columnDCT:
150
151
	; -- Even part
152
153
	movq      xmm0, XMM_MMWORD [MMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
154
	movq      xmm1, XMM_MMWORD [MMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
155
	movq      xmm2, XMM_MMWORD [MMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
156
	movq      xmm3, XMM_MMWORD [MMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
157
158
	punpcklwd xmm0,xmm0		; xmm0=(00 00 01 01 02 02 03 03)
159
	punpcklwd xmm1,xmm1		; xmm1=(20 20 21 21 22 22 23 23)
160
	psrad     xmm0,(DWORD_BIT-WORD_BIT)	; xmm0=in0=(00 01 02 03)
161
	psrad     xmm1,(DWORD_BIT-WORD_BIT)	; xmm1=in2=(20 21 22 23)
162
	cvtdq2ps  xmm0,xmm0			; xmm0=in0=(00 01 02 03)
163
	cvtdq2ps  xmm1,xmm1			; xmm1=in2=(20 21 22 23)
164
165
	punpcklwd xmm2,xmm2		; xmm2=(40 40 41 41 42 42 43 43)
166
	punpcklwd xmm3,xmm3		; xmm3=(60 60 61 61 62 62 63 63)
167
	psrad     xmm2,(DWORD_BIT-WORD_BIT)	; xmm2=in4=(40 41 42 43)
168
	psrad     xmm3,(DWORD_BIT-WORD_BIT)	; xmm3=in6=(60 61 62 63)
169
	cvtdq2ps  xmm2,xmm2			; xmm2=in4=(40 41 42 43)
170
	cvtdq2ps  xmm3,xmm3			; xmm3=in6=(60 61 62 63)
171
172
	mulps     xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
173
	mulps     xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
174
	mulps     xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
175
	mulps     xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
176
177
	movaps	xmm4,xmm0
178
	movaps	xmm5,xmm1
179
	subps	xmm0,xmm2		; xmm0=tmp11
180
	subps	xmm1,xmm3
181
	addps	xmm4,xmm2		; xmm4=tmp10
182
	addps	xmm5,xmm3		; xmm5=tmp13
183
184
	mulps	xmm1,[rel PD_1_414]
185
	subps	xmm1,xmm5		; xmm1=tmp12
186
187
	movaps	xmm6,xmm4
188
	movaps	xmm7,xmm0
189
	subps	xmm4,xmm5		; xmm4=tmp3
190
	subps	xmm0,xmm1		; xmm0=tmp2
191
	addps	xmm6,xmm5		; xmm6=tmp0
192
	addps	xmm7,xmm1		; xmm7=tmp1
193
194
	movaps	XMMWORD [wk(1)], xmm4	; tmp3
195
	movaps	XMMWORD [wk(0)], xmm0	; tmp2
196
197
	; -- Odd part
198
199
	movq      xmm2, XMM_MMWORD [MMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
200
	movq      xmm3, XMM_MMWORD [MMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
201
	movq      xmm5, XMM_MMWORD [MMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
202
	movq      xmm1, XMM_MMWORD [MMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
203
204
	punpcklwd xmm2,xmm2		; xmm2=(10 10 11 11 12 12 13 13)
205
	punpcklwd xmm3,xmm3		; xmm3=(30 30 31 31 32 32 33 33)
206
	psrad     xmm2,(DWORD_BIT-WORD_BIT)	; xmm2=in1=(10 11 12 13)
207
	psrad     xmm3,(DWORD_BIT-WORD_BIT)	; xmm3=in3=(30 31 32 33)
208
	cvtdq2ps  xmm2,xmm2			; xmm2=in1=(10 11 12 13)
209
	cvtdq2ps  xmm3,xmm3			; xmm3=in3=(30 31 32 33)
210
211
	punpcklwd xmm5,xmm5		; xmm5=(50 50 51 51 52 52 53 53)
212
	punpcklwd xmm1,xmm1		; xmm1=(70 70 71 71 72 72 73 73)
213
	psrad     xmm5,(DWORD_BIT-WORD_BIT)	; xmm5=in5=(50 51 52 53)
214
	psrad     xmm1,(DWORD_BIT-WORD_BIT)	; xmm1=in7=(70 71 72 73)
215
	cvtdq2ps  xmm5,xmm5			; xmm5=in5=(50 51 52 53)
216
	cvtdq2ps  xmm1,xmm1			; xmm1=in7=(70 71 72 73)
217
218
	mulps     xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
219
	mulps     xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
220
	mulps     xmm5, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
221
	mulps     xmm1, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_FLOAT_MULT_TYPE)]
222
223
	movaps	xmm4,xmm2
224
	movaps	xmm0,xmm5
225
	addps	xmm2,xmm1		; xmm2=z11
226
	addps	xmm5,xmm3		; xmm5=z13
227
	subps	xmm4,xmm1		; xmm4=z12
228
	subps	xmm0,xmm3		; xmm0=z10
229
230
	movaps	xmm1,xmm2
231
	subps	xmm2,xmm5
232
	addps	xmm1,xmm5		; xmm1=tmp7
233
234
	mulps	xmm2,[rel PD_1_414]	; xmm2=tmp11
235
236
	movaps	xmm3,xmm0
237
	addps	xmm0,xmm4
238
	mulps	xmm0,[rel PD_1_847]	; xmm0=z5
239
	mulps	xmm3,[rel PD_M2_613]	; xmm3=(z10 * -2.613125930)
240
	mulps	xmm4,[rel PD_1_082]	; xmm4=(z12 * 1.082392200)
241
	addps	xmm3,xmm0		; xmm3=tmp12
242
	subps	xmm4,xmm0		; xmm4=tmp10
243
244
	; -- Final output stage
245
246
	subps	xmm3,xmm1		; xmm3=tmp6
247
	movaps	xmm5,xmm6
248
	movaps	xmm0,xmm7
249
	addps	xmm6,xmm1		; xmm6=data0=(00 01 02 03)
250
	addps	xmm7,xmm3		; xmm7=data1=(10 11 12 13)
251
	subps	xmm5,xmm1		; xmm5=data7=(70 71 72 73)
252
	subps	xmm0,xmm3		; xmm0=data6=(60 61 62 63)
253
	subps	xmm2,xmm3		; xmm2=tmp5
254
255
	movaps    xmm1,xmm6		; transpose coefficients(phase 1)
256
	unpcklps  xmm6,xmm7		; xmm6=(00 10 01 11)
257
	unpckhps  xmm1,xmm7		; xmm1=(02 12 03 13)
258
	movaps    xmm3,xmm0		; transpose coefficients(phase 1)
259
	unpcklps  xmm0,xmm5		; xmm0=(60 70 61 71)
260
	unpckhps  xmm3,xmm5		; xmm3=(62 72 63 73)
261
262
	movaps	xmm7, XMMWORD [wk(0)]	; xmm7=tmp2
263
	movaps	xmm5, XMMWORD [wk(1)]	; xmm5=tmp3
264
265
	movaps	XMMWORD [wk(0)], xmm0	; wk(0)=(60 70 61 71)
266
	movaps	XMMWORD [wk(1)], xmm3	; wk(1)=(62 72 63 73)
267
268
	addps	xmm4,xmm2		; xmm4=tmp4
269
	movaps	xmm0,xmm7
270
	movaps	xmm3,xmm5
271
	addps	xmm7,xmm2		; xmm7=data2=(20 21 22 23)
272
	addps	xmm5,xmm4		; xmm5=data4=(40 41 42 43)
273
	subps	xmm0,xmm2		; xmm0=data5=(50 51 52 53)
274
	subps	xmm3,xmm4		; xmm3=data3=(30 31 32 33)
275
276
	movaps    xmm2,xmm7		; transpose coefficients(phase 1)
277
	unpcklps  xmm7,xmm3		; xmm7=(20 30 21 31)
278
	unpckhps  xmm2,xmm3		; xmm2=(22 32 23 33)
279
	movaps    xmm4,xmm5		; transpose coefficients(phase 1)
280
	unpcklps  xmm5,xmm0		; xmm5=(40 50 41 51)
281
	unpckhps  xmm4,xmm0		; xmm4=(42 52 43 53)
282
283
	movaps    xmm3,xmm6		; transpose coefficients(phase 2)
284
	unpcklps2 xmm6,xmm7		; xmm6=(00 10 20 30)
285
	unpckhps2 xmm3,xmm7		; xmm3=(01 11 21 31)
286
	movaps    xmm0,xmm1		; transpose coefficients(phase 2)
287
	unpcklps2 xmm1,xmm2		; xmm1=(02 12 22 32)
288
	unpckhps2 xmm0,xmm2		; xmm0=(03 13 23 33)
289
290
	movaps	xmm7, XMMWORD [wk(0)]	; xmm7=(60 70 61 71)
291
	movaps	xmm2, XMMWORD [wk(1)]	; xmm2=(62 72 63 73)
292
293
	movaps	XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm6
294
	movaps	XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm3
295
	movaps	XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_FAST_FLOAT)], xmm1
296
	movaps	XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_FAST_FLOAT)], xmm0
297
298
	movaps    xmm6,xmm5		; transpose coefficients(phase 2)
299
	unpcklps2 xmm5,xmm7		; xmm5=(40 50 60 70)
300
	unpckhps2 xmm6,xmm7		; xmm6=(41 51 61 71)
301
	movaps    xmm3,xmm4		; transpose coefficients(phase 2)
302
	unpcklps2 xmm4,xmm2		; xmm4=(42 52 62 72)
303
	unpckhps2 xmm3,xmm2		; xmm3=(43 53 63 73)
304
305
	movaps	XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm5
306
	movaps	XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm6
307
	movaps	XMMWORD [XMMBLOCK(2,1,rdi,SIZEOF_FAST_FLOAT)], xmm4
308
	movaps	XMMWORD [XMMBLOCK(3,1,rdi,SIZEOF_FAST_FLOAT)], xmm3
309
310
.nextcolumn:
311
	add	rsi, byte 4*SIZEOF_JCOEF		; coef_block
312
	add	rdx, byte 4*SIZEOF_FLOAT_MULT_TYPE	; quantptr
313
	add	rdi,      4*DCTSIZE*SIZEOF_FAST_FLOAT	; wsptr
314
	dec	rcx					; ctr
315
	jnz	near .columnloop
316
317
	; -- Prefetch the next coefficient block
318
319
	prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32]
320
	prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32]
321
	prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32]
322
	prefetchnta [rsi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32]
323
324
	; ---- Pass 2: process rows from work array, store into output array.
325
326
	mov	rax, [original_rbp]
327
	lea	rsi, [workspace]			; FAST_FLOAT * wsptr
328
	mov	rdi, r12	; (JSAMPROW *)
329
	mov	rax, r13
330
	mov	rcx, DCTSIZE/4				; ctr
331
.rowloop:
332
333
	; -- Even part
334
335
	movaps	xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_FAST_FLOAT)]
336
	movaps	xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_FAST_FLOAT)]
337
	movaps	xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_FAST_FLOAT)]
338
	movaps	xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_FAST_FLOAT)]
339
340
	movaps	xmm4,xmm0
341
	movaps	xmm5,xmm1
342
	subps	xmm0,xmm2		; xmm0=tmp11
343
	subps	xmm1,xmm3
344
	addps	xmm4,xmm2		; xmm4=tmp10
345
	addps	xmm5,xmm3		; xmm5=tmp13
346
347
	mulps	xmm1,[rel PD_1_414]
348
	subps	xmm1,xmm5		; xmm1=tmp12
349
350
	movaps	xmm6,xmm4
351
	movaps	xmm7,xmm0
352
	subps	xmm4,xmm5		; xmm4=tmp3
353
	subps	xmm0,xmm1		; xmm0=tmp2
354
	addps	xmm6,xmm5		; xmm6=tmp0
355
	addps	xmm7,xmm1		; xmm7=tmp1
356
357
	movaps	XMMWORD [wk(1)], xmm4	; tmp3
358
	movaps	XMMWORD [wk(0)], xmm0	; tmp2
359
360
	; -- Odd part
361
362
	movaps	xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_FAST_FLOAT)]
363
	movaps	xmm3, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_FAST_FLOAT)]
364
	movaps	xmm5, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_FAST_FLOAT)]
365
	movaps	xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_FAST_FLOAT)]
366
367
	movaps	xmm4,xmm2
368
	movaps	xmm0,xmm5
369
	addps	xmm2,xmm1		; xmm2=z11
370
	addps	xmm5,xmm3		; xmm5=z13
371
	subps	xmm4,xmm1		; xmm4=z12
372
	subps	xmm0,xmm3		; xmm0=z10
373
374
	movaps	xmm1,xmm2
375
	subps	xmm2,xmm5
376
	addps	xmm1,xmm5		; xmm1=tmp7
377
378
	mulps	xmm2,[rel PD_1_414]	; xmm2=tmp11
379
380
	movaps	xmm3,xmm0
381
	addps	xmm0,xmm4
382
	mulps	xmm0,[rel PD_1_847]	; xmm0=z5
383
	mulps	xmm3,[rel PD_M2_613]	; xmm3=(z10 * -2.613125930)
384
	mulps	xmm4,[rel PD_1_082]	; xmm4=(z12 * 1.082392200)
385
	addps	xmm3,xmm0		; xmm3=tmp12
386
	subps	xmm4,xmm0		; xmm4=tmp10
387
388
	; -- Final output stage
389
390
	subps	xmm3,xmm1		; xmm3=tmp6
391
	movaps	xmm5,xmm6
392
	movaps	xmm0,xmm7
393
	addps	xmm6,xmm1		; xmm6=data0=(00 10 20 30)
394
	addps	xmm7,xmm3		; xmm7=data1=(01 11 21 31)
395
	subps	xmm5,xmm1		; xmm5=data7=(07 17 27 37)
396
	subps	xmm0,xmm3		; xmm0=data6=(06 16 26 36)
397
	subps	xmm2,xmm3		; xmm2=tmp5
398
399
	movaps	xmm1,[rel PD_RNDINT_MAGIC]	; xmm1=[rel PD_RNDINT_MAGIC]
400
	pcmpeqd	xmm3,xmm3
401
	psrld	xmm3,WORD_BIT		; xmm3={0xFFFF 0x0000 0xFFFF 0x0000 ..}
402
403
	addps	xmm6,xmm1	; xmm6=roundint(data0/8)=(00 ** 10 ** 20 ** 30 **)
404
	addps	xmm7,xmm1	; xmm7=roundint(data1/8)=(01 ** 11 ** 21 ** 31 **)
405
	addps	xmm0,xmm1	; xmm0=roundint(data6/8)=(06 ** 16 ** 26 ** 36 **)
406
	addps	xmm5,xmm1	; xmm5=roundint(data7/8)=(07 ** 17 ** 27 ** 37 **)
407
408
	pand	xmm6,xmm3		; xmm6=(00 -- 10 -- 20 -- 30 --)
409
	pslld	xmm7,WORD_BIT		; xmm7=(-- 01 -- 11 -- 21 -- 31)
410
	pand	xmm0,xmm3		; xmm0=(06 -- 16 -- 26 -- 36 --)
411
	pslld	xmm5,WORD_BIT		; xmm5=(-- 07 -- 17 -- 27 -- 37)
412
	por	xmm6,xmm7		; xmm6=(00 01 10 11 20 21 30 31)
413
	por	xmm0,xmm5		; xmm0=(06 07 16 17 26 27 36 37)
414
415
	movaps	xmm1, XMMWORD [wk(0)]	; xmm1=tmp2
416
	movaps	xmm3, XMMWORD [wk(1)]	; xmm3=tmp3
417
418
	addps	xmm4,xmm2		; xmm4=tmp4
419
	movaps	xmm7,xmm1
420
	movaps	xmm5,xmm3
421
	addps	xmm1,xmm2		; xmm1=data2=(02 12 22 32)
422
	addps	xmm3,xmm4		; xmm3=data4=(04 14 24 34)
423
	subps	xmm7,xmm2		; xmm7=data5=(05 15 25 35)
424
	subps	xmm5,xmm4		; xmm5=data3=(03 13 23 33)
425
426
	movaps	xmm2,[rel PD_RNDINT_MAGIC]	; xmm2=[rel PD_RNDINT_MAGIC]
427
	pcmpeqd	xmm4,xmm4
428
	psrld	xmm4,WORD_BIT		; xmm4={0xFFFF 0x0000 0xFFFF 0x0000 ..}
429
430
	addps	xmm3,xmm2	; xmm3=roundint(data4/8)=(04 ** 14 ** 24 ** 34 **)
431
	addps	xmm7,xmm2	; xmm7=roundint(data5/8)=(05 ** 15 ** 25 ** 35 **)
432
	addps	xmm1,xmm2	; xmm1=roundint(data2/8)=(02 ** 12 ** 22 ** 32 **)
433
	addps	xmm5,xmm2	; xmm5=roundint(data3/8)=(03 ** 13 ** 23 ** 33 **)
434
435
	pand	xmm3,xmm4		; xmm3=(04 -- 14 -- 24 -- 34 --)
436
	pslld	xmm7,WORD_BIT		; xmm7=(-- 05 -- 15 -- 25 -- 35)
437
	pand	xmm1,xmm4		; xmm1=(02 -- 12 -- 22 -- 32 --)
438
	pslld	xmm5,WORD_BIT		; xmm5=(-- 03 -- 13 -- 23 -- 33)
439
	por	xmm3,xmm7		; xmm3=(04 05 14 15 24 25 34 35)
440
	por	xmm1,xmm5		; xmm1=(02 03 12 13 22 23 32 33)
441
442
	movdqa    xmm2,[rel PB_CENTERJSAMP]	; xmm2=[rel PB_CENTERJSAMP]
443
444
	packsswb  xmm6,xmm3	; xmm6=(00 01 10 11 20 21 30 31 04 05 14 15 24 25 34 35)
445
	packsswb  xmm1,xmm0	; xmm1=(02 03 12 13 22 23 32 33 06 07 16 17 26 27 36 37)
446
	paddb     xmm6,xmm2
447
	paddb     xmm1,xmm2
448
449
	movdqa    xmm4,xmm6	; transpose coefficients(phase 2)
450
	punpcklwd xmm6,xmm1	; xmm6=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
451
	punpckhwd xmm4,xmm1	; xmm4=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
452
453
	movdqa    xmm7,xmm6	; transpose coefficients(phase 3)
454
	punpckldq xmm6,xmm4	; xmm6=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
455
	punpckhdq xmm7,xmm4	; xmm7=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
456
457
	pshufd	xmm5,xmm6,0x4E	; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
458
	pshufd	xmm3,xmm7,0x4E	; xmm3=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
459
460
	mov	rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
461
	mov	rbx, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
462
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6
463
	movq	XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE], xmm7
464
	mov	rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
465
	mov	rbx, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
466
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm5
467
	movq	XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE], xmm3
468
469
	add	rsi, byte 4*SIZEOF_FAST_FLOAT	; wsptr
470
	add	rdi, byte 4*SIZEOF_JSAMPROW
471
	dec	rcx				; ctr
472
	jnz	near .rowloop
473
474
	pop	rbx
475
	uncollect_args
476
	mov	rsp,rbp		; rsp <- aligned rbp
477
	pop	rsp		; rsp <- original rbp
478
	pop	rbp
479
	ret
480
481
; For some reason, the OS X linker does not honor the request to align the
482
; segment unless we do this.
483
	align	16
(-)a/jpeg/simd/jiss2flt.asm (+498 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jiss2flt.asm - floating-point IDCT (SSE & SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a floating-point implementation of the inverse DCT
18
; (Discrete Cosine Transform). The following code is based directly on
19
; the IJG's original jidctflt.c; see the jidctflt.c for more details.
20
;
21
; [TAB8]
22
23
%include "jsimdext.inc"
24
%include "jdct.inc"
25
26
; --------------------------------------------------------------------------
27
28
%macro	unpcklps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5)
29
	shufps	%1,%2,0x44
30
%endmacro
31
32
%macro	unpckhps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7)
33
	shufps	%1,%2,0xEE
34
%endmacro
35
36
; --------------------------------------------------------------------------
37
	SECTION	SEG_CONST
38
39
	alignz	16
40
	global	EXTN(jconst_idct_float_sse2)
41
42
EXTN(jconst_idct_float_sse2):
43
44
PD_1_414	times 4 dd  1.414213562373095048801689
45
PD_1_847	times 4 dd  1.847759065022573512256366
46
PD_1_082	times 4 dd  1.082392200292393968799446
47
PD_M2_613	times 4 dd -2.613125929752753055713286
48
PD_RNDINT_MAGIC	times 4 dd  100663296.0	; (float)(0x00C00000 << 3)
49
PB_CENTERJSAMP	times 16 db CENTERJSAMPLE
50
51
	alignz	16
52
53
; --------------------------------------------------------------------------
54
	SECTION	SEG_TEXT
55
	BITS	32
56
;
57
; Perform dequantization and inverse DCT on one block of coefficients.
58
;
59
; GLOBAL(void)
60
; jsimd_idct_float_sse2 (void * dct_table, JCOEFPTR coef_block,
61
;                        JSAMPARRAY output_buf, JDIMENSION output_col)
62
;
63
64
%define dct_table(b)	(b)+8			; void * dct_table
65
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
66
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
67
%define output_col(b)	(b)+20		; JDIMENSION output_col
68
69
%define original_ebp	ebp+0
70
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
71
%define WK_NUM		2
72
%define workspace	wk(0)-DCTSIZE2*SIZEOF_FAST_FLOAT
73
					; FAST_FLOAT workspace[DCTSIZE2]
74
75
	align	16
76
	global	EXTN(jsimd_idct_float_sse2)
77
78
EXTN(jsimd_idct_float_sse2):
79
	push	ebp
80
	mov	eax,esp				; eax = original ebp
81
	sub	esp, byte 4
82
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
83
	mov	[esp],eax
84
	mov	ebp,esp				; ebp = aligned ebp
85
	lea	esp, [workspace]
86
	push	ebx
87
;	push	ecx		; need not be preserved
88
;	push	edx		; need not be preserved
89
	push	esi
90
	push	edi
91
92
	get_GOT	ebx		; get GOT address
93
94
	; ---- Pass 1: process columns from input, store into work array.
95
96
;	mov	eax, [original_ebp]
97
	mov	edx, POINTER [dct_table(eax)]	; quantptr
98
	mov	esi, JCOEFPTR [coef_block(eax)]		; inptr
99
	lea	edi, [workspace]			; FAST_FLOAT * wsptr
100
	mov	ecx, DCTSIZE/4				; ctr
101
	alignx	16,7
102
.columnloop:
103
%ifndef NO_ZERO_COLUMN_TEST_FLOAT_SSE
104
	mov	eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
105
	or	eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
106
	jnz	near .columnDCT
107
108
	movq	xmm1, XMM_MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
109
	movq	xmm2, XMM_MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
110
	movq	xmm3, XMM_MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
111
	movq	xmm4, XMM_MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
112
	movq	xmm5, XMM_MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
113
	movq	xmm6, XMM_MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
114
	movq	xmm7, XMM_MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
115
	por	xmm1,xmm2
116
	por	xmm3,xmm4
117
	por	xmm5,xmm6
118
	por	xmm1,xmm3
119
	por	xmm5,xmm7
120
	por	xmm1,xmm5
121
	packsswb xmm1,xmm1
122
	movd	eax,xmm1
123
	test	eax,eax
124
	jnz	short .columnDCT
125
126
	; -- AC terms all zero
127
128
	movq      xmm0, XMM_MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
129
130
	punpcklwd xmm0,xmm0		; xmm0=(00 00 01 01 02 02 03 03)
131
	psrad     xmm0,(DWORD_BIT-WORD_BIT)	; xmm0=in0=(00 01 02 03)
132
	cvtdq2ps  xmm0,xmm0			; xmm0=in0=(00 01 02 03)
133
134
	mulps	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
135
136
	movaps	xmm1,xmm0
137
	movaps	xmm2,xmm0
138
	movaps	xmm3,xmm0
139
140
	shufps	xmm0,xmm0,0x00			; xmm0=(00 00 00 00)
141
	shufps	xmm1,xmm1,0x55			; xmm1=(01 01 01 01)
142
	shufps	xmm2,xmm2,0xAA			; xmm2=(02 02 02 02)
143
	shufps	xmm3,xmm3,0xFF			; xmm3=(03 03 03 03)
144
145
	movaps	XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm0
146
	movaps	XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0
147
	movaps	XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm1
148
	movaps	XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1
149
	movaps	XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm2
150
	movaps	XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm2
151
	movaps	XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm3
152
	movaps	XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3
153
	jmp	near .nextcolumn
154
	alignx	16,7
155
%endif
156
.columnDCT:
157
158
	; -- Even part
159
160
	movq      xmm0, XMM_MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
161
	movq      xmm1, XMM_MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
162
	movq      xmm2, XMM_MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
163
	movq      xmm3, XMM_MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
164
165
	punpcklwd xmm0,xmm0		; xmm0=(00 00 01 01 02 02 03 03)
166
	punpcklwd xmm1,xmm1		; xmm1=(20 20 21 21 22 22 23 23)
167
	psrad     xmm0,(DWORD_BIT-WORD_BIT)	; xmm0=in0=(00 01 02 03)
168
	psrad     xmm1,(DWORD_BIT-WORD_BIT)	; xmm1=in2=(20 21 22 23)
169
	cvtdq2ps  xmm0,xmm0			; xmm0=in0=(00 01 02 03)
170
	cvtdq2ps  xmm1,xmm1			; xmm1=in2=(20 21 22 23)
171
172
	punpcklwd xmm2,xmm2		; xmm2=(40 40 41 41 42 42 43 43)
173
	punpcklwd xmm3,xmm3		; xmm3=(60 60 61 61 62 62 63 63)
174
	psrad     xmm2,(DWORD_BIT-WORD_BIT)	; xmm2=in4=(40 41 42 43)
175
	psrad     xmm3,(DWORD_BIT-WORD_BIT)	; xmm3=in6=(60 61 62 63)
176
	cvtdq2ps  xmm2,xmm2			; xmm2=in4=(40 41 42 43)
177
	cvtdq2ps  xmm3,xmm3			; xmm3=in6=(60 61 62 63)
178
179
	mulps     xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
180
	mulps     xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
181
	mulps     xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
182
	mulps     xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
183
184
	movaps	xmm4,xmm0
185
	movaps	xmm5,xmm1
186
	subps	xmm0,xmm2		; xmm0=tmp11
187
	subps	xmm1,xmm3
188
	addps	xmm4,xmm2		; xmm4=tmp10
189
	addps	xmm5,xmm3		; xmm5=tmp13
190
191
	mulps	xmm1,[GOTOFF(ebx,PD_1_414)]
192
	subps	xmm1,xmm5		; xmm1=tmp12
193
194
	movaps	xmm6,xmm4
195
	movaps	xmm7,xmm0
196
	subps	xmm4,xmm5		; xmm4=tmp3
197
	subps	xmm0,xmm1		; xmm0=tmp2
198
	addps	xmm6,xmm5		; xmm6=tmp0
199
	addps	xmm7,xmm1		; xmm7=tmp1
200
201
	movaps	XMMWORD [wk(1)], xmm4	; tmp3
202
	movaps	XMMWORD [wk(0)], xmm0	; tmp2
203
204
	; -- Odd part
205
206
	movq      xmm2, XMM_MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
207
	movq      xmm3, XMM_MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
208
	movq      xmm5, XMM_MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
209
	movq      xmm1, XMM_MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
210
211
	punpcklwd xmm2,xmm2		; xmm2=(10 10 11 11 12 12 13 13)
212
	punpcklwd xmm3,xmm3		; xmm3=(30 30 31 31 32 32 33 33)
213
	psrad     xmm2,(DWORD_BIT-WORD_BIT)	; xmm2=in1=(10 11 12 13)
214
	psrad     xmm3,(DWORD_BIT-WORD_BIT)	; xmm3=in3=(30 31 32 33)
215
	cvtdq2ps  xmm2,xmm2			; xmm2=in1=(10 11 12 13)
216
	cvtdq2ps  xmm3,xmm3			; xmm3=in3=(30 31 32 33)
217
218
	punpcklwd xmm5,xmm5		; xmm5=(50 50 51 51 52 52 53 53)
219
	punpcklwd xmm1,xmm1		; xmm1=(70 70 71 71 72 72 73 73)
220
	psrad     xmm5,(DWORD_BIT-WORD_BIT)	; xmm5=in5=(50 51 52 53)
221
	psrad     xmm1,(DWORD_BIT-WORD_BIT)	; xmm1=in7=(70 71 72 73)
222
	cvtdq2ps  xmm5,xmm5			; xmm5=in5=(50 51 52 53)
223
	cvtdq2ps  xmm1,xmm1			; xmm1=in7=(70 71 72 73)
224
225
	mulps     xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
226
	mulps     xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
227
	mulps     xmm5, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
228
	mulps     xmm1, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
229
230
	movaps	xmm4,xmm2
231
	movaps	xmm0,xmm5
232
	addps	xmm2,xmm1		; xmm2=z11
233
	addps	xmm5,xmm3		; xmm5=z13
234
	subps	xmm4,xmm1		; xmm4=z12
235
	subps	xmm0,xmm3		; xmm0=z10
236
237
	movaps	xmm1,xmm2
238
	subps	xmm2,xmm5
239
	addps	xmm1,xmm5		; xmm1=tmp7
240
241
	mulps	xmm2,[GOTOFF(ebx,PD_1_414)]	; xmm2=tmp11
242
243
	movaps	xmm3,xmm0
244
	addps	xmm0,xmm4
245
	mulps	xmm0,[GOTOFF(ebx,PD_1_847)]	; xmm0=z5
246
	mulps	xmm3,[GOTOFF(ebx,PD_M2_613)]	; xmm3=(z10 * -2.613125930)
247
	mulps	xmm4,[GOTOFF(ebx,PD_1_082)]	; xmm4=(z12 * 1.082392200)
248
	addps	xmm3,xmm0		; xmm3=tmp12
249
	subps	xmm4,xmm0		; xmm4=tmp10
250
251
	; -- Final output stage
252
253
	subps	xmm3,xmm1		; xmm3=tmp6
254
	movaps	xmm5,xmm6
255
	movaps	xmm0,xmm7
256
	addps	xmm6,xmm1		; xmm6=data0=(00 01 02 03)
257
	addps	xmm7,xmm3		; xmm7=data1=(10 11 12 13)
258
	subps	xmm5,xmm1		; xmm5=data7=(70 71 72 73)
259
	subps	xmm0,xmm3		; xmm0=data6=(60 61 62 63)
260
	subps	xmm2,xmm3		; xmm2=tmp5
261
262
	movaps    xmm1,xmm6		; transpose coefficients(phase 1)
263
	unpcklps  xmm6,xmm7		; xmm6=(00 10 01 11)
264
	unpckhps  xmm1,xmm7		; xmm1=(02 12 03 13)
265
	movaps    xmm3,xmm0		; transpose coefficients(phase 1)
266
	unpcklps  xmm0,xmm5		; xmm0=(60 70 61 71)
267
	unpckhps  xmm3,xmm5		; xmm3=(62 72 63 73)
268
269
	movaps	xmm7, XMMWORD [wk(0)]	; xmm7=tmp2
270
	movaps	xmm5, XMMWORD [wk(1)]	; xmm5=tmp3
271
272
	movaps	XMMWORD [wk(0)], xmm0	; wk(0)=(60 70 61 71)
273
	movaps	XMMWORD [wk(1)], xmm3	; wk(1)=(62 72 63 73)
274
275
	addps	xmm4,xmm2		; xmm4=tmp4
276
	movaps	xmm0,xmm7
277
	movaps	xmm3,xmm5
278
	addps	xmm7,xmm2		; xmm7=data2=(20 21 22 23)
279
	addps	xmm5,xmm4		; xmm5=data4=(40 41 42 43)
280
	subps	xmm0,xmm2		; xmm0=data5=(50 51 52 53)
281
	subps	xmm3,xmm4		; xmm3=data3=(30 31 32 33)
282
283
	movaps    xmm2,xmm7		; transpose coefficients(phase 1)
284
	unpcklps  xmm7,xmm3		; xmm7=(20 30 21 31)
285
	unpckhps  xmm2,xmm3		; xmm2=(22 32 23 33)
286
	movaps    xmm4,xmm5		; transpose coefficients(phase 1)
287
	unpcklps  xmm5,xmm0		; xmm5=(40 50 41 51)
288
	unpckhps  xmm4,xmm0		; xmm4=(42 52 43 53)
289
290
	movaps    xmm3,xmm6		; transpose coefficients(phase 2)
291
	unpcklps2 xmm6,xmm7		; xmm6=(00 10 20 30)
292
	unpckhps2 xmm3,xmm7		; xmm3=(01 11 21 31)
293
	movaps    xmm0,xmm1		; transpose coefficients(phase 2)
294
	unpcklps2 xmm1,xmm2		; xmm1=(02 12 22 32)
295
	unpckhps2 xmm0,xmm2		; xmm0=(03 13 23 33)
296
297
	movaps	xmm7, XMMWORD [wk(0)]	; xmm7=(60 70 61 71)
298
	movaps	xmm2, XMMWORD [wk(1)]	; xmm2=(62 72 63 73)
299
300
	movaps	XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm6
301
	movaps	XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3
302
	movaps	XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm1
303
	movaps	XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm0
304
305
	movaps    xmm6,xmm5		; transpose coefficients(phase 2)
306
	unpcklps2 xmm5,xmm7		; xmm5=(40 50 60 70)
307
	unpckhps2 xmm6,xmm7		; xmm6=(41 51 61 71)
308
	movaps    xmm3,xmm4		; transpose coefficients(phase 2)
309
	unpcklps2 xmm4,xmm2		; xmm4=(42 52 62 72)
310
	unpckhps2 xmm3,xmm2		; xmm3=(43 53 63 73)
311
312
	movaps	XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm5
313
	movaps	XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm6
314
	movaps	XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm4
315
	movaps	XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3
316
317
.nextcolumn:
318
	add	esi, byte 4*SIZEOF_JCOEF		; coef_block
319
	add	edx, byte 4*SIZEOF_FLOAT_MULT_TYPE	; quantptr
320
	add	edi,      4*DCTSIZE*SIZEOF_FAST_FLOAT	; wsptr
321
	dec	ecx					; ctr
322
	jnz	near .columnloop
323
324
	; -- Prefetch the next coefficient block
325
326
	prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32]
327
	prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32]
328
	prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32]
329
	prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32]
330
331
	; ---- Pass 2: process rows from work array, store into output array.
332
333
	mov	eax, [original_ebp]
334
	lea	esi, [workspace]			; FAST_FLOAT * wsptr
335
	mov	edi, JSAMPARRAY [output_buf(eax)]	; (JSAMPROW *)
336
	mov	eax, JDIMENSION [output_col(eax)]
337
	mov	ecx, DCTSIZE/4				; ctr
338
	alignx	16,7
339
.rowloop:
340
341
	; -- Even part
342
343
	movaps	xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
344
	movaps	xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_FAST_FLOAT)]
345
	movaps	xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_FAST_FLOAT)]
346
	movaps	xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_FAST_FLOAT)]
347
348
	movaps	xmm4,xmm0
349
	movaps	xmm5,xmm1
350
	subps	xmm0,xmm2		; xmm0=tmp11
351
	subps	xmm1,xmm3
352
	addps	xmm4,xmm2		; xmm4=tmp10
353
	addps	xmm5,xmm3		; xmm5=tmp13
354
355
	mulps	xmm1,[GOTOFF(ebx,PD_1_414)]
356
	subps	xmm1,xmm5		; xmm1=tmp12
357
358
	movaps	xmm6,xmm4
359
	movaps	xmm7,xmm0
360
	subps	xmm4,xmm5		; xmm4=tmp3
361
	subps	xmm0,xmm1		; xmm0=tmp2
362
	addps	xmm6,xmm5		; xmm6=tmp0
363
	addps	xmm7,xmm1		; xmm7=tmp1
364
365
	movaps	XMMWORD [wk(1)], xmm4	; tmp3
366
	movaps	XMMWORD [wk(0)], xmm0	; tmp2
367
368
	; -- Odd part
369
370
	movaps	xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
371
	movaps	xmm3, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_FAST_FLOAT)]
372
	movaps	xmm5, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_FAST_FLOAT)]
373
	movaps	xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_FAST_FLOAT)]
374
375
	movaps	xmm4,xmm2
376
	movaps	xmm0,xmm5
377
	addps	xmm2,xmm1		; xmm2=z11
378
	addps	xmm5,xmm3		; xmm5=z13
379
	subps	xmm4,xmm1		; xmm4=z12
380
	subps	xmm0,xmm3		; xmm0=z10
381
382
	movaps	xmm1,xmm2
383
	subps	xmm2,xmm5
384
	addps	xmm1,xmm5		; xmm1=tmp7
385
386
	mulps	xmm2,[GOTOFF(ebx,PD_1_414)]	; xmm2=tmp11
387
388
	movaps	xmm3,xmm0
389
	addps	xmm0,xmm4
390
	mulps	xmm0,[GOTOFF(ebx,PD_1_847)]	; xmm0=z5
391
	mulps	xmm3,[GOTOFF(ebx,PD_M2_613)]	; xmm3=(z10 * -2.613125930)
392
	mulps	xmm4,[GOTOFF(ebx,PD_1_082)]	; xmm4=(z12 * 1.082392200)
393
	addps	xmm3,xmm0		; xmm3=tmp12
394
	subps	xmm4,xmm0		; xmm4=tmp10
395
396
	; -- Final output stage
397
398
	subps	xmm3,xmm1		; xmm3=tmp6
399
	movaps	xmm5,xmm6
400
	movaps	xmm0,xmm7
401
	addps	xmm6,xmm1		; xmm6=data0=(00 10 20 30)
402
	addps	xmm7,xmm3		; xmm7=data1=(01 11 21 31)
403
	subps	xmm5,xmm1		; xmm5=data7=(07 17 27 37)
404
	subps	xmm0,xmm3		; xmm0=data6=(06 16 26 36)
405
	subps	xmm2,xmm3		; xmm2=tmp5
406
407
	movaps	xmm1,[GOTOFF(ebx,PD_RNDINT_MAGIC)]	; xmm1=[PD_RNDINT_MAGIC]
408
	pcmpeqd	xmm3,xmm3
409
	psrld	xmm3,WORD_BIT		; xmm3={0xFFFF 0x0000 0xFFFF 0x0000 ..}
410
411
	addps	xmm6,xmm1	; xmm6=roundint(data0/8)=(00 ** 10 ** 20 ** 30 **)
412
	addps	xmm7,xmm1	; xmm7=roundint(data1/8)=(01 ** 11 ** 21 ** 31 **)
413
	addps	xmm0,xmm1	; xmm0=roundint(data6/8)=(06 ** 16 ** 26 ** 36 **)
414
	addps	xmm5,xmm1	; xmm5=roundint(data7/8)=(07 ** 17 ** 27 ** 37 **)
415
416
	pand	xmm6,xmm3		; xmm6=(00 -- 10 -- 20 -- 30 --)
417
	pslld	xmm7,WORD_BIT		; xmm7=(-- 01 -- 11 -- 21 -- 31)
418
	pand	xmm0,xmm3		; xmm0=(06 -- 16 -- 26 -- 36 --)
419
	pslld	xmm5,WORD_BIT		; xmm5=(-- 07 -- 17 -- 27 -- 37)
420
	por	xmm6,xmm7		; xmm6=(00 01 10 11 20 21 30 31)
421
	por	xmm0,xmm5		; xmm0=(06 07 16 17 26 27 36 37)
422
423
	movaps	xmm1, XMMWORD [wk(0)]	; xmm1=tmp2
424
	movaps	xmm3, XMMWORD [wk(1)]	; xmm3=tmp3
425
426
	addps	xmm4,xmm2		; xmm4=tmp4
427
	movaps	xmm7,xmm1
428
	movaps	xmm5,xmm3
429
	addps	xmm1,xmm2		; xmm1=data2=(02 12 22 32)
430
	addps	xmm3,xmm4		; xmm3=data4=(04 14 24 34)
431
	subps	xmm7,xmm2		; xmm7=data5=(05 15 25 35)
432
	subps	xmm5,xmm4		; xmm5=data3=(03 13 23 33)
433
434
	movaps	xmm2,[GOTOFF(ebx,PD_RNDINT_MAGIC)]	; xmm2=[PD_RNDINT_MAGIC]
435
	pcmpeqd	xmm4,xmm4
436
	psrld	xmm4,WORD_BIT		; xmm4={0xFFFF 0x0000 0xFFFF 0x0000 ..}
437
438
	addps	xmm3,xmm2	; xmm3=roundint(data4/8)=(04 ** 14 ** 24 ** 34 **)
439
	addps	xmm7,xmm2	; xmm7=roundint(data5/8)=(05 ** 15 ** 25 ** 35 **)
440
	addps	xmm1,xmm2	; xmm1=roundint(data2/8)=(02 ** 12 ** 22 ** 32 **)
441
	addps	xmm5,xmm2	; xmm5=roundint(data3/8)=(03 ** 13 ** 23 ** 33 **)
442
443
	pand	xmm3,xmm4		; xmm3=(04 -- 14 -- 24 -- 34 --)
444
	pslld	xmm7,WORD_BIT		; xmm7=(-- 05 -- 15 -- 25 -- 35)
445
	pand	xmm1,xmm4		; xmm1=(02 -- 12 -- 22 -- 32 --)
446
	pslld	xmm5,WORD_BIT		; xmm5=(-- 03 -- 13 -- 23 -- 33)
447
	por	xmm3,xmm7		; xmm3=(04 05 14 15 24 25 34 35)
448
	por	xmm1,xmm5		; xmm1=(02 03 12 13 22 23 32 33)
449
450
	movdqa    xmm2,[GOTOFF(ebx,PB_CENTERJSAMP)]	; xmm2=[PB_CENTERJSAMP]
451
452
	packsswb  xmm6,xmm3	; xmm6=(00 01 10 11 20 21 30 31 04 05 14 15 24 25 34 35)
453
	packsswb  xmm1,xmm0	; xmm1=(02 03 12 13 22 23 32 33 06 07 16 17 26 27 36 37)
454
	paddb     xmm6,xmm2
455
	paddb     xmm1,xmm2
456
457
	movdqa    xmm4,xmm6	; transpose coefficients(phase 2)
458
	punpcklwd xmm6,xmm1	; xmm6=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
459
	punpckhwd xmm4,xmm1	; xmm4=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
460
461
	movdqa    xmm7,xmm6	; transpose coefficients(phase 3)
462
	punpckldq xmm6,xmm4	; xmm6=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
463
	punpckhdq xmm7,xmm4	; xmm7=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
464
465
	pshufd	xmm5,xmm6,0x4E	; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
466
	pshufd	xmm3,xmm7,0x4E	; xmm3=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
467
468
	pushpic	ebx			; save GOT address
469
470
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
471
	mov	ebx, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
472
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm6
473
	movq	XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE], xmm7
474
	mov	edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
475
	mov	ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
476
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm5
477
	movq	XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE], xmm3
478
479
	poppic	ebx			; restore GOT address
480
481
	add	esi, byte 4*SIZEOF_FAST_FLOAT	; wsptr
482
	add	edi, byte 4*SIZEOF_JSAMPROW
483
	dec	ecx				; ctr
484
	jnz	near .rowloop
485
486
	pop	edi
487
	pop	esi
488
;	pop	edx		; need not be preserved
489
;	pop	ecx		; need not be preserved
490
	pop	ebx
491
	mov	esp,ebp		; esp <- aligned ebp
492
	pop	esp		; esp <- original ebp
493
	pop	ebp
494
	ret
495
496
; For some reason, the OS X linker does not honor the request to align the
497
; segment unless we do this.
498
	align	16
(-)a/jpeg/simd/jiss2fst-64.asm (+492 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jiss2fst-64.asm - fast integer IDCT (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/projecpt/showfiles.php?group_id=6208
17
;
18
; This file contains a fast, not so accurate integer implementation of
19
; the inverse DCT (Discrete Cosine Transform). The following code is
20
; based directly on the IJG's original jidctfst.c; see the jidctfst.c
21
; for more details.
22
;
23
; [TAB8]
24
25
%include "jsimdext.inc"
26
%include "jdct.inc"
27
28
; --------------------------------------------------------------------------
29
30
%define CONST_BITS	8	; 14 is also OK.
31
%define PASS1_BITS	2
32
33
%if IFAST_SCALE_BITS != PASS1_BITS
34
%error "'IFAST_SCALE_BITS' must be equal to 'PASS1_BITS'."
35
%endif
36
37
%if CONST_BITS == 8
38
F_1_082	equ	277		; FIX(1.082392200)
39
F_1_414	equ	362		; FIX(1.414213562)
40
F_1_847	equ	473		; FIX(1.847759065)
41
F_2_613	equ	669		; FIX(2.613125930)
42
F_1_613	equ	(F_2_613 - 256)	; FIX(2.613125930) - FIX(1)
43
%else
44
; NASM cannot do compile-time arithmetic on floating-point constants.
45
%define	DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
46
F_1_082	equ	DESCALE(1162209775,30-CONST_BITS)	; FIX(1.082392200)
47
F_1_414	equ	DESCALE(1518500249,30-CONST_BITS)	; FIX(1.414213562)
48
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
49
F_2_613	equ	DESCALE(2805822602,30-CONST_BITS)	; FIX(2.613125930)
50
F_1_613	equ	(F_2_613 - (1 << CONST_BITS))	; FIX(2.613125930) - FIX(1)
51
%endif
52
53
; --------------------------------------------------------------------------
54
	SECTION	SEG_CONST
55
56
; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
57
; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
58
59
%define PRE_MULTIPLY_SCALE_BITS   2
60
%define CONST_SHIFT     (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
61
62
	alignz	16
63
	global	EXTN(jconst_idct_ifast_sse2)
64
65
EXTN(jconst_idct_ifast_sse2):
66
67
PW_F1414	times 8 dw  F_1_414 << CONST_SHIFT
68
PW_F1847	times 8 dw  F_1_847 << CONST_SHIFT
69
PW_MF1613	times 8 dw -F_1_613 << CONST_SHIFT
70
PW_F1082	times 8 dw  F_1_082 << CONST_SHIFT
71
PB_CENTERJSAMP	times 16 db CENTERJSAMPLE
72
73
	alignz	16
74
75
; --------------------------------------------------------------------------
76
	SECTION	SEG_TEXT
77
	BITS	64
78
;
79
; Perform dequantization and inverse DCT on one block of coefficients.
80
;
81
; GLOBAL(void)
82
; jsimd_idct_ifast_sse2 (void * dct_table, JCOEFPTR coef_block,
83
;                       JSAMPARRAY output_buf, JDIMENSION output_col)
84
;
85
86
; r10 = jpeg_component_info * compptr
87
; r11 = JCOEFPTR coef_block
88
; r12 = JSAMPARRAY output_buf
89
; r13 = JDIMENSION output_col
90
91
%define original_rbp	rbp+0
92
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
93
%define WK_NUM		2
94
95
	align	16
96
	global	EXTN(jsimd_idct_ifast_sse2)
97
98
EXTN(jsimd_idct_ifast_sse2):
99
	push	rbp
100
	mov	rax,rsp				; rax = original rbp
101
	sub	rsp, byte 4
102
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
103
	mov	[rsp],rax
104
	mov	rbp,rsp				; rbp = aligned rbp
105
	lea	rsp, [wk(0)]
106
	collect_args
107
108
	; ---- Pass 1: process columns from input.
109
110
	mov	rdx, r10	; quantptr
111
	mov	rsi, r11		; inptr
112
113
%ifndef NO_ZERO_COLUMN_TEST_IFAST_SSE2
114
	mov	eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
115
	or	eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
116
	jnz	near .columnDCT
117
118
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
119
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
120
	por	xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
121
	por	xmm1, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
122
	por	xmm0, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
123
	por	xmm1, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
124
	por	xmm0, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
125
	por	xmm1,xmm0
126
	packsswb xmm1,xmm1
127
	packsswb xmm1,xmm1
128
	movd	eax,xmm1
129
	test	rax,rax
130
	jnz	short .columnDCT
131
132
	; -- AC terms all zero
133
134
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
135
	pmullw	xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
136
137
	movdqa    xmm7,xmm0		; xmm0=in0=(00 01 02 03 04 05 06 07)
138
	punpcklwd xmm0,xmm0		; xmm0=(00 00 01 01 02 02 03 03)
139
	punpckhwd xmm7,xmm7		; xmm7=(04 04 05 05 06 06 07 07)
140
141
	pshufd	xmm6,xmm0,0x00		; xmm6=col0=(00 00 00 00 00 00 00 00)
142
	pshufd	xmm2,xmm0,0x55		; xmm2=col1=(01 01 01 01 01 01 01 01)
143
	pshufd	xmm5,xmm0,0xAA		; xmm5=col2=(02 02 02 02 02 02 02 02)
144
	pshufd	xmm0,xmm0,0xFF		; xmm0=col3=(03 03 03 03 03 03 03 03)
145
	pshufd	xmm1,xmm7,0x00		; xmm1=col4=(04 04 04 04 04 04 04 04)
146
	pshufd	xmm4,xmm7,0x55		; xmm4=col5=(05 05 05 05 05 05 05 05)
147
	pshufd	xmm3,xmm7,0xAA		; xmm3=col6=(06 06 06 06 06 06 06 06)
148
	pshufd	xmm7,xmm7,0xFF		; xmm7=col7=(07 07 07 07 07 07 07 07)
149
150
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=col1
151
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=col3
152
	jmp	near .column_end
153
%endif
154
.columnDCT:
155
156
	; -- Even part
157
158
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
159
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
160
	pmullw	xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
161
	pmullw	xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
162
	movdqa	xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
163
	movdqa	xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
164
	pmullw	xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
165
	pmullw	xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
166
167
	movdqa	xmm4,xmm0
168
	movdqa	xmm5,xmm1
169
	psubw	xmm0,xmm2		; xmm0=tmp11
170
	psubw	xmm1,xmm3
171
	paddw	xmm4,xmm2		; xmm4=tmp10
172
	paddw	xmm5,xmm3		; xmm5=tmp13
173
174
	psllw	xmm1,PRE_MULTIPLY_SCALE_BITS
175
	pmulhw	xmm1,[rel PW_F1414]
176
	psubw	xmm1,xmm5		; xmm1=tmp12
177
178
	movdqa	xmm6,xmm4
179
	movdqa	xmm7,xmm0
180
	psubw	xmm4,xmm5		; xmm4=tmp3
181
	psubw	xmm0,xmm1		; xmm0=tmp2
182
	paddw	xmm6,xmm5		; xmm6=tmp0
183
	paddw	xmm7,xmm1		; xmm7=tmp1
184
185
	movdqa	XMMWORD [wk(1)], xmm4	; wk(1)=tmp3
186
	movdqa	XMMWORD [wk(0)], xmm0	; wk(0)=tmp2
187
188
	; -- Odd part
189
190
	movdqa	xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
191
	movdqa	xmm3, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
192
	pmullw	xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
193
	pmullw	xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
194
	movdqa	xmm5, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
195
	movdqa	xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
196
	pmullw	xmm5, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
197
	pmullw	xmm1, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
198
199
	movdqa	xmm4,xmm2
200
	movdqa	xmm0,xmm5
201
	psubw	xmm2,xmm1		; xmm2=z12
202
	psubw	xmm5,xmm3		; xmm5=z10
203
	paddw	xmm4,xmm1		; xmm4=z11
204
	paddw	xmm0,xmm3		; xmm0=z13
205
206
	movdqa	xmm1,xmm5		; xmm1=z10(unscaled)
207
	psllw	xmm2,PRE_MULTIPLY_SCALE_BITS
208
	psllw	xmm5,PRE_MULTIPLY_SCALE_BITS
209
210
	movdqa	xmm3,xmm4
211
	psubw	xmm4,xmm0
212
	paddw	xmm3,xmm0		; xmm3=tmp7
213
214
	psllw	xmm4,PRE_MULTIPLY_SCALE_BITS
215
	pmulhw	xmm4,[rel PW_F1414]	; xmm4=tmp11
216
217
	; To avoid overflow...
218
	;
219
	; (Original)
220
	; tmp12 = -2.613125930 * z10 + z5;
221
	;
222
	; (This implementation)
223
	; tmp12 = (-1.613125930 - 1) * z10 + z5;
224
	;       = -1.613125930 * z10 - z10 + z5;
225
226
	movdqa	xmm0,xmm5
227
	paddw	xmm5,xmm2
228
	pmulhw	xmm5,[rel PW_F1847]	; xmm5=z5
229
	pmulhw	xmm0,[rel PW_MF1613]
230
	pmulhw	xmm2,[rel PW_F1082]
231
	psubw	xmm0,xmm1
232
	psubw	xmm2,xmm5		; xmm2=tmp10
233
	paddw	xmm0,xmm5		; xmm0=tmp12
234
235
	; -- Final output stage
236
237
	psubw	xmm0,xmm3		; xmm0=tmp6
238
	movdqa	xmm1,xmm6
239
	movdqa	xmm5,xmm7
240
	paddw	xmm6,xmm3		; xmm6=data0=(00 01 02 03 04 05 06 07)
241
	paddw	xmm7,xmm0		; xmm7=data1=(10 11 12 13 14 15 16 17)
242
	psubw	xmm1,xmm3		; xmm1=data7=(70 71 72 73 74 75 76 77)
243
	psubw	xmm5,xmm0		; xmm5=data6=(60 61 62 63 64 65 66 67)
244
	psubw	xmm4,xmm0		; xmm4=tmp5
245
246
	movdqa    xmm3,xmm6		; transpose coefficients(phase 1)
247
	punpcklwd xmm6,xmm7		; xmm6=(00 10 01 11 02 12 03 13)
248
	punpckhwd xmm3,xmm7		; xmm3=(04 14 05 15 06 16 07 17)
249
	movdqa    xmm0,xmm5		; transpose coefficients(phase 1)
250
	punpcklwd xmm5,xmm1		; xmm5=(60 70 61 71 62 72 63 73)
251
	punpckhwd xmm0,xmm1		; xmm0=(64 74 65 75 66 76 67 77)
252
253
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=tmp2
254
	movdqa	xmm1, XMMWORD [wk(1)]	; xmm1=tmp3
255
256
	movdqa	XMMWORD [wk(0)], xmm5	; wk(0)=(60 70 61 71 62 72 63 73)
257
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=(64 74 65 75 66 76 67 77)
258
259
	paddw	xmm2,xmm4		; xmm2=tmp4
260
	movdqa	xmm5,xmm7
261
	movdqa	xmm0,xmm1
262
	paddw	xmm7,xmm4		; xmm7=data2=(20 21 22 23 24 25 26 27)
263
	paddw	xmm1,xmm2		; xmm1=data4=(40 41 42 43 44 45 46 47)
264
	psubw	xmm5,xmm4		; xmm5=data5=(50 51 52 53 54 55 56 57)
265
	psubw	xmm0,xmm2		; xmm0=data3=(30 31 32 33 34 35 36 37)
266
267
	movdqa    xmm4,xmm7		; transpose coefficients(phase 1)
268
	punpcklwd xmm7,xmm0		; xmm7=(20 30 21 31 22 32 23 33)
269
	punpckhwd xmm4,xmm0		; xmm4=(24 34 25 35 26 36 27 37)
270
	movdqa    xmm2,xmm1		; transpose coefficients(phase 1)
271
	punpcklwd xmm1,xmm5		; xmm1=(40 50 41 51 42 52 43 53)
272
	punpckhwd xmm2,xmm5		; xmm2=(44 54 45 55 46 56 47 57)
273
274
	movdqa    xmm0,xmm3		; transpose coefficients(phase 2)
275
	punpckldq xmm3,xmm4		; xmm3=(04 14 24 34 05 15 25 35)
276
	punpckhdq xmm0,xmm4		; xmm0=(06 16 26 36 07 17 27 37)
277
	movdqa    xmm5,xmm6		; transpose coefficients(phase 2)
278
	punpckldq xmm6,xmm7		; xmm6=(00 10 20 30 01 11 21 31)
279
	punpckhdq xmm5,xmm7		; xmm5=(02 12 22 32 03 13 23 33)
280
281
	movdqa	xmm4, XMMWORD [wk(0)]	; xmm4=(60 70 61 71 62 72 63 73)
282
	movdqa	xmm7, XMMWORD [wk(1)]	; xmm7=(64 74 65 75 66 76 67 77)
283
284
	movdqa	XMMWORD [wk(0)], xmm3	; wk(0)=(04 14 24 34 05 15 25 35)
285
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=(06 16 26 36 07 17 27 37)
286
287
	movdqa    xmm3,xmm1		; transpose coefficients(phase 2)
288
	punpckldq xmm1,xmm4		; xmm1=(40 50 60 70 41 51 61 71)
289
	punpckhdq xmm3,xmm4		; xmm3=(42 52 62 72 43 53 63 73)
290
	movdqa    xmm0,xmm2		; transpose coefficients(phase 2)
291
	punpckldq xmm2,xmm7		; xmm2=(44 54 64 74 45 55 65 75)
292
	punpckhdq xmm0,xmm7		; xmm0=(46 56 66 76 47 57 67 77)
293
294
	movdqa     xmm4,xmm6		; transpose coefficients(phase 3)
295
	punpcklqdq xmm6,xmm1		; xmm6=col0=(00 10 20 30 40 50 60 70)
296
	punpckhqdq xmm4,xmm1		; xmm4=col1=(01 11 21 31 41 51 61 71)
297
	movdqa     xmm7,xmm5		; transpose coefficients(phase 3)
298
	punpcklqdq xmm5,xmm3		; xmm5=col2=(02 12 22 32 42 52 62 72)
299
	punpckhqdq xmm7,xmm3		; xmm7=col3=(03 13 23 33 43 53 63 73)
300
301
	movdqa	xmm1, XMMWORD [wk(0)]	; xmm1=(04 14 24 34 05 15 25 35)
302
	movdqa	xmm3, XMMWORD [wk(1)]	; xmm3=(06 16 26 36 07 17 27 37)
303
304
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=col1
305
	movdqa	XMMWORD [wk(1)], xmm7	; wk(1)=col3
306
307
	movdqa     xmm4,xmm1		; transpose coefficients(phase 3)
308
	punpcklqdq xmm1,xmm2		; xmm1=col4=(04 14 24 34 44 54 64 74)
309
	punpckhqdq xmm4,xmm2		; xmm4=col5=(05 15 25 35 45 55 65 75)
310
	movdqa     xmm7,xmm3		; transpose coefficients(phase 3)
311
	punpcklqdq xmm3,xmm0		; xmm3=col6=(06 16 26 36 46 56 66 76)
312
	punpckhqdq xmm7,xmm0		; xmm7=col7=(07 17 27 37 47 57 67 77)
313
.column_end:
314
315
	; -- Prefetch the next coefficient block
316
317
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
318
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
319
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
320
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
321
322
	; ---- Pass 2: process rows from work array, store into output array.
323
324
	mov	rax, [original_rbp]
325
	mov	rdi, r12	; (JSAMPROW *)
326
	mov	rax, r13
327
328
	; -- Even part
329
330
	; xmm6=col0, xmm5=col2, xmm1=col4, xmm3=col6
331
332
	movdqa	xmm2,xmm6
333
	movdqa	xmm0,xmm5
334
	psubw	xmm6,xmm1		; xmm6=tmp11
335
	psubw	xmm5,xmm3
336
	paddw	xmm2,xmm1		; xmm2=tmp10
337
	paddw	xmm0,xmm3		; xmm0=tmp13
338
339
	psllw	xmm5,PRE_MULTIPLY_SCALE_BITS
340
	pmulhw	xmm5,[rel PW_F1414]
341
	psubw	xmm5,xmm0		; xmm5=tmp12
342
343
	movdqa	xmm1,xmm2
344
	movdqa	xmm3,xmm6
345
	psubw	xmm2,xmm0		; xmm2=tmp3
346
	psubw	xmm6,xmm5		; xmm6=tmp2
347
	paddw	xmm1,xmm0		; xmm1=tmp0
348
	paddw	xmm3,xmm5		; xmm3=tmp1
349
350
	movdqa	xmm0, XMMWORD [wk(0)]	; xmm0=col1
351
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=col3
352
353
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=tmp3
354
	movdqa	XMMWORD [wk(1)], xmm6	; wk(1)=tmp2
355
356
	; -- Odd part
357
358
	; xmm0=col1, xmm5=col3, xmm4=col5, xmm7=col7
359
360
	movdqa	xmm2,xmm0
361
	movdqa	xmm6,xmm4
362
	psubw	xmm0,xmm7		; xmm0=z12
363
	psubw	xmm4,xmm5		; xmm4=z10
364
	paddw	xmm2,xmm7		; xmm2=z11
365
	paddw	xmm6,xmm5		; xmm6=z13
366
367
	movdqa	xmm7,xmm4		; xmm7=z10(unscaled)
368
	psllw	xmm0,PRE_MULTIPLY_SCALE_BITS
369
	psllw	xmm4,PRE_MULTIPLY_SCALE_BITS
370
371
	movdqa	xmm5,xmm2
372
	psubw	xmm2,xmm6
373
	paddw	xmm5,xmm6		; xmm5=tmp7
374
375
	psllw	xmm2,PRE_MULTIPLY_SCALE_BITS
376
	pmulhw	xmm2,[rel PW_F1414]	; xmm2=tmp11
377
378
	; To avoid overflow...
379
	;
380
	; (Original)
381
	; tmp12 = -2.613125930 * z10 + z5;
382
	;
383
	; (This implementation)
384
	; tmp12 = (-1.613125930 - 1) * z10 + z5;
385
	;       = -1.613125930 * z10 - z10 + z5;
386
387
	movdqa	xmm6,xmm4
388
	paddw	xmm4,xmm0
389
	pmulhw	xmm4,[rel PW_F1847]	; xmm4=z5
390
	pmulhw	xmm6,[rel PW_MF1613]
391
	pmulhw	xmm0,[rel PW_F1082]
392
	psubw	xmm6,xmm7
393
	psubw	xmm0,xmm4		; xmm0=tmp10
394
	paddw	xmm6,xmm4		; xmm6=tmp12
395
396
	; -- Final output stage
397
398
	psubw	xmm6,xmm5		; xmm6=tmp6
399
	movdqa	xmm7,xmm1
400
	movdqa	xmm4,xmm3
401
	paddw	xmm1,xmm5		; xmm1=data0=(00 10 20 30 40 50 60 70)
402
	paddw	xmm3,xmm6		; xmm3=data1=(01 11 21 31 41 51 61 71)
403
	psraw	xmm1,(PASS1_BITS+3)	; descale
404
	psraw	xmm3,(PASS1_BITS+3)	; descale
405
	psubw	xmm7,xmm5		; xmm7=data7=(07 17 27 37 47 57 67 77)
406
	psubw	xmm4,xmm6		; xmm4=data6=(06 16 26 36 46 56 66 76)
407
	psraw	xmm7,(PASS1_BITS+3)	; descale
408
	psraw	xmm4,(PASS1_BITS+3)	; descale
409
	psubw	xmm2,xmm6		; xmm2=tmp5
410
411
	packsswb  xmm1,xmm4	; xmm1=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
412
	packsswb  xmm3,xmm7	; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
413
414
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=tmp2
415
	movdqa	xmm6, XMMWORD [wk(0)]	; xmm6=tmp3
416
417
	paddw	xmm0,xmm2		; xmm0=tmp4
418
	movdqa	xmm4,xmm5
419
	movdqa	xmm7,xmm6
420
	paddw	xmm5,xmm2		; xmm5=data2=(02 12 22 32 42 52 62 72)
421
	paddw	xmm6,xmm0		; xmm6=data4=(04 14 24 34 44 54 64 74)
422
	psraw	xmm5,(PASS1_BITS+3)	; descale
423
	psraw	xmm6,(PASS1_BITS+3)	; descale
424
	psubw	xmm4,xmm2		; xmm4=data5=(05 15 25 35 45 55 65 75)
425
	psubw	xmm7,xmm0		; xmm7=data3=(03 13 23 33 43 53 63 73)
426
	psraw	xmm4,(PASS1_BITS+3)	; descale
427
	psraw	xmm7,(PASS1_BITS+3)	; descale
428
429
	movdqa    xmm2,[rel PB_CENTERJSAMP]	; xmm2=[rel PB_CENTERJSAMP]
430
431
	packsswb  xmm5,xmm6	; xmm5=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74)
432
	packsswb  xmm7,xmm4	; xmm7=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75)
433
434
	paddb     xmm1,xmm2
435
	paddb     xmm3,xmm2
436
	paddb     xmm5,xmm2
437
	paddb     xmm7,xmm2
438
439
	movdqa    xmm0,xmm1	; transpose coefficients(phase 1)
440
	punpcklbw xmm1,xmm3	; xmm1=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71)
441
	punpckhbw xmm0,xmm3	; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77)
442
	movdqa    xmm6,xmm5	; transpose coefficients(phase 1)
443
	punpcklbw xmm5,xmm7	; xmm5=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73)
444
	punpckhbw xmm6,xmm7	; xmm6=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75)
445
446
	movdqa    xmm4,xmm1	; transpose coefficients(phase 2)
447
	punpcklwd xmm1,xmm5	; xmm1=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
448
	punpckhwd xmm4,xmm5	; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73)
449
	movdqa    xmm2,xmm6	; transpose coefficients(phase 2)
450
	punpcklwd xmm6,xmm0	; xmm6=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
451
	punpckhwd xmm2,xmm0	; xmm2=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77)
452
453
	movdqa    xmm3,xmm1	; transpose coefficients(phase 3)
454
	punpckldq xmm1,xmm6	; xmm1=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
455
	punpckhdq xmm3,xmm6	; xmm3=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
456
	movdqa    xmm7,xmm4	; transpose coefficients(phase 3)
457
	punpckldq xmm4,xmm2	; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57)
458
	punpckhdq xmm7,xmm2	; xmm7=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77)
459
460
	pshufd	xmm5,xmm1,0x4E	; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
461
	pshufd	xmm0,xmm3,0x4E	; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
462
	pshufd	xmm6,xmm4,0x4E	; xmm6=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47)
463
	pshufd	xmm2,xmm7,0x4E	; xmm2=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67)
464
465
	mov	rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
466
	mov	rsi, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
467
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm1
468
	movq	XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3
469
	mov	rdx, JSAMPROW [rdi+4*SIZEOF_JSAMPROW]
470
	mov	rsi, JSAMPROW [rdi+6*SIZEOF_JSAMPROW]
471
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4
472
	movq	XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm7
473
474
	mov	rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
475
	mov	rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
476
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm5
477
	movq	XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm0
478
	mov	rdx, JSAMPROW [rdi+5*SIZEOF_JSAMPROW]
479
	mov	rsi, JSAMPROW [rdi+7*SIZEOF_JSAMPROW]
480
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6
481
	movq	XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm2
482
483
	uncollect_args
484
	mov	rsp,rbp		; rsp <- aligned rbp
485
	pop	rsp		; rsp <- original rbp
486
	pop	rbp
487
	ret
488
	ret
489
490
; For some reason, the OS X linker does not honor the request to align the
491
; segment unless we do this.
492
	align	16
(-)a/jpeg/simd/jiss2fst.asm (+502 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jiss2fst.asm - fast integer IDCT (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a fast, not so accurate integer implementation of
18
; the inverse DCT (Discrete Cosine Transform). The following code is
19
; based directly on the IJG's original jidctfst.c; see the jidctfst.c
20
; for more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	8	; 14 is also OK.
30
%define PASS1_BITS	2
31
32
%if IFAST_SCALE_BITS != PASS1_BITS
33
%error "'IFAST_SCALE_BITS' must be equal to 'PASS1_BITS'."
34
%endif
35
36
%if CONST_BITS == 8
37
F_1_082	equ	277		; FIX(1.082392200)
38
F_1_414	equ	362		; FIX(1.414213562)
39
F_1_847	equ	473		; FIX(1.847759065)
40
F_2_613	equ	669		; FIX(2.613125930)
41
F_1_613	equ	(F_2_613 - 256)	; FIX(2.613125930) - FIX(1)
42
%else
43
; NASM cannot do compile-time arithmetic on floating-point constants.
44
%define	DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
45
F_1_082	equ	DESCALE(1162209775,30-CONST_BITS)	; FIX(1.082392200)
46
F_1_414	equ	DESCALE(1518500249,30-CONST_BITS)	; FIX(1.414213562)
47
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
48
F_2_613	equ	DESCALE(2805822602,30-CONST_BITS)	; FIX(2.613125930)
49
F_1_613	equ	(F_2_613 - (1 << CONST_BITS))	; FIX(2.613125930) - FIX(1)
50
%endif
51
52
; --------------------------------------------------------------------------
53
	SECTION	SEG_CONST
54
55
; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
56
; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
57
58
%define PRE_MULTIPLY_SCALE_BITS   2
59
%define CONST_SHIFT     (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
60
61
	alignz	16
62
	global	EXTN(jconst_idct_ifast_sse2)
63
64
EXTN(jconst_idct_ifast_sse2):
65
66
PW_F1414	times 8 dw  F_1_414 << CONST_SHIFT
67
PW_F1847	times 8 dw  F_1_847 << CONST_SHIFT
68
PW_MF1613	times 8 dw -F_1_613 << CONST_SHIFT
69
PW_F1082	times 8 dw  F_1_082 << CONST_SHIFT
70
PB_CENTERJSAMP	times 16 db CENTERJSAMPLE
71
72
	alignz	16
73
74
; --------------------------------------------------------------------------
75
	SECTION	SEG_TEXT
76
	BITS	32
77
;
78
; Perform dequantization and inverse DCT on one block of coefficients.
79
;
80
; GLOBAL(void)
81
; jsimd_idct_ifast_sse2 (void * dct_table, JCOEFPTR coef_block,
82
;                       JSAMPARRAY output_buf, JDIMENSION output_col)
83
;
84
85
%define dct_table(b)	(b)+8			; jpeg_component_info * compptr
86
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
87
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
88
%define output_col(b)	(b)+20		; JDIMENSION output_col
89
90
%define original_ebp	ebp+0
91
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
92
%define WK_NUM		2
93
94
	align	16
95
	global	EXTN(jsimd_idct_ifast_sse2)
96
97
EXTN(jsimd_idct_ifast_sse2):
98
	push	ebp
99
	mov	eax,esp				; eax = original ebp
100
	sub	esp, byte 4
101
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
102
	mov	[esp],eax
103
	mov	ebp,esp				; ebp = aligned ebp
104
	lea	esp, [wk(0)]
105
	pushpic	ebx
106
;	push	ecx		; unused
107
;	push	edx		; need not be preserved
108
	push	esi
109
	push	edi
110
111
	get_GOT	ebx		; get GOT address
112
113
	; ---- Pass 1: process columns from input.
114
115
;	mov	eax, [original_ebp]
116
	mov	edx, POINTER [dct_table(eax)]	; quantptr
117
	mov	esi, JCOEFPTR [coef_block(eax)]		; inptr
118
119
%ifndef NO_ZERO_COLUMN_TEST_IFAST_SSE2
120
	mov	eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
121
	or	eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
122
	jnz	near .columnDCT
123
124
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
125
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)]
126
	por	xmm0, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
127
	por	xmm1, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)]
128
	por	xmm0, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
129
	por	xmm1, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)]
130
	por	xmm0, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
131
	por	xmm1,xmm0
132
	packsswb xmm1,xmm1
133
	packsswb xmm1,xmm1
134
	movd	eax,xmm1
135
	test	eax,eax
136
	jnz	short .columnDCT
137
138
	; -- AC terms all zero
139
140
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
141
	pmullw	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
142
143
	movdqa    xmm7,xmm0		; xmm0=in0=(00 01 02 03 04 05 06 07)
144
	punpcklwd xmm0,xmm0		; xmm0=(00 00 01 01 02 02 03 03)
145
	punpckhwd xmm7,xmm7		; xmm7=(04 04 05 05 06 06 07 07)
146
147
	pshufd	xmm6,xmm0,0x00		; xmm6=col0=(00 00 00 00 00 00 00 00)
148
	pshufd	xmm2,xmm0,0x55		; xmm2=col1=(01 01 01 01 01 01 01 01)
149
	pshufd	xmm5,xmm0,0xAA		; xmm5=col2=(02 02 02 02 02 02 02 02)
150
	pshufd	xmm0,xmm0,0xFF		; xmm0=col3=(03 03 03 03 03 03 03 03)
151
	pshufd	xmm1,xmm7,0x00		; xmm1=col4=(04 04 04 04 04 04 04 04)
152
	pshufd	xmm4,xmm7,0x55		; xmm4=col5=(05 05 05 05 05 05 05 05)
153
	pshufd	xmm3,xmm7,0xAA		; xmm3=col6=(06 06 06 06 06 06 06 06)
154
	pshufd	xmm7,xmm7,0xFF		; xmm7=col7=(07 07 07 07 07 07 07 07)
155
156
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=col1
157
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=col3
158
	jmp	near .column_end
159
	alignx	16,7
160
%endif
161
.columnDCT:
162
163
	; -- Even part
164
165
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
166
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)]
167
	pmullw	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_IFAST_MULT_TYPE)]
168
	pmullw	xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_IFAST_MULT_TYPE)]
169
	movdqa	xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)]
170
	movdqa	xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)]
171
	pmullw	xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_IFAST_MULT_TYPE)]
172
	pmullw	xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_IFAST_MULT_TYPE)]
173
174
	movdqa	xmm4,xmm0
175
	movdqa	xmm5,xmm1
176
	psubw	xmm0,xmm2		; xmm0=tmp11
177
	psubw	xmm1,xmm3
178
	paddw	xmm4,xmm2		; xmm4=tmp10
179
	paddw	xmm5,xmm3		; xmm5=tmp13
180
181
	psllw	xmm1,PRE_MULTIPLY_SCALE_BITS
182
	pmulhw	xmm1,[GOTOFF(ebx,PW_F1414)]
183
	psubw	xmm1,xmm5		; xmm1=tmp12
184
185
	movdqa	xmm6,xmm4
186
	movdqa	xmm7,xmm0
187
	psubw	xmm4,xmm5		; xmm4=tmp3
188
	psubw	xmm0,xmm1		; xmm0=tmp2
189
	paddw	xmm6,xmm5		; xmm6=tmp0
190
	paddw	xmm7,xmm1		; xmm7=tmp1
191
192
	movdqa	XMMWORD [wk(1)], xmm4	; wk(1)=tmp3
193
	movdqa	XMMWORD [wk(0)], xmm0	; wk(0)=tmp2
194
195
	; -- Odd part
196
197
	movdqa	xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
198
	movdqa	xmm3, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
199
	pmullw	xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_IFAST_MULT_TYPE)]
200
	pmullw	xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_IFAST_MULT_TYPE)]
201
	movdqa	xmm5, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
202
	movdqa	xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
203
	pmullw	xmm5, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_IFAST_MULT_TYPE)]
204
	pmullw	xmm1, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_IFAST_MULT_TYPE)]
205
206
	movdqa	xmm4,xmm2
207
	movdqa	xmm0,xmm5
208
	psubw	xmm2,xmm1		; xmm2=z12
209
	psubw	xmm5,xmm3		; xmm5=z10
210
	paddw	xmm4,xmm1		; xmm4=z11
211
	paddw	xmm0,xmm3		; xmm0=z13
212
213
	movdqa	xmm1,xmm5		; xmm1=z10(unscaled)
214
	psllw	xmm2,PRE_MULTIPLY_SCALE_BITS
215
	psllw	xmm5,PRE_MULTIPLY_SCALE_BITS
216
217
	movdqa	xmm3,xmm4
218
	psubw	xmm4,xmm0
219
	paddw	xmm3,xmm0		; xmm3=tmp7
220
221
	psllw	xmm4,PRE_MULTIPLY_SCALE_BITS
222
	pmulhw	xmm4,[GOTOFF(ebx,PW_F1414)]	; xmm4=tmp11
223
224
	; To avoid overflow...
225
	;
226
	; (Original)
227
	; tmp12 = -2.613125930 * z10 + z5;
228
	;
229
	; (This implementation)
230
	; tmp12 = (-1.613125930 - 1) * z10 + z5;
231
	;       = -1.613125930 * z10 - z10 + z5;
232
233
	movdqa	xmm0,xmm5
234
	paddw	xmm5,xmm2
235
	pmulhw	xmm5,[GOTOFF(ebx,PW_F1847)]	; xmm5=z5
236
	pmulhw	xmm0,[GOTOFF(ebx,PW_MF1613)]
237
	pmulhw	xmm2,[GOTOFF(ebx,PW_F1082)]
238
	psubw	xmm0,xmm1
239
	psubw	xmm2,xmm5		; xmm2=tmp10
240
	paddw	xmm0,xmm5		; xmm0=tmp12
241
242
	; -- Final output stage
243
244
	psubw	xmm0,xmm3		; xmm0=tmp6
245
	movdqa	xmm1,xmm6
246
	movdqa	xmm5,xmm7
247
	paddw	xmm6,xmm3		; xmm6=data0=(00 01 02 03 04 05 06 07)
248
	paddw	xmm7,xmm0		; xmm7=data1=(10 11 12 13 14 15 16 17)
249
	psubw	xmm1,xmm3		; xmm1=data7=(70 71 72 73 74 75 76 77)
250
	psubw	xmm5,xmm0		; xmm5=data6=(60 61 62 63 64 65 66 67)
251
	psubw	xmm4,xmm0		; xmm4=tmp5
252
253
	movdqa    xmm3,xmm6		; transpose coefficients(phase 1)
254
	punpcklwd xmm6,xmm7		; xmm6=(00 10 01 11 02 12 03 13)
255
	punpckhwd xmm3,xmm7		; xmm3=(04 14 05 15 06 16 07 17)
256
	movdqa    xmm0,xmm5		; transpose coefficients(phase 1)
257
	punpcklwd xmm5,xmm1		; xmm5=(60 70 61 71 62 72 63 73)
258
	punpckhwd xmm0,xmm1		; xmm0=(64 74 65 75 66 76 67 77)
259
260
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=tmp2
261
	movdqa	xmm1, XMMWORD [wk(1)]	; xmm1=tmp3
262
263
	movdqa	XMMWORD [wk(0)], xmm5	; wk(0)=(60 70 61 71 62 72 63 73)
264
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=(64 74 65 75 66 76 67 77)
265
266
	paddw	xmm2,xmm4		; xmm2=tmp4
267
	movdqa	xmm5,xmm7
268
	movdqa	xmm0,xmm1
269
	paddw	xmm7,xmm4		; xmm7=data2=(20 21 22 23 24 25 26 27)
270
	paddw	xmm1,xmm2		; xmm1=data4=(40 41 42 43 44 45 46 47)
271
	psubw	xmm5,xmm4		; xmm5=data5=(50 51 52 53 54 55 56 57)
272
	psubw	xmm0,xmm2		; xmm0=data3=(30 31 32 33 34 35 36 37)
273
274
	movdqa    xmm4,xmm7		; transpose coefficients(phase 1)
275
	punpcklwd xmm7,xmm0		; xmm7=(20 30 21 31 22 32 23 33)
276
	punpckhwd xmm4,xmm0		; xmm4=(24 34 25 35 26 36 27 37)
277
	movdqa    xmm2,xmm1		; transpose coefficients(phase 1)
278
	punpcklwd xmm1,xmm5		; xmm1=(40 50 41 51 42 52 43 53)
279
	punpckhwd xmm2,xmm5		; xmm2=(44 54 45 55 46 56 47 57)
280
281
	movdqa    xmm0,xmm3		; transpose coefficients(phase 2)
282
	punpckldq xmm3,xmm4		; xmm3=(04 14 24 34 05 15 25 35)
283
	punpckhdq xmm0,xmm4		; xmm0=(06 16 26 36 07 17 27 37)
284
	movdqa    xmm5,xmm6		; transpose coefficients(phase 2)
285
	punpckldq xmm6,xmm7		; xmm6=(00 10 20 30 01 11 21 31)
286
	punpckhdq xmm5,xmm7		; xmm5=(02 12 22 32 03 13 23 33)
287
288
	movdqa	xmm4, XMMWORD [wk(0)]	; xmm4=(60 70 61 71 62 72 63 73)
289
	movdqa	xmm7, XMMWORD [wk(1)]	; xmm7=(64 74 65 75 66 76 67 77)
290
291
	movdqa	XMMWORD [wk(0)], xmm3	; wk(0)=(04 14 24 34 05 15 25 35)
292
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=(06 16 26 36 07 17 27 37)
293
294
	movdqa    xmm3,xmm1		; transpose coefficients(phase 2)
295
	punpckldq xmm1,xmm4		; xmm1=(40 50 60 70 41 51 61 71)
296
	punpckhdq xmm3,xmm4		; xmm3=(42 52 62 72 43 53 63 73)
297
	movdqa    xmm0,xmm2		; transpose coefficients(phase 2)
298
	punpckldq xmm2,xmm7		; xmm2=(44 54 64 74 45 55 65 75)
299
	punpckhdq xmm0,xmm7		; xmm0=(46 56 66 76 47 57 67 77)
300
301
	movdqa     xmm4,xmm6		; transpose coefficients(phase 3)
302
	punpcklqdq xmm6,xmm1		; xmm6=col0=(00 10 20 30 40 50 60 70)
303
	punpckhqdq xmm4,xmm1		; xmm4=col1=(01 11 21 31 41 51 61 71)
304
	movdqa     xmm7,xmm5		; transpose coefficients(phase 3)
305
	punpcklqdq xmm5,xmm3		; xmm5=col2=(02 12 22 32 42 52 62 72)
306
	punpckhqdq xmm7,xmm3		; xmm7=col3=(03 13 23 33 43 53 63 73)
307
308
	movdqa	xmm1, XMMWORD [wk(0)]	; xmm1=(04 14 24 34 05 15 25 35)
309
	movdqa	xmm3, XMMWORD [wk(1)]	; xmm3=(06 16 26 36 07 17 27 37)
310
311
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=col1
312
	movdqa	XMMWORD [wk(1)], xmm7	; wk(1)=col3
313
314
	movdqa     xmm4,xmm1		; transpose coefficients(phase 3)
315
	punpcklqdq xmm1,xmm2		; xmm1=col4=(04 14 24 34 44 54 64 74)
316
	punpckhqdq xmm4,xmm2		; xmm4=col5=(05 15 25 35 45 55 65 75)
317
	movdqa     xmm7,xmm3		; transpose coefficients(phase 3)
318
	punpcklqdq xmm3,xmm0		; xmm3=col6=(06 16 26 36 46 56 66 76)
319
	punpckhqdq xmm7,xmm0		; xmm7=col7=(07 17 27 37 47 57 67 77)
320
.column_end:
321
322
	; -- Prefetch the next coefficient block
323
324
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
325
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
326
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
327
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
328
329
	; ---- Pass 2: process rows from work array, store into output array.
330
331
	mov	eax, [original_ebp]
332
	mov	edi, JSAMPARRAY [output_buf(eax)]	; (JSAMPROW *)
333
	mov	eax, JDIMENSION [output_col(eax)]
334
335
	; -- Even part
336
337
	; xmm6=col0, xmm5=col2, xmm1=col4, xmm3=col6
338
339
	movdqa	xmm2,xmm6
340
	movdqa	xmm0,xmm5
341
	psubw	xmm6,xmm1		; xmm6=tmp11
342
	psubw	xmm5,xmm3
343
	paddw	xmm2,xmm1		; xmm2=tmp10
344
	paddw	xmm0,xmm3		; xmm0=tmp13
345
346
	psllw	xmm5,PRE_MULTIPLY_SCALE_BITS
347
	pmulhw	xmm5,[GOTOFF(ebx,PW_F1414)]
348
	psubw	xmm5,xmm0		; xmm5=tmp12
349
350
	movdqa	xmm1,xmm2
351
	movdqa	xmm3,xmm6
352
	psubw	xmm2,xmm0		; xmm2=tmp3
353
	psubw	xmm6,xmm5		; xmm6=tmp2
354
	paddw	xmm1,xmm0		; xmm1=tmp0
355
	paddw	xmm3,xmm5		; xmm3=tmp1
356
357
	movdqa	xmm0, XMMWORD [wk(0)]	; xmm0=col1
358
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=col3
359
360
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=tmp3
361
	movdqa	XMMWORD [wk(1)], xmm6	; wk(1)=tmp2
362
363
	; -- Odd part
364
365
	; xmm0=col1, xmm5=col3, xmm4=col5, xmm7=col7
366
367
	movdqa	xmm2,xmm0
368
	movdqa	xmm6,xmm4
369
	psubw	xmm0,xmm7		; xmm0=z12
370
	psubw	xmm4,xmm5		; xmm4=z10
371
	paddw	xmm2,xmm7		; xmm2=z11
372
	paddw	xmm6,xmm5		; xmm6=z13
373
374
	movdqa	xmm7,xmm4		; xmm7=z10(unscaled)
375
	psllw	xmm0,PRE_MULTIPLY_SCALE_BITS
376
	psllw	xmm4,PRE_MULTIPLY_SCALE_BITS
377
378
	movdqa	xmm5,xmm2
379
	psubw	xmm2,xmm6
380
	paddw	xmm5,xmm6		; xmm5=tmp7
381
382
	psllw	xmm2,PRE_MULTIPLY_SCALE_BITS
383
	pmulhw	xmm2,[GOTOFF(ebx,PW_F1414)]	; xmm2=tmp11
384
385
	; To avoid overflow...
386
	;
387
	; (Original)
388
	; tmp12 = -2.613125930 * z10 + z5;
389
	;
390
	; (This implementation)
391
	; tmp12 = (-1.613125930 - 1) * z10 + z5;
392
	;       = -1.613125930 * z10 - z10 + z5;
393
394
	movdqa	xmm6,xmm4
395
	paddw	xmm4,xmm0
396
	pmulhw	xmm4,[GOTOFF(ebx,PW_F1847)]	; xmm4=z5
397
	pmulhw	xmm6,[GOTOFF(ebx,PW_MF1613)]
398
	pmulhw	xmm0,[GOTOFF(ebx,PW_F1082)]
399
	psubw	xmm6,xmm7
400
	psubw	xmm0,xmm4		; xmm0=tmp10
401
	paddw	xmm6,xmm4		; xmm6=tmp12
402
403
	; -- Final output stage
404
405
	psubw	xmm6,xmm5		; xmm6=tmp6
406
	movdqa	xmm7,xmm1
407
	movdqa	xmm4,xmm3
408
	paddw	xmm1,xmm5		; xmm1=data0=(00 10 20 30 40 50 60 70)
409
	paddw	xmm3,xmm6		; xmm3=data1=(01 11 21 31 41 51 61 71)
410
	psraw	xmm1,(PASS1_BITS+3)	; descale
411
	psraw	xmm3,(PASS1_BITS+3)	; descale
412
	psubw	xmm7,xmm5		; xmm7=data7=(07 17 27 37 47 57 67 77)
413
	psubw	xmm4,xmm6		; xmm4=data6=(06 16 26 36 46 56 66 76)
414
	psraw	xmm7,(PASS1_BITS+3)	; descale
415
	psraw	xmm4,(PASS1_BITS+3)	; descale
416
	psubw	xmm2,xmm6		; xmm2=tmp5
417
418
	packsswb  xmm1,xmm4	; xmm1=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
419
	packsswb  xmm3,xmm7	; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
420
421
	movdqa	xmm5, XMMWORD [wk(1)]	; xmm5=tmp2
422
	movdqa	xmm6, XMMWORD [wk(0)]	; xmm6=tmp3
423
424
	paddw	xmm0,xmm2		; xmm0=tmp4
425
	movdqa	xmm4,xmm5
426
	movdqa	xmm7,xmm6
427
	paddw	xmm5,xmm2		; xmm5=data2=(02 12 22 32 42 52 62 72)
428
	paddw	xmm6,xmm0		; xmm6=data4=(04 14 24 34 44 54 64 74)
429
	psraw	xmm5,(PASS1_BITS+3)	; descale
430
	psraw	xmm6,(PASS1_BITS+3)	; descale
431
	psubw	xmm4,xmm2		; xmm4=data5=(05 15 25 35 45 55 65 75)
432
	psubw	xmm7,xmm0		; xmm7=data3=(03 13 23 33 43 53 63 73)
433
	psraw	xmm4,(PASS1_BITS+3)	; descale
434
	psraw	xmm7,(PASS1_BITS+3)	; descale
435
436
	movdqa    xmm2,[GOTOFF(ebx,PB_CENTERJSAMP)]	; xmm2=[PB_CENTERJSAMP]
437
438
	packsswb  xmm5,xmm6	; xmm5=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74)
439
	packsswb  xmm7,xmm4	; xmm7=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75)
440
441
	paddb     xmm1,xmm2
442
	paddb     xmm3,xmm2
443
	paddb     xmm5,xmm2
444
	paddb     xmm7,xmm2
445
446
	movdqa    xmm0,xmm1	; transpose coefficients(phase 1)
447
	punpcklbw xmm1,xmm3	; xmm1=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71)
448
	punpckhbw xmm0,xmm3	; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77)
449
	movdqa    xmm6,xmm5	; transpose coefficients(phase 1)
450
	punpcklbw xmm5,xmm7	; xmm5=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73)
451
	punpckhbw xmm6,xmm7	; xmm6=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75)
452
453
	movdqa    xmm4,xmm1	; transpose coefficients(phase 2)
454
	punpcklwd xmm1,xmm5	; xmm1=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
455
	punpckhwd xmm4,xmm5	; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73)
456
	movdqa    xmm2,xmm6	; transpose coefficients(phase 2)
457
	punpcklwd xmm6,xmm0	; xmm6=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
458
	punpckhwd xmm2,xmm0	; xmm2=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77)
459
460
	movdqa    xmm3,xmm1	; transpose coefficients(phase 3)
461
	punpckldq xmm1,xmm6	; xmm1=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
462
	punpckhdq xmm3,xmm6	; xmm3=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
463
	movdqa    xmm7,xmm4	; transpose coefficients(phase 3)
464
	punpckldq xmm4,xmm2	; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57)
465
	punpckhdq xmm7,xmm2	; xmm7=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77)
466
467
	pshufd	xmm5,xmm1,0x4E	; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
468
	pshufd	xmm0,xmm3,0x4E	; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
469
	pshufd	xmm6,xmm4,0x4E	; xmm6=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47)
470
	pshufd	xmm2,xmm7,0x4E	; xmm2=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67)
471
472
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
473
	mov	esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
474
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm1
475
	movq	XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm3
476
	mov	edx, JSAMPROW [edi+4*SIZEOF_JSAMPROW]
477
	mov	esi, JSAMPROW [edi+6*SIZEOF_JSAMPROW]
478
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm4
479
	movq	XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm7
480
481
	mov	edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
482
	mov	esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
483
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm5
484
	movq	XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm0
485
	mov	edx, JSAMPROW [edi+5*SIZEOF_JSAMPROW]
486
	mov	esi, JSAMPROW [edi+7*SIZEOF_JSAMPROW]
487
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm6
488
	movq	XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm2
489
490
	pop	edi
491
	pop	esi
492
;	pop	edx		; need not be preserved
493
;	pop	ecx		; unused
494
	poppic	ebx
495
	mov	esp,ebp		; esp <- aligned ebp
496
	pop	esp		; esp <- original ebp
497
	pop	ebp
498
	ret
499
500
; For some reason, the OS X linker does not honor the request to align the
501
; segment unless we do this.
502
	align	16
(-)a/jpeg/simd/jiss2int-64.asm (+848 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jiss2int-64.asm - accurate integer IDCT (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; This file contains a slow-but-accurate integer implementation of the
19
; inverse DCT (Discrete Cosine Transform). The following code is based
20
; directly on the IJG's original jidctint.c; see the jidctint.c for
21
; more details.
22
;
23
; [TAB8]
24
25
%include "jsimdext.inc"
26
%include "jdct.inc"
27
28
; --------------------------------------------------------------------------
29
30
%define CONST_BITS	13
31
%define PASS1_BITS	2
32
33
%define DESCALE_P1	(CONST_BITS-PASS1_BITS)
34
%define DESCALE_P2	(CONST_BITS+PASS1_BITS+3)
35
36
%if CONST_BITS == 13
37
F_0_298	equ	 2446		; FIX(0.298631336)
38
F_0_390	equ	 3196		; FIX(0.390180644)
39
F_0_541	equ	 4433		; FIX(0.541196100)
40
F_0_765	equ	 6270		; FIX(0.765366865)
41
F_0_899	equ	 7373		; FIX(0.899976223)
42
F_1_175	equ	 9633		; FIX(1.175875602)
43
F_1_501	equ	12299		; FIX(1.501321110)
44
F_1_847	equ	15137		; FIX(1.847759065)
45
F_1_961	equ	16069		; FIX(1.961570560)
46
F_2_053	equ	16819		; FIX(2.053119869)
47
F_2_562	equ	20995		; FIX(2.562915447)
48
F_3_072	equ	25172		; FIX(3.072711026)
49
%else
50
; NASM cannot do compile-time arithmetic on floating-point constants.
51
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
52
F_0_298	equ	DESCALE( 320652955,30-CONST_BITS)	; FIX(0.298631336)
53
F_0_390	equ	DESCALE( 418953276,30-CONST_BITS)	; FIX(0.390180644)
54
F_0_541	equ	DESCALE( 581104887,30-CONST_BITS)	; FIX(0.541196100)
55
F_0_765	equ	DESCALE( 821806413,30-CONST_BITS)	; FIX(0.765366865)
56
F_0_899	equ	DESCALE( 966342111,30-CONST_BITS)	; FIX(0.899976223)
57
F_1_175	equ	DESCALE(1262586813,30-CONST_BITS)	; FIX(1.175875602)
58
F_1_501	equ	DESCALE(1612031267,30-CONST_BITS)	; FIX(1.501321110)
59
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
60
F_1_961	equ	DESCALE(2106220350,30-CONST_BITS)	; FIX(1.961570560)
61
F_2_053	equ	DESCALE(2204520673,30-CONST_BITS)	; FIX(2.053119869)
62
F_2_562	equ	DESCALE(2751909506,30-CONST_BITS)	; FIX(2.562915447)
63
F_3_072	equ	DESCALE(3299298341,30-CONST_BITS)	; FIX(3.072711026)
64
%endif
65
66
; --------------------------------------------------------------------------
67
	SECTION	SEG_CONST
68
69
	alignz	16
70
	global	EXTN(jconst_idct_islow_sse2)
71
72
EXTN(jconst_idct_islow_sse2):
73
74
PW_F130_F054	times 4 dw  (F_0_541+F_0_765), F_0_541
75
PW_F054_MF130	times 4 dw  F_0_541, (F_0_541-F_1_847)
76
PW_MF078_F117	times 4 dw  (F_1_175-F_1_961), F_1_175
77
PW_F117_F078	times 4 dw  F_1_175, (F_1_175-F_0_390)
78
PW_MF060_MF089	times 4 dw  (F_0_298-F_0_899),-F_0_899
79
PW_MF089_F060	times 4 dw -F_0_899, (F_1_501-F_0_899)
80
PW_MF050_MF256	times 4 dw  (F_2_053-F_2_562),-F_2_562
81
PW_MF256_F050	times 4 dw -F_2_562, (F_3_072-F_2_562)
82
PD_DESCALE_P1	times 4 dd  1 << (DESCALE_P1-1)
83
PD_DESCALE_P2	times 4 dd  1 << (DESCALE_P2-1)
84
PB_CENTERJSAMP	times 16 db CENTERJSAMPLE
85
86
	alignz	16
87
88
; --------------------------------------------------------------------------
89
	SECTION	SEG_TEXT
90
	BITS	64
91
;
92
; Perform dequantization and inverse DCT on one block of coefficients.
93
;
94
; GLOBAL(void)
95
; jsimd_idct_islow_sse2 (void * dct_table, JCOEFPTR coef_block,
96
;                        JSAMPARRAY output_buf, JDIMENSION output_col)
97
;
98
99
; r10 = jpeg_component_info * compptr
100
; r11 = JCOEFPTR coef_block
101
; r12 = JSAMPARRAY output_buf
102
; r13 = JDIMENSION output_col
103
104
%define original_rbp	rbp+0
105
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
106
%define WK_NUM		12
107
108
	align	16
109
	global	EXTN(jsimd_idct_islow_sse2)
110
111
EXTN(jsimd_idct_islow_sse2):
112
	push	rbp
113
	mov	rax,rsp				; rax = original rbp
114
	sub	rsp, byte 4
115
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
116
	mov	[rsp],rax
117
	mov	rbp,rsp				; rbp = aligned rbp
118
	lea	rsp, [wk(0)]
119
	collect_args
120
121
	; ---- Pass 1: process columns from input.
122
123
	mov	rdx, r10	; quantptr
124
	mov	rsi, r11		; inptr
125
126
%ifndef NO_ZERO_COLUMN_TEST_ISLOW_SSE2
127
	mov	eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
128
	or	eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
129
	jnz	near .columnDCT
130
131
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
132
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
133
	por	xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
134
	por	xmm1, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
135
	por	xmm0, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
136
	por	xmm1, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
137
	por	xmm0, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
138
	por	xmm1,xmm0
139
	packsswb xmm1,xmm1
140
	packsswb xmm1,xmm1
141
	movd	eax,xmm1
142
	test	rax,rax
143
	jnz	short .columnDCT
144
145
	; -- AC terms all zero
146
147
	movdqa	xmm5, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
148
	pmullw	xmm5, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
149
150
	psllw	xmm5,PASS1_BITS
151
152
	movdqa    xmm4,xmm5		; xmm5=in0=(00 01 02 03 04 05 06 07)
153
	punpcklwd xmm5,xmm5		; xmm5=(00 00 01 01 02 02 03 03)
154
	punpckhwd xmm4,xmm4		; xmm4=(04 04 05 05 06 06 07 07)
155
156
	pshufd	xmm7,xmm5,0x00		; xmm7=col0=(00 00 00 00 00 00 00 00)
157
	pshufd	xmm6,xmm5,0x55		; xmm6=col1=(01 01 01 01 01 01 01 01)
158
	pshufd	xmm1,xmm5,0xAA		; xmm1=col2=(02 02 02 02 02 02 02 02)
159
	pshufd	xmm5,xmm5,0xFF		; xmm5=col3=(03 03 03 03 03 03 03 03)
160
	pshufd	xmm0,xmm4,0x00		; xmm0=col4=(04 04 04 04 04 04 04 04)
161
	pshufd	xmm3,xmm4,0x55		; xmm3=col5=(05 05 05 05 05 05 05 05)
162
	pshufd	xmm2,xmm4,0xAA		; xmm2=col6=(06 06 06 06 06 06 06 06)
163
	pshufd	xmm4,xmm4,0xFF		; xmm4=col7=(07 07 07 07 07 07 07 07)
164
165
	movdqa	XMMWORD [wk(8)], xmm6	; wk(8)=col1
166
	movdqa	XMMWORD [wk(9)], xmm5	; wk(9)=col3
167
	movdqa	XMMWORD [wk(10)], xmm3	; wk(10)=col5
168
	movdqa	XMMWORD [wk(11)], xmm4	; wk(11)=col7
169
	jmp	near .column_end
170
%endif
171
.columnDCT:
172
173
	; -- Even part
174
175
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
176
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
177
	pmullw	xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
178
	pmullw	xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
179
	movdqa	xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
180
	movdqa	xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
181
	pmullw	xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
182
	pmullw	xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
183
184
	; (Original)
185
	; z1 = (z2 + z3) * 0.541196100;
186
	; tmp2 = z1 + z3 * -1.847759065;
187
	; tmp3 = z1 + z2 * 0.765366865;
188
	;
189
	; (This implementation)
190
	; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
191
	; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
192
193
	movdqa    xmm4,xmm1		; xmm1=in2=z2
194
	movdqa    xmm5,xmm1
195
	punpcklwd xmm4,xmm3		; xmm3=in6=z3
196
	punpckhwd xmm5,xmm3
197
	movdqa    xmm1,xmm4
198
	movdqa    xmm3,xmm5
199
	pmaddwd   xmm4,[rel PW_F130_F054]	; xmm4=tmp3L
200
	pmaddwd   xmm5,[rel PW_F130_F054]	; xmm5=tmp3H
201
	pmaddwd   xmm1,[rel PW_F054_MF130]	; xmm1=tmp2L
202
	pmaddwd   xmm3,[rel PW_F054_MF130]	; xmm3=tmp2H
203
204
	movdqa    xmm6,xmm0
205
	paddw     xmm0,xmm2		; xmm0=in0+in4
206
	psubw     xmm6,xmm2		; xmm6=in0-in4
207
208
	pxor      xmm7,xmm7
209
	pxor      xmm2,xmm2
210
	punpcklwd xmm7,xmm0		; xmm7=tmp0L
211
	punpckhwd xmm2,xmm0		; xmm2=tmp0H
212
	psrad     xmm7,(16-CONST_BITS)	; psrad xmm7,16 & pslld xmm7,CONST_BITS
213
	psrad     xmm2,(16-CONST_BITS)	; psrad xmm2,16 & pslld xmm2,CONST_BITS
214
215
	movdqa	xmm0,xmm7
216
	paddd	xmm7,xmm4		; xmm7=tmp10L
217
	psubd	xmm0,xmm4		; xmm0=tmp13L
218
	movdqa	xmm4,xmm2
219
	paddd	xmm2,xmm5		; xmm2=tmp10H
220
	psubd	xmm4,xmm5		; xmm4=tmp13H
221
222
	movdqa	XMMWORD [wk(0)], xmm7	; wk(0)=tmp10L
223
	movdqa	XMMWORD [wk(1)], xmm2	; wk(1)=tmp10H
224
	movdqa	XMMWORD [wk(2)], xmm0	; wk(2)=tmp13L
225
	movdqa	XMMWORD [wk(3)], xmm4	; wk(3)=tmp13H
226
227
	pxor      xmm5,xmm5
228
	pxor      xmm7,xmm7
229
	punpcklwd xmm5,xmm6		; xmm5=tmp1L
230
	punpckhwd xmm7,xmm6		; xmm7=tmp1H
231
	psrad     xmm5,(16-CONST_BITS)	; psrad xmm5,16 & pslld xmm5,CONST_BITS
232
	psrad     xmm7,(16-CONST_BITS)	; psrad xmm7,16 & pslld xmm7,CONST_BITS
233
234
	movdqa	xmm2,xmm5
235
	paddd	xmm5,xmm1		; xmm5=tmp11L
236
	psubd	xmm2,xmm1		; xmm2=tmp12L
237
	movdqa	xmm0,xmm7
238
	paddd	xmm7,xmm3		; xmm7=tmp11H
239
	psubd	xmm0,xmm3		; xmm0=tmp12H
240
241
	movdqa	XMMWORD [wk(4)], xmm5	; wk(4)=tmp11L
242
	movdqa	XMMWORD [wk(5)], xmm7	; wk(5)=tmp11H
243
	movdqa	XMMWORD [wk(6)], xmm2	; wk(6)=tmp12L
244
	movdqa	XMMWORD [wk(7)], xmm0	; wk(7)=tmp12H
245
246
	; -- Odd part
247
248
	movdqa	xmm4, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
249
	movdqa	xmm6, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
250
	pmullw	xmm4, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
251
	pmullw	xmm6, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
252
	movdqa	xmm1, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
253
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
254
	pmullw	xmm1, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
255
	pmullw	xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
256
257
	movdqa	xmm5,xmm6
258
	movdqa	xmm7,xmm4
259
	paddw	xmm5,xmm3		; xmm5=z3
260
	paddw	xmm7,xmm1		; xmm7=z4
261
262
	; (Original)
263
	; z5 = (z3 + z4) * 1.175875602;
264
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
265
	; z3 += z5;  z4 += z5;
266
	;
267
	; (This implementation)
268
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
269
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
270
271
	movdqa    xmm2,xmm5
272
	movdqa    xmm0,xmm5
273
	punpcklwd xmm2,xmm7
274
	punpckhwd xmm0,xmm7
275
	movdqa    xmm5,xmm2
276
	movdqa    xmm7,xmm0
277
	pmaddwd   xmm2,[rel PW_MF078_F117]	; xmm2=z3L
278
	pmaddwd   xmm0,[rel PW_MF078_F117]	; xmm0=z3H
279
	pmaddwd   xmm5,[rel PW_F117_F078]	; xmm5=z4L
280
	pmaddwd   xmm7,[rel PW_F117_F078]	; xmm7=z4H
281
282
	movdqa	XMMWORD [wk(10)], xmm2	; wk(10)=z3L
283
	movdqa	XMMWORD [wk(11)], xmm0	; wk(11)=z3H
284
285
	; (Original)
286
	; z1 = tmp0 + tmp3;  z2 = tmp1 + tmp2;
287
	; tmp0 = tmp0 * 0.298631336;  tmp1 = tmp1 * 2.053119869;
288
	; tmp2 = tmp2 * 3.072711026;  tmp3 = tmp3 * 1.501321110;
289
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
290
	; tmp0 += z1 + z3;  tmp1 += z2 + z4;
291
	; tmp2 += z2 + z3;  tmp3 += z1 + z4;
292
	;
293
	; (This implementation)
294
	; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
295
	; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
296
	; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
297
	; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
298
	; tmp0 += z3;  tmp1 += z4;
299
	; tmp2 += z3;  tmp3 += z4;
300
301
	movdqa    xmm2,xmm3
302
	movdqa    xmm0,xmm3
303
	punpcklwd xmm2,xmm4
304
	punpckhwd xmm0,xmm4
305
	movdqa    xmm3,xmm2
306
	movdqa    xmm4,xmm0
307
	pmaddwd   xmm2,[rel PW_MF060_MF089]	; xmm2=tmp0L
308
	pmaddwd   xmm0,[rel PW_MF060_MF089]	; xmm0=tmp0H
309
	pmaddwd   xmm3,[rel PW_MF089_F060]	; xmm3=tmp3L
310
	pmaddwd   xmm4,[rel PW_MF089_F060]	; xmm4=tmp3H
311
312
	paddd	xmm2, XMMWORD [wk(10)]	; xmm2=tmp0L
313
	paddd	xmm0, XMMWORD [wk(11)]	; xmm0=tmp0H
314
	paddd	xmm3,xmm5		; xmm3=tmp3L
315
	paddd	xmm4,xmm7		; xmm4=tmp3H
316
317
	movdqa	XMMWORD [wk(8)], xmm2	; wk(8)=tmp0L
318
	movdqa	XMMWORD [wk(9)], xmm0	; wk(9)=tmp0H
319
320
	movdqa    xmm2,xmm1
321
	movdqa    xmm0,xmm1
322
	punpcklwd xmm2,xmm6
323
	punpckhwd xmm0,xmm6
324
	movdqa    xmm1,xmm2
325
	movdqa    xmm6,xmm0
326
	pmaddwd   xmm2,[rel PW_MF050_MF256]	; xmm2=tmp1L
327
	pmaddwd   xmm0,[rel PW_MF050_MF256]	; xmm0=tmp1H
328
	pmaddwd   xmm1,[rel PW_MF256_F050]	; xmm1=tmp2L
329
	pmaddwd   xmm6,[rel PW_MF256_F050]	; xmm6=tmp2H
330
331
	paddd	xmm2,xmm5		; xmm2=tmp1L
332
	paddd	xmm0,xmm7		; xmm0=tmp1H
333
	paddd	xmm1, XMMWORD [wk(10)]	; xmm1=tmp2L
334
	paddd	xmm6, XMMWORD [wk(11)]	; xmm6=tmp2H
335
336
	movdqa	XMMWORD [wk(10)], xmm2	; wk(10)=tmp1L
337
	movdqa	XMMWORD [wk(11)], xmm0	; wk(11)=tmp1H
338
339
	; -- Final output stage
340
341
	movdqa	xmm5, XMMWORD [wk(0)]	; xmm5=tmp10L
342
	movdqa	xmm7, XMMWORD [wk(1)]	; xmm7=tmp10H
343
344
	movdqa	xmm2,xmm5
345
	movdqa	xmm0,xmm7
346
	paddd	xmm5,xmm3		; xmm5=data0L
347
	paddd	xmm7,xmm4		; xmm7=data0H
348
	psubd	xmm2,xmm3		; xmm2=data7L
349
	psubd	xmm0,xmm4		; xmm0=data7H
350
351
	movdqa	xmm3,[rel PD_DESCALE_P1]	; xmm3=[rel PD_DESCALE_P1]
352
353
	paddd	xmm5,xmm3
354
	paddd	xmm7,xmm3
355
	psrad	xmm5,DESCALE_P1
356
	psrad	xmm7,DESCALE_P1
357
	paddd	xmm2,xmm3
358
	paddd	xmm0,xmm3
359
	psrad	xmm2,DESCALE_P1
360
	psrad	xmm0,DESCALE_P1
361
362
	packssdw  xmm5,xmm7		; xmm5=data0=(00 01 02 03 04 05 06 07)
363
	packssdw  xmm2,xmm0		; xmm2=data7=(70 71 72 73 74 75 76 77)
364
365
	movdqa	xmm4, XMMWORD [wk(4)]	; xmm4=tmp11L
366
	movdqa	xmm3, XMMWORD [wk(5)]	; xmm3=tmp11H
367
368
	movdqa	xmm7,xmm4
369
	movdqa	xmm0,xmm3
370
	paddd	xmm4,xmm1		; xmm4=data1L
371
	paddd	xmm3,xmm6		; xmm3=data1H
372
	psubd	xmm7,xmm1		; xmm7=data6L
373
	psubd	xmm0,xmm6		; xmm0=data6H
374
375
	movdqa	xmm1,[rel PD_DESCALE_P1]	; xmm1=[rel PD_DESCALE_P1]
376
377
	paddd	xmm4,xmm1
378
	paddd	xmm3,xmm1
379
	psrad	xmm4,DESCALE_P1
380
	psrad	xmm3,DESCALE_P1
381
	paddd	xmm7,xmm1
382
	paddd	xmm0,xmm1
383
	psrad	xmm7,DESCALE_P1
384
	psrad	xmm0,DESCALE_P1
385
386
	packssdw  xmm4,xmm3		; xmm4=data1=(10 11 12 13 14 15 16 17)
387
	packssdw  xmm7,xmm0		; xmm7=data6=(60 61 62 63 64 65 66 67)
388
389
	movdqa    xmm6,xmm5		; transpose coefficients(phase 1)
390
	punpcklwd xmm5,xmm4		; xmm5=(00 10 01 11 02 12 03 13)
391
	punpckhwd xmm6,xmm4		; xmm6=(04 14 05 15 06 16 07 17)
392
	movdqa    xmm1,xmm7		; transpose coefficients(phase 1)
393
	punpcklwd xmm7,xmm2		; xmm7=(60 70 61 71 62 72 63 73)
394
	punpckhwd xmm1,xmm2		; xmm1=(64 74 65 75 66 76 67 77)
395
396
	movdqa	xmm3, XMMWORD [wk(6)]	; xmm3=tmp12L
397
	movdqa	xmm0, XMMWORD [wk(7)]	; xmm0=tmp12H
398
	movdqa	xmm4, XMMWORD [wk(10)]	; xmm4=tmp1L
399
	movdqa	xmm2, XMMWORD [wk(11)]	; xmm2=tmp1H
400
401
	movdqa	XMMWORD [wk(0)], xmm5	; wk(0)=(00 10 01 11 02 12 03 13)
402
	movdqa	XMMWORD [wk(1)], xmm6	; wk(1)=(04 14 05 15 06 16 07 17)
403
	movdqa	XMMWORD [wk(4)], xmm7	; wk(4)=(60 70 61 71 62 72 63 73)
404
	movdqa	XMMWORD [wk(5)], xmm1	; wk(5)=(64 74 65 75 66 76 67 77)
405
406
	movdqa	xmm5,xmm3
407
	movdqa	xmm6,xmm0
408
	paddd	xmm3,xmm4		; xmm3=data2L
409
	paddd	xmm0,xmm2		; xmm0=data2H
410
	psubd	xmm5,xmm4		; xmm5=data5L
411
	psubd	xmm6,xmm2		; xmm6=data5H
412
413
	movdqa	xmm7,[rel PD_DESCALE_P1]	; xmm7=[rel PD_DESCALE_P1]
414
415
	paddd	xmm3,xmm7
416
	paddd	xmm0,xmm7
417
	psrad	xmm3,DESCALE_P1
418
	psrad	xmm0,DESCALE_P1
419
	paddd	xmm5,xmm7
420
	paddd	xmm6,xmm7
421
	psrad	xmm5,DESCALE_P1
422
	psrad	xmm6,DESCALE_P1
423
424
	packssdw  xmm3,xmm0		; xmm3=data2=(20 21 22 23 24 25 26 27)
425
	packssdw  xmm5,xmm6		; xmm5=data5=(50 51 52 53 54 55 56 57)
426
427
	movdqa	xmm1, XMMWORD [wk(2)]	; xmm1=tmp13L
428
	movdqa	xmm4, XMMWORD [wk(3)]	; xmm4=tmp13H
429
	movdqa	xmm2, XMMWORD [wk(8)]	; xmm2=tmp0L
430
	movdqa	xmm7, XMMWORD [wk(9)]	; xmm7=tmp0H
431
432
	movdqa	xmm0,xmm1
433
	movdqa	xmm6,xmm4
434
	paddd	xmm1,xmm2		; xmm1=data3L
435
	paddd	xmm4,xmm7		; xmm4=data3H
436
	psubd	xmm0,xmm2		; xmm0=data4L
437
	psubd	xmm6,xmm7		; xmm6=data4H
438
439
	movdqa	xmm2,[rel PD_DESCALE_P1]	; xmm2=[rel PD_DESCALE_P1]
440
441
	paddd	xmm1,xmm2
442
	paddd	xmm4,xmm2
443
	psrad	xmm1,DESCALE_P1
444
	psrad	xmm4,DESCALE_P1
445
	paddd	xmm0,xmm2
446
	paddd	xmm6,xmm2
447
	psrad	xmm0,DESCALE_P1
448
	psrad	xmm6,DESCALE_P1
449
450
	packssdw  xmm1,xmm4		; xmm1=data3=(30 31 32 33 34 35 36 37)
451
	packssdw  xmm0,xmm6		; xmm0=data4=(40 41 42 43 44 45 46 47)
452
453
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=(00 10 01 11 02 12 03 13)
454
	movdqa	xmm2, XMMWORD [wk(1)]	; xmm2=(04 14 05 15 06 16 07 17)
455
456
	movdqa    xmm4,xmm3		; transpose coefficients(phase 1)
457
	punpcklwd xmm3,xmm1		; xmm3=(20 30 21 31 22 32 23 33)
458
	punpckhwd xmm4,xmm1		; xmm4=(24 34 25 35 26 36 27 37)
459
	movdqa    xmm6,xmm0		; transpose coefficients(phase 1)
460
	punpcklwd xmm0,xmm5		; xmm0=(40 50 41 51 42 52 43 53)
461
	punpckhwd xmm6,xmm5		; xmm6=(44 54 45 55 46 56 47 57)
462
463
	movdqa    xmm1,xmm7		; transpose coefficients(phase 2)
464
	punpckldq xmm7,xmm3		; xmm7=(00 10 20 30 01 11 21 31)
465
	punpckhdq xmm1,xmm3		; xmm1=(02 12 22 32 03 13 23 33)
466
	movdqa    xmm5,xmm2		; transpose coefficients(phase 2)
467
	punpckldq xmm2,xmm4		; xmm2=(04 14 24 34 05 15 25 35)
468
	punpckhdq xmm5,xmm4		; xmm5=(06 16 26 36 07 17 27 37)
469
470
	movdqa	xmm3, XMMWORD [wk(4)]	; xmm3=(60 70 61 71 62 72 63 73)
471
	movdqa	xmm4, XMMWORD [wk(5)]	; xmm4=(64 74 65 75 66 76 67 77)
472
473
	movdqa	XMMWORD [wk(6)], xmm2	; wk(6)=(04 14 24 34 05 15 25 35)
474
	movdqa	XMMWORD [wk(7)], xmm5	; wk(7)=(06 16 26 36 07 17 27 37)
475
476
	movdqa    xmm2,xmm0		; transpose coefficients(phase 2)
477
	punpckldq xmm0,xmm3		; xmm0=(40 50 60 70 41 51 61 71)
478
	punpckhdq xmm2,xmm3		; xmm2=(42 52 62 72 43 53 63 73)
479
	movdqa    xmm5,xmm6		; transpose coefficients(phase 2)
480
	punpckldq xmm6,xmm4		; xmm6=(44 54 64 74 45 55 65 75)
481
	punpckhdq xmm5,xmm4		; xmm5=(46 56 66 76 47 57 67 77)
482
483
	movdqa     xmm3,xmm7		; transpose coefficients(phase 3)
484
	punpcklqdq xmm7,xmm0		; xmm7=col0=(00 10 20 30 40 50 60 70)
485
	punpckhqdq xmm3,xmm0		; xmm3=col1=(01 11 21 31 41 51 61 71)
486
	movdqa     xmm4,xmm1		; transpose coefficients(phase 3)
487
	punpcklqdq xmm1,xmm2		; xmm1=col2=(02 12 22 32 42 52 62 72)
488
	punpckhqdq xmm4,xmm2		; xmm4=col3=(03 13 23 33 43 53 63 73)
489
490
	movdqa	xmm0, XMMWORD [wk(6)]	; xmm0=(04 14 24 34 05 15 25 35)
491
	movdqa	xmm2, XMMWORD [wk(7)]	; xmm2=(06 16 26 36 07 17 27 37)
492
493
	movdqa	XMMWORD [wk(8)], xmm3	; wk(8)=col1
494
	movdqa	XMMWORD [wk(9)], xmm4	; wk(9)=col3
495
496
	movdqa     xmm3,xmm0		; transpose coefficients(phase 3)
497
	punpcklqdq xmm0,xmm6		; xmm0=col4=(04 14 24 34 44 54 64 74)
498
	punpckhqdq xmm3,xmm6		; xmm3=col5=(05 15 25 35 45 55 65 75)
499
	movdqa     xmm4,xmm2		; transpose coefficients(phase 3)
500
	punpcklqdq xmm2,xmm5		; xmm2=col6=(06 16 26 36 46 56 66 76)
501
	punpckhqdq xmm4,xmm5		; xmm4=col7=(07 17 27 37 47 57 67 77)
502
503
	movdqa	XMMWORD [wk(10)], xmm3	; wk(10)=col5
504
	movdqa	XMMWORD [wk(11)], xmm4	; wk(11)=col7
505
.column_end:
506
507
	; -- Prefetch the next coefficient block
508
509
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
510
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
511
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
512
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
513
514
	; ---- Pass 2: process rows from work array, store into output array.
515
516
	mov	rax, [original_rbp]
517
	mov	rdi, r12	; (JSAMPROW *)
518
	mov	rax, r13
519
520
	; -- Even part
521
522
	; xmm7=col0, xmm1=col2, xmm0=col4, xmm2=col6
523
524
	; (Original)
525
	; z1 = (z2 + z3) * 0.541196100;
526
	; tmp2 = z1 + z3 * -1.847759065;
527
	; tmp3 = z1 + z2 * 0.765366865;
528
	;
529
	; (This implementation)
530
	; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
531
	; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
532
533
	movdqa    xmm6,xmm1		; xmm1=in2=z2
534
	movdqa    xmm5,xmm1
535
	punpcklwd xmm6,xmm2		; xmm2=in6=z3
536
	punpckhwd xmm5,xmm2
537
	movdqa    xmm1,xmm6
538
	movdqa    xmm2,xmm5
539
	pmaddwd   xmm6,[rel PW_F130_F054]	; xmm6=tmp3L
540
	pmaddwd   xmm5,[rel PW_F130_F054]	; xmm5=tmp3H
541
	pmaddwd   xmm1,[rel PW_F054_MF130]	; xmm1=tmp2L
542
	pmaddwd   xmm2,[rel PW_F054_MF130]	; xmm2=tmp2H
543
544
	movdqa    xmm3,xmm7
545
	paddw     xmm7,xmm0		; xmm7=in0+in4
546
	psubw     xmm3,xmm0		; xmm3=in0-in4
547
548
	pxor      xmm4,xmm4
549
	pxor      xmm0,xmm0
550
	punpcklwd xmm4,xmm7		; xmm4=tmp0L
551
	punpckhwd xmm0,xmm7		; xmm0=tmp0H
552
	psrad     xmm4,(16-CONST_BITS)	; psrad xmm4,16 & pslld xmm4,CONST_BITS
553
	psrad     xmm0,(16-CONST_BITS)	; psrad xmm0,16 & pslld xmm0,CONST_BITS
554
555
	movdqa	xmm7,xmm4
556
	paddd	xmm4,xmm6		; xmm4=tmp10L
557
	psubd	xmm7,xmm6		; xmm7=tmp13L
558
	movdqa	xmm6,xmm0
559
	paddd	xmm0,xmm5		; xmm0=tmp10H
560
	psubd	xmm6,xmm5		; xmm6=tmp13H
561
562
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=tmp10L
563
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=tmp10H
564
	movdqa	XMMWORD [wk(2)], xmm7	; wk(2)=tmp13L
565
	movdqa	XMMWORD [wk(3)], xmm6	; wk(3)=tmp13H
566
567
	pxor      xmm5,xmm5
568
	pxor      xmm4,xmm4
569
	punpcklwd xmm5,xmm3		; xmm5=tmp1L
570
	punpckhwd xmm4,xmm3		; xmm4=tmp1H
571
	psrad     xmm5,(16-CONST_BITS)	; psrad xmm5,16 & pslld xmm5,CONST_BITS
572
	psrad     xmm4,(16-CONST_BITS)	; psrad xmm4,16 & pslld xmm4,CONST_BITS
573
574
	movdqa	xmm0,xmm5
575
	paddd	xmm5,xmm1		; xmm5=tmp11L
576
	psubd	xmm0,xmm1		; xmm0=tmp12L
577
	movdqa	xmm7,xmm4
578
	paddd	xmm4,xmm2		; xmm4=tmp11H
579
	psubd	xmm7,xmm2		; xmm7=tmp12H
580
581
	movdqa	XMMWORD [wk(4)], xmm5	; wk(4)=tmp11L
582
	movdqa	XMMWORD [wk(5)], xmm4	; wk(5)=tmp11H
583
	movdqa	XMMWORD [wk(6)], xmm0	; wk(6)=tmp12L
584
	movdqa	XMMWORD [wk(7)], xmm7	; wk(7)=tmp12H
585
586
	; -- Odd part
587
588
	movdqa	xmm6, XMMWORD [wk(9)]	; xmm6=col3
589
	movdqa	xmm3, XMMWORD [wk(8)]	; xmm3=col1
590
	movdqa	xmm1, XMMWORD [wk(11)]	; xmm1=col7
591
	movdqa	xmm2, XMMWORD [wk(10)]	; xmm2=col5
592
593
	movdqa	xmm5,xmm6
594
	movdqa	xmm4,xmm3
595
	paddw	xmm5,xmm1		; xmm5=z3
596
	paddw	xmm4,xmm2		; xmm4=z4
597
598
	; (Original)
599
	; z5 = (z3 + z4) * 1.175875602;
600
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
601
	; z3 += z5;  z4 += z5;
602
	;
603
	; (This implementation)
604
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
605
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
606
607
	movdqa    xmm0,xmm5
608
	movdqa    xmm7,xmm5
609
	punpcklwd xmm0,xmm4
610
	punpckhwd xmm7,xmm4
611
	movdqa    xmm5,xmm0
612
	movdqa    xmm4,xmm7
613
	pmaddwd   xmm0,[rel PW_MF078_F117]	; xmm0=z3L
614
	pmaddwd   xmm7,[rel PW_MF078_F117]	; xmm7=z3H
615
	pmaddwd   xmm5,[rel PW_F117_F078]	; xmm5=z4L
616
	pmaddwd   xmm4,[rel PW_F117_F078]	; xmm4=z4H
617
618
	movdqa	XMMWORD [wk(10)], xmm0	; wk(10)=z3L
619
	movdqa	XMMWORD [wk(11)], xmm7	; wk(11)=z3H
620
621
	; (Original)
622
	; z1 = tmp0 + tmp3;  z2 = tmp1 + tmp2;
623
	; tmp0 = tmp0 * 0.298631336;  tmp1 = tmp1 * 2.053119869;
624
	; tmp2 = tmp2 * 3.072711026;  tmp3 = tmp3 * 1.501321110;
625
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
626
	; tmp0 += z1 + z3;  tmp1 += z2 + z4;
627
	; tmp2 += z2 + z3;  tmp3 += z1 + z4;
628
	;
629
	; (This implementation)
630
	; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
631
	; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
632
	; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
633
	; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
634
	; tmp0 += z3;  tmp1 += z4;
635
	; tmp2 += z3;  tmp3 += z4;
636
637
	movdqa    xmm0,xmm1
638
	movdqa    xmm7,xmm1
639
	punpcklwd xmm0,xmm3
640
	punpckhwd xmm7,xmm3
641
	movdqa    xmm1,xmm0
642
	movdqa    xmm3,xmm7
643
	pmaddwd   xmm0,[rel PW_MF060_MF089]	; xmm0=tmp0L
644
	pmaddwd   xmm7,[rel PW_MF060_MF089]	; xmm7=tmp0H
645
	pmaddwd   xmm1,[rel PW_MF089_F060]	; xmm1=tmp3L
646
	pmaddwd   xmm3,[rel PW_MF089_F060]	; xmm3=tmp3H
647
648
	paddd	xmm0, XMMWORD [wk(10)]	; xmm0=tmp0L
649
	paddd	xmm7, XMMWORD [wk(11)]	; xmm7=tmp0H
650
	paddd	xmm1,xmm5		; xmm1=tmp3L
651
	paddd	xmm3,xmm4		; xmm3=tmp3H
652
653
	movdqa	XMMWORD [wk(8)], xmm0	; wk(8)=tmp0L
654
	movdqa	XMMWORD [wk(9)], xmm7	; wk(9)=tmp0H
655
656
	movdqa    xmm0,xmm2
657
	movdqa    xmm7,xmm2
658
	punpcklwd xmm0,xmm6
659
	punpckhwd xmm7,xmm6
660
	movdqa    xmm2,xmm0
661
	movdqa    xmm6,xmm7
662
	pmaddwd   xmm0,[rel PW_MF050_MF256]	; xmm0=tmp1L
663
	pmaddwd   xmm7,[rel PW_MF050_MF256]	; xmm7=tmp1H
664
	pmaddwd   xmm2,[rel PW_MF256_F050]	; xmm2=tmp2L
665
	pmaddwd   xmm6,[rel PW_MF256_F050]	; xmm6=tmp2H
666
667
	paddd	xmm0,xmm5		; xmm0=tmp1L
668
	paddd	xmm7,xmm4		; xmm7=tmp1H
669
	paddd	xmm2, XMMWORD [wk(10)]	; xmm2=tmp2L
670
	paddd	xmm6, XMMWORD [wk(11)]	; xmm6=tmp2H
671
672
	movdqa	XMMWORD [wk(10)], xmm0	; wk(10)=tmp1L
673
	movdqa	XMMWORD [wk(11)], xmm7	; wk(11)=tmp1H
674
675
	; -- Final output stage
676
677
	movdqa	xmm5, XMMWORD [wk(0)]	; xmm5=tmp10L
678
	movdqa	xmm4, XMMWORD [wk(1)]	; xmm4=tmp10H
679
680
	movdqa	xmm0,xmm5
681
	movdqa	xmm7,xmm4
682
	paddd	xmm5,xmm1		; xmm5=data0L
683
	paddd	xmm4,xmm3		; xmm4=data0H
684
	psubd	xmm0,xmm1		; xmm0=data7L
685
	psubd	xmm7,xmm3		; xmm7=data7H
686
687
	movdqa	xmm1,[rel PD_DESCALE_P2]	; xmm1=[rel PD_DESCALE_P2]
688
689
	paddd	xmm5,xmm1
690
	paddd	xmm4,xmm1
691
	psrad	xmm5,DESCALE_P2
692
	psrad	xmm4,DESCALE_P2
693
	paddd	xmm0,xmm1
694
	paddd	xmm7,xmm1
695
	psrad	xmm0,DESCALE_P2
696
	psrad	xmm7,DESCALE_P2
697
698
	packssdw  xmm5,xmm4		; xmm5=data0=(00 10 20 30 40 50 60 70)
699
	packssdw  xmm0,xmm7		; xmm0=data7=(07 17 27 37 47 57 67 77)
700
701
	movdqa	xmm3, XMMWORD [wk(4)]	; xmm3=tmp11L
702
	movdqa	xmm1, XMMWORD [wk(5)]	; xmm1=tmp11H
703
704
	movdqa	xmm4,xmm3
705
	movdqa	xmm7,xmm1
706
	paddd	xmm3,xmm2		; xmm3=data1L
707
	paddd	xmm1,xmm6		; xmm1=data1H
708
	psubd	xmm4,xmm2		; xmm4=data6L
709
	psubd	xmm7,xmm6		; xmm7=data6H
710
711
	movdqa	xmm2,[rel PD_DESCALE_P2]	; xmm2=[rel PD_DESCALE_P2]
712
713
	paddd	xmm3,xmm2
714
	paddd	xmm1,xmm2
715
	psrad	xmm3,DESCALE_P2
716
	psrad	xmm1,DESCALE_P2
717
	paddd	xmm4,xmm2
718
	paddd	xmm7,xmm2
719
	psrad	xmm4,DESCALE_P2
720
	psrad	xmm7,DESCALE_P2
721
722
	packssdw  xmm3,xmm1		; xmm3=data1=(01 11 21 31 41 51 61 71)
723
	packssdw  xmm4,xmm7		; xmm4=data6=(06 16 26 36 46 56 66 76)
724
725
	packsswb  xmm5,xmm4		; xmm5=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
726
	packsswb  xmm3,xmm0		; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
727
728
	movdqa	xmm6, XMMWORD [wk(6)]	; xmm6=tmp12L
729
	movdqa	xmm2, XMMWORD [wk(7)]	; xmm2=tmp12H
730
	movdqa	xmm1, XMMWORD [wk(10)]	; xmm1=tmp1L
731
	movdqa	xmm7, XMMWORD [wk(11)]	; xmm7=tmp1H
732
733
	movdqa	XMMWORD [wk(0)], xmm5	; wk(0)=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
734
	movdqa	XMMWORD [wk(1)], xmm3	; wk(1)=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
735
736
	movdqa	xmm4,xmm6
737
	movdqa	xmm0,xmm2
738
	paddd	xmm6,xmm1		; xmm6=data2L
739
	paddd	xmm2,xmm7		; xmm2=data2H
740
	psubd	xmm4,xmm1		; xmm4=data5L
741
	psubd	xmm0,xmm7		; xmm0=data5H
742
743
	movdqa	xmm5,[rel PD_DESCALE_P2]	; xmm5=[rel PD_DESCALE_P2]
744
745
	paddd	xmm6,xmm5
746
	paddd	xmm2,xmm5
747
	psrad	xmm6,DESCALE_P2
748
	psrad	xmm2,DESCALE_P2
749
	paddd	xmm4,xmm5
750
	paddd	xmm0,xmm5
751
	psrad	xmm4,DESCALE_P2
752
	psrad	xmm0,DESCALE_P2
753
754
	packssdw  xmm6,xmm2		; xmm6=data2=(02 12 22 32 42 52 62 72)
755
	packssdw  xmm4,xmm0		; xmm4=data5=(05 15 25 35 45 55 65 75)
756
757
	movdqa	xmm3, XMMWORD [wk(2)]	; xmm3=tmp13L
758
	movdqa	xmm1, XMMWORD [wk(3)]	; xmm1=tmp13H
759
	movdqa	xmm7, XMMWORD [wk(8)]	; xmm7=tmp0L
760
	movdqa	xmm5, XMMWORD [wk(9)]	; xmm5=tmp0H
761
762
	movdqa	xmm2,xmm3
763
	movdqa	xmm0,xmm1
764
	paddd	xmm3,xmm7		; xmm3=data3L
765
	paddd	xmm1,xmm5		; xmm1=data3H
766
	psubd	xmm2,xmm7		; xmm2=data4L
767
	psubd	xmm0,xmm5		; xmm0=data4H
768
769
	movdqa	xmm7,[rel PD_DESCALE_P2]	; xmm7=[rel PD_DESCALE_P2]
770
771
	paddd	xmm3,xmm7
772
	paddd	xmm1,xmm7
773
	psrad	xmm3,DESCALE_P2
774
	psrad	xmm1,DESCALE_P2
775
	paddd	xmm2,xmm7
776
	paddd	xmm0,xmm7
777
	psrad	xmm2,DESCALE_P2
778
	psrad	xmm0,DESCALE_P2
779
780
	movdqa    xmm5,[rel PB_CENTERJSAMP]	; xmm5=[rel PB_CENTERJSAMP]
781
782
	packssdw  xmm3,xmm1		; xmm3=data3=(03 13 23 33 43 53 63 73)
783
	packssdw  xmm2,xmm0		; xmm2=data4=(04 14 24 34 44 54 64 74)
784
785
	movdqa    xmm7, XMMWORD [wk(0)]	; xmm7=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
786
	movdqa    xmm1, XMMWORD [wk(1)]	; xmm1=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
787
788
	packsswb  xmm6,xmm2		; xmm6=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74)
789
	packsswb  xmm3,xmm4		; xmm3=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75)
790
791
	paddb     xmm7,xmm5
792
	paddb     xmm1,xmm5
793
	paddb     xmm6,xmm5
794
	paddb     xmm3,xmm5
795
796
	movdqa    xmm0,xmm7	; transpose coefficients(phase 1)
797
	punpcklbw xmm7,xmm1	; xmm7=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71)
798
	punpckhbw xmm0,xmm1	; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77)
799
	movdqa    xmm2,xmm6	; transpose coefficients(phase 1)
800
	punpcklbw xmm6,xmm3	; xmm6=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73)
801
	punpckhbw xmm2,xmm3	; xmm2=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75)
802
803
	movdqa    xmm4,xmm7	; transpose coefficients(phase 2)
804
	punpcklwd xmm7,xmm6	; xmm7=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
805
	punpckhwd xmm4,xmm6	; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73)
806
	movdqa    xmm5,xmm2	; transpose coefficients(phase 2)
807
	punpcklwd xmm2,xmm0	; xmm2=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
808
	punpckhwd xmm5,xmm0	; xmm5=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77)
809
810
	movdqa    xmm1,xmm7	; transpose coefficients(phase 3)
811
	punpckldq xmm7,xmm2	; xmm7=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
812
	punpckhdq xmm1,xmm2	; xmm1=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
813
	movdqa    xmm3,xmm4	; transpose coefficients(phase 3)
814
	punpckldq xmm4,xmm5	; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57)
815
	punpckhdq xmm3,xmm5	; xmm3=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77)
816
817
	pshufd	xmm6,xmm7,0x4E	; xmm6=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
818
	pshufd	xmm0,xmm1,0x4E	; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
819
	pshufd	xmm2,xmm4,0x4E	; xmm2=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47)
820
	pshufd	xmm5,xmm3,0x4E	; xmm5=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67)
821
822
	mov	rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
823
	mov	rsi, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
824
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm7
825
	movq	XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm1
826
	mov	rdx, JSAMPROW [rdi+4*SIZEOF_JSAMPROW]
827
	mov	rsi, JSAMPROW [rdi+6*SIZEOF_JSAMPROW]
828
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4
829
	movq	XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3
830
831
	mov	rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
832
	mov	rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
833
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6
834
	movq	XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm0
835
	mov	rdx, JSAMPROW [rdi+5*SIZEOF_JSAMPROW]
836
	mov	rsi, JSAMPROW [rdi+7*SIZEOF_JSAMPROW]
837
	movq	XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm2
838
	movq	XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm5
839
840
	uncollect_args
841
	mov	rsp,rbp		; rsp <- aligned rbp
842
	pop	rsp		; rsp <- original rbp
843
	pop	rbp
844
	ret
845
846
; For some reason, the OS X linker does not honor the request to align the
847
; segment unless we do this.
848
	align	16
(-)a/jpeg/simd/jiss2int.asm (+859 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jiss2int.asm - accurate integer IDCT (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a slow-but-accurate integer implementation of the
18
; inverse DCT (Discrete Cosine Transform). The following code is based
19
; directly on the IJG's original jidctint.c; see the jidctint.c for
20
; more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	13
30
%define PASS1_BITS	2
31
32
%define DESCALE_P1	(CONST_BITS-PASS1_BITS)
33
%define DESCALE_P2	(CONST_BITS+PASS1_BITS+3)
34
35
%if CONST_BITS == 13
36
F_0_298	equ	 2446		; FIX(0.298631336)
37
F_0_390	equ	 3196		; FIX(0.390180644)
38
F_0_541	equ	 4433		; FIX(0.541196100)
39
F_0_765	equ	 6270		; FIX(0.765366865)
40
F_0_899	equ	 7373		; FIX(0.899976223)
41
F_1_175	equ	 9633		; FIX(1.175875602)
42
F_1_501	equ	12299		; FIX(1.501321110)
43
F_1_847	equ	15137		; FIX(1.847759065)
44
F_1_961	equ	16069		; FIX(1.961570560)
45
F_2_053	equ	16819		; FIX(2.053119869)
46
F_2_562	equ	20995		; FIX(2.562915447)
47
F_3_072	equ	25172		; FIX(3.072711026)
48
%else
49
; NASM cannot do compile-time arithmetic on floating-point constants.
50
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
51
F_0_298	equ	DESCALE( 320652955,30-CONST_BITS)	; FIX(0.298631336)
52
F_0_390	equ	DESCALE( 418953276,30-CONST_BITS)	; FIX(0.390180644)
53
F_0_541	equ	DESCALE( 581104887,30-CONST_BITS)	; FIX(0.541196100)
54
F_0_765	equ	DESCALE( 821806413,30-CONST_BITS)	; FIX(0.765366865)
55
F_0_899	equ	DESCALE( 966342111,30-CONST_BITS)	; FIX(0.899976223)
56
F_1_175	equ	DESCALE(1262586813,30-CONST_BITS)	; FIX(1.175875602)
57
F_1_501	equ	DESCALE(1612031267,30-CONST_BITS)	; FIX(1.501321110)
58
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
59
F_1_961	equ	DESCALE(2106220350,30-CONST_BITS)	; FIX(1.961570560)
60
F_2_053	equ	DESCALE(2204520673,30-CONST_BITS)	; FIX(2.053119869)
61
F_2_562	equ	DESCALE(2751909506,30-CONST_BITS)	; FIX(2.562915447)
62
F_3_072	equ	DESCALE(3299298341,30-CONST_BITS)	; FIX(3.072711026)
63
%endif
64
65
; --------------------------------------------------------------------------
66
	SECTION	SEG_CONST
67
68
	alignz	16
69
	global	EXTN(jconst_idct_islow_sse2)
70
71
EXTN(jconst_idct_islow_sse2):
72
73
PW_F130_F054	times 4 dw  (F_0_541+F_0_765), F_0_541
74
PW_F054_MF130	times 4 dw  F_0_541, (F_0_541-F_1_847)
75
PW_MF078_F117	times 4 dw  (F_1_175-F_1_961), F_1_175
76
PW_F117_F078	times 4 dw  F_1_175, (F_1_175-F_0_390)
77
PW_MF060_MF089	times 4 dw  (F_0_298-F_0_899),-F_0_899
78
PW_MF089_F060	times 4 dw -F_0_899, (F_1_501-F_0_899)
79
PW_MF050_MF256	times 4 dw  (F_2_053-F_2_562),-F_2_562
80
PW_MF256_F050	times 4 dw -F_2_562, (F_3_072-F_2_562)
81
PD_DESCALE_P1	times 4 dd  1 << (DESCALE_P1-1)
82
PD_DESCALE_P2	times 4 dd  1 << (DESCALE_P2-1)
83
PB_CENTERJSAMP	times 16 db CENTERJSAMPLE
84
85
	alignz	16
86
87
; --------------------------------------------------------------------------
88
	SECTION	SEG_TEXT
89
	BITS	32
90
;
91
; Perform dequantization and inverse DCT on one block of coefficients.
92
;
93
; GLOBAL(void)
94
; jsimd_idct_islow_sse2 (void * dct_table, JCOEFPTR coef_block,
95
;                        JSAMPARRAY output_buf, JDIMENSION output_col)
96
;
97
98
%define dct_table(b)	(b)+8			; jpeg_component_info * compptr
99
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
100
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
101
%define output_col(b)	(b)+20		; JDIMENSION output_col
102
103
%define original_ebp	ebp+0
104
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
105
%define WK_NUM		12
106
107
	align	16
108
	global	EXTN(jsimd_idct_islow_sse2)
109
110
EXTN(jsimd_idct_islow_sse2):
111
	push	ebp
112
	mov	eax,esp				; eax = original ebp
113
	sub	esp, byte 4
114
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
115
	mov	[esp],eax
116
	mov	ebp,esp				; ebp = aligned ebp
117
	lea	esp, [wk(0)]
118
	pushpic	ebx
119
;	push	ecx		; unused
120
;	push	edx		; need not be preserved
121
	push	esi
122
	push	edi
123
124
	get_GOT	ebx		; get GOT address
125
126
	; ---- Pass 1: process columns from input.
127
128
;	mov	eax, [original_ebp]
129
	mov	edx, POINTER [dct_table(eax)]	; quantptr
130
	mov	esi, JCOEFPTR [coef_block(eax)]		; inptr
131
132
%ifndef NO_ZERO_COLUMN_TEST_ISLOW_SSE2
133
	mov	eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
134
	or	eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
135
	jnz	near .columnDCT
136
137
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
138
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)]
139
	por	xmm0, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
140
	por	xmm1, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)]
141
	por	xmm0, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
142
	por	xmm1, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)]
143
	por	xmm0, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
144
	por	xmm1,xmm0
145
	packsswb xmm1,xmm1
146
	packsswb xmm1,xmm1
147
	movd	eax,xmm1
148
	test	eax,eax
149
	jnz	short .columnDCT
150
151
	; -- AC terms all zero
152
153
	movdqa	xmm5, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
154
	pmullw	xmm5, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
155
156
	psllw	xmm5,PASS1_BITS
157
158
	movdqa    xmm4,xmm5		; xmm5=in0=(00 01 02 03 04 05 06 07)
159
	punpcklwd xmm5,xmm5		; xmm5=(00 00 01 01 02 02 03 03)
160
	punpckhwd xmm4,xmm4		; xmm4=(04 04 05 05 06 06 07 07)
161
162
	pshufd	xmm7,xmm5,0x00		; xmm7=col0=(00 00 00 00 00 00 00 00)
163
	pshufd	xmm6,xmm5,0x55		; xmm6=col1=(01 01 01 01 01 01 01 01)
164
	pshufd	xmm1,xmm5,0xAA		; xmm1=col2=(02 02 02 02 02 02 02 02)
165
	pshufd	xmm5,xmm5,0xFF		; xmm5=col3=(03 03 03 03 03 03 03 03)
166
	pshufd	xmm0,xmm4,0x00		; xmm0=col4=(04 04 04 04 04 04 04 04)
167
	pshufd	xmm3,xmm4,0x55		; xmm3=col5=(05 05 05 05 05 05 05 05)
168
	pshufd	xmm2,xmm4,0xAA		; xmm2=col6=(06 06 06 06 06 06 06 06)
169
	pshufd	xmm4,xmm4,0xFF		; xmm4=col7=(07 07 07 07 07 07 07 07)
170
171
	movdqa	XMMWORD [wk(8)], xmm6	; wk(8)=col1
172
	movdqa	XMMWORD [wk(9)], xmm5	; wk(9)=col3
173
	movdqa	XMMWORD [wk(10)], xmm3	; wk(10)=col5
174
	movdqa	XMMWORD [wk(11)], xmm4	; wk(11)=col7
175
	jmp	near .column_end
176
	alignx	16,7
177
%endif
178
.columnDCT:
179
180
	; -- Even part
181
182
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
183
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)]
184
	pmullw	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
185
	pmullw	xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
186
	movdqa	xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)]
187
	movdqa	xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)]
188
	pmullw	xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
189
	pmullw	xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
190
191
	; (Original)
192
	; z1 = (z2 + z3) * 0.541196100;
193
	; tmp2 = z1 + z3 * -1.847759065;
194
	; tmp3 = z1 + z2 * 0.765366865;
195
	;
196
	; (This implementation)
197
	; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
198
	; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
199
200
	movdqa    xmm4,xmm1		; xmm1=in2=z2
201
	movdqa    xmm5,xmm1
202
	punpcklwd xmm4,xmm3		; xmm3=in6=z3
203
	punpckhwd xmm5,xmm3
204
	movdqa    xmm1,xmm4
205
	movdqa    xmm3,xmm5
206
	pmaddwd   xmm4,[GOTOFF(ebx,PW_F130_F054)]	; xmm4=tmp3L
207
	pmaddwd   xmm5,[GOTOFF(ebx,PW_F130_F054)]	; xmm5=tmp3H
208
	pmaddwd   xmm1,[GOTOFF(ebx,PW_F054_MF130)]	; xmm1=tmp2L
209
	pmaddwd   xmm3,[GOTOFF(ebx,PW_F054_MF130)]	; xmm3=tmp2H
210
211
	movdqa    xmm6,xmm0
212
	paddw     xmm0,xmm2		; xmm0=in0+in4
213
	psubw     xmm6,xmm2		; xmm6=in0-in4
214
215
	pxor      xmm7,xmm7
216
	pxor      xmm2,xmm2
217
	punpcklwd xmm7,xmm0		; xmm7=tmp0L
218
	punpckhwd xmm2,xmm0		; xmm2=tmp0H
219
	psrad     xmm7,(16-CONST_BITS)	; psrad xmm7,16 & pslld xmm7,CONST_BITS
220
	psrad     xmm2,(16-CONST_BITS)	; psrad xmm2,16 & pslld xmm2,CONST_BITS
221
222
	movdqa	xmm0,xmm7
223
	paddd	xmm7,xmm4		; xmm7=tmp10L
224
	psubd	xmm0,xmm4		; xmm0=tmp13L
225
	movdqa	xmm4,xmm2
226
	paddd	xmm2,xmm5		; xmm2=tmp10H
227
	psubd	xmm4,xmm5		; xmm4=tmp13H
228
229
	movdqa	XMMWORD [wk(0)], xmm7	; wk(0)=tmp10L
230
	movdqa	XMMWORD [wk(1)], xmm2	; wk(1)=tmp10H
231
	movdqa	XMMWORD [wk(2)], xmm0	; wk(2)=tmp13L
232
	movdqa	XMMWORD [wk(3)], xmm4	; wk(3)=tmp13H
233
234
	pxor      xmm5,xmm5
235
	pxor      xmm7,xmm7
236
	punpcklwd xmm5,xmm6		; xmm5=tmp1L
237
	punpckhwd xmm7,xmm6		; xmm7=tmp1H
238
	psrad     xmm5,(16-CONST_BITS)	; psrad xmm5,16 & pslld xmm5,CONST_BITS
239
	psrad     xmm7,(16-CONST_BITS)	; psrad xmm7,16 & pslld xmm7,CONST_BITS
240
241
	movdqa	xmm2,xmm5
242
	paddd	xmm5,xmm1		; xmm5=tmp11L
243
	psubd	xmm2,xmm1		; xmm2=tmp12L
244
	movdqa	xmm0,xmm7
245
	paddd	xmm7,xmm3		; xmm7=tmp11H
246
	psubd	xmm0,xmm3		; xmm0=tmp12H
247
248
	movdqa	XMMWORD [wk(4)], xmm5	; wk(4)=tmp11L
249
	movdqa	XMMWORD [wk(5)], xmm7	; wk(5)=tmp11H
250
	movdqa	XMMWORD [wk(6)], xmm2	; wk(6)=tmp12L
251
	movdqa	XMMWORD [wk(7)], xmm0	; wk(7)=tmp12H
252
253
	; -- Odd part
254
255
	movdqa	xmm4, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
256
	movdqa	xmm6, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
257
	pmullw	xmm4, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
258
	pmullw	xmm6, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
259
	movdqa	xmm1, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
260
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
261
	pmullw	xmm1, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
262
	pmullw	xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
263
264
	movdqa	xmm5,xmm6
265
	movdqa	xmm7,xmm4
266
	paddw	xmm5,xmm3		; xmm5=z3
267
	paddw	xmm7,xmm1		; xmm7=z4
268
269
	; (Original)
270
	; z5 = (z3 + z4) * 1.175875602;
271
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
272
	; z3 += z5;  z4 += z5;
273
	;
274
	; (This implementation)
275
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
276
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
277
278
	movdqa    xmm2,xmm5
279
	movdqa    xmm0,xmm5
280
	punpcklwd xmm2,xmm7
281
	punpckhwd xmm0,xmm7
282
	movdqa    xmm5,xmm2
283
	movdqa    xmm7,xmm0
284
	pmaddwd   xmm2,[GOTOFF(ebx,PW_MF078_F117)]	; xmm2=z3L
285
	pmaddwd   xmm0,[GOTOFF(ebx,PW_MF078_F117)]	; xmm0=z3H
286
	pmaddwd   xmm5,[GOTOFF(ebx,PW_F117_F078)]	; xmm5=z4L
287
	pmaddwd   xmm7,[GOTOFF(ebx,PW_F117_F078)]	; xmm7=z4H
288
289
	movdqa	XMMWORD [wk(10)], xmm2	; wk(10)=z3L
290
	movdqa	XMMWORD [wk(11)], xmm0	; wk(11)=z3H
291
292
	; (Original)
293
	; z1 = tmp0 + tmp3;  z2 = tmp1 + tmp2;
294
	; tmp0 = tmp0 * 0.298631336;  tmp1 = tmp1 * 2.053119869;
295
	; tmp2 = tmp2 * 3.072711026;  tmp3 = tmp3 * 1.501321110;
296
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
297
	; tmp0 += z1 + z3;  tmp1 += z2 + z4;
298
	; tmp2 += z2 + z3;  tmp3 += z1 + z4;
299
	;
300
	; (This implementation)
301
	; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
302
	; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
303
	; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
304
	; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
305
	; tmp0 += z3;  tmp1 += z4;
306
	; tmp2 += z3;  tmp3 += z4;
307
308
	movdqa    xmm2,xmm3
309
	movdqa    xmm0,xmm3
310
	punpcklwd xmm2,xmm4
311
	punpckhwd xmm0,xmm4
312
	movdqa    xmm3,xmm2
313
	movdqa    xmm4,xmm0
314
	pmaddwd   xmm2,[GOTOFF(ebx,PW_MF060_MF089)]	; xmm2=tmp0L
315
	pmaddwd   xmm0,[GOTOFF(ebx,PW_MF060_MF089)]	; xmm0=tmp0H
316
	pmaddwd   xmm3,[GOTOFF(ebx,PW_MF089_F060)]	; xmm3=tmp3L
317
	pmaddwd   xmm4,[GOTOFF(ebx,PW_MF089_F060)]	; xmm4=tmp3H
318
319
	paddd	xmm2, XMMWORD [wk(10)]	; xmm2=tmp0L
320
	paddd	xmm0, XMMWORD [wk(11)]	; xmm0=tmp0H
321
	paddd	xmm3,xmm5		; xmm3=tmp3L
322
	paddd	xmm4,xmm7		; xmm4=tmp3H
323
324
	movdqa	XMMWORD [wk(8)], xmm2	; wk(8)=tmp0L
325
	movdqa	XMMWORD [wk(9)], xmm0	; wk(9)=tmp0H
326
327
	movdqa    xmm2,xmm1
328
	movdqa    xmm0,xmm1
329
	punpcklwd xmm2,xmm6
330
	punpckhwd xmm0,xmm6
331
	movdqa    xmm1,xmm2
332
	movdqa    xmm6,xmm0
333
	pmaddwd   xmm2,[GOTOFF(ebx,PW_MF050_MF256)]	; xmm2=tmp1L
334
	pmaddwd   xmm0,[GOTOFF(ebx,PW_MF050_MF256)]	; xmm0=tmp1H
335
	pmaddwd   xmm1,[GOTOFF(ebx,PW_MF256_F050)]	; xmm1=tmp2L
336
	pmaddwd   xmm6,[GOTOFF(ebx,PW_MF256_F050)]	; xmm6=tmp2H
337
338
	paddd	xmm2,xmm5		; xmm2=tmp1L
339
	paddd	xmm0,xmm7		; xmm0=tmp1H
340
	paddd	xmm1, XMMWORD [wk(10)]	; xmm1=tmp2L
341
	paddd	xmm6, XMMWORD [wk(11)]	; xmm6=tmp2H
342
343
	movdqa	XMMWORD [wk(10)], xmm2	; wk(10)=tmp1L
344
	movdqa	XMMWORD [wk(11)], xmm0	; wk(11)=tmp1H
345
346
	; -- Final output stage
347
348
	movdqa	xmm5, XMMWORD [wk(0)]	; xmm5=tmp10L
349
	movdqa	xmm7, XMMWORD [wk(1)]	; xmm7=tmp10H
350
351
	movdqa	xmm2,xmm5
352
	movdqa	xmm0,xmm7
353
	paddd	xmm5,xmm3		; xmm5=data0L
354
	paddd	xmm7,xmm4		; xmm7=data0H
355
	psubd	xmm2,xmm3		; xmm2=data7L
356
	psubd	xmm0,xmm4		; xmm0=data7H
357
358
	movdqa	xmm3,[GOTOFF(ebx,PD_DESCALE_P1)]	; xmm3=[PD_DESCALE_P1]
359
360
	paddd	xmm5,xmm3
361
	paddd	xmm7,xmm3
362
	psrad	xmm5,DESCALE_P1
363
	psrad	xmm7,DESCALE_P1
364
	paddd	xmm2,xmm3
365
	paddd	xmm0,xmm3
366
	psrad	xmm2,DESCALE_P1
367
	psrad	xmm0,DESCALE_P1
368
369
	packssdw  xmm5,xmm7		; xmm5=data0=(00 01 02 03 04 05 06 07)
370
	packssdw  xmm2,xmm0		; xmm2=data7=(70 71 72 73 74 75 76 77)
371
372
	movdqa	xmm4, XMMWORD [wk(4)]	; xmm4=tmp11L
373
	movdqa	xmm3, XMMWORD [wk(5)]	; xmm3=tmp11H
374
375
	movdqa	xmm7,xmm4
376
	movdqa	xmm0,xmm3
377
	paddd	xmm4,xmm1		; xmm4=data1L
378
	paddd	xmm3,xmm6		; xmm3=data1H
379
	psubd	xmm7,xmm1		; xmm7=data6L
380
	psubd	xmm0,xmm6		; xmm0=data6H
381
382
	movdqa	xmm1,[GOTOFF(ebx,PD_DESCALE_P1)]	; xmm1=[PD_DESCALE_P1]
383
384
	paddd	xmm4,xmm1
385
	paddd	xmm3,xmm1
386
	psrad	xmm4,DESCALE_P1
387
	psrad	xmm3,DESCALE_P1
388
	paddd	xmm7,xmm1
389
	paddd	xmm0,xmm1
390
	psrad	xmm7,DESCALE_P1
391
	psrad	xmm0,DESCALE_P1
392
393
	packssdw  xmm4,xmm3		; xmm4=data1=(10 11 12 13 14 15 16 17)
394
	packssdw  xmm7,xmm0		; xmm7=data6=(60 61 62 63 64 65 66 67)
395
396
	movdqa    xmm6,xmm5		; transpose coefficients(phase 1)
397
	punpcklwd xmm5,xmm4		; xmm5=(00 10 01 11 02 12 03 13)
398
	punpckhwd xmm6,xmm4		; xmm6=(04 14 05 15 06 16 07 17)
399
	movdqa    xmm1,xmm7		; transpose coefficients(phase 1)
400
	punpcklwd xmm7,xmm2		; xmm7=(60 70 61 71 62 72 63 73)
401
	punpckhwd xmm1,xmm2		; xmm1=(64 74 65 75 66 76 67 77)
402
403
	movdqa	xmm3, XMMWORD [wk(6)]	; xmm3=tmp12L
404
	movdqa	xmm0, XMMWORD [wk(7)]	; xmm0=tmp12H
405
	movdqa	xmm4, XMMWORD [wk(10)]	; xmm4=tmp1L
406
	movdqa	xmm2, XMMWORD [wk(11)]	; xmm2=tmp1H
407
408
	movdqa	XMMWORD [wk(0)], xmm5	; wk(0)=(00 10 01 11 02 12 03 13)
409
	movdqa	XMMWORD [wk(1)], xmm6	; wk(1)=(04 14 05 15 06 16 07 17)
410
	movdqa	XMMWORD [wk(4)], xmm7	; wk(4)=(60 70 61 71 62 72 63 73)
411
	movdqa	XMMWORD [wk(5)], xmm1	; wk(5)=(64 74 65 75 66 76 67 77)
412
413
	movdqa	xmm5,xmm3
414
	movdqa	xmm6,xmm0
415
	paddd	xmm3,xmm4		; xmm3=data2L
416
	paddd	xmm0,xmm2		; xmm0=data2H
417
	psubd	xmm5,xmm4		; xmm5=data5L
418
	psubd	xmm6,xmm2		; xmm6=data5H
419
420
	movdqa	xmm7,[GOTOFF(ebx,PD_DESCALE_P1)]	; xmm7=[PD_DESCALE_P1]
421
422
	paddd	xmm3,xmm7
423
	paddd	xmm0,xmm7
424
	psrad	xmm3,DESCALE_P1
425
	psrad	xmm0,DESCALE_P1
426
	paddd	xmm5,xmm7
427
	paddd	xmm6,xmm7
428
	psrad	xmm5,DESCALE_P1
429
	psrad	xmm6,DESCALE_P1
430
431
	packssdw  xmm3,xmm0		; xmm3=data2=(20 21 22 23 24 25 26 27)
432
	packssdw  xmm5,xmm6		; xmm5=data5=(50 51 52 53 54 55 56 57)
433
434
	movdqa	xmm1, XMMWORD [wk(2)]	; xmm1=tmp13L
435
	movdqa	xmm4, XMMWORD [wk(3)]	; xmm4=tmp13H
436
	movdqa	xmm2, XMMWORD [wk(8)]	; xmm2=tmp0L
437
	movdqa	xmm7, XMMWORD [wk(9)]	; xmm7=tmp0H
438
439
	movdqa	xmm0,xmm1
440
	movdqa	xmm6,xmm4
441
	paddd	xmm1,xmm2		; xmm1=data3L
442
	paddd	xmm4,xmm7		; xmm4=data3H
443
	psubd	xmm0,xmm2		; xmm0=data4L
444
	psubd	xmm6,xmm7		; xmm6=data4H
445
446
	movdqa	xmm2,[GOTOFF(ebx,PD_DESCALE_P1)]	; xmm2=[PD_DESCALE_P1]
447
448
	paddd	xmm1,xmm2
449
	paddd	xmm4,xmm2
450
	psrad	xmm1,DESCALE_P1
451
	psrad	xmm4,DESCALE_P1
452
	paddd	xmm0,xmm2
453
	paddd	xmm6,xmm2
454
	psrad	xmm0,DESCALE_P1
455
	psrad	xmm6,DESCALE_P1
456
457
	packssdw  xmm1,xmm4		; xmm1=data3=(30 31 32 33 34 35 36 37)
458
	packssdw  xmm0,xmm6		; xmm0=data4=(40 41 42 43 44 45 46 47)
459
460
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=(00 10 01 11 02 12 03 13)
461
	movdqa	xmm2, XMMWORD [wk(1)]	; xmm2=(04 14 05 15 06 16 07 17)
462
463
	movdqa    xmm4,xmm3		; transpose coefficients(phase 1)
464
	punpcklwd xmm3,xmm1		; xmm3=(20 30 21 31 22 32 23 33)
465
	punpckhwd xmm4,xmm1		; xmm4=(24 34 25 35 26 36 27 37)
466
	movdqa    xmm6,xmm0		; transpose coefficients(phase 1)
467
	punpcklwd xmm0,xmm5		; xmm0=(40 50 41 51 42 52 43 53)
468
	punpckhwd xmm6,xmm5		; xmm6=(44 54 45 55 46 56 47 57)
469
470
	movdqa    xmm1,xmm7		; transpose coefficients(phase 2)
471
	punpckldq xmm7,xmm3		; xmm7=(00 10 20 30 01 11 21 31)
472
	punpckhdq xmm1,xmm3		; xmm1=(02 12 22 32 03 13 23 33)
473
	movdqa    xmm5,xmm2		; transpose coefficients(phase 2)
474
	punpckldq xmm2,xmm4		; xmm2=(04 14 24 34 05 15 25 35)
475
	punpckhdq xmm5,xmm4		; xmm5=(06 16 26 36 07 17 27 37)
476
477
	movdqa	xmm3, XMMWORD [wk(4)]	; xmm3=(60 70 61 71 62 72 63 73)
478
	movdqa	xmm4, XMMWORD [wk(5)]	; xmm4=(64 74 65 75 66 76 67 77)
479
480
	movdqa	XMMWORD [wk(6)], xmm2	; wk(6)=(04 14 24 34 05 15 25 35)
481
	movdqa	XMMWORD [wk(7)], xmm5	; wk(7)=(06 16 26 36 07 17 27 37)
482
483
	movdqa    xmm2,xmm0		; transpose coefficients(phase 2)
484
	punpckldq xmm0,xmm3		; xmm0=(40 50 60 70 41 51 61 71)
485
	punpckhdq xmm2,xmm3		; xmm2=(42 52 62 72 43 53 63 73)
486
	movdqa    xmm5,xmm6		; transpose coefficients(phase 2)
487
	punpckldq xmm6,xmm4		; xmm6=(44 54 64 74 45 55 65 75)
488
	punpckhdq xmm5,xmm4		; xmm5=(46 56 66 76 47 57 67 77)
489
490
	movdqa     xmm3,xmm7		; transpose coefficients(phase 3)
491
	punpcklqdq xmm7,xmm0		; xmm7=col0=(00 10 20 30 40 50 60 70)
492
	punpckhqdq xmm3,xmm0		; xmm3=col1=(01 11 21 31 41 51 61 71)
493
	movdqa     xmm4,xmm1		; transpose coefficients(phase 3)
494
	punpcklqdq xmm1,xmm2		; xmm1=col2=(02 12 22 32 42 52 62 72)
495
	punpckhqdq xmm4,xmm2		; xmm4=col3=(03 13 23 33 43 53 63 73)
496
497
	movdqa	xmm0, XMMWORD [wk(6)]	; xmm0=(04 14 24 34 05 15 25 35)
498
	movdqa	xmm2, XMMWORD [wk(7)]	; xmm2=(06 16 26 36 07 17 27 37)
499
500
	movdqa	XMMWORD [wk(8)], xmm3	; wk(8)=col1
501
	movdqa	XMMWORD [wk(9)], xmm4	; wk(9)=col3
502
503
	movdqa     xmm3,xmm0		; transpose coefficients(phase 3)
504
	punpcklqdq xmm0,xmm6		; xmm0=col4=(04 14 24 34 44 54 64 74)
505
	punpckhqdq xmm3,xmm6		; xmm3=col5=(05 15 25 35 45 55 65 75)
506
	movdqa     xmm4,xmm2		; transpose coefficients(phase 3)
507
	punpcklqdq xmm2,xmm5		; xmm2=col6=(06 16 26 36 46 56 66 76)
508
	punpckhqdq xmm4,xmm5		; xmm4=col7=(07 17 27 37 47 57 67 77)
509
510
	movdqa	XMMWORD [wk(10)], xmm3	; wk(10)=col5
511
	movdqa	XMMWORD [wk(11)], xmm4	; wk(11)=col7
512
.column_end:
513
514
	; -- Prefetch the next coefficient block
515
516
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
517
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
518
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
519
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
520
521
	; ---- Pass 2: process rows from work array, store into output array.
522
523
	mov	eax, [original_ebp]
524
	mov	edi, JSAMPARRAY [output_buf(eax)]	; (JSAMPROW *)
525
	mov	eax, JDIMENSION [output_col(eax)]
526
527
	; -- Even part
528
529
	; xmm7=col0, xmm1=col2, xmm0=col4, xmm2=col6
530
531
	; (Original)
532
	; z1 = (z2 + z3) * 0.541196100;
533
	; tmp2 = z1 + z3 * -1.847759065;
534
	; tmp3 = z1 + z2 * 0.765366865;
535
	;
536
	; (This implementation)
537
	; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
538
	; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
539
540
	movdqa    xmm6,xmm1		; xmm1=in2=z2
541
	movdqa    xmm5,xmm1
542
	punpcklwd xmm6,xmm2		; xmm2=in6=z3
543
	punpckhwd xmm5,xmm2
544
	movdqa    xmm1,xmm6
545
	movdqa    xmm2,xmm5
546
	pmaddwd   xmm6,[GOTOFF(ebx,PW_F130_F054)]	; xmm6=tmp3L
547
	pmaddwd   xmm5,[GOTOFF(ebx,PW_F130_F054)]	; xmm5=tmp3H
548
	pmaddwd   xmm1,[GOTOFF(ebx,PW_F054_MF130)]	; xmm1=tmp2L
549
	pmaddwd   xmm2,[GOTOFF(ebx,PW_F054_MF130)]	; xmm2=tmp2H
550
551
	movdqa    xmm3,xmm7
552
	paddw     xmm7,xmm0		; xmm7=in0+in4
553
	psubw     xmm3,xmm0		; xmm3=in0-in4
554
555
	pxor      xmm4,xmm4
556
	pxor      xmm0,xmm0
557
	punpcklwd xmm4,xmm7		; xmm4=tmp0L
558
	punpckhwd xmm0,xmm7		; xmm0=tmp0H
559
	psrad     xmm4,(16-CONST_BITS)	; psrad xmm4,16 & pslld xmm4,CONST_BITS
560
	psrad     xmm0,(16-CONST_BITS)	; psrad xmm0,16 & pslld xmm0,CONST_BITS
561
562
	movdqa	xmm7,xmm4
563
	paddd	xmm4,xmm6		; xmm4=tmp10L
564
	psubd	xmm7,xmm6		; xmm7=tmp13L
565
	movdqa	xmm6,xmm0
566
	paddd	xmm0,xmm5		; xmm0=tmp10H
567
	psubd	xmm6,xmm5		; xmm6=tmp13H
568
569
	movdqa	XMMWORD [wk(0)], xmm4	; wk(0)=tmp10L
570
	movdqa	XMMWORD [wk(1)], xmm0	; wk(1)=tmp10H
571
	movdqa	XMMWORD [wk(2)], xmm7	; wk(2)=tmp13L
572
	movdqa	XMMWORD [wk(3)], xmm6	; wk(3)=tmp13H
573
574
	pxor      xmm5,xmm5
575
	pxor      xmm4,xmm4
576
	punpcklwd xmm5,xmm3		; xmm5=tmp1L
577
	punpckhwd xmm4,xmm3		; xmm4=tmp1H
578
	psrad     xmm5,(16-CONST_BITS)	; psrad xmm5,16 & pslld xmm5,CONST_BITS
579
	psrad     xmm4,(16-CONST_BITS)	; psrad xmm4,16 & pslld xmm4,CONST_BITS
580
581
	movdqa	xmm0,xmm5
582
	paddd	xmm5,xmm1		; xmm5=tmp11L
583
	psubd	xmm0,xmm1		; xmm0=tmp12L
584
	movdqa	xmm7,xmm4
585
	paddd	xmm4,xmm2		; xmm4=tmp11H
586
	psubd	xmm7,xmm2		; xmm7=tmp12H
587
588
	movdqa	XMMWORD [wk(4)], xmm5	; wk(4)=tmp11L
589
	movdqa	XMMWORD [wk(5)], xmm4	; wk(5)=tmp11H
590
	movdqa	XMMWORD [wk(6)], xmm0	; wk(6)=tmp12L
591
	movdqa	XMMWORD [wk(7)], xmm7	; wk(7)=tmp12H
592
593
	; -- Odd part
594
595
	movdqa	xmm6, XMMWORD [wk(9)]	; xmm6=col3
596
	movdqa	xmm3, XMMWORD [wk(8)]	; xmm3=col1
597
	movdqa	xmm1, XMMWORD [wk(11)]	; xmm1=col7
598
	movdqa	xmm2, XMMWORD [wk(10)]	; xmm2=col5
599
600
	movdqa	xmm5,xmm6
601
	movdqa	xmm4,xmm3
602
	paddw	xmm5,xmm1		; xmm5=z3
603
	paddw	xmm4,xmm2		; xmm4=z4
604
605
	; (Original)
606
	; z5 = (z3 + z4) * 1.175875602;
607
	; z3 = z3 * -1.961570560;  z4 = z4 * -0.390180644;
608
	; z3 += z5;  z4 += z5;
609
	;
610
	; (This implementation)
611
	; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
612
	; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
613
614
	movdqa    xmm0,xmm5
615
	movdqa    xmm7,xmm5
616
	punpcklwd xmm0,xmm4
617
	punpckhwd xmm7,xmm4
618
	movdqa    xmm5,xmm0
619
	movdqa    xmm4,xmm7
620
	pmaddwd   xmm0,[GOTOFF(ebx,PW_MF078_F117)]	; xmm0=z3L
621
	pmaddwd   xmm7,[GOTOFF(ebx,PW_MF078_F117)]	; xmm7=z3H
622
	pmaddwd   xmm5,[GOTOFF(ebx,PW_F117_F078)]	; xmm5=z4L
623
	pmaddwd   xmm4,[GOTOFF(ebx,PW_F117_F078)]	; xmm4=z4H
624
625
	movdqa	XMMWORD [wk(10)], xmm0	; wk(10)=z3L
626
	movdqa	XMMWORD [wk(11)], xmm7	; wk(11)=z3H
627
628
	; (Original)
629
	; z1 = tmp0 + tmp3;  z2 = tmp1 + tmp2;
630
	; tmp0 = tmp0 * 0.298631336;  tmp1 = tmp1 * 2.053119869;
631
	; tmp2 = tmp2 * 3.072711026;  tmp3 = tmp3 * 1.501321110;
632
	; z1 = z1 * -0.899976223;  z2 = z2 * -2.562915447;
633
	; tmp0 += z1 + z3;  tmp1 += z2 + z4;
634
	; tmp2 += z2 + z3;  tmp3 += z1 + z4;
635
	;
636
	; (This implementation)
637
	; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
638
	; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
639
	; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
640
	; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
641
	; tmp0 += z3;  tmp1 += z4;
642
	; tmp2 += z3;  tmp3 += z4;
643
644
	movdqa    xmm0,xmm1
645
	movdqa    xmm7,xmm1
646
	punpcklwd xmm0,xmm3
647
	punpckhwd xmm7,xmm3
648
	movdqa    xmm1,xmm0
649
	movdqa    xmm3,xmm7
650
	pmaddwd   xmm0,[GOTOFF(ebx,PW_MF060_MF089)]	; xmm0=tmp0L
651
	pmaddwd   xmm7,[GOTOFF(ebx,PW_MF060_MF089)]	; xmm7=tmp0H
652
	pmaddwd   xmm1,[GOTOFF(ebx,PW_MF089_F060)]	; xmm1=tmp3L
653
	pmaddwd   xmm3,[GOTOFF(ebx,PW_MF089_F060)]	; xmm3=tmp3H
654
655
	paddd	xmm0, XMMWORD [wk(10)]	; xmm0=tmp0L
656
	paddd	xmm7, XMMWORD [wk(11)]	; xmm7=tmp0H
657
	paddd	xmm1,xmm5		; xmm1=tmp3L
658
	paddd	xmm3,xmm4		; xmm3=tmp3H
659
660
	movdqa	XMMWORD [wk(8)], xmm0	; wk(8)=tmp0L
661
	movdqa	XMMWORD [wk(9)], xmm7	; wk(9)=tmp0H
662
663
	movdqa    xmm0,xmm2
664
	movdqa    xmm7,xmm2
665
	punpcklwd xmm0,xmm6
666
	punpckhwd xmm7,xmm6
667
	movdqa    xmm2,xmm0
668
	movdqa    xmm6,xmm7
669
	pmaddwd   xmm0,[GOTOFF(ebx,PW_MF050_MF256)]	; xmm0=tmp1L
670
	pmaddwd   xmm7,[GOTOFF(ebx,PW_MF050_MF256)]	; xmm7=tmp1H
671
	pmaddwd   xmm2,[GOTOFF(ebx,PW_MF256_F050)]	; xmm2=tmp2L
672
	pmaddwd   xmm6,[GOTOFF(ebx,PW_MF256_F050)]	; xmm6=tmp2H
673
674
	paddd	xmm0,xmm5		; xmm0=tmp1L
675
	paddd	xmm7,xmm4		; xmm7=tmp1H
676
	paddd	xmm2, XMMWORD [wk(10)]	; xmm2=tmp2L
677
	paddd	xmm6, XMMWORD [wk(11)]	; xmm6=tmp2H
678
679
	movdqa	XMMWORD [wk(10)], xmm0	; wk(10)=tmp1L
680
	movdqa	XMMWORD [wk(11)], xmm7	; wk(11)=tmp1H
681
682
	; -- Final output stage
683
684
	movdqa	xmm5, XMMWORD [wk(0)]	; xmm5=tmp10L
685
	movdqa	xmm4, XMMWORD [wk(1)]	; xmm4=tmp10H
686
687
	movdqa	xmm0,xmm5
688
	movdqa	xmm7,xmm4
689
	paddd	xmm5,xmm1		; xmm5=data0L
690
	paddd	xmm4,xmm3		; xmm4=data0H
691
	psubd	xmm0,xmm1		; xmm0=data7L
692
	psubd	xmm7,xmm3		; xmm7=data7H
693
694
	movdqa	xmm1,[GOTOFF(ebx,PD_DESCALE_P2)]	; xmm1=[PD_DESCALE_P2]
695
696
	paddd	xmm5,xmm1
697
	paddd	xmm4,xmm1
698
	psrad	xmm5,DESCALE_P2
699
	psrad	xmm4,DESCALE_P2
700
	paddd	xmm0,xmm1
701
	paddd	xmm7,xmm1
702
	psrad	xmm0,DESCALE_P2
703
	psrad	xmm7,DESCALE_P2
704
705
	packssdw  xmm5,xmm4		; xmm5=data0=(00 10 20 30 40 50 60 70)
706
	packssdw  xmm0,xmm7		; xmm0=data7=(07 17 27 37 47 57 67 77)
707
708
	movdqa	xmm3, XMMWORD [wk(4)]	; xmm3=tmp11L
709
	movdqa	xmm1, XMMWORD [wk(5)]	; xmm1=tmp11H
710
711
	movdqa	xmm4,xmm3
712
	movdqa	xmm7,xmm1
713
	paddd	xmm3,xmm2		; xmm3=data1L
714
	paddd	xmm1,xmm6		; xmm1=data1H
715
	psubd	xmm4,xmm2		; xmm4=data6L
716
	psubd	xmm7,xmm6		; xmm7=data6H
717
718
	movdqa	xmm2,[GOTOFF(ebx,PD_DESCALE_P2)]	; xmm2=[PD_DESCALE_P2]
719
720
	paddd	xmm3,xmm2
721
	paddd	xmm1,xmm2
722
	psrad	xmm3,DESCALE_P2
723
	psrad	xmm1,DESCALE_P2
724
	paddd	xmm4,xmm2
725
	paddd	xmm7,xmm2
726
	psrad	xmm4,DESCALE_P2
727
	psrad	xmm7,DESCALE_P2
728
729
	packssdw  xmm3,xmm1		; xmm3=data1=(01 11 21 31 41 51 61 71)
730
	packssdw  xmm4,xmm7		; xmm4=data6=(06 16 26 36 46 56 66 76)
731
732
	packsswb  xmm5,xmm4		; xmm5=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
733
	packsswb  xmm3,xmm0		; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
734
735
	movdqa	xmm6, XMMWORD [wk(6)]	; xmm6=tmp12L
736
	movdqa	xmm2, XMMWORD [wk(7)]	; xmm2=tmp12H
737
	movdqa	xmm1, XMMWORD [wk(10)]	; xmm1=tmp1L
738
	movdqa	xmm7, XMMWORD [wk(11)]	; xmm7=tmp1H
739
740
	movdqa	XMMWORD [wk(0)], xmm5	; wk(0)=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
741
	movdqa	XMMWORD [wk(1)], xmm3	; wk(1)=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
742
743
	movdqa	xmm4,xmm6
744
	movdqa	xmm0,xmm2
745
	paddd	xmm6,xmm1		; xmm6=data2L
746
	paddd	xmm2,xmm7		; xmm2=data2H
747
	psubd	xmm4,xmm1		; xmm4=data5L
748
	psubd	xmm0,xmm7		; xmm0=data5H
749
750
	movdqa	xmm5,[GOTOFF(ebx,PD_DESCALE_P2)]	; xmm5=[PD_DESCALE_P2]
751
752
	paddd	xmm6,xmm5
753
	paddd	xmm2,xmm5
754
	psrad	xmm6,DESCALE_P2
755
	psrad	xmm2,DESCALE_P2
756
	paddd	xmm4,xmm5
757
	paddd	xmm0,xmm5
758
	psrad	xmm4,DESCALE_P2
759
	psrad	xmm0,DESCALE_P2
760
761
	packssdw  xmm6,xmm2		; xmm6=data2=(02 12 22 32 42 52 62 72)
762
	packssdw  xmm4,xmm0		; xmm4=data5=(05 15 25 35 45 55 65 75)
763
764
	movdqa	xmm3, XMMWORD [wk(2)]	; xmm3=tmp13L
765
	movdqa	xmm1, XMMWORD [wk(3)]	; xmm1=tmp13H
766
	movdqa	xmm7, XMMWORD [wk(8)]	; xmm7=tmp0L
767
	movdqa	xmm5, XMMWORD [wk(9)]	; xmm5=tmp0H
768
769
	movdqa	xmm2,xmm3
770
	movdqa	xmm0,xmm1
771
	paddd	xmm3,xmm7		; xmm3=data3L
772
	paddd	xmm1,xmm5		; xmm1=data3H
773
	psubd	xmm2,xmm7		; xmm2=data4L
774
	psubd	xmm0,xmm5		; xmm0=data4H
775
776
	movdqa	xmm7,[GOTOFF(ebx,PD_DESCALE_P2)]	; xmm7=[PD_DESCALE_P2]
777
778
	paddd	xmm3,xmm7
779
	paddd	xmm1,xmm7
780
	psrad	xmm3,DESCALE_P2
781
	psrad	xmm1,DESCALE_P2
782
	paddd	xmm2,xmm7
783
	paddd	xmm0,xmm7
784
	psrad	xmm2,DESCALE_P2
785
	psrad	xmm0,DESCALE_P2
786
787
	movdqa    xmm5,[GOTOFF(ebx,PB_CENTERJSAMP)]	; xmm5=[PB_CENTERJSAMP]
788
789
	packssdw  xmm3,xmm1		; xmm3=data3=(03 13 23 33 43 53 63 73)
790
	packssdw  xmm2,xmm0		; xmm2=data4=(04 14 24 34 44 54 64 74)
791
792
	movdqa    xmm7, XMMWORD [wk(0)]	; xmm7=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
793
	movdqa    xmm1, XMMWORD [wk(1)]	; xmm1=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
794
795
	packsswb  xmm6,xmm2		; xmm6=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74)
796
	packsswb  xmm3,xmm4		; xmm3=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75)
797
798
	paddb     xmm7,xmm5
799
	paddb     xmm1,xmm5
800
	paddb     xmm6,xmm5
801
	paddb     xmm3,xmm5
802
803
	movdqa    xmm0,xmm7	; transpose coefficients(phase 1)
804
	punpcklbw xmm7,xmm1	; xmm7=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71)
805
	punpckhbw xmm0,xmm1	; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77)
806
	movdqa    xmm2,xmm6	; transpose coefficients(phase 1)
807
	punpcklbw xmm6,xmm3	; xmm6=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73)
808
	punpckhbw xmm2,xmm3	; xmm2=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75)
809
810
	movdqa    xmm4,xmm7	; transpose coefficients(phase 2)
811
	punpcklwd xmm7,xmm6	; xmm7=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
812
	punpckhwd xmm4,xmm6	; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73)
813
	movdqa    xmm5,xmm2	; transpose coefficients(phase 2)
814
	punpcklwd xmm2,xmm0	; xmm2=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
815
	punpckhwd xmm5,xmm0	; xmm5=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77)
816
817
	movdqa    xmm1,xmm7	; transpose coefficients(phase 3)
818
	punpckldq xmm7,xmm2	; xmm7=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
819
	punpckhdq xmm1,xmm2	; xmm1=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
820
	movdqa    xmm3,xmm4	; transpose coefficients(phase 3)
821
	punpckldq xmm4,xmm5	; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57)
822
	punpckhdq xmm3,xmm5	; xmm3=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77)
823
824
	pshufd	xmm6,xmm7,0x4E	; xmm6=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
825
	pshufd	xmm0,xmm1,0x4E	; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
826
	pshufd	xmm2,xmm4,0x4E	; xmm2=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47)
827
	pshufd	xmm5,xmm3,0x4E	; xmm5=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67)
828
829
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
830
	mov	esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
831
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm7
832
	movq	XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm1
833
	mov	edx, JSAMPROW [edi+4*SIZEOF_JSAMPROW]
834
	mov	esi, JSAMPROW [edi+6*SIZEOF_JSAMPROW]
835
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm4
836
	movq	XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm3
837
838
	mov	edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
839
	mov	esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
840
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm6
841
	movq	XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm0
842
	mov	edx, JSAMPROW [edi+5*SIZEOF_JSAMPROW]
843
	mov	esi, JSAMPROW [edi+7*SIZEOF_JSAMPROW]
844
	movq	XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm2
845
	movq	XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm5
846
847
	pop	edi
848
	pop	esi
849
;	pop	edx		; need not be preserved
850
;	pop	ecx		; unused
851
	poppic	ebx
852
	mov	esp,ebp		; esp <- aligned ebp
853
	pop	esp		; esp <- original ebp
854
	pop	ebp
855
	ret
856
857
; For some reason, the OS X linker does not honor the request to align the
858
; segment unless we do this.
859
	align	16
(-)a/jpeg/simd/jiss2red-64.asm (+576 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jiss2red-64.asm - reduced-size IDCT (64-bit SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2009 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library
9
; Copyright (C) 1999-2006, MIYASAKA Masaru.
10
; For conditions of distribution and use, see copyright notice in jsimdext.inc
11
;
12
; This file should be assembled with NASM (Netwide Assembler),
13
; can *not* be assembled with Microsoft's MASM or any compatible
14
; assembler (including Borland's Turbo Assembler).
15
; NASM is available from http://nasm.sourceforge.net/ or
16
; http://sourceforge.net/project/showfiles.php?group_id=6208
17
;
18
; This file contains inverse-DCT routines that produce reduced-size
19
; output: either 4x4 or 2x2 pixels from an 8x8 DCT block.
20
; The following code is based directly on the IJG's original jidctred.c;
21
; see the jidctred.c for more details.
22
;
23
; [TAB8]
24
25
%include "jsimdext.inc"
26
%include "jdct.inc"
27
28
; --------------------------------------------------------------------------
29
30
%define CONST_BITS	13
31
%define PASS1_BITS	2
32
33
%define DESCALE_P1_4	(CONST_BITS-PASS1_BITS+1)
34
%define DESCALE_P2_4	(CONST_BITS+PASS1_BITS+3+1)
35
%define DESCALE_P1_2	(CONST_BITS-PASS1_BITS+2)
36
%define DESCALE_P2_2	(CONST_BITS+PASS1_BITS+3+2)
37
38
%if CONST_BITS == 13
39
F_0_211	equ	 1730		; FIX(0.211164243)
40
F_0_509	equ	 4176		; FIX(0.509795579)
41
F_0_601	equ	 4926		; FIX(0.601344887)
42
F_0_720	equ	 5906		; FIX(0.720959822)
43
F_0_765	equ	 6270		; FIX(0.765366865)
44
F_0_850	equ	 6967		; FIX(0.850430095)
45
F_0_899	equ	 7373		; FIX(0.899976223)
46
F_1_061	equ	 8697		; FIX(1.061594337)
47
F_1_272	equ	10426		; FIX(1.272758580)
48
F_1_451	equ	11893		; FIX(1.451774981)
49
F_1_847	equ	15137		; FIX(1.847759065)
50
F_2_172	equ	17799		; FIX(2.172734803)
51
F_2_562	equ	20995		; FIX(2.562915447)
52
F_3_624	equ	29692		; FIX(3.624509785)
53
%else
54
; NASM cannot do compile-time arithmetic on floating-point constants.
55
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
56
F_0_211	equ	DESCALE( 226735879,30-CONST_BITS)	; FIX(0.211164243)
57
F_0_509	equ	DESCALE( 547388834,30-CONST_BITS)	; FIX(0.509795579)
58
F_0_601	equ	DESCALE( 645689155,30-CONST_BITS)	; FIX(0.601344887)
59
F_0_720	equ	DESCALE( 774124714,30-CONST_BITS)	; FIX(0.720959822)
60
F_0_765	equ	DESCALE( 821806413,30-CONST_BITS)	; FIX(0.765366865)
61
F_0_850	equ	DESCALE( 913142361,30-CONST_BITS)	; FIX(0.850430095)
62
F_0_899	equ	DESCALE( 966342111,30-CONST_BITS)	; FIX(0.899976223)
63
F_1_061	equ	DESCALE(1139878239,30-CONST_BITS)	; FIX(1.061594337)
64
F_1_272	equ	DESCALE(1366614119,30-CONST_BITS)	; FIX(1.272758580)
65
F_1_451	equ	DESCALE(1558831516,30-CONST_BITS)	; FIX(1.451774981)
66
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
67
F_2_172	equ	DESCALE(2332956230,30-CONST_BITS)	; FIX(2.172734803)
68
F_2_562	equ	DESCALE(2751909506,30-CONST_BITS)	; FIX(2.562915447)
69
F_3_624	equ	DESCALE(3891787747,30-CONST_BITS)	; FIX(3.624509785)
70
%endif
71
72
; --------------------------------------------------------------------------
73
	SECTION	SEG_CONST
74
75
	alignz	16
76
	global	EXTN(jconst_idct_red_sse2)
77
78
EXTN(jconst_idct_red_sse2):
79
80
PW_F184_MF076	times 4 dw  F_1_847,-F_0_765
81
PW_F256_F089	times 4 dw  F_2_562, F_0_899
82
PW_F106_MF217	times 4 dw  F_1_061,-F_2_172
83
PW_MF060_MF050	times 4 dw -F_0_601,-F_0_509
84
PW_F145_MF021	times 4 dw  F_1_451,-F_0_211
85
PW_F362_MF127	times 4 dw  F_3_624,-F_1_272
86
PW_F085_MF072	times 4 dw  F_0_850,-F_0_720
87
PD_DESCALE_P1_4	times 4 dd  1 << (DESCALE_P1_4-1)
88
PD_DESCALE_P2_4	times 4 dd  1 << (DESCALE_P2_4-1)
89
PD_DESCALE_P1_2	times 4 dd  1 << (DESCALE_P1_2-1)
90
PD_DESCALE_P2_2	times 4 dd  1 << (DESCALE_P2_2-1)
91
PB_CENTERJSAMP	times 16 db CENTERJSAMPLE
92
93
	alignz	16
94
95
; --------------------------------------------------------------------------
96
	SECTION	SEG_TEXT
97
	BITS	64
98
;
99
; Perform dequantization and inverse DCT on one block of coefficients,
100
; producing a reduced-size 4x4 output block.
101
;
102
; GLOBAL(void)
103
; jsimd_idct_4x4_sse2 (void * dct_table, JCOEFPTR coef_block,
104
;                      JSAMPARRAY output_buf, JDIMENSION output_col)
105
;
106
107
; r10 = void * dct_table
108
; r11 = JCOEFPTR coef_block
109
; r12 = JSAMPARRAY output_buf
110
; r13 = JDIMENSION output_col
111
112
%define original_rbp	rbp+0
113
%define wk(i)		rbp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
114
%define WK_NUM		2
115
116
	align	16
117
	global	EXTN(jsimd_idct_4x4_sse2)
118
119
EXTN(jsimd_idct_4x4_sse2):
120
	push	rbp
121
	mov	rax,rsp				; rax = original rbp
122
	sub	rsp, byte 4
123
	and	rsp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
124
	mov	[rsp],rax
125
	mov	rbp,rsp				; rbp = aligned rbp
126
	lea	rsp, [wk(0)]
127
	collect_args
128
129
	; ---- Pass 1: process columns from input.
130
131
	mov	rdx, r10	; quantptr
132
	mov	rsi, r11		; inptr
133
134
%ifndef NO_ZERO_COLUMN_TEST_4X4_SSE2
135
	mov	eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
136
	or	eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
137
	jnz	short .columnDCT
138
139
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
140
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
141
	por	xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
142
	por	xmm1, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
143
	por	xmm0, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
144
	por	xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
145
	por	xmm0,xmm1
146
	packsswb xmm0,xmm0
147
	packsswb xmm0,xmm0
148
	movd	eax,xmm0
149
	test	rax,rax
150
	jnz	short .columnDCT
151
152
	; -- AC terms all zero
153
154
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
155
	pmullw	xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
156
157
	psllw	xmm0,PASS1_BITS
158
159
	movdqa    xmm3,xmm0	; xmm0=in0=(00 01 02 03 04 05 06 07)
160
	punpcklwd xmm0,xmm0	; xmm0=(00 00 01 01 02 02 03 03)
161
	punpckhwd xmm3,xmm3	; xmm3=(04 04 05 05 06 06 07 07)
162
163
	pshufd	xmm1,xmm0,0x50	; xmm1=[col0 col1]=(00 00 00 00 01 01 01 01)
164
	pshufd	xmm0,xmm0,0xFA	; xmm0=[col2 col3]=(02 02 02 02 03 03 03 03)
165
	pshufd	xmm6,xmm3,0x50	; xmm6=[col4 col5]=(04 04 04 04 05 05 05 05)
166
	pshufd	xmm3,xmm3,0xFA	; xmm3=[col6 col7]=(06 06 06 06 07 07 07 07)
167
168
	jmp	near .column_end
169
%endif
170
.columnDCT:
171
172
	; -- Odd part
173
174
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
175
	movdqa	xmm1, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
176
	pmullw	xmm0, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
177
	pmullw	xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
178
	movdqa	xmm2, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
179
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
180
	pmullw	xmm2, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
181
	pmullw	xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
182
183
	movdqa    xmm4,xmm0
184
	movdqa    xmm5,xmm0
185
	punpcklwd xmm4,xmm1
186
	punpckhwd xmm5,xmm1
187
	movdqa    xmm0,xmm4
188
	movdqa    xmm1,xmm5
189
	pmaddwd   xmm4,[rel PW_F256_F089]	; xmm4=(tmp2L)
190
	pmaddwd   xmm5,[rel PW_F256_F089]	; xmm5=(tmp2H)
191
	pmaddwd   xmm0,[rel PW_F106_MF217]	; xmm0=(tmp0L)
192
	pmaddwd   xmm1,[rel PW_F106_MF217]	; xmm1=(tmp0H)
193
194
	movdqa    xmm6,xmm2
195
	movdqa    xmm7,xmm2
196
	punpcklwd xmm6,xmm3
197
	punpckhwd xmm7,xmm3
198
	movdqa    xmm2,xmm6
199
	movdqa    xmm3,xmm7
200
	pmaddwd   xmm6,[rel PW_MF060_MF050]	; xmm6=(tmp2L)
201
	pmaddwd   xmm7,[rel PW_MF060_MF050]	; xmm7=(tmp2H)
202
	pmaddwd   xmm2,[rel PW_F145_MF021]	; xmm2=(tmp0L)
203
	pmaddwd   xmm3,[rel PW_F145_MF021]	; xmm3=(tmp0H)
204
205
	paddd	xmm6,xmm4		; xmm6=tmp2L
206
	paddd	xmm7,xmm5		; xmm7=tmp2H
207
	paddd	xmm2,xmm0		; xmm2=tmp0L
208
	paddd	xmm3,xmm1		; xmm3=tmp0H
209
210
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=tmp0L
211
	movdqa	XMMWORD [wk(1)], xmm3	; wk(1)=tmp0H
212
213
	; -- Even part
214
215
	movdqa	xmm4, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
216
	movdqa	xmm5, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
217
	movdqa	xmm0, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
218
	pmullw	xmm4, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
219
	pmullw	xmm5, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
220
	pmullw	xmm0, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
221
222
	pxor      xmm1,xmm1
223
	pxor      xmm2,xmm2
224
	punpcklwd xmm1,xmm4		; xmm1=tmp0L
225
	punpckhwd xmm2,xmm4		; xmm2=tmp0H
226
	psrad     xmm1,(16-CONST_BITS-1) ; psrad xmm1,16 & pslld xmm1,CONST_BITS+1
227
	psrad     xmm2,(16-CONST_BITS-1) ; psrad xmm2,16 & pslld xmm2,CONST_BITS+1
228
229
	movdqa    xmm3,xmm5		; xmm5=in2=z2
230
	punpcklwd xmm5,xmm0		; xmm0=in6=z3
231
	punpckhwd xmm3,xmm0
232
	pmaddwd   xmm5,[rel PW_F184_MF076]	; xmm5=tmp2L
233
	pmaddwd   xmm3,[rel PW_F184_MF076]	; xmm3=tmp2H
234
235
	movdqa	xmm4,xmm1
236
	movdqa	xmm0,xmm2
237
	paddd	xmm1,xmm5		; xmm1=tmp10L
238
	paddd	xmm2,xmm3		; xmm2=tmp10H
239
	psubd	xmm4,xmm5		; xmm4=tmp12L
240
	psubd	xmm0,xmm3		; xmm0=tmp12H
241
242
	; -- Final output stage
243
244
	movdqa	xmm5,xmm1
245
	movdqa	xmm3,xmm2
246
	paddd	xmm1,xmm6		; xmm1=data0L
247
	paddd	xmm2,xmm7		; xmm2=data0H
248
	psubd	xmm5,xmm6		; xmm5=data3L
249
	psubd	xmm3,xmm7		; xmm3=data3H
250
251
	movdqa	xmm6,[rel PD_DESCALE_P1_4]	; xmm6=[rel PD_DESCALE_P1_4]
252
253
	paddd	xmm1,xmm6
254
	paddd	xmm2,xmm6
255
	psrad	xmm1,DESCALE_P1_4
256
	psrad	xmm2,DESCALE_P1_4
257
	paddd	xmm5,xmm6
258
	paddd	xmm3,xmm6
259
	psrad	xmm5,DESCALE_P1_4
260
	psrad	xmm3,DESCALE_P1_4
261
262
	packssdw  xmm1,xmm2		; xmm1=data0=(00 01 02 03 04 05 06 07)
263
	packssdw  xmm5,xmm3		; xmm5=data3=(30 31 32 33 34 35 36 37)
264
265
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=tmp0L
266
	movdqa	xmm6, XMMWORD [wk(1)]	; xmm6=tmp0H
267
268
	movdqa	xmm2,xmm4
269
	movdqa	xmm3,xmm0
270
	paddd	xmm4,xmm7		; xmm4=data1L
271
	paddd	xmm0,xmm6		; xmm0=data1H
272
	psubd	xmm2,xmm7		; xmm2=data2L
273
	psubd	xmm3,xmm6		; xmm3=data2H
274
275
	movdqa	xmm7,[rel PD_DESCALE_P1_4]	; xmm7=[rel PD_DESCALE_P1_4]
276
277
	paddd	xmm4,xmm7
278
	paddd	xmm0,xmm7
279
	psrad	xmm4,DESCALE_P1_4
280
	psrad	xmm0,DESCALE_P1_4
281
	paddd	xmm2,xmm7
282
	paddd	xmm3,xmm7
283
	psrad	xmm2,DESCALE_P1_4
284
	psrad	xmm3,DESCALE_P1_4
285
286
	packssdw  xmm4,xmm0		; xmm4=data1=(10 11 12 13 14 15 16 17)
287
	packssdw  xmm2,xmm3		; xmm2=data2=(20 21 22 23 24 25 26 27)
288
289
	movdqa    xmm6,xmm1	; transpose coefficients(phase 1)
290
	punpcklwd xmm1,xmm4	; xmm1=(00 10 01 11 02 12 03 13)
291
	punpckhwd xmm6,xmm4	; xmm6=(04 14 05 15 06 16 07 17)
292
	movdqa    xmm7,xmm2	; transpose coefficients(phase 1)
293
	punpcklwd xmm2,xmm5	; xmm2=(20 30 21 31 22 32 23 33)
294
	punpckhwd xmm7,xmm5	; xmm7=(24 34 25 35 26 36 27 37)
295
296
	movdqa    xmm0,xmm1	; transpose coefficients(phase 2)
297
	punpckldq xmm1,xmm2	; xmm1=[col0 col1]=(00 10 20 30 01 11 21 31)
298
	punpckhdq xmm0,xmm2	; xmm0=[col2 col3]=(02 12 22 32 03 13 23 33)
299
	movdqa    xmm3,xmm6	; transpose coefficients(phase 2)
300
	punpckldq xmm6,xmm7	; xmm6=[col4 col5]=(04 14 24 34 05 15 25 35)
301
	punpckhdq xmm3,xmm7	; xmm3=[col6 col7]=(06 16 26 36 07 17 27 37)
302
.column_end:
303
304
	; -- Prefetch the next coefficient block
305
306
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
307
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
308
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
309
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
310
311
	; ---- Pass 2: process rows, store into output array.
312
313
	mov	rax, [original_rbp]
314
	mov	rdi, r12	; (JSAMPROW *)
315
	mov	rax, r13
316
317
	; -- Even part
318
319
	pxor      xmm4,xmm4
320
	punpcklwd xmm4,xmm1		; xmm4=tmp0
321
	psrad     xmm4,(16-CONST_BITS-1) ; psrad xmm4,16 & pslld xmm4,CONST_BITS+1
322
323
	; -- Odd part
324
325
	punpckhwd xmm1,xmm0
326
	punpckhwd xmm6,xmm3
327
	movdqa    xmm5,xmm1
328
	movdqa    xmm2,xmm6
329
	pmaddwd   xmm1,[rel PW_F256_F089]	; xmm1=(tmp2)
330
	pmaddwd   xmm6,[rel PW_MF060_MF050]	; xmm6=(tmp2)
331
	pmaddwd   xmm5,[rel PW_F106_MF217]	; xmm5=(tmp0)
332
	pmaddwd   xmm2,[rel PW_F145_MF021]	; xmm2=(tmp0)
333
334
	paddd     xmm6,xmm1		; xmm6=tmp2
335
	paddd     xmm2,xmm5		; xmm2=tmp0
336
337
	; -- Even part
338
339
	punpcklwd xmm0,xmm3
340
	pmaddwd   xmm0,[rel PW_F184_MF076]	; xmm0=tmp2
341
342
	movdqa    xmm7,xmm4
343
	paddd     xmm4,xmm0		; xmm4=tmp10
344
	psubd     xmm7,xmm0		; xmm7=tmp12
345
346
	; -- Final output stage
347
348
	movdqa	xmm1,[rel PD_DESCALE_P2_4]	; xmm1=[rel PD_DESCALE_P2_4]
349
350
	movdqa	xmm5,xmm4
351
	movdqa	xmm3,xmm7
352
	paddd	xmm4,xmm6		; xmm4=data0=(00 10 20 30)
353
	paddd	xmm7,xmm2		; xmm7=data1=(01 11 21 31)
354
	psubd	xmm5,xmm6		; xmm5=data3=(03 13 23 33)
355
	psubd	xmm3,xmm2		; xmm3=data2=(02 12 22 32)
356
357
	paddd	xmm4,xmm1
358
	paddd	xmm7,xmm1
359
	psrad	xmm4,DESCALE_P2_4
360
	psrad	xmm7,DESCALE_P2_4
361
	paddd	xmm5,xmm1
362
	paddd	xmm3,xmm1
363
	psrad	xmm5,DESCALE_P2_4
364
	psrad	xmm3,DESCALE_P2_4
365
366
	packssdw  xmm4,xmm3		; xmm4=(00 10 20 30 02 12 22 32)
367
	packssdw  xmm7,xmm5		; xmm7=(01 11 21 31 03 13 23 33)
368
369
	movdqa    xmm0,xmm4		; transpose coefficients(phase 1)
370
	punpcklwd xmm4,xmm7		; xmm4=(00 01 10 11 20 21 30 31)
371
	punpckhwd xmm0,xmm7		; xmm0=(02 03 12 13 22 23 32 33)
372
373
	movdqa    xmm6,xmm4		; transpose coefficients(phase 2)
374
	punpckldq xmm4,xmm0		; xmm4=(00 01 02 03 10 11 12 13)
375
	punpckhdq xmm6,xmm0		; xmm6=(20 21 22 23 30 31 32 33)
376
377
	packsswb  xmm4,xmm6		; xmm4=(00 01 02 03 10 11 12 13 20 ..)
378
	paddb     xmm4,[rel PB_CENTERJSAMP]
379
380
	pshufd    xmm2,xmm4,0x39	; xmm2=(10 11 12 13 20 21 22 23 30 ..)
381
	pshufd    xmm1,xmm4,0x4E	; xmm1=(20 21 22 23 30 31 32 33 00 ..)
382
	pshufd    xmm3,xmm4,0x93	; xmm3=(30 31 32 33 00 01 02 03 10 ..)
383
384
	mov	rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
385
	mov	rsi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
386
	movd	XMM_DWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4
387
	movd	XMM_DWORD [rsi+rax*SIZEOF_JSAMPLE], xmm2
388
	mov	rdx, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
389
	mov	rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
390
	movd	XMM_DWORD [rdx+rax*SIZEOF_JSAMPLE], xmm1
391
	movd	XMM_DWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3
392
393
	uncollect_args
394
	mov	rsp,rbp		; rsp <- aligned rbp
395
	pop	rsp		; rsp <- original rbp
396
	pop	rbp
397
	ret
398
399
400
; --------------------------------------------------------------------------
401
;
402
; Perform dequantization and inverse DCT on one block of coefficients,
403
; producing a reduced-size 2x2 output block.
404
;
405
; GLOBAL(void)
406
; jsimd_idct_2x2_sse2 (void * dct_table, JCOEFPTR coef_block,
407
;                      JSAMPARRAY output_buf, JDIMENSION output_col)
408
;
409
410
; r10 = void * dct_table
411
; r11 = JCOEFPTR coef_block
412
; r12 = JSAMPARRAY output_buf
413
; r13 = JDIMENSION output_col
414
415
	align	16
416
	global	EXTN(jsimd_idct_2x2_sse2)
417
418
EXTN(jsimd_idct_2x2_sse2):
419
	push	rbp
420
	mov	rax,rsp
421
	mov	rbp,rsp
422
	collect_args
423
	push	rbx
424
425
	; ---- Pass 1: process columns from input.
426
427
	mov	rdx, r10	; quantptr
428
	mov	rsi, r11		; inptr
429
430
	; | input:                  | result:        |
431
	; | 00 01 ** 03 ** 05 ** 07 |                |
432
	; | 10 11 ** 13 ** 15 ** 17 |                |
433
	; | ** ** ** ** ** ** ** ** |                |
434
	; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 |
435
	; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 |
436
	; | 50 51 ** 53 ** 55 ** 57 |                |
437
	; | ** ** ** ** ** ** ** ** |                |
438
	; | 70 71 ** 73 ** 75 ** 77 |                |
439
440
	; -- Odd part
441
442
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
443
	movdqa	xmm1, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
444
	pmullw	xmm0, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
445
	pmullw	xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
446
	movdqa	xmm2, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
447
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
448
	pmullw	xmm2, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
449
	pmullw	xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
450
451
	; xmm0=(10 11 ** 13 ** 15 ** 17), xmm1=(30 31 ** 33 ** 35 ** 37)
452
	; xmm2=(50 51 ** 53 ** 55 ** 57), xmm3=(70 71 ** 73 ** 75 ** 77)
453
454
	pcmpeqd   xmm7,xmm7
455
	pslld     xmm7,WORD_BIT		; xmm7={0x0000 0xFFFF 0x0000 0xFFFF ..}
456
457
	movdqa    xmm4,xmm0		; xmm4=(10 11 ** 13 ** 15 ** 17)
458
	movdqa    xmm5,xmm2		; xmm5=(50 51 ** 53 ** 55 ** 57)
459
	punpcklwd xmm4,xmm1		; xmm4=(10 30 11 31 ** ** 13 33)
460
	punpcklwd xmm5,xmm3		; xmm5=(50 70 51 71 ** ** 53 73)
461
	pmaddwd   xmm4,[rel PW_F362_MF127]
462
	pmaddwd   xmm5,[rel PW_F085_MF072]
463
464
	psrld	xmm0,WORD_BIT		; xmm0=(11 -- 13 -- 15 -- 17 --)
465
	pand	xmm1,xmm7		; xmm1=(-- 31 -- 33 -- 35 -- 37)
466
	psrld	xmm2,WORD_BIT		; xmm2=(51 -- 53 -- 55 -- 57 --)
467
	pand	xmm3,xmm7		; xmm3=(-- 71 -- 73 -- 75 -- 77)
468
	por	xmm0,xmm1		; xmm0=(11 31 13 33 15 35 17 37)
469
	por	xmm2,xmm3		; xmm2=(51 71 53 73 55 75 57 77)
470
	pmaddwd	xmm0,[rel PW_F362_MF127]
471
	pmaddwd	xmm2,[rel PW_F085_MF072]
472
473
	paddd	xmm4,xmm5		; xmm4=tmp0[col0 col1 **** col3]
474
	paddd	xmm0,xmm2		; xmm0=tmp0[col1 col3 col5 col7]
475
476
	; -- Even part
477
478
	movdqa	xmm6, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
479
	pmullw	xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
480
481
	; xmm6=(00 01 ** 03 ** 05 ** 07)
482
483
	movdqa	xmm1,xmm6		; xmm1=(00 01 ** 03 ** 05 ** 07)
484
	pslld	xmm6,WORD_BIT		; xmm6=(-- 00 -- ** -- ** -- **)
485
	pand	xmm1,xmm7		; xmm1=(-- 01 -- 03 -- 05 -- 07)
486
	psrad	xmm6,(WORD_BIT-CONST_BITS-2) ; xmm6=tmp10[col0 **** **** ****]
487
	psrad	xmm1,(WORD_BIT-CONST_BITS-2) ; xmm1=tmp10[col1 col3 col5 col7]
488
489
	; -- Final output stage
490
491
	movdqa	xmm3,xmm6
492
	movdqa	xmm5,xmm1
493
	paddd	xmm6,xmm4	; xmm6=data0[col0 **** **** ****]=(A0 ** ** **)
494
	paddd	xmm1,xmm0	; xmm1=data0[col1 col3 col5 col7]=(A1 A3 A5 A7)
495
	psubd	xmm3,xmm4	; xmm3=data1[col0 **** **** ****]=(B0 ** ** **)
496
	psubd	xmm5,xmm0	; xmm5=data1[col1 col3 col5 col7]=(B1 B3 B5 B7)
497
498
	movdqa	xmm2,[rel PD_DESCALE_P1_2]	; xmm2=[rel PD_DESCALE_P1_2]
499
500
	punpckldq  xmm6,xmm3		; xmm6=(A0 B0 ** **)
501
502
	movdqa     xmm7,xmm1
503
	punpcklqdq xmm1,xmm5		; xmm1=(A1 A3 B1 B3)
504
	punpckhqdq xmm7,xmm5		; xmm7=(A5 A7 B5 B7)
505
506
	paddd	xmm6,xmm2
507
	psrad	xmm6,DESCALE_P1_2
508
509
	paddd	xmm1,xmm2
510
	paddd	xmm7,xmm2
511
	psrad	xmm1,DESCALE_P1_2
512
	psrad	xmm7,DESCALE_P1_2
513
514
	; -- Prefetch the next coefficient block
515
516
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
517
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
518
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
519
	prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
520
521
	; ---- Pass 2: process rows, store into output array.
522
523
	mov	rdi, r12	; (JSAMPROW *)
524
	mov	rax, r13
525
526
	; | input:| result:|
527
	; | A0 B0 |        |
528
	; | A1 B1 | C0 C1  |
529
	; | A3 B3 | D0 D1  |
530
	; | A5 B5 |        |
531
	; | A7 B7 |        |
532
533
	; -- Odd part
534
535
	packssdw  xmm1,xmm1		; xmm1=(A1 A3 B1 B3 A1 A3 B1 B3)
536
	packssdw  xmm7,xmm7		; xmm7=(A5 A7 B5 B7 A5 A7 B5 B7)
537
	pmaddwd   xmm1,[rel PW_F362_MF127]
538
	pmaddwd   xmm7,[rel PW_F085_MF072]
539
540
	paddd     xmm1,xmm7		; xmm1=tmp0[row0 row1 row0 row1]
541
542
	; -- Even part
543
544
	pslld     xmm6,(CONST_BITS+2)	; xmm6=tmp10[row0 row1 **** ****]
545
546
	; -- Final output stage
547
548
	movdqa    xmm4,xmm6
549
	paddd     xmm6,xmm1	; xmm6=data0[row0 row1 **** ****]=(C0 C1 ** **)
550
	psubd     xmm4,xmm1	; xmm4=data1[row0 row1 **** ****]=(D0 D1 ** **)
551
552
	punpckldq xmm6,xmm4	; xmm6=(C0 D0 C1 D1)
553
554
	paddd     xmm6,[rel PD_DESCALE_P2_2]
555
	psrad     xmm6,DESCALE_P2_2
556
557
	packssdw  xmm6,xmm6		; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1)
558
	packsswb  xmm6,xmm6		; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1 ..)
559
	paddb     xmm6,[rel PB_CENTERJSAMP]
560
561
	pextrw	ebx,xmm6,0x00		; ebx=(C0 D0 -- --)
562
	pextrw	ecx,xmm6,0x01		; ecx=(C1 D1 -- --)
563
564
	mov	rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
565
	mov	rsi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
566
	mov	WORD [rdx+rax*SIZEOF_JSAMPLE], bx
567
	mov	WORD [rsi+rax*SIZEOF_JSAMPLE], cx
568
569
	pop	rbx
570
	uncollect_args
571
	pop	rbp
572
	ret
573
574
; For some reason, the OS X linker does not honor the request to align the
575
; segment unless we do this.
576
	align	16
(-)a/jpeg/simd/jiss2red.asm (+594 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jiss2red.asm - reduced-size IDCT (SSE2)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains inverse-DCT routines that produce reduced-size
18
; output: either 4x4 or 2x2 pixels from an 8x8 DCT block.
19
; The following code is based directly on the IJG's original jidctred.c;
20
; see the jidctred.c for more details.
21
;
22
; [TAB8]
23
24
%include "jsimdext.inc"
25
%include "jdct.inc"
26
27
; --------------------------------------------------------------------------
28
29
%define CONST_BITS	13
30
%define PASS1_BITS	2
31
32
%define DESCALE_P1_4	(CONST_BITS-PASS1_BITS+1)
33
%define DESCALE_P2_4	(CONST_BITS+PASS1_BITS+3+1)
34
%define DESCALE_P1_2	(CONST_BITS-PASS1_BITS+2)
35
%define DESCALE_P2_2	(CONST_BITS+PASS1_BITS+3+2)
36
37
%if CONST_BITS == 13
38
F_0_211	equ	 1730		; FIX(0.211164243)
39
F_0_509	equ	 4176		; FIX(0.509795579)
40
F_0_601	equ	 4926		; FIX(0.601344887)
41
F_0_720	equ	 5906		; FIX(0.720959822)
42
F_0_765	equ	 6270		; FIX(0.765366865)
43
F_0_850	equ	 6967		; FIX(0.850430095)
44
F_0_899	equ	 7373		; FIX(0.899976223)
45
F_1_061	equ	 8697		; FIX(1.061594337)
46
F_1_272	equ	10426		; FIX(1.272758580)
47
F_1_451	equ	11893		; FIX(1.451774981)
48
F_1_847	equ	15137		; FIX(1.847759065)
49
F_2_172	equ	17799		; FIX(2.172734803)
50
F_2_562	equ	20995		; FIX(2.562915447)
51
F_3_624	equ	29692		; FIX(3.624509785)
52
%else
53
; NASM cannot do compile-time arithmetic on floating-point constants.
54
%define DESCALE(x,n)  (((x)+(1<<((n)-1)))>>(n))
55
F_0_211	equ	DESCALE( 226735879,30-CONST_BITS)	; FIX(0.211164243)
56
F_0_509	equ	DESCALE( 547388834,30-CONST_BITS)	; FIX(0.509795579)
57
F_0_601	equ	DESCALE( 645689155,30-CONST_BITS)	; FIX(0.601344887)
58
F_0_720	equ	DESCALE( 774124714,30-CONST_BITS)	; FIX(0.720959822)
59
F_0_765	equ	DESCALE( 821806413,30-CONST_BITS)	; FIX(0.765366865)
60
F_0_850	equ	DESCALE( 913142361,30-CONST_BITS)	; FIX(0.850430095)
61
F_0_899	equ	DESCALE( 966342111,30-CONST_BITS)	; FIX(0.899976223)
62
F_1_061	equ	DESCALE(1139878239,30-CONST_BITS)	; FIX(1.061594337)
63
F_1_272	equ	DESCALE(1366614119,30-CONST_BITS)	; FIX(1.272758580)
64
F_1_451	equ	DESCALE(1558831516,30-CONST_BITS)	; FIX(1.451774981)
65
F_1_847	equ	DESCALE(1984016188,30-CONST_BITS)	; FIX(1.847759065)
66
F_2_172	equ	DESCALE(2332956230,30-CONST_BITS)	; FIX(2.172734803)
67
F_2_562	equ	DESCALE(2751909506,30-CONST_BITS)	; FIX(2.562915447)
68
F_3_624	equ	DESCALE(3891787747,30-CONST_BITS)	; FIX(3.624509785)
69
%endif
70
71
; --------------------------------------------------------------------------
72
	SECTION	SEG_CONST
73
74
	alignz	16
75
	global	EXTN(jconst_idct_red_sse2)
76
77
EXTN(jconst_idct_red_sse2):
78
79
PW_F184_MF076	times 4 dw  F_1_847,-F_0_765
80
PW_F256_F089	times 4 dw  F_2_562, F_0_899
81
PW_F106_MF217	times 4 dw  F_1_061,-F_2_172
82
PW_MF060_MF050	times 4 dw -F_0_601,-F_0_509
83
PW_F145_MF021	times 4 dw  F_1_451,-F_0_211
84
PW_F362_MF127	times 4 dw  F_3_624,-F_1_272
85
PW_F085_MF072	times 4 dw  F_0_850,-F_0_720
86
PD_DESCALE_P1_4	times 4 dd  1 << (DESCALE_P1_4-1)
87
PD_DESCALE_P2_4	times 4 dd  1 << (DESCALE_P2_4-1)
88
PD_DESCALE_P1_2	times 4 dd  1 << (DESCALE_P1_2-1)
89
PD_DESCALE_P2_2	times 4 dd  1 << (DESCALE_P2_2-1)
90
PB_CENTERJSAMP	times 16 db CENTERJSAMPLE
91
92
	alignz	16
93
94
; --------------------------------------------------------------------------
95
	SECTION	SEG_TEXT
96
	BITS	32
97
;
98
; Perform dequantization and inverse DCT on one block of coefficients,
99
; producing a reduced-size 4x4 output block.
100
;
101
; GLOBAL(void)
102
; jsimd_idct_4x4_sse2 (void * dct_table, JCOEFPTR coef_block,
103
;                      JSAMPARRAY output_buf, JDIMENSION output_col)
104
;
105
106
%define dct_table(b)	(b)+8			; void * dct_table
107
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
108
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
109
%define output_col(b)	(b)+20		; JDIMENSION output_col
110
111
%define original_ebp	ebp+0
112
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
113
%define WK_NUM		2
114
115
	align	16
116
	global	EXTN(jsimd_idct_4x4_sse2)
117
118
EXTN(jsimd_idct_4x4_sse2):
119
	push	ebp
120
	mov	eax,esp				; eax = original ebp
121
	sub	esp, byte 4
122
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
123
	mov	[esp],eax
124
	mov	ebp,esp				; ebp = aligned ebp
125
	lea	esp, [wk(0)]
126
	pushpic	ebx
127
;	push	ecx		; unused
128
;	push	edx		; need not be preserved
129
	push	esi
130
	push	edi
131
132
	get_GOT	ebx		; get GOT address
133
134
	; ---- Pass 1: process columns from input.
135
136
;	mov	eax, [original_ebp]
137
	mov	edx, POINTER [dct_table(eax)]	; quantptr
138
	mov	esi, JCOEFPTR [coef_block(eax)]		; inptr
139
140
%ifndef NO_ZERO_COLUMN_TEST_4X4_SSE2
141
	mov	eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
142
	or	eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
143
	jnz	short .columnDCT
144
145
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
146
	movdqa	xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)]
147
	por	xmm0, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
148
	por	xmm1, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
149
	por	xmm0, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)]
150
	por	xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
151
	por	xmm0,xmm1
152
	packsswb xmm0,xmm0
153
	packsswb xmm0,xmm0
154
	movd	eax,xmm0
155
	test	eax,eax
156
	jnz	short .columnDCT
157
158
	; -- AC terms all zero
159
160
	movdqa	xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
161
	pmullw	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
162
163
	psllw	xmm0,PASS1_BITS
164
165
	movdqa    xmm3,xmm0	; xmm0=in0=(00 01 02 03 04 05 06 07)
166
	punpcklwd xmm0,xmm0	; xmm0=(00 00 01 01 02 02 03 03)
167
	punpckhwd xmm3,xmm3	; xmm3=(04 04 05 05 06 06 07 07)
168
169
	pshufd	xmm1,xmm0,0x50	; xmm1=[col0 col1]=(00 00 00 00 01 01 01 01)
170
	pshufd	xmm0,xmm0,0xFA	; xmm0=[col2 col3]=(02 02 02 02 03 03 03 03)
171
	pshufd	xmm6,xmm3,0x50	; xmm6=[col4 col5]=(04 04 04 04 05 05 05 05)
172
	pshufd	xmm3,xmm3,0xFA	; xmm3=[col6 col7]=(06 06 06 06 07 07 07 07)
173
174
	jmp	near .column_end
175
	alignx	16,7
176
%endif
177
.columnDCT:
178
179
	; -- Odd part
180
181
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
182
	movdqa	xmm1, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
183
	pmullw	xmm0, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
184
	pmullw	xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
185
	movdqa	xmm2, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
186
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
187
	pmullw	xmm2, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
188
	pmullw	xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
189
190
	movdqa    xmm4,xmm0
191
	movdqa    xmm5,xmm0
192
	punpcklwd xmm4,xmm1
193
	punpckhwd xmm5,xmm1
194
	movdqa    xmm0,xmm4
195
	movdqa    xmm1,xmm5
196
	pmaddwd   xmm4,[GOTOFF(ebx,PW_F256_F089)]	; xmm4=(tmp2L)
197
	pmaddwd   xmm5,[GOTOFF(ebx,PW_F256_F089)]	; xmm5=(tmp2H)
198
	pmaddwd   xmm0,[GOTOFF(ebx,PW_F106_MF217)]	; xmm0=(tmp0L)
199
	pmaddwd   xmm1,[GOTOFF(ebx,PW_F106_MF217)]	; xmm1=(tmp0H)
200
201
	movdqa    xmm6,xmm2
202
	movdqa    xmm7,xmm2
203
	punpcklwd xmm6,xmm3
204
	punpckhwd xmm7,xmm3
205
	movdqa    xmm2,xmm6
206
	movdqa    xmm3,xmm7
207
	pmaddwd   xmm6,[GOTOFF(ebx,PW_MF060_MF050)]	; xmm6=(tmp2L)
208
	pmaddwd   xmm7,[GOTOFF(ebx,PW_MF060_MF050)]	; xmm7=(tmp2H)
209
	pmaddwd   xmm2,[GOTOFF(ebx,PW_F145_MF021)]	; xmm2=(tmp0L)
210
	pmaddwd   xmm3,[GOTOFF(ebx,PW_F145_MF021)]	; xmm3=(tmp0H)
211
212
	paddd	xmm6,xmm4		; xmm6=tmp2L
213
	paddd	xmm7,xmm5		; xmm7=tmp2H
214
	paddd	xmm2,xmm0		; xmm2=tmp0L
215
	paddd	xmm3,xmm1		; xmm3=tmp0H
216
217
	movdqa	XMMWORD [wk(0)], xmm2	; wk(0)=tmp0L
218
	movdqa	XMMWORD [wk(1)], xmm3	; wk(1)=tmp0H
219
220
	; -- Even part
221
222
	movdqa	xmm4, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
223
	movdqa	xmm5, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)]
224
	movdqa	xmm0, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)]
225
	pmullw	xmm4, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
226
	pmullw	xmm5, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
227
	pmullw	xmm0, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
228
229
	pxor      xmm1,xmm1
230
	pxor      xmm2,xmm2
231
	punpcklwd xmm1,xmm4		; xmm1=tmp0L
232
	punpckhwd xmm2,xmm4		; xmm2=tmp0H
233
	psrad     xmm1,(16-CONST_BITS-1) ; psrad xmm1,16 & pslld xmm1,CONST_BITS+1
234
	psrad     xmm2,(16-CONST_BITS-1) ; psrad xmm2,16 & pslld xmm2,CONST_BITS+1
235
236
	movdqa    xmm3,xmm5		; xmm5=in2=z2
237
	punpcklwd xmm5,xmm0		; xmm0=in6=z3
238
	punpckhwd xmm3,xmm0
239
	pmaddwd   xmm5,[GOTOFF(ebx,PW_F184_MF076)]	; xmm5=tmp2L
240
	pmaddwd   xmm3,[GOTOFF(ebx,PW_F184_MF076)]	; xmm3=tmp2H
241
242
	movdqa	xmm4,xmm1
243
	movdqa	xmm0,xmm2
244
	paddd	xmm1,xmm5		; xmm1=tmp10L
245
	paddd	xmm2,xmm3		; xmm2=tmp10H
246
	psubd	xmm4,xmm5		; xmm4=tmp12L
247
	psubd	xmm0,xmm3		; xmm0=tmp12H
248
249
	; -- Final output stage
250
251
	movdqa	xmm5,xmm1
252
	movdqa	xmm3,xmm2
253
	paddd	xmm1,xmm6		; xmm1=data0L
254
	paddd	xmm2,xmm7		; xmm2=data0H
255
	psubd	xmm5,xmm6		; xmm5=data3L
256
	psubd	xmm3,xmm7		; xmm3=data3H
257
258
	movdqa	xmm6,[GOTOFF(ebx,PD_DESCALE_P1_4)]	; xmm6=[PD_DESCALE_P1_4]
259
260
	paddd	xmm1,xmm6
261
	paddd	xmm2,xmm6
262
	psrad	xmm1,DESCALE_P1_4
263
	psrad	xmm2,DESCALE_P1_4
264
	paddd	xmm5,xmm6
265
	paddd	xmm3,xmm6
266
	psrad	xmm5,DESCALE_P1_4
267
	psrad	xmm3,DESCALE_P1_4
268
269
	packssdw  xmm1,xmm2		; xmm1=data0=(00 01 02 03 04 05 06 07)
270
	packssdw  xmm5,xmm3		; xmm5=data3=(30 31 32 33 34 35 36 37)
271
272
	movdqa	xmm7, XMMWORD [wk(0)]	; xmm7=tmp0L
273
	movdqa	xmm6, XMMWORD [wk(1)]	; xmm6=tmp0H
274
275
	movdqa	xmm2,xmm4
276
	movdqa	xmm3,xmm0
277
	paddd	xmm4,xmm7		; xmm4=data1L
278
	paddd	xmm0,xmm6		; xmm0=data1H
279
	psubd	xmm2,xmm7		; xmm2=data2L
280
	psubd	xmm3,xmm6		; xmm3=data2H
281
282
	movdqa	xmm7,[GOTOFF(ebx,PD_DESCALE_P1_4)]	; xmm7=[PD_DESCALE_P1_4]
283
284
	paddd	xmm4,xmm7
285
	paddd	xmm0,xmm7
286
	psrad	xmm4,DESCALE_P1_4
287
	psrad	xmm0,DESCALE_P1_4
288
	paddd	xmm2,xmm7
289
	paddd	xmm3,xmm7
290
	psrad	xmm2,DESCALE_P1_4
291
	psrad	xmm3,DESCALE_P1_4
292
293
	packssdw  xmm4,xmm0		; xmm4=data1=(10 11 12 13 14 15 16 17)
294
	packssdw  xmm2,xmm3		; xmm2=data2=(20 21 22 23 24 25 26 27)
295
296
	movdqa    xmm6,xmm1	; transpose coefficients(phase 1)
297
	punpcklwd xmm1,xmm4	; xmm1=(00 10 01 11 02 12 03 13)
298
	punpckhwd xmm6,xmm4	; xmm6=(04 14 05 15 06 16 07 17)
299
	movdqa    xmm7,xmm2	; transpose coefficients(phase 1)
300
	punpcklwd xmm2,xmm5	; xmm2=(20 30 21 31 22 32 23 33)
301
	punpckhwd xmm7,xmm5	; xmm7=(24 34 25 35 26 36 27 37)
302
303
	movdqa    xmm0,xmm1	; transpose coefficients(phase 2)
304
	punpckldq xmm1,xmm2	; xmm1=[col0 col1]=(00 10 20 30 01 11 21 31)
305
	punpckhdq xmm0,xmm2	; xmm0=[col2 col3]=(02 12 22 32 03 13 23 33)
306
	movdqa    xmm3,xmm6	; transpose coefficients(phase 2)
307
	punpckldq xmm6,xmm7	; xmm6=[col4 col5]=(04 14 24 34 05 15 25 35)
308
	punpckhdq xmm3,xmm7	; xmm3=[col6 col7]=(06 16 26 36 07 17 27 37)
309
.column_end:
310
311
	; -- Prefetch the next coefficient block
312
313
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
314
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
315
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
316
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
317
318
	; ---- Pass 2: process rows, store into output array.
319
320
	mov	eax, [original_ebp]
321
	mov	edi, JSAMPARRAY [output_buf(eax)]	; (JSAMPROW *)
322
	mov	eax, JDIMENSION [output_col(eax)]
323
324
	; -- Even part
325
326
	pxor      xmm4,xmm4
327
	punpcklwd xmm4,xmm1		; xmm4=tmp0
328
	psrad     xmm4,(16-CONST_BITS-1) ; psrad xmm4,16 & pslld xmm4,CONST_BITS+1
329
330
	; -- Odd part
331
332
	punpckhwd xmm1,xmm0
333
	punpckhwd xmm6,xmm3
334
	movdqa    xmm5,xmm1
335
	movdqa    xmm2,xmm6
336
	pmaddwd   xmm1,[GOTOFF(ebx,PW_F256_F089)]	; xmm1=(tmp2)
337
	pmaddwd   xmm6,[GOTOFF(ebx,PW_MF060_MF050)]	; xmm6=(tmp2)
338
	pmaddwd   xmm5,[GOTOFF(ebx,PW_F106_MF217)]	; xmm5=(tmp0)
339
	pmaddwd   xmm2,[GOTOFF(ebx,PW_F145_MF021)]	; xmm2=(tmp0)
340
341
	paddd     xmm6,xmm1		; xmm6=tmp2
342
	paddd     xmm2,xmm5		; xmm2=tmp0
343
344
	; -- Even part
345
346
	punpcklwd xmm0,xmm3
347
	pmaddwd   xmm0,[GOTOFF(ebx,PW_F184_MF076)]	; xmm0=tmp2
348
349
	movdqa    xmm7,xmm4
350
	paddd     xmm4,xmm0		; xmm4=tmp10
351
	psubd     xmm7,xmm0		; xmm7=tmp12
352
353
	; -- Final output stage
354
355
	movdqa	xmm1,[GOTOFF(ebx,PD_DESCALE_P2_4)]	; xmm1=[PD_DESCALE_P2_4]
356
357
	movdqa	xmm5,xmm4
358
	movdqa	xmm3,xmm7
359
	paddd	xmm4,xmm6		; xmm4=data0=(00 10 20 30)
360
	paddd	xmm7,xmm2		; xmm7=data1=(01 11 21 31)
361
	psubd	xmm5,xmm6		; xmm5=data3=(03 13 23 33)
362
	psubd	xmm3,xmm2		; xmm3=data2=(02 12 22 32)
363
364
	paddd	xmm4,xmm1
365
	paddd	xmm7,xmm1
366
	psrad	xmm4,DESCALE_P2_4
367
	psrad	xmm7,DESCALE_P2_4
368
	paddd	xmm5,xmm1
369
	paddd	xmm3,xmm1
370
	psrad	xmm5,DESCALE_P2_4
371
	psrad	xmm3,DESCALE_P2_4
372
373
	packssdw  xmm4,xmm3		; xmm4=(00 10 20 30 02 12 22 32)
374
	packssdw  xmm7,xmm5		; xmm7=(01 11 21 31 03 13 23 33)
375
376
	movdqa    xmm0,xmm4		; transpose coefficients(phase 1)
377
	punpcklwd xmm4,xmm7		; xmm4=(00 01 10 11 20 21 30 31)
378
	punpckhwd xmm0,xmm7		; xmm0=(02 03 12 13 22 23 32 33)
379
380
	movdqa    xmm6,xmm4		; transpose coefficients(phase 2)
381
	punpckldq xmm4,xmm0		; xmm4=(00 01 02 03 10 11 12 13)
382
	punpckhdq xmm6,xmm0		; xmm6=(20 21 22 23 30 31 32 33)
383
384
	packsswb  xmm4,xmm6		; xmm4=(00 01 02 03 10 11 12 13 20 ..)
385
	paddb     xmm4,[GOTOFF(ebx,PB_CENTERJSAMP)]
386
387
	pshufd    xmm2,xmm4,0x39	; xmm2=(10 11 12 13 20 21 22 23 30 ..)
388
	pshufd    xmm1,xmm4,0x4E	; xmm1=(20 21 22 23 30 31 32 33 00 ..)
389
	pshufd    xmm3,xmm4,0x93	; xmm3=(30 31 32 33 00 01 02 03 10 ..)
390
391
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
392
	mov	esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
393
	movd	XMM_DWORD [edx+eax*SIZEOF_JSAMPLE], xmm4
394
	movd	XMM_DWORD [esi+eax*SIZEOF_JSAMPLE], xmm2
395
	mov	edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
396
	mov	esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
397
	movd	XMM_DWORD [edx+eax*SIZEOF_JSAMPLE], xmm1
398
	movd	XMM_DWORD [esi+eax*SIZEOF_JSAMPLE], xmm3
399
400
	pop	edi
401
	pop	esi
402
;	pop	edx		; need not be preserved
403
;	pop	ecx		; unused
404
	poppic	ebx
405
	mov	esp,ebp		; esp <- aligned ebp
406
	pop	esp		; esp <- original ebp
407
	pop	ebp
408
	ret
409
410
411
; --------------------------------------------------------------------------
412
;
413
; Perform dequantization and inverse DCT on one block of coefficients,
414
; producing a reduced-size 2x2 output block.
415
;
416
; GLOBAL(void)
417
; jsimd_idct_2x2_sse2 (void * dct_table, JCOEFPTR coef_block,
418
;                      JSAMPARRAY output_buf, JDIMENSION output_col)
419
;
420
421
%define dct_table(b)	(b)+8			; void * dct_table
422
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
423
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
424
%define output_col(b)	(b)+20		; JDIMENSION output_col
425
426
	align	16
427
	global	EXTN(jsimd_idct_2x2_sse2)
428
429
EXTN(jsimd_idct_2x2_sse2):
430
	push	ebp
431
	mov	ebp,esp
432
	push	ebx
433
;	push	ecx		; need not be preserved
434
;	push	edx		; need not be preserved
435
	push	esi
436
	push	edi
437
438
	get_GOT	ebx		; get GOT address
439
440
	; ---- Pass 1: process columns from input.
441
442
	mov	edx, POINTER [dct_table(ebp)]	; quantptr
443
	mov	esi, JCOEFPTR [coef_block(ebp)]		; inptr
444
445
	; | input:                  | result:        |
446
	; | 00 01 ** 03 ** 05 ** 07 |                |
447
	; | 10 11 ** 13 ** 15 ** 17 |                |
448
	; | ** ** ** ** ** ** ** ** |                |
449
	; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 |
450
	; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 |
451
	; | 50 51 ** 53 ** 55 ** 57 |                |
452
	; | ** ** ** ** ** ** ** ** |                |
453
	; | 70 71 ** 73 ** 75 ** 77 |                |
454
455
	; -- Odd part
456
457
	movdqa	xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
458
	movdqa	xmm1, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
459
	pmullw	xmm0, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
460
	pmullw	xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
461
	movdqa	xmm2, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
462
	movdqa	xmm3, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
463
	pmullw	xmm2, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
464
	pmullw	xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
465
466
	; xmm0=(10 11 ** 13 ** 15 ** 17), xmm1=(30 31 ** 33 ** 35 ** 37)
467
	; xmm2=(50 51 ** 53 ** 55 ** 57), xmm3=(70 71 ** 73 ** 75 ** 77)
468
469
	pcmpeqd   xmm7,xmm7
470
	pslld     xmm7,WORD_BIT		; xmm7={0x0000 0xFFFF 0x0000 0xFFFF ..}
471
472
	movdqa    xmm4,xmm0		; xmm4=(10 11 ** 13 ** 15 ** 17)
473
	movdqa    xmm5,xmm2		; xmm5=(50 51 ** 53 ** 55 ** 57)
474
	punpcklwd xmm4,xmm1		; xmm4=(10 30 11 31 ** ** 13 33)
475
	punpcklwd xmm5,xmm3		; xmm5=(50 70 51 71 ** ** 53 73)
476
	pmaddwd   xmm4,[GOTOFF(ebx,PW_F362_MF127)]
477
	pmaddwd   xmm5,[GOTOFF(ebx,PW_F085_MF072)]
478
479
	psrld	xmm0,WORD_BIT		; xmm0=(11 -- 13 -- 15 -- 17 --)
480
	pand	xmm1,xmm7		; xmm1=(-- 31 -- 33 -- 35 -- 37)
481
	psrld	xmm2,WORD_BIT		; xmm2=(51 -- 53 -- 55 -- 57 --)
482
	pand	xmm3,xmm7		; xmm3=(-- 71 -- 73 -- 75 -- 77)
483
	por	xmm0,xmm1		; xmm0=(11 31 13 33 15 35 17 37)
484
	por	xmm2,xmm3		; xmm2=(51 71 53 73 55 75 57 77)
485
	pmaddwd	xmm0,[GOTOFF(ebx,PW_F362_MF127)]
486
	pmaddwd	xmm2,[GOTOFF(ebx,PW_F085_MF072)]
487
488
	paddd	xmm4,xmm5		; xmm4=tmp0[col0 col1 **** col3]
489
	paddd	xmm0,xmm2		; xmm0=tmp0[col1 col3 col5 col7]
490
491
	; -- Even part
492
493
	movdqa	xmm6, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
494
	pmullw	xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
495
496
	; xmm6=(00 01 ** 03 ** 05 ** 07)
497
498
	movdqa	xmm1,xmm6		; xmm1=(00 01 ** 03 ** 05 ** 07)
499
	pslld	xmm6,WORD_BIT		; xmm6=(-- 00 -- ** -- ** -- **)
500
	pand	xmm1,xmm7		; xmm1=(-- 01 -- 03 -- 05 -- 07)
501
	psrad	xmm6,(WORD_BIT-CONST_BITS-2) ; xmm6=tmp10[col0 **** **** ****]
502
	psrad	xmm1,(WORD_BIT-CONST_BITS-2) ; xmm1=tmp10[col1 col3 col5 col7]
503
504
	; -- Final output stage
505
506
	movdqa	xmm3,xmm6
507
	movdqa	xmm5,xmm1
508
	paddd	xmm6,xmm4	; xmm6=data0[col0 **** **** ****]=(A0 ** ** **)
509
	paddd	xmm1,xmm0	; xmm1=data0[col1 col3 col5 col7]=(A1 A3 A5 A7)
510
	psubd	xmm3,xmm4	; xmm3=data1[col0 **** **** ****]=(B0 ** ** **)
511
	psubd	xmm5,xmm0	; xmm5=data1[col1 col3 col5 col7]=(B1 B3 B5 B7)
512
513
	movdqa	xmm2,[GOTOFF(ebx,PD_DESCALE_P1_2)]	; xmm2=[PD_DESCALE_P1_2]
514
515
	punpckldq  xmm6,xmm3		; xmm6=(A0 B0 ** **)
516
517
	movdqa     xmm7,xmm1
518
	punpcklqdq xmm1,xmm5		; xmm1=(A1 A3 B1 B3)
519
	punpckhqdq xmm7,xmm5		; xmm7=(A5 A7 B5 B7)
520
521
	paddd	xmm6,xmm2
522
	psrad	xmm6,DESCALE_P1_2
523
524
	paddd	xmm1,xmm2
525
	paddd	xmm7,xmm2
526
	psrad	xmm1,DESCALE_P1_2
527
	psrad	xmm7,DESCALE_P1_2
528
529
	; -- Prefetch the next coefficient block
530
531
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
532
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
533
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
534
	prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
535
536
	; ---- Pass 2: process rows, store into output array.
537
538
	mov	edi, JSAMPARRAY [output_buf(ebp)]	; (JSAMPROW *)
539
	mov	eax, JDIMENSION [output_col(ebp)]
540
541
	; | input:| result:|
542
	; | A0 B0 |        |
543
	; | A1 B1 | C0 C1  |
544
	; | A3 B3 | D0 D1  |
545
	; | A5 B5 |        |
546
	; | A7 B7 |        |
547
548
	; -- Odd part
549
550
	packssdw  xmm1,xmm1		; xmm1=(A1 A3 B1 B3 A1 A3 B1 B3)
551
	packssdw  xmm7,xmm7		; xmm7=(A5 A7 B5 B7 A5 A7 B5 B7)
552
	pmaddwd   xmm1,[GOTOFF(ebx,PW_F362_MF127)]
553
	pmaddwd   xmm7,[GOTOFF(ebx,PW_F085_MF072)]
554
555
	paddd     xmm1,xmm7		; xmm1=tmp0[row0 row1 row0 row1]
556
557
	; -- Even part
558
559
	pslld     xmm6,(CONST_BITS+2)	; xmm6=tmp10[row0 row1 **** ****]
560
561
	; -- Final output stage
562
563
	movdqa    xmm4,xmm6
564
	paddd     xmm6,xmm1	; xmm6=data0[row0 row1 **** ****]=(C0 C1 ** **)
565
	psubd     xmm4,xmm1	; xmm4=data1[row0 row1 **** ****]=(D0 D1 ** **)
566
567
	punpckldq xmm6,xmm4	; xmm6=(C0 D0 C1 D1)
568
569
	paddd     xmm6,[GOTOFF(ebx,PD_DESCALE_P2_2)]
570
	psrad     xmm6,DESCALE_P2_2
571
572
	packssdw  xmm6,xmm6		; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1)
573
	packsswb  xmm6,xmm6		; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1 ..)
574
	paddb     xmm6,[GOTOFF(ebx,PB_CENTERJSAMP)]
575
576
	pextrw	ebx,xmm6,0x00		; ebx=(C0 D0 -- --)
577
	pextrw	ecx,xmm6,0x01		; ecx=(C1 D1 -- --)
578
579
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
580
	mov	esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
581
	mov	WORD [edx+eax*SIZEOF_JSAMPLE], bx
582
	mov	WORD [esi+eax*SIZEOF_JSAMPLE], cx
583
584
	pop	edi
585
	pop	esi
586
;	pop	edx		; need not be preserved
587
;	pop	ecx		; need not be preserved
588
	pop	ebx
589
	pop	ebp
590
	ret
591
592
; For some reason, the OS X linker does not honor the request to align the
593
; segment unless we do this.
594
	align	16
(-)a/jpeg/simd/jisseflt.asm (+572 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jisseflt.asm - floating-point IDCT (SSE & MMX)
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; This file contains a floating-point implementation of the inverse DCT
18
; (Discrete Cosine Transform). The following code is based directly on
19
; the IJG's original jidctflt.c; see the jidctflt.c for more details.
20
;
21
; [TAB8]
22
23
%include "jsimdext.inc"
24
%include "jdct.inc"
25
26
; --------------------------------------------------------------------------
27
28
%macro	unpcklps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5)
29
	shufps	%1,%2,0x44
30
%endmacro
31
32
%macro	unpckhps2 2	; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7)
33
	shufps	%1,%2,0xEE
34
%endmacro
35
36
; --------------------------------------------------------------------------
37
	SECTION	SEG_CONST
38
39
	alignz	16
40
	global	EXTN(jconst_idct_float_sse)
41
42
EXTN(jconst_idct_float_sse):
43
44
PD_1_414	times 4 dd  1.414213562373095048801689
45
PD_1_847	times 4 dd  1.847759065022573512256366
46
PD_1_082	times 4 dd  1.082392200292393968799446
47
PD_M2_613	times 4 dd -2.613125929752753055713286
48
PD_0_125	times 4 dd  0.125	; 1/8
49
PB_CENTERJSAMP	times 8 db  CENTERJSAMPLE
50
51
	alignz	16
52
53
; --------------------------------------------------------------------------
54
	SECTION	SEG_TEXT
55
	BITS	32
56
;
57
; Perform dequantization and inverse DCT on one block of coefficients.
58
;
59
; GLOBAL(void)
60
; jsimd_idct_float_sse (void * dct_table, JCOEFPTR coef_block,
61
;                       JSAMPARRAY output_buf, JDIMENSION output_col)
62
;
63
64
%define dct_table(b)	(b)+8			; void * dct_table
65
%define coef_block(b)	(b)+12		; JCOEFPTR coef_block
66
%define output_buf(b)	(b)+16		; JSAMPARRAY output_buf
67
%define output_col(b)	(b)+20		; JDIMENSION output_col
68
69
%define original_ebp	ebp+0
70
%define wk(i)		ebp-(WK_NUM-(i))*SIZEOF_XMMWORD	; xmmword wk[WK_NUM]
71
%define WK_NUM		2
72
%define workspace	wk(0)-DCTSIZE2*SIZEOF_FAST_FLOAT
73
					; FAST_FLOAT workspace[DCTSIZE2]
74
75
	align	16
76
	global	EXTN(jsimd_idct_float_sse)
77
78
EXTN(jsimd_idct_float_sse):
79
	push	ebp
80
	mov	eax,esp				; eax = original ebp
81
	sub	esp, byte 4
82
	and	esp, byte (-SIZEOF_XMMWORD)	; align to 128 bits
83
	mov	[esp],eax
84
	mov	ebp,esp				; ebp = aligned ebp
85
	lea	esp, [workspace]
86
	push	ebx
87
;	push	ecx		; need not be preserved
88
;	push	edx		; need not be preserved
89
	push	esi
90
	push	edi
91
92
	get_GOT	ebx		; get GOT address
93
94
	; ---- Pass 1: process columns from input, store into work array.
95
96
;	mov	eax, [original_ebp]
97
	mov	edx, POINTER [dct_table(eax)]	; quantptr
98
	mov	esi, JCOEFPTR [coef_block(eax)]		; inptr
99
	lea	edi, [workspace]			; FAST_FLOAT * wsptr
100
	mov	ecx, DCTSIZE/4				; ctr
101
	alignx	16,7
102
.columnloop:
103
%ifndef NO_ZERO_COLUMN_TEST_FLOAT_SSE
104
	mov	eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
105
	or	eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
106
	jnz	near .columnDCT
107
108
	movq	mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
109
	movq	mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
110
	por	mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
111
	por	mm1, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
112
	por	mm0, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
113
	por	mm1, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
114
	por	mm0, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
115
	por	mm1,mm0
116
	packsswb mm1,mm1
117
	movd	eax,mm1
118
	test	eax,eax
119
	jnz	short .columnDCT
120
121
	; -- AC terms all zero
122
123
	movq      mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
124
125
	punpckhwd mm1,mm0			; mm1=(** 02 ** 03)
126
	punpcklwd mm0,mm0			; mm0=(00 00 01 01)
127
	psrad     mm1,(DWORD_BIT-WORD_BIT)	; mm1=in0H=(02 03)
128
	psrad     mm0,(DWORD_BIT-WORD_BIT)	; mm0=in0L=(00 01)
129
	cvtpi2ps  xmm3,mm1			; xmm3=(02 03 ** **)
130
	cvtpi2ps  xmm0,mm0			; xmm0=(00 01 ** **)
131
	movlhps   xmm0,xmm3			; xmm0=in0=(00 01 02 03)
132
133
	mulps	xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
134
135
	movaps	xmm1,xmm0
136
	movaps	xmm2,xmm0
137
	movaps	xmm3,xmm0
138
139
	shufps	xmm0,xmm0,0x00			; xmm0=(00 00 00 00)
140
	shufps	xmm1,xmm1,0x55			; xmm1=(01 01 01 01)
141
	shufps	xmm2,xmm2,0xAA			; xmm2=(02 02 02 02)
142
	shufps	xmm3,xmm3,0xFF			; xmm3=(03 03 03 03)
143
144
	movaps	XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm0
145
	movaps	XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0
146
	movaps	XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm1
147
	movaps	XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1
148
	movaps	XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm2
149
	movaps	XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm2
150
	movaps	XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm3
151
	movaps	XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3
152
	jmp	near .nextcolumn
153
	alignx	16,7
154
%endif
155
.columnDCT:
156
157
	; -- Even part
158
159
	movq      mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
160
	movq      mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
161
	movq      mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
162
	movq      mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
163
164
	punpckhwd mm4,mm0			; mm4=(** 02 ** 03)
165
	punpcklwd mm0,mm0			; mm0=(00 00 01 01)
166
	punpckhwd mm5,mm1			; mm5=(** 22 ** 23)
167
	punpcklwd mm1,mm1			; mm1=(20 20 21 21)
168
169
	psrad     mm4,(DWORD_BIT-WORD_BIT)	; mm4=in0H=(02 03)
170
	psrad     mm0,(DWORD_BIT-WORD_BIT)	; mm0=in0L=(00 01)
171
	cvtpi2ps  xmm4,mm4			; xmm4=(02 03 ** **)
172
	cvtpi2ps  xmm0,mm0			; xmm0=(00 01 ** **)
173
	psrad     mm5,(DWORD_BIT-WORD_BIT)	; mm5=in2H=(22 23)
174
	psrad     mm1,(DWORD_BIT-WORD_BIT)	; mm1=in2L=(20 21)
175
	cvtpi2ps  xmm5,mm5			; xmm5=(22 23 ** **)
176
	cvtpi2ps  xmm1,mm1			; xmm1=(20 21 ** **)
177
178
	punpckhwd mm6,mm2			; mm6=(** 42 ** 43)
179
	punpcklwd mm2,mm2			; mm2=(40 40 41 41)
180
	punpckhwd mm7,mm3			; mm7=(** 62 ** 63)
181
	punpcklwd mm3,mm3			; mm3=(60 60 61 61)
182
183
	psrad     mm6,(DWORD_BIT-WORD_BIT)	; mm6=in4H=(42 43)
184
	psrad     mm2,(DWORD_BIT-WORD_BIT)	; mm2=in4L=(40 41)
185
	cvtpi2ps  xmm6,mm6			; xmm6=(42 43 ** **)
186
	cvtpi2ps  xmm2,mm2			; xmm2=(40 41 ** **)
187
	psrad     mm7,(DWORD_BIT-WORD_BIT)	; mm7=in6H=(62 63)
188
	psrad     mm3,(DWORD_BIT-WORD_BIT)	; mm3=in6L=(60 61)
189
	cvtpi2ps  xmm7,mm7			; xmm7=(62 63 ** **)
190
	cvtpi2ps  xmm3,mm3			; xmm3=(60 61 ** **)
191
192
	movlhps   xmm0,xmm4			; xmm0=in0=(00 01 02 03)
193
	movlhps   xmm1,xmm5			; xmm1=in2=(20 21 22 23)
194
	mulps     xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
195
	mulps     xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
196
197
	movlhps   xmm2,xmm6			; xmm2=in4=(40 41 42 43)
198
	movlhps   xmm3,xmm7			; xmm3=in6=(60 61 62 63)
199
	mulps     xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
200
	mulps     xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
201
202
	movaps	xmm4,xmm0
203
	movaps	xmm5,xmm1
204
	subps	xmm0,xmm2		; xmm0=tmp11
205
	subps	xmm1,xmm3
206
	addps	xmm4,xmm2		; xmm4=tmp10
207
	addps	xmm5,xmm3		; xmm5=tmp13
208
209
	mulps	xmm1,[GOTOFF(ebx,PD_1_414)]
210
	subps	xmm1,xmm5		; xmm1=tmp12
211
212
	movaps	xmm6,xmm4
213
	movaps	xmm7,xmm0
214
	subps	xmm4,xmm5		; xmm4=tmp3
215
	subps	xmm0,xmm1		; xmm0=tmp2
216
	addps	xmm6,xmm5		; xmm6=tmp0
217
	addps	xmm7,xmm1		; xmm7=tmp1
218
219
	movaps	XMMWORD [wk(1)], xmm4	; tmp3
220
	movaps	XMMWORD [wk(0)], xmm0	; tmp2
221
222
	; -- Odd part
223
224
	movq      mm4, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
225
	movq      mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
226
	movq      mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
227
	movq      mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
228
229
	punpckhwd mm6,mm4			; mm6=(** 12 ** 13)
230
	punpcklwd mm4,mm4			; mm4=(10 10 11 11)
231
	punpckhwd mm2,mm0			; mm2=(** 32 ** 33)
232
	punpcklwd mm0,mm0			; mm0=(30 30 31 31)
233
234
	psrad     mm6,(DWORD_BIT-WORD_BIT)	; mm6=in1H=(12 13)
235
	psrad     mm4,(DWORD_BIT-WORD_BIT)	; mm4=in1L=(10 11)
236
	cvtpi2ps  xmm4,mm6			; xmm4=(12 13 ** **)
237
	cvtpi2ps  xmm2,mm4			; xmm2=(10 11 ** **)
238
	psrad     mm2,(DWORD_BIT-WORD_BIT)	; mm2=in3H=(32 33)
239
	psrad     mm0,(DWORD_BIT-WORD_BIT)	; mm0=in3L=(30 31)
240
	cvtpi2ps  xmm0,mm2			; xmm0=(32 33 ** **)
241
	cvtpi2ps  xmm3,mm0			; xmm3=(30 31 ** **)
242
243
	punpckhwd mm7,mm5			; mm7=(** 52 ** 53)
244
	punpcklwd mm5,mm5			; mm5=(50 50 51 51)
245
	punpckhwd mm3,mm1			; mm3=(** 72 ** 73)
246
	punpcklwd mm1,mm1			; mm1=(70 70 71 71)
247
248
	movlhps   xmm2,xmm4			; xmm2=in1=(10 11 12 13)
249
	movlhps   xmm3,xmm0			; xmm3=in3=(30 31 32 33)
250
251
	psrad     mm7,(DWORD_BIT-WORD_BIT)	; mm7=in5H=(52 53)
252
	psrad     mm5,(DWORD_BIT-WORD_BIT)	; mm5=in5L=(50 51)
253
	cvtpi2ps  xmm4,mm7			; xmm4=(52 53 ** **)
254
	cvtpi2ps  xmm5,mm5			; xmm5=(50 51 ** **)
255
	psrad     mm3,(DWORD_BIT-WORD_BIT)	; mm3=in7H=(72 73)
256
	psrad     mm1,(DWORD_BIT-WORD_BIT)	; mm1=in7L=(70 71)
257
	cvtpi2ps  xmm0,mm3			; xmm0=(72 73 ** **)
258
	cvtpi2ps  xmm1,mm1			; xmm1=(70 71 ** **)
259
260
	mulps     xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
261
	mulps     xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
262
263
	movlhps   xmm5,xmm4			; xmm5=in5=(50 51 52 53)
264
	movlhps   xmm1,xmm0			; xmm1=in7=(70 71 72 73)
265
	mulps     xmm5, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
266
	mulps     xmm1, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
267
268
	movaps	xmm4,xmm2
269
	movaps	xmm0,xmm5
270
	addps	xmm2,xmm1		; xmm2=z11
271
	addps	xmm5,xmm3		; xmm5=z13
272
	subps	xmm4,xmm1		; xmm4=z12
273
	subps	xmm0,xmm3		; xmm0=z10
274
275
	movaps	xmm1,xmm2
276
	subps	xmm2,xmm5
277
	addps	xmm1,xmm5		; xmm1=tmp7
278
279
	mulps	xmm2,[GOTOFF(ebx,PD_1_414)]	; xmm2=tmp11
280
281
	movaps	xmm3,xmm0
282
	addps	xmm0,xmm4
283
	mulps	xmm0,[GOTOFF(ebx,PD_1_847)]	; xmm0=z5
284
	mulps	xmm3,[GOTOFF(ebx,PD_M2_613)]	; xmm3=(z10 * -2.613125930)
285
	mulps	xmm4,[GOTOFF(ebx,PD_1_082)]	; xmm4=(z12 * 1.082392200)
286
	addps	xmm3,xmm0		; xmm3=tmp12
287
	subps	xmm4,xmm0		; xmm4=tmp10
288
289
	; -- Final output stage
290
291
	subps	xmm3,xmm1		; xmm3=tmp6
292
	movaps	xmm5,xmm6
293
	movaps	xmm0,xmm7
294
	addps	xmm6,xmm1		; xmm6=data0=(00 01 02 03)
295
	addps	xmm7,xmm3		; xmm7=data1=(10 11 12 13)
296
	subps	xmm5,xmm1		; xmm5=data7=(70 71 72 73)
297
	subps	xmm0,xmm3		; xmm0=data6=(60 61 62 63)
298
	subps	xmm2,xmm3		; xmm2=tmp5
299
300
	movaps    xmm1,xmm6		; transpose coefficients(phase 1)
301
	unpcklps  xmm6,xmm7		; xmm6=(00 10 01 11)
302
	unpckhps  xmm1,xmm7		; xmm1=(02 12 03 13)
303
	movaps    xmm3,xmm0		; transpose coefficients(phase 1)
304
	unpcklps  xmm0,xmm5		; xmm0=(60 70 61 71)
305
	unpckhps  xmm3,xmm5		; xmm3=(62 72 63 73)
306
307
	movaps	xmm7, XMMWORD [wk(0)]	; xmm7=tmp2
308
	movaps	xmm5, XMMWORD [wk(1)]	; xmm5=tmp3
309
310
	movaps	XMMWORD [wk(0)], xmm0	; wk(0)=(60 70 61 71)
311
	movaps	XMMWORD [wk(1)], xmm3	; wk(1)=(62 72 63 73)
312
313
	addps	xmm4,xmm2		; xmm4=tmp4
314
	movaps	xmm0,xmm7
315
	movaps	xmm3,xmm5
316
	addps	xmm7,xmm2		; xmm7=data2=(20 21 22 23)
317
	addps	xmm5,xmm4		; xmm5=data4=(40 41 42 43)
318
	subps	xmm0,xmm2		; xmm0=data5=(50 51 52 53)
319
	subps	xmm3,xmm4		; xmm3=data3=(30 31 32 33)
320
321
	movaps    xmm2,xmm7		; transpose coefficients(phase 1)
322
	unpcklps  xmm7,xmm3		; xmm7=(20 30 21 31)
323
	unpckhps  xmm2,xmm3		; xmm2=(22 32 23 33)
324
	movaps    xmm4,xmm5		; transpose coefficients(phase 1)
325
	unpcklps  xmm5,xmm0		; xmm5=(40 50 41 51)
326
	unpckhps  xmm4,xmm0		; xmm4=(42 52 43 53)
327
328
	movaps    xmm3,xmm6		; transpose coefficients(phase 2)
329
	unpcklps2 xmm6,xmm7		; xmm6=(00 10 20 30)
330
	unpckhps2 xmm3,xmm7		; xmm3=(01 11 21 31)
331
	movaps    xmm0,xmm1		; transpose coefficients(phase 2)
332
	unpcklps2 xmm1,xmm2		; xmm1=(02 12 22 32)
333
	unpckhps2 xmm0,xmm2		; xmm0=(03 13 23 33)
334
335
	movaps	xmm7, XMMWORD [wk(0)]	; xmm7=(60 70 61 71)
336
	movaps	xmm2, XMMWORD [wk(1)]	; xmm2=(62 72 63 73)
337
338
	movaps	XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm6
339
	movaps	XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3
340
	movaps	XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm1
341
	movaps	XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm0
342
343
	movaps    xmm6,xmm5		; transpose coefficients(phase 2)
344
	unpcklps2 xmm5,xmm7		; xmm5=(40 50 60 70)
345
	unpckhps2 xmm6,xmm7		; xmm6=(41 51 61 71)
346
	movaps    xmm3,xmm4		; transpose coefficients(phase 2)
347
	unpcklps2 xmm4,xmm2		; xmm4=(42 52 62 72)
348
	unpckhps2 xmm3,xmm2		; xmm3=(43 53 63 73)
349
350
	movaps	XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm5
351
	movaps	XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm6
352
	movaps	XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm4
353
	movaps	XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3
354
355
.nextcolumn:
356
	add	esi, byte 4*SIZEOF_JCOEF		; coef_block
357
	add	edx, byte 4*SIZEOF_FLOAT_MULT_TYPE	; quantptr
358
	add	edi,      4*DCTSIZE*SIZEOF_FAST_FLOAT	; wsptr
359
	dec	ecx					; ctr
360
	jnz	near .columnloop
361
362
	; -- Prefetch the next coefficient block
363
364
	prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32]
365
	prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32]
366
	prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32]
367
	prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32]
368
369
	; ---- Pass 2: process rows from work array, store into output array.
370
371
	mov	eax, [original_ebp]
372
	lea	esi, [workspace]			; FAST_FLOAT * wsptr
373
	mov	edi, JSAMPARRAY [output_buf(eax)]	; (JSAMPROW *)
374
	mov	eax, JDIMENSION [output_col(eax)]
375
	mov	ecx, DCTSIZE/4				; ctr
376
	alignx	16,7
377
.rowloop:
378
379
	; -- Even part
380
381
	movaps	xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
382
	movaps	xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_FAST_FLOAT)]
383
	movaps	xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_FAST_FLOAT)]
384
	movaps	xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_FAST_FLOAT)]
385
386
	movaps	xmm4,xmm0
387
	movaps	xmm5,xmm1
388
	subps	xmm0,xmm2		; xmm0=tmp11
389
	subps	xmm1,xmm3
390
	addps	xmm4,xmm2		; xmm4=tmp10
391
	addps	xmm5,xmm3		; xmm5=tmp13
392
393
	mulps	xmm1,[GOTOFF(ebx,PD_1_414)]
394
	subps	xmm1,xmm5		; xmm1=tmp12
395
396
	movaps	xmm6,xmm4
397
	movaps	xmm7,xmm0
398
	subps	xmm4,xmm5		; xmm4=tmp3
399
	subps	xmm0,xmm1		; xmm0=tmp2
400
	addps	xmm6,xmm5		; xmm6=tmp0
401
	addps	xmm7,xmm1		; xmm7=tmp1
402
403
	movaps	XMMWORD [wk(1)], xmm4	; tmp3
404
	movaps	XMMWORD [wk(0)], xmm0	; tmp2
405
406
	; -- Odd part
407
408
	movaps	xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
409
	movaps	xmm3, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_FAST_FLOAT)]
410
	movaps	xmm5, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_FAST_FLOAT)]
411
	movaps	xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_FAST_FLOAT)]
412
413
	movaps	xmm4,xmm2
414
	movaps	xmm0,xmm5
415
	addps	xmm2,xmm1		; xmm2=z11
416
	addps	xmm5,xmm3		; xmm5=z13
417
	subps	xmm4,xmm1		; xmm4=z12
418
	subps	xmm0,xmm3		; xmm0=z10
419
420
	movaps	xmm1,xmm2
421
	subps	xmm2,xmm5
422
	addps	xmm1,xmm5		; xmm1=tmp7
423
424
	mulps	xmm2,[GOTOFF(ebx,PD_1_414)]	; xmm2=tmp11
425
426
	movaps	xmm3,xmm0
427
	addps	xmm0,xmm4
428
	mulps	xmm0,[GOTOFF(ebx,PD_1_847)]	; xmm0=z5
429
	mulps	xmm3,[GOTOFF(ebx,PD_M2_613)]	; xmm3=(z10 * -2.613125930)
430
	mulps	xmm4,[GOTOFF(ebx,PD_1_082)]	; xmm4=(z12 * 1.082392200)
431
	addps	xmm3,xmm0		; xmm3=tmp12
432
	subps	xmm4,xmm0		; xmm4=tmp10
433
434
	; -- Final output stage
435
436
	subps	xmm3,xmm1		; xmm3=tmp6
437
	movaps	xmm5,xmm6
438
	movaps	xmm0,xmm7
439
	addps	xmm6,xmm1		; xmm6=data0=(00 10 20 30)
440
	addps	xmm7,xmm3		; xmm7=data1=(01 11 21 31)
441
	subps	xmm5,xmm1		; xmm5=data7=(07 17 27 37)
442
	subps	xmm0,xmm3		; xmm0=data6=(06 16 26 36)
443
	subps	xmm2,xmm3		; xmm2=tmp5
444
445
	movaps	xmm1,[GOTOFF(ebx,PD_0_125)]	; xmm1=[PD_0_125]
446
447
	mulps	xmm6,xmm1		; descale(1/8)
448
	mulps	xmm7,xmm1		; descale(1/8)
449
	mulps	xmm5,xmm1		; descale(1/8)
450
	mulps	xmm0,xmm1		; descale(1/8)
451
452
	movhlps   xmm3,xmm6
453
	movhlps   xmm1,xmm7
454
	cvtps2pi  mm0,xmm6		; round to int32, mm0=data0L=(00 10)
455
	cvtps2pi  mm1,xmm7		; round to int32, mm1=data1L=(01 11)
456
	cvtps2pi  mm2,xmm3		; round to int32, mm2=data0H=(20 30)
457
	cvtps2pi  mm3,xmm1		; round to int32, mm3=data1H=(21 31)
458
	packssdw  mm0,mm2		; mm0=data0=(00 10 20 30)
459
	packssdw  mm1,mm3		; mm1=data1=(01 11 21 31)
460
461
	movhlps   xmm6,xmm5
462
	movhlps   xmm7,xmm0
463
	cvtps2pi  mm4,xmm5		; round to int32, mm4=data7L=(07 17)
464
	cvtps2pi  mm5,xmm0		; round to int32, mm5=data6L=(06 16)
465
	cvtps2pi  mm6,xmm6		; round to int32, mm6=data7H=(27 37)
466
	cvtps2pi  mm7,xmm7		; round to int32, mm7=data6H=(26 36)
467
	packssdw  mm4,mm6		; mm4=data7=(07 17 27 37)
468
	packssdw  mm5,mm7		; mm5=data6=(06 16 26 36)
469
470
	packsswb  mm0,mm5		; mm0=(00 10 20 30 06 16 26 36)
471
	packsswb  mm1,mm4		; mm1=(01 11 21 31 07 17 27 37)
472
473
	movaps	xmm3, XMMWORD [wk(0)]	; xmm3=tmp2
474
	movaps	xmm1, XMMWORD [wk(1)]	; xmm1=tmp3
475
476
	movaps	xmm6,[GOTOFF(ebx,PD_0_125)]	; xmm6=[PD_0_125]
477
478
	addps	xmm4,xmm2		; xmm4=tmp4
479
	movaps	xmm5,xmm3
480
	movaps	xmm0,xmm1
481
	addps	xmm3,xmm2		; xmm3=data2=(02 12 22 32)
482
	addps	xmm1,xmm4		; xmm1=data4=(04 14 24 34)
483
	subps	xmm5,xmm2		; xmm5=data5=(05 15 25 35)
484
	subps	xmm0,xmm4		; xmm0=data3=(03 13 23 33)
485
486
	mulps	xmm3,xmm6		; descale(1/8)
487
	mulps	xmm1,xmm6		; descale(1/8)
488
	mulps	xmm5,xmm6		; descale(1/8)
489
	mulps	xmm0,xmm6		; descale(1/8)
490
491
	movhlps   xmm7,xmm3
492
	movhlps   xmm2,xmm1
493
	cvtps2pi  mm2,xmm3		; round to int32, mm2=data2L=(02 12)
494
	cvtps2pi  mm3,xmm1		; round to int32, mm3=data4L=(04 14)
495
	cvtps2pi  mm6,xmm7		; round to int32, mm6=data2H=(22 32)
496
	cvtps2pi  mm7,xmm2		; round to int32, mm7=data4H=(24 34)
497
	packssdw  mm2,mm6		; mm2=data2=(02 12 22 32)
498
	packssdw  mm3,mm7		; mm3=data4=(04 14 24 34)
499
500
	movhlps   xmm4,xmm5
501
	movhlps   xmm6,xmm0
502
	cvtps2pi  mm5,xmm5		; round to int32, mm5=data5L=(05 15)
503
	cvtps2pi  mm4,xmm0		; round to int32, mm4=data3L=(03 13)
504
	cvtps2pi  mm6,xmm4		; round to int32, mm6=data5H=(25 35)
505
	cvtps2pi  mm7,xmm6		; round to int32, mm7=data3H=(23 33)
506
	packssdw  mm5,mm6		; mm5=data5=(05 15 25 35)
507
	packssdw  mm4,mm7		; mm4=data3=(03 13 23 33)
508
509
	movq      mm6,[GOTOFF(ebx,PB_CENTERJSAMP)]	; mm6=[PB_CENTERJSAMP]
510
511
	packsswb  mm2,mm3		; mm2=(02 12 22 32 04 14 24 34)
512
	packsswb  mm4,mm5		; mm4=(03 13 23 33 05 15 25 35)
513
514
	paddb     mm0,mm6
515
	paddb     mm1,mm6
516
	paddb     mm2,mm6
517
	paddb     mm4,mm6
518
519
	movq      mm7,mm0		; transpose coefficients(phase 1)
520
	punpcklbw mm0,mm1		; mm0=(00 01 10 11 20 21 30 31)
521
	punpckhbw mm7,mm1		; mm7=(06 07 16 17 26 27 36 37)
522
	movq      mm3,mm2		; transpose coefficients(phase 1)
523
	punpcklbw mm2,mm4		; mm2=(02 03 12 13 22 23 32 33)
524
	punpckhbw mm3,mm4		; mm3=(04 05 14 15 24 25 34 35)
525
526
	movq      mm5,mm0		; transpose coefficients(phase 2)
527
	punpcklwd mm0,mm2		; mm0=(00 01 02 03 10 11 12 13)
528
	punpckhwd mm5,mm2		; mm5=(20 21 22 23 30 31 32 33)
529
	movq      mm6,mm3		; transpose coefficients(phase 2)
530
	punpcklwd mm3,mm7		; mm3=(04 05 06 07 14 15 16 17)
531
	punpckhwd mm6,mm7		; mm6=(24 25 26 27 34 35 36 37)
532
533
	movq      mm1,mm0		; transpose coefficients(phase 3)
534
	punpckldq mm0,mm3		; mm0=(00 01 02 03 04 05 06 07)
535
	punpckhdq mm1,mm3		; mm1=(10 11 12 13 14 15 16 17)
536
	movq      mm4,mm5		; transpose coefficients(phase 3)
537
	punpckldq mm5,mm6		; mm5=(20 21 22 23 24 25 26 27)
538
	punpckhdq mm4,mm6		; mm4=(30 31 32 33 34 35 36 37)
539
540
	pushpic	ebx			; save GOT address
541
542
	mov	edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
543
	mov	ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
544
	movq	MMWORD [edx+eax*SIZEOF_JSAMPLE], mm0
545
	movq	MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm1
546
	mov	edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
547
	mov	ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
548
	movq	MMWORD [edx+eax*SIZEOF_JSAMPLE], mm5
549
	movq	MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm4
550
551
	poppic	ebx			; restore GOT address
552
553
	add	esi, byte 4*SIZEOF_FAST_FLOAT	; wsptr
554
	add	edi, byte 4*SIZEOF_JSAMPROW
555
	dec	ecx				; ctr
556
	jnz	near .rowloop
557
558
	emms		; empty MMX state
559
560
	pop	edi
561
	pop	esi
562
;	pop	edx		; need not be preserved
563
;	pop	ecx		; need not be preserved
564
	pop	ebx
565
	mov	esp,ebp		; esp <- aligned ebp
566
	pop	esp		; esp <- original ebp
567
	pop	ebp
568
	ret
569
570
; For some reason, the OS X linker does not honor the request to align the
571
; segment unless we do this.
572
	align	16
(-)a/jpeg/simd/jsimd.h (+504 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * simd/jsimd.h
3
 *
4
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
 * 
6
 * Based on the x86 SIMD extension for IJG JPEG library,
7
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
8
 * For conditions of distribution and use, see copyright notice in jsimdext.inc
9
 *
10
 */
11
12
/* Bitmask for supported acceleration methods */
13
14
#define JSIMD_NONE    0x00
15
#define JSIMD_MMX     0x01
16
#define JSIMD_3DNOW   0x02
17
#define JSIMD_SSE     0x04
18
#define JSIMD_SSE2    0x08
19
20
/* Short forms of external names for systems with brain-damaged linkers. */
21
22
#ifdef NEED_SHORT_EXTERNAL_NAMES
23
#define jpeg_simd_cpu_support                 jSiCpuSupport
24
#define jsimd_rgb_ycc_convert_mmx             jSRGBYCCM
25
#define jsimd_extrgb_ycc_convert_mmx          jSEXTRGBYCCM
26
#define jsimd_extrgbx_ycc_convert_mmx         jSEXTRGBXYCCM
27
#define jsimd_extbgr_ycc_convert_mmx          jSEXTBGRYCCM
28
#define jsimd_extbgrx_ycc_convert_mmx         jSEXTBGRXYCCM
29
#define jsimd_extxbgr_ycc_convert_mmx         jSEXTXBGRYCCM
30
#define jsimd_extxrgb_ycc_convert_mmx         jSEXTXRGBYCCM
31
#define jsimd_ycc_rgb_convert_mmx             jSYCCRGBM
32
#define jsimd_ycc_extrgb_convert_mmx          jSYCCEXTRGBM
33
#define jsimd_ycc_extrgbx_convert_mmx         jSYCCEXTRGBXM
34
#define jsimd_ycc_extbgr_convert_mmx          jSYCCEXTBGRM
35
#define jsimd_ycc_extbgrx_convert_mmx         jSYCCEXTBGRXM
36
#define jsimd_ycc_extxbgr_convert_mmx         jSYCCEXTXBGRM
37
#define jsimd_ycc_extxrgb_convert_mmx         jSYCCEXTXRGBM
38
#define jconst_rgb_ycc_convert_sse2           jSCRGBYCCS2
39
#define jsimd_rgb_ycc_convert_sse2            jSRGBYCCS2
40
#define jsimd_extrgb_ycc_convert_sse2         jSEXTRGBYCCS2
41
#define jsimd_extrgbx_ycc_convert_sse2        jSEXTRGBXYCCS2
42
#define jsimd_extbgr_ycc_convert_sse2         jSEXTBGRYCCS2
43
#define jsimd_extbgrx_ycc_convert_sse2        jSEXTBGRXYCCS2
44
#define jsimd_extxbgr_ycc_convert_sse2        jSEXTXBGRYCCS2
45
#define jsimd_extxrgb_ycc_convert_sse2        jSEXTXRGBYCCS2
46
#define jconst_ycc_rgb_convert_sse2           jSCYCCRGBS2
47
#define jsimd_ycc_rgb_convert_sse2            jSYCCRGBS2
48
#define jsimd_ycc_extrgb_convert_sse2         jSYCCEXTRGBS2
49
#define jsimd_ycc_extrgbx_convert_sse2        jSYCCEXTRGBXS2
50
#define jsimd_ycc_extbgr_convert_sse2         jSYCCEXTBGRS2
51
#define jsimd_ycc_extbgrx_convert_sse2        jSYCCEXTBGRXS2
52
#define jsimd_ycc_extxbgr_convert_sse2        jSYCCEXTXBGRS2
53
#define jsimd_ycc_extxrgb_convert_sse2        jSYCCEXTXRGBS2
54
#define jsimd_h2v2_downsample_mmx             jSDnH2V2M
55
#define jsimd_h2v1_downsample_mmx             jSDnH2V1M
56
#define jsimd_h2v2_downsample_sse2            jSDnH2V2S2
57
#define jsimd_h2v1_downsample_sse2            jSDnH2V1S2
58
#define jsimd_h2v2_upsample_mmx               jSUpH2V2M
59
#define jsimd_h2v1_upsample_mmx               jSUpH2V1M
60
#define jsimd_h2v2_fancy_upsample_mmx         jSFUpH2V2M
61
#define jsimd_h2v1_fancy_upsample_mmx         jSFUpH2V1M
62
#define jsimd_h2v2_merged_upsample_mmx        jSMUpH2V2M
63
#define jsimd_h2v2_extrgb_merged_upsample_mmx jSMUpH2V2EXTRGBM
64
#define jsimd_h2v2_extrgbx_merged_upsample_mmx jSMUpH2V2EXTRGBXM
65
#define jsimd_h2v2_extbgr_merged_upsample_mmx jSMUpH2V2EXTBGRM
66
#define jsimd_h2v2_extbgrx_merged_upsample_mmx jSMUpH2V2EXTBGRXM
67
#define jsimd_h2v2_extxbgr_merged_upsample_mmx jSMUpH2V2EXTXBGRM
68
#define jsimd_h2v2_extxrgb_merged_upsample_mmx jSMUpH2V2EXTXRGBM
69
#define jsimd_h2v1_merged_upsample_mmx        jSMUpH2V1M
70
#define jsimd_h2v1_extrgb_merged_upsample_mmx jSMUpH2V1EXTRGBM
71
#define jsimd_h2v1_extrgbx_merged_upsample_mmx jSMUpH2V1EXTRGBXM
72
#define jsimd_h2v1_extbgr_merged_upsample_mmx jSMUpH2V1EXTBGRM
73
#define jsimd_h2v1_extbgrx_merged_upsample_mmx jSMUpH2V1EXTBGRXM
74
#define jsimd_h2v1_extxbgr_merged_upsample_mmx jSMUpH2V1EXTXBGRM
75
#define jsimd_h2v1_extxrgb_merged_upsample_mmx jSMUpH2V1EXTXRGBM
76
#define jsimd_h2v2_upsample_sse2              jSUpH2V2S2
77
#define jsimd_h2v1_upsample_sse2              jSUpH2V1S2
78
#define jconst_fancy_upsample_sse2            jSCFUpS2
79
#define jsimd_h2v2_fancy_upsample_sse2        jSFUpH2V2S2
80
#define jsimd_h2v1_fancy_upsample_sse2        jSFUpH2V1S2
81
#define jconst_merged_upsample_sse2           jSCMUpS2
82
#define jsimd_h2v2_merged_upsample_sse2       jSMUpH2V2S2
83
#define jsimd_h2v2_extrgb_merged_upsample_sse2 jSMUpH2V2EXTRGBS2
84
#define jsimd_h2v2_extrgbx_merged_upsample_sse2 jSMUpH2V2EXTRGBXS2
85
#define jsimd_h2v2_extbgr_merged_upsample_sse2 jSMUpH2V2EXTBGRS2
86
#define jsimd_h2v2_extbgrx_merged_upsample_sse2 jSMUpH2V2EXTBGRXS2
87
#define jsimd_h2v2_extxbgr_merged_upsample_sse2 jSMUpH2V2EXTXBGRS2
88
#define jsimd_h2v2_extxrgb_merged_upsample_sse2 jSMUpH2V2EXTXRGBS2
89
#define jsimd_h2v1_merged_upsample_sse2       jSMUpH2V1S2
90
#define jsimd_h2v1_extrgb_merged_upsample_sse2 jSMUpH2V1EXTRGBS2
91
#define jsimd_h2v1_extrgbx_merged_upsample_sse2 jSMUpH2V1EXTRGBXS2
92
#define jsimd_h2v1_extbgr_merged_upsample_sse2 jSMUpH2V1EXTBGRS2
93
#define jsimd_h2v1_extbgrx_merged_upsample_sse2 jSMUpH2V1EXTBGRXS2
94
#define jsimd_h2v1_extxbgr_merged_upsample_sse2 jSMUpH2V1EXTXBGRS2
95
#define jsimd_h2v1_extxrgb_merged_upsample_sse2 jSMUpH2V1EXTXRGBS2
96
#define jsimd_convsamp_mmx                    jSConvM
97
#define jsimd_convsamp_sse2                   jSConvS2
98
#define jsimd_convsamp_float_3dnow            jSConvF3D
99
#define jsimd_convsamp_float_sse              jSConvFS
100
#define jsimd_convsamp_float_sse2             jSConvFS2
101
#define jsimd_fdct_islow_mmx                  jSFDMIS
102
#define jsimd_fdct_ifast_mmx                  jSFDMIF
103
#define jconst_fdct_islow_sse2                jSCFDS2IS
104
#define jsimd_fdct_islow_sse2                 jSFDS2IS
105
#define jconst_fdct_ifast_sse2                jSCFDS2IF
106
#define jsimd_fdct_ifast_sse2                 jSFDS2IF
107
#define jsimd_fdct_float_3dnow                jSFD3DF
108
#define jconst_fdct_float_sse                 jSCFDSF
109
#define jsimd_fdct_float_sse                  jSFDSF
110
#define jsimd_quantize_mmx                    jSQuantM
111
#define jsimd_quantize_sse2                   jSQuantS2
112
#define jsimd_quantize_float_3dnow            jSQuantF3D
113
#define jsimd_quantize_float_sse              jSQuantFS
114
#define jsimd_quantize_float_sse2             jSQuantFS2
115
#define jsimd_idct_2x2_mmx                    jSIDM22
116
#define jsimd_idct_4x4_mmx                    jSIDM44
117
#define jconst_idct_red_sse2                  jSCIDS2R
118
#define jsimd_idct_2x2_sse2                   jSIDS222
119
#define jsimd_idct_4x4_sse2                   jSIDS244
120
#define jsimd_idct_islow_mmx                  jSIDMIS
121
#define jsimd_idct_ifast_mmx                  jSIDMIF
122
#define jconst_idct_islow_sse2                jSCIDS2IS
123
#define jsimd_idct_islow_sse2                 jSIDS2IS
124
#define jconst_idct_ifast_sse2                jSCIDS2IF
125
#define jsimd_idct_ifast_sse2                 jSIDS2IF
126
#define jsimd_idct_float_3dnow                jSID3DF
127
#define jconst_fdct_float_sse                 jSCIDSF
128
#define jsimd_idct_float_sse                  jSIDSF
129
#define jconst_fdct_float_sse2                jSCIDS2F
130
#define jsimd_idct_float_sse2                 jSIDS2F
131
#endif /* NEED_SHORT_EXTERNAL_NAMES */
132
133
/* SIMD Ext: retrieve SIMD/CPU information */
134
EXTERN(unsigned int) jpeg_simd_cpu_support JPP((void));
135
136
/* SIMD Color Space Conversion */
137
EXTERN(void) jsimd_rgb_ycc_convert_mmx
138
        JPP((JDIMENSION img_width,
139
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
140
             JDIMENSION output_row, int num_rows));
141
EXTERN(void) jsimd_extrgb_ycc_convert_mmx
142
        JPP((JDIMENSION img_width,
143
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
144
             JDIMENSION output_row, int num_rows));
145
EXTERN(void) jsimd_extrgbx_ycc_convert_mmx
146
        JPP((JDIMENSION img_width,
147
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
148
             JDIMENSION output_row, int num_rows));
149
EXTERN(void) jsimd_extbgr_ycc_convert_mmx
150
        JPP((JDIMENSION img_width,
151
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
152
             JDIMENSION output_row, int num_rows));
153
EXTERN(void) jsimd_extbgrx_ycc_convert_mmx
154
        JPP((JDIMENSION img_width,
155
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
156
             JDIMENSION output_row, int num_rows));
157
EXTERN(void) jsimd_extxbgr_ycc_convert_mmx
158
        JPP((JDIMENSION img_width,
159
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
160
             JDIMENSION output_row, int num_rows));
161
EXTERN(void) jsimd_extxrgb_ycc_convert_mmx
162
        JPP((JDIMENSION img_width,
163
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
164
             JDIMENSION output_row, int num_rows));
165
166
EXTERN(void) jsimd_ycc_rgb_convert_mmx
167
        JPP((JDIMENSION out_width,
168
             JSAMPIMAGE input_buf, JDIMENSION input_row,
169
             JSAMPARRAY output_buf, int num_rows));
170
EXTERN(void) jsimd_ycc_extrgb_convert_mmx
171
        JPP((JDIMENSION out_width,
172
             JSAMPIMAGE input_buf, JDIMENSION input_row,
173
             JSAMPARRAY output_buf, int num_rows));
174
EXTERN(void) jsimd_ycc_extrgbx_convert_mmx
175
        JPP((JDIMENSION out_width,
176
             JSAMPIMAGE input_buf, JDIMENSION input_row,
177
             JSAMPARRAY output_buf, int num_rows));
178
EXTERN(void) jsimd_ycc_extbgr_convert_mmx
179
        JPP((JDIMENSION out_width,
180
             JSAMPIMAGE input_buf, JDIMENSION input_row,
181
             JSAMPARRAY output_buf, int num_rows));
182
EXTERN(void) jsimd_ycc_extbgrx_convert_mmx
183
        JPP((JDIMENSION out_width,
184
             JSAMPIMAGE input_buf, JDIMENSION input_row,
185
             JSAMPARRAY output_buf, int num_rows));
186
EXTERN(void) jsimd_ycc_extxbgr_convert_mmx
187
        JPP((JDIMENSION out_width,
188
             JSAMPIMAGE input_buf, JDIMENSION input_row,
189
             JSAMPARRAY output_buf, int num_rows));
190
EXTERN(void) jsimd_ycc_extxrgb_convert_mmx
191
        JPP((JDIMENSION out_width,
192
             JSAMPIMAGE input_buf, JDIMENSION input_row,
193
             JSAMPARRAY output_buf, int num_rows));
194
195
extern const int jconst_rgb_ycc_convert_sse2[];
196
EXTERN(void) jsimd_rgb_ycc_convert_sse2
197
        JPP((JDIMENSION img_width,
198
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
199
             JDIMENSION output_row, int num_rows));
200
EXTERN(void) jsimd_extrgb_ycc_convert_sse2
201
        JPP((JDIMENSION img_width,
202
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
203
             JDIMENSION output_row, int num_rows));
204
EXTERN(void) jsimd_extrgbx_ycc_convert_sse2
205
        JPP((JDIMENSION img_width,
206
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
207
             JDIMENSION output_row, int num_rows));
208
EXTERN(void) jsimd_extbgr_ycc_convert_sse2
209
        JPP((JDIMENSION img_width,
210
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
211
             JDIMENSION output_row, int num_rows));
212
EXTERN(void) jsimd_extbgrx_ycc_convert_sse2
213
        JPP((JDIMENSION img_width,
214
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
215
             JDIMENSION output_row, int num_rows));
216
EXTERN(void) jsimd_extxbgr_ycc_convert_sse2
217
        JPP((JDIMENSION img_width,
218
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
219
             JDIMENSION output_row, int num_rows));
220
EXTERN(void) jsimd_extxrgb_ycc_convert_sse2
221
        JPP((JDIMENSION img_width,
222
             JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
223
             JDIMENSION output_row, int num_rows));
224
225
extern const int jconst_ycc_rgb_convert_sse2[];
226
EXTERN(void) jsimd_ycc_rgb_convert_sse2
227
        JPP((JDIMENSION out_width,
228
             JSAMPIMAGE input_buf, JDIMENSION input_row,
229
             JSAMPARRAY output_buf, int num_rows));
230
EXTERN(void) jsimd_ycc_extrgb_convert_sse2
231
        JPP((JDIMENSION out_width,
232
             JSAMPIMAGE input_buf, JDIMENSION input_row,
233
             JSAMPARRAY output_buf, int num_rows));
234
EXTERN(void) jsimd_ycc_extrgbx_convert_sse2
235
        JPP((JDIMENSION out_width,
236
             JSAMPIMAGE input_buf, JDIMENSION input_row,
237
             JSAMPARRAY output_buf, int num_rows));
238
EXTERN(void) jsimd_ycc_extbgr_convert_sse2
239
        JPP((JDIMENSION out_width,
240
             JSAMPIMAGE input_buf, JDIMENSION input_row,
241
             JSAMPARRAY output_buf, int num_rows));
242
EXTERN(void) jsimd_ycc_extbgrx_convert_sse2
243
        JPP((JDIMENSION out_width,
244
             JSAMPIMAGE input_buf, JDIMENSION input_row,
245
             JSAMPARRAY output_buf, int num_rows));
246
EXTERN(void) jsimd_ycc_extxbgr_convert_sse2
247
        JPP((JDIMENSION out_width,
248
             JSAMPIMAGE input_buf, JDIMENSION input_row,
249
             JSAMPARRAY output_buf, int num_rows));
250
EXTERN(void) jsimd_ycc_extxrgb_convert_sse2
251
        JPP((JDIMENSION out_width,
252
             JSAMPIMAGE input_buf, JDIMENSION input_row,
253
             JSAMPARRAY output_buf, int num_rows));
254
255
/* SIMD Downsample */
256
EXTERN(void) jsimd_h2v2_downsample_mmx
257
        JPP((JDIMENSION image_width, int max_v_samp_factor,
258
             JDIMENSION v_samp_factor, JDIMENSION width_blocks,
259
             JSAMPARRAY input_data, JSAMPARRAY output_data));
260
EXTERN(void) jsimd_h2v1_downsample_mmx
261
        JPP((JDIMENSION image_width, int max_v_samp_factor,
262
             JDIMENSION v_samp_factor, JDIMENSION width_blocks,
263
             JSAMPARRAY input_data, JSAMPARRAY output_data));
264
265
EXTERN(void) jsimd_h2v2_downsample_sse2
266
        JPP((JDIMENSION image_width, int max_v_samp_factor,
267
             JDIMENSION v_samp_factor, JDIMENSION width_blocks,
268
             JSAMPARRAY input_data, JSAMPARRAY output_data));
269
EXTERN(void) jsimd_h2v1_downsample_sse2
270
        JPP((JDIMENSION image_width, int max_v_samp_factor,
271
             JDIMENSION v_samp_factor, JDIMENSION width_blocks,
272
             JSAMPARRAY input_data, JSAMPARRAY output_data));
273
274
/* SIMD Upsample */
275
EXTERN(void) jsimd_h2v2_upsample_mmx
276
        JPP((int max_v_samp_factor, JDIMENSION output_width,
277
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
278
EXTERN(void) jsimd_h2v1_upsample_mmx
279
        JPP((int max_v_samp_factor, JDIMENSION output_width,
280
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
281
282
EXTERN(void) jsimd_h2v2_fancy_upsample_mmx
283
        JPP((int max_v_samp_factor, JDIMENSION downsampled_width,
284
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
285
EXTERN(void) jsimd_h2v1_fancy_upsample_mmx
286
        JPP((int max_v_samp_factor, JDIMENSION downsampled_width,
287
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
288
289
EXTERN(void) jsimd_h2v2_merged_upsample_mmx
290
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
291
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
292
EXTERN(void) jsimd_h2v2_extrgb_merged_upsample_mmx
293
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
294
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
295
EXTERN(void) jsimd_h2v2_extrgbx_merged_upsample_mmx
296
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
297
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
298
EXTERN(void) jsimd_h2v2_extbgr_merged_upsample_mmx
299
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
300
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
301
EXTERN(void) jsimd_h2v2_extbgrx_merged_upsample_mmx
302
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
303
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
304
EXTERN(void) jsimd_h2v2_extxbgr_merged_upsample_mmx
305
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
306
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
307
EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_mmx
308
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
309
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
310
EXTERN(void) jsimd_h2v1_merged_upsample_mmx
311
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
312
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
313
EXTERN(void) jsimd_h2v1_extrgb_merged_upsample_mmx
314
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
315
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
316
EXTERN(void) jsimd_h2v1_extrgbx_merged_upsample_mmx
317
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
318
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
319
EXTERN(void) jsimd_h2v1_extbgr_merged_upsample_mmx
320
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
321
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
322
EXTERN(void) jsimd_h2v1_extbgrx_merged_upsample_mmx
323
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
324
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
325
EXTERN(void) jsimd_h2v1_extxbgr_merged_upsample_mmx
326
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
327
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
328
EXTERN(void) jsimd_h2v1_extxrgb_merged_upsample_mmx
329
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
330
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
331
332
EXTERN(void) jsimd_h2v2_upsample_sse2
333
        JPP((int max_v_samp_factor, JDIMENSION output_width,
334
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
335
EXTERN(void) jsimd_h2v1_upsample_sse2
336
        JPP((int max_v_samp_factor, JDIMENSION output_width,
337
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
338
339
extern const int jconst_fancy_upsample_sse2[];
340
EXTERN(void) jsimd_h2v2_fancy_upsample_sse2
341
        JPP((int max_v_samp_factor, JDIMENSION downsampled_width,
342
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
343
EXTERN(void) jsimd_h2v1_fancy_upsample_sse2
344
        JPP((int max_v_samp_factor, JDIMENSION downsampled_width,
345
             JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
346
347
extern const int jconst_merged_upsample_sse2[];
348
EXTERN(void) jsimd_h2v2_merged_upsample_sse2
349
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
350
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
351
EXTERN(void) jsimd_h2v2_extrgb_merged_upsample_sse2
352
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
353
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
354
EXTERN(void) jsimd_h2v2_extrgbx_merged_upsample_sse2
355
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
356
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
357
EXTERN(void) jsimd_h2v2_extbgr_merged_upsample_sse2
358
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
359
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
360
EXTERN(void) jsimd_h2v2_extbgrx_merged_upsample_sse2
361
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
362
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
363
EXTERN(void) jsimd_h2v2_extxbgr_merged_upsample_sse2
364
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
365
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
366
EXTERN(void) jsimd_h2v2_extxrgb_merged_upsample_sse2
367
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
368
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
369
EXTERN(void) jsimd_h2v1_merged_upsample_sse2
370
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
371
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
372
EXTERN(void) jsimd_h2v1_extrgb_merged_upsample_sse2
373
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
374
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
375
EXTERN(void) jsimd_h2v1_extrgbx_merged_upsample_sse2
376
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
377
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
378
EXTERN(void) jsimd_h2v1_extbgr_merged_upsample_sse2
379
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
380
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
381
EXTERN(void) jsimd_h2v1_extbgrx_merged_upsample_sse2
382
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
383
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
384
EXTERN(void) jsimd_h2v1_extxbgr_merged_upsample_sse2
385
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
386
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
387
EXTERN(void) jsimd_h2v1_extxrgb_merged_upsample_sse2
388
        JPP((JDIMENSION output_width, JSAMPIMAGE input_buf,
389
             JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf));
390
391
/* SIMD Sample Conversion */
392
EXTERN(void) jsimd_convsamp_mmx JPP((JSAMPARRAY sample_data,
393
                                     JDIMENSION start_col,
394
                                     DCTELEM * workspace));
395
396
EXTERN(void) jsimd_convsamp_sse2 JPP((JSAMPARRAY sample_data,
397
                                      JDIMENSION start_col,
398
                                      DCTELEM * workspace));
399
400
EXTERN(void) jsimd_convsamp_float_3dnow JPP((JSAMPARRAY sample_data,
401
                                             JDIMENSION start_col,
402
                                             FAST_FLOAT * workspace));
403
404
EXTERN(void) jsimd_convsamp_float_sse JPP((JSAMPARRAY sample_data,
405
                                           JDIMENSION start_col,
406
                                           FAST_FLOAT * workspace));
407
408
EXTERN(void) jsimd_convsamp_float_sse2 JPP((JSAMPARRAY sample_data,
409
                                            JDIMENSION start_col,
410
                                            FAST_FLOAT * workspace));
411
412
/* SIMD Forward DCT */
413
EXTERN(void) jsimd_fdct_islow_mmx JPP((DCTELEM * data));
414
EXTERN(void) jsimd_fdct_ifast_mmx JPP((DCTELEM * data));
415
416
extern const int jconst_fdct_ifast_sse2[];
417
EXTERN(void) jsimd_fdct_islow_sse2 JPP((DCTELEM * data));
418
extern const int jconst_fdct_islow_sse2[];
419
EXTERN(void) jsimd_fdct_ifast_sse2 JPP((DCTELEM * data));
420
421
EXTERN(void) jsimd_fdct_float_3dnow JPP((FAST_FLOAT * data));
422
423
extern const int jconst_fdct_float_sse[];
424
EXTERN(void) jsimd_fdct_float_sse JPP((FAST_FLOAT * data));
425
426
/* SIMD Quantization */
427
EXTERN(void) jsimd_quantize_mmx JPP((JCOEFPTR coef_block,
428
                                     DCTELEM * divisors,
429
                                     DCTELEM * workspace));
430
431
EXTERN(void) jsimd_quantize_sse2 JPP((JCOEFPTR coef_block,
432
                                      DCTELEM * divisors,
433
                                      DCTELEM * workspace));
434
435
EXTERN(void) jsimd_quantize_float_3dnow JPP((JCOEFPTR coef_block,
436
                                             FAST_FLOAT * divisors,
437
                                             FAST_FLOAT * workspace));
438
439
EXTERN(void) jsimd_quantize_float_sse JPP((JCOEFPTR coef_block,
440
                                           FAST_FLOAT * divisors,
441
                                           FAST_FLOAT * workspace));
442
443
EXTERN(void) jsimd_quantize_float_sse2 JPP((JCOEFPTR coef_block,
444
                                            FAST_FLOAT * divisors,
445
                                            FAST_FLOAT * workspace));
446
447
/* SIMD Reduced Inverse DCT */
448
EXTERN(void) jsimd_idct_2x2_mmx JPP((void * dct_table,
449
                                     JCOEFPTR coef_block,
450
                                     JSAMPARRAY output_buf,
451
                                     JDIMENSION output_col));
452
EXTERN(void) jsimd_idct_4x4_mmx JPP((void * dct_table,
453
                                     JCOEFPTR coef_block,
454
                                     JSAMPARRAY output_buf,
455
                                     JDIMENSION output_col));
456
457
extern const int jconst_idct_red_sse2[];
458
EXTERN(void) jsimd_idct_2x2_sse2 JPP((void * dct_table,
459
                                      JCOEFPTR coef_block,
460
                                      JSAMPARRAY output_buf,
461
                                      JDIMENSION output_col));
462
EXTERN(void) jsimd_idct_4x4_sse2 JPP((void * dct_table,
463
                                      JCOEFPTR coef_block,
464
                                      JSAMPARRAY output_buf,
465
                                      JDIMENSION output_col));
466
467
/* SIMD Inverse DCT */
468
EXTERN(void) jsimd_idct_islow_mmx JPP((void * dct_table,
469
                                       JCOEFPTR coef_block,
470
                                       JSAMPARRAY output_buf,
471
                                       JDIMENSION output_col));
472
EXTERN(void) jsimd_idct_ifast_mmx JPP((void * dct_table,
473
                                       JCOEFPTR coef_block,
474
                                       JSAMPARRAY output_buf,
475
                                       JDIMENSION output_col));
476
477
extern const int jconst_idct_islow_sse2[];
478
EXTERN(void) jsimd_idct_islow_sse2 JPP((void * dct_table,
479
                                        JCOEFPTR coef_block,
480
                                        JSAMPARRAY output_buf,
481
                                        JDIMENSION output_col));
482
extern const int jconst_idct_ifast_sse2[];
483
EXTERN(void) jsimd_idct_ifast_sse2 JPP((void * dct_table,
484
                                        JCOEFPTR coef_block,
485
                                        JSAMPARRAY output_buf,
486
                                        JDIMENSION output_col));
487
488
EXTERN(void) jsimd_idct_float_3dnow JPP((void * dct_table,
489
                                         JCOEFPTR coef_block,
490
                                         JSAMPARRAY output_buf,
491
                                         JDIMENSION output_col));
492
493
extern const int jconst_idct_float_sse[];
494
EXTERN(void) jsimd_idct_float_sse JPP((void * dct_table,
495
                                       JCOEFPTR coef_block,
496
                                       JSAMPARRAY output_buf,
497
                                       JDIMENSION output_col));
498
499
extern const int jconst_idct_float_sse2[];
500
EXTERN(void) jsimd_idct_float_sse2 JPP((void * dct_table,
501
                                        JCOEFPTR coef_block,
502
                                        JSAMPARRAY output_buf,
503
                                        JDIMENSION output_col));
504
(-)a/jpeg/simd/jsimd_i386.c (+957 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * jsimd_i386.c
3
 *
4
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
 * Copyright 2009 D. R. Commander
6
 * 
7
 * Based on the x86 SIMD extension for IJG JPEG library,
8
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
9
 * For conditions of distribution and use, see copyright notice in jsimdext.inc
10
 *
11
 * This file contains the interface between the "normal" portions
12
 * of the library and the SIMD implementations when running on a
13
 * 32-bit x86 architecture.
14
 */
15
16
#define JPEG_INTERNALS
17
#include "../jinclude.h"
18
#include "../jpeglib.h"
19
#include "../jsimd.h"
20
#include "../jdct.h"
21
#include "../jsimddct.h"
22
#include "jsimd.h"
23
24
/*
25
 * In the PIC cases, we have no guarantee that constants will keep
26
 * their alignment. This macro allows us to verify it at runtime.
27
 */
28
#define IS_ALIGNED(ptr, order) (((unsigned)ptr & ((1 << order) - 1)) == 0)
29
30
#define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */
31
32
static unsigned int simd_support = ~0;
33
34
/*
35
 * Check what SIMD accelerations are supported.
36
 *
37
 * FIXME: This code is racy under a multi-threaded environment.
38
 */
39
LOCAL(void)
40
init_simd (void)
41
{
42
  char *env = NULL;
43
44
  if (simd_support != ~0)
45
    return;
46
47
  simd_support = jpeg_simd_cpu_support();
48
49
  /* Force different settings through environment variables */
50
  env = getenv("JSIMD_FORCEMMX");
51
  if ((env != NULL) && (strcmp(env, "1") == 0))
52
    simd_support &= JSIMD_MMX;
53
  env = getenv("JSIMD_FORCE3DNOW");
54
  if ((env != NULL) && (strcmp(env, "1") == 0))
55
    simd_support &= JSIMD_3DNOW|JSIMD_MMX;
56
  env = getenv("JSIMD_FORCESSE");
57
  if ((env != NULL) && (strcmp(env, "1") == 0))
58
    simd_support &= JSIMD_SSE|JSIMD_MMX;
59
  env = getenv("JSIMD_FORCESSE2");
60
  if ((env != NULL) && (strcmp(env, "1") == 0))
61
    simd_support &= JSIMD_SSE2;
62
}
63
64
GLOBAL(int)
65
jsimd_can_rgb_ycc (void)
66
{
67
  init_simd();
68
69
  /* The code is optimised for these values only */
70
  if (BITS_IN_JSAMPLE != 8)
71
    return 0;
72
  if (sizeof(JDIMENSION) != 4)
73
    return 0;
74
  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
75
    return 0;
76
77
  if ((simd_support & JSIMD_SSE2) &&
78
      IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2))
79
    return 1;
80
  if (simd_support & JSIMD_MMX)
81
    return 1;
82
83
  return 0;
84
}
85
86
GLOBAL(int)
87
jsimd_can_ycc_rgb (void)
88
{
89
  init_simd();
90
91
  /* The code is optimised for these values only */
92
  if (BITS_IN_JSAMPLE != 8)
93
    return 0;
94
  if (sizeof(JDIMENSION) != 4)
95
    return 0;
96
  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
97
    return 0;
98
99
  if ((simd_support & JSIMD_SSE2) &&
100
      IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2))
101
    return 1;
102
  if (simd_support & JSIMD_MMX)
103
    return 1;
104
105
  return 0;
106
}
107
108
GLOBAL(void)
109
jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
110
                       JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
111
                       JDIMENSION output_row, int num_rows)
112
{
113
  void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
114
  void (*mmxfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
115
116
  switch(cinfo->in_color_space)
117
  {
118
    case JCS_EXT_RGB:
119
      sse2fct=jsimd_extrgb_ycc_convert_sse2;
120
      mmxfct=jsimd_extrgb_ycc_convert_mmx;
121
      break;
122
    case JCS_EXT_RGBX:
123
      sse2fct=jsimd_extrgbx_ycc_convert_sse2;
124
      mmxfct=jsimd_extrgbx_ycc_convert_mmx;
125
      break;
126
    case JCS_EXT_BGR:
127
      sse2fct=jsimd_extbgr_ycc_convert_sse2;
128
      mmxfct=jsimd_extbgr_ycc_convert_mmx;
129
      break;
130
    case JCS_EXT_BGRX:
131
      sse2fct=jsimd_extbgrx_ycc_convert_sse2;
132
      mmxfct=jsimd_extbgrx_ycc_convert_mmx;
133
      break;
134
    case JCS_EXT_XBGR:
135
      sse2fct=jsimd_extxbgr_ycc_convert_sse2;
136
      mmxfct=jsimd_extxbgr_ycc_convert_mmx;
137
      break;
138
    case JCS_EXT_XRGB:
139
      sse2fct=jsimd_extxrgb_ycc_convert_sse2;
140
      mmxfct=jsimd_extxrgb_ycc_convert_mmx;
141
      break;
142
    default:
143
      sse2fct=jsimd_rgb_ycc_convert_sse2;
144
      mmxfct=jsimd_rgb_ycc_convert_mmx;
145
      break;
146
  }
147
148
  if ((simd_support & JSIMD_SSE2) &&
149
      IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2))
150
    sse2fct(cinfo->image_width, input_buf,
151
        output_buf, output_row, num_rows);
152
  else if (simd_support & JSIMD_MMX)
153
    mmxfct(cinfo->image_width, input_buf,
154
        output_buf, output_row, num_rows);
155
}
156
157
GLOBAL(void)
158
jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
159
                       JSAMPIMAGE input_buf, JDIMENSION input_row,
160
                       JSAMPARRAY output_buf, int num_rows)
161
{
162
  void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
163
  void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
164
165
  switch(cinfo->out_color_space)
166
  {
167
    case JCS_EXT_RGB:
168
      sse2fct=jsimd_ycc_extrgb_convert_sse2;
169
      mmxfct=jsimd_ycc_extrgb_convert_mmx;
170
      break;
171
    case JCS_EXT_RGBX:
172
      sse2fct=jsimd_ycc_extrgbx_convert_sse2;
173
      mmxfct=jsimd_ycc_extrgbx_convert_mmx;
174
      break;
175
    case JCS_EXT_BGR:
176
      sse2fct=jsimd_ycc_extbgr_convert_sse2;
177
      mmxfct=jsimd_ycc_extbgr_convert_mmx;
178
      break;
179
    case JCS_EXT_BGRX:
180
      sse2fct=jsimd_ycc_extbgrx_convert_sse2;
181
      mmxfct=jsimd_ycc_extbgrx_convert_mmx;
182
      break;
183
    case JCS_EXT_XBGR:
184
      sse2fct=jsimd_ycc_extxbgr_convert_sse2;
185
      mmxfct=jsimd_ycc_extxbgr_convert_mmx;
186
      break;
187
    case JCS_EXT_XRGB:
188
      sse2fct=jsimd_ycc_extxrgb_convert_sse2;
189
      mmxfct=jsimd_ycc_extxrgb_convert_mmx;
190
      break;
191
    default:
192
      sse2fct=jsimd_ycc_rgb_convert_sse2;
193
      mmxfct=jsimd_ycc_rgb_convert_mmx;
194
      break;
195
  }
196
197
  if ((simd_support & JSIMD_SSE2) &&
198
      IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2))
199
    sse2fct(cinfo->output_width, input_buf,
200
        input_row, output_buf, num_rows);
201
  else if (simd_support & JSIMD_MMX)
202
    mmxfct(cinfo->output_width, input_buf,
203
        input_row, output_buf, num_rows);
204
}
205
206
GLOBAL(int)
207
jsimd_can_h2v2_downsample (void)
208
{
209
  init_simd();
210
211
  /* The code is optimised for these values only */
212
  if (BITS_IN_JSAMPLE != 8)
213
    return 0;
214
  if (sizeof(JDIMENSION) != 4)
215
    return 0;
216
217
  if (simd_support & JSIMD_SSE2)
218
    return 1;
219
  if (simd_support & JSIMD_MMX)
220
    return 1;
221
222
  return 0;
223
}
224
225
GLOBAL(int)
226
jsimd_can_h2v1_downsample (void)
227
{
228
  init_simd();
229
230
  /* The code is optimised for these values only */
231
  if (BITS_IN_JSAMPLE != 8)
232
    return 0;
233
  if (sizeof(JDIMENSION) != 4)
234
    return 0;
235
236
  if (simd_support & JSIMD_SSE2)
237
    return 1;
238
  if (simd_support & JSIMD_MMX)
239
    return 1;
240
241
  return 0;
242
}
243
244
GLOBAL(void)
245
jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
246
                       JSAMPARRAY input_data, JSAMPARRAY output_data)
247
{
248
  if (simd_support & JSIMD_SSE2)
249
    jsimd_h2v2_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
250
        compptr->v_samp_factor, compptr->width_in_blocks,
251
        input_data, output_data);
252
  else if (simd_support & JSIMD_MMX)
253
    jsimd_h2v2_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor,
254
        compptr->v_samp_factor, compptr->width_in_blocks,
255
        input_data, output_data);
256
}
257
258
GLOBAL(void)
259
jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
260
                       JSAMPARRAY input_data, JSAMPARRAY output_data)
261
{
262
  if (simd_support & JSIMD_SSE2)
263
    jsimd_h2v1_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
264
        compptr->v_samp_factor, compptr->width_in_blocks,
265
        input_data, output_data);
266
  else if (simd_support & JSIMD_MMX)
267
    jsimd_h2v1_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor,
268
        compptr->v_samp_factor, compptr->width_in_blocks,
269
        input_data, output_data);
270
}
271
272
GLOBAL(int)
273
jsimd_can_h2v2_upsample (void)
274
{
275
  init_simd();
276
277
  /* The code is optimised for these values only */
278
  if (BITS_IN_JSAMPLE != 8)
279
    return 0;
280
  if (sizeof(JDIMENSION) != 4)
281
    return 0;
282
283
  if (simd_support & JSIMD_SSE2)
284
    return 1;
285
  if (simd_support & JSIMD_MMX)
286
    return 1;
287
288
  return 0;
289
}
290
291
GLOBAL(int)
292
jsimd_can_h2v1_upsample (void)
293
{
294
  init_simd();
295
296
  /* The code is optimised for these values only */
297
  if (BITS_IN_JSAMPLE != 8)
298
    return 0;
299
  if (sizeof(JDIMENSION) != 4)
300
    return 0;
301
302
  if (simd_support & JSIMD_SSE2)
303
    return 1;
304
  if (simd_support & JSIMD_MMX)
305
    return 1;
306
307
  return 0;
308
}
309
310
GLOBAL(void)
311
jsimd_h2v2_upsample (j_decompress_ptr cinfo,
312
                     jpeg_component_info * compptr, 
313
                     JSAMPARRAY input_data,
314
                     JSAMPARRAY * output_data_ptr)
315
{
316
  if (simd_support & JSIMD_SSE2)
317
    jsimd_h2v2_upsample_sse2(cinfo->max_v_samp_factor,
318
        cinfo->output_width, input_data, output_data_ptr);
319
  else if (simd_support & JSIMD_MMX)
320
    jsimd_h2v2_upsample_mmx(cinfo->max_v_samp_factor,
321
        cinfo->output_width, input_data, output_data_ptr);
322
}
323
324
GLOBAL(void)
325
jsimd_h2v1_upsample (j_decompress_ptr cinfo,
326
                     jpeg_component_info * compptr, 
327
                     JSAMPARRAY input_data,
328
                     JSAMPARRAY * output_data_ptr)
329
{
330
  if (simd_support & JSIMD_SSE2)
331
    jsimd_h2v1_upsample_sse2(cinfo->max_v_samp_factor,
332
        cinfo->output_width, input_data, output_data_ptr);
333
  else if (simd_support & JSIMD_MMX)
334
    jsimd_h2v1_upsample_mmx(cinfo->max_v_samp_factor,
335
        cinfo->output_width, input_data, output_data_ptr);
336
}
337
338
GLOBAL(int)
339
jsimd_can_h2v2_fancy_upsample (void)
340
{
341
  init_simd();
342
343
  /* The code is optimised for these values only */
344
  if (BITS_IN_JSAMPLE != 8)
345
    return 0;
346
  if (sizeof(JDIMENSION) != 4)
347
    return 0;
348
349
  if ((simd_support & JSIMD_SSE2) &&
350
      IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
351
    return 1;
352
  if (simd_support & JSIMD_MMX)
353
    return 1;
354
355
  return 0;
356
}
357
358
GLOBAL(int)
359
jsimd_can_h2v1_fancy_upsample (void)
360
{
361
  init_simd();
362
363
  /* The code is optimised for these values only */
364
  if (BITS_IN_JSAMPLE != 8)
365
    return 0;
366
  if (sizeof(JDIMENSION) != 4)
367
    return 0;
368
369
  if ((simd_support & JSIMD_SSE2) &&
370
      IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
371
    return 1;
372
  if (simd_support & JSIMD_MMX)
373
    return 1;
374
375
  return 0;
376
}
377
378
GLOBAL(void)
379
jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
380
                           jpeg_component_info * compptr, 
381
                           JSAMPARRAY input_data,
382
                           JSAMPARRAY * output_data_ptr)
383
{
384
  if ((simd_support & JSIMD_SSE2) &&
385
      IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
386
    jsimd_h2v2_fancy_upsample_sse2(cinfo->max_v_samp_factor,
387
        compptr->downsampled_width, input_data, output_data_ptr);
388
  else if (simd_support & JSIMD_MMX)
389
    jsimd_h2v2_fancy_upsample_mmx(cinfo->max_v_samp_factor,
390
        compptr->downsampled_width, input_data, output_data_ptr);
391
}
392
393
GLOBAL(void)
394
jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
395
                           jpeg_component_info * compptr, 
396
                           JSAMPARRAY input_data,
397
                           JSAMPARRAY * output_data_ptr)
398
{
399
  if ((simd_support & JSIMD_SSE2) &&
400
      IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
401
    jsimd_h2v1_fancy_upsample_sse2(cinfo->max_v_samp_factor,
402
        compptr->downsampled_width, input_data, output_data_ptr);
403
  else if (simd_support & JSIMD_MMX)
404
    jsimd_h2v1_fancy_upsample_mmx(cinfo->max_v_samp_factor,
405
        compptr->downsampled_width, input_data, output_data_ptr);
406
}
407
408
GLOBAL(int)
409
jsimd_can_h2v2_merged_upsample (void)
410
{
411
  init_simd();
412
413
  /* The code is optimised for these values only */
414
  if (BITS_IN_JSAMPLE != 8)
415
    return 0;
416
  if (sizeof(JDIMENSION) != 4)
417
    return 0;
418
419
  if ((simd_support & JSIMD_SSE2) &&
420
      IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
421
    return 1;
422
  if (simd_support & JSIMD_MMX)
423
    return 1;
424
425
  return 0;
426
}
427
428
GLOBAL(int)
429
jsimd_can_h2v1_merged_upsample (void)
430
{
431
  init_simd();
432
433
  /* The code is optimised for these values only */
434
  if (BITS_IN_JSAMPLE != 8)
435
    return 0;
436
  if (sizeof(JDIMENSION) != 4)
437
    return 0;
438
439
  if ((simd_support & JSIMD_SSE2) &&
440
      IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
441
    return 1;
442
  if (simd_support & JSIMD_MMX)
443
    return 1;
444
445
  return 0;
446
}
447
448
GLOBAL(void)
449
jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
450
                            JSAMPIMAGE input_buf,
451
                            JDIMENSION in_row_group_ctr,
452
                            JSAMPARRAY output_buf)
453
{
454
  void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
455
  void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
456
457
  switch(cinfo->out_color_space)
458
  {
459
    case JCS_EXT_RGB:
460
      sse2fct=jsimd_h2v2_extrgb_merged_upsample_sse2;
461
      mmxfct=jsimd_h2v2_extrgb_merged_upsample_mmx;
462
      break;
463
    case JCS_EXT_RGBX:
464
      sse2fct=jsimd_h2v2_extrgbx_merged_upsample_sse2;
465
      mmxfct=jsimd_h2v2_extrgbx_merged_upsample_mmx;
466
      break;
467
    case JCS_EXT_BGR:
468
      sse2fct=jsimd_h2v2_extbgr_merged_upsample_sse2;
469
      mmxfct=jsimd_h2v2_extbgr_merged_upsample_mmx;
470
      break;
471
    case JCS_EXT_BGRX:
472
      sse2fct=jsimd_h2v2_extbgrx_merged_upsample_sse2;
473
      mmxfct=jsimd_h2v2_extbgrx_merged_upsample_mmx;
474
      break;
475
    case JCS_EXT_XBGR:
476
      sse2fct=jsimd_h2v2_extxbgr_merged_upsample_sse2;
477
      mmxfct=jsimd_h2v2_extxbgr_merged_upsample_mmx;
478
      break;
479
    case JCS_EXT_XRGB:
480
      sse2fct=jsimd_h2v2_extxrgb_merged_upsample_sse2;
481
      mmxfct=jsimd_h2v2_extxrgb_merged_upsample_mmx;
482
      break;
483
    default:
484
      sse2fct=jsimd_h2v2_merged_upsample_sse2;
485
      mmxfct=jsimd_h2v2_merged_upsample_mmx;
486
      break;
487
  }
488
489
  if ((simd_support & JSIMD_SSE2) &&
490
      IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
491
    sse2fct(cinfo->output_width, input_buf,
492
        in_row_group_ctr, output_buf);
493
  else if (simd_support & JSIMD_MMX)
494
    mmxfct(cinfo->output_width, input_buf,
495
        in_row_group_ctr, output_buf);
496
}
497
498
GLOBAL(void)
499
jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
500
                            JSAMPIMAGE input_buf,
501
                            JDIMENSION in_row_group_ctr,
502
                            JSAMPARRAY output_buf)
503
{
504
  void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
505
  void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
506
507
  switch(cinfo->out_color_space)
508
  {
509
    case JCS_EXT_RGB:
510
      sse2fct=jsimd_h2v1_extrgb_merged_upsample_sse2;
511
      mmxfct=jsimd_h2v1_extrgb_merged_upsample_mmx;
512
      break;
513
    case JCS_EXT_RGBX:
514
      sse2fct=jsimd_h2v1_extrgbx_merged_upsample_sse2;
515
      mmxfct=jsimd_h2v1_extrgbx_merged_upsample_mmx;
516
      break;
517
    case JCS_EXT_BGR:
518
      sse2fct=jsimd_h2v1_extbgr_merged_upsample_sse2;
519
      mmxfct=jsimd_h2v1_extbgr_merged_upsample_mmx;
520
      break;
521
    case JCS_EXT_BGRX:
522
      sse2fct=jsimd_h2v1_extbgrx_merged_upsample_sse2;
523
      mmxfct=jsimd_h2v1_extbgrx_merged_upsample_mmx;
524
      break;
525
    case JCS_EXT_XBGR:
526
      sse2fct=jsimd_h2v1_extxbgr_merged_upsample_sse2;
527
      mmxfct=jsimd_h2v1_extxbgr_merged_upsample_mmx;
528
      break;
529
    case JCS_EXT_XRGB:
530
      sse2fct=jsimd_h2v1_extxrgb_merged_upsample_sse2;
531
      mmxfct=jsimd_h2v1_extxrgb_merged_upsample_mmx;
532
      break;
533
    default:
534
      sse2fct=jsimd_h2v1_merged_upsample_sse2;
535
      mmxfct=jsimd_h2v1_merged_upsample_mmx;
536
      break;
537
  }
538
539
  if ((simd_support & JSIMD_SSE2) &&
540
      IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
541
    sse2fct(cinfo->output_width, input_buf,
542
        in_row_group_ctr, output_buf);
543
  else if (simd_support & JSIMD_MMX)
544
    mmxfct(cinfo->output_width, input_buf,
545
        in_row_group_ctr, output_buf);
546
}
547
548
GLOBAL(int)
549
jsimd_can_convsamp (void)
550
{
551
  init_simd();
552
553
  /* The code is optimised for these values only */
554
  if (DCTSIZE != 8)
555
    return 0;
556
  if (BITS_IN_JSAMPLE != 8)
557
    return 0;
558
  if (sizeof(JDIMENSION) != 4)
559
    return 0;
560
  if (sizeof(DCTELEM) != 2)
561
    return 0;
562
563
  if (simd_support & JSIMD_SSE2)
564
    return 1;
565
  if (simd_support & JSIMD_MMX)
566
    return 1;
567
568
  return 0;
569
}
570
571
GLOBAL(int)
572
jsimd_can_convsamp_float (void)
573
{
574
  init_simd();
575
576
  /* The code is optimised for these values only */
577
  if (DCTSIZE != 8)
578
    return 0;
579
  if (BITS_IN_JSAMPLE != 8)
580
    return 0;
581
  if (sizeof(JDIMENSION) != 4)
582
    return 0;
583
  if (sizeof(FAST_FLOAT) != 4)
584
    return 0;
585
586
  if (simd_support & JSIMD_SSE2)
587
    return 1;
588
  if (simd_support & JSIMD_SSE)
589
    return 1;
590
  if (simd_support & JSIMD_3DNOW)
591
    return 1;
592
593
  return 0;
594
}
595
596
GLOBAL(void)
597
jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
598
                DCTELEM * workspace)
599
{
600
  if (simd_support & JSIMD_SSE2)
601
    jsimd_convsamp_sse2(sample_data, start_col, workspace);
602
  else if (simd_support & JSIMD_MMX)
603
    jsimd_convsamp_mmx(sample_data, start_col, workspace);
604
}
605
606
GLOBAL(void)
607
jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
608
                      FAST_FLOAT * workspace)
609
{
610
  if (simd_support & JSIMD_SSE2)
611
    jsimd_convsamp_float_sse2(sample_data, start_col, workspace);
612
  else if (simd_support & JSIMD_SSE)
613
    jsimd_convsamp_float_sse(sample_data, start_col, workspace);
614
  else if (simd_support & JSIMD_3DNOW)
615
    jsimd_convsamp_float_3dnow(sample_data, start_col, workspace);
616
}
617
618
GLOBAL(int)
619
jsimd_can_fdct_islow (void)
620
{
621
  init_simd();
622
623
  /* The code is optimised for these values only */
624
  if (DCTSIZE != 8)
625
    return 0;
626
  if (sizeof(DCTELEM) != 2)
627
    return 0;
628
629
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
630
    return 1;
631
  if (simd_support & JSIMD_MMX)
632
    return 1;
633
634
  return 0;
635
}
636
637
GLOBAL(int)
638
jsimd_can_fdct_ifast (void)
639
{
640
  init_simd();
641
642
  /* The code is optimised for these values only */
643
  if (DCTSIZE != 8)
644
    return 0;
645
  if (sizeof(DCTELEM) != 2)
646
    return 0;
647
648
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_ifast_sse2))
649
    return 1;
650
  if (simd_support & JSIMD_MMX)
651
    return 1;
652
653
  return 0;
654
}
655
656
GLOBAL(int)
657
jsimd_can_fdct_float (void)
658
{
659
  init_simd();
660
661
  /* The code is optimised for these values only */
662
  if (DCTSIZE != 8)
663
    return 0;
664
  if (sizeof(FAST_FLOAT) != 4)
665
    return 0;
666
667
  if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse))
668
    return 1;
669
  if (simd_support & JSIMD_3DNOW)
670
    return 1;
671
672
  return 0;
673
}
674
675
GLOBAL(void)
676
jsimd_fdct_islow (DCTELEM * data)
677
{
678
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
679
    jsimd_fdct_islow_sse2(data);
680
  else if (simd_support & JSIMD_MMX)
681
    jsimd_fdct_islow_mmx(data);
682
}
683
684
GLOBAL(void)
685
jsimd_fdct_ifast (DCTELEM * data)
686
{
687
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
688
    jsimd_fdct_ifast_sse2(data);
689
  else if (simd_support & JSIMD_MMX)
690
    jsimd_fdct_ifast_mmx(data);
691
}
692
693
GLOBAL(void)
694
jsimd_fdct_float (FAST_FLOAT * data)
695
{
696
  if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse))
697
    jsimd_fdct_float_sse(data);
698
  else if (simd_support & JSIMD_3DNOW)
699
    jsimd_fdct_float_3dnow(data);
700
}
701
702
GLOBAL(int)
703
jsimd_can_quantize (void)
704
{
705
  init_simd();
706
707
  /* The code is optimised for these values only */
708
  if (DCTSIZE != 8)
709
    return 0;
710
  if (sizeof(JCOEF) != 2)
711
    return 0;
712
  if (sizeof(DCTELEM) != 2)
713
    return 0;
714
715
  if (simd_support & JSIMD_SSE2)
716
    return 1;
717
  if (simd_support & JSIMD_MMX)
718
    return 1;
719
720
  return 0;
721
}
722
723
GLOBAL(int)
724
jsimd_can_quantize_float (void)
725
{
726
  init_simd();
727
728
  /* The code is optimised for these values only */
729
  if (DCTSIZE != 8)
730
    return 0;
731
  if (sizeof(JCOEF) != 2)
732
    return 0;
733
  if (sizeof(FAST_FLOAT) != 4)
734
    return 0;
735
736
  if (simd_support & JSIMD_SSE2)
737
    return 1;
738
  if (simd_support & JSIMD_SSE)
739
    return 1;
740
  if (simd_support & JSIMD_3DNOW)
741
    return 1;
742
743
  return 0;
744
}
745
746
GLOBAL(void)
747
jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
748
                DCTELEM * workspace)
749
{
750
  if (simd_support & JSIMD_SSE2)
751
    jsimd_quantize_sse2(coef_block, divisors, workspace);
752
  else if (simd_support & JSIMD_MMX)
753
    jsimd_quantize_mmx(coef_block, divisors, workspace);
754
}
755
756
GLOBAL(void)
757
jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
758
                      FAST_FLOAT * workspace)
759
{
760
  if (simd_support & JSIMD_SSE2)
761
    jsimd_quantize_float_sse2(coef_block, divisors, workspace);
762
  else if (simd_support & JSIMD_SSE)
763
    jsimd_quantize_float_sse(coef_block, divisors, workspace);
764
  else if (simd_support & JSIMD_3DNOW)
765
    jsimd_quantize_float_3dnow(coef_block, divisors, workspace);
766
}
767
768
GLOBAL(int)
769
jsimd_can_idct_2x2 (void)
770
{
771
  init_simd();
772
773
  /* The code is optimised for these values only */
774
  if (DCTSIZE != 8)
775
    return 0;
776
  if (sizeof(JCOEF) != 2)
777
    return 0;
778
  if (BITS_IN_JSAMPLE != 8)
779
    return 0;
780
  if (sizeof(JDIMENSION) != 4)
781
    return 0;
782
  if (sizeof(ISLOW_MULT_TYPE) != 2)
783
    return 0;
784
785
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
786
    return 1;
787
  if (simd_support & JSIMD_MMX)
788
    return 1;
789
790
  return 0;
791
}
792
793
GLOBAL(int)
794
jsimd_can_idct_4x4 (void)
795
{
796
  init_simd();
797
798
  /* The code is optimised for these values only */
799
  if (DCTSIZE != 8)
800
    return 0;
801
  if (sizeof(JCOEF) != 2)
802
    return 0;
803
  if (BITS_IN_JSAMPLE != 8)
804
    return 0;
805
  if (sizeof(JDIMENSION) != 4)
806
    return 0;
807
  if (sizeof(ISLOW_MULT_TYPE) != 2)
808
    return 0;
809
810
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
811
    return 1;
812
  if (simd_support & JSIMD_MMX)
813
    return 1;
814
815
  return 0;
816
}
817
818
GLOBAL(void)
819
jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
820
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
821
                JDIMENSION output_col)
822
{
823
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
824
    jsimd_idct_2x2_sse2(compptr->dct_table, coef_block, output_buf, output_col);
825
  else if (simd_support & JSIMD_MMX)
826
    jsimd_idct_2x2_mmx(compptr->dct_table, coef_block, output_buf, output_col);
827
}
828
829
GLOBAL(void)
830
jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
831
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
832
                JDIMENSION output_col)
833
{
834
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
835
    jsimd_idct_4x4_sse2(compptr->dct_table, coef_block, output_buf, output_col);
836
  else if (simd_support & JSIMD_MMX)
837
    jsimd_idct_4x4_mmx(compptr->dct_table, coef_block, output_buf, output_col);
838
}
839
840
GLOBAL(int)
841
jsimd_can_idct_islow (void)
842
{
843
  init_simd();
844
845
  /* The code is optimised for these values only */
846
  if (DCTSIZE != 8)
847
    return 0;
848
  if (sizeof(JCOEF) != 2)
849
    return 0;
850
  if (BITS_IN_JSAMPLE != 8)
851
    return 0;
852
  if (sizeof(JDIMENSION) != 4)
853
    return 0;
854
  if (sizeof(ISLOW_MULT_TYPE) != 2)
855
    return 0;
856
857
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_islow_sse2))
858
    return 1;
859
  if (simd_support & JSIMD_MMX)
860
    return 1;
861
862
  return 0;
863
}
864
865
GLOBAL(int)
866
jsimd_can_idct_ifast (void)
867
{
868
  init_simd();
869
870
  /* The code is optimised for these values only */
871
  if (DCTSIZE != 8)
872
    return 0;
873
  if (sizeof(JCOEF) != 2)
874
    return 0;
875
  if (BITS_IN_JSAMPLE != 8)
876
    return 0;
877
  if (sizeof(JDIMENSION) != 4)
878
    return 0;
879
  if (sizeof(IFAST_MULT_TYPE) != 2)
880
    return 0;
881
  if (IFAST_SCALE_BITS != 2)
882
    return 0;
883
884
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
885
    return 1;
886
  if (simd_support & JSIMD_MMX)
887
    return 1;
888
889
  return 0;
890
}
891
892
GLOBAL(int)
893
jsimd_can_idct_float (void)
894
{
895
  init_simd();
896
897
  if (DCTSIZE != 8)
898
    return 0;
899
  if (sizeof(JCOEF) != 2)
900
    return 0;
901
  if (BITS_IN_JSAMPLE != 8)
902
    return 0;
903
  if (sizeof(JDIMENSION) != 4)
904
    return 0;
905
  if (sizeof(FAST_FLOAT) != 4)
906
    return 0;
907
  if (sizeof(FLOAT_MULT_TYPE) != 4)
908
    return 0;
909
910
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2))
911
    return 1;
912
  if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse))
913
    return 1;
914
  if (simd_support & JSIMD_3DNOW)
915
    return 1;
916
917
  return 0;
918
}
919
920
GLOBAL(void)
921
jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
922
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
923
                JDIMENSION output_col)
924
{
925
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_islow_sse2))
926
    jsimd_idct_islow_sse2(compptr->dct_table, coef_block, output_buf, output_col);
927
  else if (simd_support & JSIMD_MMX)
928
    jsimd_idct_islow_mmx(compptr->dct_table, coef_block, output_buf, output_col);
929
}
930
931
GLOBAL(void)
932
jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
933
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
934
                JDIMENSION output_col)
935
{
936
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
937
    jsimd_idct_ifast_sse2(compptr->dct_table, coef_block, output_buf, output_col);
938
  else if (simd_support & JSIMD_MMX)
939
    jsimd_idct_ifast_mmx(compptr->dct_table, coef_block, output_buf, output_col);
940
}
941
942
GLOBAL(void)
943
jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
944
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
945
                JDIMENSION output_col)
946
{
947
  if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2))
948
    jsimd_idct_float_sse2(compptr->dct_table, coef_block,
949
        output_buf, output_col);
950
  else if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse))
951
    jsimd_idct_float_sse(compptr->dct_table, coef_block,
952
        output_buf, output_col);
953
  else if (simd_support & JSIMD_3DNOW)
954
    jsimd_idct_float_3dnow(compptr->dct_table, coef_block,
955
        output_buf, output_col);
956
}
957
(-)a/jpeg/simd/jsimd_x86_64.c (+681 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * jsimd_x86_64.c
3
 *
4
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
 * Copyright 2009 D. R. Commander
6
 * 
7
 * Based on the x86 SIMD extension for IJG JPEG library,
8
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
9
 * For conditions of distribution and use, see copyright notice in jsimdext.inc
10
 *
11
 * This file contains the interface between the "normal" portions
12
 * of the library and the SIMD implementations when running on a
13
 * x86_64 architecture.
14
 */
15
16
#define JPEG_INTERNALS
17
#include "../jinclude.h"
18
#include "../jpeglib.h"
19
#include "../jsimd.h"
20
#include "../jdct.h"
21
#include "../jsimddct.h"
22
#include "jsimd.h"
23
24
/*
25
 * In the PIC cases, we have no guarantee that constants will keep
26
 * their alignment. This macro allows us to verify it at runtime.
27
 */
28
#define IS_ALIGNED(ptr, order) (((size_t)ptr & ((1 << order) - 1)) == 0)
29
30
#define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */
31
32
GLOBAL(int)
33
jsimd_can_rgb_ycc (void)
34
{
35
  /* The code is optimised for these values only */
36
  if (BITS_IN_JSAMPLE != 8)
37
    return 0;
38
  if (sizeof(JDIMENSION) != 4)
39
    return 0;
40
  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
41
    return 0;
42
43
  if (!IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2))
44
    return 0;
45
46
  return 1;
47
}
48
49
GLOBAL(int)
50
jsimd_can_ycc_rgb (void)
51
{
52
  /* The code is optimised for these values only */
53
  if (BITS_IN_JSAMPLE != 8)
54
    return 0;
55
  if (sizeof(JDIMENSION) != 4)
56
    return 0;
57
  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
58
    return 0;
59
60
  if (!IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2))
61
    return 0;
62
63
  return 1;
64
}
65
66
GLOBAL(void)
67
jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
68
                       JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
69
                       JDIMENSION output_row, int num_rows)
70
{
71
  void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
72
73
  switch(cinfo->in_color_space)
74
  {
75
    case JCS_EXT_RGB:
76
      sse2fct=jsimd_extrgb_ycc_convert_sse2;
77
      break;
78
    case JCS_EXT_RGBX:
79
      sse2fct=jsimd_extrgbx_ycc_convert_sse2;
80
      break;
81
    case JCS_EXT_BGR:
82
      sse2fct=jsimd_extbgr_ycc_convert_sse2;
83
      break;
84
    case JCS_EXT_BGRX:
85
      sse2fct=jsimd_extbgrx_ycc_convert_sse2;
86
      break;
87
    case JCS_EXT_XBGR:
88
      sse2fct=jsimd_extxbgr_ycc_convert_sse2;
89
      break;
90
    case JCS_EXT_XRGB:
91
      sse2fct=jsimd_extxrgb_ycc_convert_sse2;
92
      break;
93
    default:
94
      sse2fct=jsimd_rgb_ycc_convert_sse2;
95
      break;
96
  }
97
98
  sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
99
}
100
101
GLOBAL(void)
102
jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
103
                       JSAMPIMAGE input_buf, JDIMENSION input_row,
104
                       JSAMPARRAY output_buf, int num_rows)
105
{
106
  void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
107
108
  switch(cinfo->out_color_space)
109
  {
110
    case JCS_EXT_RGB:
111
      sse2fct=jsimd_ycc_extrgb_convert_sse2;
112
      break;
113
    case JCS_EXT_RGBX:
114
      sse2fct=jsimd_ycc_extrgbx_convert_sse2;
115
      break;
116
    case JCS_EXT_BGR:
117
      sse2fct=jsimd_ycc_extbgr_convert_sse2;
118
      break;
119
    case JCS_EXT_BGRX:
120
      sse2fct=jsimd_ycc_extbgrx_convert_sse2;
121
      break;
122
    case JCS_EXT_XBGR:
123
      sse2fct=jsimd_ycc_extxbgr_convert_sse2;
124
      break;
125
    case JCS_EXT_XRGB:
126
      sse2fct=jsimd_ycc_extxrgb_convert_sse2;
127
      break;
128
    default:
129
      sse2fct=jsimd_ycc_rgb_convert_sse2;
130
      break;
131
  }
132
133
  sse2fct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
134
}
135
136
GLOBAL(int)
137
jsimd_can_h2v2_downsample (void)
138
{
139
  /* The code is optimised for these values only */
140
  if (BITS_IN_JSAMPLE != 8)
141
    return 0;
142
  if (sizeof(JDIMENSION) != 4)
143
    return 0;
144
145
  return 1;
146
}
147
148
GLOBAL(int)
149
jsimd_can_h2v1_downsample (void)
150
{
151
  /* The code is optimised for these values only */
152
  if (BITS_IN_JSAMPLE != 8)
153
    return 0;
154
  if (sizeof(JDIMENSION) != 4)
155
    return 0;
156
157
  return 1;
158
}
159
160
GLOBAL(void)
161
jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
162
                       JSAMPARRAY input_data, JSAMPARRAY output_data)
163
{
164
  jsimd_h2v2_downsample_sse2(cinfo->image_width,
165
                             cinfo->max_v_samp_factor,
166
                             compptr->v_samp_factor,
167
                             compptr->width_in_blocks,
168
                             input_data, output_data);
169
}
170
171
GLOBAL(void)
172
jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
173
                       JSAMPARRAY input_data, JSAMPARRAY output_data)
174
{
175
  jsimd_h2v1_downsample_sse2(cinfo->image_width,
176
                             cinfo->max_v_samp_factor,
177
                             compptr->v_samp_factor,
178
                             compptr->width_in_blocks,
179
                             input_data, output_data);
180
}
181
182
GLOBAL(int)
183
jsimd_can_h2v2_upsample (void)
184
{
185
  /* The code is optimised for these values only */
186
  if (BITS_IN_JSAMPLE != 8)
187
    return 0;
188
  if (sizeof(JDIMENSION) != 4)
189
    return 0;
190
191
  return 1;
192
}
193
194
GLOBAL(int)
195
jsimd_can_h2v1_upsample (void)
196
{
197
  /* The code is optimised for these values only */
198
  if (BITS_IN_JSAMPLE != 8)
199
    return 0;
200
  if (sizeof(JDIMENSION) != 4)
201
    return 0;
202
203
  return 1;
204
}
205
206
GLOBAL(void)
207
jsimd_h2v2_upsample (j_decompress_ptr cinfo,
208
                     jpeg_component_info * compptr, 
209
                     JSAMPARRAY input_data,
210
                     JSAMPARRAY * output_data_ptr)
211
{
212
  jsimd_h2v2_upsample_sse2(cinfo->max_v_samp_factor,
213
                           cinfo->output_width,
214
                           input_data, output_data_ptr);
215
}
216
217
GLOBAL(void)
218
jsimd_h2v1_upsample (j_decompress_ptr cinfo,
219
                     jpeg_component_info * compptr, 
220
                     JSAMPARRAY input_data,
221
                     JSAMPARRAY * output_data_ptr)
222
{
223
  jsimd_h2v1_upsample_sse2(cinfo->max_v_samp_factor,
224
                           cinfo->output_width,
225
                           input_data, output_data_ptr);
226
}
227
228
GLOBAL(int)
229
jsimd_can_h2v2_fancy_upsample (void)
230
{
231
  /* The code is optimised for these values only */
232
  if (BITS_IN_JSAMPLE != 8)
233
    return 0;
234
  if (sizeof(JDIMENSION) != 4)
235
    return 0;
236
237
  if (!IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
238
    return 0;
239
240
  return 1;
241
}
242
243
GLOBAL(int)
244
jsimd_can_h2v1_fancy_upsample (void)
245
{
246
  /* The code is optimised for these values only */
247
  if (BITS_IN_JSAMPLE != 8)
248
    return 0;
249
  if (sizeof(JDIMENSION) != 4)
250
    return 0;
251
252
  if (!IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
253
    return 0;
254
255
  return 1;
256
}
257
258
GLOBAL(void)
259
jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
260
                           jpeg_component_info * compptr, 
261
                           JSAMPARRAY input_data,
262
                           JSAMPARRAY * output_data_ptr)
263
{
264
  jsimd_h2v2_fancy_upsample_sse2(cinfo->max_v_samp_factor,
265
                                 compptr->downsampled_width,
266
                                 input_data, output_data_ptr);
267
}
268
269
GLOBAL(void)
270
jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
271
                           jpeg_component_info * compptr, 
272
                           JSAMPARRAY input_data,
273
                           JSAMPARRAY * output_data_ptr)
274
{
275
  jsimd_h2v1_fancy_upsample_sse2(cinfo->max_v_samp_factor,
276
                                 compptr->downsampled_width,
277
                                 input_data, output_data_ptr);
278
}
279
280
GLOBAL(int)
281
jsimd_can_h2v2_merged_upsample (void)
282
{
283
  /* The code is optimised for these values only */
284
  if (BITS_IN_JSAMPLE != 8)
285
    return 0;
286
  if (sizeof(JDIMENSION) != 4)
287
    return 0;
288
289
  if (!IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
290
    return 0;
291
292
  return 1;
293
}
294
295
GLOBAL(int)
296
jsimd_can_h2v1_merged_upsample (void)
297
{
298
  /* The code is optimised for these values only */
299
  if (BITS_IN_JSAMPLE != 8)
300
    return 0;
301
  if (sizeof(JDIMENSION) != 4)
302
    return 0;
303
304
  if (!IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
305
    return 0;
306
307
  return 1;
308
}
309
310
GLOBAL(void)
311
jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
312
                            JSAMPIMAGE input_buf,
313
                            JDIMENSION in_row_group_ctr,
314
                            JSAMPARRAY output_buf)
315
{
316
  void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
317
318
  switch(cinfo->out_color_space)
319
  {
320
    case JCS_EXT_RGB:
321
      sse2fct=jsimd_h2v2_extrgb_merged_upsample_sse2;
322
      break;
323
    case JCS_EXT_RGBX:
324
      sse2fct=jsimd_h2v2_extrgbx_merged_upsample_sse2;
325
      break;
326
    case JCS_EXT_BGR:
327
      sse2fct=jsimd_h2v2_extbgr_merged_upsample_sse2;
328
      break;
329
    case JCS_EXT_BGRX:
330
      sse2fct=jsimd_h2v2_extbgrx_merged_upsample_sse2;
331
      break;
332
    case JCS_EXT_XBGR:
333
      sse2fct=jsimd_h2v2_extxbgr_merged_upsample_sse2;
334
      break;
335
    case JCS_EXT_XRGB:
336
      sse2fct=jsimd_h2v2_extxrgb_merged_upsample_sse2;
337
      break;
338
    default:
339
      sse2fct=jsimd_h2v2_merged_upsample_sse2;
340
      break;
341
  }
342
343
  sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
344
}
345
346
GLOBAL(void)
347
jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
348
                            JSAMPIMAGE input_buf,
349
                            JDIMENSION in_row_group_ctr,
350
                            JSAMPARRAY output_buf)
351
{
352
  void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
353
354
  switch(cinfo->out_color_space)
355
  {
356
    case JCS_EXT_RGB:
357
      sse2fct=jsimd_h2v1_extrgb_merged_upsample_sse2;
358
      break;
359
    case JCS_EXT_RGBX:
360
      sse2fct=jsimd_h2v1_extrgbx_merged_upsample_sse2;
361
      break;
362
    case JCS_EXT_BGR:
363
      sse2fct=jsimd_h2v1_extbgr_merged_upsample_sse2;
364
      break;
365
    case JCS_EXT_BGRX:
366
      sse2fct=jsimd_h2v1_extbgrx_merged_upsample_sse2;
367
      break;
368
    case JCS_EXT_XBGR:
369
      sse2fct=jsimd_h2v1_extxbgr_merged_upsample_sse2;
370
      break;
371
    case JCS_EXT_XRGB:
372
      sse2fct=jsimd_h2v1_extxrgb_merged_upsample_sse2;
373
      break;
374
    default:
375
      sse2fct=jsimd_h2v1_merged_upsample_sse2;
376
      break;
377
  }
378
379
  sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
380
}
381
382
GLOBAL(int)
383
jsimd_can_convsamp (void)
384
{
385
  /* The code is optimised for these values only */
386
  if (DCTSIZE != 8)
387
    return 0;
388
  if (BITS_IN_JSAMPLE != 8)
389
    return 0;
390
  if (sizeof(JDIMENSION) != 4)
391
    return 0;
392
  if (sizeof(DCTELEM) != 2)
393
    return 0;
394
395
  return 1;
396
}
397
398
GLOBAL(int)
399
jsimd_can_convsamp_float (void)
400
{
401
  /* The code is optimised for these values only */
402
  if (DCTSIZE != 8)
403
    return 0;
404
  if (BITS_IN_JSAMPLE != 8)
405
    return 0;
406
  if (sizeof(JDIMENSION) != 4)
407
    return 0;
408
  if (sizeof(FAST_FLOAT) != 4)
409
    return 0;
410
411
  return 1;
412
}
413
414
GLOBAL(void)
415
jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
416
                DCTELEM * workspace)
417
{
418
  jsimd_convsamp_sse2(sample_data, start_col, workspace);
419
}
420
421
GLOBAL(void)
422
jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
423
                      FAST_FLOAT * workspace)
424
{
425
  jsimd_convsamp_float_sse2(sample_data, start_col, workspace);
426
}
427
428
GLOBAL(int)
429
jsimd_can_fdct_islow (void)
430
{
431
  /* The code is optimised for these values only */
432
  if (DCTSIZE != 8)
433
    return 0;
434
  if (sizeof(DCTELEM) != 2)
435
    return 0;
436
437
  if (!IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
438
    return 0;
439
440
  return 1;
441
}
442
443
GLOBAL(int)
444
jsimd_can_fdct_ifast (void)
445
{
446
  /* The code is optimised for these values only */
447
  if (DCTSIZE != 8)
448
    return 0;
449
  if (sizeof(DCTELEM) != 2)
450
    return 0;
451
452
  if (!IS_ALIGNED_SSE(jconst_fdct_ifast_sse2))
453
    return 0;
454
455
  return 1;
456
}
457
458
GLOBAL(int)
459
jsimd_can_fdct_float (void)
460
{
461
  /* The code is optimised for these values only */
462
  if (DCTSIZE != 8)
463
    return 0;
464
  if (sizeof(FAST_FLOAT) != 4)
465
    return 0;
466
467
  if (!IS_ALIGNED_SSE(jconst_fdct_float_sse))
468
    return 0;
469
470
  return 1;
471
}
472
473
GLOBAL(void)
474
jsimd_fdct_islow (DCTELEM * data)
475
{
476
  jsimd_fdct_islow_sse2(data);
477
}
478
479
GLOBAL(void)
480
jsimd_fdct_ifast (DCTELEM * data)
481
{
482
  jsimd_fdct_ifast_sse2(data);
483
}
484
485
GLOBAL(void)
486
jsimd_fdct_float (FAST_FLOAT * data)
487
{
488
  jsimd_fdct_float_sse(data);
489
}
490
491
GLOBAL(int)
492
jsimd_can_quantize (void)
493
{
494
  /* The code is optimised for these values only */
495
  if (DCTSIZE != 8)
496
    return 0;
497
  if (sizeof(JCOEF) != 2)
498
    return 0;
499
  if (sizeof(DCTELEM) != 2)
500
    return 0;
501
502
  return 1;
503
}
504
505
GLOBAL(int)
506
jsimd_can_quantize_float (void)
507
{
508
  /* The code is optimised for these values only */
509
  if (DCTSIZE != 8)
510
    return 0;
511
  if (sizeof(JCOEF) != 2)
512
    return 0;
513
  if (sizeof(FAST_FLOAT) != 4)
514
    return 0;
515
516
  return 1;
517
}
518
519
GLOBAL(void)
520
jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
521
                DCTELEM * workspace)
522
{
523
  jsimd_quantize_sse2(coef_block, divisors, workspace);
524
}
525
526
GLOBAL(void)
527
jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
528
                      FAST_FLOAT * workspace)
529
{
530
  jsimd_quantize_float_sse2(coef_block, divisors, workspace);
531
}
532
533
GLOBAL(int)
534
jsimd_can_idct_2x2 (void)
535
{
536
  /* The code is optimised for these values only */
537
  if (DCTSIZE != 8)
538
    return 0;
539
  if (sizeof(JCOEF) != 2)
540
    return 0;
541
  if (BITS_IN_JSAMPLE != 8)
542
    return 0;
543
  if (sizeof(JDIMENSION) != 4)
544
    return 0;
545
  if (sizeof(ISLOW_MULT_TYPE) != 2)
546
    return 0;
547
548
  if (!IS_ALIGNED_SSE(jconst_idct_red_sse2))
549
    return 0;
550
551
  return 1;
552
}
553
554
GLOBAL(int)
555
jsimd_can_idct_4x4 (void)
556
{
557
  /* The code is optimised for these values only */
558
  if (DCTSIZE != 8)
559
    return 0;
560
  if (sizeof(JCOEF) != 2)
561
    return 0;
562
  if (BITS_IN_JSAMPLE != 8)
563
    return 0;
564
  if (sizeof(JDIMENSION) != 4)
565
    return 0;
566
  if (sizeof(ISLOW_MULT_TYPE) != 2)
567
    return 0;
568
569
  if (!IS_ALIGNED_SSE(jconst_idct_red_sse2))
570
    return 0;
571
572
  return 1;
573
}
574
575
GLOBAL(void)
576
jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
577
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
578
                JDIMENSION output_col)
579
{
580
  jsimd_idct_2x2_sse2(compptr->dct_table, coef_block, output_buf, output_col);
581
}
582
583
GLOBAL(void)
584
jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
585
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
586
                JDIMENSION output_col)
587
{
588
  jsimd_idct_4x4_sse2(compptr->dct_table, coef_block, output_buf, output_col);
589
}
590
591
GLOBAL(int)
592
jsimd_can_idct_islow (void)
593
{
594
  /* The code is optimised for these values only */
595
  if (DCTSIZE != 8)
596
    return 0;
597
  if (sizeof(JCOEF) != 2)
598
    return 0;
599
  if (BITS_IN_JSAMPLE != 8)
600
    return 0;
601
  if (sizeof(JDIMENSION) != 4)
602
    return 0;
603
  if (sizeof(ISLOW_MULT_TYPE) != 2)
604
    return 0;
605
606
  if (!IS_ALIGNED_SSE(jconst_idct_islow_sse2))
607
    return 0;
608
609
  return 1;
610
}
611
612
GLOBAL(int)
613
jsimd_can_idct_ifast (void)
614
{
615
  /* The code is optimised for these values only */
616
  if (DCTSIZE != 8)
617
    return 0;
618
  if (sizeof(JCOEF) != 2)
619
    return 0;
620
  if (BITS_IN_JSAMPLE != 8)
621
    return 0;
622
  if (sizeof(JDIMENSION) != 4)
623
    return 0;
624
  if (sizeof(IFAST_MULT_TYPE) != 2)
625
    return 0;
626
  if (IFAST_SCALE_BITS != 2)
627
    return 0;
628
629
  if (!IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
630
    return 0;
631
632
  return 1;
633
}
634
635
GLOBAL(int)
636
jsimd_can_idct_float (void)
637
{
638
  if (DCTSIZE != 8)
639
    return 0;
640
  if (sizeof(JCOEF) != 2)
641
    return 0;
642
  if (BITS_IN_JSAMPLE != 8)
643
    return 0;
644
  if (sizeof(JDIMENSION) != 4)
645
    return 0;
646
  if (sizeof(FAST_FLOAT) != 4)
647
    return 0;
648
  if (sizeof(FLOAT_MULT_TYPE) != 4)
649
    return 0;
650
651
  if (!IS_ALIGNED_SSE(jconst_idct_float_sse2))
652
    return 0;
653
654
  return 1;
655
}
656
657
GLOBAL(void)
658
jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
659
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
660
                JDIMENSION output_col)
661
{
662
  jsimd_idct_islow_sse2(compptr->dct_table, coef_block, output_buf, output_col);
663
}
664
665
GLOBAL(void)
666
jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
667
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
668
                JDIMENSION output_col)
669
{
670
  jsimd_idct_ifast_sse2(compptr->dct_table, coef_block, output_buf, output_col);
671
}
672
673
GLOBAL(void)
674
jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
675
                JCOEFPTR coef_block, JSAMPARRAY output_buf,
676
                JDIMENSION output_col)
677
{
678
  jsimd_idct_float_sse2(compptr->dct_table, coef_block,
679
                        output_buf, output_col);
680
}
681
(-)a/jpeg/simd/jsimdcfg.inc (+69 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; Automatically generated include file from jsimdcfg.inc.h
3
;
4
;
5
; -- jpeglib.h
6
;
7
%define DCTSIZE 8
8
%define DCTSIZE2 64
9
;
10
; -- jmorecfg.h
11
;
12
%define RGB_RED 0
13
%define RGB_GREEN 1
14
%define RGB_BLUE 2
15
%define RGB_PIXELSIZE 3
16
; Representation of a single sample (pixel element value).
17
; On this SIMD implementation, this must be 'unsigned char'.
18
;
19
%define JSAMPLE byte ; unsigned char
20
%define SIZEOF_JSAMPLE SIZEOF_BYTE ; sizeof(JSAMPLE)
21
%define CENTERJSAMPLE 128
22
; Representation of a DCT frequency coefficient.
23
; On this SIMD implementation, this must be 'short'.
24
;
25
%define JCOEF word ; short
26
%define SIZEOF_JCOEF SIZEOF_WORD ; sizeof(JCOEF)
27
; Datatype used for image dimensions.
28
; On this SIMD implementation, this must be 'unsigned int'.
29
;
30
%define JDIMENSION dword ; unsigned int
31
%define SIZEOF_JDIMENSION SIZEOF_DWORD ; sizeof(JDIMENSION)
32
%define JSAMPROW POINTER ; JSAMPLE * (jpeglib.h)
33
%define JSAMPARRAY POINTER ; JSAMPROW * (jpeglib.h)
34
%define JSAMPIMAGE POINTER ; JSAMPARRAY * (jpeglib.h)
35
%define JCOEFPTR POINTER ; JCOEF * (jpeglib.h)
36
%define SIZEOF_JSAMPROW SIZEOF_POINTER ; sizeof(JSAMPROW)
37
%define SIZEOF_JSAMPARRAY SIZEOF_POINTER ; sizeof(JSAMPARRAY)
38
%define SIZEOF_JSAMPIMAGE SIZEOF_POINTER ; sizeof(JSAMPIMAGE)
39
%define SIZEOF_JCOEFPTR SIZEOF_POINTER ; sizeof(JCOEFPTR)
40
;
41
; -- jdct.h
42
;
43
; A forward DCT routine is given a pointer to a work area of type DCTELEM[];
44
; the DCT is to be performed in-place in that buffer.
45
; To maximize parallelism, Type DCTELEM is changed to short (originally, int).
46
;
47
%define DCTELEM word ; short
48
%define SIZEOF_DCTELEM SIZEOF_WORD ; sizeof(DCTELEM)
49
%define float FP32 ; float
50
%define SIZEOF_FAST_FLOAT SIZEOF_FP32 ; sizeof(float)
51
; To maximize parallelism, Type short is changed to short.
52
;
53
%define ISLOW_MULT_TYPE word ; must be short
54
%define SIZEOF_ISLOW_MULT_TYPE SIZEOF_WORD ; sizeof(ISLOW_MULT_TYPE)
55
%define IFAST_MULT_TYPE word ; must be short
56
%define SIZEOF_IFAST_MULT_TYPE SIZEOF_WORD ; sizeof(IFAST_MULT_TYPE)
57
%define IFAST_SCALE_BITS 2 ; fractional bits in scale factors
58
%define FLOAT_MULT_TYPE FP32 ; must be float
59
%define SIZEOF_FLOAT_MULT_TYPE SIZEOF_FP32 ; sizeof(FLOAT_MULT_TYPE)
60
;
61
; -- jsimd.h
62
;
63
%define JSIMD_NONE 0x00
64
%define JSIMD_MMX 0x01
65
%define JSIMD_3DNOW 0x02
66
%define JSIMD_SSE 0x04
67
%define JSIMD_SSE2 0x08
68
; Short forms of external names for systems with brain-damaged linkers.
69
;
(-)a/jpeg/simd/jsimdcfg.inc.h (+168 lines)
Line     Link Here 
Line 0    Link Here 
1
// This file generates the include file for the assembly
2
// implementations by abusing the C preprocessor.
3
//
4
// Note: Some things are manually defined as they need to
5
// be mapped to NASM types.
6
7
;
8
; Automatically generated include file from jsimdcfg.inc.h
9
;
10
11
#define JPEG_INTERNALS
12
13
#include "../jpeglib.h"
14
#include "../jconfig.h"
15
#include "../jmorecfg.h"
16
#include "jsimd.h"
17
18
#define define(var) %define _cpp_protection_##var
19
#define definev(var) %define _cpp_protection_##var var
20
21
;
22
; -- jpeglib.h
23
;
24
25
definev(DCTSIZE)
26
definev(DCTSIZE2)
27
28
;
29
; -- jmorecfg.h
30
;
31
32
definev(RGB_RED)
33
definev(RGB_GREEN)
34
definev(RGB_BLUE)
35
36
definev(RGB_PIXELSIZE)
37
38
; Representation of a single sample (pixel element value).
39
; On this SIMD implementation, this must be 'unsigned char'.
40
;
41
42
%define JSAMPLE                 byte          ; unsigned char
43
%define SIZEOF_JSAMPLE          SIZEOF_BYTE   ; sizeof(JSAMPLE)
44
45
definev(CENTERJSAMPLE)
46
47
; Representation of a DCT frequency coefficient.
48
; On this SIMD implementation, this must be 'short'.
49
;
50
%define JCOEF                   word          ; short
51
%define SIZEOF_JCOEF            SIZEOF_WORD   ; sizeof(JCOEF)
52
53
; Datatype used for image dimensions.
54
; On this SIMD implementation, this must be 'unsigned int'.
55
;
56
%define JDIMENSION              dword         ; unsigned int
57
%define SIZEOF_JDIMENSION       SIZEOF_DWORD  ; sizeof(JDIMENSION)
58
59
%define JSAMPROW                POINTER       ; JSAMPLE FAR * (jpeglib.h)
60
%define JSAMPARRAY              POINTER       ; JSAMPROW *    (jpeglib.h)
61
%define JSAMPIMAGE              POINTER       ; JSAMPARRAY *  (jpeglib.h)
62
%define JCOEFPTR                POINTER       ; JCOEF FAR *   (jpeglib.h)
63
%define SIZEOF_JSAMPROW         SIZEOF_POINTER  ; sizeof(JSAMPROW)
64
%define SIZEOF_JSAMPARRAY       SIZEOF_POINTER  ; sizeof(JSAMPARRAY)
65
%define SIZEOF_JSAMPIMAGE       SIZEOF_POINTER  ; sizeof(JSAMPIMAGE)
66
%define SIZEOF_JCOEFPTR         SIZEOF_POINTER  ; sizeof(JCOEFPTR)
67
68
;
69
; -- jdct.h
70
;
71
72
; A forward DCT routine is given a pointer to a work area of type DCTELEM[];
73
; the DCT is to be performed in-place in that buffer.
74
; To maximize parallelism, Type DCTELEM is changed to short (originally, int).
75
;
76
%define DCTELEM                 word          ; short
77
%define SIZEOF_DCTELEM          SIZEOF_WORD   ; sizeof(DCTELEM)
78
79
%define FAST_FLOAT              FP32            ; float
80
%define SIZEOF_FAST_FLOAT       SIZEOF_FP32     ; sizeof(FAST_FLOAT)
81
82
; To maximize parallelism, Type MULTIPLIER is changed to short.
83
;
84
%define ISLOW_MULT_TYPE         word          ; must be short
85
%define SIZEOF_ISLOW_MULT_TYPE  SIZEOF_WORD   ; sizeof(ISLOW_MULT_TYPE)
86
87
%define IFAST_MULT_TYPE         word          ; must be short
88
%define SIZEOF_IFAST_MULT_TYPE  SIZEOF_WORD   ; sizeof(IFAST_MULT_TYPE)
89
%define IFAST_SCALE_BITS        2             ; fractional bits in scale factors
90
91
%define FLOAT_MULT_TYPE         FP32          ; must be float
92
%define SIZEOF_FLOAT_MULT_TYPE  SIZEOF_FP32   ; sizeof(FLOAT_MULT_TYPE)
93
94
;
95
; -- jsimd.h
96
;
97
98
definev(JSIMD_NONE)
99
definev(JSIMD_MMX)
100
definev(JSIMD_3DNOW)
101
definev(JSIMD_SSE)
102
definev(JSIMD_SSE2)
103
104
; Short forms of external names for systems with brain-damaged linkers.
105
;
106
#ifdef NEED_SHORT_EXTERNAL_NAMES
107
definev(jpeg_simd_cpu_support)
108
definev(jsimd_rgb_ycc_convert_mmx)
109
definev(jsimd_ycc_rgb_convert_mmx)
110
definev(jconst_rgb_ycc_convert_sse2)
111
definev(jsimd_rgb_ycc_convert_sse2)
112
definev(jconst_ycc_rgb_convert_sse2)
113
definev(jsimd_ycc_rgb_convert_sse2)
114
definev(jsimd_h2v2_downsample_mmx)
115
definev(jsimd_h2v1_downsample_mmx)
116
definev(jsimd_h2v2_downsample_sse2)
117
definev(jsimd_h2v1_downsample_sse2)
118
definev(jsimd_h2v2_upsample_mmx)
119
definev(jsimd_h2v1_upsample_mmx)
120
definev(jsimd_h2v1_fancy_upsample_mmx)
121
definev(jsimd_h2v2_fancy_upsample_mmx)
122
definev(jsimd_h2v1_merged_upsample_mmx)
123
definev(jsimd_h2v2_merged_upsample_mmx)
124
definev(jsimd_h2v2_upsample_sse2)
125
definev(jsimd_h2v1_upsample_sse2)
126
definev(jconst_fancy_upsample_sse2)
127
definev(jsimd_h2v1_fancy_upsample_sse2)
128
definev(jsimd_h2v2_fancy_upsample_sse2)
129
definev(jconst_merged_upsample_sse2)
130
definev(jsimd_h2v1_merged_upsample_sse2)
131
definev(jsimd_h2v2_merged_upsample_sse2)
132
definev(jsimd_convsamp_mmx)
133
definev(jsimd_convsamp_sse2)
134
definev(jsimd_convsamp_float_3dnow)
135
definev(jsimd_convsamp_float_sse)
136
definev(jsimd_convsamp_float_sse2)
137
definev(jsimd_fdct_islow_mmx)
138
definev(jsimd_fdct_ifast_mmx)
139
definev(jconst_fdct_islow_sse2)
140
definev(jsimd_fdct_islow_sse2)
141
definev(jconst_fdct_ifast_sse2)
142
definev(jsimd_fdct_ifast_sse2)
143
definev(jsimd_fdct_float_3dnow)
144
definev(jconst_fdct_float_sse)
145
definev(jsimd_fdct_float_sse)
146
definev(jsimd_quantize_mmx)
147
definev(jsimd_quantize_sse2)
148
definev(jsimd_quantize_float_3dnow)
149
definev(jsimd_quantize_float_sse)
150
definev(jsimd_quantize_float_sse2)
151
definev(jsimd_idct_2x2_mmx)
152
definev(jsimd_idct_4x4_mmx)
153
definev(jconst_idct_red_sse2)
154
definev(jsimd_idct_2x2_sse2)
155
definev(jsimd_idct_4x4_sse2)
156
definev(jsimd_idct_islow_mmx)
157
definev(jsimd_idct_ifast_mmx)
158
definev(jconst_idct_islow_sse2)
159
definev(jsimd_idct_islow_sse2)
160
definev(jconst_idct_ifast_sse2)
161
definev(jsimd_idct_ifast_sse2)
162
definev(jsimd_idct_float_3dnow)
163
definev(jconst_idct_float_sse)
164
definev(jsimd_idct_float_sse)
165
definev(jconst_idct_float_sse2)
166
definev(jsimd_idct_float_sse2)
167
#endif /* NEED_SHORT_EXTERNAL_NAMES */
168
(-)a/jpeg/simd/jsimdcpu.asm (+105 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jsimdcpu.asm - SIMD instruction support check
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
;
6
; Based on
7
; x86 SIMD extension for IJG JPEG library
8
; Copyright (C) 1999-2006, MIYASAKA Masaru.
9
; For conditions of distribution and use, see copyright notice in jsimdext.inc
10
;
11
; This file should be assembled with NASM (Netwide Assembler),
12
; can *not* be assembled with Microsoft's MASM or any compatible
13
; assembler (including Borland's Turbo Assembler).
14
; NASM is available from http://nasm.sourceforge.net/ or
15
; http://sourceforge.net/project/showfiles.php?group_id=6208
16
;
17
; [TAB8]
18
19
%include "jsimdext.inc"
20
21
; --------------------------------------------------------------------------
22
	SECTION	SEG_TEXT
23
	BITS	32
24
;
25
; Check if the CPU supports SIMD instructions
26
;
27
; GLOBAL(unsigned int)
28
; jpeg_simd_cpu_support (void)
29
;
30
31
	align	16
32
	global	EXTN(jpeg_simd_cpu_support)
33
34
EXTN(jpeg_simd_cpu_support):
35
	push	ebx
36
;	push	ecx		; need not be preserved
37
;	push	edx		; need not be preserved
38
;	push	esi		; unused
39
	push	edi
40
41
	xor	edi,edi			; simd support flag
42
43
	pushfd
44
	pop	eax
45
	mov	edx,eax
46
	xor	eax, 1<<21		; flip ID bit in EFLAGS
47
	push	eax
48
	popfd
49
	pushfd
50
	pop	eax
51
	xor	eax,edx
52
	jz	short .return		; CPUID is not supported
53
54
	; Check for MMX instruction support
55
	xor	eax,eax
56
	cpuid
57
	test	eax,eax
58
	jz	short .return
59
60
	xor	eax,eax
61
	inc	eax
62
	cpuid
63
	mov	eax,edx			; eax = Standard feature flags
64
65
	test	eax, 1<<23		; bit23:MMX
66
	jz	short .no_mmx
67
	or	edi, byte JSIMD_MMX
68
.no_mmx:
69
	test	eax, 1<<25		; bit25:SSE
70
	jz	short .no_sse
71
	or	edi, byte JSIMD_SSE
72
.no_sse:
73
	test	eax, 1<<26		; bit26:SSE2
74
	jz	short .no_sse2
75
	or	edi, byte JSIMD_SSE2
76
.no_sse2:
77
78
	; Check for 3DNow! instruction support
79
	mov	eax, 0x80000000
80
	cpuid
81
	cmp	eax, 0x80000000
82
	jbe	short .return
83
84
	mov	eax, 0x80000001
85
	cpuid
86
	mov	eax,edx			; eax = Extended feature flags
87
88
	test	eax, 1<<31		; bit31:3DNow!(vendor independent)
89
	jz	short .no_3dnow
90
	or	edi, byte JSIMD_3DNOW
91
.no_3dnow:
92
93
.return:
94
	mov	eax,edi
95
96
	pop	edi
97
;	pop	esi		; unused
98
;	pop	edx		; need not be preserved
99
;	pop	ecx		; need not be preserved
100
	pop	ebx
101
	ret
102
103
; For some reason, the OS X linker does not honor the request to align the
104
; segment unless we do this.
105
	align	16
(-)a/jpeg/simd/jsimdext.inc (+372 lines)
Line     Link Here 
Line 0    Link Here 
1
;
2
; jsimdext.inc - common declarations
3
;
4
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5
; Copyright 2010 D. R. Commander
6
;
7
; Based on
8
; x86 SIMD extension for IJG JPEG library - version 1.02
9
;
10
; Copyright (C) 1999-2006, MIYASAKA Masaru.
11
;
12
; This software is provided 'as-is', without any express or implied
13
; warranty.  In no event will the authors be held liable for any damages
14
; arising from the use of this software.
15
;
16
; Permission is granted to anyone to use this software for any purpose,
17
; including commercial applications, and to alter it and redistribute it
18
; freely, subject to the following restrictions:
19
;
20
; 1. The origin of this software must not be misrepresented; you must not
21
;    claim that you wrote the original software. If you use this software
22
;    in a product, an acknowledgment in the product documentation would be
23
;    appreciated but is not required.
24
; 2. Altered source versions must be plainly marked as such, and must not be
25
;    misrepresented as being the original software.
26
; 3. This notice may not be removed or altered from any source distribution.
27
;
28
; [TAB8]
29
30
; ==========================================================================
31
;  System-dependent configurations
32
33
%ifdef WIN32	; ----(nasm -fwin32 -DWIN32 ...)--------
34
; * Microsoft Visual C++
35
; * MinGW (Minimalist GNU for Windows)
36
; * CygWin
37
; * LCC-Win32
38
39
; -- segment definition --
40
;
41
%define SEG_TEXT    .text  align=16 public use32 class=CODE
42
%define SEG_CONST   .rdata align=16 public use32 class=CONST
43
44
%elifdef WIN64	; ----(nasm -fwin64 -DWIN64 ...)--------
45
; * Microsoft Visual C++
46
47
; -- segment definition --
48
;
49
%define SEG_TEXT    .text  align=16 public use64 class=CODE
50
%define SEG_CONST   .rdata align=16 public use64 class=CONST
51
%ifdef MSVC
52
%define EXTN(name)  name			; foo() -> foo
53
%endif
54
55
%elifdef OBJ32	; ----(nasm -fobj -DOBJ32 ...)----------
56
; * Borland C++ (Win32)
57
58
; -- segment definition --
59
;
60
%define SEG_TEXT    .text  align=16 public use32 class=CODE
61
%define SEG_CONST   .data  align=16 public use32 class=DATA
62
63
%elifdef ELF	; ----(nasm -felf[64] -DELF ...)------------
64
; * Linux
65
; * *BSD family Unix using elf format
66
; * Unix System V, including Solaris x86, UnixWare and SCO Unix
67
68
; mark stack as non-executable
69
section .note.GNU-stack noalloc noexec nowrite progbits
70
71
; -- segment definition --
72
;
73
%ifdef __x86_64__
74
%define SEG_TEXT    .text   progbits align=16
75
%define SEG_CONST   .rodata progbits align=16
76
%else
77
%define SEG_TEXT    .text   progbits alloc exec   nowrite align=16
78
%define SEG_CONST   .rodata progbits alloc noexec nowrite align=16
79
%endif
80
81
; To make the code position-independent, append -DPIC to the commandline
82
;
83
%define GOT_SYMBOL  _GLOBAL_OFFSET_TABLE_	; ELF supports PIC
84
%define EXTN(name)  name			; foo() -> foo
85
86
%elifdef AOUT	; ----(nasm -faoutb/aout -DAOUT ...)----
87
; * Older Linux using a.out format  (nasm -f aout -DAOUT ...)
88
; * *BSD family Unix using a.out format  (nasm -f aoutb -DAOUT ...)
89
90
; -- segment definition --
91
;
92
%define SEG_TEXT    .text
93
%define SEG_CONST   .data
94
95
; To make the code position-independent, append -DPIC to the commandline
96
;
97
%define GOT_SYMBOL  __GLOBAL_OFFSET_TABLE_	; BSD-style a.out supports PIC
98
99
%elifdef MACHO	; ----(nasm -fmacho -DMACHO ...)--------
100
; * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (Mach-O format)
101
102
; -- segment definition --
103
;
104
%define SEG_TEXT    .text  ;align=16	; nasm doesn't accept align=16. why?
105
%define SEG_CONST   .rodata align=16
106
107
; The generation of position-independent code (PIC) is the default on Darwin.
108
;
109
%define PIC
110
%define GOT_SYMBOL  _MACHO_PIC_		; Mach-O style code-relative addressing
111
112
%else		; ----(Other case)----------------------
113
114
; -- segment definition --
115
;
116
%define SEG_TEXT    .text
117
%define SEG_CONST   .data
118
119
%endif	; ----------------------------------------------
120
121
; ==========================================================================
122
123
; --------------------------------------------------------------------------
124
;  Common types
125
;
126
%ifdef __x86_64__
127
%define POINTER                 qword           ; general pointer type
128
%define SIZEOF_POINTER          SIZEOF_QWORD    ; sizeof(POINTER)
129
%define POINTER_BIT             QWORD_BIT       ; sizeof(POINTER)*BYTE_BIT
130
%else
131
%define POINTER                 dword           ; general pointer type
132
%define SIZEOF_POINTER          SIZEOF_DWORD    ; sizeof(POINTER)
133
%define POINTER_BIT             DWORD_BIT       ; sizeof(POINTER)*BYTE_BIT
134
%endif
135
136
%define INT                     dword           ; signed integer type
137
%define SIZEOF_INT              SIZEOF_DWORD    ; sizeof(INT)
138
%define INT_BIT                 DWORD_BIT       ; sizeof(INT)*BYTE_BIT
139
140
%define FP32                    dword           ; IEEE754 single
141
%define SIZEOF_FP32             SIZEOF_DWORD    ; sizeof(FP32)
142
%define FP32_BIT                DWORD_BIT       ; sizeof(FP32)*BYTE_BIT
143
144
%define MMWORD                  qword           ; int64  (MMX register)
145
%define SIZEOF_MMWORD           SIZEOF_QWORD    ; sizeof(MMWORD)
146
%define MMWORD_BIT              QWORD_BIT       ; sizeof(MMWORD)*BYTE_BIT
147
148
; NASM is buggy and doesn't properly handle operand sizes for SSE
149
; instructions, so for now we have to define XMMWORD as blank.
150
%define XMMWORD                                 ; int128 (SSE register)
151
%define SIZEOF_XMMWORD          SIZEOF_OWORD    ; sizeof(XMMWORD)
152
%define XMMWORD_BIT             OWORD_BIT       ; sizeof(XMMWORD)*BYTE_BIT
153
154
; Similar hacks for when we load a dword or MMWORD into an xmm# register
155
%define XMM_DWORD
156
%define XMM_MMWORD
157
158
%define SIZEOF_BYTE             1               ; sizeof(BYTE)
159
%define SIZEOF_WORD             2               ; sizeof(WORD)
160
%define SIZEOF_DWORD            4               ; sizeof(DWORD)
161
%define SIZEOF_QWORD            8               ; sizeof(QWORD)
162
%define SIZEOF_OWORD            16              ; sizeof(OWORD)
163
164
%define BYTE_BIT                8               ; CHAR_BIT in C
165
%define WORD_BIT                16              ; sizeof(WORD)*BYTE_BIT
166
%define DWORD_BIT               32              ; sizeof(DWORD)*BYTE_BIT
167
%define QWORD_BIT               64              ; sizeof(QWORD)*BYTE_BIT
168
%define OWORD_BIT               128             ; sizeof(OWORD)*BYTE_BIT
169
170
; --------------------------------------------------------------------------
171
;  External Symbol Name
172
;
173
%ifndef EXTN
174
%define EXTN(name)   _ %+ name		; foo() -> _foo
175
%endif
176
177
; --------------------------------------------------------------------------
178
;  Macros for position-independent code (PIC) support
179
;
180
%ifndef GOT_SYMBOL
181
%undef PIC
182
%endif
183
184
%ifdef PIC ; -------------------------------------------
185
186
%ifidn GOT_SYMBOL,_MACHO_PIC_ ; --------------------
187
188
; At present, nasm doesn't seem to support PIC generation for Mach-O.
189
; The PIC support code below is a little tricky.
190
191
	SECTION	SEG_CONST
192
const_base:
193
194
%define GOTOFF(got,sym) (got) + (sym) - const_base
195
196
%imacro get_GOT	1
197
	; NOTE: this macro destroys ecx resister.
198
	call	%%geteip
199
	add	ecx, byte (%%ref - $)
200
	jmp	short %%adjust
201
%%geteip:
202
	mov	ecx, POINTER [esp]
203
	ret
204
%%adjust:
205
	push	ebp
206
	xor	ebp,ebp		; ebp = 0
207
%ifidni %1,ebx	; (%1 == ebx)
208
	; db 0x8D,0x9C + jmp near const_base =
209
	;   lea ebx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,9C,E9,(offset32)
210
	db	0x8D,0x9C		; 8D,9C
211
	jmp	near const_base		; E9,(const_base-%%ref)
212
%%ref:
213
%else  ; (%1 != ebx)
214
	; db 0x8D,0x8C + jmp near const_base =
215
	;   lea ecx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,8C,E9,(offset32)
216
	db	0x8D,0x8C		; 8D,8C
217
	jmp	near const_base		; E9,(const_base-%%ref)
218
%%ref:	mov	%1, ecx
219
%endif ; (%1 == ebx)
220
	pop	ebp
221
%endmacro
222
223
%else	; GOT_SYMBOL != _MACHO_PIC_ ----------------
224
225
%define GOTOFF(got,sym) (got) + (sym) wrt ..gotoff
226
227
%imacro get_GOT	1
228
	extern	GOT_SYMBOL
229
	call	%%geteip
230
	add	%1, GOT_SYMBOL + $$ - $ wrt ..gotpc
231
	jmp	short %%done
232
%%geteip:
233
	mov	%1, POINTER [esp]
234
	ret
235
%%done:
236
%endmacro
237
238
%endif	; GOT_SYMBOL == _MACHO_PIC_ ----------------
239
240
%imacro pushpic	1.nolist
241
	push	%1
242
%endmacro
243
%imacro poppic	1.nolist
244
	pop	%1
245
%endmacro
246
%imacro movpic	2.nolist
247
	mov	%1,%2
248
%endmacro
249
250
%else	; !PIC -----------------------------------------
251
252
%define GOTOFF(got,sym) (sym)
253
254
%imacro get_GOT	1.nolist
255
%endmacro
256
%imacro pushpic	1.nolist
257
%endmacro
258
%imacro poppic	1.nolist
259
%endmacro
260
%imacro movpic	2.nolist
261
%endmacro
262
263
%endif	;  PIC -----------------------------------------
264
265
; --------------------------------------------------------------------------
266
;  Align the next instruction on {2,4,8,16,..}-byte boundary.
267
;  ".balign n,,m" in GNU as
268
;
269
%define MSKLE(x,y)  (~(((y) & 0xFFFF) - ((x) & 0xFFFF)) >> 16)
270
%define FILLB(b,n)  (($$-(b)) & ((n)-1))
271
272
%imacro alignx 1-2.nolist 0xFFFF
273
%%bs:	times MSKLE(FILLB(%%bs,%1),%2) & MSKLE(16,FILLB($,%1)) & FILLB($,%1) \
274
	       db 0x90                               ; nop
275
	times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/9 \
276
	       db 0x8D,0x9C,0x23,0x00,0x00,0x00,0x00 ; lea ebx,[ebx+0x00000000]
277
	times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/7 \
278
	       db 0x8D,0xAC,0x25,0x00,0x00,0x00,0x00 ; lea ebp,[ebp+0x00000000]
279
	times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/6 \
280
	       db 0x8D,0xAD,0x00,0x00,0x00,0x00      ; lea ebp,[ebp+0x00000000]
281
	times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/4 \
282
	       db 0x8D,0x6C,0x25,0x00                ; lea ebp,[ebp+0x00]
283
	times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/3 \
284
	       db 0x8D,0x6D,0x00                     ; lea ebp,[ebp+0x00]
285
	times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/2 \
286
	       db 0x8B,0xED                          ; mov ebp,ebp
287
	times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/1 \
288
	       db 0x90                               ; nop
289
%endmacro
290
291
; Align the next data on {2,4,8,16,..}-byte boundary.
292
;
293
%imacro alignz 1.nolist
294
	align %1, db 0		; filling zeros
295
%endmacro
296
297
%ifdef __x86_64__
298
299
%ifdef WIN64
300
301
%imacro collect_args 0
302
	push r10
303
	push r11
304
	push r12
305
	push r13
306
	push r14
307
	push r15
308
	mov r10, rcx
309
	mov r11, rdx
310
	mov r12, r8
311
	mov r13, r9
312
	mov r14, [rax+48]
313
	mov r15, [rax+56]
314
	push rsi
315
	push rdi
316
	sub     rsp, SIZEOF_XMMWORD
317
	movlpd  XMMWORD [rsp], xmm6
318
	sub     rsp, SIZEOF_XMMWORD
319
	movlpd  XMMWORD [rsp], xmm7
320
%endmacro
321
322
%imacro uncollect_args 0
323
	movlpd  xmm7, XMMWORD [rsp]
324
	add     rsp, SIZEOF_XMMWORD
325
	movlpd  xmm6, XMMWORD [rsp]
326
	add     rsp, SIZEOF_XMMWORD
327
	pop rdi
328
	pop rsi
329
	pop r15
330
	pop r14
331
	pop r13
332
	pop r12
333
	pop r11
334
	pop r10
335
%endmacro
336
337
%else
338
339
%imacro collect_args 0
340
	push r10
341
	push r11
342
	push r12
343
	push r13
344
	push r14
345
	push r15
346
	mov r10, rdi
347
	mov r11, rsi
348
	mov r12, rdx
349
	mov r13, rcx
350
	mov r14, r8
351
	mov r15, r9
352
%endmacro
353
354
%imacro uncollect_args 0
355
	pop r15
356
	pop r14
357
	pop r13
358
	pop r12
359
	pop r11
360
	pop r10
361
%endmacro
362
363
%endif
364
365
%endif
366
367
; --------------------------------------------------------------------------
368
;  Defines picked up from the C headers
369
;
370
%include "jsimdcfg.inc"
371
372
; --------------------------------------------------------------------------
(-)a/jpeg/structure.doc (-948 lines)
Line     Link Here 
 Lines 1-948    Link Here 
1
IJG JPEG LIBRARY:  SYSTEM ARCHITECTURE
2
3
Copyright (C) 1991-1995, Thomas G. Lane.
4
This file is part of the Independent JPEG Group's software.
5
For conditions of distribution and use, see the accompanying README file.
6
7
8
This file provides an overview of the architecture of the IJG JPEG software;
9
that is, the functions of the various modules in the system and the interfaces
10
between modules.  For more precise details about any data structure or calling
11
convention, see the include files and comments in the source code.
12
13
We assume that the reader is already somewhat familiar with the JPEG standard.
14
The README file includes references for learning about JPEG.  The file
15
libjpeg.doc describes the library from the viewpoint of an application
16
programmer using the library; it's best to read that file before this one.
17
Also, the file coderules.doc describes the coding style conventions we use.
18
19
In this document, JPEG-specific terminology follows the JPEG standard:
20
  A "component" means a color channel, e.g., Red or Luminance.
21
  A "sample" is a single component value (i.e., one number in the image data).
22
  A "coefficient" is a frequency coefficient (a DCT transform output number).
23
  A "block" is an 8x8 group of samples or coefficients.
24
  An "MCU" (minimum coded unit) is an interleaved set of blocks of size
25
	determined by the sampling factors, or a single block in a
26
	noninterleaved scan.
27
We do not use the terms "pixel" and "sample" interchangeably.  When we say
28
pixel, we mean an element of the full-size image, while a sample is an element
29
of the downsampled image.  Thus the number of samples may vary across
30
components while the number of pixels does not.  (This terminology is not used
31
rigorously throughout the code, but it is used in places where confusion would
32
otherwise result.)
33
34
35
*** System features ***
36
37
The IJG distribution contains two parts:
38
  * A subroutine library for JPEG compression and decompression.
39
  * cjpeg/djpeg, two sample applications that use the library to transform
40
    JFIF JPEG files to and from several other image formats.
41
cjpeg/djpeg are of no great intellectual complexity: they merely add a simple
42
command-line user interface and I/O routines for several uncompressed image
43
formats.  This document concentrates on the library itself.
44
45
We desire the library to be capable of supporting all JPEG baseline, extended
46
sequential, and progressive DCT processes.  Hierarchical processes are not
47
supported.
48
49
The library does not support the lossless (spatial) JPEG process.  Lossless
50
JPEG shares little or no code with lossy JPEG, and would normally be used
51
without the extensive pre- and post-processing provided by this library.
52
We feel that lossless JPEG is better handled by a separate library.
53
54
Within these limits, any set of compression parameters allowed by the JPEG
55
spec should be readable for decompression.  (We can be more restrictive about
56
what formats we can generate.)  Although the system design allows for all
57
parameter values, some uncommon settings are not yet implemented and may
58
never be; nonintegral sampling ratios are the prime example.  Furthermore,
59
we treat 8-bit vs. 12-bit data precision as a compile-time switch, not a
60
run-time option, because most machines can store 8-bit pixels much more
61
compactly than 12-bit.
62
63
For legal reasons, JPEG arithmetic coding is not currently supported, but
64
extending the library to include it would be straightforward.
65
66
By itself, the library handles only interchange JPEG datastreams --- in
67
particular the widely used JFIF file format.  The library can be used by
68
surrounding code to process interchange or abbreviated JPEG datastreams that
69
are embedded in more complex file formats.  (For example, libtiff uses this
70
library to implement JPEG compression within the TIFF file format.)
71
72
The library includes a substantial amount of code that is not covered by the
73
JPEG standard but is necessary for typical applications of JPEG.  These
74
functions preprocess the image before JPEG compression or postprocess it after
75
decompression.  They include colorspace conversion, downsampling/upsampling,
76
and color quantization.  This code can be omitted if not needed.
77
78
A wide range of quality vs. speed tradeoffs are possible in JPEG processing,
79
and even more so in decompression postprocessing.  The decompression library
80
provides multiple implementations that cover most of the useful tradeoffs,
81
ranging from very-high-quality down to fast-preview operation.  On the
82
compression side we have generally not provided low-quality choices, since
83
compression is normally less time-critical.  It should be understood that the
84
low-quality modes may not meet the JPEG standard's accuracy requirements;
85
nonetheless, they are useful for viewers.
86
87
88
*** Portability issues ***
89
90
Portability is an essential requirement for the library.  The key portability
91
issues that show up at the level of system architecture are:
92
93
1.  Memory usage.  We want the code to be able to run on PC-class machines
94
with limited memory.  Images should therefore be processed sequentially (in
95
strips), to avoid holding the whole image in memory at once.  Where a
96
full-image buffer is necessary, we should be able to use either virtual memory
97
or temporary files.
98
99
2.  Near/far pointer distinction.  To run efficiently on 80x86 machines, the
100
code should distinguish "small" objects (kept in near data space) from
101
"large" ones (kept in far data space).  This is an annoying restriction, but
102
fortunately it does not impact code quality for less brain-damaged machines,
103
and the source code clutter turns out to be minimal with sufficient use of
104
pointer typedefs.
105
106
3. Data precision.  We assume that "char" is at least 8 bits, "short" and
107
"int" at least 16, "long" at least 32.  The code will work fine with larger
108
data sizes, although memory may be used inefficiently in some cases.  However,
109
the JPEG compressed datastream must ultimately appear on external storage as a
110
sequence of 8-bit bytes if it is to conform to the standard.  This may pose a
111
problem on machines where char is wider than 8 bits.  The library represents
112
compressed data as an array of values of typedef JOCTET.  If no data type
113
exactly 8 bits wide is available, custom data source and data destination
114
modules must be written to unpack and pack the chosen JOCTET datatype into
115
8-bit external representation.
116
117
118
*** System overview ***
119
120
The compressor and decompressor are each divided into two main sections:
121
the JPEG compressor or decompressor proper, and the preprocessing or
122
postprocessing functions.  The interface between these two sections is the
123
image data that the official JPEG spec regards as its input or output: this
124
data is in the colorspace to be used for compression, and it is downsampled
125
to the sampling factors to be used.  The preprocessing and postprocessing
126
steps are responsible for converting a normal image representation to or from
127
this form.  (Those few applications that want to deal with YCbCr downsampled
128
data can skip the preprocessing or postprocessing step.)
129
130
Looking more closely, the compressor library contains the following main
131
elements:
132
133
  Preprocessing:
134
    * Color space conversion (e.g., RGB to YCbCr).
135
    * Edge expansion and downsampling.  Optionally, this step can do simple
136
      smoothing --- this is often helpful for low-quality source data.
137
  JPEG proper:
138
    * MCU assembly, DCT, quantization.
139
    * Entropy coding (sequential or progressive, Huffman or arithmetic).
140
141
In addition to these modules we need overall control, marker generation,
142
and support code (memory management & error handling).  There is also a
143
module responsible for physically writing the output data --- typically
144
this is just an interface to fwrite(), but some applications may need to
145
do something else with the data.
146
147
The decompressor library contains the following main elements:
148
149
  JPEG proper:
150
    * Entropy decoding (sequential or progressive, Huffman or arithmetic).
151
    * Dequantization, inverse DCT, MCU disassembly.
152
  Postprocessing:
153
    * Upsampling.  Optionally, this step may be able to do more general
154
      rescaling of the image.
155
    * Color space conversion (e.g., YCbCr to RGB).  This step may also
156
      provide gamma adjustment [ currently it does not ].
157
    * Optional color quantization (e.g., reduction to 256 colors).
158
    * Optional color precision reduction (e.g., 24-bit to 15-bit color).
159
      [This feature is not currently implemented.]
160
161
We also need overall control, marker parsing, and a data source module.
162
The support code (memory management & error handling) can be shared with
163
the compression half of the library.
164
165
There may be several implementations of each of these elements, particularly
166
in the decompressor, where a wide range of speed/quality tradeoffs is very
167
useful.  It must be understood that some of the best speedups involve
168
merging adjacent steps in the pipeline.  For example, upsampling, color space
169
conversion, and color quantization might all be done at once when using a
170
low-quality ordered-dither technique.  The system architecture is designed to
171
allow such merging where appropriate.
172
173
174
Note: it is convenient to regard edge expansion (padding to block boundaries)
175
as a preprocessing/postprocessing function, even though the JPEG spec includes
176
it in compression/decompression.  We do this because downsampling/upsampling
177
can be simplified a little if they work on padded data: it's not necessary to
178
have special cases at the right and bottom edges.  Therefore the interface
179
buffer is always an integral number of blocks wide and high, and we expect
180
compression preprocessing to pad the source data properly.  Padding will occur
181
only to the next block (8-sample) boundary.  In an interleaved-scan situation,
182
additional dummy blocks may be used to fill out MCUs, but the MCU assembly and
183
disassembly logic will create or discard these blocks internally.  (This is
184
advantageous for speed reasons, since we avoid DCTing the dummy blocks.
185
It also permits a small reduction in file size, because the compressor can
186
choose dummy block contents so as to minimize their size in compressed form.
187
Finally, it makes the interface buffer specification independent of whether
188
the file is actually interleaved or not.)  Applications that wish to deal
189
directly with the downsampled data must provide similar buffering and padding
190
for odd-sized images.
191
192
193
*** Poor man's object-oriented programming ***
194
195
It should be clear by now that we have a lot of quasi-independent processing
196
steps, many of which have several possible behaviors.  To avoid cluttering the
197
code with lots of switch statements, we use a simple form of object-style
198
programming to separate out the different possibilities.
199
200
For example, two different color quantization algorithms could be implemented
201
as two separate modules that present the same external interface; at runtime,
202
the calling code will access the proper module indirectly through an "object".
203
204
We can get the limited features we need while staying within portable C.
205
The basic tool is a function pointer.  An "object" is just a struct
206
containing one or more function pointer fields, each of which corresponds to
207
a method name in real object-oriented languages.  During initialization we
208
fill in the function pointers with references to whichever module we have
209
determined we need to use in this run.  Then invocation of the module is done
210
by indirecting through a function pointer; on most machines this is no more
211
expensive than a switch statement, which would be the only other way of
212
making the required run-time choice.  The really significant benefit, of
213
course, is keeping the source code clean and well structured.
214
215
We can also arrange to have private storage that varies between different
216
implementations of the same kind of object.  We do this by making all the
217
module-specific object structs be separately allocated entities, which will
218
be accessed via pointers in the master compression or decompression struct.
219
The "public" fields or methods for a given kind of object are specified by
220
a commonly known struct.  But a module's initialization code can allocate
221
a larger struct that contains the common struct as its first member, plus
222
additional private fields.  With appropriate pointer casting, the module's
223
internal functions can access these private fields.  (For a simple example,
224
see jdatadst.c, which implements the external interface specified by struct
225
jpeg_destination_mgr, but adds extra fields.)
226
227
(Of course this would all be a lot easier if we were using C++, but we are
228
not yet prepared to assume that everyone has a C++ compiler.)
229
230
An important benefit of this scheme is that it is easy to provide multiple
231
versions of any method, each tuned to a particular case.  While a lot of
232
precalculation might be done to select an optimal implementation of a method,
233
the cost per invocation is constant.  For example, the upsampling step might
234
have a "generic" method, plus one or more "hardwired" methods for the most
235
popular sampling factors; the hardwired methods would be faster because they'd
236
use straight-line code instead of for-loops.  The cost to determine which
237
method to use is paid only once, at startup, and the selection criteria are
238
hidden from the callers of the method.
239
240
This plan differs a little bit from usual object-oriented structures, in that
241
only one instance of each object class will exist during execution.  The
242
reason for having the class structure is that on different runs we may create
243
different instances (choose to execute different modules).  You can think of
244
the term "method" as denoting the common interface presented by a particular
245
set of interchangeable functions, and "object" as denoting a group of related
246
methods, or the total shared interface behavior of a group of modules.
247
248
249
*** Overall control structure ***
250
251
We previously mentioned the need for overall control logic in the compression
252
and decompression libraries.  In IJG implementations prior to v5, overall
253
control was mostly provided by "pipeline control" modules, which proved to be
254
large, unwieldy, and hard to understand.  To improve the situation, the
255
control logic has been subdivided into multiple modules.  The control modules
256
consist of:
257
258
1. Master control for module selection and initialization.  This has two
259
responsibilities:
260
261
   1A.  Startup initialization at the beginning of image processing.
262
        The individual processing modules to be used in this run are selected
263
        and given initialization calls.
264
265
   1B.  Per-pass control.  This determines how many passes will be performed
266
        and calls each active processing module to configure itself
267
        appropriately at the beginning of each pass.  End-of-pass processing,
268
	where necessary, is also invoked from the master control module.
269
270
   Method selection is partially distributed, in that a particular processing
271
   module may contain several possible implementations of a particular method,
272
   which it will select among when given its initialization call.  The master
273
   control code need only be concerned with decisions that affect more than
274
   one module.
275
 
276
2. Data buffering control.  A separate control module exists for each
277
   inter-processing-step data buffer.  This module is responsible for
278
   invoking the processing steps that write or read that data buffer.
279
280
Each buffer controller sees the world as follows:
281
282
input data => processing step A => buffer => processing step B => output data
283
                      |              |               |
284
              ------------------ controller ------------------
285
286
The controller knows the dataflow requirements of steps A and B: how much data
287
they want to accept in one chunk and how much they output in one chunk.  Its
288
function is to manage its buffer and call A and B at the proper times.
289
290
A data buffer control module may itself be viewed as a processing step by a
291
higher-level control module; thus the control modules form a binary tree with
292
elementary processing steps at the leaves of the tree.
293
294
The control modules are objects.  A considerable amount of flexibility can
295
be had by replacing implementations of a control module.  For example:
296
* Merging of adjacent steps in the pipeline is done by replacing a control
297
  module and its pair of processing-step modules with a single processing-
298
  step module.  (Hence the possible merges are determined by the tree of
299
  control modules.)
300
* In some processing modes, a given interstep buffer need only be a "strip"
301
  buffer large enough to accommodate the desired data chunk sizes.  In other
302
  modes, a full-image buffer is needed and several passes are required.
303
  The control module determines which kind of buffer is used and manipulates
304
  virtual array buffers as needed.  One or both processing steps may be
305
  unaware of the multi-pass behavior.
306
307
In theory, we might be able to make all of the data buffer controllers
308
interchangeable and provide just one set of implementations for all.  In
309
practice, each one contains considerable special-case processing for its
310
particular job.  The buffer controller concept should be regarded as an
311
overall system structuring principle, not as a complete description of the
312
task performed by any one controller.
313
314
315
*** Compression object structure ***
316
317
Here is a sketch of the logical structure of the JPEG compression library:
318
319
                                                 |-- Colorspace conversion
320
                  |-- Preprocessing controller --|
321
                  |                              |-- Downsampling
322
Main controller --|
323
                  |                            |-- Forward DCT, quantize
324
                  |-- Coefficient controller --|
325
                                               |-- Entropy encoding
326
327
This sketch also describes the flow of control (subroutine calls) during
328
typical image data processing.  Each of the components shown in the diagram is
329
an "object" which may have several different implementations available.  One
330
or more source code files contain the actual implementation(s) of each object.
331
332
The objects shown above are:
333
334
* Main controller: buffer controller for the subsampled-data buffer, which
335
  holds the preprocessed input data.  This controller invokes preprocessing to
336
  fill the subsampled-data buffer, and JPEG compression to empty it.  There is
337
  usually no need for a full-image buffer here; a strip buffer is adequate.
338
339
* Preprocessing controller: buffer controller for the downsampling input data
340
  buffer, which lies between colorspace conversion and downsampling.  Note
341
  that a unified conversion/downsampling module would probably replace this
342
  controller entirely.
343
344
* Colorspace conversion: converts application image data into the desired
345
  JPEG color space; also changes the data from pixel-interleaved layout to
346
  separate component planes.  Processes one pixel row at a time.
347
348
* Downsampling: performs reduction of chroma components as required.
349
  Optionally may perform pixel-level smoothing as well.  Processes a "row
350
  group" at a time, where a row group is defined as Vmax pixel rows of each
351
  component before downsampling, and Vk sample rows afterwards (remember Vk
352
  differs across components).  Some downsampling or smoothing algorithms may
353
  require context rows above and below the current row group; the
354
  preprocessing controller is responsible for supplying these rows via proper
355
  buffering.  The downsampler is responsible for edge expansion at the right
356
  edge (i.e., extending each sample row to a multiple of 8 samples); but the
357
  preprocessing controller is responsible for vertical edge expansion (i.e.,
358
  duplicating the bottom sample row as needed to make a multiple of 8 rows).
359
360
* Coefficient controller: buffer controller for the DCT-coefficient data.
361
  This controller handles MCU assembly, including insertion of dummy DCT
362
  blocks when needed at the right or bottom edge.  When performing
363
  Huffman-code optimization or emitting a multiscan JPEG file, this
364
  controller is responsible for buffering the full image.  The equivalent of
365
  one fully interleaved MCU row of subsampled data is processed per call,
366
  even when the JPEG file is noninterleaved.
367
368
* Forward DCT and quantization: Perform DCT, quantize, and emit coefficients.
369
  Works on one or more DCT blocks at a time.  (Note: the coefficients are now
370
  emitted in normal array order, which the entropy encoder is expected to
371
  convert to zigzag order as necessary.  Prior versions of the IJG code did
372
  the conversion to zigzag order within the quantization step.)
373
374
* Entropy encoding: Perform Huffman or arithmetic entropy coding and emit the
375
  coded data to the data destination module.  Works on one MCU per call.
376
  For progressive JPEG, the same DCT blocks are fed to the entropy coder
377
  during each pass, and the coder must emit the appropriate subset of
378
  coefficients.
379
380
In addition to the above objects, the compression library includes these
381
objects:
382
383
* Master control: determines the number of passes required, controls overall
384
  and per-pass initialization of the other modules.
385
386
* Marker writing: generates JPEG markers (except for RSTn, which is emitted
387
  by the entropy encoder when needed).
388
389
* Data destination manager: writes the output JPEG datastream to its final
390
  destination (e.g., a file).  The destination manager supplied with the
391
  library knows how to write to a stdio stream; for other behaviors, the
392
  surrounding application may provide its own destination manager.
393
394
* Memory manager: allocates and releases memory, controls virtual arrays
395
  (with backing store management, where required).
396
397
* Error handler: performs formatting and output of error and trace messages;
398
  determines handling of nonfatal errors.  The surrounding application may
399
  override some or all of this object's methods to change error handling.
400
401
* Progress monitor: supports output of "percent-done" progress reports.
402
  This object represents an optional callback to the surrounding application:
403
  if wanted, it must be supplied by the application.
404
405
The error handler, destination manager, and progress monitor objects are
406
defined as separate objects in order to simplify application-specific
407
customization of the JPEG library.  A surrounding application may override
408
individual methods or supply its own all-new implementation of one of these
409
objects.  The object interfaces for these objects are therefore treated as
410
part of the application interface of the library, whereas the other objects
411
are internal to the library.
412
413
The error handler and memory manager are shared by JPEG compression and
414
decompression; the progress monitor, if used, may be shared as well.
415
416
417
*** Decompression object structure ***
418
419
Here is a sketch of the logical structure of the JPEG decompression library:
420
421
                                               |-- Entropy decoding
422
                  |-- Coefficient controller --|
423
                  |                            |-- Dequantize, Inverse DCT
424
Main controller --|
425
                  |                               |-- Upsampling
426
                  |-- Postprocessing controller --|   |-- Colorspace conversion
427
                                                  |-- Color quantization
428
                                                  |-- Color precision reduction
429
430
As before, this diagram also represents typical control flow.  The objects
431
shown are:
432
433
* Main controller: buffer controller for the subsampled-data buffer, which
434
  holds the output of JPEG decompression proper.  This controller's primary
435
  task is to feed the postprocessing procedure.  Some upsampling algorithms
436
  may require context rows above and below the current row group; when this
437
  is true, the main controller is responsible for managing its buffer so as
438
  to make context rows available.  In the current design, the main buffer is
439
  always a strip buffer; a full-image buffer is never required.
440
441
* Coefficient controller: buffer controller for the DCT-coefficient data.
442
  This controller handles MCU disassembly, including deletion of any dummy
443
  DCT blocks at the right or bottom edge.  When reading a multiscan JPEG
444
  file, this controller is responsible for buffering the full image.
445
  (Buffering DCT coefficients, rather than samples, is necessary to support
446
  progressive JPEG.)  The equivalent of one fully interleaved MCU row of
447
  subsampled data is processed per call, even when the source JPEG file is
448
  noninterleaved.
449
450
* Entropy decoding: Read coded data from the data source module and perform
451
  Huffman or arithmetic entropy decoding.  Works on one MCU per call.
452
  For progressive JPEG decoding, the coefficient controller supplies the prior
453
  coefficients of each MCU (initially all zeroes), which the entropy decoder
454
  modifies in each scan.
455
456
* Dequantization and inverse DCT: like it says.  Note that the coefficients
457
  buffered by the coefficient controller have NOT been dequantized; we
458
  merge dequantization and inverse DCT into a single step for speed reasons.
459
  When scaled-down output is asked for, simplified DCT algorithms may be used
460
  that emit only 1x1, 2x2, or 4x4 samples per DCT block, not the full 8x8.
461
  Works on one DCT block at a time.
462
463
* Postprocessing controller: buffer controller for the color quantization
464
  input buffer, when quantization is in use.  (Without quantization, this
465
  controller just calls the upsampler.)  For two-pass quantization, this
466
  controller is responsible for buffering the full-image data.
467
468
* Upsampling: restores chroma components to full size.  (May support more
469
  general output rescaling, too.  Note that if undersized DCT outputs have
470
  been emitted by the DCT module, this module must adjust so that properly
471
  sized outputs are created.)  Works on one row group at a time.  This module
472
  also calls the color conversion module, so its top level is effectively a
473
  buffer controller for the upsampling->color conversion buffer.  However, in
474
  all but the highest-quality operating modes, upsampling and color
475
  conversion are likely to be merged into a single step.
476
477
* Colorspace conversion: convert from JPEG color space to output color space,
478
  and change data layout from separate component planes to pixel-interleaved.
479
  Works on one pixel row at a time.
480
481
* Color quantization: reduce the data to colormapped form, using either an
482
  externally specified colormap or an internally generated one.  This module
483
  is not used for full-color output.  Works on one pixel row at a time; may
484
  require two passes to generate a color map.  Note that the output will
485
  always be a single component representing colormap indexes.  In the current
486
  design, the output values are JSAMPLEs, so an 8-bit compilation cannot
487
  quantize to more than 256 colors.  This is unlikely to be a problem in
488
  practice.
489
490
* Color reduction: this module handles color precision reduction, e.g.,
491
  generating 15-bit color (5 bits/primary) from JPEG's 24-bit output.
492
  Not quite clear yet how this should be handled... should we merge it with
493
  colorspace conversion???
494
495
Note that some high-speed operating modes might condense the entire
496
postprocessing sequence to a single module (upsample, color convert, and
497
quantize in one step).
498
499
In addition to the above objects, the decompression library includes these
500
objects:
501
502
* Master control: determines the number of passes required, controls overall
503
  and per-pass initialization of the other modules.  This is subdivided into
504
  input and output control: jdinput.c controls only input-side processing,
505
  while jdmaster.c handles overall initialization and output-side control.
506
507
* Marker reading: decodes JPEG markers (except for RSTn).
508
509
* Data source manager: supplies the input JPEG datastream.  The source
510
  manager supplied with the library knows how to read from a stdio stream;
511
  for other behaviors, the surrounding application may provide its own source
512
  manager.
513
514
* Memory manager: same as for compression library.
515
516
* Error handler: same as for compression library.
517
518
* Progress monitor: same as for compression library.
519
520
As with compression, the data source manager, error handler, and progress
521
monitor are candidates for replacement by a surrounding application.
522
523
524
*** Decompression input and output separation ***
525
526
To support efficient incremental display of progressive JPEG files, the
527
decompressor is divided into two sections that can run independently:
528
529
1. Data input includes marker parsing, entropy decoding, and input into the
530
   coefficient controller's DCT coefficient buffer.  Note that this
531
   processing is relatively cheap and fast.
532
533
2. Data output reads from the DCT coefficient buffer and performs the IDCT
534
   and all postprocessing steps.
535
536
For a progressive JPEG file, the data input processing is allowed to get
537
arbitrarily far ahead of the data output processing.  (This occurs only
538
if the application calls jpeg_consume_input(); otherwise input and output
539
run in lockstep, since the input section is called only when the output
540
section needs more data.)  In this way the application can avoid making
541
extra display passes when data is arriving faster than the display pass
542
can run.  Furthermore, it is possible to abort an output pass without
543
losing anything, since the coefficient buffer is read-only as far as the
544
output section is concerned.  See libjpeg.doc for more detail.
545
546
A full-image coefficient array is only created if the JPEG file has multiple
547
scans (or if the application specifies buffered-image mode anyway).  When
548
reading a single-scan file, the coefficient controller normally creates only
549
a one-MCU buffer, so input and output processing must run in lockstep in this
550
case.  jpeg_consume_input() is effectively a no-op in this situation.
551
552
The main impact of dividing the decompressor in this fashion is that we must
553
be very careful with shared variables in the cinfo data structure.  Each
554
variable that can change during the course of decompression must be
555
classified as belonging to data input or data output, and each section must
556
look only at its own variables.  For example, the data output section may not
557
depend on any of the variables that describe the current scan in the JPEG
558
file, because these may change as the data input section advances into a new
559
scan.
560
561
The progress monitor is (somewhat arbitrarily) defined to treat input of the
562
file as one pass when buffered-image mode is not used, and to ignore data
563
input work completely when buffered-image mode is used.  Note that the
564
library has no reliable way to predict the number of passes when dealing
565
with a progressive JPEG file, nor can it predict the number of output passes
566
in buffered-image mode.  So the work estimate is inherently bogus anyway.
567
568
No comparable division is currently made in the compression library, because
569
there isn't any real need for it.
570
571
572
*** Data formats ***
573
574
Arrays of pixel sample values use the following data structure:
575
576
    typedef something JSAMPLE;		a pixel component value, 0..MAXJSAMPLE
577
    typedef JSAMPLE *JSAMPROW;		ptr to a row of samples
578
    typedef JSAMPROW *JSAMPARRAY;	ptr to a list of rows
579
    typedef JSAMPARRAY *JSAMPIMAGE;	ptr to a list of color-component arrays
580
581
The basic element type JSAMPLE will typically be one of unsigned char,
582
(signed) char, or short.  Short will be used if samples wider than 8 bits are
583
to be supported (this is a compile-time option).  Otherwise, unsigned char is
584
used if possible.  If the compiler only supports signed chars, then it is
585
necessary to mask off the value when reading.  Thus, all reads of JSAMPLE
586
values must be coded as "GETJSAMPLE(value)", where the macro will be defined
587
as "((value) & 0xFF)" on signed-char machines and "((int) (value))" elsewhere.
588
589
With these conventions, JSAMPLE values can be assumed to be >= 0.  This helps
590
simplify correct rounding during downsampling, etc.  The JPEG standard's
591
specification that sample values run from -128..127 is accommodated by
592
subtracting 128 just as the sample value is copied into the source array for
593
the DCT step (this will be an array of signed ints).  Similarly, during
594
decompression the output of the IDCT step will be immediately shifted back to
595
0..255.  (NB: different values are required when 12-bit samples are in use.
596
The code is written in terms of MAXJSAMPLE and CENTERJSAMPLE, which will be
597
defined as 255 and 128 respectively in an 8-bit implementation, and as 4095
598
and 2048 in a 12-bit implementation.)
599
600
We use a pointer per row, rather than a two-dimensional JSAMPLE array.  This
601
choice costs only a small amount of memory and has several benefits:
602
* Code using the data structure doesn't need to know the allocated width of
603
  the rows.  This simplifies edge expansion/compression, since we can work
604
  in an array that's wider than the logical picture width.
605
* Indexing doesn't require multiplication; this is a performance win on many
606
  machines.
607
* Arrays with more than 64K total elements can be supported even on machines
608
  where malloc() cannot allocate chunks larger than 64K.
609
* The rows forming a component array may be allocated at different times
610
  without extra copying.  This trick allows some speedups in smoothing steps
611
  that need access to the previous and next rows.
612
613
Note that each color component is stored in a separate array; we don't use the
614
traditional layout in which the components of a pixel are stored together.
615
This simplifies coding of modules that work on each component independently,
616
because they don't need to know how many components there are.  Furthermore,
617
we can read or write each component to a temporary file independently, which
618
is helpful when dealing with noninterleaved JPEG files.
619
620
In general, a specific sample value is accessed by code such as
621
	GETJSAMPLE(image[colorcomponent][row][col])
622
where col is measured from the image left edge, but row is measured from the
623
first sample row currently in memory.  Either of the first two indexings can
624
be precomputed by copying the relevant pointer.
625
626
627
Since most image-processing applications prefer to work on images in which
628
the components of a pixel are stored together, the data passed to or from the
629
surrounding application uses the traditional convention: a single pixel is
630
represented by N consecutive JSAMPLE values, and an image row is an array of
631
(# of color components)*(image width) JSAMPLEs.  One or more rows of data can
632
be represented by a pointer of type JSAMPARRAY in this scheme.  This scheme is
633
converted to component-wise storage inside the JPEG library.  (Applications
634
that want to skip JPEG preprocessing or postprocessing will have to contend
635
with component-wise storage.)
636
637
638
Arrays of DCT-coefficient values use the following data structure:
639
640
    typedef short JCOEF;		a 16-bit signed integer
641
    typedef JCOEF JBLOCK[DCTSIZE2];	an 8x8 block of coefficients
642
    typedef JBLOCK *JBLOCKROW;		ptr to one horizontal row of 8x8 blocks
643
    typedef JBLOCKROW *JBLOCKARRAY;	ptr to a list of such rows
644
    typedef JBLOCKARRAY *JBLOCKIMAGE;	ptr to a list of color component arrays
645
646
The underlying type is at least a 16-bit signed integer; while "short" is big
647
enough on all machines of interest, on some machines it is preferable to use
648
"int" for speed reasons, despite the storage cost.  Coefficients are grouped
649
into 8x8 blocks (but we always use #defines DCTSIZE and DCTSIZE2 rather than
650
"8" and "64").
651
652
The contents of a coefficient block may be in either "natural" or zigzagged
653
order, and may be true values or divided by the quantization coefficients,
654
depending on where the block is in the processing pipeline.  In the current
655
library, coefficient blocks are kept in natural order everywhere; the entropy
656
codecs zigzag or dezigzag the data as it is written or read.  The blocks
657
contain quantized coefficients everywhere outside the DCT/IDCT subsystems.
658
(This latter decision may need to be revisited to support variable
659
quantization a la JPEG Part 3.)
660
661
Notice that the allocation unit is now a row of 8x8 blocks, corresponding to
662
eight rows of samples.  Otherwise the structure is much the same as for
663
samples, and for the same reasons.
664
665
On machines where malloc() can't handle a request bigger than 64Kb, this data
666
structure limits us to rows of less than 512 JBLOCKs, or a picture width of
667
4000+ pixels.  This seems an acceptable restriction.
668
669
670
On 80x86 machines, the bottom-level pointer types (JSAMPROW and JBLOCKROW)
671
must be declared as "far" pointers, but the upper levels can be "near"
672
(implying that the pointer lists are allocated in the DS segment).
673
We use a #define symbol FAR, which expands to the "far" keyword when
674
compiling on 80x86 machines and to nothing elsewhere.
675
676
677
*** Suspendable processing ***
678
679
In some applications it is desirable to use the JPEG library as an
680
incremental, memory-to-memory filter.  In this situation the data source or
681
destination may be a limited-size buffer, and we can't rely on being able to
682
empty or refill the buffer at arbitrary times.  Instead the application would
683
like to have control return from the library at buffer overflow/underrun, and
684
then resume compression or decompression at a later time.
685
686
This scenario is supported for simple cases.  (For anything more complex, we
687
recommend that the application "bite the bullet" and develop real multitasking
688
capability.)  The libjpeg.doc file goes into more detail about the usage and
689
limitations of this capability; here we address the implications for library
690
structure.
691
692
The essence of the problem is that the entropy codec (coder or decoder) must
693
be prepared to stop at arbitrary times.  In turn, the controllers that call
694
the entropy codec must be able to stop before having produced or consumed all
695
the data that they normally would handle in one call.  That part is reasonably
696
straightforward: we make the controller call interfaces include "progress
697
counters" which indicate the number of data chunks successfully processed, and
698
we require callers to test the counter rather than just assume all of the data
699
was processed.
700
701
Rather than trying to restart at an arbitrary point, the current Huffman
702
codecs are designed to restart at the beginning of the current MCU after a
703
suspension due to buffer overflow/underrun.  At the start of each call, the
704
codec's internal state is loaded from permanent storage (in the JPEG object
705
structures) into local variables.  On successful completion of the MCU, the
706
permanent state is updated.  (This copying is not very expensive, and may even
707
lead to *improved* performance if the local variables can be registerized.)
708
If a suspension occurs, the codec simply returns without updating the state,
709
thus effectively reverting to the start of the MCU.  Note that this implies
710
leaving some data unprocessed in the source/destination buffer (ie, the
711
compressed partial MCU).  The data source/destination module interfaces are
712
specified so as to make this possible.  This also implies that the data buffer
713
must be large enough to hold a worst-case compressed MCU; a couple thousand
714
bytes should be enough.
715
716
In a successive-approximation AC refinement scan, the progressive Huffman
717
decoder has to be able to undo assignments of newly nonzero coefficients if it
718
suspends before the MCU is complete, since decoding requires distinguishing
719
previously-zero and previously-nonzero coefficients.  This is a bit tedious
720
but probably won't have much effect on performance.  Other variants of Huffman
721
decoding need not worry about this, since they will just store the same values
722
again if forced to repeat the MCU.
723
724
This approach would probably not work for an arithmetic codec, since its
725
modifiable state is quite large and couldn't be copied cheaply.  Instead it
726
would have to suspend and resume exactly at the point of the buffer end.
727
728
The JPEG marker reader is designed to cope with suspension at an arbitrary
729
point.  It does so by backing up to the start of the marker parameter segment,
730
so the data buffer must be big enough to hold the largest marker of interest.
731
Again, a couple KB should be adequate.  (A special "skip" convention is used
732
to bypass COM and APPn markers, so these can be larger than the buffer size
733
without causing problems; otherwise a 64K buffer would be needed in the worst
734
case.)
735
736
The JPEG marker writer currently does *not* cope with suspension.  I feel that
737
this is not necessary; it is much easier simply to require the application to
738
ensure there is enough buffer space before starting.  (An empty 2K buffer is
739
more than sufficient for the header markers; and ensuring there are a dozen or
740
two bytes available before calling jpeg_finish_compress() will suffice for the
741
trailer.)  This would not work for writing multi-scan JPEG files, but
742
we simply do not intend to support that capability with suspension.
743
744
745
*** Memory manager services ***
746
747
The JPEG library's memory manager controls allocation and deallocation of
748
memory, and it manages large "virtual" data arrays on machines where the
749
operating system does not provide virtual memory.  Note that the same
750
memory manager serves both compression and decompression operations.
751
752
In all cases, allocated objects are tied to a particular compression or
753
decompression master record, and they will be released when that master
754
record is destroyed.
755
756
The memory manager does not provide explicit deallocation of objects.
757
Instead, objects are created in "pools" of free storage, and a whole pool
758
can be freed at once.  This approach helps prevent storage-leak bugs, and
759
it speeds up operations whenever malloc/free are slow (as they often are).
760
The pools can be regarded as lifetime identifiers for objects.  Two
761
pools/lifetimes are defined:
762
  * JPOOL_PERMANENT	lasts until master record is destroyed
763
  * JPOOL_IMAGE		lasts until done with image (JPEG datastream)
764
Permanent lifetime is used for parameters and tables that should be carried
765
across from one datastream to another; this includes all application-visible
766
parameters.  Image lifetime is used for everything else.  (A third lifetime,
767
JPOOL_PASS = one processing pass, was originally planned.  However it was
768
dropped as not being worthwhile.  The actual usage patterns are such that the
769
peak memory usage would be about the same anyway; and having per-pass storage
770
substantially complicates the virtual memory allocation rules --- see below.)
771
772
The memory manager deals with three kinds of object:
773
1. "Small" objects.  Typically these require no more than 10K-20K total.
774
2. "Large" objects.  These may require tens to hundreds of K depending on
775
   image size.  Semantically they behave the same as small objects, but we
776
   distinguish them for two reasons:
777
     * On MS-DOS machines, large objects are referenced by FAR pointers,
778
       small objects by NEAR pointers.
779
     * Pool allocation heuristics may differ for large and small objects.
780
   Note that individual "large" objects cannot exceed the size allowed by
781
   type size_t, which may be 64K or less on some machines.
782
3. "Virtual" objects.  These are large 2-D arrays of JSAMPLEs or JBLOCKs
783
   (typically large enough for the entire image being processed).  The
784
   memory manager provides stripwise access to these arrays.  On machines
785
   without virtual memory, the rest of the array may be swapped out to a
786
   temporary file.
787
788
(Note: JSAMPARRAY and JBLOCKARRAY data structures are a combination of large
789
objects for the data proper and small objects for the row pointers.  For
790
convenience and speed, the memory manager provides single routines to create
791
these structures.  Similarly, virtual arrays include a small control block
792
and a JSAMPARRAY or JBLOCKARRAY working buffer, all created with one call.)
793
794
In the present implementation, virtual arrays are only permitted to have image
795
lifespan.  (Permanent lifespan would not be reasonable, and pass lifespan is
796
not very useful since a virtual array's raison d'etre is to store data for
797
multiple passes through the image.)  We also expect that only "small" objects
798
will be given permanent lifespan, though this restriction is not required by
799
the memory manager.
800
801
In a non-virtual-memory machine, some performance benefit can be gained by
802
making the in-memory buffers for virtual arrays be as large as possible.
803
(For small images, the buffers might fit entirely in memory, so blind
804
swapping would be very wasteful.)  The memory manager will adjust the height
805
of the buffers to fit within a prespecified maximum memory usage.  In order
806
to do this in a reasonably optimal fashion, the manager needs to allocate all
807
of the virtual arrays at once.  Therefore, there isn't a one-step allocation
808
routine for virtual arrays; instead, there is a "request" routine that simply
809
allocates the control block, and a "realize" routine (called just once) that
810
determines space allocation and creates all of the actual buffers.  The
811
realize routine must allow for space occupied by non-virtual large objects.
812
(We don't bother to factor in the space needed for small objects, on the
813
grounds that it isn't worth the trouble.)
814
815
To support all this, we establish the following protocol for doing business
816
with the memory manager:
817
  1. Modules must request virtual arrays (which may have only image lifespan)
818
     during the initial setup phase, i.e., in their jinit_xxx routines.
819
  2. All "large" objects (including JSAMPARRAYs and JBLOCKARRAYs) must also be
820
     allocated during initial setup.
821
  3. realize_virt_arrays will be called at the completion of initial setup.
822
     The above conventions ensure that sufficient information is available
823
     for it to choose a good size for virtual array buffers.
824
Small objects of any lifespan may be allocated at any time.  We expect that
825
the total space used for small objects will be small enough to be negligible
826
in the realize_virt_arrays computation.
827
828
In a virtual-memory machine, we simply pretend that the available space is
829
infinite, thus causing realize_virt_arrays to decide that it can allocate all
830
the virtual arrays as full-size in-memory buffers.  The overhead of the
831
virtual-array access protocol is very small when no swapping occurs.
832
833
A virtual array can be specified to be "pre-zeroed"; when this flag is set,
834
never-yet-written sections of the array are set to zero before being made
835
available to the caller.  If this flag is not set, never-written sections
836
of the array contain garbage.  (This feature exists primarily because the
837
equivalent logic would otherwise be needed in jdcoefct.c for progressive
838
JPEG mode; we may as well make it available for possible other uses.)
839
840
The first write pass on a virtual array is required to occur in top-to-bottom
841
order; read passes, as well as any write passes after the first one, may
842
access the array in any order.  This restriction exists partly to simplify
843
the virtual array control logic, and partly because some file systems may not
844
support seeking beyond the current end-of-file in a temporary file.  The main
845
implication of this restriction is that rearrangement of rows (such as
846
converting top-to-bottom data order to bottom-to-top) must be handled while
847
reading data out of the virtual array, not while putting it in.
848
849
850
*** Memory manager internal structure ***
851
852
To isolate system dependencies as much as possible, we have broken the
853
memory manager into two parts.  There is a reasonably system-independent
854
"front end" (jmemmgr.c) and a "back end" that contains only the code
855
likely to change across systems.  All of the memory management methods
856
outlined above are implemented by the front end.  The back end provides
857
the following routines for use by the front end (none of these routines
858
are known to the rest of the JPEG code):
859
860
jpeg_mem_init, jpeg_mem_term	system-dependent initialization/shutdown
861
862
jpeg_get_small, jpeg_free_small	interface to malloc and free library routines
863
				(or their equivalents)
864
865
jpeg_get_large, jpeg_free_large	interface to FAR malloc/free in MSDOS machines;
866
				else usually the same as
867
				jpeg_get_small/jpeg_free_small
868
869
jpeg_mem_available		estimate available memory
870
871
jpeg_open_backing_store		create a backing-store object
872
873
read_backing_store,		manipulate a backing-store object
874
write_backing_store,
875
close_backing_store
876
877
On some systems there will be more than one type of backing-store object
878
(specifically, in MS-DOS a backing store file might be an area of extended
879
memory as well as a disk file).  jpeg_open_backing_store is responsible for
880
choosing how to implement a given object.  The read/write/close routines
881
are method pointers in the structure that describes a given object; this
882
lets them be different for different object types.
883
884
It may be necessary to ensure that backing store objects are explicitly
885
released upon abnormal program termination.  For example, MS-DOS won't free
886
extended memory by itself.  To support this, we will expect the main program
887
or surrounding application to arrange to call self_destruct (typically via
888
jpeg_destroy) upon abnormal termination.  This may require a SIGINT signal
889
handler or equivalent.  We don't want to have the back end module install its
890
own signal handler, because that would pre-empt the surrounding application's
891
ability to control signal handling.
892
893
The IJG distribution includes several memory manager back end implementations.
894
Usually the same back end should be suitable for all applications on a given
895
system, but it is possible for an application to supply its own back end at
896
need.
897
898
899
*** Implications of DNL marker ***
900
901
Some JPEG files may use a DNL marker to postpone definition of the image
902
height (this would be useful for a fax-like scanner's output, for instance).
903
In these files the SOF marker claims the image height is 0, and you only
904
find out the true image height at the end of the first scan.
905
906
We could read these files as follows:
907
1. Upon seeing zero image height, replace it by 65535 (the maximum allowed).
908
2. When the DNL is found, update the image height in the global image
909
   descriptor.
910
This implies that control modules must avoid making copies of the image
911
height, and must re-test for termination after each MCU row.  This would
912
be easy enough to do.
913
914
In cases where image-size data structures are allocated, this approach will
915
result in very inefficient use of virtual memory or much-larger-than-necessary
916
temporary files.  This seems acceptable for something that probably won't be a
917
mainstream usage.  People might have to forgo use of memory-hogging options
918
(such as two-pass color quantization or noninterleaved JPEG files) if they
919
want efficient conversion of such files.  (One could improve efficiency by
920
demanding a user-supplied upper bound for the height, less than 65536; in most
921
cases it could be much less.)
922
923
The standard also permits the SOF marker to overestimate the image height,
924
with a DNL to give the true, smaller height at the end of the first scan.
925
This would solve the space problems if the overestimate wasn't too great.
926
However, it implies that you don't even know whether DNL will be used.
927
928
This leads to a couple of very serious objections:
929
1. Testing for a DNL marker must occur in the inner loop of the decompressor's
930
   Huffman decoder; this implies a speed penalty whether the feature is used
931
   or not.
932
2. There is no way to hide the last-minute change in image height from an
933
   application using the decoder.  Thus *every* application using the IJG
934
   library would suffer a complexity penalty whether it cared about DNL or
935
   not.
936
We currently do not support DNL because of these problems.
937
938
A different approach is to insist that DNL-using files be preprocessed by a
939
separate program that reads ahead to the DNL, then goes back and fixes the SOF
940
marker.  This is a much simpler solution and is probably far more efficient.
941
Even if one wants piped input, buffering the first scan of the JPEG file needs
942
a lot smaller temp file than is implied by the maximum-height method.  For
943
this approach we'd simply treat DNL as a no-op in the decompressor (at most,
944
check that it matches the SOF image height).
945
946
We will not worry about making the compressor capable of outputting DNL.
947
Something similar to the first scheme above could be applied if anyone ever
948
wants to make that work.
(-)a/jpeg/transupp.h (+210 lines)
Line     Link Here 
Line 0    Link Here 
1
/*
2
 * transupp.h
3
 *
4
 * Copyright (C) 1997-2009, 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 declarations for image transformation routines and
9
 * other utility code used by the jpegtran sample application.  These are
10
 * NOT part of the core JPEG library.  But we keep these routines separate
11
 * from jpegtran.c to ease the task of maintaining jpegtran-like programs
12
 * that have other user interfaces.
13
 *
14
 * NOTE: all the routines declared here have very specific requirements
15
 * about when they are to be executed during the reading and writing of the
16
 * source and destination files.  See the comments in transupp.c, or see
17
 * jpegtran.c for an example of correct usage.
18
 */
19
20
/* If you happen not to want the image transform support, disable it here */
21
#ifndef TRANSFORMS_SUPPORTED
22
#define TRANSFORMS_SUPPORTED 1		/* 0 disables transform code */
23
#endif
24
25
/*
26
 * Although rotating and flipping data expressed as DCT coefficients is not
27
 * hard, there is an asymmetry in the JPEG format specification for images
28
 * whose dimensions aren't multiples of the iMCU size.  The right and bottom
29
 * image edges are padded out to the next iMCU boundary with junk data; but
30
 * no padding is possible at the top and left edges.  If we were to flip
31
 * the whole image including the pad data, then pad garbage would become
32
 * visible at the top and/or left, and real pixels would disappear into the
33
 * pad margins --- perhaps permanently, since encoders & decoders may not
34
 * bother to preserve DCT blocks that appear to be completely outside the
35
 * nominal image area.  So, we have to exclude any partial iMCUs from the
36
 * basic transformation.
37
 *
38
 * Transpose is the only transformation that can handle partial iMCUs at the
39
 * right and bottom edges completely cleanly.  flip_h can flip partial iMCUs
40
 * at the bottom, but leaves any partial iMCUs at the right edge untouched.
41
 * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
42
 * The other transforms are defined as combinations of these basic transforms
43
 * and process edge blocks in a way that preserves the equivalence.
44
 *
45
 * The "trim" option causes untransformable partial iMCUs to be dropped;
46
 * this is not strictly lossless, but it usually gives the best-looking
47
 * result for odd-size images.  Note that when this option is active,
48
 * the expected mathematical equivalences between the transforms may not hold.
49
 * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
50
 * followed by -rot 180 -trim trims both edges.)
51
 *
52
 * We also offer a lossless-crop option, which discards data outside a given
53
 * image region but losslessly preserves what is inside.  Like the rotate and
54
 * flip transforms, lossless crop is restricted by the JPEG format: the upper
55
 * left corner of the selected region must fall on an iMCU boundary.  If this
56
 * does not hold for the given crop parameters, we silently move the upper left
57
 * corner up and/or left to make it so, simultaneously increasing the region
58
 * dimensions to keep the lower right crop corner unchanged.  (Thus, the
59
 * output image covers at least the requested region, but may cover more.)
60
 *
61
 * We also provide a lossless-resize option, which is kind of a lossless-crop
62
 * operation in the DCT coefficient block domain - it discards higher-order
63
 * coefficients and losslessly preserves lower-order coefficients of a
64
 * sub-block.
65
 *
66
 * Rotate/flip transform, resize, and crop can be requested together in a
67
 * single invocation.  The crop is applied last --- that is, the crop region
68
 * is specified in terms of the destination image after transform/resize.
69
 *
70
 * We also offer a "force to grayscale" option, which simply discards the
71
 * chrominance channels of a YCbCr image.  This is lossless in the sense that
72
 * the luminance channel is preserved exactly.  It's not the same kind of
73
 * thing as the rotate/flip transformations, but it's convenient to handle it
74
 * as part of this package, mainly because the transformation routines have to
75
 * be aware of the option to know how many components to work on.
76
 */
77
78
79
/* Short forms of external names for systems with brain-damaged linkers. */
80
81
#ifdef NEED_SHORT_EXTERNAL_NAMES
82
#define jtransform_parse_crop_spec	jTrParCrop
83
#define jtransform_request_workspace	jTrRequest
84
#define jtransform_adjust_parameters	jTrAdjust
85
#define jtransform_execute_transform	jTrExec
86
#define jtransform_perfect_transform	jTrPerfect
87
#define jcopy_markers_setup		jCMrkSetup
88
#define jcopy_markers_execute		jCMrkExec
89
#endif /* NEED_SHORT_EXTERNAL_NAMES */
90
91
92
/*
93
 * Codes for supported types of image transformations.
94
 */
95
96
typedef enum {
97
	JXFORM_NONE,		/* no transformation */
98
	JXFORM_FLIP_H,		/* horizontal flip */
99
	JXFORM_FLIP_V,		/* vertical flip */
100
	JXFORM_TRANSPOSE,	/* transpose across UL-to-LR axis */
101
	JXFORM_TRANSVERSE,	/* transpose across UR-to-LL axis */
102
	JXFORM_ROT_90,		/* 90-degree clockwise rotation */
103
	JXFORM_ROT_180,		/* 180-degree rotation */
104
	JXFORM_ROT_270		/* 270-degree clockwise (or 90 ccw) */
105
} JXFORM_CODE;
106
107
/*
108
 * Codes for crop parameters, which can individually be unspecified,
109
 * positive, or negative.  (Negative width or height makes no sense, though.)
110
 */
111
112
typedef enum {
113
	JCROP_UNSET,
114
	JCROP_POS,
115
	JCROP_NEG
116
} JCROP_CODE;
117
118
/*
119
 * Transform parameters struct.
120
 * NB: application must not change any elements of this struct after
121
 * calling jtransform_request_workspace.
122
 */
123
124
typedef struct {
125
  /* Options: set by caller */
126
  JXFORM_CODE transform;	/* image transform operator */
127
  boolean perfect;		/* if TRUE, fail if partial MCUs are requested */
128
  boolean trim;			/* if TRUE, trim partial MCUs as needed */
129
  boolean force_grayscale;	/* if TRUE, convert color image to grayscale */
130
  boolean crop;			/* if TRUE, crop source image */
131
132
  /* Crop parameters: application need not set these unless crop is TRUE.
133
   * These can be filled in by jtransform_parse_crop_spec().
134
   */
135
  JDIMENSION crop_width;	/* Width of selected region */
136
  JCROP_CODE crop_width_set;
137
  JDIMENSION crop_height;	/* Height of selected region */
138
  JCROP_CODE crop_height_set;
139
  JDIMENSION crop_xoffset;	/* X offset of selected region */
140
  JCROP_CODE crop_xoffset_set;	/* (negative measures from right edge) */
141
  JDIMENSION crop_yoffset;	/* Y offset of selected region */
142
  JCROP_CODE crop_yoffset_set;	/* (negative measures from bottom edge) */
143
144
  /* Internal workspace: caller should not touch these */
145
  int num_components;		/* # of components in workspace */
146
  jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
147
  JDIMENSION output_width;	/* cropped destination dimensions */
148
  JDIMENSION output_height;
149
  JDIMENSION x_crop_offset;	/* destination crop offsets measured in iMCUs */
150
  JDIMENSION y_crop_offset;
151
  int iMCU_sample_width;	/* destination iMCU size */
152
  int iMCU_sample_height;
153
} jpeg_transform_info;
154
155
156
#if TRANSFORMS_SUPPORTED
157
158
/* Parse a crop specification (written in X11 geometry style) */
159
EXTERN(boolean) jtransform_parse_crop_spec
160
	JPP((jpeg_transform_info *info, const char *spec));
161
/* Request any required workspace */
162
EXTERN(boolean) jtransform_request_workspace
163
	JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
164
/* Adjust output image parameters */
165
EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
166
	JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
167
	     jvirt_barray_ptr *src_coef_arrays,
168
	     jpeg_transform_info *info));
169
/* Execute the actual transformation, if any */
170
EXTERN(void) jtransform_execute_transform
171
	JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
172
	     jvirt_barray_ptr *src_coef_arrays,
173
	     jpeg_transform_info *info));
174
/* Determine whether lossless transformation is perfectly
175
 * possible for a specified image and transformation.
176
 */
177
EXTERN(boolean) jtransform_perfect_transform
178
	JPP((JDIMENSION image_width, JDIMENSION image_height,
179
	     int MCU_width, int MCU_height,
180
	     JXFORM_CODE transform));
181
182
/* jtransform_execute_transform used to be called
183
 * jtransform_execute_transformation, but some compilers complain about
184
 * routine names that long.  This macro is here to avoid breaking any
185
 * old source code that uses the original name...
186
 */
187
#define jtransform_execute_transformation	jtransform_execute_transform
188
189
#endif /* TRANSFORMS_SUPPORTED */
190
191
192
/*
193
 * Support for copying optional markers from source to destination file.
194
 */
195
196
typedef enum {
197
	JCOPYOPT_NONE,		/* copy no optional markers */
198
	JCOPYOPT_COMMENTS,	/* copy only comment (COM) markers */
199
	JCOPYOPT_ALL		/* copy all optional markers */
200
} JCOPY_OPTION;
201
202
#define JCOPYOPT_DEFAULT  JCOPYOPT_COMMENTS	/* recommended default */
203
204
/* Setup decompression object to save desired markers in memory */
205
EXTERN(void) jcopy_markers_setup
206
	JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
207
/* Copy markers saved in the given source object to the destination object */
208
EXTERN(void) jcopy_markers_execute
209
	JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
210
	     JCOPY_OPTION option));
(-)a/jpeg/usage.doc (-562 lines)
Line     Link Here 
 Lines 1-562    Link Here 
1
USAGE instructions for the Independent JPEG Group's JPEG software
2
=================================================================
3
4
This file describes usage of the JPEG conversion programs cjpeg and djpeg,
5
as well as the utility programs jpegtran, rdjpgcom and wrjpgcom.  (See
6
the other documentation files if you wish to use the JPEG library within
7
your own programs.)
8
9
If you are on a Unix machine you may prefer to read the Unix-style manual
10
pages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1.
11
12
13
INTRODUCTION
14
15
These programs implement JPEG image compression and decompression.  JPEG
16
(pronounced "jay-peg") is a standardized compression method for full-color
17
and gray-scale images.  JPEG is designed to handle "real-world" scenes,
18
for example scanned photographs.  Cartoons, line drawings, and other
19
non-realistic images are not JPEG's strong suit; on that sort of material
20
you may get poor image quality and/or little compression.
21
22
JPEG is lossy, meaning that the output image is not necessarily identical to
23
the input image.  Hence you should not use JPEG if you have to have identical
24
output bits.  However, on typical real-world images, very good compression
25
levels can be obtained with no visible change, and amazingly high compression
26
is possible if you can tolerate a low-quality image.  You can trade off image
27
quality against file size by adjusting the compressor's "quality" setting.
28
29
30
GENERAL USAGE
31
32
We provide two programs, cjpeg to compress an image file into JPEG format,
33
and djpeg to decompress a JPEG file back into a conventional image format.
34
35
On Unix-like systems, you say:
36
	cjpeg [switches] [imagefile] >jpegfile
37
or
38
	djpeg [switches] [jpegfile]  >imagefile
39
The programs read the specified input file, or standard input if none is
40
named.  They always write to standard output (with trace/error messages to
41
standard error).  These conventions are handy for piping images between
42
programs.
43
44
On most non-Unix systems, you say:
45
	cjpeg [switches] imagefile jpegfile
46
or
47
	djpeg [switches] jpegfile  imagefile
48
i.e., both the input and output files are named on the command line.  This
49
style is a little more foolproof, and it loses no functionality if you don't
50
have pipes.  (You can get this style on Unix too, if you prefer, by defining
51
TWO_FILE_COMMANDLINE when you compile the programs; see install.doc.)
52
53
You can also say:
54
	cjpeg [switches] -outfile jpegfile  imagefile
55
or
56
	djpeg [switches] -outfile imagefile  jpegfile
57
This syntax works on all systems, so it is useful for scripts.
58
59
The currently supported image file formats are: PPM (PBMPLUS color format),
60
PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit
61
format).  (RLE is supported only if the URT library is available.)
62
cjpeg recognizes the input image format automatically, with the exception
63
of some Targa-format files.  You have to tell djpeg which format to generate.
64
65
JPEG files are in the defacto standard JFIF file format.  There are other,
66
less widely used JPEG-based file formats, but we don't support them.
67
68
All switch names may be abbreviated; for example, -grayscale may be written
69
-gray or -gr.  Most of the "basic" switches can be abbreviated to as little as
70
one letter.  Upper and lower case are equivalent (-BMP is the same as -bmp).
71
British spellings are also accepted (e.g., -greyscale), though for brevity
72
these are not mentioned below.
73
74
75
CJPEG DETAILS
76
77
The basic command line switches for cjpeg are:
78
79
	-quality N	Scale quantization tables to adjust image quality.
80
			Quality is 0 (worst) to 100 (best); default is 75.
81
			(See below for more info.)
82
83
	-grayscale	Create monochrome JPEG file from color input.
84
			Be sure to use this switch when compressing a grayscale
85
			BMP file, because cjpeg isn't bright enough to notice
86
			whether a BMP file uses only shades of gray.  By
87
			saying -grayscale, you'll get a smaller JPEG file that
88
			takes less time to process.
89
90
	-optimize	Perform optimization of entropy encoding parameters.
91
			Without this, default encoding parameters are used.
92
			-optimize usually makes the JPEG file a little smaller,
93
			but cjpeg runs somewhat slower and needs much more
94
			memory.  Image quality and speed of decompression are
95
			unaffected by -optimize.
96
97
	-progressive	Create progressive JPEG file (see below).
98
99
	-targa		Input file is Targa format.  Targa files that contain
100
			an "identification" field will not be automatically
101
			recognized by cjpeg; for such files you must specify
102
			-targa to make cjpeg treat the input as Targa format.
103
			For most Targa files, you won't need this switch.
104
105
The -quality switch lets you trade off compressed file size against quality of
106
the reconstructed image: the higher the quality setting, the larger the JPEG
107
file, and the closer the output image will be to the original input.  Normally
108
you want to use the lowest quality setting (smallest file) that decompresses
109
into something visually indistinguishable from the original image.  For this
110
purpose the quality setting should be between 50 and 95; the default of 75 is
111
often about right.  If you see defects at -quality 75, then go up 5 or 10
112
counts at a time until you are happy with the output image.  (The optimal
113
setting will vary from one image to another.)
114
115
-quality 100 will generate a quantization table of all 1's, minimizing loss
116
in the quantization step (but there is still information loss in subsampling,
117
as well as roundoff error).  This setting is mainly of interest for
118
experimental purposes.  Quality values above about 95 are NOT recommended for
119
normal use; the compressed file size goes up dramatically for hardly any gain
120
in output image quality.
121
122
In the other direction, quality values below 50 will produce very small files
123
of low image quality.  Settings around 5 to 10 might be useful in preparing an
124
index of a large image library, for example.  Try -quality 2 (or so) for some
125
amusing Cubist effects.  (Note: quality values below about 25 generate 2-byte
126
quantization tables, which are considered optional in the JPEG standard.
127
cjpeg emits a warning message when you give such a quality value, because some
128
other JPEG programs may be unable to decode the resulting file.  Use -baseline
129
if you need to ensure compatibility at low quality values.)
130
131
The -progressive switch creates a "progressive JPEG" file.  In this type of
132
JPEG file, the data is stored in multiple scans of increasing quality.  If the
133
file is being transmitted over a slow communications link, the decoder can use
134
the first scan to display a low-quality image very quickly, and can then
135
improve the display with each subsequent scan.  The final image is exactly
136
equivalent to a standard JPEG file of the same quality setting, and the total
137
file size is about the same --- often a little smaller.  CAUTION: progressive
138
JPEG is not yet widely implemented, so many decoders will be unable to view a
139
progressive JPEG file at all.
140
141
Switches for advanced users:
142
143
	-dct int	Use integer DCT method (default).
144
	-dct fast	Use fast integer DCT (less accurate).
145
	-dct float	Use floating-point DCT method.
146
			The float method is very slightly more accurate than
147
			the int method, but is much slower unless your machine
148
			has very fast floating-point hardware.  Also note that
149
			results of the floating-point method may vary slightly
150
			across machines, while the integer methods should give
151
			the same results everywhere.  The fast integer method
152
			is much less accurate than the other two.
153
154
	-restart N	Emit a JPEG restart marker every N MCU rows, or every
155
			N MCU blocks if "B" is attached to the number.
156
			-restart 0 (the default) means no restart markers.
157
158
	-smooth N	Smooth the input image to eliminate dithering noise.
159
			N, ranging from 1 to 100, indicates the strength of
160
			smoothing.  0 (the default) means no smoothing.
161
162
	-maxmemory N	Set limit for amount of memory to use in processing
163
			large images.  Value is in thousands of bytes, or
164
			millions of bytes if "M" is attached to the number.
165
			For example, -max 4m selects 4000000 bytes.  If more
166
			space is needed, temporary files will be used.
167
168
	-verbose	Enable debug printout.  More -v's give more printout.
169
	or  -debug	Also, version information is printed at startup.
170
171
The -restart option inserts extra markers that allow a JPEG decoder to
172
resynchronize after a transmission error.  Without restart markers, any damage
173
to a compressed file will usually ruin the image from the point of the error
174
to the end of the image; with restart markers, the damage is usually confined
175
to the portion of the image up to the next restart marker.  Of course, the
176
restart markers occupy extra space.  We recommend -restart 1 for images that
177
will be transmitted across unreliable networks such as Usenet.
178
179
The -smooth option filters the input to eliminate fine-scale noise.  This is
180
often useful when converting dithered images to JPEG: a moderate smoothing
181
factor of 10 to 50 gets rid of dithering patterns in the input file, resulting
182
in a smaller JPEG file and a better-looking image.  Too large a smoothing
183
factor will visibly blur the image, however.
184
185
Switches for wizards:
186
187
	-baseline	Force baseline-compatible quantization tables to be
188
			generated.  This clamps quantization values to 8 bits
189
			even at low quality settings.  (This switch is poorly
190
			named, since it does not ensure that the output is
191
			actually baseline JPEG.  For example, you can use
192
			-baseline and -progressive together.)
193
194
	-qtables file	Use the quantization tables given in the specified
195
			text file.
196
197
	-qslots N[,...] Select which quantization table to use for each color
198
			component.
199
200
	-sample HxV[,...]  Set JPEG sampling factors for each color component.
201
202
	-scans file	Use the scan script given in the specified text file.
203
204
The "wizard" switches are intended for experimentation with JPEG.  If you
205
don't know what you are doing, DON'T USE THEM.  These switches are documented
206
further in the file wizard.doc.
207
208
209
DJPEG DETAILS
210
211
The basic command line switches for djpeg are:
212
213
	-colors N	Reduce image to at most N colors.  This reduces the
214
	or -quantize N	number of colors used in the output image, so that it
215
			can be displayed on a colormapped display or stored in
216
			a colormapped file format.  For example, if you have
217
			an 8-bit display, you'd need to reduce to 256 or fewer
218
			colors.  (-colors is the recommended name, -quantize
219
			is provided only for backwards compatibility.)
220
221
	-fast		Select recommended processing options for fast, low
222
			quality output.  (The default options are chosen for
223
			highest quality output.)  Currently, this is equivalent
224
			to "-dct fast -nosmooth -onepass -dither ordered".
225
226
	-grayscale	Force gray-scale output even if JPEG file is color.
227
			Useful for viewing on monochrome displays; also,
228
			djpeg runs noticeably faster in this mode.
229
230
	-scale M/N	Scale the output image by a factor M/N.  Currently
231
			the scale factor must be 1/1, 1/2, 1/4, or 1/8.
232
			Scaling is handy if the image is larger than your
233
			screen; also, djpeg runs much faster when scaling
234
			down the output.
235
236
	-bmp		Select BMP output format (Windows flavor).  8-bit
237
			colormapped format is emitted if -colors or -grayscale
238
			is specified, or if the JPEG file is gray-scale;
239
			otherwise, 24-bit full-color format is emitted.
240
241
	-gif		Select GIF output format.  Since GIF does not support
242
			more than 256 colors, -colors 256 is assumed (unless
243
			you specify a smaller number of colors).  If you
244
			specify -fast, the default number of colors is 216.
245
246
	-os2		Select BMP output format (OS/2 1.x flavor).  8-bit
247
			colormapped format is emitted if -colors or -grayscale
248
			is specified, or if the JPEG file is gray-scale;
249
			otherwise, 24-bit full-color format is emitted.
250
251
	-pnm		Select PBMPLUS (PPM/PGM) output format (this is the
252
			default format).  PGM is emitted if the JPEG file is
253
			gray-scale or if -grayscale is specified; otherwise
254
			PPM is emitted.
255
256
	-rle		Select RLE output format.  (Requires URT library.)
257
258
	-targa		Select Targa output format.  Gray-scale format is
259
			emitted if the JPEG file is gray-scale or if
260
			-grayscale is specified; otherwise, colormapped format
261
			is emitted if -colors is specified; otherwise, 24-bit
262
			full-color format is emitted.
263
264
Switches for advanced users:
265
266
	-dct int	Use integer DCT method (default).
267
	-dct fast	Use fast integer DCT (less accurate).
268
	-dct float	Use floating-point DCT method.
269
			The float method is very slightly more accurate than
270
			the int method, but is much slower unless your machine
271
			has very fast floating-point hardware.  Also note that
272
			results of the floating-point method may vary slightly
273
			across machines, while the integer methods should give
274
			the same results everywhere.  The fast integer method
275
			is much less accurate than the other two.
276
277
	-dither fs	Use Floyd-Steinberg dithering in color quantization.
278
	-dither ordered	Use ordered dithering in color quantization.
279
	-dither none	Do not use dithering in color quantization.
280
			By default, Floyd-Steinberg dithering is applied when
281
			quantizing colors; this is slow but usually produces
282
			the best results.  Ordered dither is a compromise
283
			between speed and quality; no dithering is fast but
284
			usually looks awful.  Note that these switches have
285
			no effect unless color quantization is being done.
286
			Ordered dither is only available in -onepass mode.
287
288
	-map FILE	Quantize to the colors used in the specified image
289
			file.  This is useful for producing multiple files
290
			with identical color maps, or for forcing a predefined
291
			set of colors to be used.  The FILE must be a GIF
292
			or PPM file.  This option overrides -colors and
293
			-onepass.
294
295
	-nosmooth	Use a faster, lower-quality upsampling routine.
296
297
	-onepass	Use one-pass instead of two-pass color quantization.
298
			The one-pass method is faster and needs less memory,
299
			but it produces a lower-quality image.  -onepass is
300
			ignored unless you also say -colors N.  Also,
301
			the one-pass method is always used for gray-scale
302
			output (the two-pass method is no improvement then).
303
304
	-maxmemory N	Set limit for amount of memory to use in processing
305
			large images.  Value is in thousands of bytes, or
306
			millions of bytes if "M" is attached to the number.
307
			For example, -max 4m selects 4000000 bytes.  If more
308
			space is needed, temporary files will be used.
309
310
	-verbose	Enable debug printout.  More -v's give more printout.
311
	or  -debug	Also, version information is printed at startup.
312
313
314
HINTS FOR CJPEG
315
316
Color GIF files are not the ideal input for JPEG; JPEG is really intended for
317
compressing full-color (24-bit) images.  In particular, don't try to convert
318
cartoons, line drawings, and other images that have only a few distinct
319
colors.  GIF works great on these, JPEG does not.  If you want to convert a
320
GIF to JPEG, you should experiment with cjpeg's -quality and -smooth options
321
to get a satisfactory conversion.  -smooth 10 or so is often helpful.
322
323
Avoid running an image through a series of JPEG compression/decompression
324
cycles.  Image quality loss will accumulate; after ten or so cycles the image
325
may be noticeably worse than it was after one cycle.  It's best to use a
326
lossless format while manipulating an image, then convert to JPEG format when
327
you are ready to file the image away.
328
329
The -optimize option to cjpeg is worth using when you are making a "final"
330
version for posting or archiving.  It's also a win when you are using low
331
quality settings to make very small JPEG files; the percentage improvement
332
is often a lot more than it is on larger files.  (At present, -optimize
333
mode is always selected when generating progressive JPEG files.)
334
335
GIF input files are no longer supported, to avoid the Unisys LZW patent.
336
Use a Unisys-licensed program if you need to read a GIF file.  (Conversion
337
of GIF files to JPEG is usually a bad idea anyway.)
338
339
340
HINTS FOR DJPEG
341
342
To get a quick preview of an image, use the -grayscale and/or -scale switches.
343
"-grayscale -scale 1/8" is the fastest case.
344
345
Several options are available that trade off image quality to gain speed.
346
"-fast" turns on the recommended settings.
347
348
"-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality.
349
When producing a color-quantized image, "-onepass -dither ordered" is fast but
350
much lower quality than the default behavior.  "-dither none" may give
351
acceptable results in two-pass mode, but is seldom tolerable in one-pass mode.
352
353
If you are fortunate enough to have very fast floating point hardware,
354
"-dct float" may be even faster than "-dct fast".  But on most machines
355
"-dct float" is slower than "-dct int"; in this case it is not worth using,
356
because its theoretical accuracy advantage is too small to be significant
357
in practice.
358
359
Two-pass color quantization requires a good deal of memory; on MS-DOS machines
360
it may run out of memory even with -maxmemory 0.  In that case you can still
361
decompress, with some loss of image quality, by specifying -onepass for
362
one-pass quantization.
363
364
To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files.  These
365
are larger than they should be, but are readable by standard GIF decoders.
366
367
368
HINTS FOR BOTH PROGRAMS
369
370
If more space is needed than will fit in the available main memory (as
371
determined by -maxmemory), temporary files will be used.  (MS-DOS versions
372
will try to get extended or expanded memory first.)  The temporary files are
373
often rather large: in typical cases they occupy three bytes per pixel, for
374
example 3*800*600 = 1.44Mb for an 800x600 image.  If you don't have enough
375
free disk space, leave out -progressive and -optimize (for cjpeg) or specify
376
-onepass (for djpeg).
377
378
On MS-DOS, the temporary files are created in the directory named by the TMP
379
or TEMP environment variable, or in the current directory if neither of those
380
exist.  Amiga implementations put the temp files in the directory named by
381
JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free
382
space.
383
384
The default memory usage limit (-maxmemory) is set when the software is
385
compiled.  If you get an "insufficient memory" error, try specifying a smaller
386
-maxmemory value, even -maxmemory 0 to use the absolute minimum space.  You
387
may want to recompile with a smaller default value if this happens often.
388
389
On machines that have "environment" variables, you can define the environment
390
variable JPEGMEM to set the default memory limit.  The value is specified as
391
described for the -maxmemory switch.  JPEGMEM overrides the default value
392
specified when the program was compiled, and itself is overridden by an
393
explicit -maxmemory switch.
394
395
On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to
396
use.  (Extended or expanded memory is also used if available.)  Most
397
DOS-specific versions of this software do their own memory space estimation
398
and do not need you to specify -maxmemory.
399
400
401
JPEGTRAN
402
403
jpegtran performs various useful transformations of JPEG files.
404
It can translate the coded representation from one variant of JPEG to another,
405
for example from baseline JPEG to progressive JPEG or vice versa.  It can also
406
perform some rearrangements of the image data, for example turning an image
407
from landscape to portrait format by rotation.
408
409
jpegtran works by rearranging the compressed data (DCT coefficients), without
410
ever fully decoding the image.  Therefore, its transformations are lossless:
411
there is no image degradation at all, which would not be true if you used
412
djpeg followed by cjpeg to accomplish the same conversion.  But by the same
413
token, jpegtran cannot perform lossy operations such as changing the image
414
quality.
415
416
jpegtran uses a command line syntax similar to cjpeg or djpeg.
417
On Unix-like systems, you say:
418
	jpegtran [switches] [inputfile] >outputfile
419
On most non-Unix systems, you say:
420
	jpegtran [switches] inputfile outputfile
421
where both the input and output files are JPEG files.
422
423
To specify the coded JPEG representation used in the output file,
424
jpegtran accepts a subset of the switches recognized by cjpeg:
425
	-optimize	Perform optimization of entropy encoding parameters.
426
	-progressive	Create progressive JPEG file.
427
	-restart N	Emit a JPEG restart marker every N MCU rows, or every
428
			N MCU blocks if "B" is attached to the number.
429
	-scans file	Use the scan script given in the specified text file.
430
See the previous discussion of cjpeg for more details about these switches.
431
If you specify none of these switches, you get a plain baseline-JPEG output
432
file.  The quality setting and so forth are determined by the input file.
433
434
The image can be losslessly transformed by giving one of these switches:
435
	-flip horizontal	Mirror image horizontally (left-right).
436
	-flip vertical		Mirror image vertically (top-bottom).
437
	-rotate 90		Rotate image 90 degrees clockwise.
438
	-rotate 180		Rotate image 180 degrees.
439
	-rotate 270		Rotate image 270 degrees clockwise (or 90 ccw).
440
	-transpose		Transpose image (across UL-to-LR axis).
441
	-transverse		Transverse transpose (across UR-to-LL axis).
442
443
The transpose transformation has no restrictions regarding image dimensions.
444
The other transformations operate rather oddly if the image dimensions are not
445
a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
446
transform complete blocks of DCT coefficient data in the desired way.
447
448
jpegtran's default behavior when transforming an odd-size image is designed
449
to preserve exact reversibility and mathematical consistency of the
450
transformation set.  As stated, transpose is able to flip the entire image
451
area.  Horizontal mirroring leaves any partial iMCU column at the right edge
452
untouched, but is able to flip all rows of the image.  Similarly, vertical
453
mirroring leaves any partial iMCU row at the bottom edge untouched, but is
454
able to flip all columns.  The other transforms can be built up as sequences
455
of transpose and flip operations; for consistency, their actions on edge
456
pixels are defined to be the same as the end result of the corresponding
457
transpose-and-flip sequence.
458
459
For practical use, you may prefer to discard any untransformable edge pixels
460
rather than having a strange-looking strip along the right and/or bottom edges
461
of a transformed image.  To do this, add the -trim switch:
462
	-trim		Drop non-transformable edge blocks.
463
Obviously, a transformation with -trim is not reversible, so strictly speaking
464
jpegtran with this switch is not lossless.  Also, the expected mathematical
465
equivalences between the transformations no longer hold.  For example,
466
"-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by
467
"-rot 180 -trim" trims both edges.
468
469
Another not-strictly-lossless transformation switch is:
470
	-grayscale	Force grayscale output.
471
This option discards the chrominance channels if the input image is YCbCr
472
(ie, a standard color JPEG), resulting in a grayscale JPEG file.  The
473
luminance channel is preserved exactly, so this is a better method of reducing
474
to grayscale than decompression, conversion, and recompression.  This switch
475
is particularly handy for fixing a monochrome picture that was mistakenly
476
encoded as a color JPEG.  (In such a case, the space savings from getting rid
477
of the near-empty chroma channels won't be large; but the decoding time for
478
a grayscale JPEG is substantially less than that for a color JPEG.)
479
480
jpegtran also recognizes these switches that control what to do with "extra"
481
markers, such as comment blocks:
482
	-copy none	Copy no extra markers from source file.  This setting
483
			suppresses all comments and other excess baggage
484
			present in the source file.
485
	-copy comments	Copy only comment markers.  This setting copies
486
			comments from the source file, but discards
487
			any other inessential data. 
488
	-copy all	Copy all extra markers.  This setting preserves
489
			miscellaneous markers found in the source file, such
490
			as JFIF thumbnails and Photoshop settings.  In some
491
			files these extra markers can be sizable.
492
The default behavior is -copy comments.  (Note: in IJG releases v6 and v6a,
493
jpegtran always did the equivalent of -copy none.)
494
495
Additional switches recognized by jpegtran are:
496
	-outfile filename
497
	-maxmemory N
498
	-verbose
499
	-debug
500
These work the same as in cjpeg or djpeg.
501
502
503
THE COMMENT UTILITIES
504
505
The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
506
Although the standard doesn't actually define what COM blocks are for, they
507
are widely used to hold user-supplied text strings.  This lets you add
508
annotations, titles, index terms, etc to your JPEG files, and later retrieve
509
them as text.  COM blocks do not interfere with the image stored in the JPEG
510
file.  The maximum size of a COM block is 64K, but you can have as many of
511
them as you like in one JPEG file.
512
513
We provide two utility programs to display COM block contents and add COM
514
blocks to a JPEG file.
515
516
rdjpgcom searches a JPEG file and prints the contents of any COM blocks on
517
standard output.  The command line syntax is
518
	rdjpgcom [-verbose] [inputfilename]
519
The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG
520
image dimensions.  If you omit the input file name from the command line,
521
the JPEG file is read from standard input.  (This may not work on some
522
operating systems, if binary data can't be read from stdin.)
523
524
wrjpgcom adds a COM block, containing text you provide, to a JPEG file.
525
Ordinarily, the COM block is added after any existing COM blocks, but you
526
can delete the old COM blocks if you wish.  wrjpgcom produces a new JPEG
527
file; it does not modify the input file.  DO NOT try to overwrite the input
528
file by directing wrjpgcom's output back into it; on most systems this will
529
just destroy your file.
530
531
The command line syntax for wrjpgcom is similar to cjpeg's.  On Unix-like
532
systems, it is
533
	wrjpgcom [switches] [inputfilename]
534
The output file is written to standard output.  The input file comes from
535
the named file, or from standard input if no input file is named.
536
537
On most non-Unix systems, the syntax is
538
	wrjpgcom [switches] inputfilename outputfilename
539
where both input and output file names must be given explicitly.
540
541
wrjpgcom understands three switches:
542
	-replace		 Delete any existing COM blocks from the file.
543
	-comment "Comment text"	 Supply new COM text on command line.
544
	-cfile name		 Read text for new COM block from named file.
545
(Switch names can be abbreviated.)  If you have only one line of comment text
546
to add, you can provide it on the command line with -comment.  The comment
547
text must be surrounded with quotes so that it is treated as a single
548
argument.  Longer comments can be read from a text file.
549
550
If you give neither -comment nor -cfile, then wrjpgcom will read the comment
551
text from standard input.  (In this case an input image file name MUST be
552
supplied, so that the source JPEG file comes from somewhere else.)  You can
553
enter multiple lines, up to 64KB worth.  Type an end-of-file indicator
554
(usually control-D or control-Z) to terminate the comment text entry.
555
556
wrjpgcom will not add a COM block if the provided comment string is empty.
557
Therefore -replace -comment "" can be used to delete all COM blocks from a
558
file.
559
560
These utility programs do not depend on the IJG JPEG library.  In
561
particular, the source code for rdjpgcom is intended as an illustration of
562
the minimum amount of code required to parse a JPEG file header correctly.
(-)a/jpeg/wizard.doc (-211 lines)
Line     Link Here 
 Lines 1-211    Link Here 
1
Advanced usage instructions for the Independent JPEG Group's JPEG software
2
==========================================================================
3
4
This file describes cjpeg's "switches for wizards".
5
6
The "wizard" switches are intended for experimentation with JPEG by persons
7
who are reasonably knowledgeable about the JPEG standard.  If you don't know
8
what you are doing, DON'T USE THESE SWITCHES.  You'll likely produce files
9
with worse image quality and/or poorer compression than you'd get from the
10
default settings.  Furthermore, these switches must be used with caution
11
when making files intended for general use, because not all JPEG decoders
12
will support unusual JPEG parameter settings.
13
14
15
Quantization Table Adjustment
16
-----------------------------
17
18
Ordinarily, cjpeg starts with a default set of tables (the same ones given
19
as examples in the JPEG standard) and scales them up or down according to
20
the -quality setting.  The details of the scaling algorithm can be found in
21
jcparam.c.  At very low quality settings, some quantization table entries
22
can get scaled up to values exceeding 255.  Although 2-byte quantization
23
values are supported by the IJG software, this feature is not in baseline
24
JPEG and is not supported by all implementations.  If you need to ensure
25
wide compatibility of low-quality files, you can constrain the scaled
26
quantization values to no more than 255 by giving the -baseline switch.
27
Note that use of -baseline will result in poorer quality for the same file
28
size, since more bits than necessary are expended on higher AC coefficients.
29
30
You can substitute a different set of quantization values by using the
31
-qtables switch:
32
33
	-qtables file	Use the quantization tables given in the named file.
34
35
The specified file should be a text file containing decimal quantization
36
values.  The file should contain one to four tables, each of 64 elements.
37
The tables are implicitly numbered 0,1,etc. in order of appearance.  Table
38
entries appear in normal array order (NOT in the zigzag order in which they
39
will be stored in the JPEG file).
40
41
Quantization table files are free format, in that arbitrary whitespace can
42
appear between numbers.  Also, comments can be included: a comment starts
43
with '#' and extends to the end of the line.  Here is an example file that
44
duplicates the default quantization tables:
45
46
	# Quantization tables given in JPEG spec, section K.1
47
48
	# This is table 0 (the luminance table):
49
	  16  11  10  16  24  40  51  61
50
	  12  12  14  19  26  58  60  55
51
	  14  13  16  24  40  57  69  56
52
	  14  17  22  29  51  87  80  62
53
	  18  22  37  56  68 109 103  77
54
	  24  35  55  64  81 104 113  92
55
	  49  64  78  87 103 121 120 101
56
	  72  92  95  98 112 100 103  99
57
58
	# This is table 1 (the chrominance table):
59
	  17  18  24  47  99  99  99  99
60
	  18  21  26  66  99  99  99  99
61
	  24  26  56  99  99  99  99  99
62
	  47  66  99  99  99  99  99  99
63
	  99  99  99  99  99  99  99  99
64
	  99  99  99  99  99  99  99  99
65
	  99  99  99  99  99  99  99  99
66
	  99  99  99  99  99  99  99  99
67
68
If the -qtables switch is used without -quality, then the specified tables
69
are used exactly as-is.  If both -qtables and -quality are used, then the
70
tables taken from the file are scaled in the same fashion that the default
71
tables would be scaled for that quality setting.  If -baseline appears, then
72
the quantization values are constrained to the range 1-255.
73
74
By default, cjpeg will use quantization table 0 for luminance components and
75
table 1 for chrominance components.  To override this choice, use the -qslots
76
switch:
77
78
	-qslots N[,...]		Select which quantization table to use for
79
				each color component.
80
81
The -qslots switch specifies a quantization table number for each color
82
component, in the order in which the components appear in the JPEG SOF marker.
83
For example, to create a separate table for each of Y,Cb,Cr, you could
84
provide a -qtables file that defines three quantization tables and say
85
"-qslots 0,1,2".  If -qslots gives fewer table numbers than there are color
86
components, then the last table number is repeated as necessary.
87
88
89
Sampling Factor Adjustment
90
--------------------------
91
92
By default, cjpeg uses 2:1 horizontal and vertical downsampling when
93
compressing YCbCr data, and no downsampling for all other color spaces.
94
You can override this default with the -sample switch:
95
96
	-sample HxV[,...]	Set JPEG sampling factors for each color
97
				component.
98
99
The -sample switch specifies the JPEG sampling factors for each color
100
component, in the order in which they appear in the JPEG SOF marker.
101
If you specify fewer HxV pairs than there are components, the remaining
102
components are set to 1x1 sampling.  For example, the default YCbCr setting
103
is equivalent to "-sample 2x2,1x1,1x1", which can be abbreviated to
104
"-sample 2x2".
105
106
There are still some JPEG decoders in existence that support only 2x1
107
sampling (also called 4:2:2 sampling).  Compatibility with such decoders can
108
be achieved by specifying "-sample 2x1".  This is not recommended unless
109
really necessary, since it increases file size and encoding/decoding time
110
with very little quality gain.
111
112
113
Multiple Scan / Progression Control
114
-----------------------------------
115
116
By default, cjpeg emits a single-scan sequential JPEG file.  The
117
-progressive switch generates a progressive JPEG file using a default series
118
of progression parameters.  You can create multiple-scan sequential JPEG
119
files or progressive JPEG files with custom progression parameters by using
120
the -scans switch:
121
122
	-scans file	Use the scan sequence given in the named file.
123
124
The specified file should be a text file containing a "scan script".
125
The script specifies the contents and ordering of the scans to be emitted.
126
Each entry in the script defines one scan.  A scan definition specifies
127
the components to be included in the scan, and for progressive JPEG it also
128
specifies the progression parameters Ss,Se,Ah,Al for the scan.  Scan
129
definitions are separated by semicolons (';').  A semicolon after the last
130
scan definition is optional.
131
132
Each scan definition contains one to four component indexes, optionally
133
followed by a colon (':') and the four progressive-JPEG parameters.  The
134
component indexes denote which color component(s) are to be transmitted in
135
the scan.  Components are numbered in the order in which they appear in the
136
JPEG SOF marker, with the first component being numbered 0.  (Note that these
137
indexes are not the "component ID" codes assigned to the components, just
138
positional indexes.)
139
140
The progression parameters for each scan are:
141
	Ss	Zigzag index of first coefficient included in scan
142
	Se	Zigzag index of last coefficient included in scan
143
	Ah	Zero for first scan of a coefficient, else Al of prior scan
144
	Al	Successive approximation low bit position for scan
145
If the progression parameters are omitted, the values 0,63,0,0 are used,
146
producing a sequential JPEG file.  cjpeg automatically determines whether
147
the script represents a progressive or sequential file, by observing whether
148
Ss and Se values other than 0 and 63 appear.  (The -progressive switch is
149
not needed to specify this; in fact, it is ignored when -scans appears.)
150
The scan script must meet the JPEG restrictions on progression sequences.
151
(cjpeg checks that the spec's requirements are obeyed.)
152
153
Scan script files are free format, in that arbitrary whitespace can appear
154
between numbers and around punctuation.  Also, comments can be included: a
155
comment starts with '#' and extends to the end of the line.  For additional
156
legibility, commas or dashes can be placed between values.  (Actually, any
157
single punctuation character other than ':' or ';' can be inserted.)  For
158
example, the following two scan definitions are equivalent:
159
	0 1 2: 0 63 0 0;
160
	0,1,2 : 0-63, 0,0 ;
161
162
Here is an example of a scan script that generates a partially interleaved
163
sequential JPEG file:
164
165
	0;			# Y only in first scan
166
	1 2;			# Cb and Cr in second scan
167
168
Here is an example of a progressive scan script using only spectral selection
169
(no successive approximation):
170
171
	# Interleaved DC scan for Y,Cb,Cr:
172
	0,1,2: 0-0,   0, 0 ;
173
	# AC scans:
174
	0:     1-2,   0, 0 ;	# First two Y AC coefficients
175
	0:     3-5,   0, 0 ;	# Three more
176
	1:     1-63,  0, 0 ;	# All AC coefficients for Cb
177
	2:     1-63,  0, 0 ;	# All AC coefficients for Cr
178
	0:     6-9,   0, 0 ;	# More Y coefficients
179
	0:     10-63, 0, 0 ;	# Remaining Y coefficients
180
181
Here is an example of a successive-approximation script.  This is equivalent
182
to the default script used by "cjpeg -progressive" for YCbCr images:
183
184
	# Initial DC scan for Y,Cb,Cr (lowest bit not sent)
185
	0,1,2: 0-0,   0, 1 ;
186
	# First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits:
187
	0:     1-5,   0, 2 ;
188
	# Send all Cr,Cb AC coefficients, minus lowest bit:
189
	# (chroma data is usually too small to be worth subdividing further;
190
	#  but note we send Cr first since eye is least sensitive to Cb)
191
	2:     1-63,  0, 1 ;
192
	1:     1-63,  0, 1 ;
193
	# Send remaining Y AC coefficients, minus 2 lowest bits:
194
	0:     6-63,  0, 2 ;
195
	# Send next-to-lowest bit of all Y AC coefficients:
196
	0:     1-63,  2, 1 ;
197
	# At this point we've sent all but the lowest bit of all coefficients.
198
	# Send lowest bit of DC coefficients
199
	0,1,2: 0-0,   1, 0 ;
200
	# Send lowest bit of AC coefficients
201
	2:     1-63,  1, 0 ;
202
	1:     1-63,  1, 0 ;
203
	# Y AC lowest bit scan is last; it's usually the largest scan
204
	0:     1-63,  1, 0 ;
205
206
It may be worth pointing out that this script is tuned for quality settings
207
of around 50 to 75.  For lower quality settings, you'd probably want to use
208
a script with fewer stages of successive approximation (otherwise the
209
initial scans will be really bad).  For higher quality settings, you might
210
want to use more stages of successive approximation (so that the initial
211
scans are not too large).

Return to bug 573948