Beispiel #1
0
inline int import_image(T2 const& im_in,
                             WebPPicture & pic,
                             bool alpha)
{
    image<typename T2::pixel> const& data = im_in.data();
    std::size_t width = im_in.width();
    std::size_t height = im_in.height();
    std::size_t stride = sizeof(typename T2::pixel_type) * width;
    if (data.width() == width &&
        data.height() == height)
    {
        if (alpha)
        {
            return WebPPictureImportRGBA(&pic, data.bytes(), static_cast<int>(stride));
        }
        else
        {
    #if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
            return WebPPictureImportRGBX(&pic, data.bytes(), static_cast<int>(stride));
    #else
            return WebPPictureImportRGBA(&pic, data.bytes(), static_cast<int>(stride));
    #endif
        }
    }
    else
    {
        // need to copy: https://github.com/mapnik/mapnik/issues/2024
        image_rgba8 im(width,height);
        for (unsigned y = 0; y < height; ++y)
        {
            typename T2::pixel_type const * row_from = im_in.get_row(y);
            image_rgba8::pixel_type * row_to = im.get_row(y);
            std::copy(row_from, row_from + width, row_to);
        }
        if (alpha)
        {
            return WebPPictureImportRGBA(&pic, im.bytes(), static_cast<int>(stride));
        }
        else
        {
    #if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
            return WebPPictureImportRGBX(&pic, im.bytes(), static_cast<int>(stride));
    #else
            return WebPPictureImportRGBA(&pic, im.bytes(), static_cast<int>(stride));
    #endif
        }
    }
}
Beispiel #2
0
inline int import_image_data(T2 const& image,
                             WebPPicture & pic,
                             bool alpha)
{
    ImageData<typename T2::pixel_type> const& data = image.data();
    int stride = sizeof(typename T2::pixel_type) * image.width();
    if (data.width() == image.width() &&
        data.height() == image.height())
    {
        if (alpha)
        {
            return WebPPictureImportRGBA(&pic, data.getBytes(), stride);
        }
        else
        {
    #if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
            return WebPPictureImportRGBX(&pic, data.getBytes(), stride);
    #else
            return WebPPictureImportRGBA(&pic, data.getBytes(), stride);
    #endif
        }
    }
    else
    {
        // need to copy: https://github.com/mapnik/mapnik/issues/2024
        image_data_32 im(image.width(),image.height());
        for (unsigned y = 0; y < image.height(); ++y)
        {
            typename T2::pixel_type const * row_from = image.getRow(y);
            image_data_32::pixel_type * row_to = im.getRow(y);
            std::memcpy(row_to,row_from,stride);
        }
        if (alpha)
        {
            return WebPPictureImportRGBA(&pic, im.getBytes(), stride);
        }
        else
        {
    #if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
            return WebPPictureImportRGBX(&pic, im.getBytes(), stride);
    #else
            return WebPPictureImportRGBA(&pic, im.getBytes(), stride);
    #endif
        }
    }
}