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
4 include $(BUILDDIR)/common/Mapfile-vers.gmk
5 include $(BUILDDIR)/common/Library.gmk
10 # Add to ambient vpath to get files in a subdirectory
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
16 #include "splashscreen_impl.h"
18 -#include "../libpng/png.h"
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
26 #include "splashscreen_impl.h"
27 #include "splashscreen_gfx.h"
29 -#include "../giflib/gif_lib.h"
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
43 #include "java_util_zip_Adler32.h"
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
54 #include "java_util_zip_Deflater.h"
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
65 #include "java_util_zip_CRC32.h"
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
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
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
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
90 include $(BUILDDIR)/common/Defs.gmk
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
106 -# Add to ambient vpath so we pick up the library files
108 -vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/zlib-$(ZLIB_VERSION)
111 # Link to JVM library for JVM_Zip* functions
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
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
138 #include "jni_util.h"
141 #include "java_util_zip_Inflater.h"
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
148 #include "io_util_md.h"
149 #include "zip_util.h"
154 /* USE_MMAP means mmap the CEN & ENDHDR part of the zip file. */
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
159 splashscreen_impl.c \
160 splashscreen_jpeg.c \
162 - splashscreen_sys.c \
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
247 -CFLAGS += -DSPLASHSCREEN
248 +CFLAGS += -DSPLASHSCREEN -DPNG_NO_MMX_CODE
250 ifneq ($(PLATFORM), windows)
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
256 CFLAGS += -DWITH_WIN32
257 OTHER_LDLIBS += kernel32.lib user32.lib gdi32.lib
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
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
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
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
334 - * reserved comment block
335 - * DO NOT REMOVE OR ALTER!
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.
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
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.
355 -#define JPEG_INTERNALS
356 -#include "jinclude.h"
357 -#include "jpeglib.h"
361 - * Initialization of a JPEG compression object.
362 - * The error manager must already be set up (in case memory manager fails).
366 -jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
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);
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
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));
389 - cinfo->client_data = client_data;
391 - cinfo->is_decompressor = FALSE;
393 - /* Initialize a memory manager instance for this object */
394 - jinit_memory_mgr((j_common_ptr) cinfo);
396 - /* Zero out pointers to permanent structures. */
397 - cinfo->progress = NULL;
398 - cinfo->dest = NULL;
400 - cinfo->comp_info = NULL;
402 - for (i = 0; i < NUM_QUANT_TBLS; i++)
403 - cinfo->quant_tbl_ptrs[i] = NULL;
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;
410 - cinfo->script_space = NULL;
412 - cinfo->input_gamma = 1.0; /* in case application forgets */
414 - /* OK, I'm ready */
415 - cinfo->global_state = CSTATE_START;
420 - * Destruction of a JPEG compression object
424 -jpeg_destroy_compress (j_compress_ptr cinfo)
426 - jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
431 - * Abort processing of a JPEG compression operation,
432 - * but don't destroy the object itself.
436 -jpeg_abort_compress (j_compress_ptr cinfo)
438 - jpeg_abort((j_common_ptr) cinfo); /* use common routine */
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.
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.
455 -jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
461 - for (i = 0; i < NUM_QUANT_TBLS; i++) {
462 - if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
463 - qtbl->sent_table = suppress;
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;
476 - * Finish JPEG compression.
478 - * If a multipass operating mode was selected, this may do a great deal of
479 - * work including most of the actual output.
483 -jpeg_finish_compress (j_compress_ptr cinfo)
485 - JDIMENSION iMCU_row;
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);
504 - /* We bypass the main controller and invoke coef controller directly;
505 - * all work is being done from the coefficient buffer.
507 - if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
508 - ERREXIT(cinfo, JERR_CANT_SUSPEND);
510 - (*cinfo->master->finish_pass) (cinfo);
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);
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().
528 -jpeg_write_marker (j_compress_ptr cinfo, int marker,
529 - const JOCTET *dataptr, unsigned int datalen)
531 - JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
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);
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);
547 -/* Same, but piecemeal. */
550 -jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
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);
558 - (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
562 -jpeg_write_m_byte (j_compress_ptr cinfo, int val)
564 - (*cinfo->marker->write_marker_byte) (cinfo, val);
569 - * Alternate compression function: just write an abbreviated table file.
570 - * Before calling this, all parameters and a data destination must be set up.
572 - * To produce a pair of files containing abbreviated tables and abbreviated
573 - * image data, one would proceed as follows:
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);
582 - * jpeg_finish_compress(cinfo);
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.
590 -jpeg_write_tables (j_compress_ptr cinfo)
592 - if (cinfo->global_state != CSTATE_START)
593 - ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
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);
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().
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
622 - * reserved comment block
623 - * DO NOT REMOVE OR ALTER!
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.
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.
641 -#define JPEG_INTERNALS
642 -#include "jinclude.h"
643 -#include "jpeglib.h"
647 - * Compression initialization.
648 - * Before calling this, all parameters and a data destination must be set up.
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
662 -jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
664 - if (cinfo->global_state != CSTATE_START)
665 - ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
667 - if (write_all_tables)
668 - jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
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.
680 - cinfo->next_scanline = 0;
681 - cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
686 - * Write some scanlines of data to the JPEG compressor.
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.
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.
701 -jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
702 - JDIMENSION num_lines)
704 - JDIMENSION row_ctr, rows_left;
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);
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);
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.
723 - if (cinfo->master->call_pass_startup)
724 - (*cinfo->master->pass_startup) (cinfo);
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;
732 - (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
733 - cinfo->next_scanline += row_ctr;
739 - * Alternate entry point to write raw data.
740 - * Processes exactly one iMCU row per call, unless suspended.
744 -jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
745 - JDIMENSION num_lines)
747 - JDIMENSION lines_per_iMCU_row;
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);
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);
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.
768 - if (cinfo->master->call_pass_startup)
769 - (*cinfo->master->pass_startup) (cinfo);
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);
776 - /* Directly compress the row. */
777 - if (! (*cinfo->coef->compress_data) (cinfo, data)) {
778 - /* If compressor did not consume the whole row, suspend processing. */
782 - /* OK, we processed one iMCU row. */
783 - cinfo->next_scanline += lines_per_iMCU_row;
784 - return lines_per_iMCU_row;
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
791 - * reserved comment block
792 - * DO NOT REMOVE OR ALTER!
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.
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.
806 -#define JPEG_INTERNALS
807 -#include "jinclude.h"
808 -#include "jpeglib.h"
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.
816 -#ifdef ENTROPY_OPT_SUPPORTED
817 -#define FULL_COEF_BUFFER_SUPPORTED
819 -#ifdef C_MULTISCAN_FILES_SUPPORTED
820 -#define FULL_COEF_BUFFER_SUPPORTED
825 -/* Private buffer controller object */
828 - struct jpeg_c_coef_controller pub; /* public fields */
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 */
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.
844 - JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
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;
850 -typedef my_coef_controller * my_coef_ptr;
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));
865 -start_iMCU_row (j_compress_ptr cinfo)
866 -/* Reset within-iMCU-row counters for a new row */
868 - my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
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.
874 - if (cinfo->comps_in_scan > 1) {
875 - coef->MCU_rows_per_iMCU_row = 1;
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;
880 - coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
884 - coef->MCU_vert_offset = 0;
889 - * Initialize for a processing pass.
893 -start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
895 - my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
897 - coef->iMCU_row_num = 0;
898 - start_iMCU_row(cinfo);
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;
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;
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;
919 - ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
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.
931 - * NB: input_buf contains a plane for each component in image,
932 - * which we index according to the component's SOF position.
936 -compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
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;
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;
949 - for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
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.)
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];
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];
990 - blkn += compptr->MCU_width;
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...)
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;
1004 - /* Completed an MCU row, but perhaps not an iMCU row */
1005 - coef->mcu_ctr = 0;
1007 - /* Completed the iMCU row, advance counters for next one */
1008 - coef->iMCU_row_num++;
1009 - start_iMCU_row(cinfo);
1014 -#ifdef FULL_COEF_BUFFER_SUPPORTED
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.
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.
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).
1038 -compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
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;
1045 - jpeg_component_info *compptr;
1046 - JBLOCKARRAY buffer;
1047 - JBLOCKROW thisblockrow, lastblockrow;
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;
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;
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);
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.
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);
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;
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...
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;
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;
1108 - thisblockrow += h_samp_factor; /* advance to next MCU in row */
1109 - lastblockrow += h_samp_factor;
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.
1118 - /* Emit data to the entropy encoder, sharing code with subsequent passes */
1119 - return compress_output(cinfo, input_buf);
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.
1130 - * NB: input_buf is ignored; it is likely to be a NULL pointer.
1134 -compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
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;
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.
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);
1156 - /* Loop to process one whole iMCU row */
1157 - for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
1159 - for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
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++;
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;
1181 - /* Completed an MCU row, but perhaps not an iMCU row */
1182 - coef->mcu_ctr = 0;
1184 - /* Completed the iMCU row, advance counters for next one */
1185 - coef->iMCU_row_num++;
1186 - start_iMCU_row(cinfo);
1190 -#endif /* FULL_COEF_BUFFER_SUPPORTED */
1194 - * Initialize coefficient buffer controller.
1198 -jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
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;
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. */
1214 - jpeg_component_info *compptr;
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);
1227 - ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
1230 - /* We only need a single-MCU buffer. */
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;
1240 - coef->whole_image[0] = NULL; /* flag for no virtual arrays */
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
1248 - * reserved comment block
1249 - * DO NOT REMOVE OR ALTER!
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.
1258 - * This file contains input colorspace conversion routines.
1261 -#define JPEG_INTERNALS
1262 -#include "jinclude.h"
1263 -#include "jpeglib.h"
1266 -/* Private subobject */
1269 - struct jpeg_color_converter pub; /* public fields */
1271 - /* Private state for RGB->YCC conversion */
1272 - INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
1273 -} my_color_converter;
1275 -typedef my_color_converter * my_cconvert_ptr;
1278 -/**************** RGB -> YCbCr conversion: most common case **************/
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.
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.
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.
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))
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).
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))
1332 - * Initialize for RGB->YCC colorspace conversion.
1336 -rgb_ycc_start (j_compress_ptr cinfo)
1338 - my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
1339 - INT32 * rgb_ycc_tab;
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)));
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.
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;
1361 - rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
1362 - rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
1368 - * Convert some rows of samples to the JPEG colorspace.
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.
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.
1380 -rgb_ycc_convert (j_compress_ptr cinfo,
1381 - JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
1382 - JDIMENSION output_row, int num_rows)
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;
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];
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.
1409 - outptr0[col] = (JSAMPLE)
1410 - ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
1413 - outptr1[col] = (JSAMPLE)
1414 - ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
1417 - outptr2[col] = (JSAMPLE)
1418 - ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
1425 -/**************** Cases other than RGB -> YCbCr **************/
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).
1436 -rgb_gray_convert (j_compress_ptr cinfo,
1437 - JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
1438 - JDIMENSION output_row, int num_rows)
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;
1448 - while (--num_rows >= 0) {
1449 - inptr = *input_buf++;
1450 - outptr = output_buf[0][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;
1458 - outptr[col] = (JSAMPLE)
1459 - ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
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.
1474 -cmyk_ycck_convert (j_compress_ptr cinfo,
1475 - JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
1476 - JDIMENSION output_row, int num_rows)
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;
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];
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 */
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.
1506 - outptr0[col] = (JSAMPLE)
1507 - ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
1510 - outptr1[col] = (JSAMPLE)
1511 - ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
1514 - outptr2[col] = (JSAMPLE)
1515 - ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
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).
1529 -grayscale_convert (j_compress_ptr cinfo,
1530 - JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
1531 - JDIMENSION output_row, int num_rows)
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;
1539 - while (--num_rows >= 0) {
1540 - inptr = *input_buf++;
1541 - outptr = output_buf[0][output_row];
1543 - for (col = 0; col < num_cols; col++) {
1544 - outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
1545 - inptr += instride;
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.
1558 -null_convert (j_compress_ptr cinfo,
1559 - JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
1560 - JDIMENSION output_row, int num_rows)
1562 - register JSAMPROW inptr;
1563 - register JSAMPROW outptr;
1564 - register JDIMENSION col;
1566 - int nc = cinfo->num_components;
1567 - JDIMENSION num_cols = cinfo->image_width;
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 */
1586 - * Empty method for start_pass.
1590 -null_method (j_compress_ptr cinfo)
1592 - /* no work needed */
1597 - * Module initialization routine for input colorspace conversion.
1601 -jinit_color_converter (j_compress_ptr cinfo)
1603 - my_cconvert_ptr cconvert;
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;
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);
1620 -#if RGB_PIXELSIZE != 3
1621 - if (cinfo->input_components != RGB_PIXELSIZE)
1622 - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
1624 -#endif /* else share code with YCbCr */
1627 - if (cinfo->input_components != 3)
1628 - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
1633 - if (cinfo->input_components != 4)
1634 - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
1637 - default: /* JCS_UNKNOWN can be anything */
1638 - if (cinfo->input_components < 1)
1639 - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
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;
1656 - ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
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;
1665 - ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
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;
1677 - ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
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;
1686 - ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
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;
1698 - ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
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;
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
1714 - * reserved comment block
1715 - * DO NOT REMOVE OR ALTER!
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.
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
1730 -#define JPEG_INTERNALS
1731 -#include "jinclude.h"
1732 -#include "jpeglib.h"
1733 -#include "jdct.h" /* Private declarations for DCT subsystem */
1736 -/* Private subobject for this module */
1739 - struct jpeg_forward_dct pub; /* public fields */
1741 - /* Pointer to the DCT routine actually in use */
1742 - forward_DCT_method_ptr do_dct;
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.
1748 - DCTELEM * divisors[NUM_QUANT_TBLS];
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];
1755 -} my_fdct_controller;
1757 -typedef my_fdct_controller * my_fdct_ptr;
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.
1770 -start_pass_fdctmgr (j_compress_ptr cinfo)
1772 - my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
1773 - int ci, qtblno, i;
1774 - jpeg_component_info *compptr;
1775 - JQUANT_TBL * qtbl;
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
1791 - /* For LL&M IDCT method, divisors are equal to raw quantization
1792 - * coefficients multiplied by 8 (to counteract scaling).
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));
1799 - dtbl = fdct->divisors[qtblno];
1800 - for (i = 0; i < DCTSIZE2; i++) {
1801 - dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
1805 -#ifdef DCT_IFAST_SUPPORTED
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.
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
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));
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]),
1843 -#ifdef DCT_FLOAT_SUPPORTED
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.
1854 - FAST_FLOAT * fdtbl;
1856 - static const double aanscalefactor[DCTSIZE] = {
1857 - 1.0, 1.387039845, 1.306562965, 1.175875602,
1858 - 1.0, 0.785694958, 0.541196100, 0.275899379
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));
1866 - fdtbl = fdct->float_divisors[qtblno];
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)));
1880 - ERREXIT(cinfo, JERR_NOT_COMPILED);
1888 - * Perform forward DCT on one or more blocks of a component.
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[].
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. */
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 */
1909 - sample_data += start_row; /* fold in the vertical offset once */
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;
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;
1930 - { register int elemc;
1931 - for (elemc = DCTSIZE; elemc > 0; elemc--) {
1932 - *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
1939 - /* Perform the DCT */
1940 - (*do_dct) (workspace);
1942 - /* Quantize/descale the coefficients, and store into coef_blocks[] */
1943 - { register DCTELEM temp, qval;
1945 - register JCOEFPTR output_ptr = coef_blocks[bi];
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.
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.
1963 -#define DIVIDE_BY(a,b) a /= b
1965 -#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
1969 - temp += qval>>1; /* for rounding */
1970 - DIVIDE_BY(temp, qval);
1973 - temp += qval>>1; /* for rounding */
1974 - DIVIDE_BY(temp, qval);
1976 - output_ptr[i] = (JCOEF) temp;
1983 -#ifdef DCT_FLOAT_SUPPORTED
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. */
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 */
1999 - sample_data += start_row; /* fold in the vertical offset once */
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;
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);
2020 - { register int elemc;
2021 - for (elemc = DCTSIZE; elemc > 0; elemc--) {
2022 - *workspaceptr++ = (FAST_FLOAT)
2023 - (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
2030 - /* Perform the DCT */
2031 - (*do_dct) (workspace);
2033 - /* Quantize/descale the coefficients, and store into coef_blocks[] */
2034 - { register FAST_FLOAT temp;
2036 - register JCOEFPTR output_ptr = coef_blocks[bi];
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.
2047 - output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
2053 -#endif /* DCT_FLOAT_SUPPORTED */
2057 - * Initialize FDCT manager.
2061 -jinit_forward_dct (j_compress_ptr cinfo)
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;
2072 - switch (cinfo->dct_method) {
2073 -#ifdef DCT_ISLOW_SUPPORTED
2075 - fdct->pub.forward_DCT = forward_DCT;
2076 - fdct->do_dct = jpeg_fdct_islow;
2079 -#ifdef DCT_IFAST_SUPPORTED
2081 - fdct->pub.forward_DCT = forward_DCT;
2082 - fdct->do_dct = jpeg_fdct_ifast;
2085 -#ifdef DCT_FLOAT_SUPPORTED
2087 - fdct->pub.forward_DCT = forward_DCT_float;
2088 - fdct->do_float_dct = jpeg_fdct_float;
2092 - ERREXIT(cinfo, JERR_NOT_COMPILED);
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;
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
2109 - * reserved comment block
2110 - * DO NOT REMOVE OR ALTER!
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.
2119 - * This file contains Huffman entropy encoding routines.
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.
2128 -#define JPEG_INTERNALS
2129 -#include "jinclude.h"
2130 -#include "jpeglib.h"
2131 -#include "jchuff.h" /* Declarations shared with jcphuff.c */
2134 -/* Expanded entropy encoder object for Huffman encoding.
2136 - * The savable_state subrecord contains fields that change within an MCU,
2137 - * but must not be updated permanently until we complete the MCU.
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 */
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.
2151 -#ifndef NO_STRUCT_ASSIGN
2152 -#define ASSIGN_STATE(dest,src) ((dest) = (src))
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])
2167 - struct jpeg_entropy_encoder pub; /* public fields */
2169 - savable_state saved; /* Bit buffer & DC state at start of MCU */
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) */
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];
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];
2183 -} huff_entropy_encoder;
2185 -typedef huff_entropy_encoder * huff_entropy_ptr;
2187 -/* Working state while writing an MCU.
2188 - * This struct contains all the fields that are needed by subroutines.
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 */
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));
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.
2217 -start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
2219 - huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
2220 - int ci, dctbl, actbl;
2221 - jpeg_component_info * compptr;
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;
2228 - ERREXIT(cinfo, JERR_NOT_COMPILED);
2231 - entropy->pub.encode_mcu = encode_mcu_huff;
2232 - entropy->pub.finish_pass = finish_pass_huff;
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));
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]);
2268 - /* Initialize DC predictions to 0 */
2269 - entropy->saved.last_dc_val[ci] = 0;
2272 - /* Initialize bit buffer to empty */
2273 - entropy->saved.put_buffer = 0;
2274 - entropy->saved.put_bits = 0;
2276 - /* Initialize restart stuff */
2277 - entropy->restarts_to_go = cinfo->restart_interval;
2278 - entropy->next_restart_num = 0;
2283 - * Compute the derived values for a Huffman table.
2284 - * This routine also performs some validation checks on the table.
2286 - * Note this is also used by jcphuff.c.
2290 -jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
2291 - c_derived_tbl ** pdtbl)
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;
2300 - /* Note that huffsize[] and huffcode[] are filled in code-length order,
2301 - * paralleling the order of the symbols themselves in htbl->huffval[].
2304 - /* Find the input Huffman table */
2305 - if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
2306 - ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
2308 - isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
2310 - ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
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));
2319 - /* Figure C.1: make table of Huffman code length for each symbol */
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);
2327 - huffsize[p++] = (char) l;
2332 - /* Figure C.2: generate the codes themselves */
2333 - /* We also validate that the counts represent a legal Huffman code tree. */
2338 - while (huffsize[p]) {
2339 - while (((int) huffsize[p]) == si) {
2340 - huffcode[p++] = code;
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.
2346 - if (((INT32) code) >= (((INT32) 1) << si))
2347 - ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
2352 - /* Figure C.3: generate encoding tables */
2353 - /* These are code and size indexed by symbol value */
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.
2359 - MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
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.)
2366 - maxsymbol = isDC ? 15 : 255;
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];
2378 -/* Outputting bytes to the file */
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)) \
2389 -dump_buffer (working_state * state)
2390 -/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
2392 - struct jpeg_destination_mgr * dest = state->cinfo->dest;
2394 - if (! (*dest->empty_output_buffer) (state->cinfo))
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;
2403 -/* Outputting bits to the file */
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.
2413 -emit_bits (working_state * state, unsigned int code, int size)
2414 -/* Emit some bits; return TRUE if successful, FALSE if must suspend */
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;
2420 - /* if size is 0, caller used an invalid Huffman table entry */
2422 - ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
2424 - put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
2426 - put_bits += size; /* new number of bits in buffer */
2428 - put_buffer <<= 24 - put_bits; /* align incoming bits */
2430 - put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
2432 - while (put_bits >= 8) {
2433 - int c = (int) ((put_buffer >> 16) & 0xFF);
2435 - emit_byte(state, c, return FALSE);
2436 - if (c == 0xFF) { /* need to stuff a zero byte? */
2437 - emit_byte(state, 0, return FALSE);
2443 - state->cur.put_buffer = put_buffer; /* update state variables */
2444 - state->cur.put_bits = put_bits;
2451 -flush_bits (working_state * state)
2453 - if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
2455 - state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
2456 - state->cur.put_bits = 0;
2461 -/* Encode a single block's worth of coefficients */
2464 -encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
2465 - c_derived_tbl *dctbl, c_derived_tbl *actbl)
2467 - register int temp, temp2;
2468 - register int nbits;
2469 - register int k, r, i;
2471 - /* Encode the DC coefficient difference per section F.1.2.1 */
2473 - temp = temp2 = block[0] - last_dc_val;
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 */
2482 - /* Find the number of bits needed for the magnitude of the coefficient */
2488 - /* Check for out-of-range coefficient values.
2489 - * Since we're encoding a difference, the range limit is twice as much.
2491 - if (nbits > MAX_COEF_BITS+1)
2492 - ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
2494 - /* Emit the Huffman-coded symbol for the number of bits */
2495 - if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
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))
2504 - /* Encode the AC coefficients per section F.1.2.2 */
2506 - r = 0; /* r = run length of zeros */
2508 - for (k = 1; k < DCTSIZE2; k++) {
2509 - if ((temp = block[jpeg_natural_order[k]]) == 0) {
2512 - /* if run length > 15, must emit special run-length-16 codes (0xF0) */
2514 - if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
2521 - temp = -temp; /* temp is abs value of input */
2522 - /* This code assumes we are on a two's complement machine */
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))
2530 - /* Check for out-of-range coefficient values */
2531 - if (nbits > MAX_COEF_BITS)
2532 - ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
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]))
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))
2548 - /* If the last coef(s) were zero, emit an end-of-block code */
2550 - if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
2558 - * Emit a restart marker & resynchronize predictions.
2562 -emit_restart (working_state * state, int restart_num)
2566 - if (! flush_bits(state))
2569 - emit_byte(state, 0xFF, return FALSE);
2570 - emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
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;
2576 - /* The restart counter is not updated until we successfully write the MCU. */
2583 - * Encode and output one MCU's worth of Huffman-compressed coefficients.
2587 -encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
2589 - huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
2590 - working_state state;
2592 - jpeg_component_info * compptr;
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;
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))
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]))
2616 - /* Update last_dc_val */
2617 - state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
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);
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;
2632 - entropy->restarts_to_go--;
2640 - * Finish up at the end of a Huffman-compressed scan.
2644 -finish_pass_huff (j_compress_ptr cinfo)
2646 - huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
2647 - working_state state;
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;
2655 - /* Flush out the last data */
2656 - if (! flush_bits(&state))
2657 - ERREXIT(cinfo, JERR_CANT_SUSPEND);
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);
2667 - * Huffman coding optimization.
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.
2677 -#ifdef ENTROPY_OPT_SUPPORTED
2680 -/* Process a single block's worth of coefficients */
2683 -htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
2684 - long dc_counts[], long ac_counts[])
2686 - register int temp;
2687 - register int nbits;
2688 - register int k, r;
2690 - /* Encode the DC coefficient difference per section F.1.2.1 */
2692 - temp = block[0] - last_dc_val;
2696 - /* Find the number of bits needed for the magnitude of the coefficient */
2702 - /* Check for out-of-range coefficient values.
2703 - * Since we're encoding a difference, the range limit is twice as much.
2705 - if (nbits > MAX_COEF_BITS+1)
2706 - ERREXIT(cinfo, JERR_BAD_DCT_COEF);
2708 - /* Count the Huffman symbol for the number of bits */
2709 - dc_counts[nbits]++;
2711 - /* Encode the AC coefficients per section F.1.2.2 */
2713 - r = 0; /* r = run length of zeros */
2715 - for (k = 1; k < DCTSIZE2; k++) {
2716 - if ((temp = block[jpeg_natural_order[k]]) == 0) {
2719 - /* if run length > 15, must emit special run-length-16 codes (0xF0) */
2721 - ac_counts[0xF0]++;
2725 - /* Find the number of bits needed for the magnitude of the coefficient */
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))
2733 - /* Check for out-of-range coefficient values */
2734 - if (nbits > MAX_COEF_BITS)
2735 - ERREXIT(cinfo, JERR_BAD_DCT_COEF);
2737 - /* Count Huffman symbol for run length / number of bits */
2738 - ac_counts[(r << 4) + nbits]++;
2744 - /* If the last coef(s) were zero, emit an end-of-block code */
2751 - * Trial-encode one MCU's worth of Huffman-compressed coefficients.
2752 - * No data is actually output, so no suspension return is possible.
2756 -encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
2758 - huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
2760 - jpeg_component_info * compptr;
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;
2771 - entropy->restarts_to_go--;
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];
2788 - * Generate the best Huffman code table for the given counts, fill htbl.
2789 - * Note this is also used by jcphuff.c.
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.
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.
2816 -jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
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 */
2826 - /* This algorithm is explained in section K.2 of the JPEG standard */
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 */
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.
2839 - /* Huffman's basic algorithm to assign optimal code lengths to symbols */
2842 - /* Find the smallest nonzero frequency, set c1 = its symbol */
2843 - /* In case of ties, take the larger symbol number */
2846 - for (i = 0; i <= 256; i++) {
2847 - if (freq[i] && freq[i] <= v) {
2853 - /* Find the next smallest nonzero frequency, set c2 = its symbol */
2854 - /* In case of ties, take the larger symbol number */
2857 - for (i = 0; i <= 256; i++) {
2858 - if (freq[i] && freq[i] <= v && i != c1) {
2864 - /* Done if we've merged everything into one frequency */
2868 - /* Else merge the two counts/trees */
2869 - freq[c1] += freq[c2];
2872 - /* Increment the codesize of everything in c1's tree branch */
2874 - while (others[c1] >= 0) {
2879 - others[c1] = c2; /* chain c2 onto c1's tree branch */
2881 - /* Increment the codesize of everything in c2's tree branch */
2883 - while (others[c2] >= 0) {
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);
2897 - bits[codesize[i]]++;
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
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)
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 */
2925 - /* Remove the count for the pseudo-symbol 256 from the largest codelength */
2926 - while (bits[i] == 0) /* find largest codelength still in use */
2930 - /* Return final symbol counts (only for lengths 0..16) */
2931 - MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
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.
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;
2947 - /* Set sent_table FALSE so updated table will be written to JPEG file. */
2948 - htbl->sent_table = FALSE;
2953 - * Finish up a statistics-gathering pass and create the new Huffman tables.
2957 -finish_pass_gather (j_compress_ptr cinfo)
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];
2966 - /* It's important not to apply jpeg_gen_optimal_table more than once
2967 - * per table, because it clobbers the input frequency counts!
2969 - MEMZERO(did_dc, SIZEOF(did_dc));
2970 - MEMZERO(did_ac, SIZEOF(did_ac));
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;
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;
2994 -#endif /* ENTROPY_OPT_SUPPORTED */
2998 - * Module initialization routine for Huffman entropy encoding.
3002 -jinit_huff_encoder (j_compress_ptr cinfo)
3004 - huff_entropy_ptr entropy;
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;
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;
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
3026 - * reserved comment block
3027 - * DO NOT REMOVE OR ALTER!
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.
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.
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.
3047 -#if BITS_IN_JSAMPLE == 8
3048 -#define MAX_COEF_BITS 10
3050 -#define MAX_COEF_BITS 14
3053 -/* Derived data constructed for each Huffman table */
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 */
3061 -/* Short forms of external names for systems with brain-damaged linkers. */
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 */
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));
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
3081 - * reserved comment block
3082 - * DO NOT REMOVE OR ALTER!
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.
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.
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.
3101 -#define JPEG_INTERNALS
3102 -#include "jinclude.h"
3103 -#include "jpeglib.h"
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.
3113 -jinit_compress_master (j_compress_ptr cinfo)
3115 - /* Initialize master control (includes parameter checking/processing) */
3116 - jinit_c_master_control(cinfo, FALSE /* full compression */);
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 */);
3125 - jinit_forward_dct(cinfo);
3126 - /* Entropy encoding: either Huffman or arithmetic coding. */
3127 - if (cinfo->arith_code) {
3128 - ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
3130 - if (cinfo->progressive_mode) {
3131 -#ifdef C_PROGRESSIVE_SUPPORTED
3132 - jinit_phuff_encoder(cinfo);
3134 - ERREXIT(cinfo, JERR_NOT_COMPILED);
3137 - jinit_huff_encoder(cinfo);
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 */);
3145 - jinit_marker_writer(cinfo);
3147 - /* We can now tell the memory manager to allocate virtual arrays. */
3148 - (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
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.
3154 - (*cinfo->marker->write_file_header) (cinfo);
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
3161 - * reserved comment block
3162 - * DO NOT REMOVE OR ALTER!
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.
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.
3176 -#define JPEG_INTERNALS
3177 -#include "jinclude.h"
3178 -#include "jpeglib.h"
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.
3186 -#undef FULL_MAIN_BUFFER_SUPPORTED
3189 -/* Private buffer controller object */
3192 - struct jpeg_c_main_controller pub; /* public fields */
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 */
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.
3203 - JSAMPARRAY buffer[MAX_COMPONENTS];
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.
3209 - jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
3211 -} my_main_controller;
3213 -typedef my_main_controller * my_main_ptr;
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));
3228 - * Initialize for a processing pass.
3232 -start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
3234 - my_main_ptr _main = (my_main_ptr) cinfo->main;
3236 - /* Do nothing in raw-data mode. */
3237 - if (cinfo->raw_data_in)
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 */
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);
3251 - _main->pub.process_data = process_data_simple_main;
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;
3263 - ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
3270 - * Process some data.
3271 - * This routine handles the simple pass-through mode,
3272 - * where we have only a strip buffer.
3276 -process_data_simple_main (j_compress_ptr cinfo,
3277 - JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
3278 - JDIMENSION in_rows_avail)
3280 - my_main_ptr _main = (my_main_ptr) cinfo->main;
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,