patches/icedtea-libraries.patch
changeset 1623: 308c172cd230
parent 776:3ef0fc18a758
manifest: 308c172cd230
author: Gary Benson <gbenson@redhat.com>
date: Fri Jul 03 11:52:45 2009 +0100 (27 hours ago)
permissions: -rw-r--r--
2009-07-03 Gary Benson <gbenson@redhat.com>

* ports/hotspot/src/share/vm/shark/sharkEntry.hpp
(SharkEntry::print_statistics): Removed.
* ports/hotspot/src/share/vm/shark/sharkEntry.cpp: Removed.

* ports/hotspot/src/share/vm/shark/sharkCompiler.cpp
(SharkCompiler::compile_method): Save location of native code
across the call to ciEnv::register_method (which frees the buffer
blob it's in), and inline what was SharkEntry::print_statistics.

* ports/hotspot/src/share/vm/includeDB_shark: Updated.
        1 --- openjdk.old/jdk/make/sun/jpeg/Makefile	2007-10-12 03:54:08.000000000 -0400
        2 +++ openjdk/jdk/make/sun/jpeg/Makefile	2007-10-24 15:15:25.000000000 -0400
        3 @@ -68,6 +68,8 @@
        4  include $(BUILDDIR)/common/Mapfile-vers.gmk
        5  include $(BUILDDIR)/common/Library.gmk
        6  
        7 +LDLIBS += -ldl 
        8 +
        9  #
       10  # Add to ambient vpath to get files in a subdirectory
       11  #
       12 --- openjdk.old/jdk/src/share/native/sun/awt/splashscreen/splashscreen_png.c	2007-10-12 04:03:51.000000000 -0400
       13 +++ openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_png.c	2007-10-22 12:50:36.000000000 -0400
       14 @@ -25,7 +25,7 @@
       15  
       16  #include "splashscreen_impl.h"
       17  
       18 -#include "../libpng/png.h"
       19 +#include <png.h>
       20  
       21  #include <setjmp.h>
       22  
       23 --- openjdk.old/jdk/src/share/native/sun/awt/splashscreen/splashscreen_gif.c	2007-10-12 04:03:51.000000000 -0400
       24 +++ openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_gif.c	2007-10-22 12:50:36.000000000 -0400
       25 @@ -26,7 +26,7 @@
       26  #include "splashscreen_impl.h"
       27  #include "splashscreen_gfx.h"
       28  
       29 -#include "../giflib/gif_lib.h"
       30 +#include <gif_lib.h>
       31  
       32  #define GIF_TRANSPARENT     0x01
       33  #define GIF_USER_INPUT      0x02
       34 --- openjdk.old/jdk/src/share/native/java/util/zip/Adler32.c	2007-10-12 04:03:46.000000000 -0400
       35 +++ openjdk/jdk/src/share/native/java/util/zip/Adler32.c	2007-10-22 13:21:09.000000000 -0400
       36 @@ -29,7 +29,7 @@
       37  
       38  #include "jni.h"
       39  #include "jni_util.h"
       40 -#include "zlib.h"
       41 +#include <zlib.h>
       42  
       43  #include "java_util_zip_Adler32.h"
       44  
       45 --- openjdk.old/jdk/src/share/native/java/util/zip/Deflater.c	2007-10-12 04:03:46.000000000 -0400
       46 +++ openjdk/jdk/src/share/native/java/util/zip/Deflater.c	2007-10-22 13:22:34.000000000 -0400
       47 @@ -32,7 +32,7 @@
       48  #include "jlong.h"
       49  #include "jni.h"
       50  #include "jni_util.h"
       51 -#include "zlib.h"
       52 +#include <zlib.h>
       53  
       54  #include "java_util_zip_Deflater.h"
       55  
       56 --- openjdk.old/jdk/src/share/native/java/util/zip/CRC32.c	2007-10-12 04:03:46.000000000 -0400
       57 +++ openjdk/jdk/src/share/native/java/util/zip/CRC32.c	2007-10-22 13:23:08.000000000 -0400
       58 @@ -29,7 +29,7 @@
       59  
       60  #include "jni.h"
       61  #include "jni_util.h"
       62 -#include "zlib.h"
       63 +#include <zlib.h>
       64  
       65  #include "java_util_zip_CRC32.h"
       66  
       67 --- openjdk.old/jdk/make/common/Program.gmk	2007-10-12 03:54:05.000000000 -0400
       68 +++ openjdk/jdk/make/common/Program.gmk	2007-10-22 13:26:06.000000000 -0400
       69 @@ -85,7 +85,7 @@
       70  	endif
       71      endif
       72      ifeq ($(PLATFORM), linux)
       73 -	LDFLAGS += -z origin
       74 +	LDFLAGS += -lz -z origin
       75  	LDFLAGS += -Wl,--allow-shlib-undefined
       76  	LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH)/jli
       77  	LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH)/jli
       78 @@ -251,7 +251,6 @@
       79  endif
       80  
       81  OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)/bin -I$(LAUNCHER_PLATFORM_SRC)/bin
       82 -OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
       83  
       84  # this may not be necessary...
       85  ifeq ($(PLATFORM), windows)
       86 --- openjdk.old/jdk/make/java/zip/Makefile	2007-10-12 03:54:05.000000000 -0400
       87 +++ openjdk/jdk/make/java/zip/Makefile	2007-10-22 13:27:01.000000000 -0400
       88 @@ -30,8 +30,6 @@
       89  PRODUCT = sun
       90  include $(BUILDDIR)/common/Defs.gmk
       91  
       92 -ZLIB_VERSION = 1.1.3
       93 -
       94  #
       95  # Files to compile.
       96  #
       97 @@ -72,16 +70,10 @@
       98  CPPFLAGS += -UDEBUG 
       99  endif
      100  
      101 -CPPFLAGS += -I$(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
      102  CPPFLAGS += -I$(SHARE_SRC)/native/java/io
      103  CPPFLAGS += -I$(PLATFORM_SRC)/native/java/io
      104  
      105  #
      106 -# Add to ambient vpath so we pick up the library files
      107 -#
      108 -vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/zlib-$(ZLIB_VERSION)
      109 -
      110 -#
      111  # Link to JVM library for JVM_Zip* functions
      112  #
      113 -OTHER_LDLIBS = $(JVMLIB)
      114 +OTHER_LDLIBS = $(JVMLIB) -lz
      115 --- openjdk.old/jdk/make/java/zip/FILES_c.gmk	2007-10-12 03:54:05.000000000 -0400
      116 +++ openjdk/jdk/make/java/zip/FILES_c.gmk	2007-10-22 13:52:53.000000000 -0400
      117 @@ -30,15 +30,4 @@
      118  	Inflater.c \
      119  	ZipFile.c \
      120  	ZipEntry.c \
      121 -	zadler32.c \
      122 -	zcrc32.c \
      123 -	deflate.c \
      124 -	trees.c \
      125 -	zutil.c \
      126 -	inflate.c \
      127 -	infblock.c \
      128 -	inftrees.c \
      129 -	infcodes.c \
      130 -	infutil.c \
      131 -	inffast.c \
      132  	zip_util.c
      133 --- openjdk.old/jdk/src/share/native/java/util/zip/Inflater.c	2007-10-12 04:03:46.000000000 -0400
      134 +++ openjdk/jdk/src/share/native/java/util/zip/Inflater.c	2007-10-22 15:21:32.000000000 -0400
      135 @@ -35,7 +35,7 @@
      136  #include "jni.h"
      137  #include "jvm.h"
      138  #include "jni_util.h"
      139 -#include "zlib.h"
      140 +#include <zlib.h>
      141  #include "java_util_zip_Inflater.h"
      142  
      143  #define ThrowDataFormatException(env, msg) \
      144 --- openjdk.old/jdk/src/share/native/java/util/zip/zip_util.c	2007-10-12 04:03:46.000000000 -0400
      145 +++ openjdk/jdk/src/share/native/java/util/zip/zip_util.c	2007-10-23 14:33:18.000000000 -0400
      146 @@ -44,7 +44,8 @@
      147  #include "io_util.h"
      148  #include "io_util_md.h"
      149  #include "zip_util.h"
      150 -#include "zlib.h"
      151 +
      152 +#include <zlib.h>
      153  
      154  /* USE_MMAP means mmap the CEN & ENDHDR part of the zip file. */
      155  #ifdef USE_MMAP
      156 --- openjdk.old/jdk/make/sun/splashscreen/FILES_c.gmk	2007-10-12 03:54:08.000000000 -0400
      157 +++ openjdk/jdk/make/sun/splashscreen/FILES_c.gmk	2007-10-23 16:15:48.000000000 -0400
      158 @@ -30,81 +30,5 @@
      159  	splashscreen_impl.c \
      160  	splashscreen_jpeg.c \
      161  	splashscreen_png.c \
      162 -	splashscreen_sys.c \
      163 -	png.c \
      164 -	pngerror.c \
      165 -	pngget.c \
      166 -	pngmem.c  \
      167 -	pngpread.c \
      168 -	pngread.c \
      169 -	pngrio.c \
      170 -	pngrtran.c \
      171 -	pngrutil.c \
      172 -	pngset.c \
      173 -	pngtrans.c \
      174 -	pngwio.c \
      175 -	pngwrite.c \
      176 -	pngwtran.c \
      177 -	pngwutil.c \
      178 -	dgif_lib.c \
      179 -	gif_err.c \
      180 -	gifalloc.c \
      181 -	compress.c \
      182 -	deflate.c \
      183 -	gzio.c \
      184 -	infblock.c \
      185 -	infcodes.c \
      186 -	inffast.c \
      187 -	inflate.c \
      188 -	inftrees.c \
      189 -	infutil.c \
      190 -	trees.c \
      191 -	uncompr.c \
      192 -	zadler32.c \
      193 -	zcrc32.c \
      194 -	zutil.c \
      195 -	jcomapi.c \
      196 -	jdapimin.c \
      197 -	jdapistd.c \
      198 -	jdcoefct.c \
      199 -	jdcolor.c \
      200 -	jddctmgr.c \
      201 -	jdhuff.c \
      202 -	jdinput.c \
      203 -	jdmainct.c \
      204 -	jdmarker.c \
      205 -	jdmaster.c \
      206 -	jdmerge.c \
      207 -	jdphuff.c \
      208 -	jdpostct.c \
      209 -	jdsample.c \
      210 -	jerror.c \
      211 -	jidctflt.c \
      212 -	jidctfst.c \
      213 -	jidctint.c \
      214 -	jidctred.c \
      215 -	jmemmgr.c \
      216 -	jmemnobs.c \
      217 -	jquant1.c \
      218 -	jquant2.c \
      219 -	jutils.c \
      220 -	jcapimin.c \
      221 -	jcapistd.c \
      222 -	jccoefct.c \
      223 -	jccolor.c \
      224 -	jcdctmgr.c \
      225 -	jchuff.c \
      226 -	jcinit.c \
      227 -	jcmainct.c \
      228 -	jcmarker.c \
      229 -	jcmaster.c \
      230 -	jcparam.c \
      231 -	jcphuff.c \
      232 -	jcprepct.c \
      233 -	jcsample.c \
      234 -	jctrans.c \
      235 -	jdtrans.c \
      236 -	jfdctflt.c \
      237 -	jfdctfst.c \
      238 -	jfdctint.c
      239 +	splashscreen_sys.c 
      240  
      241 --- openjdk.old/jdk/make/sun/splashscreen/Makefile	2007-10-12 03:54:08.000000000 -0400
      242 +++ openjdk/jdk/make/sun/splashscreen/Makefile	2007-10-23 16:20:24.000000000 -0400
      243 @@ -59,12 +59,12 @@
      244  # C Flags
      245  #
      246  
      247 -CFLAGS += -DSPLASHSCREEN
      248 +CFLAGS += -DSPLASHSCREEN -DPNG_NO_MMX_CODE
      249  
      250  ifneq ($(PLATFORM), windows)
      251    CFLAGS += -DWITH_X11
      252    CPPFLAGS += -I$(OPENWIN_HOME)/include -I$(OPENWIN_HOME)/include/X11/extensions
      253 -  OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext $(LIBM) -lpthread
      254 +  OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext $(LIBM) -lpng -ljpeg -lgif -lz -lpthread
      255  else # PLATFORM
      256    CFLAGS += -DWITH_WIN32
      257    OTHER_LDLIBS += kernel32.lib user32.lib gdi32.lib 
      258 @@ -76,14 +76,10 @@
      259  #
      260  vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/splashscreen
      261  vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)
      262 -vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/giflib
      263 -vpath %.c   $(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
      264 -vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/libpng
      265  vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/image/jpeg
      266  vpath %.c   $(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen
      267  
      268  CPPFLAGS += -I$(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen -I$(SHARE_SRC)/native/$(PKGDIR)/splashscreen
      269 -CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/image/jpeg -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
      270  
      271  ifeq ($(PLATFORM), linux)
      272    ifeq ($(ARCH_DATA_MODEL), 64)
      273 diff -ruN openjdk.old/jdk/make/sun/jpeg/FILES_c.gmk openjdk/jdk/make/sun/jpeg/FILES_c.gmk
      274 --- openjdk.old/jdk/make/sun/jpeg/FILES_c.gmk	2007-10-12 03:54:08.000000000 -0400
      275 +++ openjdk/jdk/make/sun/jpeg/FILES_c.gmk	2007-10-23 17:13:59.000000000 -0400
      276 @@ -25,51 +25,7 @@
      277  
      278  FILES_c = \
      279  	imageioJPEG.c \
      280 -	jpegdecoder.c \
      281 -	jcomapi.c \
      282 -	jdapimin.c \
      283 -	jdapistd.c \
      284 -	jdcoefct.c \
      285 -	jdcolor.c \
      286 -	jddctmgr.c \
      287 -	jdhuff.c \
      288 -	jdinput.c \
      289 -	jdmainct.c \
      290 -	jdmarker.c \
      291 -	jdmaster.c \
      292 -	jdmerge.c \
      293 -	jdphuff.c \
      294 -	jdpostct.c \
      295 -	jdsample.c \
      296 -	jerror.c \
      297 -	jidctflt.c \
      298 -	jidctfst.c \
      299 -	jidctint.c \
      300 -	jidctred.c \
      301 -	jmemmgr.c \
      302 -	jmemnobs.c \
      303 -	jquant1.c \
      304 -	jquant2.c \
      305 -	jutils.c \
      306 -	jcapimin.c \
      307 -	jcapistd.c \
      308 -	jccoefct.c \
      309 -	jccolor.c \
      310 -	jcdctmgr.c \
      311 -	jchuff.c \
      312 -	jcinit.c \
      313 -	jcmainct.c \
      314 -	jcmarker.c \
      315 -	jcmaster.c \
      316 -	jcparam.c \
      317 -	jcphuff.c \
      318 -	jcprepct.c \
      319 -	jcsample.c \
      320 -	jctrans.c \
      321 -	jdtrans.c \
      322 -	jfdctflt.c \
      323 -	jfdctfst.c \
      324 -	jfdctint.c
      325 +	jpegdecoder.c
      326  
      327  ifndef OPENJDK
      328  FILES_c += \
      329 diff -ruN ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcapimin.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcapimin.c
      330 --- ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcapimin.c	2007-10-30 04:38:50.000000000 -0400
      331 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcapimin.c	1969-12-31 19:00:00.000000000 -0500
      332 @@ -1,284 +0,0 @@
      333 -/*
      334 - * reserved comment block
      335 - * DO NOT REMOVE OR ALTER!
      336 - */
      337 -/*
      338 - * jcapimin.c
      339 - *
      340 - * Copyright (C) 1994-1998, Thomas G. Lane.
      341 - * This file is part of the Independent JPEG Group's software.
      342 - * For conditions of distribution and use, see the accompanying README file.
      343 - *
      344 - * This file contains application interface code for the compression half
      345 - * of the JPEG library.  These are the "minimum" API routines that may be
      346 - * needed in either the normal full-compression case or the transcoding-only
      347 - * case.
      348 - *
      349 - * Most of the routines intended to be called directly by an application
      350 - * are in this file or in jcapistd.c.  But also see jcparam.c for
      351 - * parameter-setup helper routines, jcomapi.c for routines shared by
      352 - * compression and decompression, and jctrans.c for the transcoding case.
      353 - */
      354 -
      355 -#define JPEG_INTERNALS
      356 -#include "jinclude.h"
      357 -#include "jpeglib.h"
      358 -
      359 -
      360 -/*
      361 - * Initialization of a JPEG compression object.
      362 - * The error manager must already be set up (in case memory manager fails).
      363 - */
      364 -
      365 -GLOBAL(void)
      366 -jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
      367 -{
      368 -  int i;
      369 -
      370 -  /* Guard against version mismatches between library and caller. */
      371 -  cinfo->mem = NULL;            /* so jpeg_destroy knows mem mgr not called */
      372 -  if (version != JPEG_LIB_VERSION)
      373 -    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
      374 -  if (structsize != SIZEOF(struct jpeg_compress_struct))
      375 -    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
      376 -             (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
      377 -
      378 -  /* For debugging purposes, we zero the whole master structure.
      379 -   * But the application has already set the err pointer, and may have set
      380 -   * client_data, so we have to save and restore those fields.
      381 -   * Note: if application hasn't set client_data, tools like Purify may
      382 -   * complain here.
      383 -   */
      384 -  {
      385 -    struct jpeg_error_mgr * err = cinfo->err;
      386 -    void * client_data = cinfo->client_data; /* ignore Purify complaint here */
      387 -    MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
      388 -    cinfo->err = err;
      389 -    cinfo->client_data = client_data;
      390 -  }
      391 -  cinfo->is_decompressor = FALSE;
      392 -
      393 -  /* Initialize a memory manager instance for this object */
      394 -  jinit_memory_mgr((j_common_ptr) cinfo);
      395 -
      396 -  /* Zero out pointers to permanent structures. */
      397 -  cinfo->progress = NULL;
      398 -  cinfo->dest = NULL;
      399 -
      400 -  cinfo->comp_info = NULL;
      401 -
      402 -  for (i = 0; i < NUM_QUANT_TBLS; i++)
      403 -    cinfo->quant_tbl_ptrs[i] = NULL;
      404 -
      405 -  for (i = 0; i < NUM_HUFF_TBLS; i++) {
      406 -    cinfo->dc_huff_tbl_ptrs[i] = NULL;
      407 -    cinfo->ac_huff_tbl_ptrs[i] = NULL;
      408 -  }
      409 -
      410 -  cinfo->script_space = NULL;
      411 -
      412 -  cinfo->input_gamma = 1.0;     /* in case application forgets */
      413 -
      414 -  /* OK, I'm ready */
      415 -  cinfo->global_state = CSTATE_START;
      416 -}
      417 -
      418 -
      419 -/*
      420 - * Destruction of a JPEG compression object
      421 - */
      422 -
      423 -GLOBAL(void)
      424 -jpeg_destroy_compress (j_compress_ptr cinfo)
      425 -{
      426 -  jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
      427 -}
      428 -
      429 -
      430 -/*
      431 - * Abort processing of a JPEG compression operation,
      432 - * but don't destroy the object itself.
      433 - */
      434 -
      435 -GLOBAL(void)
      436 -jpeg_abort_compress (j_compress_ptr cinfo)
      437 -{
      438 -  jpeg_abort((j_common_ptr) cinfo); /* use common routine */
      439 -}
      440 -
      441 -
      442 -/*
      443 - * Forcibly suppress or un-suppress all quantization and Huffman tables.
      444 - * Marks all currently defined tables as already written (if suppress)
      445 - * or not written (if !suppress).  This will control whether they get emitted
      446 - * by a subsequent jpeg_start_compress call.
      447 - *
      448 - * This routine is exported for use by applications that want to produce
      449 - * abbreviated JPEG datastreams.  It logically belongs in jcparam.c, but
      450 - * since it is called by jpeg_start_compress, we put it here --- otherwise
      451 - * jcparam.o would be linked whether the application used it or not.
      452 - */
      453 -
      454 -GLOBAL(void)
      455 -jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
      456 -{
      457 -  int i;
      458 -  JQUANT_TBL * qtbl;
      459 -  JHUFF_TBL * htbl;
      460 -
      461 -  for (i = 0; i < NUM_QUANT_TBLS; i++) {
      462 -    if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
      463 -      qtbl->sent_table = suppress;
      464 -  }
      465 -
      466 -  for (i = 0; i < NUM_HUFF_TBLS; i++) {
      467 -    if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
      468 -      htbl->sent_table = suppress;
      469 -    if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
      470 -      htbl->sent_table = suppress;
      471 -  }
      472 -}
      473 -
      474 -
      475 -/*
      476 - * Finish JPEG compression.
      477 - *
      478 - * If a multipass operating mode was selected, this may do a great deal of
      479 - * work including most of the actual output.
      480 - */
      481 -
      482 -GLOBAL(void)
      483 -jpeg_finish_compress (j_compress_ptr cinfo)
      484 -{
      485 -  JDIMENSION iMCU_row;
      486 -
      487 -  if (cinfo->global_state == CSTATE_SCANNING ||
      488 -      cinfo->global_state == CSTATE_RAW_OK) {
      489 -    /* Terminate first pass */
      490 -    if (cinfo->next_scanline < cinfo->image_height)
      491 -      ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
      492 -    (*cinfo->master->finish_pass) (cinfo);
      493 -  } else if (cinfo->global_state != CSTATE_WRCOEFS)
      494 -    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
      495 -  /* Perform any remaining passes */
      496 -  while (! cinfo->master->is_last_pass) {
      497 -    (*cinfo->master->prepare_for_pass) (cinfo);
      498 -    for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
      499 -      if (cinfo->progress != NULL) {
      500 -        cinfo->progress->pass_counter = (long) iMCU_row;
      501 -        cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
      502 -        (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
      503 -      }
      504 -      /* We bypass the main controller and invoke coef controller directly;
      505 -       * all work is being done from the coefficient buffer.
      506 -       */
      507 -      if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
      508 -        ERREXIT(cinfo, JERR_CANT_SUSPEND);
      509 -    }
      510 -    (*cinfo->master->finish_pass) (cinfo);
      511 -  }
      512 -  /* Write EOI, do final cleanup */
      513 -  (*cinfo->marker->write_file_trailer) (cinfo);
      514 -  (*cinfo->dest->term_destination) (cinfo);
      515 -  /* We can use jpeg_abort to release memory and reset global_state */
      516 -  jpeg_abort((j_common_ptr) cinfo);
      517 -}
      518 -
      519 -
      520 -/*
      521 - * Write a special marker.
      522 - * This is only recommended for writing COM or APPn markers.
      523 - * Must be called after jpeg_start_compress() and before
      524 - * first call to jpeg_write_scanlines() or jpeg_write_raw_data().
      525 - */
      526 -
      527 -GLOBAL(void)
      528 -jpeg_write_marker (j_compress_ptr cinfo, int marker,
      529 -                   const JOCTET *dataptr, unsigned int datalen)
      530 -{
      531 -  JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
      532 -
      533 -  if (cinfo->next_scanline != 0 ||
      534 -      (cinfo->global_state != CSTATE_SCANNING &&
      535 -       cinfo->global_state != CSTATE_RAW_OK &&
      536 -       cinfo->global_state != CSTATE_WRCOEFS))
      537 -    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
      538 -
      539 -  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
      540 -  write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
      541 -  while (datalen--) {
      542 -    (*write_marker_byte) (cinfo, *dataptr);
      543 -    dataptr++;
      544 -  }
      545 -}
      546 -
      547 -/* Same, but piecemeal. */
      548 -
      549 -GLOBAL(void)
      550 -jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
      551 -{
      552 -  if (cinfo->next_scanline != 0 ||
      553 -      (cinfo->global_state != CSTATE_SCANNING &&
      554 -       cinfo->global_state != CSTATE_RAW_OK &&
      555 -       cinfo->global_state != CSTATE_WRCOEFS))
      556 -    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
      557 -
      558 -  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
      559 -}
      560 -
      561 -GLOBAL(void)
      562 -jpeg_write_m_byte (j_compress_ptr cinfo, int val)
      563 -{
      564 -  (*cinfo->marker->write_marker_byte) (cinfo, val);
      565 -}
      566 -
      567 -
      568 -/*
      569 - * Alternate compression function: just write an abbreviated table file.
      570 - * Before calling this, all parameters and a data destination must be set up.
      571 - *
      572 - * To produce a pair of files containing abbreviated tables and abbreviated
      573 - * image data, one would proceed as follows:
      574 - *
      575 - *              initialize JPEG object
      576 - *              set JPEG parameters
      577 - *              set destination to table file
      578 - *              jpeg_write_tables(cinfo);
      579 - *              set destination to image file
      580 - *              jpeg_start_compress(cinfo, FALSE);
      581 - *              write data...
      582 - *              jpeg_finish_compress(cinfo);
      583 - *
      584 - * jpeg_write_tables has the side effect of marking all tables written
      585 - * (same as jpeg_suppress_tables(..., TRUE)).  Thus a subsequent start_compress
      586 - * will not re-emit the tables unless it is passed write_all_tables=TRUE.
      587 - */
      588 -
      589 -GLOBAL(void)
      590 -jpeg_write_tables (j_compress_ptr cinfo)
      591 -{
      592 -  if (cinfo->global_state != CSTATE_START)
      593 -    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
      594 -
      595 -  /* (Re)initialize error mgr and destination modules */
      596 -  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
      597 -  (*cinfo->dest->init_destination) (cinfo);
      598 -  /* Initialize the marker writer ... bit of a crock to do it here. */
      599 -  jinit_marker_writer(cinfo);
      600 -  /* Write them tables! */
      601 -  (*cinfo->marker->write_tables_only) (cinfo);
      602 -  /* And clean up. */
      603 -  (*cinfo->dest->term_destination) (cinfo);
      604 -  /*
      605 -   * In library releases up through v6a, we called jpeg_abort() here to free
      606 -   * any working memory allocated by the destination manager and marker
      607 -   * writer.  Some applications had a problem with that: they allocated space
      608 -   * of their own from the library memory manager, and didn't want it to go
      609 -   * away during write_tables.  So now we do nothing.  This will cause a
      610 -   * memory leak if an app calls write_tables repeatedly without doing a full
      611 -   * compression cycle or otherwise resetting the JPEG object.  However, that
      612 -   * seems less bad than unexpectedly freeing memory in the normal case.
      613 -   * An app that prefers the old behavior can call jpeg_abort for itself after
      614 -   * each call to jpeg_write_tables().
      615 -   */
      616 -}
      617 diff -ruN ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcapistd.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcapistd.c
      618 --- ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcapistd.c	2007-10-30 04:38:51.000000000 -0400
      619 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcapistd.c	1969-12-31 19:00:00.000000000 -0500
      620 @@ -1,165 +0,0 @@
      621 -/*
      622 - * reserved comment block
      623 - * DO NOT REMOVE OR ALTER!
      624 - */
      625 -/*
      626 - * jcapistd.c
      627 - *
      628 - * Copyright (C) 1994-1996, Thomas G. Lane.
      629 - * This file is part of the Independent JPEG Group's software.
      630 - * For conditions of distribution and use, see the accompanying README file.
      631 - *
      632 - * This file contains application interface code for the compression half
      633 - * of the JPEG library.  These are the "standard" API routines that are
      634 - * used in the normal full-compression case.  They are not used by a
      635 - * transcoding-only application.  Note that if an application links in
      636 - * jpeg_start_compress, it will end up linking in the entire compressor.
      637 - * We thus must separate this file from jcapimin.c to avoid linking the
      638 - * whole compression library into a transcoder.
      639 - */
      640 -
      641 -#define JPEG_INTERNALS
      642 -#include "jinclude.h"
      643 -#include "jpeglib.h"
      644 -
      645 -
      646 -/*
      647 - * Compression initialization.
      648 - * Before calling this, all parameters and a data destination must be set up.
      649 - *
      650 - * We require a write_all_tables parameter as a failsafe check when writing
      651 - * multiple datastreams from the same compression object.  Since prior runs
      652 - * will have left all the tables marked sent_table=TRUE, a subsequent run
      653 - * would emit an abbreviated stream (no tables) by default.  This may be what
      654 - * is wanted, but for safety's sake it should not be the default behavior:
      655 - * programmers should have to make a deliberate choice to emit abbreviated
      656 - * images.  Therefore the documentation and examples should encourage people
      657 - * to pass write_all_tables=TRUE; then it will take active thought to do the
      658 - * wrong thing.
      659 - */
      660 -
      661 -GLOBAL(void)
      662 -jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
      663 -{
      664 -  if (cinfo->global_state != CSTATE_START)
      665 -    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
      666 -
      667 -  if (write_all_tables)
      668 -    jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
      669 -
      670 -  /* (Re)initialize error mgr and destination modules */
      671 -  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
      672 -  (*cinfo->dest->init_destination) (cinfo);
      673 -  /* Perform master selection of active modules */
      674 -  jinit_compress_master(cinfo);
      675 -  /* Set up for the first pass */
      676 -  (*cinfo->master->prepare_for_pass) (cinfo);
      677 -  /* Ready for application to drive first pass through jpeg_write_scanlines
      678 -   * or jpeg_write_raw_data.
      679 -   */
      680 -  cinfo->next_scanline = 0;
      681 -  cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
      682 -}
      683 -
      684 -
      685 -/*
      686 - * Write some scanlines of data to the JPEG compressor.
      687 - *
      688 - * The return value will be the number of lines actually written.
      689 - * This should be less than the supplied num_lines only in case that
      690 - * the data destination module has requested suspension of the compressor,
      691 - * or if more than image_height scanlines are passed in.
      692 - *
      693 - * Note: we warn about excess calls to jpeg_write_scanlines() since
      694 - * this likely signals an application programmer error.  However,
      695 - * excess scanlines passed in the last valid call are *silently* ignored,
      696 - * so that the application need not adjust num_lines for end-of-image
      697 - * when using a multiple-scanline buffer.
      698 - */
      699 -
      700 -GLOBAL(JDIMENSION)
      701 -jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
      702 -                      JDIMENSION num_lines)
      703 -{
      704 -  JDIMENSION row_ctr, rows_left;
      705 -
      706 -  if (cinfo->global_state != CSTATE_SCANNING)
      707 -    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
      708 -  if (cinfo->next_scanline >= cinfo->image_height)
      709 -    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
      710 -
      711 -  /* Call progress monitor hook if present */
      712 -  if (cinfo->progress != NULL) {
      713 -    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
      714 -    cinfo->progress->pass_limit = (long) cinfo->image_height;
      715 -    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
      716 -  }
      717 -
      718 -  /* Give master control module another chance if this is first call to
      719 -   * jpeg_write_scanlines.  This lets output of the frame/scan headers be
      720 -   * delayed so that application can write COM, etc, markers between
      721 -   * jpeg_start_compress and jpeg_write_scanlines.
      722 -   */
      723 -  if (cinfo->master->call_pass_startup)
      724 -    (*cinfo->master->pass_startup) (cinfo);
      725 -
      726 -  /* Ignore any extra scanlines at bottom of image. */
      727 -  rows_left = cinfo->image_height - cinfo->next_scanline;
      728 -  if (num_lines > rows_left)
      729 -    num_lines = rows_left;
      730 -
      731 -  row_ctr = 0;
      732 -  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
      733 -  cinfo->next_scanline += row_ctr;
      734 -  return row_ctr;
      735 -}
      736 -
      737 -
      738 -/*
      739 - * Alternate entry point to write raw data.
      740 - * Processes exactly one iMCU row per call, unless suspended.
      741 - */
      742 -
      743 -GLOBAL(JDIMENSION)
      744 -jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
      745 -                     JDIMENSION num_lines)
      746 -{
      747 -  JDIMENSION lines_per_iMCU_row;
      748 -
      749 -  if (cinfo->global_state != CSTATE_RAW_OK)
      750 -    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
      751 -  if (cinfo->next_scanline >= cinfo->image_height) {
      752 -    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
      753 -    return 0;
      754 -  }
      755 -
      756 -  /* Call progress monitor hook if present */
      757 -  if (cinfo->progress != NULL) {
      758 -    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
      759 -    cinfo->progress->pass_limit = (long) cinfo->image_height;
      760 -    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
      761 -  }
      762 -
      763 -  /* Give master control module another chance if this is first call to
      764 -   * jpeg_write_raw_data.  This lets output of the frame/scan headers be
      765 -   * delayed so that application can write COM, etc, markers between
      766 -   * jpeg_start_compress and jpeg_write_raw_data.
      767 -   */
      768 -  if (cinfo->master->call_pass_startup)
      769 -    (*cinfo->master->pass_startup) (cinfo);
      770 -
      771 -  /* Verify that at least one iMCU row has been passed. */
      772 -  lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
      773 -  if (num_lines < lines_per_iMCU_row)
      774 -    ERREXIT(cinfo, JERR_BUFFER_SIZE);
      775 -
      776 -  /* Directly compress the row. */
      777 -  if (! (*cinfo->coef->compress_data) (cinfo, data)) {
      778 -    /* If compressor did not consume the whole row, suspend processing. */
      779 -    return 0;
      780 -  }
      781 -
      782 -  /* OK, we processed one iMCU row. */
      783 -  cinfo->next_scanline += lines_per_iMCU_row;
      784 -  return lines_per_iMCU_row;
      785 -}
      786 diff -ruN ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jccoefct.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jccoefct.c
      787 --- ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jccoefct.c	2007-10-30 04:38:51.000000000 -0400
      788 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jccoefct.c	1969-12-31 19:00:00.000000000 -0500
      789 @@ -1,453 +0,0 @@
      790 -/*
      791 - * reserved comment block
      792 - * DO NOT REMOVE OR ALTER!
      793 - */
      794 -/*
      795 - * jccoefct.c
      796 - *
      797 - * Copyright (C) 1994-1997, Thomas G. Lane.
      798 - * This file is part of the Independent JPEG Group's software.
      799 - * For conditions of distribution and use, see the accompanying README file.
      800 - *
      801 - * This file contains the coefficient buffer controller for compression.
      802 - * This controller is the top level of the JPEG compressor proper.
      803 - * The coefficient buffer lies between forward-DCT and entropy encoding steps.
      804 - */
      805 -
      806 -#define JPEG_INTERNALS
      807 -#include "jinclude.h"
      808 -#include "jpeglib.h"
      809 -
      810 -
      811 -/* We use a full-image coefficient buffer when doing Huffman optimization,
      812 - * and also for writing multiple-scan JPEG files.  In all cases, the DCT
      813 - * step is run during the first pass, and subsequent passes need only read
      814 - * the buffered coefficients.
      815 - */
      816 -#ifdef ENTROPY_OPT_SUPPORTED
      817 -#define FULL_COEF_BUFFER_SUPPORTED
      818 -#else
      819 -#ifdef C_MULTISCAN_FILES_SUPPORTED
      820 -#define FULL_COEF_BUFFER_SUPPORTED
      821 -#endif
      822 -#endif
      823 -
      824 -
      825 -/* Private buffer controller object */
      826 -
      827 -typedef struct {
      828 -  struct jpeg_c_coef_controller pub; /* public fields */
      829 -
      830 -  JDIMENSION iMCU_row_num;      /* iMCU row # within image */
      831 -  JDIMENSION mcu_ctr;           /* counts MCUs processed in current row */
      832 -  int MCU_vert_offset;          /* counts MCU rows within iMCU row */
      833 -  int MCU_rows_per_iMCU_row;    /* number of such rows needed */
      834 -
      835 -  /* For single-pass compression, it's sufficient to buffer just one MCU
      836 -   * (although this may prove a bit slow in practice).  We allocate a
      837 -   * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each
      838 -   * MCU constructed and sent.  (On 80x86, the workspace is FAR even though
      839 -   * it's not really very big; this is to keep the module interfaces unchanged
      840 -   * when a large coefficient buffer is necessary.)
      841 -   * In multi-pass modes, this array points to the current MCU's blocks
      842 -   * within the virtual arrays.
      843 -   */
      844 -  JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
      845 -
      846 -  /* In multi-pass modes, we need a virtual block array for each component. */
      847 -  jvirt_barray_ptr whole_image[MAX_COMPONENTS];
      848 -} my_coef_controller;
      849 -
      850 -typedef my_coef_controller * my_coef_ptr;
      851 -
      852 -
      853 -/* Forward declarations */
      854 -METHODDEF(boolean) compress_data
      855 -    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
      856 -#ifdef FULL_COEF_BUFFER_SUPPORTED
      857 -METHODDEF(boolean) compress_first_pass
      858 -    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
      859 -METHODDEF(boolean) compress_output
      860 -    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
      861 -#endif
      862 -
      863 -
      864 -LOCAL(void)
      865 -start_iMCU_row (j_compress_ptr cinfo)
      866 -/* Reset within-iMCU-row counters for a new row */
      867 -{
      868 -  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
      869 -
      870 -  /* In an interleaved scan, an MCU row is the same as an iMCU row.
      871 -   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
      872 -   * But at the bottom of the image, process only what's left.
      873 -   */
      874 -  if (cinfo->comps_in_scan > 1) {
      875 -    coef->MCU_rows_per_iMCU_row = 1;
      876 -  } else {
      877 -    if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
      878 -      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
      879 -    else
      880 -      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
      881 -  }
      882 -
      883 -  coef->mcu_ctr = 0;
      884 -  coef->MCU_vert_offset = 0;
      885 -}
      886 -
      887 -
      888 -/*
      889 - * Initialize for a processing pass.
      890 - */
      891 -
      892 -METHODDEF(void)
      893 -start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
      894 -{
      895 -  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
      896 -
      897 -  coef->iMCU_row_num = 0;
      898 -  start_iMCU_row(cinfo);
      899 -
      900 -  switch (pass_mode) {
      901 -  case JBUF_PASS_THRU:
      902 -    if (coef->whole_image[0] != NULL)
      903 -      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
      904 -    coef->pub.compress_data = compress_data;
      905 -    break;
      906 -#ifdef FULL_COEF_BUFFER_SUPPORTED
      907 -  case JBUF_SAVE_AND_PASS:
      908 -    if (coef->whole_image[0] == NULL)
      909 -      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
      910 -    coef->pub.compress_data = compress_first_pass;
      911 -    break;
      912 -  case JBUF_CRANK_DEST:
      913 -    if (coef->whole_image[0] == NULL)
      914 -      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
      915 -    coef->pub.compress_data = compress_output;
      916 -    break;
      917 -#endif
      918 -  default:
      919 -    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
      920 -    break;
      921 -  }
      922 -}
      923 -
      924 -
      925 -/*
      926 - * Process some data in the single-pass case.
      927 - * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
      928 - * per call, ie, v_samp_factor block rows for each component in the image.
      929 - * Returns TRUE if the iMCU row is completed, FALSE if suspended.
      930 - *
      931 - * NB: input_buf contains a plane for each component in image,
      932 - * which we index according to the component's SOF position.
      933 - */
      934 -
      935 -METHODDEF(boolean)
      936 -compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
      937 -{
      938 -  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
      939 -  JDIMENSION MCU_col_num;       /* index of current MCU within row */
      940 -  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
      941 -  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
      942 -  int blkn, bi, ci, yindex, yoffset, blockcnt;
      943 -  JDIMENSION ypos, xpos;
      944 -  jpeg_component_info *compptr;
      945 -
      946 -  /* Loop to write as much as one whole iMCU row */
      947 -  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
      948 -       yoffset++) {
      949 -    for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
      950 -         MCU_col_num++) {
      951 -      /* Determine where data comes from in input_buf and do the DCT thing.
      952 -       * Each call on forward_DCT processes a horizontal row of DCT blocks
      953 -       * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
      954 -       * sequentially.  Dummy blocks at the right or bottom edge are filled in
      955 -       * specially.  The data in them does not matter for image reconstruction,
      956 -       * so we fill them with values that will encode to the smallest amount of
      957 -       * data, viz: all zeroes in the AC entries, DC entries equal to previous
      958 -       * block's DC value.  (Thanks to Thomas Kinsman for this idea.)
      959 -       */
      960 -      blkn = 0;
      961 -      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
      962 -        compptr = cinfo->cur_comp_info[ci];
      963 -        blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
      964 -                                                : compptr->last_col_width;
      965 -        xpos = MCU_col_num * compptr->MCU_sample_width;
      966 -        ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
      967 -        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
      968 -          if (coef->iMCU_row_num < last_iMCU_row ||
      969 -              yoffset+yindex < compptr->last_row_height) {
      970 -            (*cinfo->fdct->forward_DCT) (cinfo, compptr,
      971 -                                         input_buf[compptr->component_index],
      972 -                                         coef->MCU_buffer[blkn],
      973 -                                         ypos, xpos, (JDIMENSION) blockcnt);
      974 -            if (blockcnt < compptr->MCU_width) {
      975 -              /* Create some dummy blocks at the right edge of the image. */
      976 -              jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
      977 -                        (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
      978 -              for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
      979 -                coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
      980 -              }
      981 -            }
      982 -          } else {
      983 -            /* Create a row of dummy blocks at the bottom of the image. */
      984 -            jzero_far((void FAR *) coef->MCU_buffer[blkn],
      985 -                      compptr->MCU_width * SIZEOF(JBLOCK));
      986 -            for (bi = 0; bi < compptr->MCU_width; bi++) {
      987 -              coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
      988 -            }
      989 -          }
      990 -          blkn += compptr->MCU_width;
      991 -          ypos += DCTSIZE;
      992 -        }
      993 -      }
      994 -      /* Try to write the MCU.  In event of a suspension failure, we will
      995 -       * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
      996 -       */
      997 -      if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
      998 -        /* Suspension forced; update state counters and exit */
      999 -        coef->MCU_vert_offset = yoffset;
     1000 -        coef->mcu_ctr = MCU_col_num;
     1001 -        return FALSE;
     1002 -      }
     1003 -    }
     1004 -    /* Completed an MCU row, but perhaps not an iMCU row */
     1005 -    coef->mcu_ctr = 0;
     1006 -  }
     1007 -  /* Completed the iMCU row, advance counters for next one */
     1008 -  coef->iMCU_row_num++;
     1009 -  start_iMCU_row(cinfo);
     1010 -  return TRUE;
     1011 -}
     1012 -
     1013 -
     1014 -#ifdef FULL_COEF_BUFFER_SUPPORTED
     1015 -
     1016 -/*
     1017 - * Process some data in the first pass of a multi-pass case.
     1018 - * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
     1019 - * per call, ie, v_samp_factor block rows for each component in the image.
     1020 - * This amount of data is read from the source buffer, DCT'd and quantized,
     1021 - * and saved into the virtual arrays.  We also generate suitable dummy blocks
     1022 - * as needed at the right and lower edges.  (The dummy blocks are constructed
     1023 - * in the virtual arrays, which have been padded appropriately.)  This makes
     1024 - * it possible for subsequent passes not to worry about real vs. dummy blocks.
     1025 - *
     1026 - * We must also emit the data to the entropy encoder.  This is conveniently
     1027 - * done by calling compress_output() after we've loaded the current strip
     1028 - * of the virtual arrays.
     1029 - *
     1030 - * NB: input_buf contains a plane for each component in image.  All
     1031 - * components are DCT'd and loaded into the virtual arrays in this pass.
     1032 - * However, it may be that only a subset of the components are emitted to
     1033 - * the entropy encoder during this first pass; be careful about looking
     1034 - * at the scan-dependent variables (MCU dimensions, etc).
     1035 - */
     1036 -
     1037 -METHODDEF(boolean)
     1038 -compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
     1039 -{
     1040 -  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
     1041 -  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
     1042 -  JDIMENSION blocks_across, MCUs_across, MCUindex;
     1043 -  int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
     1044 -  JCOEF lastDC;
     1045 -  jpeg_component_info *compptr;
     1046 -  JBLOCKARRAY buffer;
     1047 -  JBLOCKROW thisblockrow, lastblockrow;
     1048 -
     1049 -  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
     1050 -       ci++, compptr++) {
     1051 -    /* Align the virtual buffer for this component. */
     1052 -    buffer = (*cinfo->mem->access_virt_barray)
     1053 -      ((j_common_ptr) cinfo, coef->whole_image[ci],
     1054 -       coef->iMCU_row_num * compptr->v_samp_factor,
     1055 -       (JDIMENSION) compptr->v_samp_factor, TRUE);
     1056 -    /* Count non-dummy DCT block rows in this iMCU row. */
     1057 -    if (coef->iMCU_row_num < last_iMCU_row)
     1058 -      block_rows = compptr->v_samp_factor;
     1059 -    else {
     1060 -      /* NB: can't use last_row_height here, since may not be set! */
     1061 -      block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
     1062 -      if (block_rows == 0) block_rows = compptr->v_samp_factor;
     1063 -    }
     1064 -    blocks_across = compptr->width_in_blocks;
     1065 -    h_samp_factor = compptr->h_samp_factor;
     1066 -    /* Count number of dummy blocks to be added at the right margin. */
     1067 -    ndummy = (int) (blocks_across % h_samp_factor);
     1068 -    if (ndummy > 0)
     1069 -      ndummy = h_samp_factor - ndummy;
     1070 -    /* Perform DCT for all non-dummy blocks in this iMCU row.  Each call
     1071 -     * on forward_DCT processes a complete horizontal row of DCT blocks.
     1072 -     */
     1073 -    for (block_row = 0; block_row < block_rows; block_row++) {
     1074 -      thisblockrow = buffer[block_row];
     1075 -      (*cinfo->fdct->forward_DCT) (cinfo, compptr,
     1076 -                                   input_buf[ci], thisblockrow,
     1077 -                                   (JDIMENSION) (block_row * DCTSIZE),
     1078 -                                   (JDIMENSION) 0, blocks_across);
     1079 -      if (ndummy > 0) {
     1080 -        /* Create dummy blocks at the right edge of the image. */
     1081 -        thisblockrow += blocks_across; /* => first dummy block */
     1082 -        jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
     1083 -        lastDC = thisblockrow[-1][0];
     1084 -        for (bi = 0; bi < ndummy; bi++) {
     1085 -          thisblockrow[bi][0] = lastDC;
     1086 -        }
     1087 -      }
     1088 -    }
     1089 -    /* If at end of image, create dummy block rows as needed.
     1090 -     * The tricky part here is that within each MCU, we want the DC values
     1091 -     * of the dummy blocks to match the last real block's DC value.
     1092 -     * This squeezes a few more bytes out of the resulting file...
     1093 -     */
     1094 -    if (coef->iMCU_row_num == last_iMCU_row) {
     1095 -      blocks_across += ndummy;  /* include lower right corner */
     1096 -      MCUs_across = blocks_across / h_samp_factor;
     1097 -      for (block_row = block_rows; block_row < compptr->v_samp_factor;
     1098 -           block_row++) {
     1099 -        thisblockrow = buffer[block_row];
     1100 -        lastblockrow = buffer[block_row-1];
     1101 -        jzero_far((void FAR *) thisblockrow,
     1102 -                  (size_t) (blocks_across * SIZEOF(JBLOCK)));
     1103 -        for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
     1104 -          lastDC = lastblockrow[h_samp_factor-1][0];
     1105 -          for (bi = 0; bi < h_samp_factor; bi++) {
     1106 -            thisblockrow[bi][0] = lastDC;
     1107 -          }
     1108 -          thisblockrow += h_samp_factor; /* advance to next MCU in row */
     1109 -          lastblockrow += h_samp_factor;
     1110 -        }
     1111 -      }
     1112 -    }
     1113 -  }
     1114 -  /* NB: compress_output will increment iMCU_row_num if successful.
     1115 -   * A suspension return will result in redoing all the work above next time.
     1116 -   */
     1117 -
     1118 -  /* Emit data to the entropy encoder, sharing code with subsequent passes */
     1119 -  return compress_output(cinfo, input_buf);
     1120 -}
     1121 -
     1122 -
     1123 -/*
     1124 - * Process some data in subsequent passes of a multi-pass case.
     1125 - * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
     1126 - * per call, ie, v_samp_factor block rows for each component in the scan.
     1127 - * The data is obtained from the virtual arrays and fed to the entropy coder.
     1128 - * Returns TRUE if the iMCU row is completed, FALSE if suspended.
     1129 - *
     1130 - * NB: input_buf is ignored; it is likely to be a NULL pointer.
     1131 - */
     1132 -
     1133 -METHODDEF(boolean)
     1134 -compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
     1135 -{
     1136 -  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
     1137 -  JDIMENSION MCU_col_num;       /* index of current MCU within row */
     1138 -  int blkn, ci, xindex, yindex, yoffset;
     1139 -  JDIMENSION start_col;
     1140 -  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
     1141 -  JBLOCKROW buffer_ptr;
     1142 -  jpeg_component_info *compptr;
     1143 -
     1144 -  /* Align the virtual buffers for the components used in this scan.
     1145 -   * NB: during first pass, this is safe only because the buffers will
     1146 -   * already be aligned properly, so jmemmgr.c won't need to do any I/O.
     1147 -   */
     1148 -  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
     1149 -    compptr = cinfo->cur_comp_info[ci];
     1150 -    buffer[ci] = (*cinfo->mem->access_virt_barray)
     1151 -      ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
     1152 -       coef->iMCU_row_num * compptr->v_samp_factor,
     1153 -       (JDIMENSION) compptr->v_samp_factor, FALSE);
     1154 -  }
     1155 -
     1156 -  /* Loop to process one whole iMCU row */
     1157 -  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
     1158 -       yoffset++) {
     1159 -    for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
     1160 -         MCU_col_num++) {
     1161 -      /* Construct list of pointers to DCT blocks belonging to this MCU */
     1162 -      blkn = 0;                 /* index of current DCT block within MCU */
     1163 -      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
     1164 -        compptr = cinfo->cur_comp_info[ci];
     1165 -        start_col = MCU_col_num * compptr->MCU_width;
     1166 -        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
     1167 -          buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
     1168 -          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
     1169 -            coef->MCU_buffer[blkn++] = buffer_ptr++;
     1170 -          }
     1171 -        }
     1172 -      }
     1173 -      /* Try to write the MCU. */
     1174 -      if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
     1175 -        /* Suspension forced; update state counters and exit */
     1176 -        coef->MCU_vert_offset = yoffset;
     1177 -        coef->mcu_ctr = MCU_col_num;
     1178 -        return FALSE;
     1179 -      }
     1180 -    }
     1181 -    /* Completed an MCU row, but perhaps not an iMCU row */
     1182 -    coef->mcu_ctr = 0;
     1183 -  }
     1184 -  /* Completed the iMCU row, advance counters for next one */
     1185 -  coef->iMCU_row_num++;
     1186 -  start_iMCU_row(cinfo);
     1187 -  return TRUE;
     1188 -}
     1189 -
     1190 -#endif /* FULL_COEF_BUFFER_SUPPORTED */
     1191 -
     1192 -
     1193 -/*
     1194 - * Initialize coefficient buffer controller.
     1195 - */
     1196 -
     1197 -GLOBAL(void)
     1198 -jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
     1199 -{
     1200 -  my_coef_ptr coef;
     1201 -
     1202 -  coef = (my_coef_ptr)
     1203 -    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     1204 -                                SIZEOF(my_coef_controller));
     1205 -  cinfo->coef = (struct jpeg_c_coef_controller *) coef;
     1206 -  coef->pub.start_pass = start_pass_coef;
     1207 -
     1208 -  /* Create the coefficient buffer. */
     1209 -  if (need_full_buffer) {
     1210 -#ifdef FULL_COEF_BUFFER_SUPPORTED
     1211 -    /* Allocate a full-image virtual array for each component, */
     1212 -    /* padded to a multiple of samp_factor DCT blocks in each direction. */
     1213 -    int ci;
     1214 -    jpeg_component_info *compptr;
     1215 -
     1216 -    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
     1217 -         ci++, compptr++) {
     1218 -      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
     1219 -        ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
     1220 -         (JDIMENSION) jround_up((long) compptr->width_in_blocks,
     1221 -                                (long) compptr->h_samp_factor),
     1222 -         (JDIMENSION) jround_up((long) compptr->height_in_blocks,
     1223 -                                (long) compptr->v_samp_factor),
     1224 -         (JDIMENSION) compptr->v_samp_factor);
     1225 -    }
     1226 -#else
     1227 -    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
     1228 -#endif
     1229 -  } else {
     1230 -    /* We only need a single-MCU buffer. */
     1231 -    JBLOCKROW buffer;
     1232 -    int i;
     1233 -
     1234 -    buffer = (JBLOCKROW)
     1235 -      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     1236 -                                  C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
     1237 -    for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
     1238 -      coef->MCU_buffer[i] = buffer + i;
     1239 -    }
     1240 -    coef->whole_image[0] = NULL; /* flag for no virtual arrays */
     1241 -  }
     1242 -}
     1243 diff -ruN ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jccolor.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jccolor.c
     1244 --- ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jccolor.c	2007-10-30 04:38:51.000000000 -0400
     1245 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jccolor.c	1969-12-31 19:00:00.000000000 -0500
     1246 @@ -1,462 +0,0 @@
     1247 -/*
     1248 - * reserved comment block
     1249 - * DO NOT REMOVE OR ALTER!
     1250 - */
     1251 -/*
     1252 - * jccolor.c
     1253 - *
     1254 - * Copyright (C) 1991-1996, Thomas G. Lane.
     1255 - * This file is part of the Independent JPEG Group's software.
     1256 - * For conditions of distribution and use, see the accompanying README file.
     1257 - *
     1258 - * This file contains input colorspace conversion routines.
     1259 - */
     1260 -
     1261 -#define JPEG_INTERNALS
     1262 -#include "jinclude.h"
     1263 -#include "jpeglib.h"
     1264 -
     1265 -
     1266 -/* Private subobject */
     1267 -
     1268 -typedef struct {
     1269 -  struct jpeg_color_converter pub; /* public fields */
     1270 -
     1271 -  /* Private state for RGB->YCC conversion */
     1272 -  INT32 * rgb_ycc_tab;          /* => table for RGB to YCbCr conversion */
     1273 -} my_color_converter;
     1274 -
     1275 -typedef my_color_converter * my_cconvert_ptr;
     1276 -
     1277 -
     1278 -/**************** RGB -> YCbCr conversion: most common case **************/
     1279 -
     1280 -/*
     1281 - * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
     1282 - * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
     1283 - * The conversion equations to be implemented are therefore
     1284 - *      Y  =  0.29900 * R + 0.58700 * G + 0.11400 * B
     1285 - *      Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B  + CENTERJSAMPLE
     1286 - *      Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B  + CENTERJSAMPLE
     1287 - * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
     1288 - * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
     1289 - * rather than CENTERJSAMPLE, for Cb and Cr.  This gave equal positive and
     1290 - * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
     1291 - * were not represented exactly.  Now we sacrifice exact representation of
     1292 - * maximum red and maximum blue in order to get exact grayscales.
     1293 - *
     1294 - * To avoid floating-point arithmetic, we represent the fractional constants
     1295 - * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
     1296 - * the products by 2^16, with appropriate rounding, to get the correct answer.
     1297 - *
     1298 - * For even more speed, we avoid doing any multiplications in the inner loop
     1299 - * by precalculating the constants times R,G,B for all possible values.
     1300 - * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
     1301 - * for 12-bit samples it is still acceptable.  It's not very reasonable for
     1302 - * 16-bit samples, but if you want lossless storage you shouldn't be changing
     1303 - * colorspace anyway.
     1304 - * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
     1305 - * in the tables to save adding them separately in the inner loop.
     1306 - */
     1307 -
     1308 -#define SCALEBITS       16      /* speediest right-shift on some machines */
     1309 -#define CBCR_OFFSET     ((INT32) CENTERJSAMPLE << SCALEBITS)
     1310 -#define ONE_HALF        ((INT32) 1 << (SCALEBITS-1))
     1311 -#define FIX(x)          ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
     1312 -
     1313 -/* We allocate one big table and divide it up into eight parts, instead of
     1314 - * doing eight alloc_small requests.  This lets us use a single table base
     1315 - * address, which can be held in a register in the inner loops on many
     1316 - * machines (more than can hold all eight addresses, anyway).
     1317 - */
     1318 -
     1319 -#define R_Y_OFF         0                       /* offset to R => Y section */
     1320 -#define G_Y_OFF         (1*(MAXJSAMPLE+1))      /* offset to G => Y section */
     1321 -#define B_Y_OFF         (2*(MAXJSAMPLE+1))      /* etc. */
     1322 -#define R_CB_OFF        (3*(MAXJSAMPLE+1))
     1323 -#define G_CB_OFF        (4*(MAXJSAMPLE+1))
     1324 -#define B_CB_OFF        (5*(MAXJSAMPLE+1))
     1325 -#define R_CR_OFF        B_CB_OFF                /* B=>Cb, R=>Cr are the same */
     1326 -#define G_CR_OFF        (6*(MAXJSAMPLE+1))
     1327 -#define B_CR_OFF        (7*(MAXJSAMPLE+1))
     1328 -#define TABLE_SIZE      (8*(MAXJSAMPLE+1))
     1329 -
     1330 -
     1331 -/*
     1332 - * Initialize for RGB->YCC colorspace conversion.
     1333 - */
     1334 -
     1335 -METHODDEF(void)
     1336 -rgb_ycc_start (j_compress_ptr cinfo)
     1337 -{
     1338 -  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
     1339 -  INT32 * rgb_ycc_tab;
     1340 -  INT32 i;
     1341 -
     1342 -  /* Allocate and fill in the conversion tables. */
     1343 -  cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
     1344 -    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     1345 -                                (TABLE_SIZE * SIZEOF(INT32)));
     1346 -
     1347 -  for (i = 0; i <= MAXJSAMPLE; i++) {
     1348 -    rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
     1349 -    rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
     1350 -    rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i     + ONE_HALF;
     1351 -    rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
     1352 -    rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
     1353 -    /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
     1354 -     * This ensures that the maximum output will round to MAXJSAMPLE
     1355 -     * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
     1356 -     */
     1357 -    rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i    + CBCR_OFFSET + ONE_HALF-1;
     1358 -/*  B=>Cb and R=>Cr tables are the same
     1359 -    rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i    + CBCR_OFFSET + ONE_HALF-1;
     1360 -*/
     1361 -    rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
     1362 -    rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
     1363 -  }
     1364 -}
     1365 -
     1366 -
     1367 -/*
     1368 - * Convert some rows of samples to the JPEG colorspace.
     1369 - *
     1370 - * Note that we change from the application's interleaved-pixel format
     1371 - * to our internal noninterleaved, one-plane-per-component format.
     1372 - * The input buffer is therefore three times as wide as the output buffer.
     1373 - *
     1374 - * A starting row offset is provided only for the output buffer.  The caller
     1375 - * can easily adjust the passed input_buf value to accommodate any row
     1376 - * offset required on that side.
     1377 - */
     1378 -
     1379 -METHODDEF(void)
     1380 -rgb_ycc_convert (j_compress_ptr cinfo,
     1381 -                 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
     1382 -                 JDIMENSION output_row, int num_rows)
     1383 -{
     1384 -  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
     1385 -  register int r, g, b;
     1386 -  register INT32 * ctab = cconvert->rgb_ycc_tab;
     1387 -  register JSAMPROW inptr;
     1388 -  register JSAMPROW outptr0, outptr1, outptr2;
     1389 -  register JDIMENSION col;
     1390 -  JDIMENSION num_cols = cinfo->image_width;
     1391 -
     1392 -  while (--num_rows >= 0) {
     1393 -    inptr = *input_buf++;
     1394 -    outptr0 = output_buf[0][output_row];
     1395 -    outptr1 = output_buf[1][output_row];
     1396 -    outptr2 = output_buf[2][output_row];
     1397 -    output_row++;
     1398 -    for (col = 0; col < num_cols; col++) {
     1399 -      r = GETJSAMPLE(inptr[RGB_RED]);
     1400 -      g = GETJSAMPLE(inptr[RGB_GREEN]);
     1401 -      b = GETJSAMPLE(inptr[RGB_BLUE]);
     1402 -      inptr += RGB_PIXELSIZE;
     1403 -      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
     1404 -       * must be too; we do not need an explicit range-limiting operation.
     1405 -       * Hence the value being shifted is never negative, and we don't
     1406 -       * need the general RIGHT_SHIFT macro.
     1407 -       */
     1408 -      /* Y */
     1409 -      outptr0[col] = (JSAMPLE)
     1410 -                ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
     1411 -                 >> SCALEBITS);
     1412 -      /* Cb */
     1413 -      outptr1[col] = (JSAMPLE)
     1414 -                ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
     1415 -                 >> SCALEBITS);
     1416 -      /* Cr */
     1417 -      outptr2[col] = (JSAMPLE)
     1418 -                ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
     1419 -                 >> SCALEBITS);
     1420 -    }
     1421 -  }
     1422 -}
     1423 -
     1424 -
     1425 -/**************** Cases other than RGB -> YCbCr **************/
     1426 -
     1427 -
     1428 -/*
     1429 - * Convert some rows of samples to the JPEG colorspace.
     1430 - * This version handles RGB->grayscale conversion, which is the same
     1431 - * as the RGB->Y portion of RGB->YCbCr.
     1432 - * We assume rgb_ycc_start has been called (we only use the Y tables).
     1433 - */
     1434 -
     1435 -METHODDEF(void)
     1436 -rgb_gray_convert (j_compress_ptr cinfo,
     1437 -                  JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
     1438 -                  JDIMENSION output_row, int num_rows)
     1439 -{
     1440 -  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
     1441 -  register int r, g, b;
     1442 -  register INT32 * ctab = cconvert->rgb_ycc_tab;
     1443 -  register JSAMPROW inptr;
     1444 -  register JSAMPROW outptr;
     1445 -  register JDIMENSION col;
     1446 -  JDIMENSION num_cols = cinfo->image_width;
     1447 -
     1448 -  while (--num_rows >= 0) {
     1449 -    inptr = *input_buf++;
     1450 -    outptr = output_buf[0][output_row];
     1451 -    output_row++;
     1452 -    for (col = 0; col < num_cols; col++) {
     1453 -      r = GETJSAMPLE(inptr[RGB_RED]);
     1454 -      g = GETJSAMPLE(inptr[RGB_GREEN]);
     1455 -      b = GETJSAMPLE(inptr[RGB_BLUE]);
     1456 -      inptr += RGB_PIXELSIZE;
     1457 -      /* Y */
     1458 -      outptr[col] = (JSAMPLE)
     1459 -                ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
     1460 -                 >> SCALEBITS);
     1461 -    }
     1462 -  }
     1463 -}
     1464 -
     1465 -/*
     1466 - * Convert some rows of samples to the JPEG colorspace.
     1467 - * This version handles Adobe-style CMYK->YCCK conversion,
     1468 - * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
     1469 - * conversion as above, while passing K (black) unchanged.
     1470 - * We assume rgb_ycc_start has been called.
     1471 - */
     1472 -
     1473 -METHODDEF(void)
     1474 -cmyk_ycck_convert (j_compress_ptr cinfo,
     1475 -                   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
     1476 -                   JDIMENSION output_row, int num_rows)
     1477 -{
     1478 -  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
     1479 -  register int r, g, b;
     1480 -  register INT32 * ctab = cconvert->rgb_ycc_tab;
     1481 -  register JSAMPROW inptr;
     1482 -  register JSAMPROW outptr0, outptr1, outptr2, outptr3;
     1483 -  register JDIMENSION col;
     1484 -  JDIMENSION num_cols = cinfo->image_width;
     1485 -
     1486 -  while (--num_rows >= 0) {
     1487 -    inptr = *input_buf++;
     1488 -    outptr0 = output_buf[0][output_row];
     1489 -    outptr1 = output_buf[1][output_row];
     1490 -    outptr2 = output_buf[2][output_row];
     1491 -    outptr3 = output_buf[3][output_row];
     1492 -    output_row++;
     1493 -    for (col = 0; col < num_cols; col++) {
     1494 -      r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
     1495 -      g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
     1496 -      b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
     1497 -      /* K passes through as-is */
     1498 -      outptr3[col] = inptr[3];  /* don't need GETJSAMPLE here */
     1499 -      inptr += 4;
     1500 -      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
     1501 -       * must be too; we do not need an explicit range-limiting operation.
     1502 -       * Hence the value being shifted is never negative, and we don't
     1503 -       * need the general RIGHT_SHIFT macro.
     1504 -       */
     1505 -      /* Y */
     1506 -      outptr0[col] = (JSAMPLE)
     1507 -                ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
     1508 -                 >> SCALEBITS);
     1509 -      /* Cb */
     1510 -      outptr1[col] = (JSAMPLE)
     1511 -                ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
     1512 -                 >> SCALEBITS);
     1513 -      /* Cr */
     1514 -      outptr2[col] = (JSAMPLE)
     1515 -                ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
     1516 -                 >> SCALEBITS);
     1517 -    }
     1518 -  }
     1519 -}
     1520 -
     1521 -
     1522 -/*
     1523 - * Convert some rows of samples to the JPEG colorspace.
     1524 - * This version handles grayscale output with no conversion.
     1525 - * The source can be either plain grayscale or YCbCr (since Y == gray).
     1526 - */
     1527 -
     1528 -METHODDEF(void)
     1529 -grayscale_convert (j_compress_ptr cinfo,
     1530 -                   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
     1531 -                   JDIMENSION output_row, int num_rows)
     1532 -{
     1533 -  register JSAMPROW inptr;
     1534 -  register JSAMPROW outptr;
     1535 -  register JDIMENSION col;
     1536 -  JDIMENSION num_cols = cinfo->image_width;
     1537 -  int instride = cinfo->input_components;
     1538 -
     1539 -  while (--num_rows >= 0) {
     1540 -    inptr = *input_buf++;
     1541 -    outptr = output_buf[0][output_row];
     1542 -    output_row++;
     1543 -    for (col = 0; col < num_cols; col++) {
     1544 -      outptr[col] = inptr[0];   /* don't need GETJSAMPLE() here */
     1545 -      inptr += instride;
     1546 -    }
     1547 -  }
     1548 -}
     1549 -
     1550 -
     1551 -/*
     1552 - * Convert some rows of samples to the JPEG colorspace.
     1553 - * This version handles multi-component colorspaces without conversion.
     1554 - * We assume input_components == num_components.
     1555 - */
     1556 -
     1557 -METHODDEF(void)
     1558 -null_convert (j_compress_ptr cinfo,
     1559 -              JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
     1560 -              JDIMENSION output_row, int num_rows)
     1561 -{
     1562 -  register JSAMPROW inptr;
     1563 -  register JSAMPROW outptr;
     1564 -  register JDIMENSION col;
     1565 -  register int ci;
     1566 -  int nc = cinfo->num_components;
     1567 -  JDIMENSION num_cols = cinfo->image_width;
     1568 -
     1569 -  while (--num_rows >= 0) {
     1570 -    /* It seems fastest to make a separate pass for each component. */
     1571 -    for (ci = 0; ci < nc; ci++) {
     1572 -      inptr = *input_buf;
     1573 -      outptr = output_buf[ci][output_row];
     1574 -      for (col = 0; col < num_cols; col++) {
     1575 -        outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
     1576 -        inptr += nc;
     1577 -      }
     1578 -    }
     1579 -    input_buf++;
     1580 -    output_row++;
     1581 -  }
     1582 -}
     1583 -
     1584 -
     1585 -/*
     1586 - * Empty method for start_pass.
     1587 - */
     1588 -
     1589 -METHODDEF(void)
     1590 -null_method (j_compress_ptr cinfo)
     1591 -{
     1592 -  /* no work needed */
     1593 -}
     1594 -
     1595 -
     1596 -/*
     1597 - * Module initialization routine for input colorspace conversion.
     1598 - */
     1599 -
     1600 -GLOBAL(void)
     1601 -jinit_color_converter (j_compress_ptr cinfo)
     1602 -{
     1603 -  my_cconvert_ptr cconvert;
     1604 -
     1605 -  cconvert = (my_cconvert_ptr)
     1606 -    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     1607 -                                SIZEOF(my_color_converter));
     1608 -  cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
     1609 -  /* set start_pass to null method until we find out differently */
     1610 -  cconvert->pub.start_pass = null_method;
     1611 -
     1612 -  /* Make sure input_components agrees with in_color_space */
     1613 -  switch (cinfo->in_color_space) {
     1614 -  case JCS_GRAYSCALE:
     1615 -    if (cinfo->input_components != 1)
     1616 -      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
     1617 -    break;
     1618 -
     1619 -  case JCS_RGB:
     1620 -#if RGB_PIXELSIZE != 3
     1621 -    if (cinfo->input_components != RGB_PIXELSIZE)
     1622 -      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
     1623 -    break;
     1624 -#endif /* else share code with YCbCr */
     1625 -
     1626 -  case JCS_YCbCr:
     1627 -    if (cinfo->input_components != 3)
     1628 -      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
     1629 -    break;
     1630 -
     1631 -  case JCS_CMYK:
     1632 -  case JCS_YCCK:
     1633 -    if (cinfo->input_components != 4)
     1634 -      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
     1635 -    break;
     1636 -
     1637 -  default:                      /* JCS_UNKNOWN can be anything */
     1638 -    if (cinfo->input_components < 1)
     1639 -      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
     1640 -    break;
     1641 -  }
     1642 -
     1643 -  /* Check num_components, set conversion method based on requested space */
     1644 -  switch (cinfo->jpeg_color_space) {
     1645 -  case JCS_GRAYSCALE:
     1646 -    if (cinfo->num_components != 1)
     1647 -      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
     1648 -    if (cinfo->in_color_space == JCS_GRAYSCALE)
     1649 -      cconvert->pub.color_convert = grayscale_convert;
     1650 -    else if (cinfo->in_color_space == JCS_RGB) {
     1651 -      cconvert->pub.start_pass = rgb_ycc_start;
     1652 -      cconvert->pub.color_convert = rgb_gray_convert;
     1653 -    } else if (cinfo->in_color_space == JCS_YCbCr)
     1654 -      cconvert->pub.color_convert = grayscale_convert;
     1655 -    else
     1656 -      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
     1657 -    break;
     1658 -
     1659 -  case JCS_RGB:
     1660 -    if (cinfo->num_components != 3)
     1661 -      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
     1662 -    if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
     1663 -      cconvert->pub.color_convert = null_convert;
     1664 -    else
     1665 -      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
     1666 -    break;
     1667 -
     1668 -  case JCS_YCbCr:
     1669 -    if (cinfo->num_components != 3)
     1670 -      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
     1671 -    if (cinfo->in_color_space == JCS_RGB) {
     1672 -      cconvert->pub.start_pass = rgb_ycc_start;
     1673 -      cconvert->pub.color_convert = rgb_ycc_convert;
     1674 -    } else if (cinfo->in_color_space == JCS_YCbCr)
     1675 -      cconvert->pub.color_convert = null_convert;
     1676 -    else
     1677 -      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
     1678 -    break;
     1679 -
     1680 -  case JCS_CMYK:
     1681 -    if (cinfo->num_components != 4)
     1682 -      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
     1683 -    if (cinfo->in_color_space == JCS_CMYK)
     1684 -      cconvert->pub.color_convert = null_convert;
     1685 -    else
     1686 -      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
     1687 -    break;
     1688 -
     1689 -  case JCS_YCCK:
     1690 -    if (cinfo->num_components != 4)
     1691 -      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
     1692 -    if (cinfo->in_color_space == JCS_CMYK) {
     1693 -      cconvert->pub.start_pass = rgb_ycc_start;
     1694 -      cconvert->pub.color_convert = cmyk_ycck_convert;
     1695 -    } else if (cinfo->in_color_space == JCS_YCCK)
     1696 -      cconvert->pub.color_convert = null_convert;
     1697 -    else
     1698 -      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
     1699 -    break;
     1700 -
     1701 -  default:                      /* allow null conversion of JCS_UNKNOWN */
     1702 -    if (cinfo->jpeg_color_space != cinfo->in_color_space ||
     1703 -        cinfo->num_components != cinfo->input_components)
     1704 -      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
     1705 -    cconvert->pub.color_convert = null_convert;
     1706 -    break;
     1707 -  }
     1708 -}
     1709 diff -ruN ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcdctmgr.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcdctmgr.c
     1710 --- ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcdctmgr.c	2007-10-30 04:38:51.000000000 -0400
     1711 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcdctmgr.c	1969-12-31 19:00:00.000000000 -0500
     1712 @@ -1,391 +0,0 @@
     1713 -/*
     1714 - * reserved comment block
     1715 - * DO NOT REMOVE OR ALTER!
     1716 - */
     1717 -/*
     1718 - * jcdctmgr.c
     1719 - *
     1720 - * Copyright (C) 1994-1996, Thomas G. Lane.
     1721 - * This file is part of the Independent JPEG Group's software.
     1722 - * For conditions of distribution and use, see the accompanying README file.
     1723 - *
     1724 - * This file contains the forward-DCT management logic.
     1725 - * This code selects a particular DCT implementation to be used,
     1726 - * and it performs related housekeeping chores including coefficient
     1727 - * quantization.
     1728 - */
     1729 -
     1730 -#define JPEG_INTERNALS
     1731 -#include "jinclude.h"
     1732 -#include "jpeglib.h"
     1733 -#include "jdct.h"               /* Private declarations for DCT subsystem */
     1734 -
     1735 -
     1736 -/* Private subobject for this module */
     1737 -
     1738 -typedef struct {
     1739 -  struct jpeg_forward_dct pub;  /* public fields */
     1740 -
     1741 -  /* Pointer to the DCT routine actually in use */
     1742 -  forward_DCT_method_ptr do_dct;
     1743 -
     1744 -  /* The actual post-DCT divisors --- not identical to the quant table
     1745 -   * entries, because of scaling (especially for an unnormalized DCT).
     1746 -   * Each table is given in normal array order.
     1747 -   */
     1748 -  DCTELEM * divisors[NUM_QUANT_TBLS];
     1749 -
     1750 -#ifdef DCT_FLOAT_SUPPORTED
     1751 -  /* Same as above for the floating-point case. */
     1752 -  float_DCT_method_ptr do_float_dct;
     1753 -  FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
     1754 -#endif
     1755 -} my_fdct_controller;
     1756 -
     1757 -typedef my_fdct_controller * my_fdct_ptr;
     1758 -
     1759 -
     1760 -/*
     1761 - * Initialize for a processing pass.
     1762 - * Verify that all referenced Q-tables are present, and set up
     1763 - * the divisor table for each one.
     1764 - * In the current implementation, DCT of all components is done during
     1765 - * the first pass, even if only some components will be output in the
     1766 - * first scan.  Hence all components should be examined here.
     1767 - */
     1768 -
     1769 -METHODDEF(void)
     1770 -start_pass_fdctmgr (j_compress_ptr cinfo)
     1771 -{
     1772 -  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
     1773 -  int ci, qtblno, i;
     1774 -  jpeg_component_info *compptr;
     1775 -  JQUANT_TBL * qtbl;
     1776 -  DCTELEM * dtbl;
     1777 -
     1778 -  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
     1779 -       ci++, compptr++) {
     1780 -    qtblno = compptr->quant_tbl_no;
     1781 -    /* Make sure specified quantization table is present */
     1782 -    if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
     1783 -        cinfo->quant_tbl_ptrs[qtblno] == NULL)
     1784 -      ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
     1785 -    qtbl = cinfo->quant_tbl_ptrs[qtblno];
     1786 -    /* Compute divisors for this quant table */
     1787 -    /* We may do this more than once for same table, but it's not a big deal */
     1788 -    switch (cinfo->dct_method) {
     1789 -#ifdef DCT_ISLOW_SUPPORTED
     1790 -    case JDCT_ISLOW:
     1791 -      /* For LL&M IDCT method, divisors are equal to raw quantization
     1792 -       * coefficients multiplied by 8 (to counteract scaling).
     1793 -       */
     1794 -      if (fdct->divisors[qtblno] == NULL) {
     1795 -        fdct->divisors[qtblno] = (DCTELEM *)
     1796 -          (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     1797 -                                      DCTSIZE2 * SIZEOF(DCTELEM));
     1798 -      }
     1799 -      dtbl = fdct->divisors[qtblno];
     1800 -      for (i = 0; i < DCTSIZE2; i++) {
     1801 -        dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
     1802 -      }
     1803 -      break;
     1804 -#endif
     1805 -#ifdef DCT_IFAST_SUPPORTED
     1806 -    case JDCT_IFAST:
     1807 -      {
     1808 -        /* For AA&N IDCT method, divisors are equal to quantization
     1809 -         * coefficients scaled by scalefactor[row]*scalefactor[col], where
     1810 -         *   scalefactor[0] = 1
     1811 -         *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
     1812 -         * We apply a further scale factor of 8.
     1813 -         */
     1814 -#define CONST_BITS 14
     1815 -        static const INT16 aanscales[DCTSIZE2] = {
     1816 -          /* precomputed values scaled up by 14 bits */
     1817 -          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
     1818 -          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
     1819 -          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
     1820 -          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
     1821 -          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
     1822 -          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
     1823 -           8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
     1824 -           4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
     1825 -        };
     1826 -        SHIFT_TEMPS
     1827 -
     1828 -        if (fdct->divisors[qtblno] == NULL) {
     1829 -          fdct->divisors[qtblno] = (DCTELEM *)
     1830 -            (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     1831 -                                        DCTSIZE2 * SIZEOF(DCTELEM));
     1832 -        }
     1833 -        dtbl = fdct->divisors[qtblno];
     1834 -        for (i = 0; i < DCTSIZE2; i++) {
     1835 -          dtbl[i] = (DCTELEM)
     1836 -            DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
     1837 -                                  (INT32) aanscales[i]),
     1838 -                    CONST_BITS-3);
     1839 -        }
     1840 -      }
     1841 -      break;
     1842 -#endif
     1843 -#ifdef DCT_FLOAT_SUPPORTED
     1844 -    case JDCT_FLOAT:
     1845 -      {
     1846 -        /* For float AA&N IDCT method, divisors are equal to quantization
     1847 -         * coefficients scaled by scalefactor[row]*scalefactor[col], where
     1848 -         *   scalefactor[0] = 1
     1849 -         *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
     1850 -         * We apply a further scale factor of 8.
     1851 -         * What's actually stored is 1/divisor so that the inner loop can
     1852 -         * use a multiplication rather than a division.
     1853 -         */
     1854 -        FAST_FLOAT * fdtbl;
     1855 -        int row, col;
     1856 -        static const double aanscalefactor[DCTSIZE] = {
     1857 -          1.0, 1.387039845, 1.306562965, 1.175875602,
     1858 -          1.0, 0.785694958, 0.541196100, 0.275899379
     1859 -        };
     1860 -
     1861 -        if (fdct->float_divisors[qtblno] == NULL) {
     1862 -          fdct->float_divisors[qtblno] = (FAST_FLOAT *)
     1863 -            (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     1864 -                                        DCTSIZE2 * SIZEOF(FAST_FLOAT));
     1865 -        }
     1866 -        fdtbl = fdct->float_divisors[qtblno];
     1867 -        i = 0;
     1868 -        for (row = 0; row < DCTSIZE; row++) {
     1869 -          for (col = 0; col < DCTSIZE; col++) {
     1870 -            fdtbl[i] = (FAST_FLOAT)
     1871 -              (1.0 / (((double) qtbl->quantval[i] *
     1872 -                       aanscalefactor[row] * aanscalefactor[col] * 8.0)));
     1873 -            i++;
     1874 -          }
     1875 -        }
     1876 -      }
     1877 -      break;
     1878 -#endif
     1879 -    default:
     1880 -      ERREXIT(cinfo, JERR_NOT_COMPILED);
     1881 -      break;
     1882 -    }
     1883 -  }
     1884 -}
     1885 -
     1886 -
     1887 -/*
     1888 - * Perform forward DCT on one or more blocks of a component.
     1889 - *
     1890 - * The input samples are taken from the sample_data[] array starting at
     1891 - * position start_row/start_col, and moving to the right for any additional
     1892 - * blocks. The quantized coefficients are returned in coef_blocks[].
     1893 - */
     1894 -
     1895 -METHODDEF(void)
     1896 -forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
     1897 -             JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
     1898 -             JDIMENSION start_row, JDIMENSION start_col,
     1899 -             JDIMENSION num_blocks)
     1900 -/* This version is used for integer DCT implementations. */
     1901 -{
     1902 -  /* This routine is heavily used, so it's worth coding it tightly. */
     1903 -  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
     1904 -  forward_DCT_method_ptr do_dct = fdct->do_dct;
     1905 -  DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
     1906 -  DCTELEM workspace[DCTSIZE2];  /* work area for FDCT subroutine */
     1907 -  JDIMENSION bi;
     1908 -
     1909 -  sample_data += start_row;     /* fold in the vertical offset once */
     1910 -
     1911 -  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
     1912 -    /* Load data into workspace, applying unsigned->signed conversion */
     1913 -    { register DCTELEM *workspaceptr;
     1914 -      register JSAMPROW elemptr;
     1915 -      register int elemr;
     1916 -
     1917 -      workspaceptr = workspace;
     1918 -      for (elemr = 0; elemr < DCTSIZE; elemr++) {
     1919 -        elemptr = sample_data[elemr] + start_col;
     1920 -#if DCTSIZE == 8                /* unroll the inner loop */
     1921 -        *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
     1922 -        *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
     1923 -        *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
     1924 -        *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
     1925 -        *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
     1926 -        *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
     1927 -        *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
     1928 -        *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
     1929 -#else
     1930 -        { register int elemc;
     1931 -          for (elemc = DCTSIZE; elemc > 0; elemc--) {
     1932 -            *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
     1933 -          }
     1934 -        }
     1935 -#endif
     1936 -      }
     1937 -    }
     1938 -
     1939 -    /* Perform the DCT */
     1940 -    (*do_dct) (workspace);
     1941 -
     1942 -    /* Quantize/descale the coefficients, and store into coef_blocks[] */
     1943 -    { register DCTELEM temp, qval;
     1944 -      register int i;
     1945 -      register JCOEFPTR output_ptr = coef_blocks[bi];
     1946 -
     1947 -      for (i = 0; i < DCTSIZE2; i++) {
     1948 -        qval = divisors[i];
     1949 -        temp = workspace[i];
     1950 -        /* Divide the coefficient value by qval, ensuring proper rounding.
     1951 -         * Since C does not specify the direction of rounding for negative
     1952 -         * quotients, we have to force the dividend positive for portability.
     1953 -         *
     1954 -         * In most files, at least half of the output values will be zero
     1955 -         * (at default quantization settings, more like three-quarters...)
     1956 -         * so we should ensure that this case is fast.  On many machines,
     1957 -         * a comparison is enough cheaper than a divide to make a special test
     1958 -         * a win.  Since both inputs will be nonnegative, we need only test
     1959 -         * for a < b to discover whether a/b is 0.
     1960 -         * If your machine's division is fast enough, define FAST_DIVIDE.
     1961 -         */
     1962 -#ifdef FAST_DIVIDE
     1963 -#define DIVIDE_BY(a,b)  a /= b
     1964 -#else
     1965 -#define DIVIDE_BY(a,b)  if (a >= b) a /= b; else a = 0
     1966 -#endif
     1967 -        if (temp < 0) {
     1968 -          temp = -temp;
     1969 -          temp += qval>>1;      /* for rounding */
     1970 -          DIVIDE_BY(temp, qval);
     1971 -          temp = -temp;
     1972 -        } else {
     1973 -          temp += qval>>1;      /* for rounding */
     1974 -          DIVIDE_BY(temp, qval);
     1975 -        }
     1976 -        output_ptr[i] = (JCOEF) temp;
     1977 -      }
     1978 -    }
     1979 -  }
     1980 -}
     1981 -
     1982 -
     1983 -#ifdef DCT_FLOAT_SUPPORTED
     1984 -
     1985 -METHODDEF(void)
     1986 -forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
     1987 -                   JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
     1988 -                   JDIMENSION start_row, JDIMENSION start_col,
     1989 -                   JDIMENSION num_blocks)
     1990 -/* This version is used for floating-point DCT implementations. */
     1991 -{
     1992 -  /* This routine is heavily used, so it's worth coding it tightly. */
     1993 -  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
     1994 -  float_DCT_method_ptr do_dct = fdct->do_float_dct;
     1995 -  FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
     1996 -  FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
     1997 -  JDIMENSION bi;
     1998 -
     1999 -  sample_data += start_row;     /* fold in the vertical offset once */
     2000 -
     2001 -  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
     2002 -    /* Load data into workspace, applying unsigned->signed conversion */
     2003 -    { register FAST_FLOAT *workspaceptr;
     2004 -      register JSAMPROW elemptr;
     2005 -      register int elemr;
     2006 -
     2007 -      workspaceptr = workspace;
     2008 -      for (elemr = 0; elemr < DCTSIZE; elemr++) {
     2009 -        elemptr = sample_data[elemr] + start_col;
     2010 -#if DCTSIZE == 8                /* unroll the inner loop */
     2011 -        *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
     2012 -        *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
     2013 -        *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
     2014 -        *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
     2015 -        *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
     2016 -        *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
     2017 -        *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
     2018 -        *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
     2019 -#else
     2020 -        { register int elemc;
     2021 -          for (elemc = DCTSIZE; elemc > 0; elemc--) {
     2022 -            *workspaceptr++ = (FAST_FLOAT)
     2023 -              (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
     2024 -          }
     2025 -        }
     2026 -#endif
     2027 -      }
     2028 -    }
     2029 -
     2030 -    /* Perform the DCT */
     2031 -    (*do_dct) (workspace);
     2032 -
     2033 -    /* Quantize/descale the coefficients, and store into coef_blocks[] */
     2034 -    { register FAST_FLOAT temp;
     2035 -      register int i;
     2036 -      register JCOEFPTR output_ptr = coef_blocks[bi];
     2037 -
     2038 -      for (i = 0; i < DCTSIZE2; i++) {
     2039 -        /* Apply the quantization and scaling factor */
     2040 -        temp = workspace[i] * divisors[i];
     2041 -        /* Round to nearest integer.
     2042 -         * Since C does not specify the direction of rounding for negative
     2043 -         * quotients, we have to force the dividend positive for portability.
     2044 -         * The maximum coefficient size is +-16K (for 12-bit data), so this
     2045 -         * code should work for either 16-bit or 32-bit ints.
     2046 -         */
     2047 -        output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
     2048 -      }
     2049 -    }
     2050 -  }
     2051 -}
     2052 -
     2053 -#endif /* DCT_FLOAT_SUPPORTED */
     2054 -
     2055 -
     2056 -/*
     2057 - * Initialize FDCT manager.
     2058 - */
     2059 -
     2060 -GLOBAL(void)
     2061 -jinit_forward_dct (j_compress_ptr cinfo)
     2062 -{
     2063 -  my_fdct_ptr fdct;
     2064 -  int i;
     2065 -
     2066 -  fdct = (my_fdct_ptr)
     2067 -    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     2068 -                                SIZEOF(my_fdct_controller));
     2069 -  cinfo->fdct = (struct jpeg_forward_dct *) fdct;
     2070 -  fdct->pub.start_pass = start_pass_fdctmgr;
     2071 -
     2072 -  switch (cinfo->dct_method) {
     2073 -#ifdef DCT_ISLOW_SUPPORTED
     2074 -  case JDCT_ISLOW:
     2075 -    fdct->pub.forward_DCT = forward_DCT;
     2076 -    fdct->do_dct = jpeg_fdct_islow;
     2077 -    break;
     2078 -#endif
     2079 -#ifdef DCT_IFAST_SUPPORTED
     2080 -  case JDCT_IFAST:
     2081 -    fdct->pub.forward_DCT = forward_DCT;
     2082 -    fdct->do_dct = jpeg_fdct_ifast;
     2083 -    break;
     2084 -#endif
     2085 -#ifdef DCT_FLOAT_SUPPORTED
     2086 -  case JDCT_FLOAT:
     2087 -    fdct->pub.forward_DCT = forward_DCT_float;
     2088 -    fdct->do_float_dct = jpeg_fdct_float;
     2089 -    break;
     2090 -#endif
     2091 -  default:
     2092 -    ERREXIT(cinfo, JERR_NOT_COMPILED);
     2093 -    break;
     2094 -  }
     2095 -
     2096 -  /* Mark divisor tables unallocated */
     2097 -  for (i = 0; i < NUM_QUANT_TBLS; i++) {
     2098 -    fdct->divisors[i] = NULL;
     2099 -#ifdef DCT_FLOAT_SUPPORTED
     2100 -    fdct->float_divisors[i] = NULL;
     2101 -#endif
     2102 -  }
     2103 -}
     2104 diff -ruN ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jchuff.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jchuff.c
     2105 --- ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jchuff.c	2007-10-30 04:38:51.000000000 -0400
     2106 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jchuff.c	1969-12-31 19:00:00.000000000 -0500
     2107 @@ -1,913 +0,0 @@
     2108 -/*
     2109 - * reserved comment block
     2110 - * DO NOT REMOVE OR ALTER!
     2111 - */
     2112 -/*
     2113 - * jchuff.c
     2114 - *
     2115 - * Copyright (C) 1991-1997, Thomas G. Lane.
     2116 - * This file is part of the Independent JPEG Group's software.
     2117 - * For conditions of distribution and use, see the accompanying README file.
     2118 - *
     2119 - * This file contains Huffman entropy encoding routines.
     2120 - *
     2121 - * Much of the complexity here has to do with supporting output suspension.
     2122 - * If the data destination module demands suspension, we want to be able to
     2123 - * back up to the start of the current MCU.  To do this, we copy state
     2124 - * variables into local working storage, and update them back to the
     2125 - * permanent JPEG objects only upon successful completion of an MCU.
     2126 - */
     2127 -
     2128 -#define JPEG_INTERNALS
     2129 -#include "jinclude.h"
     2130 -#include "jpeglib.h"
     2131 -#include "jchuff.h"             /* Declarations shared with jcphuff.c */
     2132 -
     2133 -
     2134 -/* Expanded entropy encoder object for Huffman encoding.
     2135 - *
     2136 - * The savable_state subrecord contains fields that change within an MCU,
     2137 - * but must not be updated permanently until we complete the MCU.
     2138 - */
     2139 -
     2140 -typedef struct {
     2141 -  INT32 put_buffer;             /* current bit-accumulation buffer */
     2142 -  int put_bits;                 /* # of bits now in it */
     2143 -  int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
     2144 -} savable_state;
     2145 -
     2146 -/* This macro is to work around compilers with missing or broken
     2147 - * structure assignment.  You'll need to fix this code if you have
     2148 - * such a compiler and you change MAX_COMPS_IN_SCAN.
     2149 - */
     2150 -
     2151 -#ifndef NO_STRUCT_ASSIGN
     2152 -#define ASSIGN_STATE(dest,src)  ((dest) = (src))
     2153 -#else
     2154 -#if MAX_COMPS_IN_SCAN == 4
     2155 -#define ASSIGN_STATE(dest,src)  \
     2156 -        ((dest).put_buffer = (src).put_buffer, \
     2157 -         (dest).put_bits = (src).put_bits, \
     2158 -         (dest).last_dc_val[0] = (src).last_dc_val[0], \
     2159 -         (dest).last_dc_val[1] = (src).last_dc_val[1], \
     2160 -         (dest).last_dc_val[2] = (src).last_dc_val[2], \
     2161 -         (dest).last_dc_val[3] = (src).last_dc_val[3])
     2162 -#endif
     2163 -#endif
     2164 -
     2165 -
     2166 -typedef struct {
     2167 -  struct jpeg_entropy_encoder pub; /* public fields */
     2168 -
     2169 -  savable_state saved;          /* Bit buffer & DC state at start of MCU */
     2170 -
     2171 -  /* These fields are NOT loaded into local working state. */
     2172 -  unsigned int restarts_to_go;  /* MCUs left in this restart interval */
     2173 -  int next_restart_num;         /* next restart number to write (0-7) */
     2174 -
     2175 -  /* Pointers to derived tables (these workspaces have image lifespan) */
     2176 -  c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
     2177 -  c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
     2178 -
     2179 -#ifdef ENTROPY_OPT_SUPPORTED    /* Statistics tables for optimization */
     2180 -  long * dc_count_ptrs[NUM_HUFF_TBLS];
     2181 -  long * ac_count_ptrs[NUM_HUFF_TBLS];
     2182 -#endif
     2183 -} huff_entropy_encoder;
     2184 -
     2185 -typedef huff_entropy_encoder * huff_entropy_ptr;
     2186 -
     2187 -/* Working state while writing an MCU.
     2188 - * This struct contains all the fields that are needed by subroutines.
     2189 - */
     2190 -
     2191 -typedef struct {
     2192 -  JOCTET * next_output_byte;    /* => next byte to write in buffer */
     2193 -  size_t free_in_buffer;        /* # of byte spaces remaining in buffer */
     2194 -  savable_state cur;            /* Current bit buffer & DC state */
     2195 -  j_compress_ptr cinfo;         /* dump_buffer needs access to this */
     2196 -} working_state;
     2197 -
     2198 -
     2199 -/* Forward declarations */
     2200 -METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
     2201 -                                        JBLOCKROW *MCU_data));
     2202 -METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
     2203 -#ifdef ENTROPY_OPT_SUPPORTED
     2204 -METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
     2205 -                                          JBLOCKROW *MCU_data));
     2206 -METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
     2207 -#endif
     2208 -
     2209 -
     2210 -/*
     2211 - * Initialize for a Huffman-compressed scan.
     2212 - * If gather_statistics is TRUE, we do not output anything during the scan,
     2213 - * just count the Huffman symbols used and generate Huffman code tables.
     2214 - */
     2215 -
     2216 -METHODDEF(void)
     2217 -start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
     2218 -{
     2219 -  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
     2220 -  int ci, dctbl, actbl;
     2221 -  jpeg_component_info * compptr;
     2222 -
     2223 -  if (gather_statistics) {
     2224 -#ifdef ENTROPY_OPT_SUPPORTED
     2225 -    entropy->pub.encode_mcu = encode_mcu_gather;
     2226 -    entropy->pub.finish_pass = finish_pass_gather;
     2227 -#else
     2228 -    ERREXIT(cinfo, JERR_NOT_COMPILED);
     2229 -#endif
     2230 -  } else {
     2231 -    entropy->pub.encode_mcu = encode_mcu_huff;
     2232 -    entropy->pub.finish_pass = finish_pass_huff;
     2233 -  }
     2234 -
     2235 -  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
     2236 -    compptr = cinfo->cur_comp_info[ci];
     2237 -    dctbl = compptr->dc_tbl_no;
     2238 -    actbl = compptr->ac_tbl_no;
     2239 -    if (gather_statistics) {
     2240 -#ifdef ENTROPY_OPT_SUPPORTED
     2241 -      /* Check for invalid table indexes */
     2242 -      /* (make_c_derived_tbl does this in the other path) */
     2243 -      if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
     2244 -        ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
     2245 -      if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
     2246 -        ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
     2247 -      /* Allocate and zero the statistics tables */
     2248 -      /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
     2249 -      if (entropy->dc_count_ptrs[dctbl] == NULL)
     2250 -        entropy->dc_count_ptrs[dctbl] = (long *)
     2251 -          (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     2252 -                                      257 * SIZEOF(long));
     2253 -      MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
     2254 -      if (entropy->ac_count_ptrs[actbl] == NULL)
     2255 -        entropy->ac_count_ptrs[actbl] = (long *)
     2256 -          (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     2257 -                                      257 * SIZEOF(long));
     2258 -      MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
     2259 -#endif
     2260 -    } else {
     2261 -      /* Compute derived values for Huffman tables */
     2262 -      /* We may do this more than once for a table, but it's not expensive */
     2263 -      jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
     2264 -                              & entropy->dc_derived_tbls[dctbl]);
     2265 -      jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
     2266 -                              & entropy->ac_derived_tbls[actbl]);
     2267 -    }
     2268 -    /* Initialize DC predictions to 0 */
     2269 -    entropy->saved.last_dc_val[ci] = 0;
     2270 -  }
     2271 -
     2272 -  /* Initialize bit buffer to empty */
     2273 -  entropy->saved.put_buffer = 0;
     2274 -  entropy->saved.put_bits = 0;
     2275 -
     2276 -  /* Initialize restart stuff */
     2277 -  entropy->restarts_to_go = cinfo->restart_interval;
     2278 -  entropy->next_restart_num = 0;
     2279 -}
     2280 -
     2281 -
     2282 -/*
     2283 - * Compute the derived values for a Huffman table.
     2284 - * This routine also performs some validation checks on the table.
     2285 - *
     2286 - * Note this is also used by jcphuff.c.
     2287 - */
     2288 -
     2289 -GLOBAL(void)
     2290 -jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
     2291 -                         c_derived_tbl ** pdtbl)
     2292 -{
     2293 -  JHUFF_TBL *htbl;
     2294 -  c_derived_tbl *dtbl;
     2295 -  int p, i, l, lastp, si, maxsymbol;
     2296 -  char huffsize[257];
     2297 -  unsigned int huffcode[257];
     2298 -  unsigned int code;
     2299 -
     2300 -  /* Note that huffsize[] and huffcode[] are filled in code-length order,
     2301 -   * paralleling the order of the symbols themselves in htbl->huffval[].
     2302 -   */
     2303 -
     2304 -  /* Find the input Huffman table */
     2305 -  if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
     2306 -    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
     2307 -  htbl =
     2308 -    isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
     2309 -  if (htbl == NULL)
     2310 -    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
     2311 -
     2312 -  /* Allocate a workspace if we haven't already done so. */
     2313 -  if (*pdtbl == NULL)
     2314 -    *pdtbl = (c_derived_tbl *)
     2315 -      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     2316 -                                  SIZEOF(c_derived_tbl));
     2317 -  dtbl = *pdtbl;
     2318 -
     2319 -  /* Figure C.1: make table of Huffman code length for each symbol */
     2320 -
     2321 -  p = 0;
     2322 -  for (l = 1; l <= 16; l++) {
     2323 -    i = (int) htbl->bits[l];
     2324 -    if (i < 0 || p + i > 256)   /* protect against table overrun */
     2325 -      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
     2326 -    while (i--)
     2327 -      huffsize[p++] = (char) l;
     2328 -  }
     2329 -  huffsize[p] = 0;
     2330 -  lastp = p;
     2331 -
     2332 -  /* Figure C.2: generate the codes themselves */
     2333 -  /* We also validate that the counts represent a legal Huffman code tree. */
     2334 -
     2335 -  code = 0;
     2336 -  si = huffsize[0];
     2337 -  p = 0;
     2338 -  while (huffsize[p]) {
     2339 -    while (((int) huffsize[p]) == si) {
     2340 -      huffcode[p++] = code;
     2341 -      code++;
     2342 -    }
     2343 -    /* code is now 1 more than the last code used for codelength si; but
     2344 -     * it must still fit in si bits, since no code is allowed to be all ones.
     2345 -     */
     2346 -    if (((INT32) code) >= (((INT32) 1) << si))
     2347 -      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
     2348 -    code <<= 1;
     2349 -    si++;
     2350 -  }
     2351 -
     2352 -  /* Figure C.3: generate encoding tables */
     2353 -  /* These are code and size indexed by symbol value */
     2354 -
     2355 -  /* Set all codeless symbols to have code length 0;
     2356 -   * this lets us detect duplicate VAL entries here, and later
     2357 -   * allows emit_bits to detect any attempt to emit such symbols.
     2358 -   */
     2359 -  MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
     2360 -
     2361 -  /* This is also a convenient place to check for out-of-range
     2362 -   * and duplicated VAL entries.  We allow 0..255 for AC symbols
     2363 -   * but only 0..15 for DC.  (We could constrain them further
     2364 -   * based on data depth and mode, but this seems enough.)
     2365 -   */
     2366 -  maxsymbol = isDC ? 15 : 255;
     2367 -
     2368 -  for (p = 0; p < lastp; p++) {
     2369 -    i = htbl->huffval[p];
     2370 -    if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
     2371 -      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
     2372 -    dtbl->ehufco[i] = huffcode[p];
     2373 -    dtbl->ehufsi[i] = huffsize[p];
     2374 -  }
     2375 -}
     2376 -
     2377 -
     2378 -/* Outputting bytes to the file */
     2379 -
     2380 -/* Emit a byte, taking 'action' if must suspend. */
     2381 -#define emit_byte(state,val,action)  \
     2382 -        { *(state)->next_output_byte++ = (JOCTET) (val);  \
     2383 -          if (--(state)->free_in_buffer == 0)  \
     2384 -            if (! dump_buffer(state))  \
     2385 -              { action; } }
     2386 -
     2387 -
     2388 -LOCAL(boolean)
     2389 -dump_buffer (working_state * state)
     2390 -/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
     2391 -{
     2392 -  struct jpeg_destination_mgr * dest = state->cinfo->dest;
     2393 -
     2394 -  if (! (*dest->empty_output_buffer) (state->cinfo))
     2395 -    return FALSE;
     2396 -  /* After a successful buffer dump, must reset buffer pointers */
     2397 -  state->next_output_byte = dest->next_output_byte;
     2398 -  state->free_in_buffer = dest->free_in_buffer;
     2399 -  return TRUE;
     2400 -}
     2401 -
     2402 -
     2403 -/* Outputting bits to the file */
     2404 -
     2405 -/* Only the right 24 bits of put_buffer are used; the valid bits are
     2406 - * left-justified in this part.  At most 16 bits can be passed to emit_bits
     2407 - * in one call, and we never retain more than 7 bits in put_buffer
     2408 - * between calls, so 24 bits are sufficient.
     2409 - */
     2410 -
     2411 -INLINE
     2412 -LOCAL(boolean)
     2413 -emit_bits (working_state * state, unsigned int code, int size)
     2414 -/* Emit some bits; return TRUE if successful, FALSE if must suspend */
     2415 -{
     2416 -  /* This routine is heavily used, so it's worth coding tightly. */
     2417 -  register INT32 put_buffer = (INT32) code;
     2418 -  register int put_bits = state->cur.put_bits;
     2419 -
     2420 -  /* if size is 0, caller used an invalid Huffman table entry */
     2421 -  if (size == 0)
     2422 -    ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
     2423 -
     2424 -  put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
     2425 -
     2426 -  put_bits += size;             /* new number of bits in buffer */
     2427 -
     2428 -  put_buffer <<= 24 - put_bits; /* align incoming bits */
     2429 -
     2430 -  put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
     2431 -
     2432 -  while (put_bits >= 8) {
     2433 -    int c = (int) ((put_buffer >> 16) & 0xFF);
     2434 -
     2435 -    emit_byte(state, c, return FALSE);
     2436 -    if (c == 0xFF) {            /* need to stuff a zero byte? */
     2437 -      emit_byte(state, 0, return FALSE);
     2438 -    }
     2439 -    put_buffer <<= 8;
     2440 -    put_bits -= 8;
     2441 -  }
     2442 -
     2443 -  state->cur.put_buffer = put_buffer; /* update state variables */
     2444 -  state->cur.put_bits = put_bits;
     2445 -
     2446 -  return TRUE;
     2447 -}
     2448 -
     2449 -
     2450 -LOCAL(boolean)
     2451 -flush_bits (working_state * state)
     2452 -{
     2453 -  if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
     2454 -    return FALSE;
     2455 -  state->cur.put_buffer = 0;    /* and reset bit-buffer to empty */
     2456 -  state->cur.put_bits = 0;
     2457 -  return TRUE;
     2458 -}
     2459 -
     2460 -
     2461 -/* Encode a single block's worth of coefficients */
     2462 -
     2463 -LOCAL(boolean)
     2464 -encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
     2465 -                  c_derived_tbl *dctbl, c_derived_tbl *actbl)
     2466 -{
     2467 -  register int temp, temp2;
     2468 -  register int nbits;
     2469 -  register int k, r, i;
     2470 -
     2471 -  /* Encode the DC coefficient difference per section F.1.2.1 */
     2472 -
     2473 -  temp = temp2 = block[0] - last_dc_val;
     2474 -
     2475 -  if (temp < 0) {
     2476 -    temp = -temp;               /* temp is abs value of input */
     2477 -    /* For a negative input, want temp2 = bitwise complement of abs(input) */
     2478 -    /* This code assumes we are on a two's complement machine */
     2479 -    temp2--;
     2480 -  }
     2481 -
     2482 -  /* Find the number of bits needed for the magnitude of the coefficient */
     2483 -  nbits = 0;
     2484 -  while (temp) {
     2485 -    nbits++;
     2486 -    temp >>= 1;
     2487 -  }
     2488 -  /* Check for out-of-range coefficient values.
     2489 -   * Since we're encoding a difference, the range limit is twice as much.
     2490 -   */
     2491 -  if (nbits > MAX_COEF_BITS+1)
     2492 -    ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
     2493 -
     2494 -  /* Emit the Huffman-coded symbol for the number of bits */
     2495 -  if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
     2496 -    return FALSE;
     2497 -
     2498 -  /* Emit that number of bits of the value, if positive, */
     2499 -  /* or the complement of its magnitude, if negative. */
     2500 -  if (nbits)                    /* emit_bits rejects calls with size 0 */
     2501 -    if (! emit_bits(state, (unsigned int) temp2, nbits))
     2502 -      return FALSE;
     2503 -
     2504 -  /* Encode the AC coefficients per section F.1.2.2 */
     2505 -
     2506 -  r = 0;                        /* r = run length of zeros */
     2507 -
     2508 -  for (k = 1; k < DCTSIZE2; k++) {
     2509 -    if ((temp = block[jpeg_natural_order[k]]) == 0) {
     2510 -      r++;
     2511 -    } else {
     2512 -      /* if run length > 15, must emit special run-length-16 codes (0xF0) */
     2513 -      while (r > 15) {
     2514 -        if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
     2515 -          return FALSE;
     2516 -        r -= 16;
     2517 -      }
     2518 -
     2519 -      temp2 = temp;
     2520 -      if (temp < 0) {
     2521 -        temp = -temp;           /* temp is abs value of input */
     2522 -        /* This code assumes we are on a two's complement machine */
     2523 -        temp2--;
     2524 -      }
     2525 -
     2526 -      /* Find the number of bits needed for the magnitude of the coefficient */
     2527 -      nbits = 1;                /* there must be at least one 1 bit */
     2528 -      while ((temp >>= 1))
     2529 -        nbits++;
     2530 -      /* Check for out-of-range coefficient values */
     2531 -      if (nbits > MAX_COEF_BITS)
     2532 -        ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
     2533 -
     2534 -      /* Emit Huffman symbol for run length / number of bits */
     2535 -      i = (r << 4) + nbits;
     2536 -      if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
     2537 -        return FALSE;
     2538 -
     2539 -      /* Emit that number of bits of the value, if positive, */
     2540 -      /* or the complement of its magnitude, if negative. */
     2541 -      if (! emit_bits(state, (unsigned int) temp2, nbits))
     2542 -        return FALSE;
     2543 -
     2544 -      r = 0;
     2545 -    }
     2546 -  }
     2547 -
     2548 -  /* If the last coef(s) were zero, emit an end-of-block code */
     2549 -  if (r > 0)
     2550 -    if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
     2551 -      return FALSE;
     2552 -
     2553 -  return TRUE;
     2554 -}
     2555 -
     2556 -
     2557 -/*
     2558 - * Emit a restart marker & resynchronize predictions.
     2559 - */
     2560 -
     2561 -LOCAL(boolean)
     2562 -emit_restart (working_state * state, int restart_num)
     2563 -{
     2564 -  int ci;
     2565 -
     2566 -  if (! flush_bits(state))
     2567 -    return FALSE;
     2568 -
     2569 -  emit_byte(state, 0xFF, return FALSE);
     2570 -  emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
     2571 -
     2572 -  /* Re-initialize DC predictions to 0 */
     2573 -  for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
     2574 -    state->cur.last_dc_val[ci] = 0;
     2575 -
     2576 -  /* The restart counter is not updated until we successfully write the MCU. */
     2577 -
     2578 -  return TRUE;
     2579 -}
     2580 -
     2581 -
     2582 -/*
     2583 - * Encode and output one MCU's worth of Huffman-compressed coefficients.
     2584 - */
     2585 -
     2586 -METHODDEF(boolean)
     2587 -encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
     2588 -{
     2589 -  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
     2590 -  working_state state;
     2591 -  int blkn, ci;
     2592 -  jpeg_component_info * compptr;
     2593 -
     2594 -  /* Load up working state */
     2595 -  state.next_output_byte = cinfo->dest->next_output_byte;
     2596 -  state.free_in_buffer = cinfo->dest->free_in_buffer;
     2597 -  ASSIGN_STATE(state.cur, entropy->saved);
     2598 -  state.cinfo = cinfo;
     2599 -
     2600 -  /* Emit restart marker if needed */
     2601 -  if (cinfo->restart_interval) {
     2602 -    if (entropy->restarts_to_go == 0)
     2603 -      if (! emit_restart(&state, entropy->next_restart_num))
     2604 -        return FALSE;
     2605 -  }
     2606 -
     2607 -  /* Encode the MCU data blocks */
     2608 -  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
     2609 -    ci = cinfo->MCU_membership[blkn];
     2610 -    compptr = cinfo->cur_comp_info[ci];
     2611 -    if (! encode_one_block(&state,
     2612 -                           MCU_data[blkn][0], state.cur.last_dc_val[ci],
     2613 -                           entropy->dc_derived_tbls[compptr->dc_tbl_no],
     2614 -                           entropy->ac_derived_tbls[compptr->ac_tbl_no]))
     2615 -      return FALSE;
     2616 -    /* Update last_dc_val */
     2617 -    state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
     2618 -  }
     2619 -
     2620 -  /* Completed MCU, so update state */
     2621 -  cinfo->dest->next_output_byte = state.next_output_byte;
     2622 -  cinfo->dest->free_in_buffer = state.free_in_buffer;
     2623 -  ASSIGN_STATE(entropy->saved, state.cur);
     2624 -
     2625 -  /* Update restart-interval state too */
     2626 -  if (cinfo->restart_interval) {
     2627 -    if (entropy->restarts_to_go == 0) {
     2628 -      entropy->restarts_to_go = cinfo->restart_interval;
     2629 -      entropy->next_restart_num++;
     2630 -      entropy->next_restart_num &= 7;
     2631 -    }
     2632 -    entropy->restarts_to_go--;
     2633 -  }
     2634 -
     2635 -  return TRUE;
     2636 -}
     2637 -
     2638 -
     2639 -/*
     2640 - * Finish up at the end of a Huffman-compressed scan.
     2641 - */
     2642 -
     2643 -METHODDEF(void)
     2644 -finish_pass_huff (j_compress_ptr cinfo)
     2645 -{
     2646 -  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
     2647 -  working_state state;
     2648 -
     2649 -  /* Load up working state ... flush_bits needs it */
     2650 -  state.next_output_byte = cinfo->dest->next_output_byte;
     2651 -  state.free_in_buffer = cinfo->dest->free_in_buffer;
     2652 -  ASSIGN_STATE(state.cur, entropy->saved);
     2653 -  state.cinfo = cinfo;
     2654 -
     2655 -  /* Flush out the last data */
     2656 -  if (! flush_bits(&state))
     2657 -    ERREXIT(cinfo, JERR_CANT_SUSPEND);
     2658 -
     2659 -  /* Update state */
     2660 -  cinfo->dest->next_output_byte = state.next_output_byte;
     2661 -  cinfo->dest->free_in_buffer = state.free_in_buffer;
     2662 -  ASSIGN_STATE(entropy->saved, state.cur);
     2663 -}
     2664 -
     2665 -
     2666 -/*
     2667 - * Huffman coding optimization.
     2668 - *
     2669 - * We first scan the supplied data and count the number of uses of each symbol
     2670 - * that is to be Huffman-coded. (This process MUST agree with the code above.)
     2671 - * Then we build a Huffman coding tree for the observed counts.
     2672 - * Symbols which are not needed at all for the particular image are not
     2673 - * assigned any code, which saves space in the DHT marker as well as in
     2674 - * the compressed data.
     2675 - */
     2676 -
     2677 -#ifdef ENTROPY_OPT_SUPPORTED
     2678 -
     2679 -
     2680 -/* Process a single block's worth of coefficients */
     2681 -
     2682 -LOCAL(void)
     2683 -htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
     2684 -                 long dc_counts[], long ac_counts[])
     2685 -{
     2686 -  register int temp;
     2687 -  register int nbits;
     2688 -  register int k, r;
     2689 -
     2690 -  /* Encode the DC coefficient difference per section F.1.2.1 */
     2691 -
     2692 -  temp = block[0] - last_dc_val;
     2693 -  if (temp < 0)
     2694 -    temp = -temp;
     2695 -
     2696 -  /* Find the number of bits needed for the magnitude of the coefficient */
     2697 -  nbits = 0;
     2698 -  while (temp) {
     2699 -    nbits++;
     2700 -    temp >>= 1;
     2701 -  }
     2702 -  /* Check for out-of-range coefficient values.
     2703 -   * Since we're encoding a difference, the range limit is twice as much.
     2704 -   */
     2705 -  if (nbits > MAX_COEF_BITS+1)
     2706 -    ERREXIT(cinfo, JERR_BAD_DCT_COEF);
     2707 -
     2708 -  /* Count the Huffman symbol for the number of bits */
     2709 -  dc_counts[nbits]++;
     2710 -
     2711 -  /* Encode the AC coefficients per section F.1.2.2 */
     2712 -
     2713 -  r = 0;                        /* r = run length of zeros */
     2714 -
     2715 -  for (k = 1; k < DCTSIZE2; k++) {
     2716 -    if ((temp = block[jpeg_natural_order[k]]) == 0) {
     2717 -      r++;
     2718 -    } else {
     2719 -      /* if run length > 15, must emit special run-length-16 codes (0xF0) */
     2720 -      while (r > 15) {
     2721 -        ac_counts[0xF0]++;
     2722 -        r -= 16;
     2723 -      }
     2724 -
     2725 -      /* Find the number of bits needed for the magnitude of the coefficient */
     2726 -      if (temp < 0)
     2727 -        temp = -temp;
     2728 -
     2729 -      /* Find the number of bits needed for the magnitude of the coefficient */
     2730 -      nbits = 1;                /* there must be at least one 1 bit */
     2731 -      while ((temp >>= 1))
     2732 -        nbits++;
     2733 -      /* Check for out-of-range coefficient values */
     2734 -      if (nbits > MAX_COEF_BITS)
     2735 -        ERREXIT(cinfo, JERR_BAD_DCT_COEF);
     2736 -
     2737 -      /* Count Huffman symbol for run length / number of bits */
     2738 -      ac_counts[(r << 4) + nbits]++;
     2739 -
     2740 -      r = 0;
     2741 -    }
     2742 -  }
     2743 -
     2744 -  /* If the last coef(s) were zero, emit an end-of-block code */
     2745 -  if (r > 0)
     2746 -    ac_counts[0]++;
     2747 -}
     2748 -
     2749 -
     2750 -/*
     2751 - * Trial-encode one MCU's worth of Huffman-compressed coefficients.
     2752 - * No data is actually output, so no suspension return is possible.
     2753 - */
     2754 -
     2755 -METHODDEF(boolean)
     2756 -encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
     2757 -{
     2758 -  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
     2759 -  int blkn, ci;
     2760 -  jpeg_component_info * compptr;
     2761 -
     2762 -  /* Take care of restart intervals if needed */
     2763 -  if (cinfo->restart_interval) {
     2764 -    if (entropy->restarts_to_go == 0) {
     2765 -      /* Re-initialize DC predictions to 0 */
     2766 -      for (ci = 0; ci < cinfo->comps_in_scan; ci++)
     2767 -        entropy->saved.last_dc_val[ci] = 0;
     2768 -      /* Update restart state */
     2769 -      entropy->restarts_to_go = cinfo->restart_interval;
     2770 -    }
     2771 -    entropy->restarts_to_go--;
     2772 -  }
     2773 -
     2774 -  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
     2775 -    ci = cinfo->MCU_membership[blkn];
     2776 -    compptr = cinfo->cur_comp_info[ci];
     2777 -    htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
     2778 -                    entropy->dc_count_ptrs[compptr->dc_tbl_no],
     2779 -                    entropy->ac_count_ptrs[compptr->ac_tbl_no]);
     2780 -    entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
     2781 -  }
     2782 -
     2783 -  return TRUE;
     2784 -}
     2785 -
     2786 -
     2787 -/*
     2788 - * Generate the best Huffman code table for the given counts, fill htbl.
     2789 - * Note this is also used by jcphuff.c.
     2790 - *
     2791 - * The JPEG standard requires that no symbol be assigned a codeword of all
     2792 - * one bits (so that padding bits added at the end of a compressed segment
     2793 - * can't look like a valid code).  Because of the canonical ordering of
     2794 - * codewords, this just means that there must be an unused slot in the
     2795 - * longest codeword length category.  Section K.2 of the JPEG spec suggests
     2796 - * reserving such a slot by pretending that symbol 256 is a valid symbol
     2797 - * with count 1.  In theory that's not optimal; giving it count zero but
     2798 - * including it in the symbol set anyway should give a better Huffman code.
     2799 - * But the theoretically better code actually seems to come out worse in
     2800 - * practice, because it produces more all-ones bytes (which incur stuffed
     2801 - * zero bytes in the final file).  In any case the difference is tiny.
     2802 - *
     2803 - * The JPEG standard requires Huffman codes to be no more than 16 bits long.
     2804 - * If some symbols have a very small but nonzero probability, the Huffman tree
     2805 - * must be adjusted to meet the code length restriction.  We currently use
     2806 - * the adjustment method suggested in JPEG section K.2.  This method is *not*
     2807 - * optimal; it may not choose the best possible limited-length code.  But
     2808 - * typically only very-low-frequency symbols will be given less-than-optimal
     2809 - * lengths, so the code is almost optimal.  Experimental comparisons against
     2810 - * an optimal limited-length-code algorithm indicate that the difference is
     2811 - * microscopic --- usually less than a hundredth of a percent of total size.
     2812 - * So the extra complexity of an optimal algorithm doesn't seem worthwhile.
     2813 - */
     2814 -
     2815 -GLOBAL(void)
     2816 -jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
     2817 -{
     2818 -#define MAX_CLEN 32             /* assumed maximum initial code length */
     2819 -  UINT8 bits[MAX_CLEN+1];       /* bits[k] = # of symbols with code length k */
     2820 -  int codesize[257];            /* codesize[k] = code length of symbol k */
     2821 -  int others[257];              /* next symbol in current branch of tree */
     2822 -  int c1, c2;
     2823 -  int p, i, j;
     2824 -  long v;
     2825 -
     2826 -  /* This algorithm is explained in section K.2 of the JPEG standard */
     2827 -
     2828 -  MEMZERO(bits, SIZEOF(bits));
     2829 -  MEMZERO(codesize, SIZEOF(codesize));
     2830 -  for (i = 0; i < 257; i++)
     2831 -    others[i] = -1;             /* init links to empty */
     2832 -
     2833 -  freq[256] = 1;                /* make sure 256 has a nonzero count */
     2834 -  /* Including the pseudo-symbol 256 in the Huffman procedure guarantees
     2835 -   * that no real symbol is given code-value of all ones, because 256
     2836 -   * will be placed last in the largest codeword category.
     2837 -   */
     2838 -
     2839 -  /* Huffman's basic algorithm to assign optimal code lengths to symbols */
     2840 -
     2841 -  for (;;) {
     2842 -    /* Find the smallest nonzero frequency, set c1 = its symbol */
     2843 -    /* In case of ties, take the larger symbol number */
     2844 -    c1 = -1;
     2845 -    v = 1000000000L;
     2846 -    for (i = 0; i <= 256; i++) {
     2847 -      if (freq[i] && freq[i] <= v) {
     2848 -        v = freq[i];
     2849 -        c1 = i;
     2850 -      }
     2851 -    }
     2852 -
     2853 -    /* Find the next smallest nonzero frequency, set c2 = its symbol */
     2854 -    /* In case of ties, take the larger symbol number */
     2855 -    c2 = -1;
     2856 -    v = 1000000000L;
     2857 -    for (i = 0; i <= 256; i++) {
     2858 -      if (freq[i] && freq[i] <= v && i != c1) {
     2859 -        v = freq[i];
     2860 -        c2 = i;
     2861 -      }
     2862 -    }
     2863 -
     2864 -    /* Done if we've merged everything into one frequency */
     2865 -    if (c2 < 0)
     2866 -      break;
     2867 -
     2868 -    /* Else merge the two counts/trees */
     2869 -    freq[c1] += freq[c2];
     2870 -    freq[c2] = 0;
     2871 -
     2872 -    /* Increment the codesize of everything in c1's tree branch */
     2873 -    codesize[c1]++;
     2874 -    while (others[c1] >= 0) {
     2875 -      c1 = others[c1];
     2876 -      codesize[c1]++;
     2877 -    }
     2878 -
     2879 -    others[c1] = c2;            /* chain c2 onto c1's tree branch */
     2880 -
     2881 -    /* Increment the codesize of everything in c2's tree branch */
     2882 -    codesize[c2]++;
     2883 -    while (others[c2] >= 0) {
     2884 -      c2 = others[c2];
     2885 -      codesize[c2]++;
     2886 -    }
     2887 -  }
     2888 -
     2889 -  /* Now count the number of symbols of each code length */
     2890 -  for (i = 0; i <= 256; i++) {
     2891 -    if (codesize[i]) {
     2892 -      /* The JPEG standard seems to think that this can't happen, */
     2893 -      /* but I'm paranoid... */
     2894 -      if (codesize[i] > MAX_CLEN)
     2895 -        ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
     2896 -
     2897 -      bits[codesize[i]]++;
     2898 -    }
     2899 -  }
     2900 -
     2901 -  /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
     2902 -   * Huffman procedure assigned any such lengths, we must adjust the coding.
     2903 -   * Here is what the JPEG spec says about how this next bit works:
     2904 -   * Since symbols are paired for the longest Huffman code, the symbols are
     2905 -   * removed from this length category two at a time.  The prefix for the pair
     2906 -   * (which is one bit shorter) is allocated to one of the pair; then,
     2907 -   * skipping the BITS entry for that prefix length, a code word from the next
     2908 -   * shortest nonzero BITS entry is converted into a prefix for two code words
     2909 -   * one bit longer.
     2910 -   */
     2911 -
     2912 -  for (i = MAX_CLEN; i > 16; i--) {
     2913 -    while (bits[i] > 0) {
     2914 -      j = i - 2;                /* find length of new prefix to be used */
     2915 -      while (bits[j] == 0)
     2916 -        j--;
     2917 -
     2918 -      bits[i] -= 2;             /* remove two symbols */
     2919 -      bits[i-1]++;              /* one goes in this length */
     2920 -      bits[j+1] += 2;           /* two new symbols in this length */
     2921 -      bits[j]--;                /* symbol of this length is now a prefix */
     2922 -    }
     2923 -  }
     2924 -
     2925 -  /* Remove the count for the pseudo-symbol 256 from the largest codelength */
     2926 -  while (bits[i] == 0)          /* find largest codelength still in use */
     2927 -    i--;
     2928 -  bits[i]--;
     2929 -
     2930 -  /* Return final symbol counts (only for lengths 0..16) */
     2931 -  MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
     2932 -
     2933 -  /* Return a list of the symbols sorted by code length */
     2934 -  /* It's not real clear to me why we don't need to consider the codelength
     2935 -   * changes made above, but the JPEG spec seems to think this works.
     2936 -   */
     2937 -  p = 0;
     2938 -  for (i = 1; i <= MAX_CLEN; i++) {
     2939 -    for (j = 0; j <= 255; j++) {
     2940 -      if (codesize[j] == i) {
     2941 -        htbl->huffval[p] = (UINT8) j;
     2942 -        p++;
     2943 -      }
     2944 -    }
     2945 -  }
     2946 -
     2947 -  /* Set sent_table FALSE so updated table will be written to JPEG file. */
     2948 -  htbl->sent_table = FALSE;
     2949 -}
     2950 -
     2951 -
     2952 -/*
     2953 - * Finish up a statistics-gathering pass and create the new Huffman tables.
     2954 - */
     2955 -
     2956 -METHODDEF(void)
     2957 -finish_pass_gather (j_compress_ptr cinfo)
     2958 -{
     2959 -  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
     2960 -  int ci, dctbl, actbl;
     2961 -  jpeg_component_info * compptr;
     2962 -  JHUFF_TBL **htblptr;
     2963 -  boolean did_dc[NUM_HUFF_TBLS];
     2964 -  boolean did_ac[NUM_HUFF_TBLS];
     2965 -
     2966 -  /* It's important not to apply jpeg_gen_optimal_table more than once
     2967 -   * per table, because it clobbers the input frequency counts!
     2968 -   */
     2969 -  MEMZERO(did_dc, SIZEOF(did_dc));
     2970 -  MEMZERO(did_ac, SIZEOF(did_ac));
     2971 -
     2972 -  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
     2973 -    compptr = cinfo->cur_comp_info[ci];
     2974 -    dctbl = compptr->dc_tbl_no;
     2975 -    actbl = compptr->ac_tbl_no;
     2976 -    if (! did_dc[dctbl]) {
     2977 -      htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
     2978 -      if (*htblptr == NULL)
     2979 -        *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
     2980 -      jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
     2981 -      did_dc[dctbl] = TRUE;
     2982 -    }
     2983 -    if (! did_ac[actbl]) {
     2984 -      htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
     2985 -      if (*htblptr == NULL)
     2986 -        *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
     2987 -      jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
     2988 -      did_ac[actbl] = TRUE;
     2989 -    }
     2990 -  }
     2991 -}
     2992 -
     2993 -
     2994 -#endif /* ENTROPY_OPT_SUPPORTED */
     2995 -
     2996 -
     2997 -/*
     2998 - * Module initialization routine for Huffman entropy encoding.
     2999 - */
     3000 -
     3001 -GLOBAL(void)
     3002 -jinit_huff_encoder (j_compress_ptr cinfo)
     3003 -{
     3004 -  huff_entropy_ptr entropy;
     3005 -  int i;
     3006 -
     3007 -  entropy = (huff_entropy_ptr)
     3008 -    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
     3009 -                                SIZEOF(huff_entropy_encoder));
     3010 -  cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
     3011 -  entropy->pub.start_pass = start_pass_huff;
     3012 -
     3013 -  /* Mark tables unallocated */
     3014 -  for (i = 0; i < NUM_HUFF_TBLS; i++) {
     3015 -    entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
     3016 -#ifdef ENTROPY_OPT_SUPPORTED
     3017 -    entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
     3018 -#endif
     3019 -  }
     3020 -}
     3021 diff -ruN ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jchuff.h openjdk/jdk/src/share/native/sun/awt/image/jpeg/jchuff.h
     3022 --- ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jchuff.h	2007-10-30 04:38:51.000000000 -0400
     3023 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jchuff.h	1969-12-31 19:00:00.000000000 -0500
     3024 @@ -1,51 +0,0 @@
     3025 -/*
     3026 - * reserved comment block
     3027 - * DO NOT REMOVE OR ALTER!
     3028 - */
     3029 -/*
     3030 - * jchuff.h
     3031 - *
     3032 - * Copyright (C) 1991-1997, Thomas G. Lane.
     3033 - * This file is part of the Independent JPEG Group's software.
     3034 - * For conditions of distribution and use, see the accompanying README file.
     3035 - *
     3036 - * This file contains declarations for Huffman entropy encoding routines
     3037 - * that are shared between the sequential encoder (jchuff.c) and the
     3038 - * progressive encoder (jcphuff.c).  No other modules need to see these.
     3039 - */
     3040 -
     3041 -/* The legal range of a DCT coefficient is
     3042 - *  -1024 .. +1023  for 8-bit data;
     3043 - * -16384 .. +16383 for 12-bit data.
     3044 - * Hence the magnitude should always fit in 10 or 14 bits respectively.
     3045 - */
     3046 -
     3047 -#if BITS_IN_JSAMPLE == 8
     3048 -#define MAX_COEF_BITS 10
     3049 -#else
     3050 -#define MAX_COEF_BITS 14
     3051 -#endif
     3052 -
     3053 -/* Derived data constructed for each Huffman table */
     3054 -
     3055 -typedef struct {
     3056 -  unsigned int ehufco[256];     /* code for each symbol */
     3057 -  char ehufsi[256];             /* length of code for each symbol */
     3058 -  /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */
     3059 -} c_derived_tbl;
     3060 -
     3061 -/* Short forms of external names for systems with brain-damaged linkers. */
     3062 -
     3063 -#ifdef NEED_SHORT_EXTERNAL_NAMES
     3064 -#define jpeg_make_c_derived_tbl jMkCDerived
     3065 -#define jpeg_gen_optimal_table  jGenOptTbl
     3066 -#endif /* NEED_SHORT_EXTERNAL_NAMES */
     3067 -
     3068 -/* Expand a Huffman table definition into the derived format */
     3069 -EXTERN(void) jpeg_make_c_derived_tbl
     3070 -        JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
     3071 -             c_derived_tbl ** pdtbl));
     3072 -
     3073 -/* Generate an optimal table definition given the specified counts */
     3074 -EXTERN(void) jpeg_gen_optimal_table
     3075 -        JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
     3076 diff -ruN ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcinit.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcinit.c
     3077 --- ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcinit.c	2007-10-30 04:38:51.000000000 -0400
     3078 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcinit.c	1969-12-31 19:00:00.000000000 -0500
     3079 @@ -1,76 +0,0 @@
     3080 -/*
     3081 - * reserved comment block
     3082 - * DO NOT REMOVE OR ALTER!
     3083 - */
     3084 -/*
     3085 - * jcinit.c
     3086 - *
     3087 - * Copyright (C) 1991-1997, Thomas G. Lane.
     3088 - * This file is part of the Independent JPEG Group's software.
     3089 - * For conditions of distribution and use, see the accompanying README file.
     3090 - *
     3091 - * This file contains initialization logic for the JPEG compressor.
     3092 - * This routine is in charge of selecting the modules to be executed and
     3093 - * making an initialization call to each one.
     3094 - *
     3095 - * Logically, this code belongs in jcmaster.c.  It's split out because
     3096 - * linking this routine implies linking the entire compression library.
     3097 - * For a transcoding-only application, we want to be able to use jcmaster.c
     3098 - * without linking in the whole library.
     3099 - */
     3100 -
     3101 -#define JPEG_INTERNALS
     3102 -#include "jinclude.h"
     3103 -#include "jpeglib.h"
     3104 -
     3105 -
     3106 -/*
     3107 - * Master selection of compression modules.
     3108 - * This is done once at the start of processing an image.  We determine
     3109 - * which modules will be used and give them appropriate initialization calls.
     3110 - */
     3111 -
     3112 -GLOBAL(void)
     3113 -jinit_compress_master (j_compress_ptr cinfo)
     3114 -{
     3115 -  /* Initialize master control (includes parameter checking/processing) */
     3116 -  jinit_c_master_control(cinfo, FALSE /* full compression */);
     3117 -
     3118 -  /* Preprocessing */
     3119 -  if (! cinfo->raw_data_in) {
     3120 -    jinit_color_converter(cinfo);
     3121 -    jinit_downsampler(cinfo);
     3122 -    jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
     3123 -  }
     3124 -  /* Forward DCT */
     3125 -  jinit_forward_dct(cinfo);
     3126 -  /* Entropy encoding: either Huffman or arithmetic coding. */
     3127 -  if (cinfo->arith_code) {
     3128 -    ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
     3129 -  } else {
     3130 -    if (cinfo->progressive_mode) {
     3131 -#ifdef C_PROGRESSIVE_SUPPORTED
     3132 -      jinit_phuff_encoder(cinfo);
     3133 -#else
     3134 -      ERREXIT(cinfo, JERR_NOT_COMPILED);
     3135 -#endif
     3136 -    } else
     3137 -      jinit_huff_encoder(cinfo);
     3138 -  }
     3139 -
     3140 -  /* Need a full-image coefficient buffer in any multi-pass mode. */
     3141 -  jinit_c_coef_controller(cinfo,
     3142 -                (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
     3143 -  jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
     3144 -
     3145 -  jinit_marker_writer(cinfo);
     3146 -
     3147 -  /* We can now tell the memory manager to allocate virtual arrays. */
     3148 -  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
     3149 -
     3150 -  /* Write the datastream header (SOI) immediately.
     3151 -   * Frame and scan headers are postponed till later.
     3152 -   * This lets application insert special markers after the SOI.
     3153 -   */
     3154 -  (*cinfo->marker->write_file_header) (cinfo);
     3155 -}
     3156 diff -ruN ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcmainct.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcmainct.c
     3157 --- ..openjdk.old/openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcmainct.c	2007-10-30 04:38:51.000000000 -0400
     3158 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jcmainct.c	1969-12-31 19:00:00.000000000 -0500
     3159 @@ -1,297 +0,0 @@
     3160 -/*
     3161 - * reserved comment block
     3162 - * DO NOT REMOVE OR ALTER!
     3163 - */
     3164 -/*
     3165 - * jcmainct.c
     3166 - *
     3167 - * Copyright (C) 1994-1996, Thomas G. Lane.
     3168 - * This file is part of the Independent JPEG Group's software.
     3169 - * For conditions of distribution and use, see the accompanying README file.
     3170 - *
     3171 - * This file contains the main buffer controller for compression.
     3172 - * The main buffer lies between the pre-processor and the JPEG
     3173 - * compressor proper; it holds downsampled data in the JPEG colorspace.
     3174 - */
     3175 -
     3176 -#define JPEG_INTERNALS
     3177 -#include "jinclude.h"
     3178 -#include "jpeglib.h"
     3179 -
     3180 -
     3181 -/* Note: currently, there is no operating mode in which a full-image buffer
     3182 - * is needed at this step.  If there were, that mode could not be used with
     3183 - * "raw data" input, since this module is bypassed in that case.  However,
     3184 - * we've left the code here for possible use in special applications.
     3185 - */
     3186 -#undef FULL_MAIN_BUFFER_SUPPORTED
     3187 -
     3188 -
     3189 -/* Private buffer controller object */
     3190 -
     3191 -typedef struct {
     3192 -  struct jpeg_c_main_controller pub; /* public fields */
     3193 -
     3194 -  JDIMENSION cur_iMCU_row;      /* number of current iMCU row */
     3195 -  JDIMENSION rowgroup_ctr;      /* counts row groups received in iMCU row */
     3196 -  boolean suspended;            /* remember if we suspended output */
     3197 -  J_BUF_MODE pass_mode;         /* current operating mode */
     3198 -
     3199 -  /* If using just a strip buffer, this points to the entire set of buffers
     3200 -   * (we allocate one for each component).  In the full-image case, this
     3201 -   * points to the currently accessible strips of the virtual arrays.
     3202 -   */
     3203 -  JSAMPARRAY buffer[MAX_COMPONENTS];
     3204 -
     3205 -#ifdef FULL_MAIN_BUFFER_SUPPORTED
     3206 -  /* If using full-image storage, this array holds pointers to virtual-array
     3207 -   * control blocks for each component.  Unused if not full-image storage.
     3208 -   */
     3209 -  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
     3210 -#endif
     3211 -} my_main_controller;
     3212 -
     3213 -typedef my_main_controller * my_main_ptr;
     3214 -
     3215 -
     3216 -/* Forward declarations */
     3217 -METHODDEF(void) process_data_simple_main
     3218 -        JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
     3219 -             JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
     3220 -#ifdef FULL_MAIN_BUFFER_SUPPORTED
     3221 -METHODDEF(void) process_data_buffer_main
     3222 -        JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
     3223 -             JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
     3224 -#endif
     3225 -
     3226 -
     3227 -/*
     3228 - * Initialize for a processing pass.
     3229 - */
     3230 -
     3231 -METHODDEF(void)
     3232 -start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
     3233 -{
     3234 -  my_main_ptr _main = (my_main_ptr) cinfo->main;
     3235 -
     3236 -  /* Do nothing in raw-data mode. */
     3237 -  if (cinfo->raw_data_in)
     3238 -    return;
     3239 -
     3240 -  _main->cur_iMCU_row = 0;      /* initialize counters */
     3241 -  _main->rowgroup_ctr = 0;
     3242 -  _main->suspended = FALSE;
     3243 -  _main->pass_mode = pass_mode; /* save mode for use by process_data */
     3244 -
     3245 -  switch (pass_mode) {
     3246 -  case JBUF_PASS_THRU:
     3247 -#ifdef FULL_MAIN_BUFFER_SUPPORTED
     3248 -    if (_main->whole_image[0] != NULL)
     3249 -      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
     3250 -#endif
     3251 -    _main->pub.process_data = process_data_simple_main;
     3252 -    break;
     3253 -#ifdef FULL_MAIN_BUFFER_SUPPORTED
     3254 -  case JBUF_SAVE_SOURCE:
     3255 -  case JBUF_CRANK_DEST:
     3256 -  case JBUF_SAVE_AND_PASS:
     3257 -    if (_main->whole_image[0] == NULL)
     3258 -      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
     3259 -    _main->pub.process_data = process_data_buffer_main;
     3260 -    break;
     3261 -#endif
     3262 -  default:
     3263 -    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
     3264 -    break;
     3265 -  }
     3266 -}
     3267 -
     3268 -
     3269 -/*
     3270 - * Process some data.
     3271 - * This routine handles the simple pass-through mode,
     3272 - * where we have only a strip buffer.
     3273 - */
     3274 -
     3275 -METHODDEF(void)
     3276 -process_data_simple_main (j_compress_ptr cinfo,
     3277 -                          JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
     3278 -                          JDIMENSION in_rows_avail)
     3279 -{
     3280 -  my_main_ptr _main = (my_main_ptr) cinfo->main;
     3281 -
     3282 -  while (_main->cur_iMCU_row < cinfo->total_iMCU_rows) {
     3283 -    /* Read input data if we haven't filled the main buffer yet */
     3284 -    if (_main->rowgroup_ctr < DCTSIZE)
     3285 -      (*cinfo->prep->pre_process_data) (cinfo,
     3286 -                                        input_buf, in_row_ctr, in_rows_avail,
     3287 -                                        _main->buffer, &_main->rowgroup_ctr,
     3288 -                                        (JDIM