DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
jpeg.c
Go to the documentation of this file.
1/*
2 Copyright (C) 2002 Mathieu Olivier
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to:
17
18 Free Software Foundation, Inc.
19 59 Temple Place - Suite 330
20 Boston, MA 02111-1307, USA
21
22*/
23
24
25#include "darkplaces.h"
26#include "cl_screen.h"
27#include "image.h"
28#include "jpeg.h"
29#include "image_png.h"
30
32cvar_t r_texture_jpeg_fastpicmip = {CF_CLIENT | CF_ARCHIVE, "r_texture_jpeg_fastpicmip", "1", "perform gl_picmip during decompression for JPEG files (faster)"};
33
34// jboolean is unsigned char instead of int on Win32
35#ifdef WIN32
36typedef unsigned char jboolean;
37#else
38typedef int jboolean;
39#endif
40
41#ifdef LINK_TO_LIBJPEG
42#include <jpeglib.h>
43#define qjpeg_create_compress jpeg_create_compress
44#define qjpeg_create_decompress jpeg_create_decompress
45#define qjpeg_destroy_compress jpeg_destroy_compress
46#define qjpeg_destroy_decompress jpeg_destroy_decompress
47#define qjpeg_finish_compress jpeg_finish_compress
48#define qjpeg_finish_decompress jpeg_finish_decompress
49#define qjpeg_resync_to_restart jpeg_resync_to_restart
50#define qjpeg_read_header jpeg_read_header
51#define qjpeg_read_scanlines jpeg_read_scanlines
52#define qjpeg_set_defaults jpeg_set_defaults
53#define qjpeg_set_quality jpeg_set_quality
54#define qjpeg_start_compress jpeg_start_compress
55#define qjpeg_start_decompress jpeg_start_decompress
56#define qjpeg_std_error jpeg_std_error
57#define qjpeg_write_scanlines jpeg_write_scanlines
58#define qjpeg_simple_progression jpeg_simple_progression
59#define jpeg_dll true
60#else
61/*
62=================================================================
63
64 Minimal set of definitions from the JPEG lib
65
66 WARNING: for a matter of simplicity, several pointer types are
67 casted to "void*", and most enumerated values are not included
68
69=================================================================
70*/
71
72typedef void *j_common_ptr;
73typedef struct jpeg_compress_struct *j_compress_ptr;
74typedef struct jpeg_decompress_struct *j_decompress_ptr;
75
76#define JPEG_LIB_VERSION 62 // Version 6b
77
89typedef unsigned int JDIMENSION;
90
91#define JPOOL_PERMANENT 0 // lasts until master record is destroyed
92#define JPOOL_IMAGE 1 // lasts until done with image/datastream
93
94#define JPEG_EOI 0xD9 // EOI marker code
95
96#define JMSG_STR_PARM_MAX 80
97
98#define DCTSIZE2 64
99#define NUM_QUANT_TBLS 4
100#define NUM_HUFF_TBLS 4
101#define NUM_ARITH_TBLS 16
102#define MAX_COMPS_IN_SCAN 4
103#define C_MAX_BLOCKS_IN_MCU 10
104#define D_MAX_BLOCKS_IN_MCU 10
105
107{
108 void* (*alloc_small) (j_common_ptr cinfo, int pool_id, size_t sizeofobject);
117 void (*_reserve_space_for_free_pool) (void *dummy, ...);
119
122};
123
144
146{
147 const unsigned char *next_input_byte;
149
150 void (*init_source) (j_decompress_ptr cinfo);
151 jboolean (*fill_input_buffer) (j_decompress_ptr cinfo);
152 void (*skip_input_data) (j_decompress_ptr cinfo, long num_bytes);
153 jboolean (*resync_to_restart) (j_decompress_ptr cinfo, int desired);
154 void (*term_source) (j_decompress_ptr cinfo);
155};
156
157typedef struct {
158 /* These values are fixed over the whole image. */
159 /* For compression, they must be supplied by parameter setup; */
160 /* for decompression, they are read from the SOF marker. */
161 int component_id; /* identifier for this component (0..255) */
162 int component_index; /* its index in SOF or cinfo->comp_info[] */
163 int h_samp_factor; /* horizontal sampling factor (1..4) */
164 int v_samp_factor; /* vertical sampling factor (1..4) */
165 int quant_tbl_no; /* quantization table selector (0..3) */
166 /* These values may vary between scans. */
167 /* For compression, they must be supplied by parameter setup; */
168 /* for decompression, they are read from the SOS marker. */
169 /* The decompressor output side may not use these variables. */
170 int dc_tbl_no; /* DC entropy table selector (0..3) */
171 int ac_tbl_no; /* AC entropy table selector (0..3) */
172
173 /* Remaining fields should be treated as private by applications. */
174
175 /* These values are computed during compression or decompression startup: */
176 /* Component's size in DCT blocks.
177 * Any dummy blocks added to complete an MCU are not counted; therefore
178 * these values do not depend on whether a scan is interleaved or not.
179 */
182 /* Size of a DCT block in samples. Always DCTSIZE for compression.
183 * For decompression this is the size of the output from one DCT block,
184 * reflecting any scaling we choose to apply during the IDCT step.
185 * Values of 1,2,4,8 are likely to be supported. Note that different
186 * components may receive different IDCT scalings.
187 */
189 /* The downsampled dimensions are the component's actual, unpadded number
190 * of samples at the main buffer (preprocessing/compression interface), thus
191 * downsampled_width = ceil(image_width * Hi/Hmax)
192 * and similarly for height. For decompression, IDCT scaling is included, so
193 * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
194 */
195 JDIMENSION downsampled_width; /* actual width in samples */
196 JDIMENSION downsampled_height; /* actual height in samples */
197 /* This flag is used only for decompression. In cases where some of the
198 * components will be ignored (eg grayscale output from YCbCr image),
199 * we can skip most computations for the unused components.
200 */
201 jboolean component_needed; /* do we need the value of this component? */
202
203 /* These values are computed before starting a scan of the component. */
204 /* The decompressor output side may not use these variables. */
205 int MCU_width; /* number of blocks per MCU, horizontally */
206 int MCU_height; /* number of blocks per MCU, vertically */
207 int MCU_blocks; /* MCU_width * MCU_height */
208 int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
209 int last_col_width; /* # of non-dummy blocks across in last MCU */
210 int last_row_height; /* # of non-dummy blocks down in last MCU */
211
212 /* Saved quantization table for component; NULL if none yet saved.
213 * See jdinput.c comments about the need for this information.
214 * This field is currently used only for decompression.
215 */
217
218 /* Private per-component storage for DCT or IDCT subsystem. */
219 void * dct_table;
221
223{
224 struct jpeg_error_mgr *err; // USED
225 struct jpeg_memory_mgr *mem; // USED
226
227 void *progress;
231
232 struct jpeg_source_mgr *src; // USED
235
239 unsigned int scale_num, scale_denom;
254
256
258
259 int output_components; // USED
260
263 void *colormap;
264
266
282 unsigned int restart_interval;
284 unsigned char JFIF_major_version;
285 unsigned char JFIF_minor_version;
286 unsigned char density_unit;
287 unsigned short X_density;
288 unsigned short Y_density;
290 unsigned char Adobe_transform;
304 int Ss, Se, Ah, Al;
306 void *master;
307 void *main;
308 void *coef;
309 void *post;
310 void *inputctl;
311 void *marker;
312 void *entropy;
313 void *idct;
314 void *upsample;
315 void *cconvert;
317};
318
319
321{
324 void *progress;
328
329 void *dest;
336
346
348 const void *scan_info;
355
356 unsigned int restart_interval;
358
360 unsigned char JFIF_major_version;
361 unsigned char JFIF_minor_version;
362 unsigned char density_unit;
363 unsigned short X_density;
364 unsigned short Y_density;
367
378 int Ss, Se, Ah, Al;
379
380 void *master;
381 void *main;
382 void *prep;
383 void *coef;
384 void *marker;
385 void *cconvert;
387 void *fdct;
388 void *entropy;
391};
392
394{
395 unsigned char* next_output_byte;
397
398 void (*init_destination) (j_compress_ptr cinfo);
399 jboolean (*empty_output_buffer) (j_compress_ptr cinfo);
400 void (*term_destination) (j_compress_ptr cinfo);
401};
402
403
404/*
405=================================================================
406
407 DarkPlaces definitions
408
409=================================================================
410*/
411
412// Functions exported from libjpeg
413#define qjpeg_create_compress(cinfo) \
414 qjpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_compress_struct))
415#define qjpeg_create_decompress(cinfo) \
416 qjpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_decompress_struct))
417
418static void (*qjpeg_CreateCompress) (j_compress_ptr cinfo, int version, size_t structsize);
419static void (*qjpeg_CreateDecompress) (j_decompress_ptr cinfo, int version, size_t structsize);
420static void (*qjpeg_destroy_compress) (j_compress_ptr cinfo);
421static void (*qjpeg_destroy_decompress) (j_decompress_ptr cinfo);
422static void (*qjpeg_finish_compress) (j_compress_ptr cinfo);
423static jboolean (*qjpeg_finish_decompress) (j_decompress_ptr cinfo);
424static jboolean (*qjpeg_resync_to_restart) (j_decompress_ptr cinfo, int desired);
425static int (*qjpeg_read_header) (j_decompress_ptr cinfo, jboolean require_image);
426static JDIMENSION (*qjpeg_read_scanlines) (j_decompress_ptr cinfo, unsigned char** scanlines, JDIMENSION max_lines);
427static void (*qjpeg_set_defaults) (j_compress_ptr cinfo);
428static void (*qjpeg_set_quality) (j_compress_ptr cinfo, int quality, jboolean force_baseline);
429static jboolean (*qjpeg_start_compress) (j_compress_ptr cinfo, jboolean write_all_tables);
430static jboolean (*qjpeg_start_decompress) (j_decompress_ptr cinfo);
431static struct jpeg_error_mgr* (*qjpeg_std_error) (struct jpeg_error_mgr *err);
432static JDIMENSION (*qjpeg_write_scanlines) (j_compress_ptr cinfo, unsigned char** scanlines, JDIMENSION num_lines);
433static void (*qjpeg_simple_progression) (j_compress_ptr cinfo);
434
436{
437 {"jpeg_CreateCompress", (void **) &qjpeg_CreateCompress},
438 {"jpeg_CreateDecompress", (void **) &qjpeg_CreateDecompress},
439 {"jpeg_destroy_compress", (void **) &qjpeg_destroy_compress},
440 {"jpeg_destroy_decompress", (void **) &qjpeg_destroy_decompress},
441 {"jpeg_finish_compress", (void **) &qjpeg_finish_compress},
442 {"jpeg_finish_decompress", (void **) &qjpeg_finish_decompress},
443 {"jpeg_resync_to_restart", (void **) &qjpeg_resync_to_restart},
444 {"jpeg_read_header", (void **) &qjpeg_read_header},
445 {"jpeg_read_scanlines", (void **) &qjpeg_read_scanlines},
446 {"jpeg_set_defaults", (void **) &qjpeg_set_defaults},
447 {"jpeg_set_quality", (void **) &qjpeg_set_quality},
448 {"jpeg_start_compress", (void **) &qjpeg_start_compress},
449 {"jpeg_start_decompress", (void **) &qjpeg_start_decompress},
450 {"jpeg_std_error", (void **) &qjpeg_std_error},
451 {"jpeg_write_scanlines", (void **) &qjpeg_write_scanlines},
452 {"jpeg_simple_progression", (void **) &qjpeg_simple_progression},
453 {NULL, NULL}
454};
455
456// Handle for JPEG DLL
459#endif
460
461static unsigned char jpeg_eoi_marker [2] = {0xFF, JPEG_EOI};
462static jmp_buf error_in_jpeg;
464
465// Our own output manager for JPEG compression
466typedef struct
467{
469
470 qfile_t* outfile;
471 unsigned char* buffer;
472 size_t bufsize; // used if outfile is NULL
475
476
477/*
478=================================================================
479
480 DLL load & unload
481
482=================================================================
483*/
484
485/*
486====================
487JPEG_OpenLibrary
488
489Try to load the JPEG DLL
490====================
491*/
493{
494#ifdef LINK_TO_LIBJPEG
495 return true;
496#else
497 const char* dllnames [] =
498 {
499#if defined(WIN32)
500 "libjpeg.dll",
501#elif defined(MACOSX)
502 "libjpeg.62.dylib",
503#else
504 "libjpeg.so.62",
505 "libjpeg.so",
506#endif
507 NULL
508 };
509
510 // Already loaded?
511 if (jpeg_dll)
512 return true;
513
514 if (jpeg_tried_loading) // only try once
515 return false;
516
517 jpeg_tried_loading = true;
518
519#ifdef __ANDROID__
520 // loading the native Android libjpeg.so causes crashes
521 Con_Printf("Not opening libjpeg.so dynamically on Android - use LINK_TO_LIBJPEG instead if it is needed.\n");
522 return false;
523#endif
524
525 // Load the DLL
526 return Sys_LoadDependency (dllnames, &jpeg_dll, jpegfuncs);
527#endif
528}
529
530
531/*
532====================
533JPEG_CloseLibrary
534
535Unload the JPEG DLL
536====================
537*/
539{
540#ifndef LINK_TO_LIBJPEG
542 jpeg_tried_loading = false; // allow retry
543#endif
544}
545
546
547/*
548=================================================================
549
550 JPEG decompression
551
552=================================================================
553*/
554
555static void JPEG_Noop (j_decompress_ptr cinfo) {}
556
557static jboolean JPEG_FillInputBuffer (j_decompress_ptr cinfo)
558{
559 // Insert a fake EOI marker
560 cinfo->src->next_input_byte = jpeg_eoi_marker;
561 cinfo->src->bytes_in_buffer = 2;
562
563 return true;
564}
565
566static void JPEG_SkipInputData (j_decompress_ptr cinfo, long num_bytes)
567{
568 if (cinfo->src->bytes_in_buffer <= (unsigned long)num_bytes)
569 {
570 cinfo->src->bytes_in_buffer = 0;
571 return;
572 }
573
574 cinfo->src->next_input_byte += num_bytes;
575 cinfo->src->bytes_in_buffer -= num_bytes;
576}
577
578static void JPEG_MemSrc (j_decompress_ptr cinfo, const unsigned char *buffer, size_t filesize)
579{
580 cinfo->src = (struct jpeg_source_mgr *)cinfo->mem->alloc_small ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr));
581
582 cinfo->src->next_input_byte = buffer;
583 cinfo->src->bytes_in_buffer = filesize;
584
585 cinfo->src->init_source = JPEG_Noop;
586 cinfo->src->fill_input_buffer = JPEG_FillInputBuffer;
587 cinfo->src->skip_input_data = JPEG_SkipInputData;
588 cinfo->src->resync_to_restart = qjpeg_resync_to_restart; // use the default method
589 cinfo->src->term_source = JPEG_Noop;
590}
591
592static void JPEG_ErrorExit (j_common_ptr cinfo)
593{
594 ((struct jpeg_decompress_struct*)cinfo)->err->output_message (cinfo);
595 longjmp(error_in_jpeg, 1);
596}
597
598
599/*
600====================
601JPEG_LoadImage
602
603Load a JPEG image into a BGRA buffer
604====================
605*/
606unsigned char* JPEG_LoadImage_BGRA (const unsigned char *f, int filesize, int *miplevel)
607{
608 struct jpeg_decompress_struct cinfo;
609 struct jpeg_error_mgr jerr;
610 unsigned char *image_buffer = NULL, *scanline = NULL;
611 unsigned int line;
612 int submip = 0;
613
614 // No DLL = no JPEGs
615 if (!jpeg_dll)
616 return NULL;
617
618 if(miplevel && r_texture_jpeg_fastpicmip.integer)
619 submip = bound(0, *miplevel, 3);
620
621 cinfo.err = qjpeg_std_error (&jerr);
623 if(setjmp(error_in_jpeg))
624 goto error_caught;
625 cinfo.err = qjpeg_std_error (&jerr);
627 JPEG_MemSrc (&cinfo, f, filesize);
628 qjpeg_read_header (&cinfo, true);
629 cinfo.scale_num = 1;
630 cinfo.scale_denom = (1 << submip);
631 qjpeg_start_decompress (&cinfo);
632
635
636 if (image_width > 32768 || image_height > 32768 || image_width <= 0 || image_height <= 0)
637 {
638 Con_Printf("JPEG_LoadImage: invalid image size %ix%i\n", image_width, image_height);
639 return NULL;
640 }
641
642 image_buffer = (unsigned char *)Mem_Alloc(tempmempool, image_width * image_height * 4);
643 scanline = (unsigned char *)Mem_Alloc(tempmempool, image_width * cinfo.output_components);
644 if (!image_buffer || !scanline)
645 {
646 if (image_buffer)
647 Mem_Free (image_buffer);
648 if (scanline)
649 Mem_Free (scanline);
650
651 Con_Printf("JPEG_LoadImage: not enough memory for %i by %i image\n", image_width, image_height);
654 return NULL;
655 }
656
657 // Decompress the image, line by line
658 line = 0;
659 while (cinfo.output_scanline < cinfo.output_height)
660 {
661 unsigned char *buffer_ptr;
662 int ind;
663
664 qjpeg_read_scanlines (&cinfo, &scanline, 1);
665
666 // Convert the image to BGRA
667 switch (cinfo.output_components)
668 {
669 // RGB images
670 case 3:
671 buffer_ptr = &image_buffer[image_width * line * 4];
672 for (ind = 0; ind < image_width * 3; ind += 3, buffer_ptr += 4)
673 {
674 buffer_ptr[2] = scanline[ind];
675 buffer_ptr[1] = scanline[ind + 1];
676 buffer_ptr[0] = scanline[ind + 2];
677 buffer_ptr[3] = 255;
678 }
679 break;
680
681 // Greyscale images (default to it, just in case)
682 case 1:
683 default:
684 buffer_ptr = &image_buffer[image_width * line * 4];
685 for (ind = 0; ind < image_width; ind++, buffer_ptr += 4)
686 {
687 buffer_ptr[0] = scanline[ind];
688 buffer_ptr[1] = scanline[ind];
689 buffer_ptr[2] = scanline[ind];
690 buffer_ptr[3] = 255;
691 }
692 }
693
694 line++;
695 }
696 Mem_Free (scanline); scanline = NULL;
697
700
701 if(miplevel)
702 *miplevel -= submip;
703
704 return image_buffer;
705
706error_caught:
707 if(scanline)
708 Mem_Free (scanline);
709 if(image_buffer)
710 Mem_Free (image_buffer);
712 return NULL;
713}
714
715
716/*
717=================================================================
718
719 JPEG compression
720
721=================================================================
722*/
723
724#define JPEG_OUTPUT_BUF_SIZE 4096
725static void JPEG_InitDestination (j_compress_ptr cinfo)
726{
727 my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
728 dest->buffer = (unsigned char*)cinfo->mem->alloc_small ((j_common_ptr) cinfo, JPOOL_IMAGE, JPEG_OUTPUT_BUF_SIZE * sizeof(unsigned char));
729 dest->pub.next_output_byte = dest->buffer;
731}
732
733static jboolean JPEG_EmptyOutputBuffer (j_compress_ptr cinfo)
734{
735 my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
736
737 if (FS_Write (dest->outfile, dest->buffer, JPEG_OUTPUT_BUF_SIZE) != (size_t) JPEG_OUTPUT_BUF_SIZE)
738 longjmp(error_in_jpeg, 1);
739
740 dest->pub.next_output_byte = dest->buffer;
742 return true;
743}
744
745static void JPEG_TermDestination (j_compress_ptr cinfo)
746{
747 my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
748 size_t datacount = JPEG_OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
749
750 // Write any data remaining in the buffer
751 if (datacount > 0)
752 if (FS_Write (dest->outfile, dest->buffer, datacount) != (fs_offset_t)datacount)
753 longjmp(error_in_jpeg, 1);
754}
755
756static void JPEG_FileDest (j_compress_ptr cinfo, qfile_t* outfile)
757{
758 my_dest_ptr dest;
759
760 // First time for this JPEG object?
761 if (cinfo->dest == NULL)
762 cinfo->dest = (struct jpeg_destination_mgr *)(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(my_destination_mgr));
763
764 dest = (my_dest_ptr)cinfo->dest;
768 dest->outfile = outfile;
769}
770
771static void JPEG_Mem_InitDestination (j_compress_ptr cinfo)
772{
773 my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
774 dest->pub.next_output_byte = dest->buffer;
775 dest->pub.free_in_buffer = dest->bufsize;
776}
777
778static jboolean JPEG_Mem_EmptyOutputBuffer (j_compress_ptr cinfo)
779{
780 my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
781 jpeg_toolarge = true;
782 dest->pub.next_output_byte = dest->buffer;
783 dest->pub.free_in_buffer = dest->bufsize;
784 return true;
785}
786
787static void JPEG_Mem_TermDestination (j_compress_ptr cinfo)
788{
789 my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
790 dest->bufsize = dest->pub.next_output_byte - dest->buffer;
791}
792static void JPEG_MemDest (j_compress_ptr cinfo, void* buf, size_t bufsize)
793{
794 my_dest_ptr dest;
795
796 // First time for this JPEG object?
797 if (cinfo->dest == NULL)
798 cinfo->dest = (struct jpeg_destination_mgr *)(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(my_destination_mgr));
799
800 dest = (my_dest_ptr)cinfo->dest;
804 dest->outfile = NULL;
805
806 dest->buffer = (unsigned char *) buf;
807 dest->bufsize = bufsize;
808}
809
810
811/*
812====================
813JPEG_SaveImage_preflipped
814
815Save a preflipped JPEG image to a file
816====================
817*/
818qbool JPEG_SaveImage_preflipped (const char *filename, int width, int height, unsigned char *data)
819{
820 struct jpeg_compress_struct cinfo;
821 struct jpeg_error_mgr jerr;
822 unsigned char *scanline;
823 unsigned int offset, linesize;
824 qfile_t* file;
825
826 // No DLL = no JPEGs
827 if (!jpeg_dll)
828 {
829 Con_Print("You need the libjpeg library to save JPEG images\n");
830 return false;
831 }
832
833 // Open the file
834 file = FS_OpenRealFile(filename, "wb", true);
835 if (!file)
836 return false;
837
838 if(setjmp(error_in_jpeg))
839 goto error_caught;
840 cinfo.err = qjpeg_std_error (&jerr);
842
843 qjpeg_create_compress (&cinfo);
844 JPEG_FileDest (&cinfo, file);
845
846 // Set the parameters for compression
847 cinfo.image_width = width;
848 cinfo.image_height = height;
849 cinfo.in_color_space = JCS_RGB;
850 cinfo.input_components = 3;
851 qjpeg_set_defaults (&cinfo);
852 qjpeg_set_quality (&cinfo, (int)(scr_screenshot_jpeg_quality.value * 100), true);
854
855 // turn off subsampling (to make text look better)
856 cinfo.optimize_coding = 1;
857 cinfo.comp_info[0].h_samp_factor = 1;
858 cinfo.comp_info[0].v_samp_factor = 1;
859 cinfo.comp_info[1].h_samp_factor = 1;
860 cinfo.comp_info[1].v_samp_factor = 1;
861 cinfo.comp_info[2].h_samp_factor = 1;
862 cinfo.comp_info[2].v_samp_factor = 1;
863
864 qjpeg_start_compress (&cinfo, true);
865
866 // Compress each scanline
867 linesize = cinfo.image_width * 3;
868 offset = linesize * (cinfo.image_height - 1);
869 while (cinfo.next_scanline < cinfo.image_height)
870 {
871 scanline = &data[offset - cinfo.next_scanline * linesize];
872
873 qjpeg_write_scanlines (&cinfo, &scanline, 1);
874 }
875
876 qjpeg_finish_compress (&cinfo);
877 qjpeg_destroy_compress (&cinfo);
878
879 FS_Close (file);
880 return true;
881
882error_caught:
883 qjpeg_destroy_compress (&cinfo);
884 FS_Close (file);
885 return false;
886}
887
888static size_t JPEG_try_SaveImage_to_Buffer (struct jpeg_compress_struct *cinfo, char *jpegbuf, size_t jpegsize, int quality, int width, int height, unsigned char *data)
889{
890 unsigned char *scanline;
891 unsigned int linesize;
892
893 jpeg_toolarge = false;
894 JPEG_MemDest (cinfo, jpegbuf, jpegsize);
895
896 // Set the parameters for compression
897 cinfo->image_width = width;
898 cinfo->image_height = height;
899 cinfo->in_color_space = JCS_RGB;
900 cinfo->input_components = 3;
901 qjpeg_set_defaults (cinfo);
902 qjpeg_set_quality (cinfo, quality, false);
903
904 cinfo->comp_info[0].h_samp_factor = 2;
905 cinfo->comp_info[0].v_samp_factor = 2;
906 cinfo->comp_info[1].h_samp_factor = 1;
907 cinfo->comp_info[1].v_samp_factor = 1;
908 cinfo->comp_info[2].h_samp_factor = 1;
909 cinfo->comp_info[2].v_samp_factor = 1;
910 cinfo->optimize_coding = 1;
911
912 qjpeg_start_compress (cinfo, true);
913
914 // Compress each scanline
915 linesize = width * 3;
916 while (cinfo->next_scanline < cinfo->image_height)
917 {
918 scanline = &data[cinfo->next_scanline * linesize];
919
920 qjpeg_write_scanlines (cinfo, &scanline, 1);
921 }
922
923 qjpeg_finish_compress (cinfo);
924
925 if(jpeg_toolarge)
926 return 0;
927
928 return ((my_dest_ptr) cinfo->dest)->bufsize;
929}
930
931size_t JPEG_SaveImage_to_Buffer (char *jpegbuf, size_t jpegsize, int width, int height, unsigned char *data)
932{
933 struct jpeg_compress_struct cinfo;
934 struct jpeg_error_mgr jerr;
935
936 int quality;
937 int quality_guess;
938 size_t result;
939
940 // No DLL = no JPEGs
941 if (!jpeg_dll)
942 {
943 Con_Print("You need the libjpeg library to save JPEG images\n");
944 return false;
945 }
946
947 if(setjmp(error_in_jpeg))
948 goto error_caught;
949 cinfo.err = qjpeg_std_error (&jerr);
951
952 qjpeg_create_compress (&cinfo);
953
954#if 0
955 // used to get the formula below
956 {
957 char buf[1048576];
958 unsigned char *img;
959 int i;
960
962 for(i = 0; i < width * height * 3; ++i)
963 img[i] = rand() & 0xFF;
964
965 for(i = 0; i <= 100; ++i)
966 {
967 Con_Printf("! %d %d %d %d\n", width, height, i, (int) JPEG_try_SaveImage_to_Buffer(&cinfo, buf, sizeof(buf), i, width, height, img));
968 }
969
970 Mem_Free(img);
971 }
972#endif
973
974 //quality_guess = (int)((100 * jpegsize - 41000) / (width*height) + 2); // fits random data
975 quality_guess = (int)((256 * jpegsize - 81920) / (width*height) - 8); // fits Nexuiz's/Xonotic's map pictures
976
977 quality_guess = bound(0, quality_guess, 100);
978 quality = bound(0, quality_guess + sv_writepicture_quality.integer, 100); // assume it can do 10 failed attempts
979
980 while(!(result = JPEG_try_SaveImage_to_Buffer(&cinfo, jpegbuf, jpegsize, quality, width, height, data)))
981 {
982 --quality;
983 if(quality < 0)
984 {
985 Con_Printf("couldn't write image at all, probably too big\n");
986 return 0;
987 }
988 }
989 qjpeg_destroy_compress (&cinfo);
990 Con_DPrintf("JPEG_SaveImage_to_Buffer: guessed quality/size %d/%d, actually got %d/%d\n", quality_guess, (int)jpegsize, quality, (int)result);
991
992 return result;
993
994error_caught:
995 qjpeg_destroy_compress (&cinfo);
996 return 0;
997}
998
1008#define COMPRESSEDIMAGECACHE_SIZE 4096
1010
1011static void CompressedImageCache_Add(const char *imagename, size_t maxsize, void *compressed, size_t compressed_size)
1012{
1013 char vabuf[1024];
1014 const char *hashkey = va(vabuf, sizeof(vabuf), "%s:%d", imagename, (int) maxsize);
1015 int hashindex = CRC_Block((unsigned char *) hashkey, strlen(hashkey)) % COMPRESSEDIMAGECACHE_SIZE;
1017
1018 if(strlen(imagename) >= MAX_QPATH)
1019 return; // can't add this
1020
1022 dp_strlcpy(i->imagename, imagename, sizeof(i->imagename));
1023 i->maxsize = maxsize;
1024 i->compressed = compressed;
1025 i->compressed_size = compressed_size;
1026 i->next = CompressedImageCache[hashindex];
1027 CompressedImageCache[hashindex] = i;
1028}
1029
1031{
1032 char vabuf[1024];
1033 const char *hashkey = va(vabuf, sizeof(vabuf), "%s:%d", imagename, (int) maxsize);
1034 int hashindex = CRC_Block((unsigned char *) hashkey, strlen(hashkey)) % COMPRESSEDIMAGECACHE_SIZE;
1036
1037 while(i)
1038 {
1039 if(i->maxsize == maxsize)
1040 if(!strcmp(i->imagename, imagename))
1041 return i;
1042 i = i->next;
1043 }
1044 return NULL;
1045}
1046
1047qbool Image_Compress(const char *imagename, size_t maxsize, void **buf, size_t *size)
1048{
1049 unsigned char *imagedata, *newimagedata;
1050 int maxPixelCount;
1051 int components[3] = {2, 1, 0};
1053
1054 JPEG_OpenLibrary (); // for now; LH had the idea of replacing this by a better format
1055 PNG_OpenLibrary (); // for loading
1056
1057 // No DLL = no JPEGs
1058 if (!jpeg_dll)
1059 {
1060 Con_Print("You need the libjpeg library to save JPEG images\n");
1061 return false;
1062 }
1063
1065 if(i)
1066 {
1067 *size = i->compressed_size;
1068 *buf = i->compressed;
1069 return (*buf != NULL);
1070 }
1071
1072 // load the image
1073 imagedata = loadimagepixelsbgra(imagename, true, false, false, NULL);
1074 if(!imagedata)
1075 return false;
1076
1077 // find an appropriate size for somewhat okay compression
1078 if(maxsize <= 768)
1079 maxPixelCount = 32 * 32;
1080 else if(maxsize <= 1024)
1081 maxPixelCount = 64 * 64;
1082 else if(maxsize <= 4096)
1083 maxPixelCount = 128 * 128;
1084 else
1085 maxPixelCount = 256 * 256;
1086
1087 while(image_width * image_height > maxPixelCount)
1088 {
1089 int one = 1;
1090 Image_MipReduce32(imagedata, imagedata, &image_width, &image_height, &one, image_width/2, image_height/2, 1);
1091 }
1092
1093 newimagedata = (unsigned char *) Mem_Alloc(tempmempool, image_width * image_height * 3);
1094
1095 // convert the image from BGRA to RGB
1096 Image_CopyMux(newimagedata, imagedata, image_width, image_height, false, false, false, 3, 4, components);
1097 Mem_Free(imagedata);
1098
1099 // try to compress it to JPEG
1100 *buf = Z_Malloc(maxsize);
1101 *size = JPEG_SaveImage_to_Buffer((char *) *buf, maxsize, image_width, image_height, newimagedata);
1102 Mem_Free(newimagedata);
1103
1104 if(!*size)
1105 {
1106 Z_Free(*buf);
1107 *buf = NULL;
1108 Con_Printf("could not compress image %s to %d bytes\n", imagename, (int)maxsize);
1109 // return false;
1110 // also cache failures!
1111 }
1112
1113 // store it in the cache
1115 return (*buf != NULL);
1116}
cvar_t scr_screenshot_jpeg_quality
Definition cl_screen.c:60
#define CF_CLIENT
cvar/command that only the client can change/execute
Definition cmd.h:48
#define CF_ARCHIVE
cvar should have its set value saved to config.cfg and persist across sessions
Definition cmd.h:53
unsigned short CRC_Block(const unsigned char *data, size_t size)
Definition com_crc16.c:75
char * va(char *buf, size_t buflen, const char *format,...)
Definition common.c:972
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
Definition console.c:1544
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
vector size
void() predraw
fs_offset_t FS_Write(qfile_t *file, const void *data, size_t datasize)
Definition fs.c:3019
qfile_t * FS_OpenRealFile(const char *filepath, const char *mode, qbool quiet)
Definition fs.c:2901
static int(ZEXPORT *qz_inflate)(z_stream *strm
static int const char * version
Definition fs.c:479
int FS_Close(qfile_t *file)
Definition fs.c:2970
int64_t fs_offset_t
Definition fs.h:37
GLenum GLsizei width
Definition glquake.h:622
GLenum GLsizei GLsizei height
Definition glquake.h:622
GLuint buffer
Definition glquake.h:630
GLint void * img
Definition glquake.h:692
GLsizeiptr const GLvoid * data
Definition glquake.h:639
GLuint GLuint GLintptr offset
Definition glquake.h:632
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glquake.h:657
int image_height
Definition image.c:10
void Image_MipReduce32(const unsigned char *in, unsigned char *out, int *width, int *height, int *depth, int destwidth, int destheight, int destdepth)
Definition image.c:1689
void Image_CopyMux(unsigned char *outpixels, const unsigned char *inpixels, int inputwidth, int inputheight, qbool inputflipx, qbool inputflipy, qbool inputflipdiagonal, int numoutputcomponents, int numinputcomponents, int *outputinputcomponentindices)
Definition image.c:24
unsigned char * loadimagepixelsbgra(const char *filename, qbool complain, qbool allowFixtrans, qbool convertsRGB, int *miplevel)
Definition image.c:1043
int image_width
Definition image.c:9
qfile_t * outfile
Definition image_png.c:254
qbool PNG_OpenLibrary(void)
Definition image_png.c:143
unsigned int JDIMENSION
Definition jpeg.c:89
static struct jpeg_error_mgr *(* qjpeg_std_error)(struct jpeg_error_mgr *err)
Definition jpeg.c:431
int jboolean
Definition jpeg.c:38
static JDIMENSION(* qjpeg_read_scanlines)(j_decompress_ptr cinfo, unsigned char **scanlines, JDIMENSION max_lines)
Definition jpeg.c:426
static CompressedImageCacheItem * CompressedImageCache[COMPRESSEDIMAGECACHE_SIZE]
Definition jpeg.c:1009
static int(* qjpeg_read_header)(j_decompress_ptr cinfo, jboolean require_image)
Definition jpeg.c:425
static void(* qjpeg_finish_compress)(j_compress_ptr cinfo)
Definition jpeg.c:422
J_DITHER_MODE
Definition jpeg.c:88
@ JPEG_DUMMY2
Definition jpeg.c:88
static void(* qjpeg_destroy_decompress)(j_decompress_ptr cinfo)
Definition jpeg.c:421
unsigned char * JPEG_LoadImage_BGRA(const unsigned char *f, int filesize, int *miplevel)
Definition jpeg.c:606
static void JPEG_Noop(j_decompress_ptr cinfo)
Definition jpeg.c:555
static void JPEG_Mem_InitDestination(j_compress_ptr cinfo)
Definition jpeg.c:771
static jboolean JPEG_FillInputBuffer(j_decompress_ptr cinfo)
Definition jpeg.c:557
#define JPEG_EOI
Definition jpeg.c:94
#define COMPRESSEDIMAGECACHE_SIZE
Definition jpeg.c:1008
void * j_common_ptr
Definition jpeg.c:72
static void(* qjpeg_CreateCompress)(j_compress_ptr cinfo, int version, size_t structsize)
Definition jpeg.c:418
#define NUM_ARITH_TBLS
Definition jpeg.c:101
#define C_MAX_BLOCKS_IN_MCU
Definition jpeg.c:103
static jboolean(* qjpeg_start_compress)(j_compress_ptr cinfo, jboolean write_all_tables)
Definition jpeg.c:429
static JDIMENSION(* qjpeg_write_scanlines)(j_compress_ptr cinfo, unsigned char **scanlines, JDIMENSION num_lines)
Definition jpeg.c:432
static void CompressedImageCache_Add(const char *imagename, size_t maxsize, void *compressed, size_t compressed_size)
Definition jpeg.c:1011
static jboolean JPEG_EmptyOutputBuffer(j_compress_ptr cinfo)
Definition jpeg.c:733
static void(* qjpeg_destroy_compress)(j_compress_ptr cinfo)
Definition jpeg.c:420
#define NUM_HUFF_TBLS
Definition jpeg.c:100
static qbool jpeg_toolarge
Definition jpeg.c:463
J_COLOR_SPACE
Definition jpeg.c:79
@ JCS_YCCK
Definition jpeg.c:85
@ JCS_UNKNOWN
Definition jpeg.c:80
@ JCS_YCbCr
Definition jpeg.c:83
@ JCS_CMYK
Definition jpeg.c:84
@ JCS_GRAYSCALE
Definition jpeg.c:81
@ JCS_RGB
Definition jpeg.c:82
#define JPEG_OUTPUT_BUF_SIZE
Definition jpeg.c:724
static void(* qjpeg_CreateDecompress)(j_decompress_ptr cinfo, int version, size_t structsize)
Definition jpeg.c:419
qbool JPEG_SaveImage_preflipped(const char *filename, int width, int height, unsigned char *data)
Definition jpeg.c:818
static jboolean(* qjpeg_resync_to_restart)(j_decompress_ptr cinfo, int desired)
Definition jpeg.c:424
dllhandle_t jpeg_dll
Definition jpeg.c:457
static void JPEG_SkipInputData(j_decompress_ptr cinfo, long num_bytes)
Definition jpeg.c:566
static jmp_buf error_in_jpeg
Definition jpeg.c:462
static unsigned char jpeg_eoi_marker[2]
Definition jpeg.c:461
cvar_t r_texture_jpeg_fastpicmip
Definition jpeg.c:32
static void(* qjpeg_simple_progression)(j_compress_ptr cinfo)
Definition jpeg.c:433
qbool JPEG_OpenLibrary(void)
Definition jpeg.c:492
static jboolean(* qjpeg_start_decompress)(j_decompress_ptr cinfo)
Definition jpeg.c:430
static void(* qjpeg_set_quality)(j_compress_ptr cinfo, int quality, jboolean force_baseline)
Definition jpeg.c:428
my_destination_mgr * my_dest_ptr
Definition jpeg.c:474
void JPEG_CloseLibrary(void)
Definition jpeg.c:538
static void(* qjpeg_set_defaults)(j_compress_ptr cinfo)
Definition jpeg.c:427
static void JPEG_MemSrc(j_decompress_ptr cinfo, const unsigned char *buffer, size_t filesize)
Definition jpeg.c:578
static size_t JPEG_try_SaveImage_to_Buffer(struct jpeg_compress_struct *cinfo, char *jpegbuf, size_t jpegsize, int quality, int width, int height, unsigned char *data)
Definition jpeg.c:888
static void JPEG_InitDestination(j_compress_ptr cinfo)
Definition jpeg.c:725
qbool jpeg_tried_loading
Definition jpeg.c:458
static void JPEG_FileDest(j_compress_ptr cinfo, qfile_t *outfile)
Definition jpeg.c:756
static void JPEG_TermDestination(j_compress_ptr cinfo)
Definition jpeg.c:745
#define NUM_QUANT_TBLS
Definition jpeg.c:99
cvar_t sv_writepicture_quality
Definition sv_main.c:219
static jboolean(* qjpeg_finish_decompress)(j_decompress_ptr cinfo)
Definition jpeg.c:423
#define JMSG_STR_PARM_MAX
Definition jpeg.c:96
qbool Image_Compress(const char *imagename, size_t maxsize, void **buf, size_t *size)
Definition jpeg.c:1047
#define JPOOL_PERMANENT
Definition jpeg.c:91
size_t JPEG_SaveImage_to_Buffer(char *jpegbuf, size_t jpegsize, int width, int height, unsigned char *data)
Definition jpeg.c:931
static dllfunction_t jpegfuncs[]
Definition jpeg.c:435
#define JPOOL_IMAGE
Definition jpeg.c:92
static CompressedImageCacheItem * CompressedImageCache_Find(const char *imagename, size_t maxsize)
Definition jpeg.c:1030
#define MAX_COMPS_IN_SCAN
Definition jpeg.c:102
static void JPEG_MemDest(j_compress_ptr cinfo, void *buf, size_t bufsize)
Definition jpeg.c:792
static jboolean JPEG_Mem_EmptyOutputBuffer(j_compress_ptr cinfo)
Definition jpeg.c:778
J_DCT_METHOD
Definition jpeg.c:87
@ JPEG_DUMMY1
Definition jpeg.c:87
static void JPEG_ErrorExit(j_common_ptr cinfo)
Definition jpeg.c:592
static void JPEG_Mem_TermDestination(j_compress_ptr cinfo)
Definition jpeg.c:787
#define qjpeg_create_compress(cinfo)
Definition jpeg.c:413
#define qjpeg_create_decompress(cinfo)
Definition jpeg.c:415
#define DCTSIZE2
Definition jpeg.c:98
#define D_MAX_BLOCKS_IN_MCU
Definition jpeg.c:104
#define bound(min, num, max)
Definition mathlib.h:34
float strlen(string s)
int i
#define MAX_QPATH
max length of a quake game pathname
Definition qdefs.h:169
#define NULL
Definition qtypes.h:12
bool qbool
Definition qtypes.h:9
float f
char imagename[MAX_QPATH]
Definition jpeg.c:1001
struct CompressedImageCacheItem * next
Definition jpeg.c:1005
Definition cvar.h:66
float value
Definition cvar.h:74
int integer
Definition cvar.h:73
JDIMENSION downsampled_height
Definition jpeg.c:196
JDIMENSION width_in_blocks
Definition jpeg.c:180
JDIMENSION height_in_blocks
Definition jpeg.c:181
jboolean component_needed
Definition jpeg.c:201
void * dct_table
Definition jpeg.c:219
JDIMENSION downsampled_width
Definition jpeg.c:195
void * quant_table
Definition jpeg.c:216
jboolean CCIR601_sampling
Definition jpeg.c:352
JDIMENSION image_height
Definition jpeg.c:331
jboolean raw_data_in
Definition jpeg.c:349
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]
Definition jpeg.c:373
J_DCT_METHOD dct_method
Definition jpeg.c:354
jboolean write_Adobe_marker
Definition jpeg.c:365
void * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]
Definition jpeg.c:342
unsigned char JFIF_major_version
Definition jpeg.c:360
JDIMENSION next_scanline
Definition jpeg.c:366
JDIMENSION total_iMCU_rows
Definition jpeg.c:371
unsigned short Y_density
Definition jpeg.c:364
J_COLOR_SPACE in_color_space
Definition jpeg.c:333
double input_gamma
Definition jpeg.c:334
JDIMENSION MCUs_per_row
Definition jpeg.c:374
unsigned char density_unit
Definition jpeg.c:362
JDIMENSION image_width
Definition jpeg.c:330
unsigned char JFIF_minor_version
Definition jpeg.c:361
jboolean optimize_coding
Definition jpeg.c:351
struct jpeg_memory_mgr * mem
Definition jpeg.c:323
jboolean write_JFIF_header
Definition jpeg.c:359
jboolean progressive_mode
Definition jpeg.c:368
int MCU_membership[C_MAX_BLOCKS_IN_MCU]
Definition jpeg.c:377
unsigned int restart_interval
Definition jpeg.c:356
void * downsample
Definition jpeg.c:386
jpeg_component_info * comp_info
Definition jpeg.c:339
struct jpeg_error_mgr * err
Definition jpeg.c:322
void * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]
Definition jpeg.c:341
unsigned char arith_ac_K[NUM_ARITH_TBLS]
Definition jpeg.c:345
unsigned char arith_dc_U[NUM_ARITH_TBLS]
Definition jpeg.c:344
const void * scan_info
Definition jpeg.c:348
void * quant_tbl_ptrs[NUM_QUANT_TBLS]
Definition jpeg.c:340
void * client_data
Definition jpeg.c:325
void * script_space
Definition jpeg.c:389
unsigned char arith_dc_L[NUM_ARITH_TBLS]
Definition jpeg.c:343
unsigned short X_density
Definition jpeg.c:363
JDIMENSION MCU_rows_in_scan
Definition jpeg.c:375
jboolean is_decompressor
Definition jpeg.c:326
jboolean arith_code
Definition jpeg.c:350
J_COLOR_SPACE jpeg_color_space
Definition jpeg.c:338
void * sample_range_limit
Definition jpeg.c:297
J_DITHER_MODE dither_mode
Definition jpeg.c:247
unsigned char density_unit
Definition jpeg.c:286
JDIMENSION output_scanline
Definition jpeg.c:265
jpeg_component_info * comp_info
Definition jpeg.c:276
jboolean progressive_mode
Definition jpeg.c:277
jboolean saw_Adobe_marker
Definition jpeg.c:289
jboolean enable_external_quant
Definition jpeg.c:251
int desired_number_of_colors
Definition jpeg.c:249
struct jpeg_source_mgr * src
Definition jpeg.c:232
JDIMENSION output_iMCU_row
Definition jpeg.c:270
jboolean is_decompressor
Definition jpeg.c:229
unsigned char JFIF_minor_version
Definition jpeg.c:285
JDIMENSION output_height
Definition jpeg.c:255
J_COLOR_SPACE out_color_space
Definition jpeg.c:238
JDIMENSION MCU_rows_in_scan
Definition jpeg.c:301
struct jpeg_memory_mgr * mem
Definition jpeg.c:225
J_COLOR_SPACE jpeg_color_space
Definition jpeg.c:237
int(* coef_bits)[DCTSIZE2]
Definition jpeg.c:271
jboolean saw_JFIF_marker
Definition jpeg.c:283
JDIMENSION image_width
Definition jpeg.c:233
jboolean raw_data_out
Definition jpeg.c:242
jboolean buffered_image
Definition jpeg.c:241
JDIMENSION input_iMCU_row
Definition jpeg.c:268
jboolean do_block_smoothing
Definition jpeg.c:245
unsigned char JFIF_major_version
Definition jpeg.c:284
JDIMENSION total_iMCU_rows
Definition jpeg.c:296
int MCU_membership[D_MAX_BLOCKS_IN_MCU]
Definition jpeg.c:303
jboolean two_pass_quantize
Definition jpeg.c:248
unsigned char arith_ac_K[NUM_ARITH_TBLS]
Definition jpeg.c:281
unsigned int scale_denom
Definition jpeg.c:239
jboolean CCIR601_sampling
Definition jpeg.c:291
JDIMENSION MCUs_per_row
Definition jpeg.c:300
unsigned char arith_dc_U[NUM_ARITH_TBLS]
Definition jpeg.c:280
jboolean enable_1pass_quant
Definition jpeg.c:250
void * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]
Definition jpeg.c:274
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]
Definition jpeg.c:299
JDIMENSION output_width
Definition jpeg.c:253
unsigned short X_density
Definition jpeg.c:287
void * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]
Definition jpeg.c:273
struct jpeg_error_mgr * err
Definition jpeg.c:224
unsigned int scale_num
Definition jpeg.c:239
void * quant_tbl_ptrs[NUM_QUANT_TBLS]
Definition jpeg.c:272
unsigned int restart_interval
Definition jpeg.c:282
jboolean arith_code
Definition jpeg.c:278
jboolean do_fancy_upsampling
Definition jpeg.c:244
int actual_number_of_colors
Definition jpeg.c:262
unsigned short Y_density
Definition jpeg.c:288
JDIMENSION image_height
Definition jpeg.c:234
jboolean enable_2pass_quant
Definition jpeg.c:252
J_DCT_METHOD dct_method
Definition jpeg.c:243
unsigned char arith_dc_L[NUM_ARITH_TBLS]
Definition jpeg.c:279
unsigned char Adobe_transform
Definition jpeg.c:290
jboolean quantize_colors
Definition jpeg.c:246
jboolean(* empty_output_buffer)(j_compress_ptr cinfo)
Definition jpeg.c:399
unsigned char * next_output_byte
Definition jpeg.c:395
void(* term_destination)(j_compress_ptr cinfo)
Definition jpeg.c:400
size_t free_in_buffer
Definition jpeg.c:396
void(* init_destination)(j_compress_ptr cinfo)
Definition jpeg.c:398
int last_jpeg_message
Definition jpeg.c:139
void(* reset_error_mgr)(j_common_ptr cinfo)
Definition jpeg.c:130
char s[JMSG_STR_PARM_MAX]
Definition jpeg.c:134
union jpeg_error_mgr::@14 msg_parm
int msg_code
Definition jpeg.c:131
int first_addon_message
Definition jpeg.c:141
void(* format_message)(j_common_ptr cinfo, char *buffer)
Definition jpeg.c:129
int last_addon_message
Definition jpeg.c:142
long num_warnings
Definition jpeg.c:137
int trace_level
Definition jpeg.c:136
int i[8]
Definition jpeg.c:133
void(* output_message)(j_common_ptr cinfo)
Definition jpeg.c:128
void(* emit_message)(j_common_ptr cinfo, int msg_level)
Definition jpeg.c:127
const char *const * jpeg_message_table
Definition jpeg.c:138
void(* error_exit)(j_common_ptr cinfo)
Definition jpeg.c:126
const char *const * addon_message_table
Definition jpeg.c:140
long max_alloc_chunk
Definition jpeg.c:121
void(* _reserve_space_for_access_virt_sarray)(void *dummy,...)
Definition jpeg.c:115
void(* _reserve_space_for_request_virt_barray)(void *dummy,...)
Definition jpeg.c:113
void(* _reserve_space_for_free_pool)(void *dummy,...)
Definition jpeg.c:117
void(* _reserve_space_for_self_destruct)(void *dummy,...)
Definition jpeg.c:118
void(* _reserve_space_for_alloc_sarray)(void *dummy,...)
Definition jpeg.c:110
void(* _reserve_space_for_alloc_large)(void *dummy,...)
Definition jpeg.c:109
void(* _reserve_space_for_alloc_barray)(void *dummy,...)
Definition jpeg.c:111
long max_memory_to_use
Definition jpeg.c:120
void(* _reserve_space_for_request_virt_sarray)(void *dummy,...)
Definition jpeg.c:112
void(* _reserve_space_for_realize_virt_arrays)(void *dummy,...)
Definition jpeg.c:114
void(* _reserve_space_for_access_virt_barray)(void *dummy,...)
Definition jpeg.c:116
void(* skip_input_data)(j_decompress_ptr cinfo, long num_bytes)
Definition jpeg.c:152
void(* init_source)(j_decompress_ptr cinfo)
Definition jpeg.c:150
const unsigned char * next_input_byte
Definition jpeg.c:147
size_t bytes_in_buffer
Definition jpeg.c:148
void(* term_source)(j_decompress_ptr cinfo)
Definition jpeg.c:154
jboolean(* resync_to_restart)(j_decompress_ptr cinfo, int desired)
Definition jpeg.c:153
jboolean(* fill_input_buffer)(j_decompress_ptr cinfo)
Definition jpeg.c:151
size_t bufsize
Definition jpeg.c:472
qfile_t * outfile
Definition jpeg.c:470
struct jpeg_destination_mgr pub
Definition jpeg.c:468
unsigned char * buffer
Definition jpeg.c:471
void * dllhandle_t
Definition sys.h:169
qbool Sys_LoadDependency(const char **dllnames, dllhandle_t *handle, const dllfunction_t *fcts)
Definition sys_shared.c:131
void Sys_FreeLibrary(dllhandle_t *handle)
Definition sys_shared.c:245
mempool_t * tempmempool
Definition zone.c:794
#define Mem_Free(mem)
Definition zone.h:96
#define Mem_Alloc(pool, size)
Definition zone.h:92
#define Z_Malloc(size)
Definition zone.h:161
#define Z_Free(data)
Definition zone.h:164