UFO: Alien Invasion
Loading...
Searching...
No Matches
images.cpp File Reference

Image loading and saving functions. More...

#include "images.h"
#include "shared.h"
#include <jpeglib.h>
#include <png.h>
#include <zlib.h>
#include <jerror.h>
Include dependency graph for images.cpp:

Go to the source code of this file.

Data Structures

struct  bufState_t

Macros

#define TGA_UNMAP_COMP   10
#define TGA_CHANNELS   3

Functions

char const *const * Img_GetImageTypes (void)
void R_WritePNG (qFILE *f, byte *buffer, int width, int height)
void R_WriteCompressedTGA (qFILE *f, const byte *buffer, int width, int height)
void R_WriteJPG (qFILE *f, byte *buffer, int width, int height, int quality)
static bytereadFile (char const *const name, char const *const suffix, size_t &len)
static SDL_Surface * createSurface (int const height, int const width)
static void readMem (png_struct *const png, png_byte *const dst, png_size_t const size)
static SDL_Surface * Img_LoadPNG (char const *const name)
 Loads a PNG image into an SDL_Surface.
static void djpeg_nop (jpeg_decompress_struct *)
static boolean djpeg_fill_input_buffer (jpeg_decompress_struct *const cinfo)
static void djpeg_skip_input_data (jpeg_decompress_struct *const cinfo, long const num_bytes)
static SDL_Surface * Img_LoadJPG (char const *const name)
 Loads a Jpeg image into an SDL_Surface.
SDL_Surface * Img_LoadImage (char const *name)
 Loads the specified image from the game filesystem into an SDL_Surface.

Variables

static char const *const IMAGE_TYPES []

Detailed Description

Image loading and saving functions.

Definition in file images.cpp.

Macro Definition Documentation

◆ TGA_CHANNELS

#define TGA_CHANNELS   3

Definition at line 105 of file images.cpp.

Referenced by R_WriteCompressedTGA().

◆ TGA_UNMAP_COMP

#define TGA_UNMAP_COMP   10

Definition at line 54 of file images.cpp.

Referenced by R_WriteCompressedTGA().

Function Documentation

◆ createSurface()

SDL_Surface * createSurface ( int const height,
int const width )
static

Definition at line 280 of file images.cpp.

Referenced by Img_LoadJPG(), and Img_LoadPNG().

◆ djpeg_fill_input_buffer()

boolean djpeg_fill_input_buffer ( jpeg_decompress_struct *const cinfo)
static

Definition at line 365 of file images.cpp.

Referenced by Img_LoadJPG().

◆ djpeg_nop()

void djpeg_nop ( jpeg_decompress_struct * )
static

Definition at line 363 of file images.cpp.

Referenced by Img_LoadJPG().

◆ djpeg_skip_input_data()

void djpeg_skip_input_data ( jpeg_decompress_struct *const cinfo,
long const num_bytes )
static

Definition at line 371 of file images.cpp.

Referenced by Img_LoadJPG().

◆ Img_GetImageTypes()

char const *const * Img_GetImageTypes ( void )

Definition at line 56 of file images.cpp.

References IMAGE_TYPES.

Referenced by R_ImageExists().

◆ Img_LoadImage()

SDL_Surface * Img_LoadImage ( char const * name)

Loads the specified image from the game filesystem into an SDL_Surface.

Image formats are tried in the order they appear in TYPES.

Note
Make sure to free the given SDL_Surface after you are done with it.

Definition at line 488 of file images.cpp.

References Img_LoadJPG(), Img_LoadPNG(), and name.

Referenced by CalcTextureReflectivity(), R_FindImage(), R_LoadImage(), R_ReloadImageData(), and TEST_F().

◆ Img_LoadJPG()

SDL_Surface * Img_LoadJPG ( char const *const name)
static

Loads a Jpeg image into an SDL_Surface.

Parameters
[in]namePath to the imagefile, relative from gameDir and without extension
Returns
Pointer to the SDL_Surface created, or nullptr on failure

Definition at line 390 of file images.cpp.

References createSurface(), djpeg_fill_input_buffer(), djpeg_nop(), djpeg_skip_input_data(), FS_FreeFile(), len, name, and readFile().

Referenced by Img_LoadImage().

◆ Img_LoadPNG()

SDL_Surface * Img_LoadPNG ( char const *const name)
static

Loads a PNG image into an SDL_Surface.

Parameters
[in]namePath to the imagefile, relative from gameDir and without extension
Returns
Pointer to the SDL_Surface created, or nullptr on failure

Definition at line 313 of file images.cpp.

References createSurface(), FS_FreeFile(), len, name, readFile(), and readMem().

Referenced by Img_LoadImage().

◆ R_WriteCompressedTGA()

void R_WriteCompressedTGA ( qFILE * f,
const byte * buffer,
int width,
int height )
See also
R_LoadTGA
R_WriteTGA

Definition at line 111 of file images.cpp.

References f, FS_Write(), index, OBJZERO, TGA_CHANNELS, and TGA_UNMAP_COMP.

Referenced by R_ScreenShot().

◆ R_WriteJPG()

void R_WriteJPG ( qFILE * f,
byte * buffer,
int width,
int height,
int quality )
See also
R_ScreenShot_f
R_LoadJPG

Definition at line 234 of file images.cpp.

References f.

Referenced by R_ScreenShot().

◆ R_WritePNG()

void R_WritePNG ( qFILE * f,
byte * buffer,
int width,
int height )
See also
R_LoadTGA
R_LoadJPG
R_FindImage

Definition at line 66 of file images.cpp.

References f, and i.

Referenced by R_ScreenShot().

◆ readFile()

byte * readFile ( char const *const name,
char const *const suffix,
size_t & len )
static

Definition at line 271 of file images.cpp.

References FS_LoadFile(), len, MAX_QPATH, and name.

Referenced by Img_LoadJPG(), and Img_LoadPNG().

◆ readMem()

void readMem ( png_struct *const png,
png_byte *const dst,
png_size_t const size )
static

Definition at line 297 of file images.cpp.

References bufState_t::end, and bufState_t::ptr.

Referenced by Img_LoadPNG().

Variable Documentation

◆ IMAGE_TYPES

char const* const IMAGE_TYPES[]
static
Initial value:
= {
"png",
"jpg",
nullptr
}

image formats, tried in this order

Definition at line 45 of file images.cpp.

Referenced by Img_GetImageTypes().