optimize case where image_view is used but is not a subset - refs #2024

This commit is contained in:
Dane Springmeyer 2013-09-27 12:17:31 -07:00
parent 44807673a3
commit 90dd6b9d61

View file

@ -73,26 +73,48 @@ inline int import_image_data(T2 const& image,
WebPPicture & pic, WebPPicture & pic,
bool alpha) bool alpha)
{ {
// Reason for copy: https://github.com/mapnik/mapnik/issues/2024 ImageData<typename T2::pixel_type> const& data = image.data();
image_data_32 im(image.width(),image.height()); int stride = sizeof(typename T2::pixel_type) * image.width();
int stride = sizeof(typename T2::pixel_type) * im.width(); if (data.width() == image.width() &&
for (unsigned y = 0; y < image.height(); ++y) data.height() == image.height())
{ {
typename T2::pixel_type const * row_from = image.getRow(y); std::clog << "opt\n";
image_data_32::pixel_type * row_to = im.getRow(y); if (alpha)
std::memcpy(row_to,row_from,stride); {
} return WebPPictureImportRGBA(&pic, data.getBytes(), stride);
if (alpha) }
{ else
return WebPPictureImportRGBA(&pic, im.getBytes(), stride); {
#if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
return WebPPictureImportRGBX(&pic, data.getBytes(), stride);
#else
return WebPPictureImportRGBA(&pic, data.getBytes(), stride);
#endif
}
} }
else else
{ {
#if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1 // need to copy: https://github.com/mapnik/mapnik/issues/2024
return WebPPictureImportRGBX(&pic, im.getBytes(), stride); std::clog << "copy\n";
#else image_data_32 im(image.width(),image.height());
return WebPPictureImportRGBA(&pic, im.getBytes(), stride); for (unsigned y = 0; y < image.height(); ++y)
#endif {
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
}
} }
} }