Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: src/images/SkJpegUtility.cpp

Issue 12438025: Upstream changes from Android for decoding jpeg images. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 11
12 #if defined(SK_BUILD_FOR_ANDROID) && defined(SK_DEBUG)
13 #define SK_BUILD_FOR_ANDROID_FRAMEWORK
14 #endif
15
12 ///////////////////////////////////////////////////////////////////// 16 /////////////////////////////////////////////////////////////////////
13 static void sk_init_source(j_decompress_ptr cinfo) { 17 static void sk_init_source(j_decompress_ptr cinfo) {
14 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; 18 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
15 src->next_input_byte = (const JOCTET*)src->fBuffer; 19 src->next_input_byte = (const JOCTET*)src->fBuffer;
16 src->bytes_in_buffer = 0; 20 src->bytes_in_buffer = 0;
21 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
22 src->current_offset = 0;
23 #endif
17 src->fStream->rewind(); 24 src->fStream->rewind();
18 } 25 }
19 26
27 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
28 static boolean sk_seek_input_data(j_decompress_ptr cinfo, long byte_offset) {
29 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
30
31 if (byte_offset > src->current_offset) {
32 (void)src->fStream->skip(byte_offset - src->current_offset);
33 } else {
34 src->fStream->rewind();
35 (void)src->fStream->skip(byte_offset);
36 }
37
38 src->current_offset = byte_offset;
39 src->next_input_byte = (const JOCTET*)src->fBuffer;
40 src->bytes_in_buffer = 0;
robertphillips 2013/03/19 13:15:21 true?
djsollen 2013/03/19 15:38:25 Done.
41 return TRUE;
42 }
43 #endif
44
20 static boolean sk_fill_input_buffer(j_decompress_ptr cinfo) { 45 static boolean sk_fill_input_buffer(j_decompress_ptr cinfo) {
21 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; 46 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
22 if (src->fDecoder != NULL && src->fDecoder->shouldCancelDecode()) { 47 if (src->fDecoder != NULL && src->fDecoder->shouldCancelDecode()) {
23 return FALSE; 48 return FALSE;
24 } 49 }
25 size_t bytes = src->fStream->read(src->fBuffer, skjpeg_source_mgr::kBufferSi ze); 50 size_t bytes = src->fStream->read(src->fBuffer, skjpeg_source_mgr::kBufferSi ze);
26 // note that JPEG is happy with less than the full read, 51 // note that JPEG is happy with less than the full read,
27 // as long as the result is non-zero 52 // as long as the result is non-zero
28 if (bytes == 0) { 53 if (bytes == 0) {
29 return FALSE; 54 return FALSE;
30 } 55 }
31 56
57 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
58 src->current_offset += bytes;
59 #endif
32 src->next_input_byte = (const JOCTET*)src->fBuffer; 60 src->next_input_byte = (const JOCTET*)src->fBuffer;
33 src->bytes_in_buffer = bytes; 61 src->bytes_in_buffer = bytes;
34 return TRUE; 62 return TRUE;
35 } 63 }
36 64
37 static void sk_skip_input_data(j_decompress_ptr cinfo, long num_bytes) { 65 static void sk_skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
38 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; 66 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
39 67
40 if (num_bytes > (long)src->bytes_in_buffer) { 68 if (num_bytes > (long)src->bytes_in_buffer) {
41 long bytesToSkip = num_bytes - src->bytes_in_buffer; 69 long bytesToSkip = num_bytes - src->bytes_in_buffer;
42 while (bytesToSkip > 0) { 70 while (bytesToSkip > 0) {
43 long bytes = (long)src->fStream->skip(bytesToSkip); 71 long bytes = (long)src->fStream->skip(bytesToSkip);
44 if (bytes <= 0 || bytes > bytesToSkip) { 72 if (bytes <= 0 || bytes > bytesToSkip) {
45 // SkDebugf("xxxxxxxxxxxxxx failure to skip request %d returned %d\ n", bytesToSkip, bytes); 73 // SkDebugf("xxxxxxxxxxxxxx failure to skip request %d returned %d\ n", bytesToSkip, bytes);
46 cinfo->err->error_exit((j_common_ptr)cinfo); 74 cinfo->err->error_exit((j_common_ptr)cinfo);
47 return; 75 return;
48 } 76 }
77 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
78 src->current_offset += bytes;
79 #endif
49 bytesToSkip -= bytes; 80 bytesToSkip -= bytes;
50 } 81 }
51 src->next_input_byte = (const JOCTET*)src->fBuffer; 82 src->next_input_byte = (const JOCTET*)src->fBuffer;
52 src->bytes_in_buffer = 0; 83 src->bytes_in_buffer = 0;
53 } else { 84 } else {
54 src->next_input_byte += num_bytes; 85 src->next_input_byte += num_bytes;
55 src->bytes_in_buffer -= num_bytes; 86 src->bytes_in_buffer -= num_bytes;
56 } 87 }
57 } 88 }
58 89
59 static boolean sk_resync_to_restart(j_decompress_ptr cinfo, int desired) { 90 static boolean sk_resync_to_restart(j_decompress_ptr cinfo, int desired) {
60 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; 91 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
61 92
62 // what is the desired param for??? 93 // what is the desired param for???
63 94
64 if (!src->fStream->rewind()) { 95 if (!src->fStream->rewind()) {
65 SkDebugf("xxxxxxxxxxxxxx failure to rewind\n"); 96 SkDebugf("xxxxxxxxxxxxxx failure to rewind\n");
66 cinfo->err->error_exit((j_common_ptr)cinfo); 97 cinfo->err->error_exit((j_common_ptr)cinfo);
67 return FALSE; 98 return FALSE;
68 } 99 }
69 src->next_input_byte = (const JOCTET*)src->fBuffer; 100 src->next_input_byte = (const JOCTET*)src->fBuffer;
70 src->bytes_in_buffer = 0; 101 src->bytes_in_buffer = 0;
71 return TRUE; 102 return TRUE;
72 } 103 }
73 104
74 static void sk_term_source(j_decompress_ptr /*cinfo*/) {} 105 static void sk_term_source(j_decompress_ptr /*cinfo*/) {}
75 106
76 107
77 #if 0 // UNUSED
78 static void skmem_init_source(j_decompress_ptr cinfo) {
79 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
80 src->next_input_byte = (const JOCTET*)src->fMemoryBase;
81 src->bytes_in_buffer = src->fMemoryBaseSize;
82 }
83
84 static boolean skmem_fill_input_buffer(j_decompress_ptr cinfo) {
85 SkDebugf("xxxxxxxxxxxxxx skmem_fill_input_buffer called\n");
86 return FALSE;
87 }
88
89 static void skmem_skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
90 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
91 // SkDebugf("xxxxxxxxxxxxxx skmem_skip_input_data called %d\n", num_bytes);
92 src->next_input_byte = (const JOCTET*)((const char*)src->next_input_byte + n um_bytes);
93 src->bytes_in_buffer -= num_bytes;
94 }
95
96 static boolean skmem_resync_to_restart(j_decompress_ptr cinfo, int desired) {
97 SkDebugf("xxxxxxxxxxxxxx skmem_resync_to_restart called\n");
98 return TRUE;
99 }
100
101 static void skmem_term_source(j_decompress_ptr /*cinfo*/) {}
102 #endif
103
104
105 /////////////////////////////////////////////////////////////////////////////// 108 ///////////////////////////////////////////////////////////////////////////////
106 109
107 skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder, 110 skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder,
108 bool ownStream) : fStream(stream) { 111 bool ownStream) : fStream(stream) {
109 fDecoder = decoder; 112 fDecoder = decoder;
110 // const void* baseAddr = stream->getMemoryBase();
111 fMemoryBase = NULL; 113 fMemoryBase = NULL;
112 fUnrefStream = ownStream; 114 fUnrefStream = ownStream;
113 fMemoryBaseSize = 0; 115 fMemoryBaseSize = 0;
114 116
115 init_source = sk_init_source; 117 init_source = sk_init_source;
116 fill_input_buffer = sk_fill_input_buffer; 118 fill_input_buffer = sk_fill_input_buffer;
117 skip_input_data = sk_skip_input_data; 119 skip_input_data = sk_skip_input_data;
118 resync_to_restart = sk_resync_to_restart; 120 resync_to_restart = sk_resync_to_restart;
119 term_source = sk_term_source; 121 term_source = sk_term_source;
122 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
123 seek_input_data = sk_seek_input_data;
124 #endif
120 // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBa seSize); 125 // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBa seSize);
121 } 126 }
122 127
123 skjpeg_source_mgr::~skjpeg_source_mgr() { 128 skjpeg_source_mgr::~skjpeg_source_mgr() {
124 if (fMemoryBase) { 129 if (fMemoryBase) {
125 sk_free(fMemoryBase); 130 sk_free(fMemoryBase);
126 } 131 }
127 if (fUnrefStream) { 132 if (fUnrefStream) {
128 fStream->unref(); 133 fStream->unref();
129 } 134 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void skjpeg_error_exit(j_common_ptr cinfo) { 181 void skjpeg_error_exit(j_common_ptr cinfo) {
177 skjpeg_error_mgr* error = (skjpeg_error_mgr*)cinfo->err; 182 skjpeg_error_mgr* error = (skjpeg_error_mgr*)cinfo->err;
178 183
179 (*error->output_message) (cinfo); 184 (*error->output_message) (cinfo);
180 185
181 /* Let the memory manager delete any temp files before we die */ 186 /* Let the memory manager delete any temp files before we die */
182 jpeg_destroy(cinfo); 187 jpeg_destroy(cinfo);
183 188
184 longjmp(error->fJmpBuf, -1); 189 longjmp(error->fJmpBuf, -1);
185 } 190 }
OLDNEW
« src/images/SkImageDecoder_libjpeg.cpp ('K') | « src/images/SkJpegUtility.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698