DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
jpeg.c File Reference
#include "darkplaces.h"
#include "cl_screen.h"
#include "image.h"
#include "jpeg.h"
#include "image_png.h"
+ Include dependency graph for jpeg.c:

Go to the source code of this file.

Data Structures

struct  CompressedImageCacheItem
 
struct  j_compress_ptr
 
struct  j_decompress_ptr
 
struct  jpeg_component_info
 
struct  jpeg_destination_mgr
 
struct  jpeg_error_mgr
 
struct  jpeg_memory_mgr
 
struct  jpeg_source_mgr
 
struct  my_destination_mgr
 

Macros

#define C_MAX_BLOCKS_IN_MCU   10
 
#define COMPRESSEDIMAGECACHE_SIZE   4096
 
#define D_MAX_BLOCKS_IN_MCU   10
 
#define DCTSIZE2   64
 
#define JMSG_STR_PARM_MAX   80
 
#define JPEG_EOI   0xD9
 
#define JPEG_LIB_VERSION   62
 
#define JPEG_OUTPUT_BUF_SIZE   4096
 
#define JPOOL_IMAGE   1
 
#define JPOOL_PERMANENT   0
 
#define MAX_COMPS_IN_SCAN   4
 
#define NUM_ARITH_TBLS   16
 
#define NUM_HUFF_TBLS   4
 
#define NUM_QUANT_TBLS   4
 
#define qjpeg_create_compress(cinfo)
 
#define qjpeg_create_decompress(cinfo)
 

Typedefs

typedef voidj_common_ptr
 
typedef int jboolean
 
typedef unsigned int JDIMENSION
 
typedef my_destination_mgrmy_dest_ptr
 

Enumerations

enum  J_COLOR_SPACE {
  JCS_UNKNOWN , JCS_GRAYSCALE , JCS_RGB , JCS_YCbCr ,
  JCS_CMYK , JCS_YCCK
}
 
enum  J_DCT_METHOD { JPEG_DUMMY1 }
 
enum  J_DITHER_MODE { JPEG_DUMMY2 }
 

Functions

static void CompressedImageCache_Add (const char *imagename, size_t maxsize, void *compressed, size_t compressed_size)
 
static CompressedImageCacheItemCompressedImageCache_Find (const char *imagename, size_t maxsize)
 
qbool Image_Compress (const char *imagename, size_t maxsize, void **buf, size_t *size)
 
void JPEG_CloseLibrary (void)
 
static jboolean JPEG_EmptyOutputBuffer (j_compress_ptr cinfo)
 
static void JPEG_ErrorExit (j_common_ptr cinfo)
 
static void JPEG_FileDest (j_compress_ptr cinfo, qfile_t *outfile)
 
static jboolean JPEG_FillInputBuffer (j_decompress_ptr cinfo)
 
static void JPEG_InitDestination (j_compress_ptr cinfo)
 
unsigned char * JPEG_LoadImage_BGRA (const unsigned char *f, int filesize, int *miplevel)
 
static jboolean JPEG_Mem_EmptyOutputBuffer (j_compress_ptr cinfo)
 
static void JPEG_Mem_InitDestination (j_compress_ptr cinfo)
 
static void JPEG_Mem_TermDestination (j_compress_ptr cinfo)
 
static void JPEG_MemDest (j_compress_ptr cinfo, void *buf, size_t bufsize)
 
static void JPEG_MemSrc (j_decompress_ptr cinfo, const unsigned char *buffer, size_t filesize)
 
static void JPEG_Noop (j_decompress_ptr cinfo)
 
qbool JPEG_OpenLibrary (void)
 
qbool JPEG_SaveImage_preflipped (const char *filename, int width, int height, unsigned char *data)
 
size_t JPEG_SaveImage_to_Buffer (char *jpegbuf, size_t jpegsize, int width, int height, unsigned char *data)
 
static void JPEG_SkipInputData (j_decompress_ptr cinfo, long num_bytes)
 
static void JPEG_TermDestination (j_compress_ptr cinfo)
 
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)
 

Variables

static CompressedImageCacheItemCompressedImageCache [COMPRESSEDIMAGECACHE_SIZE]
 
static jmp_buf error_in_jpeg
 
dllhandle_t jpeg_dll = NULL
 
static unsigned char jpeg_eoi_marker [2] = {0xFF, JPEG_EOI}
 
static qbool jpeg_toolarge
 
qbool jpeg_tried_loading = 0
 
static dllfunction_t jpegfuncs []
 
static void(* qjpeg_CreateCompress )(j_compress_ptr cinfo, int version, size_t structsize)
 
static void(* qjpeg_CreateDecompress )(j_decompress_ptr cinfo, int version, size_t structsize)
 
static void(* qjpeg_destroy_compress )(j_compress_ptr cinfo)
 
static void(* qjpeg_destroy_decompress )(j_decompress_ptr cinfo)
 
static void(* qjpeg_finish_compress )(j_compress_ptr cinfo)
 
static jboolean(* qjpeg_finish_decompress )(j_decompress_ptr cinfo)
 
