| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 | 8 |
| 10 #include "SkJpegUtility.h" | 9 #include "SkJpegUtility.h" |
| 11 | 10 |
| 12 // Uncomment to enable the code path used by the Android framework with their | |
| 13 // custom image decoders. | |
| 14 //#if defined(SK_BUILD_FOR_ANDROID) && defined(SK_DEBUG) | |
| 15 // #define SK_BUILD_FOR_ANDROID_FRAMEWORK | |
| 16 //#endif | |
| 17 | |
| 18 ///////////////////////////////////////////////////////////////////// | 11 ///////////////////////////////////////////////////////////////////// |
| 19 static void sk_init_source(j_decompress_ptr cinfo) { | 12 static void sk_init_source(j_decompress_ptr cinfo) { |
| 20 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; | 13 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
| 21 src->next_input_byte = (const JOCTET*)src->fBuffer; | 14 src->next_input_byte = (const JOCTET*)src->fBuffer; |
| 22 src->bytes_in_buffer = 0; | 15 src->bytes_in_buffer = 0; |
| 23 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 16 #ifdef SK_BUILD_FOR_ANDROID |
| 24 src->current_offset = 0; | 17 src->current_offset = 0; |
| 25 #endif | 18 #endif |
| 26 src->fStream->rewind(); | 19 src->fStream->rewind(); |
| 27 } | 20 } |
| 28 | 21 |
| 29 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 22 #ifdef SK_BUILD_FOR_ANDROID |
| 30 static boolean sk_seek_input_data(j_decompress_ptr cinfo, long byte_offset) { | 23 static boolean sk_seek_input_data(j_decompress_ptr cinfo, long byte_offset) { |
| 31 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; | 24 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
| 32 size_t bo = (size_t) byte_offset; | 25 size_t bo = (size_t) byte_offset; |
| 33 | 26 |
| 34 if (bo > src->current_offset) { | 27 if (bo > src->current_offset) { |
| 35 (void)src->fStream->skip(bo - src->current_offset); | 28 (void)src->fStream->skip(bo - src->current_offset); |
| 36 } else { | 29 } else { |
| 37 src->fStream->rewind(); | 30 src->fStream->rewind(); |
| 38 (void)src->fStream->skip(bo); | 31 (void)src->fStream->skip(bo); |
| 39 } | 32 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 if (src->fDecoder != NULL && src->fDecoder->shouldCancelDecode()) { | 43 if (src->fDecoder != NULL && src->fDecoder->shouldCancelDecode()) { |
| 51 return FALSE; | 44 return FALSE; |
| 52 } | 45 } |
| 53 size_t bytes = src->fStream->read(src->fBuffer, skjpeg_source_mgr::kBufferSi
ze); | 46 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, | 47 // note that JPEG is happy with less than the full read, |
| 55 // as long as the result is non-zero | 48 // as long as the result is non-zero |
| 56 if (bytes == 0) { | 49 if (bytes == 0) { |
| 57 return FALSE; | 50 return FALSE; |
| 58 } | 51 } |
| 59 | 52 |
| 60 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 53 #ifdef SK_BUILD_FOR_ANDROID |
| 61 src->current_offset += bytes; | 54 src->current_offset += bytes; |
| 62 #endif | 55 #endif |
| 63 src->next_input_byte = (const JOCTET*)src->fBuffer; | 56 src->next_input_byte = (const JOCTET*)src->fBuffer; |
| 64 src->bytes_in_buffer = bytes; | 57 src->bytes_in_buffer = bytes; |
| 65 return TRUE; | 58 return TRUE; |
| 66 } | 59 } |
| 67 | 60 |
| 68 static void sk_skip_input_data(j_decompress_ptr cinfo, long num_bytes) { | 61 static void sk_skip_input_data(j_decompress_ptr cinfo, long num_bytes) { |
| 69 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; | 62 skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
| 70 | 63 |
| 71 if (num_bytes > (long)src->bytes_in_buffer) { | 64 if (num_bytes > (long)src->bytes_in_buffer) { |
| 72 long bytesToSkip = num_bytes - src->bytes_in_buffer; | 65 long bytesToSkip = num_bytes - src->bytes_in_buffer; |
| 73 while (bytesToSkip > 0) { | 66 while (bytesToSkip > 0) { |
| 74 long bytes = (long)src->fStream->skip(bytesToSkip); | 67 long bytes = (long)src->fStream->skip(bytesToSkip); |
| 75 if (bytes <= 0 || bytes > bytesToSkip) { | 68 if (bytes <= 0 || bytes > bytesToSkip) { |
| 76 // SkDebugf("xxxxxxxxxxxxxx failure to skip request %d returned %d\
n", bytesToSkip, bytes); | 69 // SkDebugf("xxxxxxxxxxxxxx failure to skip request %d returned %d\
n", bytesToSkip, bytes); |
| 77 cinfo->err->error_exit((j_common_ptr)cinfo); | 70 cinfo->err->error_exit((j_common_ptr)cinfo); |
| 78 return; | 71 return; |
| 79 } | 72 } |
| 80 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 73 #ifdef SK_BUILD_FOR_ANDROID |
| 81 src->current_offset += bytes; | 74 src->current_offset += bytes; |
| 82 #endif | 75 #endif |
| 83 bytesToSkip -= bytes; | 76 bytesToSkip -= bytes; |
| 84 } | 77 } |
| 85 src->next_input_byte = (const JOCTET*)src->fBuffer; | 78 src->next_input_byte = (const JOCTET*)src->fBuffer; |
| 86 src->bytes_in_buffer = 0; | 79 src->bytes_in_buffer = 0; |
| 87 } else { | 80 } else { |
| 88 src->next_input_byte += num_bytes; | 81 src->next_input_byte += num_bytes; |
| 89 src->bytes_in_buffer -= num_bytes; | 82 src->bytes_in_buffer -= num_bytes; |
| 90 } | 83 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 112 | 105 |
| 113 skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder) | 106 skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder) |
| 114 : fStream(SkRef(stream)) | 107 : fStream(SkRef(stream)) |
| 115 , fDecoder(decoder) { | 108 , fDecoder(decoder) { |
| 116 | 109 |
| 117 init_source = sk_init_source; | 110 init_source = sk_init_source; |
| 118 fill_input_buffer = sk_fill_input_buffer; | 111 fill_input_buffer = sk_fill_input_buffer; |
| 119 skip_input_data = sk_skip_input_data; | 112 skip_input_data = sk_skip_input_data; |
| 120 resync_to_restart = sk_resync_to_restart; | 113 resync_to_restart = sk_resync_to_restart; |
| 121 term_source = sk_term_source; | 114 term_source = sk_term_source; |
| 122 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 115 #ifdef SK_BUILD_FOR_ANDROID |
| 123 seek_input_data = sk_seek_input_data; | 116 seek_input_data = sk_seek_input_data; |
| 124 #endif | 117 #endif |
| 125 // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBa
seSize); | 118 // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBa
seSize); |
| 126 } | 119 } |
| 127 | 120 |
| 128 skjpeg_source_mgr::~skjpeg_source_mgr() { | 121 skjpeg_source_mgr::~skjpeg_source_mgr() { |
| 129 SkSafeUnref(fStream); | 122 SkSafeUnref(fStream); |
| 130 } | 123 } |
| 131 | 124 |
| 132 /////////////////////////////////////////////////////////////////////////////// | 125 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 void skjpeg_error_exit(j_common_ptr cinfo) { | 169 void skjpeg_error_exit(j_common_ptr cinfo) { |
| 177 skjpeg_error_mgr* error = (skjpeg_error_mgr*)cinfo->err; | 170 skjpeg_error_mgr* error = (skjpeg_error_mgr*)cinfo->err; |
| 178 | 171 |
| 179 (*error->output_message) (cinfo); | 172 (*error->output_message) (cinfo); |
| 180 | 173 |
| 181 /* Let the memory manager delete any temp files before we die */ | 174 /* Let the memory manager delete any temp files before we die */ |
| 182 jpeg_destroy(cinfo); | 175 jpeg_destroy(cinfo); |
| 183 | 176 |
| 184 longjmp(error->fJmpBuf, -1); | 177 longjmp(error->fJmpBuf, -1); |
| 185 } | 178 } |
| OLD | NEW |