当前位置: 首页>>代码示例>>C++>>正文


C++ OwnArrayPtr::clear方法代码示例

本文整理汇总了C++中OwnArrayPtr::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ OwnArrayPtr::clear方法的具体用法?C++ OwnArrayPtr::clear怎么用?C++ OwnArrayPtr::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OwnArrayPtr的用法示例。


在下文中一共展示了OwnArrayPtr::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dumpImage

void TestShell::dumpImage(SkCanvas* canvas) const
{
    // Fix the alpha. The expected PNGs on Mac have an alpha channel, so we want
    // to keep it. On Windows, the alpha channel is wrong since text/form control
    // drawing may have erased it in a few places. So on Windows we force it to
    // opaque and also don't write the alpha channel for the reference. Linux
    // doesn't have the wrong alpha like Windows, but we match Windows.
#if OS(MAC_OS_X)
    bool discardTransparency = false;
#else
    bool discardTransparency = true;
    makeCanvasOpaque(canvas);
#endif

    const SkBitmap& sourceBitmap = canvas->getTopDevice()->accessBitmap(false);
    SkAutoLockPixels sourceBitmapLock(sourceBitmap);

    // Compute MD5 sum.
    MD5 digester;
    Vector<uint8_t, 16> digestValue;
#if OS(ANDROID)
    // On Android, pixel layout is RGBA (see third_party/skia/include/core/SkColorPriv.h);
    // however, other Chrome platforms use BGRA (see skia/config/SkUserConfig.h).
    // To match the checksum of other Chrome platforms, we need to reorder the layout of pixels.
    // NOTE: The following code assumes we use SkBitmap::kARGB_8888_Config,
    // which has been checked in device.makeOpaque() (see above).
    const uint8_t* rawPixels = reinterpret_cast<const uint8_t*>(sourceBitmap.getPixels());
    size_t bitmapSize = sourceBitmap.getSize();
    OwnArrayPtr<uint8_t> reorderedPixels = adoptArrayPtr(new uint8_t[bitmapSize]);
    for (size_t i = 0; i < bitmapSize; i += 4) {
        reorderedPixels[i] = rawPixels[i + 2]; // R
        reorderedPixels[i + 1] = rawPixels[i + 1]; // G
        reorderedPixels[i + 2] = rawPixels[i]; // B
        reorderedPixels[i + 3] = rawPixels[i + 3]; // A
    }
    digester.addBytes(reorderedPixels.get(), bitmapSize);
    reorderedPixels.clear();
#else
    digester.addBytes(reinterpret_cast<const uint8_t*>(sourceBitmap.getPixels()), sourceBitmap.getSize());
#endif
    digester.checksum(digestValue);
    string md5hash;
    md5hash.reserve(16 * 2);
    for (unsigned i = 0; i < 16; ++i) {
        char hex[3];
        // Use "x", not "X". The string must be lowercased.
        sprintf(hex, "%02x", digestValue[i]);
        md5hash.append(hex);
    }

    // Only encode and dump the png if the hashes don't match. Encoding the
    // image is really expensive.
    if (md5hash.compare(m_params.pixelHash)) {
        std::vector<unsigned char> png;
#if OS(ANDROID)
        webkit_support::EncodeRGBAPNGWithChecksum(reinterpret_cast<const unsigned char*>(sourceBitmap.getPixels()), sourceBitmap.width(),
            sourceBitmap.height(), static_cast<int>(sourceBitmap.rowBytes()), discardTransparency, md5hash, &png);
#else
        webkit_support::EncodeBGRAPNGWithChecksum(reinterpret_cast<const unsigned char*>(sourceBitmap.getPixels()), sourceBitmap.width(),
            sourceBitmap.height(), static_cast<int>(sourceBitmap.rowBytes()), discardTransparency, md5hash, &png);
#endif

        m_printer->handleImage(md5hash.c_str(), m_params.pixelHash.c_str(), &png[0], png.size(), m_params.pixelFileName.c_str());
    } else
        m_printer->handleImage(md5hash.c_str(), m_params.pixelHash.c_str(), 0, 0, m_params.pixelFileName.c_str());
}
开发者ID:yang-bo,项目名称:webkit,代码行数:66,代码来源:TestShell.cpp


注:本文中的OwnArrayPtr::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。