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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 bool ImageFrame::copyBitmapData(const ImageFrame& other) | 86 bool ImageFrame::copyBitmapData(const ImageFrame& other) |
87 { | 87 { |
88 if (this == &other) | 88 if (this == &other) |
89 return true; | 89 return true; |
90 | 90 |
91 m_hasAlpha = other.m_hasAlpha; | 91 m_hasAlpha = other.m_hasAlpha; |
92 m_bitmap.reset(); | 92 m_bitmap.reset(); |
93 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); | 93 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
94 } | 94 } |
95 | 95 |
96 bool ImageFrame::setSize(int newWidth, int newHeight) | 96 bool ImageFrame::copyBitmapData(const ImageFrame& other, ColorType targetType) |
97 { | |
98 if (this == &other) | |
99 return true; | |
100 | |
101 m_hasAlpha = other.m_hasAlpha; | |
102 m_bitmap.reset(); | |
103 return other.m_bitmap.copyTo(&m_bitmap, static_cast<SkColorType>(targetType) ); | |
104 } | |
105 | |
106 bool ImageFrame::setSizeIndex8(int newWidth, int newHeight, const Vector<PixelDa ta>& colorMap, unsigned backgroundIndex, bool backgroundIsTransparent) | |
107 { | |
108 ASSERT(!width() && !height()); | |
109 | |
110 // Copy color palette and set transparent pixel if set. | |
111 SkPMColor ctStorage[256]; | |
112 ASSERT(colorMap.size() <= 256); | |
113 for (size_t i = 0; i < colorMap.size(); ++i) | |
114 ctStorage[i] = colorMap[i]; | |
115 if (backgroundIsTransparent) { | |
116 ASSERT(backgroundIndex < colorMap.size()); | |
117 ctStorage[backgroundIndex] = SK_ColorTRANSPARENT; | |
118 } | |
119 // Fill with transparent to the end. | |
120 int remaining = 256 - colorMap.size(); | |
121 if (remaining > 0) | |
122 memset(ctStorage + 256 - remaining, SK_ColorTRANSPARENT, sizeof(SkPMColo r) * remaining); | |
123 | |
124 SkAutoTUnref<SkColorTable> ctable(new SkColorTable(ctStorage, 256)); | |
125 size_t rowBytes = (newWidth + sizeof(size_t) - 1) & (~(sizeof(size_t) - 1)); | |
126 m_bitmap.setInfo(SkImageInfo::Make(newWidth, newHeight, kIndex_8_SkColorType , kPremul_SkAlphaType), rowBytes); | |
127 if (!m_bitmap.tryAllocPixels(m_allocator, ctable)) | |
128 return false; | |
129 memset(getAddr8(0, 0), backgroundIndex, rowBytes * newHeight); | |
130 m_hasAlpha = backgroundIsTransparent; | |
131 return true; | |
132 } | |
133 | |
134 bool ImageFrame::setSize(int newWidth, int newHeight, SkColor background) | |
97 { | 135 { |
98 // setSize() should only be called once, it leaks memory otherwise. | 136 // setSize() should only be called once, it leaks memory otherwise. |
99 ASSERT(!width() && !height()); | 137 ASSERT(!width() && !height()); |
100 | 138 |
101 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); | 139 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); |
102 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 140 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
103 return false; | 141 return false; |
104 | 142 |
105 zeroFillPixelData(); | 143 m_bitmap.eraseColor(background); |
144 m_hasAlpha = !(SkColorGetA(background) == 0xFF); | |
145 | |
106 return true; | 146 return true; |
107 } | 147 } |
108 | 148 |
109 const SkBitmap& ImageFrame::bitmap() const | 149 const SkBitmap& ImageFrame::bitmap() const |
110 { | 150 { |
111 return m_bitmap; | 151 return m_bitmap; |
112 } | 152 } |
113 | 153 |
114 bool ImageFrame::hasAlpha() const | 154 bool ImageFrame::hasAlpha() const |
115 { | 155 { |
(...skipping 21 matching lines...) Expand all Loading... | |
137 // the bitmap has been marked immutable. | 177 // the bitmap has been marked immutable. |
138 notifyBitmapIfPixelsChanged(); | 178 notifyBitmapIfPixelsChanged(); |
139 m_bitmap.setImmutable(); // Tell the bitmap it's done. | 179 m_bitmap.setImmutable(); // Tell the bitmap it's done. |
140 } | 180 } |
141 } | 181 } |
142 | 182 |
143 void ImageFrame::zeroFillFrameRect(const IntRect& rect) | 183 void ImageFrame::zeroFillFrameRect(const IntRect& rect) |
144 { | 184 { |
145 if (rect.isEmpty()) | 185 if (rect.isEmpty()) |
146 return; | 186 return; |
147 | |
148 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | 187 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
149 setHasAlpha(true); | 188 setHasAlpha(true); |
150 } | 189 } |
151 | 190 |
191 void ImageFrame::zeroFillFrameRectIndex8(const IntRect& rect, unsigned char tran sparentIndex) | |
scroggo_chromium
2016/04/29 19:48:14
transparentIndex is never used.
| |
192 { | |
193 ASSERT(m_bitmap.colorType() == kIndex_8_SkColorType); | |
194 | |
195 if (rect.isEmpty()) | |
196 return; | |
197 int ymax = std::min(rect.y() + rect.height(), m_bitmap.height()); | |
198 int xcount = std::min(rect.width(), m_bitmap.width() - rect.x()); | |
199 for (int j = rect.y(); j < ymax; ++j) { | |
200 memset(m_bitmap.getAddr8(0, j), 0xFF, sizeof(uint8_t) * xcount); | |
scroggo_chromium
2016/04/29 19:48:14
It's not obvious to me that 0xFF in the color tabl
| |
201 } | |
202 m_hasAlpha = true; | |
203 } | |
204 | |
152 } // namespace blink | 205 } // namespace blink |
OLD | NEW |