static int(* qjpeg_read_header )(j_decompress_ptr cinfo, jboolean require_image)
 
static JDIMENSION(* qjpeg_read_scanlines )(j_decompress_ptr cinfo, unsigned char **scanlines, JDIMENSION max_lines)
 
static jboolean(* qjpeg_resync_to_restart )(j_decompress_ptr cinfo, int desired)
 
static void(* qjpeg_set_defaults )(j_compress_ptr cinfo)
 
static void(* qjpeg_set_quality )(j_compress_ptr cinfo, int quality, jboolean force_baseline)
 
static void(* qjpeg_simple_progression )(j_compress_ptr cinfo)
 
static jboolean(* qjpeg_start_compress )(j_compress_ptr cinfo, jboolean write_all_tables)
 
static jboolean(* qjpeg_start_decompress )(j_decompress_ptr cinfo)
 
static struct jpeg_error_mgr *(* qjpeg_std_error )(struct jpeg_error_mgr *err)
 
static JDIMENSION(* qjpeg_write_scanlines )(j_compress_ptr cinfo, unsigned char **scanlines, JDIMENSION num_lines)
 
cvar_t r_texture_jpeg_fastpicmip = {CF_CLIENT | CF_ARCHIVE, "r_texture_jpeg_fastpicmip", "1", "perform gl_picmip during decompression for JPEG files (faster)"}
 
cvar_t sv_writepicture_quality
 

Macro Definition Documentation

◆ C_MAX_BLOCKS_IN_MCU

#define C_MAX_BLOCKS_IN_MCU   10

Definition at line 103 of file jpeg.c.

◆ COMPRESSEDIMAGECACHE_SIZE

#define COMPRESSEDIMAGECACHE_SIZE   4096

Definition at line 1008 of file jpeg.c.

Referenced by CompressedImageCache_Add(), and CompressedImageCache_Find().

◆ D_MAX_BLOCKS_IN_MCU

#define D_MAX_BLOCKS_IN_MCU   10

Definition at line 104 of file jpeg.c.

◆ DCTSIZE2

#define DCTSIZE2   64

Definition at line 98 of file jpeg.c.

◆ JMSG_STR_PARM_MAX

#define JMSG_STR_PARM_MAX   80

Definition at line 96 of file jpeg.c.

◆ JPEG_EOI

#define JPEG_EOI   0xD9

Definition at line 94 of file jpeg.c.

◆ JPEG_LIB_VERSION

#define JPEG_LIB_VERSION   62

Definition at line 76 of file jpeg.c.

◆ JPEG_OUTPUT_BUF_SIZE

#define JPEG_OUTPUT_BUF_SIZE   4096

Definition at line 724 of file jpeg.c.

Referenced by JPEG_EmptyOutputBuffer(), JPEG_InitDestination(), and JPEG_TermDestination().

◆ JPOOL_IMAGE

#define JPOOL_IMAGE   1

Definition at line 92 of file jpeg.c.

Referenced by JPEG_InitDestination().

◆ JPOOL_PERMANENT

#define JPOOL_PERMANENT   0

Definition at line 91 of file jpeg.c.

Referenced by JPEG_FileDest(), JPEG_MemDest(), and JPEG_MemSrc().

◆ MAX_COMPS_IN_SCAN

#define MAX_COMPS_IN_SCAN   4

Definition at line 102 of file jpeg.c.

◆ NUM_ARITH_TBLS

#define NUM_ARITH_TBLS   16

Definition at line 101 of file jpeg.c.

◆ NUM_HUFF_TBLS

#define NUM_HUFF_TBLS   4

Definition at line 100 of file jpeg.c.

◆ NUM_QUANT_TBLS

#define NUM_QUANT_TBLS   4

Definition at line 99 of file jpeg.c.

◆ qjpeg_create_compress

#define qjpeg_create_compress ( cinfo)
Value:
qjpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_compress_struct))
static void(* qjpeg_CreateCompress)(j_compress_ptr cinfo, int version, size_t structsize)
Definition jpeg.c:418
#define JPEG_LIB_VERSION
Definition jpeg.c:76

Definition at line 413 of file jpeg.c.

413#define qjpeg_create_compress(cinfo) \
414 qjpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_compress_struct))

Referenced by JPEG_SaveImage_preflipped(), and JPEG_SaveImage_to_Buffer().

◆ qjpeg_create_decompress

#define qjpeg_create_decompress ( cinfo)
Value:
static void(* qjpeg_CreateDecompress)(j_decompress_ptr cinfo, int version, size_t structsize)
Definition jpeg.c:419

Definition at line 415 of file jpeg.c.

415#define qjpeg_create_decompress(cinfo) \
416 qjpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_decompress_struct))

Referenced by JPEG_LoadImage_BGRA().

Typedef Documentation

◆ j_common_ptr

typedef void* j_common_ptr

Definition at line 72 of file jpeg.c.

◆ jboolean

typedef int jboolean

Definition at line 38 of file jpeg.c.

◆ JDIMENSION

typedef unsigned int JDIMENSION

