RetroArch
Classes | Macros | Typedefs | Enumerations | Functions | Variables
rjpeg.c File Reference
#include <stdint.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <retro_assert.h>
#include <retro_inline.h>
#include <boolean.h>
#include <formats/image.h>
#include <formats/rjpeg.h>
#include <features/features_cpu.h>
Include dependency graph for rjpeg.c:

Classes

struct  rjpeg__resample
 
struct  rjpeg
 
struct  rjpeg__context
 
struct  rjpeg__huffman
 
struct  rjpeg__jpeg
 

Macros

#define rjpeg_lrot(x, y)   (((x) << (y)) | ((x) >> (32 - (y))))
 
#define RJPEG_SIMD_ALIGN(type, name)   type name
 
#define RJPEG__AT_EOF(s)   ((s)->img_buffer >= (s)->img_buffer_end)
 
#define RJPEG__GET16BE(s)   ((rjpeg__get8((s)) << 8) + rjpeg__get8((s)))
 
#define RJPEG__BYTECAST(x)   ((uint8_t) ((x) & 255)) /* truncate int to byte without warnings */
 
#define FAST_BITS   9 /* larger handles more cases; smaller stomps less cache */
 
#define rjpeg__f2f(x)   ((int) (((x) * 4096 + 0.5)))
 
#define rjpeg__fsh(x)   ((x) << 12)
 
#define RJPEG__MARKER_NONE   0xff
 
#define RJPEG__RESTART(x)   ((x) >= 0xd0 && (x) <= 0xd7)
 
#define JPEG_MARKER   0xFF
 
#define JPEG_MARKER_SOI   0xD8
 
#define JPEG_MARKER_SOS   0xDA
 
#define JPEG_MARKER_EOI   0xD9
 
#define JPEG_MARKER_APP1   0xE1
 
#define JPEG_MARKER_APP2   0xE2
 
#define rjpeg__SOF(x)   ((x) == 0xc0 || (x) == 0xc1 || (x) == 0xc2)
 
#define rjpeg__SOF_progressive(x)   ((x) == 0xc2)
 
#define rjpeg__div4(x)   ((uint8_t) ((x) >> 2))
 
#define rjpeg__div16(x)   ((uint8_t) ((x) >> 4))
 
#define RJPEG__IDCT_1D(s0, s1, s2, s3, s4, s5, s6, s7)
 
#define float2fixed(x)   (((int) ((x) * 4096.0f + 0.5f)) << 8)
 

Typedefs

typedef uint8_t *(* rjpeg_resample_row_func) (uint8_t *out, uint8_t *in0, uint8_t *in1, int w, int hs)
 

Enumerations

enum  {
  RJPEG_DEFAULT = 0, RJPEG_GREY, RJPEG_GREY_ALPHA, RJPEG_RGB,
  RJPEG_RGB_ALPHA
}
 
enum  { RJPEG_SCAN_LOAD = 0, RJPEG_SCAN_TYPE, RJPEG_SCAN_HEADER }
 

Functions

static INLINE uint8_t rjpeg__get8 (rjpeg__context *s)
 
static int rjpeg__build_huffman (rjpeg__huffman *h, int *count)
 
static void rjpeg__build_fast_ac (int16_t *fast_ac, rjpeg__huffman *h)
 
static void rjpeg__grow_buffer_unsafe (rjpeg__jpeg *j)
 
static INLINE int rjpeg__jpeg_huff_decode (rjpeg__jpeg *j, rjpeg__huffman *h)
 
static INLINE int rjpeg__extend_receive (rjpeg__jpeg *j, int n)
 
static INLINE int rjpeg__jpeg_get_bits (rjpeg__jpeg *j, int n)
 
static INLINE int rjpeg__jpeg_get_bit (rjpeg__jpeg *j)
 
static int rjpeg__jpeg_decode_block (rjpeg__jpeg *j, short data[64], rjpeg__huffman *hdc, rjpeg__huffman *hac, int16_t *fac, int b, uint8_t *dequant)
 
static int rjpeg__jpeg_decode_block_prog_dc (rjpeg__jpeg *j, short data[64], rjpeg__huffman *hdc, int b)
 
static int rjpeg__jpeg_decode_block_prog_ac (rjpeg__jpeg *j, short data[64], rjpeg__huffman *hac, int16_t *fac)
 
