OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 The Android Open Source Project | 3 * Copyright 2010 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkJpegUtility.h" | 10 #include "SkJpegUtility.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 src->bytes_in_buffer = 0; | 22 src->bytes_in_buffer = 0; |
23 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 23 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
24 src->current_offset = 0; | 24 src->current_offset = 0; |
25 #endif | 25 #endif |
26 src->fStream->rewind(); | 26 src->fStream->rewind(); |
27 } | 27 } |
28 | 28 |
29 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 29 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
30 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) { |
31 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; | 31 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
| 32 size_t bo = (size_t) byte_offset; |
32 | 33 |
33 if (byte_offset > src->current_offset) { | 34 if (bo > src->current_offset) { |
34 (void)src->fStream->skip(byte_offset - src->current_offset); | 35 (void)src->fStream->skip(bo - src->current_offset); |
35 } else { | 36 } else { |
36 src->fStream->rewind(); | 37 src->fStream->rewind(); |
37 (void)src->fStream->skip(byte_offset); | 38 (void)src->fStream->skip(bo); |
38 } | 39 } |
39 | 40 |
40 src->current_offset = byte_offset; | 41 src->current_offset = bo; |
41 src->next_input_byte = (const JOCTET*)src->fBuffer; | 42 src->next_input_byte = (const JOCTET*)src->fBuffer; |
42 src->bytes_in_buffer = 0; | 43 src->bytes_in_buffer = 0; |
43 return true; | 44 return true; |
44 } | 45 } |
45 #endif | 46 #endif |
46 | 47 |
47 static boolean sk_fill_input_buffer(j_decompress_ptr cinfo) { | 48 static boolean sk_fill_input_buffer(j_decompress_ptr cinfo) { |
48 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; | 49 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
49 if (src->fDecoder != NULL && src->fDecoder->shouldCancelDecode()) { | 50 if (src->fDecoder != NULL && src->fDecoder->shouldCancelDecode()) { |
50 return FALSE; | 51 return FALSE; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 src->next_input_byte = (const JOCTET*)src->fBuffer; | 103 src->next_input_byte = (const JOCTET*)src->fBuffer; |
103 src->bytes_in_buffer = 0; | 104 src->bytes_in_buffer = 0; |
104 return TRUE; | 105 return TRUE; |
105 } | 106 } |
106 | 107 |
107 static void sk_term_source(j_decompress_ptr /*cinfo*/) {} | 108 static void sk_term_source(j_decompress_ptr /*cinfo*/) {} |
108 | 109 |
109 | 110 |
110 /////////////////////////////////////////////////////////////////////////////// | 111 /////////////////////////////////////////////////////////////////////////////// |
111 | 112 |
112 skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder, | 113 skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder) |
113 bool ownStream) : fStream(stream) { | 114 : fStream(SkRef(stream)) |
114 fDecoder = decoder; | 115 , fDecoder(decoder) { |
115 fMemoryBase = NULL; | |
116 fUnrefStream = ownStream; | |
117 fMemoryBaseSize = 0; | |
118 | 116 |
119 init_source = sk_init_source; | 117 init_source = sk_init_source; |
120 fill_input_buffer = sk_fill_input_buffer; | 118 fill_input_buffer = sk_fill_input_buffer; |
121 skip_input_data = sk_skip_input_data; | 119 skip_input_data = sk_skip_input_data; |
122 resync_to_restart = sk_resync_to_restart; | 120 resync_to_restart = sk_resync_to_restart; |
123 term_source = sk_term_source; | 121 term_source = sk_term_source; |
124 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 122 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
125 seek_input_data = sk_seek_input_data; | 123 seek_input_data = sk_seek_input_data; |
126 #endif | 124 #endif |
127 // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBa
seSize); | 125 // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBa
seSize); |
128 } | 126 } |
129 | 127 |
130 skjpeg_source_mgr::~skjpeg_source_mgr() { | 128 skjpeg_source_mgr::~skjpeg_source_mgr() { |
131 if (fMemoryBase) { | 129 SkSafeUnref(fStream); |
132 sk_free(fMemoryBase); | |
133 } | |
134 if (fUnrefStream) { | |
135 fStream->unref(); | |
136 } | |
137 } | 130 } |
138 | 131 |
139 /////////////////////////////////////////////////////////////////////////////// | 132 /////////////////////////////////////////////////////////////////////////////// |
140 | 133 |
141 static void sk_init_destination(j_compress_ptr cinfo) { | 134 static void sk_init_destination(j_compress_ptr cinfo) { |
142 skjpeg_destination_mgr* dest = (skjpeg_destination_mgr*)cinfo->dest; | 135 skjpeg_destination_mgr* dest = (skjpeg_destination_mgr*)cinfo->dest; |
143 | 136 |
144 dest->next_output_byte = dest->fBuffer; | 137 dest->next_output_byte = dest->fBuffer; |
145 dest->free_in_buffer = skjpeg_destination_mgr::kBufferSize; | 138 dest->free_in_buffer = skjpeg_destination_mgr::kBufferSize; |
146 } | 139 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 void skjpeg_error_exit(j_common_ptr cinfo) { | 176 void skjpeg_error_exit(j_common_ptr cinfo) { |
184 skjpeg_error_mgr* error = (skjpeg_error_mgr*)cinfo->err; | 177 skjpeg_error_mgr* error = (skjpeg_error_mgr*)cinfo->err; |
185 | 178 |
186 (*error->output_message) (cinfo); | 179 (*error->output_message) (cinfo); |
187 | 180 |
188 /* Let the memory manager delete any temp files before we die */ | 181 /* Let the memory manager delete any temp files before we die */ |
189 jpeg_destroy(cinfo); | 182 jpeg_destroy(cinfo); |
190 | 183 |
191 longjmp(error->fJmpBuf, -1); | 184 longjmp(error->fJmpBuf, -1); |
192 } | 185 } |
OLD | NEW |