Definition at line 89 of file jpeg.c.

◆ my_dest_ptr

Definition at line 474 of file jpeg.c.

Enumeration Type Documentation

◆ J_COLOR_SPACE

Enumerator
JCS_UNKNOWN 
JCS_GRAYSCALE 
JCS_RGB 
JCS_YCbCr 
JCS_CMYK 
JCS_YCCK 

Definition at line 78 of file jpeg.c.

79{
82 JCS_RGB,
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

◆ J_DCT_METHOD

Enumerator
JPEG_DUMMY1 

Definition at line 87 of file jpeg.c.

J_DCT_METHOD
Definition jpeg.c:87
@ JPEG_DUMMY1
Definition jpeg.c:87

◆ J_DITHER_MODE

Enumerator
JPEG_DUMMY2 

Definition at line 88 of file jpeg.c.

J_DITHER_MODE
Definition jpeg.c:88
@ JPEG_DUMMY2
Definition jpeg.c:88

Function Documentation

◆ CompressedImageCache_Add()

static void CompressedImageCache_Add ( const char * imagename,
size_t maxsize,
void * compressed,
size_t compressed_size )
static

Definition at line 1011 of file jpeg.c.

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}
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
static CompressedImageCacheItem * CompressedImageCache[COMPRESSEDIMAGECACHE_SIZE]
Definition jpeg.c:1009
#define COMPRESSEDIMAGECACHE_SIZE
Definition jpeg.c:1008
float strlen(string s)
int i
#define MAX_QPATH
max length of a quake game pathname
Definition qdefs.h:169
#define Z_Malloc(size)
Definition zone.h:161

References CompressedImageCacheItem::compressed, CompressedImageCacheItem::compressed_size, CompressedImageCache, COMPRESSEDIMAGECACHE_SIZE, CRC_Block(), dp_strlcpy, i, CompressedImageCacheItem::imagename, MAX_QPATH, CompressedImageCacheItem::maxsize, strlen(), va(), and Z_Malloc.

Referenced by Image_Compress().

◆ CompressedImageCache_Find()

static CompressedImageCacheItem * CompressedImageCache_Find ( const char * imagename,
size_t maxsize )
static

Definition at line 1030 of file jpeg.c.

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}
#define NULL
Definition qtypes.h:12

References CompressedImageCache, COMPRESSEDIMAGECACHE_SIZE, CRC_Block(), i, CompressedImageCacheItem::imagename, CompressedImageCacheItem::maxsize, NULL, strlen(), and va().

Referenced by Image_Compress().

◆ Image_Compress()

qbool Image_Compress ( const char * imagename,
size_t maxsize,
void ** buf,
size_t * size )

Definition at line 1047 of file jpeg.c.

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
1064 i = CompressedImageCache_Find(imagename, maxsize);
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
1114 CompressedImageCache_Add(imagename, maxsize, *buf, *size);
1115 return (*buf != NULL);
1116}
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
vector size
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
qbool PNG_OpenLibrary(void)
Definition image_png.c:143
static void CompressedImageCache_Add(const char *imagename, size_t maxsize, void *compressed, size_t compressed_size)
Definition jpeg.c:1011
dllhandle_t jpeg_dll
Definition jpeg.c:457
qbool JPEG_OpenLibrary(void)
Definition jpeg.c:492
size_t JPEG_SaveImage_to_Buffer(char *jpegbuf, size_t jpegsize, int width, int height, unsigned char *data)
Definition jpeg.c:931
static CompressedImageCacheItem * CompressedImageCache_Find(const char *imagename, size_t maxsize)
Definition jpeg.c:1030
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_Free(data)
Definition zone.h:164

References buf, CompressedImageCache_Add(), CompressedImageCache_Find(), Con_Print(), Con_Printf(), i, Image_CopyMux(), image_height, Image_MipReduce32(), image_width, CompressedImageCacheItem::imagename, jpeg_dll, JPEG_OpenLibrary(), JPEG_SaveImage_to_Buffer(), loadimagepixelsbgra(), CompressedImageCacheItem::maxsize, Mem_Alloc, Mem_Free, NULL, PNG_OpenLibrary(), size, tempmempool, Z_Free, and Z_Malloc.

Referenced by VM_SV_WritePicture().

◆ JPEG_CloseLibrary()

void JPEG_CloseLibrary ( void )

Definition at line 538 of file jpeg.c.

539{
540#ifndef LINK_TO_LIBJPEG
542 jpeg_tried_loading = false; // allow retry
543#endif
544}
qbool jpeg_tried_loading
Definition jpeg.c:458
void Sys_FreeLibrary(dllhandle_t *handle)
Definition sys_shared.c:245

References jpeg_dll, jpeg_tried_loading, and Sys_FreeLibrary().

Referenced by r_textures_shutdown().

◆ JPEG_EmptyOutputBuffer()

static jboolean JPEG_EmptyOutputBuffer ( j_compress_ptr cinfo)
static

