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