OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 251 } |
252 return true; | 252 return true; |
253 } | 253 } |
254 return false; | 254 return false; |
255 } | 255 } |
256 | 256 |
257 bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint c
hint) const { | 257 bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint c
hint) const { |
258 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
srcX, srcY, chint); | 258 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
srcX, srcY, chint); |
259 } | 259 } |
260 | 260 |
| 261 #if SK_SUPPORT_GPU |
| 262 #include "GrTextureToYUVPlanes.h" |
| 263 #endif |
| 264 |
| 265 #define HACKY_RASTER_IMPL 0 |
| 266 |
| 267 #if HACKY_RASTER_IMPL |
| 268 // Shouldn't really include from effects here. |
| 269 #include "../effects/SkColorMatrixFilter.h" |
| 270 |
| 271 static const float kYUVColorSpaceInvMatrices[][20] = { |
| 272 {0.299001f, 0.586998f, 0.114001f, 0.f, 0.0000821798f, |
| 273 -0.168736f, -0.331263f, 0.499999f, 0.f, 0.499954f, |
| 274 0.499999f, -0.418686f, -0.0813131f, 0.f, 0.499941f, |
| 275 0.f, 0.f, 0.f, 1.f, 0.f}, |
| 276 |
| 277 {0.256951f, 0.504421f, 0.0977346f, 0.f, 0.0625f, |
| 278 -0.148212f, -0.290954f, 0.439166f, 0.f, 0.5f, |
| 279 0.439166f, -0.367886f, -0.0712802f, 0.f, 0.5f, |
| 280 0.f, 0.f, 0.f, 1.f, 0.f}, |
| 281 |
| 282 {0.182663f, 0.614473f, 0.061971f, 0.f, 0.0625f, |
| 283 -0.100672f, -0.338658f, 0.43933f, 0.f, 0.5f, |
| 284 0.439142f, -0.39891f, -0.040231f, 0.f, 0.5f, |
| 285 0.f, 0.f, 0.f, 1.f, 0.f}, |
| 286 }; |
| 287 #endif |
| 288 |
| 289 bool SkImage::asYUV8Planes(const SkISize sizes[3], void* const planes[3], const
size_t rowBytes[3], |
| 290 SkYUVColorSpace colorSpace) { |
| 291 #if SK_SUPPORT_GPU |
| 292 if (GrTexture* texture = as_IB(this)->peekTexture()) { |
| 293 if (GrTextureToYUVPlanes(texture, sizes, planes, rowBytes, colorSpace))
{ |
| 294 return true; |
| 295 } |
| 296 } |
| 297 #endif |
| 298 #if !HACKY_RASTER_IMPL |
| 299 return false; |
| 300 #else // This seems to work for Y but not U and V |
| 301 SkPixmap pixmap; |
| 302 SkAutoTDeleteArray<uint32_t> pixels(0); |
| 303 if (!this->peekPixels(&pixmap)) { |
| 304 // Should this be premul? |
| 305 SkImageInfo info = SkImageInfo::MakeN32Premul(this->width(), this->heigh
t()); |
| 306 pixels.reset(new uint32_t[this->width() * this->height()]); |
| 307 pixmap.reset(info, pixels.get(), 0); |
| 308 if (!this->readPixels(pixmap, 0, 0, kDisallow_CachingHint)) { |
| 309 return false; |
| 310 } |
| 311 } |
| 312 for (int i = 0; i < 3; ++i) { |
| 313 size_t rb = rowBytes[i] ? rowBytes[i] : sizes[i].fWidth; |
| 314 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect( |
| 315 SkImageInfo::MakeA8(sizes[i].fWidth, sizes[i].fHeight), planes[i
], rb)); |
| 316 SkPaint paint; |
| 317 paint.setFilterQuality(kLow_SkFilterQuality); |
| 318 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 319 SkColorMatrix replicateChannel; |
| 320 for (int j = 0; j < 20; ++j) { |
| 321 replicateChannel.fMat[j] = 0.f; |
| 322 } |
| 323 replicateChannel.fMat[0+i] = 1.f; |
| 324 replicateChannel.fMat[5+i] = 1.f; |
| 325 replicateChannel.fMat[10+i] = 1.f; |
| 326 replicateChannel.fMat[15+i] = 1.f; |
| 327 SkColorMatrix::SetConcat(replicateChannel.fMat, replicateChannel.fMat, |
| 328 kYUVColorSpaceInvMatrices[colorSpace]); |
| 329 paint.setColorFilter(SkColorMatrixFilter::Create(replicateChannel))->unr
ef(); |
| 330 surface->getCanvas()->drawImageRect(this, SkIRect::MakeWH(this->width(),
this->height()), |
| 331 SkRect::MakeIWH(surface->width(), su
rface->height()), |
| 332 &paint); |
| 333 } |
| 334 return true; |
| 335 #endif |
| 336 } |
| 337 |
261 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 338 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
262 | 339 |
263 SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) { | 340 SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) { |
264 SkPixelRef* pr = bm.pixelRef(); | 341 SkPixelRef* pr = bm.pixelRef(); |
265 if (nullptr == pr) { | 342 if (nullptr == pr) { |
266 return nullptr; | 343 return nullptr; |
267 } | 344 } |
268 | 345 |
269 #if SK_SUPPORT_GPU | 346 #if SK_SUPPORT_GPU |
270 if (GrTexture* tex = pr->getTexture()) { | 347 if (GrTexture* tex = pr->getTexture()) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 410 |
334 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { | 411 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { |
335 return nullptr; | 412 return nullptr; |
336 } | 413 } |
337 | 414 |
338 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { | 415 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { |
339 return nullptr; | 416 return nullptr; |
340 } | 417 } |
341 | 418 |
342 #endif | 419 #endif |
OLD | NEW |