Definition at line 733 of file jpeg.c.

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;
741 dest->pub.free_in_buffer = JPEG_OUTPUT_BUF_SIZE;
742 return true;
743}
fs_offset_t FS_Write(qfile_t *file, const void *data, size_t datasize)
Definition fs.c:3019
#define JPEG_OUTPUT_BUF_SIZE
Definition jpeg.c:724
static jmp_buf error_in_jpeg
Definition jpeg.c:462
my_destination_mgr * my_dest_ptr
Definition jpeg.c:474

References my_destination_mgr::buffer, error_in_jpeg, jpeg_destination_mgr::free_in_buffer, FS_Write(), JPEG_OUTPUT_BUF_SIZE, jpeg_destination_mgr::next_output_byte, my_destination_mgr::outfile, and my_destination_mgr::pub.

Referenced by JPEG_FileDest().

◆ JPEG_ErrorExit()

static void JPEG_ErrorExit ( j_common_ptr cinfo)
static

Definition at line 592 of file jpeg.c.

593{
594 ((struct jpeg_decompress_struct*)cinfo)->err->output_message (cinfo);
595 longjmp(error_in_jpeg, 1);
596}
struct jpeg_error_mgr * err
Definition jpeg.c:224
void(* output_message)(j_common_ptr cinfo)
Definition jpeg.c:128

References j_decompress_ptr::err, error_in_jpeg, and jpeg_error_mgr::output_message.

Referenced by JPEG_LoadImage_BGRA(), JPEG_SaveImage_preflipped(), and JPEG_SaveImage_to_Buffer().

◆ JPEG_FileDest()

static void JPEG_FileDest ( j_compress_ptr cinfo,
qfile_t * outfile )
static

Definition at line 756 of file jpeg.c.

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}
qfile_t * outfile
Definition image_png.c:254
void * j_common_ptr
Definition jpeg.c:72
static jboolean JPEG_EmptyOutputBuffer(j_compress_ptr cinfo)
Definition jpeg.c:733
static void JPEG_InitDestination(j_compress_ptr cinfo)
Definition jpeg.c:725
static void JPEG_TermDestination(j_compress_ptr cinfo)
Definition jpeg.c:745
#define JPOOL_PERMANENT
Definition jpeg.c:91
jboolean(* empty_output_buffer)(j_compress_ptr cinfo)
Definition jpeg.c:399
void(* term_destination)(j_compress_ptr cinfo)
Definition jpeg.c:400
void(* init_destination)(j_compress_ptr cinfo)
Definition jpeg.c:398
qfile_t * outfile
Definition jpeg.c:470
struct jpeg_destination_mgr pub
Definition jpeg.c:468

References jpeg_destination_mgr::empty_output_buffer, jpeg_destination_mgr::init_destination, JPEG_EmptyOutputBuffer(), JPEG_InitDestination(), JPEG_TermDestination(), JPOOL_PERMANENT, NULL, my_destination_mgr::outfile, outfile, my_destination_mgr::pub, and jpeg_destination_mgr::term_destination.

Referenced by JPEG_SaveImage_preflipped().

◆ JPEG_FillInputBuffer()

static jboolean JPEG_FillInputBuffer ( j_decompress_ptr cinfo)
static

Definition at line 557 of file jpeg.c.

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}
static unsigned char jpeg_eoi_marker[2]
Definition jpeg.c:461

References jpeg_eoi_marker.

Referenced by JPEG_MemSrc().

◆ JPEG_InitDestination()

static void JPEG_InitDestination ( j_compress_ptr cinfo)
static

Definition at line 725 of file jpeg.c.

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;
730 dest->pub.free_in_buffer = JPEG_OUTPUT_BUF_SIZE;
731}
#define JPOOL_IMAGE
Definition jpeg.c:92

References my_destination_mgr::buffer, jpeg_destination_mgr::free_in_buffer, JPEG_OUTPUT_BUF_SIZE, JPOOL_IMAGE, jpeg_destination_mgr::next_output_byte, and my_destination_mgr::pub.

Referenced by JPEG_FileDest().

◆ JPEG_LoadImage_BGRA()

unsigned char * JPEG_LoadImage_BGRA ( const unsigned char * f,
int filesize,
int * miplevel )

Definition at line 606 of file jpeg.c.

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);
626 cinfo.err->error_exit = JPEG_ErrorExit;
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
633 image_width = cinfo.output_width;
634 image_height = cinfo.output_height;
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}
static struct jpeg_error_mgr *(* qjpeg_std_error)(struct jpeg_error_mgr *err)
Definition jpeg.c:431
static JDIMENSION(* qjpeg_read_scanlines)(j_decompress_ptr cinfo, unsigned char **scanlines, JDIMENSION max_lines)
Definition jpeg.c:426
static int(* qjpeg_read_header)(j_decompress_ptr cinfo, jboolean require_image)
Definition jpeg.c:425
static void(* qjpeg_destroy_decompress)(j_decompress_ptr cinfo)
Definition jpeg.c:421
cvar_t r_texture_jpeg_fastpicmip
Definition jpeg.c:32
static jboolean(* qjpeg_start_decompress)(j_decompress_ptr cinfo)
Definition jpeg.c:430
static void JPEG_MemSrc(j_decompress_ptr cinfo, const unsigned char *buffer, size_t filesize)
Definition jpeg.c:578
static jboolean(* qjpeg_finish_decompress)(j_decompress_ptr cinfo)
Definition jpeg.c:423
static void JPEG_ErrorExit(j_common_ptr cinfo)
Definition jpeg.c:592
#define qjpeg_create_decompress(cinfo)
Definition jpeg.c:415
#define bound(min, num, max)
Definition mathlib.h:34
float f
int integer
Definition cvar.h:73

