Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: Source/platform/image-encoders/skia/JPEGImageEncoder.cpp

Issue 837643002: Remove Uint8ClampedArray use from ImageBuffer.h ImageDataBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 { 110 {
111 if (quality < 100) 111 if (quality < 100)
112 return; 112 return;
113 113
114 for (int i = 0; i < MAX_COMPONENTS; ++i) { 114 for (int i = 0; i < MAX_COMPONENTS; ++i) {
115 cinfo->comp_info[i].h_samp_factor = 1; 115 cinfo->comp_info[i].h_samp_factor = 1;
116 cinfo->comp_info[i].v_samp_factor = 1; 116 cinfo->comp_info[i].v_samp_factor = 1;
117 } 117 }
118 } 118 }
119 119
120 static bool encodePixels(IntSize imageSize, unsigned char* inputPixels, bool pre multiplied, int quality, Vector<unsigned char>* output) 120 static bool encodePixels(IntSize imageSize, const unsigned char* inputPixels, bo ol premultiplied, int quality, Vector<unsigned char>* output)
121 { 121 {
122 JPEGOutputBuffer destination; 122 JPEGOutputBuffer destination;
123 destination.output = output; 123 destination.output = output;
124 Vector<JSAMPLE> row; 124 Vector<JSAMPLE> row;
125 125
126 jpeg_compress_struct cinfo; 126 jpeg_compress_struct cinfo;
127 jpeg_error_mgr error; 127 jpeg_error_mgr error;
128 cinfo.err = jpeg_std_error(&error); 128 cinfo.err = jpeg_std_error(&error);
129 error.error_exit = handleError; 129 error.error_exit = handleError;
130 jmp_buf jumpBuffer; 130 jmp_buf jumpBuffer;
(...skipping 18 matching lines...) Expand all
149 if (premultiplied) { 149 if (premultiplied) {
150 cinfo.in_color_space = SK_B32_SHIFT ? JCS_EXT_RGBX : JCS_EXT_BGRX; 150 cinfo.in_color_space = SK_B32_SHIFT ? JCS_EXT_RGBX : JCS_EXT_BGRX;
151 151
152 cinfo.input_components = 4; 152 cinfo.input_components = 4;
153 153
154 jpeg_set_defaults(&cinfo); 154 jpeg_set_defaults(&cinfo);
155 jpeg_set_quality(&cinfo, quality, TRUE); 155 jpeg_set_quality(&cinfo, quality, TRUE);
156 disableSubsamplingForHighQuality(&cinfo, quality); 156 disableSubsamplingForHighQuality(&cinfo, quality);
157 jpeg_start_compress(&cinfo, TRUE); 157 jpeg_start_compress(&cinfo, TRUE);
158 158
159 unsigned char* pixels = inputPixels; 159 unsigned char* pixels = const_cast<unsigned char*>(inputPixels);
160 const size_t pixelRowStride = cinfo.image_width * 4; 160 const size_t pixelRowStride = cinfo.image_width * 4;
161 while (cinfo.next_scanline < cinfo.image_height) { 161 while (cinfo.next_scanline < cinfo.image_height) {
162 jpeg_write_scanlines(&cinfo, &pixels, 1); 162 jpeg_write_scanlines(&cinfo, &pixels, 1);
163 pixels += pixelRowStride; 163 pixels += pixelRowStride;
164 } 164 }
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, unsigned char* output) ; 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 = const_cast<unsigned char*>(inputPixels);
186 row.resize(cinfo.image_width * cinfo.input_components); 186 row.resize(cinfo.image_width * cinfo.input_components);
187 const size_t pixelRowStride = cinfo.image_width * 4; 187 const size_t pixelRowStride = cinfo.image_width * 4;
188 while (cinfo.next_scanline < cinfo.image_height) { 188 while (cinfo.next_scanline < cinfo.image_height) {
189 JSAMPLE* rowData = row.data(); 189 JSAMPLE* rowData = row.data();
190 extractRowRGB(pixels, cinfo.image_width, rowData); 190 extractRowRGB(pixels, cinfo.image_width, rowData);
191 jpeg_write_scanlines(&cinfo, &rowData, 1); 191 jpeg_write_scanlines(&cinfo, &rowData, 1);
192 pixels += pixelRowStride; 192 pixels += pixelRowStride;
193 } 193 }
194 194
195 jpeg_finish_compress(&cinfo); 195 jpeg_finish_compress(&cinfo);
196 jpeg_destroy_compress(&cinfo); 196 jpeg_destroy_compress(&cinfo);
197 return true; 197 return true;
198 } 198 }
199 199
200 bool JPEGImageEncoder::encode(const SkBitmap& bitmap, int quality, Vector<unsign ed char>* output) 200 bool JPEGImageEncoder::encode(const SkBitmap& bitmap, int quality, Vector<unsign ed char>* output)
201 { 201 {
202 SkAutoLockPixels bitmapLock(bitmap); 202 SkAutoLockPixels bitmapLock(bitmap);
203 203
204 if (bitmap.colorType() != kN32_SkColorType || !bitmap.getPixels()) 204 if (bitmap.colorType() != kN32_SkColorType || !bitmap.getPixels())
205 return false; // Only support 32 bit/pixel skia bitmaps. 205 return false; // Only support 32 bit/pixel skia bitmaps.
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(IntSize(imageData.width(), imageData.height()), imageDat a.pixels(), false, quality, output);
213 } 213 }
214 214
215 } // namespace blink 215 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/ImageBuffer.cpp ('k') | Source/platform/image-encoders/skia/PNGImageEncoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698