ui/gfx: optimize color format conversions by using memcpy in jpeg_codec.cc

This is similar idea which was already applied in png_codec.cc.
https://codereview.chromium.org/397673002/
(Sorry for making another review request.)

BUG=none
R=erg@chromium.org, sky@chromium.org, dcheng@chromium.org
TEST(DONE&PASSED)=gfx_unittests --gtest_filter="JPEGCodec*"

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284585 0039d316-1c4b-4281-b951-d872f2087c98
parent d454db06
......@@ -150,13 +150,8 @@ void TermDestination(jpeg_compress_struct* cinfo) {
// reserved for the final data).
void StripAlpha(const unsigned char* rgba, int pixel_width, unsigned char* rgb)
{
for (int x = 0; x < pixel_width; x++) {
const unsigned char* pixel_in = &rgba[x * 4];
unsigned char* pixel_out = &rgb[x * 3];
pixel_out[0] = pixel_in[0];
pixel_out[1] = pixel_in[1];
pixel_out[2] = pixel_in[2];
}
for (int x = 0; x < pixel_width; x++)
memcpy(&rgb[x * 3], &rgba[x * 4], 3);
}
// Converts BGRA to RGB by reordering the color components and dropping the
......@@ -407,12 +402,8 @@ void TermSource(j_decompress_ptr cinfo) {
// value.
void AddAlpha(const unsigned char* rgb, int pixel_width, unsigned char* rgba) {
for (int x = 0; x < pixel_width; x++) {
const unsigned char* pixel_in = &rgb[x * 3];
unsigned char* pixel_out = &rgba[x * 4];
pixel_out[0] = pixel_in[0];
pixel_out[1] = pixel_in[1];
pixel_out[2] = pixel_in[2];
pixel_out[3] = 0xff;
memcpy(&rgba[x * 4], &rgb[x * 3], 3);
rgba[x * 4 + 3] = 0xff;
}
}
......
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