References bound, Con_Printf(), j_decompress_ptr::err, jpeg_error_mgr::error_exit, error_in_jpeg, f, image_height, image_width, cvar_t::integer, jpeg_dll, JPEG_ErrorExit(), JPEG_MemSrc(), Mem_Alloc, Mem_Free, NULL, j_decompress_ptr::output_components, j_decompress_ptr::output_height, j_decompress_ptr::output_scanline, j_decompress_ptr::output_width, qjpeg_create_decompress, qjpeg_destroy_decompress, qjpeg_finish_decompress, qjpeg_read_header, qjpeg_read_scanlines, qjpeg_start_decompress, qjpeg_std_error, r_texture_jpeg_fastpicmip, j_decompress_ptr::scale_denom, j_decompress_ptr::scale_num, and tempmempool.

Referenced by decode_image(), loadimagepixelsbgra(), and VM_CL_ReadPicture().

◆ JPEG_Mem_EmptyOutputBuffer()

static jboolean JPEG_Mem_EmptyOutputBuffer ( j_compress_ptr cinfo)
static

Definition at line 778 of file jpeg.c.

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}
static qbool jpeg_toolarge
Definition jpeg.c:463

References my_destination_mgr::buffer, my_destination_mgr::bufsize, jpeg_destination_mgr::free_in_buffer, jpeg_toolarge, jpeg_destination_mgr::next_output_byte, and my_destination_mgr::pub.

Referenced by JPEG_MemDest().

◆ JPEG_Mem_InitDestination()

static void JPEG_Mem_InitDestination ( j_compress_ptr cinfo)
static

Definition at line 771 of file jpeg.c.

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}

References my_destination_mgr::buffer, my_destination_mgr::bufsize, jpeg_destination_mgr::free_in_buffer, jpeg_destination_mgr::next_output_byte, and my_destination_mgr::pub.

Referenced by JPEG_MemDest().

◆ JPEG_Mem_TermDestination()

static void JPEG_Mem_TermDestination ( j_compress_ptr cinfo)
static

Definition at line 787 of file jpeg.c.

788{
789 my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
790 dest->bufsize = dest->pub.next_output_byte - dest->buffer;
791}

References my_destination_mgr::buffer, my_destination_mgr::bufsize, jpeg_destination_mgr::next_output_byte, and my_destination_mgr::pub.

Referenced by JPEG_MemDest().

◆ JPEG_MemDest()

static void JPEG_MemDest ( j_compress_ptr cinfo,
void * buf,
size_t bufsize )
static

Definition at line 792 of file jpeg.c.

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}
static void JPEG_Mem_InitDestination(j_compress_ptr cinfo)
Definition jpeg.c:771
static jboolean JPEG_Mem_EmptyOutputBuffer(j_compress_ptr cinfo)
Definition jpeg.c:778
static void JPEG_Mem_TermDestination(j_compress_ptr cinfo)
Definition jpeg.c:787
size_t bufsize
Definition jpeg.c:472
unsigned char * buffer
Definition jpeg.c:471

References buf, my_destination_mgr::buffer, my_destination_mgr::bufsize, jpeg_destination_mgr::empty_output_buffer, jpeg_destination_mgr::init_destination, JPEG_Mem_EmptyOutputBuffer(), JPEG_Mem_InitDestination(), JPEG_Mem_TermDestination(), JPOOL_PERMANENT, NULL, my_destination_mgr::outfile, my_destination_mgr::pub, and jpeg_destination_mgr::term_destination.

Referenced by JPEG_try_SaveImage_to_Buffer().

◆ JPEG_MemSrc()

static void JPEG_MemSrc ( j_decompress_ptr cinfo,
const unsigned char * buffer,
size_t filesize )
static

Definition at line 578 of file jpeg.c.

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}
GLuint buffer
Definition glquake.h:630
static void JPEG_Noop(j_decompress_ptr cinfo)
Definition jpeg.c:555
static jboolean JPEG_FillInputBuffer(j_decompress_ptr cinfo)
Definition jpeg.c:557
static jboolean(* qjpeg_resync_to_restart)(j_decompress_ptr cinfo, int desired)
Definition jpeg.c:424
static void JPEG_SkipInputData(j_decompress_ptr cinfo, long num_bytes)
Definition jpeg.c:566

References buffer, JPEG_FillInputBuffer(), JPEG_Noop(), JPEG_SkipInputData(), JPOOL_PERMANENT, and qjpeg_resync_to_restart.

Referenced by JPEG_LoadImage_BGRA().

◆ JPEG_Noop()

static void JPEG_Noop ( j_decompress_ptr cinfo)
static

Definition at line 555 of file jpeg.c.

555{}

Referenced by JPEG_MemSrc().

◆ JPEG_OpenLibrary()

qbool JPEG_OpenLibrary ( void )

Definition at line 492 of file jpeg.c.

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}
static dllfunction_t jpegfuncs[]
Definition jpeg.c:435
qbool Sys_LoadDependency(const char **dllnames, dllhandle_t *handle, const dllfunction_t *fcts)
Definition sys_shared.c:131

References Con_Printf(), jpeg_dll, jpeg_tried_loading, jpegfuncs, NULL, and Sys_LoadDependency().

Referenced by Image_Compress(), and r_textures_start().

◆ JPEG_SaveImage_preflipped()

qbool JPEG_SaveImage_preflipped ( const char * filename,
int width,
int height,
unsigned char * data )

Definition at line 818 of file jpeg.c.

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);
841 cinfo.err->error_exit = JPEG_ErrorExit;
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}
cvar_t scr_screenshot_jpeg_quality
Definition cl_screen.c:60
qfile_t * FS_OpenRealFile(const char *filepath, const char *mode, qbool quiet)
Definition fs.c:2901
int FS_Close(qfile_t *file)
Definition fs.c:2970
GLenum GLsizei width
Definition glquake.h:622
GLenum GLsizei GLsizei height
Definition glquake.h:622
GLsizeiptr const GLvoid * data
Definition glquake.h:639
GLuint GLuint GLintptr offset
Definition glquake.h:632
static void(* qjpeg_finish_compress)(j_compress_ptr cinfo)
Definition jpeg.c:422
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(* qjpeg_destroy_compress)(j_compress_ptr cinfo)
Definition jpeg.c:420
static void(* qjpeg_simple_progression)(j_compress_ptr cinfo)
Definition jpeg.c:433
static void(* qjpeg_set_quality)(j_compress_ptr cinfo, int quality, jboolean force_baseline)
Definition jpeg.c:428
static void(* qjpeg_set_defaults)(j_compress_ptr cinfo)
Definition jpeg.c:427
static void JPEG_FileDest(j_compress_ptr cinfo, qfile_t *outfile)
Definition jpeg.c:756
#define qjpeg_create_compress(cinfo)
Definition jpeg.c:413
float value
Definition cvar.h:74

References j_compress_ptr::comp_info, Con_Print(), data, j_compress_ptr::err, jpeg_error_mgr::error_exit, error_in_jpeg, FS_Close(), FS_OpenRealFile(), jpeg_component_info::h_samp_factor, height, j_compress_ptr::image_height, j_compress_ptr::image_width, j_compress_ptr::in_color_space, j_compress_ptr::input_components, JCS_RGB, jpeg_dll, JPEG_ErrorExit(), JPEG_FileDest(), j_compress_ptr::next_scanline, offset, j_compress_ptr::optimize_coding, qjpeg_create_compress, qjpeg_destroy_compress, qjpeg_finish_compress, qjpeg_set_defaults, qjpeg_set_quality, qjpeg_simple_progression, qjpeg_start_compress, qjpeg_std_error, qjpeg_write_scanlines, scr_screenshot_jpeg_quality, jpeg_component_info::v_samp_factor, cvar_t::value, and width.

Referenced by SCR_ScreenShot().

◆ JPEG_SaveImage_to_Buffer()

size_t JPEG_SaveImage_to_Buffer ( char * jpegbuf,
size_t jpegsize,
int width,
int height,
unsigned char * data )
Returns
0 if failed, or the size actually used.

Definition at line 931 of file jpeg.c.

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);
950 cinfo.err->error_exit = JPEG_ErrorExit;
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}
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
Definition console.c:1544
static int(ZEXPORT *qz_inflate)(z_stream *strm
GLint void * img
Definition glquake.h:692
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
cvar_t sv_writepicture_quality
Definition sv_main.c:219

References bound, buf, Con_DPrintf(), Con_Print(), Con_Printf(), data, j_compress_ptr::err, jpeg_error_mgr::error_exit, error_in_jpeg, height, i, img, int(), cvar_t::integer, jpeg_dll, JPEG_ErrorExit(), JPEG_try_SaveImage_to_Buffer(), Mem_Alloc, Mem_Free, qjpeg_create_compress, qjpeg_destroy_compress, qjpeg_std_error, sv_writepicture_quality, tempmempool, and width.

Referenced by Image_Compress().

◆ JPEG_SkipInputData()

static void JPEG_SkipInputData ( j_decompress_ptr cinfo,
long num_bytes )
static

Definition at line 566 of file jpeg.c.

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}

Referenced by JPEG_MemSrc().

◆ JPEG_TermDestination()

static void JPEG_TermDestination ( j_compress_ptr cinfo)
static

Definition at line 745 of file jpeg.c.

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}
int64_t fs_offset_t
Definition fs.h:37

