| OLD | NEW | 
|    1  |    1  | 
|    2 /* |    2 /* | 
|    3  * Copyright 2007 The Android Open Source Project |    3  * Copyright 2007 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 "bmpdecoderhelper.h" |   10 #include "bmpdecoderhelper.h" | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   86     const uint8_t* rgb() const { return fRGB.begin(); } |   86     const uint8_t* rgb() const { return fRGB.begin(); } | 
|   87  |   87  | 
|   88 private: |   88 private: | 
|   89     SkTDArray<uint8_t> fRGB; |   89     SkTDArray<uint8_t> fRGB; | 
|   90     int fWidth; |   90     int fWidth; | 
|   91     int fHeight; |   91     int fHeight; | 
|   92     bool fJustBounds; |   92     bool fJustBounds; | 
|   93 }; |   93 }; | 
|   94  |   94  | 
|   95 bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { |   95 bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { | 
 |   96     // First read the entire stream, so that all of the data can be passed to | 
 |   97     // the BmpDecoderHelper. | 
|   96  |   98  | 
|   97     size_t length = stream->getLength(); |   99     // Byte length of all of the data. | 
|   98     SkAutoMalloc storage(length); |  100     size_t length; | 
 |  101     // Allocated space used to hold the data. | 
 |  102     SkAutoMalloc storage; | 
|   99  |  103  | 
|  100     if (stream->read(storage.get(), length) != length) { |  104     if (stream->hasLength()) { | 
|  101         return false; |  105         length = stream->getLength(); | 
 |  106         void* dst = storage.reset(length); | 
 |  107         if (stream->read(dst, length) != length) { | 
 |  108             return false; | 
 |  109         } | 
 |  110     } else { | 
 |  111         SkDynamicMemoryWStream tempStream; | 
 |  112         // Arbitrary buffer size. | 
 |  113         const size_t bufferSize = 256 * 1024; // 256 KB | 
 |  114         char buffer[bufferSize]; | 
 |  115         length = 0; | 
 |  116         do { | 
 |  117             size_t bytesRead = stream->read(buffer, bufferSize); | 
 |  118             tempStream.write(buffer, bytesRead); | 
 |  119             length += bytesRead; | 
 |  120             SkASSERT(tempStream.bytesWritten() == length); | 
 |  121         } while (!stream->isAtEnd()); | 
 |  122         void* dst = storage.reset(length); | 
 |  123         tempStream.copyTo(dst); | 
|  102     } |  124     } | 
|  103  |  125  | 
|  104     const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode; |  126     const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode; | 
|  105     SkBmpDecoderCallback callback(justBounds); |  127     SkBmpDecoderCallback callback(justBounds); | 
|  106  |  128  | 
|  107     // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...] |  129     // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...] | 
|  108     { |  130     { | 
|  109         image_codec::BmpDecoderHelper helper; |  131         image_codec::BmpDecoderHelper helper; | 
|  110         const int max_pixels = 16383*16383; // max width*height |  132         const int max_pixels = 16383*16383; // max width*height | 
|  111         if (!helper.DecodeImage((const char*)storage.get(), length, |  133         if (!helper.DecodeImage((const char*)storage.get(), length, | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  151     const int dstHeight = sampler.scaledHeight(); |  173     const int dstHeight = sampler.scaledHeight(); | 
|  152     const uint8_t* srcRow = callback.rgb(); |  174     const uint8_t* srcRow = callback.rgb(); | 
|  153  |  175  | 
|  154     srcRow += sampler.srcY0() * srcRowBytes; |  176     srcRow += sampler.srcY0() * srcRowBytes; | 
|  155     for (int y = 0; y < dstHeight; y++) { |  177     for (int y = 0; y < dstHeight; y++) { | 
|  156         sampler.next(srcRow); |  178         sampler.next(srcRow); | 
|  157         srcRow += sampler.srcDY() * srcRowBytes; |  179         srcRow += sampler.srcDY() * srcRowBytes; | 
|  158     } |  180     } | 
|  159     return true; |  181     return true; | 
|  160 } |  182 } | 
| OLD | NEW |