OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "SkJpegUtility.h" | 9 #include "SkJpegUtility.h" |
10 | 10 |
| 11 #if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_JPEG_NO_INDEX_SUPPORTED) |
| 12 #define SK_JPEG_INDEX_SUPPORTED |
| 13 #endif |
| 14 |
11 ///////////////////////////////////////////////////////////////////// | 15 ///////////////////////////////////////////////////////////////////// |
12 static void sk_init_source(j_decompress_ptr cinfo) { | 16 static void sk_init_source(j_decompress_ptr cinfo) { |
13 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; | 17 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
14 src->next_input_byte = (const JOCTET*)src->fBuffer; | 18 src->next_input_byte = (const JOCTET*)src->fBuffer; |
15 src->bytes_in_buffer = 0; | 19 src->bytes_in_buffer = 0; |
16 #ifdef SK_BUILD_FOR_ANDROID | 20 #ifdef SK_JPEG_INDEX_SUPPORTED |
17 src->current_offset = 0; | 21 src->current_offset = 0; |
18 #endif | 22 #endif |
19 if (!src->fStream->rewind()) { | 23 if (!src->fStream->rewind()) { |
20 SkDebugf("xxxxxxxxxxxxxx failure to rewind\n"); | 24 SkDebugf("xxxxxxxxxxxxxx failure to rewind\n"); |
21 cinfo->err->error_exit((j_common_ptr)cinfo); | 25 cinfo->err->error_exit((j_common_ptr)cinfo); |
22 } | 26 } |
23 } | 27 } |
24 | 28 |
25 #ifdef SK_BUILD_FOR_ANDROID | 29 #ifdef SK_JPEG_INDEX_SUPPORTED |
26 static boolean sk_seek_input_data(j_decompress_ptr cinfo, long byte_offset) { | 30 static boolean sk_seek_input_data(j_decompress_ptr cinfo, long byte_offset) { |
27 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; | 31 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
28 size_t bo = (size_t) byte_offset; | 32 size_t bo = (size_t) byte_offset; |
29 | 33 |
30 if (bo > src->current_offset) { | 34 if (bo > src->current_offset) { |
31 (void)src->fStream->skip(bo - src->current_offset); | 35 (void)src->fStream->skip(bo - src->current_offset); |
32 } else { | 36 } else { |
33 if (!src->fStream->rewind()) { | 37 if (!src->fStream->rewind()) { |
34 SkDebugf("xxxxxxxxxxxxxx failure to rewind\n"); | 38 SkDebugf("xxxxxxxxxxxxxx failure to rewind\n"); |
35 cinfo->err->error_exit((j_common_ptr)cinfo); | 39 cinfo->err->error_exit((j_common_ptr)cinfo); |
(...skipping 14 matching lines...) Expand all Loading... |
50 if (src->fDecoder != nullptr && src->fDecoder->shouldCancelDecode()) { | 54 if (src->fDecoder != nullptr && src->fDecoder->shouldCancelDecode()) { |
51 return FALSE; | 55 return FALSE; |
52 } | 56 } |
53 size_t bytes = src->fStream->read(src->fBuffer, skjpeg_source_mgr::kBufferSi
ze); | 57 size_t bytes = src->fStream->read(src->fBuffer, skjpeg_source_mgr::kBufferSi
ze); |
54 // note that JPEG is happy with less than the full read, | 58 // note that JPEG is happy with less than the full read, |
55 // as long as the result is non-zero | 59 // as long as the result is non-zero |
56 if (bytes == 0) { | 60 if (bytes == 0) { |
57 return FALSE; | 61 return FALSE; |
58 } | 62 } |
59 | 63 |
60 #ifdef SK_BUILD_FOR_ANDROID | 64 #ifdef SK_JPEG_INDEX_SUPPORTED |
61 src->current_offset += bytes; | 65 src->current_offset += bytes; |
62 #endif | 66 #endif |
63 src->next_input_byte = (const JOCTET*)src->fBuffer; | 67 src->next_input_byte = (const JOCTET*)src->fBuffer; |
64 src->bytes_in_buffer = bytes; | 68 src->bytes_in_buffer = bytes; |
65 return TRUE; | 69 return TRUE; |
66 } | 70 } |
67 | 71 |
68 static void sk_skip_input_data(j_decompress_ptr cinfo, long num_bytes) { | 72 static void sk_skip_input_data(j_decompress_ptr cinfo, long num_bytes) { |
69 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; | 73 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
70 | 74 |
71 if (num_bytes > (long)src->bytes_in_buffer) { | 75 if (num_bytes > (long)src->bytes_in_buffer) { |
72 size_t bytesToSkip = num_bytes - src->bytes_in_buffer; | 76 size_t bytesToSkip = num_bytes - src->bytes_in_buffer; |
73 while (bytesToSkip > 0) { | 77 while (bytesToSkip > 0) { |
74 size_t bytes = src->fStream->skip(bytesToSkip); | 78 size_t bytes = src->fStream->skip(bytesToSkip); |
75 if (bytes <= 0 || bytes > bytesToSkip) { | 79 if (bytes <= 0 || bytes > bytesToSkip) { |
76 // SkDebugf("xxxxxxxxxxxxxx failure to skip request %d returned %d\
n", bytesToSkip, bytes); | 80 // SkDebugf("xxxxxxxxxxxxxx failure to skip request %d returned %d\
n", bytesToSkip, bytes); |
77 cinfo->err->error_exit((j_common_ptr)cinfo); | 81 cinfo->err->error_exit((j_common_ptr)cinfo); |
78 return; | 82 return; |
79 } | 83 } |
80 #ifdef SK_BUILD_FOR_ANDROID | 84 #ifdef SK_JPEG_INDEX_SUPPORTED |
81 src->current_offset += bytes; | 85 src->current_offset += bytes; |
82 #endif | 86 #endif |
83 bytesToSkip -= bytes; | 87 bytesToSkip -= bytes; |
84 } | 88 } |
85 src->next_input_byte = (const JOCTET*)src->fBuffer; | 89 src->next_input_byte = (const JOCTET*)src->fBuffer; |
86 src->bytes_in_buffer = 0; | 90 src->bytes_in_buffer = 0; |
87 } else { | 91 } else { |
88 src->next_input_byte += num_bytes; | 92 src->next_input_byte += num_bytes; |
89 src->bytes_in_buffer -= num_bytes; | 93 src->bytes_in_buffer -= num_bytes; |
90 } | 94 } |
91 } | 95 } |
92 | 96 |
93 static void sk_term_source(j_decompress_ptr /*cinfo*/) {} | 97 static void sk_term_source(j_decompress_ptr /*cinfo*/) {} |
94 | 98 |
95 | 99 |
96 /////////////////////////////////////////////////////////////////////////////// | 100 /////////////////////////////////////////////////////////////////////////////// |
97 | 101 |
98 skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder) | 102 skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder) |
99 : fStream(stream) | 103 : fStream(stream) |
100 , fDecoder(decoder) { | 104 , fDecoder(decoder) { |
101 | 105 |
102 init_source = sk_init_source; | 106 init_source = sk_init_source; |
103 fill_input_buffer = sk_fill_input_buffer; | 107 fill_input_buffer = sk_fill_input_buffer; |
104 skip_input_data = sk_skip_input_data; | 108 skip_input_data = sk_skip_input_data; |
105 resync_to_restart = jpeg_resync_to_restart; | 109 resync_to_restart = jpeg_resync_to_restart; |
106 term_source = sk_term_source; | 110 term_source = sk_term_source; |
107 #ifdef SK_BUILD_FOR_ANDROID | 111 #ifdef SK_JPEG_INDEX_SUPPORTED |
108 seek_input_data = sk_seek_input_data; | 112 seek_input_data = sk_seek_input_data; |
109 #endif | 113 #endif |
110 // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBa
seSize); | 114 // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBa
seSize); |
111 } | 115 } |
112 | 116 |
113 /////////////////////////////////////////////////////////////////////////////// | 117 /////////////////////////////////////////////////////////////////////////////// |
114 | 118 |
115 static void sk_init_destination(j_compress_ptr cinfo) { | 119 static void sk_init_destination(j_compress_ptr cinfo) { |
116 skjpeg_destination_mgr* dest = (skjpeg_destination_mgr*)cinfo->dest; | 120 skjpeg_destination_mgr* dest = (skjpeg_destination_mgr*)cinfo->dest; |
117 | 121 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 void skjpeg_error_exit(j_common_ptr cinfo) { | 161 void skjpeg_error_exit(j_common_ptr cinfo) { |
158 skjpeg_error_mgr* error = (skjpeg_error_mgr*)cinfo->err; | 162 skjpeg_error_mgr* error = (skjpeg_error_mgr*)cinfo->err; |
159 | 163 |
160 (*error->output_message) (cinfo); | 164 (*error->output_message) (cinfo); |
161 | 165 |
162 /* Let the memory manager delete any temp files before we die */ | 166 /* Let the memory manager delete any temp files before we die */ |
163 jpeg_destroy(cinfo); | 167 jpeg_destroy(cinfo); |
164 | 168 |
165 longjmp(error->fJmpBuf, -1); | 169 longjmp(error->fJmpBuf, -1); |
166 } | 170 } |
OLD | NEW |