Flutter Engine
The Flutter Engine
Functions
SkJpegUtility.cpp File Reference
#include "src/codec/SkJpegUtility.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypes.h"
#include "src/codec/SkCodecPriv.h"
#include "src/codec/SkJpegPriv.h"
#include <csetjmp>
#include <cstddef>
#include "jpeglib.h"

Go to the source code of this file.

Functions

void skjpeg_err_exit (j_common_ptr dinfo)
 
static void sk_init_buffered_source (j_decompress_ptr dinfo)
 
static boolean sk_fill_buffered_input_buffer (j_decompress_ptr dinfo)
 
static void sk_skip_buffered_input_data (j_decompress_ptr dinfo, long numBytes)
 
static void sk_term_source (j_decompress_ptr dinfo)
 
static void sk_init_mem_source (j_decompress_ptr dinfo)
 
static void sk_skip_mem_input_data (j_decompress_ptr cinfo, long num_bytes)
 
static boolean sk_fill_mem_input_buffer (j_decompress_ptr cinfo)
 

Function Documentation

◆ sk_fill_buffered_input_buffer()

static boolean sk_fill_buffered_input_buffer ( j_decompress_ptr  dinfo)
static

Definition at line 50 of file SkJpegUtility.cpp.

50 {
52 size_t bytes = src->fStream->read(src->fBuffer, skjpeg_source_mgr::kBufferSize);
53
54 // libjpeg is still happy with a less than full read, as long as the result is non-zero
55 if (bytes == 0) {
56 // Let libjpeg know that the buffer needs to be refilled
57 src->next_input_byte = nullptr;
58 src->bytes_in_buffer = 0;
59 return false;
60 }
61
62 src->next_input_byte = (const JOCTET*) src->fBuffer;
63 src->bytes_in_buffer = bytes;
64 return true;
65}

◆ sk_fill_mem_input_buffer()

static boolean sk_fill_mem_input_buffer ( j_decompress_ptr  cinfo)
static

Definition at line 122 of file SkJpegUtility.cpp.

122 {
123 /* The whole JPEG data is expected to reside in the supplied memory,
124 * buffer, so any request for more data beyond the given buffer size
125 * is treated as an error.
126 */
127 return false;
128}

◆ sk_init_buffered_source()

static void sk_init_buffered_source ( j_decompress_ptr  dinfo)
static

Definition at line 41 of file SkJpegUtility.cpp.

41 {
43 src->next_input_byte = (const JOCTET*) src->fBuffer;
44 src->bytes_in_buffer = 0;
45}

◆ sk_init_mem_source()

static void sk_init_mem_source ( j_decompress_ptr  dinfo)
static

Definition at line 106 of file SkJpegUtility.cpp.

106 {
107 /* no work necessary here, all things are done in constructor */
108}

◆ sk_skip_buffered_input_data()

static void sk_skip_buffered_input_data ( j_decompress_ptr  dinfo,
long  numBytes 
)
static

Definition at line 70 of file SkJpegUtility.cpp.

70 {
72 size_t bytes = (size_t) numBytes;
73
74 if (bytes > src->bytes_in_buffer) {
75 size_t bytesToSkip = bytes - src->bytes_in_buffer;
76 if (bytesToSkip != src->fStream->skip(bytesToSkip)) {
77 SkCodecPrintf("Failure to skip.\n");
78 dinfo->err->error_exit((j_common_ptr) dinfo);
79 return;
80 }
81
82 src->next_input_byte = (const JOCTET*) src->fBuffer;
83 src->bytes_in_buffer = 0;
84 } else {
85 src->next_input_byte += numBytes;
86 src->bytes_in_buffer -= numBytes;
87 }
88}
#define SkCodecPrintf(...)
Definition: SkCodecPriv.h:23

◆ sk_skip_mem_input_data()

static void sk_skip_mem_input_data ( j_decompress_ptr  cinfo,
long  num_bytes 
)
static

Definition at line 110 of file SkJpegUtility.cpp.

110 {
111 jpeg_source_mgr* src = cinfo->src;
112 size_t bytes = static_cast<size_t>(num_bytes);
113 if(bytes > src->bytes_in_buffer) {
114 src->next_input_byte = nullptr;
115 src->bytes_in_buffer = 0;
116 } else {
117 src->next_input_byte += bytes;
118 src->bytes_in_buffer -= bytes;
119 }
120}

◆ sk_term_source()

static void sk_term_source ( j_decompress_ptr  dinfo)
static

Definition at line 93 of file SkJpegUtility.cpp.

94{
95 // The current implementation of SkJpegCodec does not call
96 // jpeg_finish_decompress(), so this function is never called.
97 // If we want to modify this function to do something, we also
98 // need to modify SkJpegCodec to call jpeg_finish_decompress().
99}

◆ skjpeg_err_exit()

void skjpeg_err_exit ( j_common_ptr  dinfo)

Definition at line 25 of file SkJpegUtility.cpp.

25 {
26 // Simply return to Skia client code
27 // JpegDecoderMgr will take care of freeing memory
28 skjpeg_error_mgr* error = static_cast<skjpeg_error_mgr*>(dinfo->err);
29 (*error->output_message)(dinfo);
30 if (error->fStack[0] == nullptr) {
31 SK_ABORT("JPEG error with no jmp_buf set.");
32 }
33 longjmp(*error->fStack[0], 1);
34}
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
const uint8_t uint32_t uint32_t GError ** error