OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * Copyright (C) 2008, 2009 Google, Inc. | 3 * Copyright (C) 2008, 2009 Google, Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 bool ImageFrame::copyBitmapData(const ImageFrame& other) | 87 bool ImageFrame::copyBitmapData(const ImageFrame& other) |
88 { | 88 { |
89 if (this == &other) | 89 if (this == &other) |
90 return true; | 90 return true; |
91 | 91 |
92 m_hasAlpha = other.m_hasAlpha; | 92 m_hasAlpha = other.m_hasAlpha; |
93 m_bitmap.reset(); | 93 m_bitmap.reset(); |
94 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); | 94 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
95 } | 95 } |
96 | 96 |
97 bool ImageFrame::copyBitmapData(const ImageFrame& other, ColorType targetType) | |
scroggo_chromium
2015/12/03 21:47:21
This method is almost identical to the other one.
aleksandar.stojiljkovic
2015/12/04 00:07:35
Again had the same reasoning - as this one is conv
| |
98 { | |
99 if (this == &other) | |
scroggo_chromium
2015/12/03 21:47:21
I wonder if we ever reach this condition, or if it
aleksandar.stojiljkovic
2015/12/04 00:07:34
Yes, that is good point. ASSERT and return false i
| |
100 return true; | |
101 | |
102 m_hasAlpha = other.m_hasAlpha; | |
103 m_bitmap.reset(); | |
104 return other.m_bitmap.copyTo(&m_bitmap, static_cast<SkColorType>(targetType) ); | |
105 } | |
106 | |
107 bool ImageFrame::setSizeIndex8(int newWidth, int newHeight, const Vector<PixelDa ta>& colorMap, size_t indexOfTransparent) | |
108 { | |
109 ASSERT(!width() && !height()); | |
110 | |
111 SkPMColor ctStorage[256]; | |
112 SkPMColor* ctStorageIter(ctStorage); | |
113 // Copy color palette and set transparent pixel. | |
114 Vector<PixelData>::const_iterator colorMapEnd = (colorMap.size() <= 256) ? c olorMap.end() : (colorMap.begin() + 256); | |
115 for (Vector<PixelData>::const_iterator colorMapIter = colorMap.begin(); colo rMapIter != colorMapEnd; ) | |
116 *ctStorageIter++ = *colorMapIter++; | |
117 if (indexOfTransparent < colorMap.size()) { | |
118 ctStorage[indexOfTransparent] = 0; | |
119 } | |
120 // Fill with transparent to the end. | |
121 int remaining = 256 - colorMap.size(); | |
122 if (remaining > 0) | |
123 memset(ctStorage + 256 - remaining, 0, sizeof(SkPMColor) * remaining); | |
124 SkAutoTUnref<SkColorTable> ctable(new SkColorTable(ctStorage, 256)); | |
125 m_bitmap.setInfo(SkImageInfo::Make(newWidth, newHeight, kIndex_8_SkColorType , kPremul_SkAlphaType)); | |
scroggo_chromium
2015/12/03 21:47:21
FWIW, since the alpha is either 255 or zero, this
| |
126 if (!m_bitmap.tryAllocPixels(m_allocator, ctable)) | |
127 return false; | |
128 size_t transparent = 0xFF; | |
129 if (indexOfTransparent < colorMap.size()) { | |
scroggo_chromium
2015/12/03 21:47:21
Otherwise, we'll just initialize the bitmap to 255
aleksandar.stojiljkovic
2015/12/04 00:07:34
Yes, partially downloaded content in that case wou
| |
130 transparent = indexOfTransparent; | |
131 } | |
132 for (int j = 0; j < newHeight; ++j) { | |
133 memset(getAddr8(0, j), transparent, sizeof(uint8_t) * newWidth); | |
scroggo_chromium
2015/12/03 21:47:21
I think you could do this for the entire image wit
aleksandar.stojiljkovic
2015/12/04 00:07:34
Acknowledged.
| |
134 } | |
135 m_hasAlpha = true; | |
136 return true; | |
137 } | |
138 | |
97 bool ImageFrame::setSize(int newWidth, int newHeight) | 139 bool ImageFrame::setSize(int newWidth, int newHeight) |
98 { | 140 { |
99 // setSize() should only be called once, it leaks memory otherwise. | 141 // setSize() should only be called once, it leaks memory otherwise. |
100 ASSERT(!width() && !height()); | 142 ASSERT(!width() && !height()); |
101 | 143 |
102 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); | 144 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); |
103 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 145 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
104 return false; | 146 return false; |
105 | 147 |
106 zeroFillPixelData(); | 148 zeroFillPixelData(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 // the bitmap has been marked immutable. | 180 // the bitmap has been marked immutable. |
139 notifyBitmapIfPixelsChanged(); | 181 notifyBitmapIfPixelsChanged(); |
140 m_bitmap.setImmutable(); // Tell the bitmap it's done. | 182 m_bitmap.setImmutable(); // Tell the bitmap it's done. |
141 } | 183 } |
142 } | 184 } |
143 | 185 |
144 void ImageFrame::zeroFillFrameRect(const IntRect& rect) | 186 void ImageFrame::zeroFillFrameRect(const IntRect& rect) |
145 { | 187 { |
146 if (rect.isEmpty()) | 188 if (rect.isEmpty()) |
147 return; | 189 return; |
148 | 190 if (m_bitmap.colorType() == kIndex_8_SkColorType) { |
149 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | 191 int ymax = std::min(rect.y() + rect.height(), m_bitmap.height()); |
192 int xcount = std::min(rect.width(), m_bitmap.width() - rect.x()); | |
193 for (int j = rect.y(); j < ymax; ++j) { | |
194 memset(m_bitmap.getAddr8(0, j), 0xFF, sizeof(uint8_t) * xcount); | |
scroggo_chromium
2015/12/03 21:47:21
Again, this is going to erase to an arbitrary colo
aleksandar.stojiljkovic
2015/12/04 00:07:34
Colortable returned by this decoder always have 25
scroggo_chromium
2015/12/08 22:24:51
Except that if the image has 256 declared colors,
| |
195 } | |
196 } else { | |
197 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | |
198 } | |
150 setHasAlpha(true); | 199 setHasAlpha(true); |
151 } | 200 } |
152 | 201 |
153 } // namespace blink | 202 } // namespace blink |
OLD | NEW |