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

Side by Side Diff: third_party/WebKit/Source/platform/exported/WebImage.cpp

Issue 2556723003: Merge color options into ColorBehavior (Closed)
Patch Set: Feedback Created 4 years 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 27 matching lines...) Expand all
38 #include "third_party/skia/include/core/SkImage.h" 38 #include "third_party/skia/include/core/SkImage.h"
39 #include "wtf/PassRefPtr.h" 39 #include "wtf/PassRefPtr.h"
40 #include "wtf/Vector.h" 40 #include "wtf/Vector.h"
41 #include <algorithm> 41 #include <algorithm>
42 #include <memory> 42 #include <memory>
43 43
44 namespace blink { 44 namespace blink {
45 45
46 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) { 46 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) {
47 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); 47 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data);
48 std::unique_ptr<ImageDecoder> decoder( 48 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(
49 ImageDecoder::create(buffer, true, ImageDecoder::AlphaPremultiplied, 49 buffer, true, ImageDecoder::AlphaPremultiplied, ColorBehavior::ignore()));
50 ImageDecoder::ColorSpaceIgnored, nullptr));
51 if (!decoder || !decoder->isSizeAvailable()) 50 if (!decoder || !decoder->isSizeAvailable())
52 return WebImage(); 51 return WebImage();
53 52
54 // Frames are arranged by decreasing size, then decreasing bit depth. 53 // Frames are arranged by decreasing size, then decreasing bit depth.
55 // Pick the frame closest to |desiredSize|'s area without being smaller, 54 // Pick the frame closest to |desiredSize|'s area without being smaller,
56 // which has the highest bit depth. 55 // which has the highest bit depth.
57 const size_t frameCount = decoder->frameCount(); 56 const size_t frameCount = decoder->frameCount();
58 size_t index = 0; // Default to first frame if none are large enough. 57 size_t index = 0; // Default to first frame if none are large enough.
59 int frameAreaAtIndex = 0; 58 int frameAreaAtIndex = 0;
60 for (size_t i = 0; i < frameCount; ++i) { 59 for (size_t i = 0; i < frameCount; ++i) {
(...skipping 16 matching lines...) Expand all
77 ImageFrame* frame = decoder->frameBufferAtIndex(index); 76 ImageFrame* frame = decoder->frameBufferAtIndex(index);
78 return (frame && !decoder->failed()) ? WebImage(frame->bitmap()) : WebImage(); 77 return (frame && !decoder->failed()) ? WebImage(frame->bitmap()) : WebImage();
79 } 78 }
80 79
81 WebVector<WebImage> WebImage::framesFromData(const WebData& data) { 80 WebVector<WebImage> WebImage::framesFromData(const WebData& data) {
82 // This is to protect from malicious images. It should be big enough that it's 81 // This is to protect from malicious images. It should be big enough that it's
83 // never hit in practice. 82 // never hit in practice.
84 const size_t maxFrameCount = 8; 83 const size_t maxFrameCount = 8;
85 84
86 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); 85 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data);
87 std::unique_ptr<ImageDecoder> decoder( 86 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(
88 ImageDecoder::create(buffer, true, ImageDecoder::AlphaPremultiplied, 87 buffer, true, ImageDecoder::AlphaPremultiplied, ColorBehavior::ignore()));
89 ImageDecoder::ColorSpaceIgnored, nullptr));
90 if (!decoder || !decoder->isSizeAvailable()) 88 if (!decoder || !decoder->isSizeAvailable())
91 return WebVector<WebImage>(); 89 return WebVector<WebImage>();
92 90
93 // Frames are arranged by decreasing size, then decreasing bit depth. 91 // Frames are arranged by decreasing size, then decreasing bit depth.
94 // Keep the first frame at every size, has the highest bit depth. 92 // Keep the first frame at every size, has the highest bit depth.
95 const size_t frameCount = decoder->frameCount(); 93 const size_t frameCount = decoder->frameCount();
96 IntSize lastSize; 94 IntSize lastSize;
97 95
98 Vector<WebImage> frames; 96 Vector<WebImage> frames;
99 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { 97 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 130
133 WebImage::WebImage(PassRefPtr<Image> image) { 131 WebImage::WebImage(PassRefPtr<Image> image) {
134 if (!image) 132 if (!image)
135 return; 133 return;
136 134
137 if (sk_sp<SkImage> skImage = image->imageForCurrentFrame()) 135 if (sk_sp<SkImage> skImage = image->imageForCurrentFrame())
138 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); 136 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode);
139 } 137 }
140 138
141 } // namespace blink 139 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/BUILD.gn ('k') | third_party/WebKit/Source/platform/graphics/ColorBehavior.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698