static INLINE uint8_t rjpeg__clamp (int x)
 
static void rjpeg__idct_block (uint8_t *out, int out_stride, short data[64])
 
static uint8_t rjpeg__get_marker (rjpeg__jpeg *j)
 
static void rjpeg__jpeg_reset (rjpeg__jpeg *j)
 
static int rjpeg__parse_entropy_coded_data (rjpeg__jpeg *z)
 
static void rjpeg__jpeg_dequantize (short *data, uint8_t *dequant)
 
static void rjpeg__jpeg_finish (rjpeg__jpeg *z)
 
static int rjpeg__process_marker (rjpeg__jpeg *z, int m)
 
static int rjpeg__process_scan_header (rjpeg__jpeg *z)
 
static int rjpeg__process_frame_header (rjpeg__jpeg *z, int scan)
 
static int rjpeg__decode_jpeg_header (rjpeg__jpeg *z, int scan)
 
static int rjpeg__decode_jpeg_image (rjpeg__jpeg *j)
 
static uint8_trjpeg_resample_row_1 (uint8_t *out, uint8_t *in_near, uint8_t *in_far, int w, int hs)
 
static uint8_trjpeg__resample_row_v_2 (uint8_t *out, uint8_t *in_near, uint8_t *in_far, int w, int hs)
 
static uint8_trjpeg__resample_row_h_2 (uint8_t *out, uint8_t *in_near, uint8_t *in_far, int w, int hs)
 
static uint8_trjpeg__resample_row_hv_2 (uint8_t *out, uint8_t *in_near, uint8_t *in_far, int w, int hs)
 
static uint8_trjpeg__resample_row_generic (uint8_t *out, uint8_t *in_near, uint8_t *in_far, int w, int hs)
 
static void rjpeg__YCbCr_to_RGB_row (uint8_t *out, const uint8_t *y, const uint8_t *pcb, const uint8_t *pcr, int count, int step)
 
static void rjpeg__setup_jpeg (rjpeg__jpeg *j)
 
static void rjpeg__cleanup_jpeg (rjpeg__jpeg *j)
 
static uint8_trjpeg_load_jpeg_image (rjpeg__jpeg *z, unsigned *out_x, unsigned *out_y, int *comp, int req_comp)
 
static uint8_trjpeg_load_from_memory (const uint8_t *buffer, int len, unsigned *x, unsigned *y, int *comp, int req_comp)
 
int rjpeg_process_image (rjpeg_t *rjpeg, void **buf_data, size_t size, unsigned *width, unsigned *height)
 
bool rjpeg_set_buf_ptr (rjpeg_t *rjpeg, void *data)
 
void rjpeg_free (rjpeg_t *rjpeg)
 
rjpeg_trjpeg_alloc (void)
 

Variables

static uint32_t rjpeg__bmask [17] ={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535}
 
static int const rjpeg__jbias [16] = {0,-1,-3,-7,-15,-31,-63,-127,-255,-511,-1023,-2047,-4095,-8191,-16383,-32767}
 
static uint8_t rjpeg__jpeg_dezigzag [64+15]
 

Macro Definition Documentation

◆ FAST_BITS

#define FAST_BITS   9 /* larger handles more cases; smaller stomps less cache */

◆ float2fixed

#define float2fixed (   x)    (((int) ((x) * 4096.0f + 0.5f)) << 8)

◆ JPEG_MARKER

#define JPEG_MARKER   0xFF

◆ JPEG_MARKER_APP1

#define JPEG_MARKER_APP1   0xE1

◆ JPEG_MARKER_APP2

#define JPEG_MARKER_APP2   0xE2

◆ JPEG_MARKER_EOI

#define JPEG_MARKER_EOI   0xD9

◆ JPEG_MARKER_SOI

#define JPEG_MARKER_SOI   0xD8

◆ JPEG_MARKER_SOS

#define JPEG_MARKER_SOS   0xDA

◆ RJPEG__AT_EOF

#define RJPEG__AT_EOF (   s)    ((s)->img_buffer >= (s)->img_buffer_end)

◆ RJPEG__BYTECAST

#define RJPEG__BYTECAST (   x)    ((uint8_t) ((x) & 255)) /* truncate int to byte without warnings */

