| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright 2006 The Android Open Source Project |    2  * Copyright 2006 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 "SkImageDecoder.h" |    9 #include "SkImageDecoder.h" | 
|   10 #include "SkBitmap.h" |   10 #include "SkBitmap.h" | 
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  117     return alloc; |  117     return alloc; | 
|  118 } |  118 } | 
|  119  |  119  | 
|  120 void SkImageDecoder::setSampleSize(int size) { |  120 void SkImageDecoder::setSampleSize(int size) { | 
|  121     if (size < 1) { |  121     if (size < 1) { | 
|  122         size = 1; |  122         size = 1; | 
|  123     } |  123     } | 
|  124     fSampleSize = size; |  124     fSampleSize = size; | 
|  125 } |  125 } | 
|  126  |  126  | 
|  127 bool SkImageDecoder::chooseFromOneChoice(SkBitmap::Config config, int width, |  127 // TODO: change Chooser virtual to take colorType, so we can stop calling SkColo
     rTypeToBitmapConfig | 
|  128                                          int height) const { |  128 // | 
 |  129 bool SkImageDecoder::chooseFromOneChoice(SkColorType colorType, int width, int h
     eight) const { | 
|  129     Chooser* chooser = fChooser; |  130     Chooser* chooser = fChooser; | 
|  130  |  131      | 
|  131     if (NULL == chooser) {    // no chooser, we just say YES to decoding :) |  132     if (NULL == chooser) {    // no chooser, we just say YES to decoding :) | 
|  132         return true; |  133         return true; | 
|  133     } |  134     } | 
|  134     chooser->begin(1); |  135     chooser->begin(1); | 
|  135     chooser->inspect(0, config, width, height); |  136     chooser->inspect(0, SkColorTypeToBitmapConfig(colorType), width, height); | 
|  136     return chooser->choose() == 0; |  137     return chooser->choose() == 0; | 
|  137 } |  138 } | 
|  138  |  139  | 
|  139 bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, |  140 bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, | 
|  140                                    SkColorTable* ctable) const { |  141                                    SkColorTable* ctable) const { | 
|  141     return bitmap->allocPixels(fAllocator, ctable); |  142     return bitmap->allocPixels(fAllocator, ctable); | 
|  142 } |  143 } | 
|  143  |  144  | 
|  144 /////////////////////////////////////////////////////////////////////////////// |  145 /////////////////////////////////////////////////////////////////////////////// | 
|  145  |  146  | 
|  146 void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) { |  147 void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) { | 
|  147     fUsePrefTable = true; |  148     fUsePrefTable = true; | 
|  148     fPrefTable = prefTable; |  149     fPrefTable = prefTable; | 
|  149 } |  150 } | 
|  150  |  151  | 
|  151 SkBitmap::Config SkImageDecoder::getPrefConfig(SrcDepth srcDepth, |  152 // TODO: use colortype in fPrefTable, fDefaultPref and GetDeviceConfig() | 
|  152                                                bool srcHasAlpha) const { |  153 //       so we can stop using SkBitmapConfigToColorType() | 
 |  154 // | 
 |  155 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha
     ) const { | 
|  153     SkBitmap::Config config = SkBitmap::kNo_Config; |  156     SkBitmap::Config config = SkBitmap::kNo_Config; | 
|  154  |  157  | 
|  155     if (fUsePrefTable) { |  158     if (fUsePrefTable) { | 
|  156         switch (srcDepth) { |  159         switch (srcDepth) { | 
|  157             case kIndex_SrcDepth: |  160             case kIndex_SrcDepth: | 
|  158                 config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src |  161                 config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src | 
|  159                                      : fPrefTable.fPrefFor_8Index_NoAlpha_src; |  162                                      : fPrefTable.fPrefFor_8Index_NoAlpha_src; | 
|  160                 break; |  163                 break; | 
|  161             case k8BitGray_SrcDepth: |  164             case k8BitGray_SrcDepth: | 
|  162                 config = fPrefTable.fPrefFor_8Gray_src; |  165                 config = fPrefTable.fPrefFor_8Gray_src; | 
|  163                 break; |  166                 break; | 
|  164             case k32Bit_SrcDepth: |  167             case k32Bit_SrcDepth: | 
|  165                 config = srcHasAlpha ? fPrefTable.fPrefFor_8bpc_YesAlpha_src |  168                 config = srcHasAlpha ? fPrefTable.fPrefFor_8bpc_YesAlpha_src | 
|  166                                      : fPrefTable.fPrefFor_8bpc_NoAlpha_src; |  169                                      : fPrefTable.fPrefFor_8bpc_NoAlpha_src; | 
|  167                 break; |  170                 break; | 
|  168         } |  171         } | 
|  169     } else { |  172     } else { | 
|  170         config = fDefaultPref; |  173         config = fDefaultPref; | 
|  171     } |  174     } | 
|  172  |  175  | 
|  173     if (SkBitmap::kNo_Config == config) { |  176     if (SkBitmap::kNo_Config == config) { | 
|  174         config = SkImageDecoder::GetDeviceConfig(); |  177         config = SkImageDecoder::GetDeviceConfig(); | 
|  175     } |  178     } | 
|  176     return config; |  179     return SkBitmapConfigToColorType(config); | 
|  177 } |  180 } | 
|  178  |  181  | 
|  179 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, |  182 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, | 
|  180                             SkBitmap::Config pref, Mode mode) { |  183                             SkBitmap::Config pref, Mode mode) { | 
|  181     // we reset this to false before calling onDecode |  184     // we reset this to false before calling onDecode | 
|  182     fShouldCancelDecode = false; |  185     fShouldCancelDecode = false; | 
|  183     // assign this, for use by getPrefConfig(), in case fUsePrefTable is false |  186     // assign this, for use by getPrefConfig(), in case fUsePrefTable is false | 
|  184     fDefaultPref = pref; |  187     fDefaultPref = pref; | 
|  185  |  188  | 
|  186     // pass a temporary bitmap, so that if we return false, we are assured of |  189     // pass a temporary bitmap, so that if we return false, we are assured of | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  225         // savings are more important than speed here. This also means |  228         // savings are more important than speed here. This also means | 
|  226         // that the pixels in dst can not be reused (though there is no |  229         // that the pixels in dst can not be reused (though there is no | 
|  227         // allocation, which was already done on src). |  230         // allocation, which was already done on src). | 
|  228         int x = (dstX - srcX) / sampleSize; |  231         int x = (dstX - srcX) / sampleSize; | 
|  229         int y = (dstY - srcY) / sampleSize; |  232         int y = (dstY - srcY) / sampleSize; | 
|  230         SkIRect subset = SkIRect::MakeXYWH(x, y, w, h); |  233         SkIRect subset = SkIRect::MakeXYWH(x, y, w, h); | 
|  231         return src->extractSubset(dst, subset); |  234         return src->extractSubset(dst, subset); | 
|  232     } |  235     } | 
|  233     // if the destination has no pixels then we must allocate them. |  236     // if the destination has no pixels then we must allocate them. | 
|  234     if (dst->isNull()) { |  237     if (dst->isNull()) { | 
|  235         dst->setConfig(src->config(), w, h, 0, src->alphaType()); |  238         dst->setInfo(src->info().makeWH(w, h)); | 
|  236  |  239  | 
|  237         if (!this->allocPixelRef(dst, NULL)) { |  240         if (!this->allocPixelRef(dst, NULL)) { | 
|  238             SkDEBUGF(("failed to allocate pixels needed to crop the bitmap")); |  241             SkDEBUGF(("failed to allocate pixels needed to crop the bitmap")); | 
|  239             return false; |  242             return false; | 
|  240         } |  243         } | 
|  241     } |  244     } | 
|  242     // check to see if the destination is large enough to decode the desired |  245     // check to see if the destination is large enough to decode the desired | 
|  243     // region. If this assert fails we will just draw as much of the source |  246     // region. If this assert fails we will just draw as much of the source | 
|  244     // into the destination that we can. |  247     // into the destination that we can. | 
|  245     if (dst->width() < w || dst->height() < h) { |  248     if (dst->width() < w || dst->height() < h) { | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  302             if (kUnknown_Format == *format) { |  305             if (kUnknown_Format == *format) { | 
|  303                 if (stream->rewind()) { |  306                 if (stream->rewind()) { | 
|  304                     *format = GetStreamFormat(stream); |  307                     *format = GetStreamFormat(stream); | 
|  305                 } |  308                 } | 
|  306             } |  309             } | 
|  307         } |  310         } | 
|  308         delete codec; |  311         delete codec; | 
|  309     } |  312     } | 
|  310     return success; |  313     return success; | 
|  311 } |  314 } | 
| OLD | NEW |