References my_destination_mgr::buffer, error_in_jpeg, jpeg_destination_mgr::free_in_buffer, FS_Write(), JPEG_OUTPUT_BUF_SIZE, my_destination_mgr::outfile, and my_destination_mgr::pub.

Referenced by JPEG_FileDest().

◆ JPEG_try_SaveImage_to_Buffer()

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 )
static

Definition at line 888 of file jpeg.c.

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}
static void JPEG_MemDest(j_compress_ptr cinfo, void *buf, size_t bufsize)
Definition jpeg.c:792
JDIMENSION image_height
Definition jpeg.c:331
JDIMENSION next_scanline
Definition jpeg.c:366
J_COLOR_SPACE in_color_space
Definition jpeg.c:333
JDIMENSION image_width
Definition jpeg.c:330
jboolean optimize_coding
Definition jpeg.c:351
jpeg_component_info * comp_info
Definition jpeg.c:339

References j_compress_ptr::comp_info, data, j_compress_ptr::dest, jpeg_component_info::h_samp_factor, height, j_compress_ptr::image_height, j_compress_ptr::image_width, j_compress_ptr::in_color_space, j_compress_ptr::input_components, JCS_RGB, JPEG_MemDest(), jpeg_toolarge, j_compress_ptr::next_scanline, j_compress_ptr::optimize_coding, qjpeg_finish_compress, qjpeg_set_defaults, qjpeg_set_quality, qjpeg_start_compress, qjpeg_write_scanlines, jpeg_component_info::v_samp_factor, and width.

Referenced by JPEG_SaveImage_to_Buffer().

Variable Documentation

◆ CompressedImageCache

CompressedImageCacheItem* CompressedImageCache[COMPRESSEDIMAGECACHE_SIZE]
static

Definition at line 1009 of file jpeg.c.

Referenced by CompressedImageCache_Add(), and CompressedImageCache_Find().

◆ error_in_jpeg

◆ jpeg_dll

◆ jpeg_eoi_marker

unsigned char jpeg_eoi_marker[2] = {0xFF, JPEG_EOI}
static

Definition at line 461 of file jpeg.c.

461{0xFF, JPEG_EOI};
#define JPEG_EOI
Definition jpeg.c:94

Referenced by JPEG_FillInputBuffer().

◆ jpeg_toolarge

qbool jpeg_toolarge
static

Definition at line 463 of file jpeg.c.

Referenced by JPEG_Mem_EmptyOutputBuffer(), and JPEG_try_SaveImage_to_Buffer().

◆ jpeg_tried_loading

qbool jpeg_tried_loading = 0

Definition at line 458 of file jpeg.c.

Referenced by JPEG_CloseLibrary(), and JPEG_OpenLibrary().

◆ jpegfuncs

dllfunction_t jpegfuncs[]
static
Initial value:
=
{
{"jpeg_CreateCompress", (void **) &qjpeg_CreateCompress},
{"jpeg_CreateDecompress", (void **) &qjpeg_CreateDecompress},
{"jpeg_destroy_compress", (void **) &qjpeg_destroy_compress},
{"jpeg_destroy_decompress", (void **) &qjpeg_destroy_decompress},
{"jpeg_finish_compress", (void **) &qjpeg_finish_compress},
{"jpeg_finish_decompress", (void **) &qjpeg_finish_decompress},
{"jpeg_resync_to_restart", (void **) &qjpeg_resync_to_restart},
{"jpeg_read_header", (void **) &qjpeg_read_header},
{"jpeg_read_scanlines", (void **) &qjpeg_read_scanlines},
{"jpeg_set_defaults", (void **) &qjpeg_set_defaults},
{"jpeg_set_quality", (void **) &qjpeg_set_quality},
{"jpeg_start_compress", (void **) &qjpeg_start_compress},
{"jpeg_start_decompress", (void **) &qjpeg_start_decompress},
{"jpeg_std_error", (void **) &qjpeg_std_error},
{"jpeg_write_scanlines", (void **) &qjpeg_write_scanlines},
{"jpeg_simple_progression", (void **) &qjpeg_simple_progression},
}

Definition at line 435 of file jpeg.c.

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};

Referenced by JPEG_OpenLibrary().

◆ qjpeg_CreateCompress

void(* qjpeg_CreateCompress) (j_compress_ptr cinfo, int version, size_t structsize) ( j_compress_ptr cinfo,
int version,
size_t structsize )
static

Definition at line 418 of file jpeg.c.

◆ qjpeg_CreateDecompress

void(* qjpeg_CreateDecompress) (j_decompress_ptr cinfo, int version, size_t structsize) ( j_decompress_ptr cinfo,
int version,
size_t structsize )
static

Definition at line 419 of file jpeg.c.

◆ qjpeg_destroy_compress

void(* qjpeg_destroy_compress) (j_compress_ptr cinfo) ( j_compress_ptr cinfo)
static

Definition at line 420 of file jpeg.c.

Referenced by JPEG_SaveImage_preflipped(), and JPEG_SaveImage_to_Buffer().

◆ qjpeg_destroy_decompress

