Commit 5932bb9a authored by noel@chromium.org's avatar noel@chromium.org

Remove JPEG encoder SkBitmap API

SkBitmap is being removed from Chrome. There are no longer any callers
of JPEGImageEncoder::encode(SkBitmap,...) so we can remove it and also
the support code it required.

Note: The libjpeg-turbo specialization was the fastest encoder, but it
required premultiplied data (SkBitmap). Thus some performance was lost
when callers were switched over to use the ImageDataBuffer encoder (in
the SkImage-replaces-SkBitmap endeavor).

No change in behavior, no new tests.

BUG=449197

Review URL: https://codereview.chromium.org/1314763008

git-svn-id: svn://svn.chromium.org/blink/trunk@201367 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 0b20c12c
......@@ -31,10 +31,10 @@
#include "config.h"
#include "platform/image-encoders/skia/JPEGImageEncoder.h"
#include "SkBitmap.h"
#include "SkColorPriv.h"
#include "platform/geometry/IntSize.h"
#include "platform/graphics/ImageBuffer.h"
extern "C" {
#include <setjmp.h>
#include <stdio.h> // jpeglib.h needs stdio.h FILE
......@@ -79,20 +79,11 @@ static void handleError(j_common_ptr common)
longjmp(*jumpBufferPtr, -1);
}
static void preMultipliedBGRAtoRGB(const unsigned char* pixels, unsigned pixelCount, unsigned char* output)
{
const SkPMColor* input = reinterpret_cast_ptr<const SkPMColor*>(pixels);
for (; pixelCount-- > 0; ++input) {
*output++ = SkGetPackedR32(*input);
*output++ = SkGetPackedG32(*input);
*output++ = SkGetPackedB32(*input);
}
}
static void RGBAtoRGB(const unsigned char* pixels, unsigned pixelCount, unsigned char* output)
{
// Per <canvas> spec, composite the input image pixels source-over on black.
for (; pixelCount-- > 0; pixels += 4) {
// Do source-over composition on black.
unsigned char alpha = pixels[3];
if (alpha != 255) {
*output++ = SkMulDiv255Round(pixels[0], alpha);
......@@ -117,7 +108,7 @@ static void disableSubsamplingForHighQuality(jpeg_compress_struct* cinfo, int qu
}
}
static bool encodePixels(IntSize imageSize, const unsigned char* inputPixels, bool premultiplied, int quality, Vector<unsigned char>* output)
static bool encodePixels(IntSize imageSize, const unsigned char* inputPixels, int quality, Vector<unsigned char>* output)
{
if (imageSize.width() <= 0 || imageSize.height() <= 0)
return false;
......@@ -146,39 +137,9 @@ static bool encodePixels(IntSize imageSize, const unsigned char* inputPixels, bo
cinfo.image_height = imageSize.height();
cinfo.image_width = imageSize.width();
#if defined(JCS_EXTENSIONS)
if (premultiplied) {
cinfo.in_color_space = SK_B32_SHIFT ? JCS_EXT_RGBX : JCS_EXT_BGRX;
cinfo.input_components = 4;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
disableSubsamplingForHighQuality(&cinfo, quality);
jpeg_start_compress(&cinfo, TRUE);
unsigned char* pixels = const_cast<unsigned char*>(inputPixels);
const size_t pixelRowStride = cinfo.image_width * 4;
while (cinfo.next_scanline < cinfo.image_height) {
jpeg_write_scanlines(&cinfo, &pixels, 1);
pixels += pixelRowStride;
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
return true;
}
#endif
cinfo.in_color_space = JCS_RGB;
cinfo.input_components = 3;
void (*extractRowRGB)(const unsigned char*, unsigned, unsigned char* output);
extractRowRGB = &RGBAtoRGB;
if (premultiplied)
extractRowRGB = &preMultipliedBGRAtoRGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
disableSubsamplingForHighQuality(&cinfo, quality);
......@@ -189,7 +150,7 @@ static bool encodePixels(IntSize imageSize, const unsigned char* inputPixels, bo
const size_t pixelRowStride = cinfo.image_width * 4;
while (cinfo.next_scanline < cinfo.image_height) {
JSAMPLE* rowData = row.data();
extractRowRGB(pixels, cinfo.image_width, rowData);
RGBAtoRGB(pixels, cinfo.image_width, rowData);
jpeg_write_scanlines(&cinfo, &rowData, 1);
pixels += pixelRowStride;
}
......@@ -199,22 +160,12 @@ static bool encodePixels(IntSize imageSize, const unsigned char* inputPixels, bo
return true;
}
bool JPEGImageEncoder::encode(const SkBitmap& bitmap, int quality, Vector<unsigned char>* output)
{
SkAutoLockPixels bitmapLock(bitmap);
if (bitmap.colorType() != kN32_SkColorType || !bitmap.getPixels())
return false; // Only support 32 bit/pixel skia bitmaps.
return encodePixels(IntSize(bitmap.width(), bitmap.height()), static_cast<unsigned char *>(bitmap.getPixels()), true, quality, output);
}
bool JPEGImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vector<unsigned char>* output)
{
if (!imageData.pixels())
return false;
return encodePixels(IntSize(imageData.width(), imageData.height()), imageData.pixels(), false, quality, output);
return encodePixels(IntSize(imageData.width(), imageData.height()), imageData.pixels(), quality, output);
}
} // namespace blink
......@@ -33,16 +33,13 @@
#include "wtf/Vector.h"
class SkBitmap;
namespace blink {
struct ImageDataBuffer;
class JPEGImageEncoder {
public:
// Encode the input data with a compression quality in [0-100].
static bool encode(const SkBitmap&, int quality, Vector<unsigned char>*);
// Encode the image data with a compression quality in [0-100].
static bool encode(const ImageDataBuffer&, int quality, Vector<unsigned char>*);
// For callers: provide a reasonable compression quality default.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment