| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 const size_t size = out->buffer.size() - out->free_in_buffer; | 72 const size_t size = out->buffer.size() - out->free_in_buffer; |
| 73 out->output->append(out->buffer.data(), size); | 73 out->output->append(out->buffer.data(), size); |
| 74 } | 74 } |
| 75 | 75 |
| 76 static void handleError(j_common_ptr common) | 76 static void handleError(j_common_ptr common) |
| 77 { | 77 { |
| 78 jmp_buf* jumpBufferPtr = static_cast<jmp_buf*>(common->client_data); | 78 jmp_buf* jumpBufferPtr = static_cast<jmp_buf*>(common->client_data); |
| 79 longjmp(*jumpBufferPtr, -1); | 79 longjmp(*jumpBufferPtr, -1); |
| 80 } | 80 } |
| 81 | 81 |
| 82 static void preMultipliedBGRAtoRGB(const unsigned char* pixels, unsigned int pix
elCount, unsigned char* output) | 82 static void preMultipliedBGRAtoRGB(const unsigned char* pixels, unsigned pixelCo
unt, unsigned char* output) |
| 83 { | 83 { |
| 84 const SkPMColor* input = reinterpret_cast_ptr<const SkPMColor*>(pixels); | 84 const SkPMColor* input = reinterpret_cast_ptr<const SkPMColor*>(pixels); |
| 85 for (; pixelCount-- > 0; ++input) { | 85 for (; pixelCount-- > 0; ++input) { |
| 86 *output++ = SkGetPackedR32(*input); | 86 *output++ = SkGetPackedR32(*input); |
| 87 *output++ = SkGetPackedG32(*input); | 87 *output++ = SkGetPackedG32(*input); |
| 88 *output++ = SkGetPackedB32(*input); | 88 *output++ = SkGetPackedB32(*input); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 static void RGBAtoRGB(const unsigned char* pixels, unsigned int pixelCount, unsi
gned char* output) | 92 static void RGBAtoRGB(const unsigned char* pixels, unsigned pixelCount, unsigned
char* output) |
| 93 { | 93 { |
| 94 for (; pixelCount-- > 0; pixels += 4) { | 94 for (; pixelCount-- > 0; pixels += 4) { |
| 95 // Do source-over composition on black. | 95 // Do source-over composition on black. |
| 96 unsigned char alpha = pixels[3]; | 96 unsigned char alpha = pixels[3]; |
| 97 if (alpha != 255) { | 97 if (alpha != 255) { |
| 98 *output++ = SkMulDiv255Round(pixels[0], alpha); | 98 *output++ = SkMulDiv255Round(pixels[0], alpha); |
| 99 *output++ = SkMulDiv255Round(pixels[1], alpha); | 99 *output++ = SkMulDiv255Round(pixels[1], alpha); |
| 100 *output++ = SkMulDiv255Round(pixels[2], alpha); | 100 *output++ = SkMulDiv255Round(pixels[2], alpha); |
| 101 } else { | 101 } else { |
| 102 *output++ = pixels[0]; | 102 *output++ = pixels[0]; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 jpeg_finish_compress(&cinfo); | 166 jpeg_finish_compress(&cinfo); |
| 167 jpeg_destroy_compress(&cinfo); | 167 jpeg_destroy_compress(&cinfo); |
| 168 return true; | 168 return true; |
| 169 } | 169 } |
| 170 #endif | 170 #endif |
| 171 | 171 |
| 172 cinfo.in_color_space = JCS_RGB; | 172 cinfo.in_color_space = JCS_RGB; |
| 173 cinfo.input_components = 3; | 173 cinfo.input_components = 3; |
| 174 | 174 |
| 175 void (*extractRowRGB)(const unsigned char*, unsigned int, unsigned char* out
put); | 175 void (*extractRowRGB)(const unsigned char*, unsigned, unsigned char* output)
; |
| 176 extractRowRGB = &RGBAtoRGB; | 176 extractRowRGB = &RGBAtoRGB; |
| 177 if (premultiplied) | 177 if (premultiplied) |
| 178 extractRowRGB = &preMultipliedBGRAtoRGB; | 178 extractRowRGB = &preMultipliedBGRAtoRGB; |
| 179 | 179 |
| 180 jpeg_set_defaults(&cinfo); | 180 jpeg_set_defaults(&cinfo); |
| 181 jpeg_set_quality(&cinfo, quality, TRUE); | 181 jpeg_set_quality(&cinfo, quality, TRUE); |
| 182 disableSubsamplingForHighQuality(&cinfo, quality); | 182 disableSubsamplingForHighQuality(&cinfo, quality); |
| 183 jpeg_start_compress(&cinfo, TRUE); | 183 jpeg_start_compress(&cinfo, TRUE); |
| 184 | 184 |
| 185 unsigned char* pixels = inputPixels; | 185 unsigned char* pixels = inputPixels; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 206 | 206 |
| 207 return encodePixels(IntSize(bitmap.width(), bitmap.height()), static_cast<un
signed char *>(bitmap.getPixels()), true, quality, output); | 207 return encodePixels(IntSize(bitmap.width(), bitmap.height()), static_cast<un
signed char *>(bitmap.getPixels()), true, quality, output); |
| 208 } | 208 } |
| 209 | 209 |
| 210 bool JPEGImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec
tor<unsigned char>* output) | 210 bool JPEGImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec
tor<unsigned char>* output) |
| 211 { | 211 { |
| 212 return encodePixels(imageData.size(), imageData.data(), false, quality, outp
ut); | 212 return encodePixels(imageData.size(), imageData.data(), false, quality, outp
ut); |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace WebCore | 215 } // namespace WebCore |
| OLD | NEW |