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

Side by Side Diff: Source/platform/graphics/ImageBuffer.cpp

Issue 203443004: use new readPixels, as old version using Config8888 is deprecated (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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
« no previous file with comments | « Source/platform/graphics/GraphicsContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 template <Multiply multiplied> 264 template <Multiply multiplied>
265 PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext* context, const IntSize& size) 265 PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext* context, const IntSize& size)
266 { 266 {
267 float area = 4.0f * rect.width() * rect.height(); 267 float area = 4.0f * rect.width() * rect.height();
268 if (area > static_cast<float>(std::numeric_limits<int>::max())) 268 if (area > static_cast<float>(std::numeric_limits<int>::max()))
269 return nullptr; 269 return nullptr;
270 270
271 RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(re ct.width() * rect.height() * 4); 271 RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(re ct.width() * rect.height() * 4);
272 272
273 unsigned char* data = result->data();
274
275 if (rect.x() < 0 273 if (rect.x() < 0
276 || rect.y() < 0 274 || rect.y() < 0
277 || rect.maxX() > size.width() 275 || rect.maxX() > size.width()
278 || rect.maxY() > size.height()) 276 || rect.maxY() > size.height())
279 result->zeroFill(); 277 result->zeroFill();
280 278
281 unsigned destBytesPerRow = 4 * rect.width(); 279 SkAlphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremu l_SkAlphaType;
f(malita) 2014/03/18 16:08:24 SkAlphaType alphaType = ...
reed1 2014/03/18 19:39:38 Doh!
282 SkBitmap destBitmap; 280 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType);
283 destBitmap.installPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.heigh t()), data, destBytesPerRow);
284 281
285 SkCanvas::Config8888 config8888; 282 if (!context->readPixels(info, result->data(), 4 * rect.width(), rect.x(), r ect.y()))
286 if (multiplied == Premultiplied) 283 return nullptr;
287 config8888 = SkCanvas::kRGBA_Premul_Config8888;
288 else
289 config8888 = SkCanvas::kRGBA_Unpremul_Config8888;
290
291 context->readPixels(&destBitmap, rect.x(), rect.y(), config8888);
292 return result.release(); 284 return result.release();
293 } 285 }
294 286
295 PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRec t& rect) const 287 PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRec t& rect) const
296 { 288 {
297 if (!isValid()) 289 if (!isValid())
298 return Uint8ClampedArray::create(rect.width() * rect.height() * 4); 290 return Uint8ClampedArray::create(rect.width() * rect.height() * 4);
299 return getImageData<Unmultiplied>(rect, context(), m_surface->size()); 291 return getImageData<Unmultiplied>(rect, context(), m_surface->size());
300 } 292 }
301 293
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) 375 if (!encodeImage(imageData, mimeType, quality, &encodedImage))
384 return "data:,"; 376 return "data:,";
385 377
386 Vector<char> base64Data; 378 Vector<char> base64Data;
387 base64Encode(encodedImage, base64Data); 379 base64Encode(encodedImage, base64Data);
388 380
389 return "data:" + mimeType + ";base64," + base64Data; 381 return "data:" + mimeType + ";base64," + base64Data;
390 } 382 }
391 383
392 } // namespace WebCore 384 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/graphics/GraphicsContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698