Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkJPEGWriteUtility.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2010 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
10
13
14#include <csetjmp>
15#include <cstddef>
16
17extern "C" {
18 #include "jerror.h" // NO_G3_REWRITE
19 #include "jpeglib.h" // NO_G3_REWRITE
20}
21
22///////////////////////////////////////////////////////////////////////////////
23
24static void sk_init_destination(j_compress_ptr cinfo) {
26
27 dest->next_output_byte = dest->fBuffer;
28 dest->free_in_buffer = skjpeg_destination_mgr::kBufferSize;
29}
30
31static boolean sk_empty_output_buffer(j_compress_ptr cinfo) {
33
34// if (!dest->fStream->write(dest->fBuffer, skjpeg_destination_mgr::kBufferSize - dest->free_in_buffer))
35 if (!dest->fStream->write(dest->fBuffer,
37 ERREXIT(cinfo, JERR_FILE_WRITE);
38 return FALSE;
39 }
40
41 dest->next_output_byte = dest->fBuffer;
42 dest->free_in_buffer = skjpeg_destination_mgr::kBufferSize;
43 return TRUE;
44}
45
46static void sk_term_destination (j_compress_ptr cinfo) {
48
49 size_t size = skjpeg_destination_mgr::kBufferSize - dest->free_in_buffer;
50 if (size > 0) {
51 if (!dest->fStream->write(dest->fBuffer, size)) {
52 ERREXIT(cinfo, JERR_FILE_WRITE);
53 return;
54 }
55 }
56
57 dest->fStream->flush();
58}
59
61 this->init_destination = sk_init_destination;
62 this->empty_output_buffer = sk_empty_output_buffer;
63 this->term_destination = sk_term_destination;
64}
65
66void skjpeg_error_exit(j_common_ptr cinfo) {
68
69 (*error->output_message) (cinfo);
70
71 /* Let the memory manager delete any temp files before we die */
72 jpeg_destroy(cinfo);
73
74 if (error->fStack[0] == nullptr) {
75 SK_ABORT("JPEG error with no jmp_buf set.");
76 }
77 longjmp(*error->fStack[0], -1);
78}
#define SK_ABORT(message,...)
Definition SkAssert.h:70
void skjpeg_error_exit(j_common_ptr cinfo)
static void sk_term_destination(j_compress_ptr cinfo)
static boolean sk_empty_output_buffer(j_compress_ptr cinfo)
static void sk_init_destination(j_compress_ptr cinfo)
const uint8_t uint32_t uint32_t GError ** error
return FALSE
skjpeg_destination_mgr(SkWStream *stream)