 Chromium Code Reviews
 Chromium Code Reviews Issue 2756463003:
  Remove opaque alpha channel special case  (Closed)
    
  
    Issue 2756463003:
  Remove opaque alpha channel special case  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 | 5 * modification, are permitted provided that the following conditions | 
| 6 * are met: | 6 * are met: | 
| 7 * | 7 * | 
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright | 
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 ColorBehavior::TransformToTargetForTesting()); | 339 ColorBehavior::TransformToTargetForTesting()); | 
| 340 | 340 | 
| 341 SkImageInfo pix_info = SkImageInfo::MakeN32Premul(1, 1); | 341 SkImageInfo pix_info = SkImageInfo::MakeN32Premul(1, 1); | 
| 342 | 342 | 
| 343 size_t row_bytes = pix_info.minRowBytes(); | 343 size_t row_bytes = pix_info.minRowBytes(); | 
| 344 size_t size = pix_info.getSafeSize(row_bytes); | 344 size_t size = pix_info.getSafeSize(row_bytes); | 
| 345 | 345 | 
| 346 Vector<char> storage(size); | 346 Vector<char> storage(size); | 
| 347 SkPixmap pixmap(pix_info, storage.data(), row_bytes); | 347 SkPixmap pixmap(pix_info, storage.data(), row_bytes); | 
| 348 | 348 | 
| 349 // Before decoding, the frame is not known to be opaque. | 349 // Before decoding, the frame's alpha is unknown and assumed to be | 
| 350 // transparent. This works well with partial decoding, which will be | |
| 351 // transparent until the full first frame is decoded. | |
| 350 sk_sp<SkImage> frame = decoder->CreateFrameAtIndex(0); | 352 sk_sp<SkImage> frame = decoder->CreateFrameAtIndex(0); | 
| 351 ASSERT_TRUE(frame); | 353 ASSERT_TRUE(frame); | 
| 352 EXPECT_FALSE(frame->isOpaque()); | 354 EXPECT_FALSE(frame->isOpaque()); | 
| 353 | 355 | 
| 354 // Force a lazy decode by reading pixels. | 356 // Force a lazy decode by reading pixels. | 
| 355 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); | 357 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); | 
| 356 | 358 | 
| 357 // After decoding, the frame is known to be opaque. | |
| 358 frame = decoder->CreateFrameAtIndex(0); | 359 frame = decoder->CreateFrameAtIndex(0); | 
| 359 ASSERT_TRUE(frame); | 360 ASSERT_TRUE(frame); | 
| 360 EXPECT_TRUE(frame->isOpaque()); | 361 // The GIF file specifies it is opaque. | 
| 362 // When the file is a PNG (test_gif is false), we remain at | |
| 
scroggo_chromium
2017/05/30 19:45:17
The comment seems to imply that all PNG files will
 
cblume
2017/05/30 23:42:13
I will try to word it better.
I meant to say that
 | |
| 363 // the default: transparent | |
| 364 EXPECT_EQ(test_gif, frame->isOpaque()); | |
| 361 | 365 | 
| 362 // Re-generating the opaque-marked frame should not fail. | 366 // Re-generating the opaque-marked frame should not fail. | 
| 363 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); | 367 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); | 
| 364 } | 368 } | 
| 365 } | 369 } | 
| 366 | 370 | 
| 367 // The DeferredImageDecoder would sometimes assume that a frame was a certain | 371 // The DeferredImageDecoder would sometimes assume that a frame was a certain | 
| 368 // size even if the actual decoder reported it had a size of 0 bytes. This test | 372 // size even if the actual decoder reported it had a size of 0 bytes. This test | 
| 369 // verifies that it's fixed by always checking with the actual decoder when | 373 // verifies that it's fixed by always checking with the actual decoder when | 
| 370 // creating a frame. | 374 // creating a frame. | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 387 SharedBuffer::Create(data_->Data(), data_->size()); | 391 SharedBuffer::Create(data_->Data(), data_->size()); | 
| 388 EXPECT_EQ(original_data->size(), data_->size()); | 392 EXPECT_EQ(original_data->size(), data_->size()); | 
| 389 lazy_decoder_->SetData(original_data, false); | 393 lazy_decoder_->SetData(original_data, false); | 
| 390 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data(); | 394 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data(); | 
| 391 EXPECT_EQ(original_data->size(), new_data->size()); | 395 EXPECT_EQ(original_data->size(), new_data->size()); | 
| 392 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(), | 396 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(), | 
| 393 new_data->size())); | 397 new_data->size())); | 
| 394 } | 398 } | 
| 395 | 399 | 
| 396 } // namespace blink | 400 } // namespace blink | 
| OLD | NEW |