◆ rjpeg__div16

#define rjpeg__div16 (   x)    ((uint8_t) ((x) >> 4))

◆ rjpeg__div4

#define rjpeg__div4 (   x)    ((uint8_t) ((x) >> 2))

◆ rjpeg__f2f

#define rjpeg__f2f (   x)    ((int) (((x) * 4096 + 0.5)))

◆ rjpeg__fsh

#define rjpeg__fsh (   x)    ((x) << 12)

◆ RJPEG__GET16BE

#define RJPEG__GET16BE (   s)    ((rjpeg__get8((s)) << 8) + rjpeg__get8((s)))

◆ RJPEG__IDCT_1D

#define RJPEG__IDCT_1D (   s0,
  s1,
  s2,
  s3,
  s4,
  s5,
  s6,
  s7 
)

◆ RJPEG__MARKER_NONE

#define RJPEG__MARKER_NONE   0xff

◆ RJPEG__RESTART

#define RJPEG__RESTART (   x)    ((x) >= 0xd0 && (x) <= 0xd7)

◆ rjpeg__SOF

#define rjpeg__SOF (   x)    ((x) == 0xc0 || (x) == 0xc1 || (x) == 0xc2)

◆ rjpeg__SOF_progressive

#define rjpeg__SOF_progressive (   x)    ((x) == 0xc2)

◆ rjpeg_lrot

#define rjpeg_lrot (   x,
  y 
)    (((x) << (y)) | ((x) >> (32 - (y))))

◆ RJPEG_SIMD_ALIGN

#define RJPEG_SIMD_ALIGN (   type,
  name 
)    type name

Typedef Documentation

◆ rjpeg_resample_row_func

typedef uint8_t*(* rjpeg_resample_row_func) (uint8_t *out, uint8_t *in0, uint8_t *in1, int w, int hs)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RJPEG_DEFAULT 
RJPEG_GREY 
RJPEG_GREY_ALPHA 
RJPEG_RGB 
RJPEG_RGB_ALPHA 

◆ anonymous enum

anonymous enum
Enumerator
RJPEG_SCAN_LOAD 
RJPEG_SCAN_TYPE 
RJPEG_SCAN_HEADER 

Function Documentation

◆ rjpeg__build_fast_ac()

static void rjpeg__build_fast_ac ( int16_t fast_ac,
rjpeg__huffman h 
)
static
Here is the caller graph for this function:

◆ rjpeg__build_huffman()

static int rjpeg__build_huffman ( rjpeg__huffman h,
int *  count 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__clamp()

static INLINE uint8_t rjpeg__clamp ( int  x)
static
Here is the caller graph for this function:

◆ rjpeg__cleanup_jpeg()

static void rjpeg__cleanup_jpeg ( rjpeg__jpeg j)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__decode_jpeg_header()

static int rjpeg__decode_jpeg_header ( rjpeg__jpeg z,
int  scan 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__decode_jpeg_image()

static int rjpeg__decode_jpeg_image ( rjpeg__jpeg j)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__extend_receive()

static INLINE int rjpeg__extend_receive ( rjpeg__jpeg j,
int  n 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__get8()

static INLINE uint8_t rjpeg__get8 ( rjpeg__context s)
static
Here is the caller graph for this function:

◆ rjpeg__get_marker()

static uint8_t rjpeg__get_marker ( rjpeg__jpeg j)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__grow_buffer_unsafe()

static void rjpeg__grow_buffer_unsafe ( rjpeg__jpeg j)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__idct_block()

static void rjpeg__idct_block ( uint8_t out,
int  out_stride,
short  data[64] 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__jpeg_decode_block()

static int rjpeg__jpeg_decode_block ( rjpeg__jpeg j,
short  data[64],
rjpeg__huffman hdc,
rjpeg__huffman hac,
int16_t fac,
int  b,
uint8_t dequant 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__jpeg_decode_block_prog_ac()

static int rjpeg__jpeg_decode_block_prog_ac ( rjpeg__jpeg j,
short  data[64],
rjpeg__huffman hac,
int16_t fac 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__jpeg_decode_block_prog_dc()

static int rjpeg__jpeg_decode_block_prog_dc ( rjpeg__jpeg j,
short  data[64],
rjpeg__huffman hdc,
int  b 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__jpeg_dequantize()

static void rjpeg__jpeg_dequantize ( short *  data,
uint8_t dequant 
)
static
Here is the caller graph for this function:

◆ rjpeg__jpeg_finish()

static void rjpeg__jpeg_finish ( rjpeg__jpeg z)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__jpeg_get_bit()

static INLINE int rjpeg__jpeg_get_bit ( rjpeg__jpeg j)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__jpeg_get_bits()

static INLINE int rjpeg__jpeg_get_bits ( rjpeg__jpeg j,
int  n 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__jpeg_huff_decode()

static INLINE int rjpeg__jpeg_huff_decode ( rjpeg__jpeg j,
rjpeg__huffman h 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__jpeg_reset()

static void rjpeg__jpeg_reset ( rjpeg__jpeg j)
static
Here is the caller graph for this function:

◆ rjpeg__parse_entropy_coded_data()

static int rjpeg__parse_entropy_coded_data ( rjpeg__jpeg z)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__process_frame_header()

static int rjpeg__process_frame_header ( rjpeg__jpeg z,
int  scan 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__process_marker()

static int rjpeg__process_marker ( rjpeg__jpeg z,
int  m 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__process_scan_header()

static int rjpeg__process_scan_header ( rjpeg__jpeg z)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__resample_row_generic()

static uint8_t* rjpeg__resample_row_generic ( uint8_t out,
uint8_t in_near,
uint8_t in_far,
int  w,
int  hs 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__resample_row_h_2()

static uint8_t* rjpeg__resample_row_h_2 ( uint8_t out,
uint8_t in_near,
uint8_t in_far,
int  w,
int  hs 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__resample_row_hv_2()

static uint8_t* rjpeg__resample_row_hv_2 ( uint8_t out,
uint8_t in_near,
uint8_t in_far,
int  w,
int  hs 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__resample_row_v_2()

static uint8_t* rjpeg__resample_row_v_2 ( uint8_t out,
uint8_t in_near,
uint8_t in_far,
int  w,
int  hs 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__setup_jpeg()

static void rjpeg__setup_jpeg ( rjpeg__jpeg j)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg__YCbCr_to_RGB_row()

static void rjpeg__YCbCr_to_RGB_row ( uint8_t out,
const uint8_t y,
const uint8_t pcb,
const uint8_t pcr,
int  count,
int  step 
)
static
Here is the caller graph for this function:

◆ rjpeg_alloc()

rjpeg_t* rjpeg_alloc ( void  )
Here is the caller graph for this function:

◆ rjpeg_free()

void rjpeg_free ( rjpeg_t rjpeg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg_load_from_memory()

static uint8_t* rjpeg_load_from_memory ( const uint8_t buffer,
int  len,
unsigned *  x,
unsigned *  y,
int *  comp,
int  req_comp 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg_load_jpeg_image()

static uint8_t* rjpeg_load_jpeg_image ( rjpeg__jpeg z,
unsigned *  out_x,
unsigned *  out_y,
int *  comp,
int  req_comp 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg_process_image()

int rjpeg_process_image ( rjpeg_t rjpeg,
void **  buf_data,
size_t  size,
unsigned *  width,
unsigned *  height 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg_resample_row_1()

static uint8_t* rjpeg_resample_row_1 ( uint8_t out,
uint8_t in_near,
uint8_t in_far,
int  w,
int  hs 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rjpeg_set_buf_ptr()

bool rjpeg_set_buf_ptr ( rjpeg_t rjpeg,
void data 
)
Here is the caller graph for this function:

Variable Documentation

◆ rjpeg__bmask

uint32_t rjpeg__bmask[17] ={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535}
static

◆ rjpeg__jbias

int const rjpeg__jbias[16] = {0,-1,-3,-7,-15,-31,-63,-127,-255,-511,-1023,-2047,-4095,-8191,-16383,-32767}
static

◆ rjpeg__jpeg_dezigzag

uint8_t rjpeg__jpeg_dezigzag[64+15]
static
Initial value:
=
{
0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36,
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
53, 60, 61, 54, 47, 55, 62, 63,
63, 63, 63, 63, 63, 63, 63, 63,
63, 63, 63, 63, 63, 63, 63
}