Exemplo n.º 1
0
BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
        SkBitmapRegionDecoderInterface::Strategy strategy, SkColorType colorType,
        uint32_t sampleSize, const SkIRect& subset)
    : fBRD(nullptr)
    , fData(SkRef(encoded))
    , fStrategy(strategy)
    , fColorType(colorType)
    , fSampleSize(sampleSize)
    , fSubset(subset)
{
    // Choose a useful name for the region decoding strategy
    const char* strategyName;
    switch (strategy) {
        case SkBitmapRegionDecoderInterface::kOriginal_Strategy:
            strategyName = "Original";
            break;
        case SkBitmapRegionDecoderInterface::kCanvas_Strategy:
            strategyName = "Canvas";
            break;
        default:
            SkASSERT(false);
            strategyName = "";
            break;
    }

    // Choose a useful name for the color type
    const char* colorName = color_type_to_str(colorType);

    fName.printf("BRD_%s_%s_%s", baseName, strategyName, colorName);
    if (1 != sampleSize) {
        fName.appendf("_%.3f", get_scale_from_sample_size(sampleSize));
    }
}
Exemplo n.º 2
0
SkISize SkSampledCodec::accountForNativeScaling(int* sampleSizePtr, int* nativeSampleSize) const {
    SkISize preSampledSize = this->codec()->getInfo().dimensions();
    int sampleSize = *sampleSizePtr;
    SkASSERT(sampleSize > 1);

    if (nativeSampleSize) {
        *nativeSampleSize = 1;
    }

    // Only JPEG supports native downsampling.
    if (this->codec()->getEncodedFormat() == SkEncodedImageFormat::kJPEG) {
        // See if libjpeg supports this scale directly
        switch (sampleSize) {
            case 2:
            case 4:
            case 8:
                // This class does not need to do any sampling.
                *sampleSizePtr = 1;
                return this->codec()->getScaledDimensions(get_scale_from_sample_size(sampleSize));
            default:
                break;
        }

        // Check if sampleSize is a multiple of something libjpeg can support.
        int remainder;
        const int sampleSizes[] = { 8, 4, 2 };
        for (int supportedSampleSize : sampleSizes) {
            int actualSampleSize;
            SkTDivMod(sampleSize, supportedSampleSize, &actualSampleSize, &remainder);
            if (0 == remainder) {
                float scale = get_scale_from_sample_size(supportedSampleSize);

                // this->codec() will scale to this size.
                preSampledSize = this->codec()->getScaledDimensions(scale);

                // And then this class will sample it.
                *sampleSizePtr = actualSampleSize;
                if (nativeSampleSize) {
                    *nativeSampleSize = supportedSampleSize;
                }
                break;
            }
        }
    }

    return preSampledSize;
}
Exemplo n.º 3
0
SkISize SkWebpAdapterCodec::onGetSampledDimensions(int sampleSize) const {
    float scale = get_scale_from_sample_size(sampleSize);
    return this->codec()->getScaledDimensions(scale);
}