OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/codec/jpeg_codec.h" | 5 #include "ui/gfx/codec/jpeg_codec.h" |
6 | 6 |
7 #include <setjmp.h> | 7 #include <setjmp.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 state->out->resize(state->image_buffer_used); | 143 state->out->resize(state->image_buffer_used); |
144 } | 144 } |
145 | 145 |
146 #if !defined(JCS_EXTENSIONS) | 146 #if !defined(JCS_EXTENSIONS) |
147 // Converts RGBA to RGB (removing the alpha values) to prepare to send data to | 147 // Converts RGBA to RGB (removing the alpha values) to prepare to send data to |
148 // libjpeg. This converts one row of data in rgba with the given width in | 148 // libjpeg. This converts one row of data in rgba with the given width in |
149 // pixels the the given rgb destination buffer (which should have enough space | 149 // pixels the the given rgb destination buffer (which should have enough space |
150 // reserved for the final data). | 150 // reserved for the final data). |
151 void StripAlpha(const unsigned char* rgba, int pixel_width, unsigned char* rgb) | 151 void StripAlpha(const unsigned char* rgba, int pixel_width, unsigned char* rgb) |
152 { | 152 { |
153 for (int x = 0; x < pixel_width; x++) { | 153 for (int x = 0; x < pixel_width; x++) |
154 const unsigned char* pixel_in = &rgba[x * 4]; | 154 memcpy(&rgb[x * 3], &rgba[x * 4], 3); |
155 unsigned char* pixel_out = &rgb[x * 3]; | |
156 pixel_out[0] = pixel_in[0]; | |
157 pixel_out[1] = pixel_in[1]; | |
158 pixel_out[2] = pixel_in[2]; | |
159 } | |
160 } | 155 } |
161 | 156 |
162 // Converts BGRA to RGB by reordering the color components and dropping the | 157 // Converts BGRA to RGB by reordering the color components and dropping the |
163 // alpha. This converts one row of data in rgba with the given width in | 158 // alpha. This converts one row of data in rgba with the given width in |
164 // pixels the the given rgb destination buffer (which should have enough space | 159 // pixels the the given rgb destination buffer (which should have enough space |
165 // reserved for the final data). | 160 // reserved for the final data). |
166 void BGRAtoRGB(const unsigned char* bgra, int pixel_width, unsigned char* rgb) | 161 void BGRAtoRGB(const unsigned char* bgra, int pixel_width, unsigned char* rgb) |
167 { | 162 { |
168 for (int x = 0; x < pixel_width; x++) { | 163 for (int x = 0; x < pixel_width; x++) { |
169 const unsigned char* pixel_in = &bgra[x * 4]; | 164 const unsigned char* pixel_in = &bgra[x * 4]; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 // been read to clean up JPEG source manager. NOT called by jpeg_abort() or | 395 // been read to clean up JPEG source manager. NOT called by jpeg_abort() or |
401 // jpeg_destroy()." | 396 // jpeg_destroy()." |
402 void TermSource(j_decompress_ptr cinfo) { | 397 void TermSource(j_decompress_ptr cinfo) { |
403 } | 398 } |
404 | 399 |
405 #if !defined(JCS_EXTENSIONS) | 400 #if !defined(JCS_EXTENSIONS) |
406 // Converts one row of rgb data to rgba data by adding a fully-opaque alpha | 401 // Converts one row of rgb data to rgba data by adding a fully-opaque alpha |
407 // value. | 402 // value. |
408 void AddAlpha(const unsigned char* rgb, int pixel_width, unsigned char* rgba) { | 403 void AddAlpha(const unsigned char* rgb, int pixel_width, unsigned char* rgba) { |
409 for (int x = 0; x < pixel_width; x++) { | 404 for (int x = 0; x < pixel_width; x++) { |
410 const unsigned char* pixel_in = &rgb[x * 3]; | 405 memcpy(&rgba[x * 4], &rgb[x * 3], 3); |
411 unsigned char* pixel_out = &rgba[x * 4]; | 406 rgba[x * 4 + 3] = 0xff; |
412 pixel_out[0] = pixel_in[0]; | |
413 pixel_out[1] = pixel_in[1]; | |
414 pixel_out[2] = pixel_in[2]; | |
415 pixel_out[3] = 0xff; | |
416 } | 407 } |
417 } | 408 } |
418 | 409 |
419 // Converts one row of RGB data to BGRA by reordering the color components and | 410 // Converts one row of RGB data to BGRA by reordering the color components and |
420 // adding alpha values of 0xff. | 411 // adding alpha values of 0xff. |
421 void RGBtoBGRA(const unsigned char* bgra, int pixel_width, unsigned char* rgb) | 412 void RGBtoBGRA(const unsigned char* bgra, int pixel_width, unsigned char* rgb) |
422 { | 413 { |
423 for (int x = 0; x < pixel_width; x++) { | 414 for (int x = 0; x < pixel_width; x++) { |
424 const unsigned char* pixel_in = &bgra[x * 3]; | 415 const unsigned char* pixel_in = &bgra[x * 3]; |
425 unsigned char* pixel_out = &rgb[x * 4]; | 416 unsigned char* pixel_out = &rgb[x * 4]; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 int data_length = w * h * 4; | 613 int data_length = w * h * 4; |
623 | 614 |
624 SkBitmap* bitmap = new SkBitmap(); | 615 SkBitmap* bitmap = new SkBitmap(); |
625 bitmap->allocN32Pixels(w, h); | 616 bitmap->allocN32Pixels(w, h); |
626 memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length); | 617 memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length); |
627 | 618 |
628 return bitmap; | 619 return bitmap; |
629 } | 620 } |
630 | 621 |
631 } // namespace gfx | 622 } // namespace gfx |
OLD | NEW |