void(* qjpeg_destroy_decompress) (j_decompress_ptr cinfo) ( j_decompress_ptr cinfo)
static

Definition at line 421 of file jpeg.c.

Referenced by JPEG_LoadImage_BGRA().

◆ qjpeg_finish_compress

void(* qjpeg_finish_compress) (j_compress_ptr cinfo) ( j_compress_ptr cinfo)
static

Definition at line 422 of file jpeg.c.

Referenced by JPEG_SaveImage_preflipped(), and JPEG_try_SaveImage_to_Buffer().

◆ qjpeg_finish_decompress

jboolean(* qjpeg_finish_decompress) (j_decompress_ptr cinfo) ( j_decompress_ptr cinfo)
static

Definition at line 423 of file jpeg.c.

Referenced by JPEG_LoadImage_BGRA().

◆ qjpeg_read_header

int(* qjpeg_read_header) (j_decompress_ptr cinfo, jboolean require_image) ( j_decompress_ptr cinfo,
jboolean require_image )
static

Definition at line 425 of file jpeg.c.

Referenced by JPEG_LoadImage_BGRA().

◆ qjpeg_read_scanlines

JDIMENSION(* qjpeg_read_scanlines) (j_decompress_ptr cinfo, unsigned char **scanlines, JDIMENSION max_lines) ( j_decompress_ptr cinfo,
unsigned char ** scanlines,
JDIMENSION max_lines )
static

Definition at line 426 of file jpeg.c.

Referenced by JPEG_LoadImage_BGRA().

◆ qjpeg_resync_to_restart

jboolean(* qjpeg_resync_to_restart) (j_decompress_ptr cinfo, int desired) ( j_decompress_ptr cinfo,
int desired )
static

Definition at line 424 of file jpeg.c.

Referenced by JPEG_MemSrc().

◆ qjpeg_set_defaults

void(* qjpeg_set_defaults) (j_compress_ptr cinfo) ( j_compress_ptr cinfo)
static

Definition at line 427 of file jpeg.c.

Referenced by JPEG_SaveImage_preflipped(), and JPEG_try_SaveImage_to_Buffer().

◆ qjpeg_set_quality

void(* qjpeg_set_quality) (j_compress_ptr cinfo, int quality, jboolean force_baseline) ( j_compress_ptr cinfo,
int quality,
jboolean force_baseline )
static

Definition at line 428 of file jpeg.c.

Referenced by JPEG_SaveImage_preflipped(), and JPEG_try_SaveImage_to_Buffer().

◆ qjpeg_simple_progression

void(* qjpeg_simple_progression) (j_compress_ptr cinfo) ( j_compress_ptr cinfo)
static

Definition at line 433 of file jpeg.c.

Referenced by JPEG_SaveImage_preflipped().

◆ qjpeg_start_compress

jboolean(* qjpeg_start_compress) (j_compress_ptr cinfo, jboolean write_all_tables) ( j_compress_ptr cinfo,
jboolean write_all_tables )
static

Definition at line 429 of file jpeg.c.

Referenced by JPEG_SaveImage_preflipped(), and JPEG_try_SaveImage_to_Buffer().

◆ qjpeg_start_decompress

jboolean(* qjpeg_start_decompress) (j_decompress_ptr cinfo) ( j_decompress_ptr cinfo)
static

Definition at line 430 of file jpeg.c.

Referenced by JPEG_LoadImage_BGRA().

◆ qjpeg_std_error

struct jpeg_error_mgr *(* qjpeg_std_error) (struct jpeg_error_mgr *err) ( struct jpeg_error_mgr * err)
static

◆ qjpeg_write_scanlines

JDIMENSION(* qjpeg_write_scanlines) (j_compress_ptr cinfo, unsigned char **scanlines, JDIMENSION num_lines) ( j_compress_ptr cinfo,
unsigned char ** scanlines,
JDIMENSION num_lines )
static

Definition at line 432 of file jpeg.c.

Referenced by JPEG_SaveImage_preflipped(), and JPEG_try_SaveImage_to_Buffer().

◆ r_texture_jpeg_fastpicmip

cvar_t r_texture_jpeg_fastpicmip = {CF_CLIENT | CF_ARCHIVE, "r_texture_jpeg_fastpicmip", "1", "perform gl_picmip during decompression for JPEG files (faster)"}

Definition at line 32 of file jpeg.c.

32{CF_CLIENT | CF_ARCHIVE, "r_texture_jpeg_fastpicmip", "1", "perform gl_picmip during decompression for JPEG files (faster)"};
#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

Referenced by Host_InitLocal(), and JPEG_LoadImage_BGRA().

◆ sv_writepicture_quality

cvar_t sv_writepicture_quality
extern

Definition at line 219 of file sv_main.c.

219{CF_SERVER | CF_ARCHIVE, "sv_writepicture_quality", "10", "WritePicture quality offset (higher means better quality, but slower)"};
#define CF_SERVER
cvar/command that only the server can change/execute
Definition cmd.h:49

Referenced by JPEG_SaveImage_to_Buffer(), and SV_Init().