Chromium Code Reviews| 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::setSize(int newWidth, int newHeight) | 97 bool ImageFrame::copyBitmapData(const ImageFrame& other, ColorType targetType) |
| 98 { | |
| 99 if (this == &other) | |
| 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, unsigned char backgroundIndex, bool backgroundIsTransparent) | |
| 108 { | |
| 109 ASSERT(!width() && !height()); | |
| 110 | |
| 111 SkPMColor ctStorage[256]; | |
| 112 SkPMColor* ctStorageIter(ctStorage); | |
| 113 // Copy color palette and set transparent pixel if set. | |
| 114 Vector<PixelData>::const_iterator colorMapEnd = (colorMap.size() <= 256) ? c olorMap.end() : (colorMap.begin() + 256); | |
|
scroggo_chromium
2016/01/06 21:50:40
The style guide seems to recommend using an index
aleksandar.stojiljkovic
2016/01/18 13:58:49
Done.
| |
| 115 for (Vector<PixelData>::const_iterator colorMapIter = colorMap.begin(); colo rMapIter != colorMapEnd; ) | |
| 116 *ctStorageIter++ = *colorMapIter++; | |
| 117 if (backgroundIsTransparent) { | |
| 118 ASSERT(backgroundIndex < colorMap.size()); | |
| 119 ctStorage[backgroundIndex] = 0; | |
| 120 } | |
| 121 // Fill with backgroundIndex to the end. | |
| 122 int remaining = 256 - colorMap.size(); | |
| 123 if (remaining > 0) | |
| 124 memset(ctStorage + 256 - remaining, 0, sizeof(SkPMColor) * remaining); | |
| 125 SkAutoTUnref<SkColorTable> ctable(new SkColorTable(ctStorage, 256)); | |
| 126 size_t rowBytes = (newWidth + sizeof(size_t) - 1) & (~(sizeof(size_t) - 1)); | |
|
scroggo_chromium
2016/01/06 21:50:40
Why'd you choose this rowBytes? If you use zero, S
aleksandar.stojiljkovic
2016/01/18 13:58:49
I think the 0 makes rowBytes equals to newWidth.
scroggo_chromium
2016/04/29 19:48:14
Will you please add a comment explaining this?
| |
| 127 m_bitmap.setInfo(SkImageInfo::Make(newWidth, newHeight, kIndex_8_SkColorType , kPremul_SkAlphaType), rowBytes); | |
| 128 if (!m_bitmap.tryAllocPixels(m_allocator, ctable)) | |
| 129 return false; | |
| 130 memset(getAddr8(0, 0), backgroundIndex, rowBytes * newHeight); | |
| 131 m_hasAlpha = backgroundIsTransparent; | |
| 132 return true; | |
| 133 } | |
| 134 | |
| 135 bool ImageFrame::setSize(int newWidth, int newHeight, SkColor background) | |
| 98 { | 136 { |
| 99 // setSize() should only be called once, it leaks memory otherwise. | 137 // setSize() should only be called once, it leaks memory otherwise. |
| 100 ASSERT(!width() && !height()); | 138 ASSERT(!width() && !height()); |
| 101 | 139 |
| 102 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); | 140 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); |
| 103 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 141 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
| 104 return false; | 142 return false; |
| 105 | 143 |
| 106 zeroFillPixelData(); | 144 m_bitmap.eraseColor(background); |
| 145 m_hasAlpha = !((background >> 24) == 0xFF); | |
|
scroggo_chromium
2016/01/06 21:50:40
Why not SkColorGetA(background)?
aleksandar.stojiljkovic
2016/01/18 13:58:49
Done. Thanks, didn't know about it.
| |
| 146 | |
| 107 return true; | 147 return true; |
| 108 } | 148 } |
| 109 | 149 |
| 110 const SkBitmap& ImageFrame::bitmap() const | 150 const SkBitmap& ImageFrame::bitmap() const |
| 111 { | 151 { |
| 112 return m_bitmap; | 152 return m_bitmap; |
| 113 } | 153 } |
| 114 | 154 |
| 115 bool ImageFrame::hasAlpha() const | 155 bool ImageFrame::hasAlpha() const |
| 116 { | 156 { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 138 // the bitmap has been marked immutable. | 178 // the bitmap has been marked immutable. |
| 139 notifyBitmapIfPixelsChanged(); | 179 notifyBitmapIfPixelsChanged(); |
| 140 m_bitmap.setImmutable(); // Tell the bitmap it's done. | 180 m_bitmap.setImmutable(); // Tell the bitmap it's done. |
| 141 } | 181 } |
| 142 } | 182 } |
| 143 | 183 |
| 144 void ImageFrame::zeroFillFrameRect(const IntRect& rect) | 184 void ImageFrame::zeroFillFrameRect(const IntRect& rect) |
| 145 { | 185 { |
| 146 if (rect.isEmpty()) | 186 if (rect.isEmpty()) |
| 147 return; | 187 return; |
| 148 | 188 if (m_bitmap.colorType() == kIndex_8_SkColorType) { |
| 149 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | 189 int ymax = std::min(rect.y() + rect.height(), m_bitmap.height()); |
| 190 int xcount = std::min(rect.width(), m_bitmap.width() - rect.x()); | |
| 191 for (int j = rect.y(); j < ymax; ++j) { | |
| 192 memset(m_bitmap.getAddr8(0, j), 0xFF, sizeof(uint8_t) * xcount); | |
|
scroggo_chromium
2016/01/06 21:50:40
As stated before, I'm concerned about setting this
aleksandar.stojiljkovic
2016/01/18 13:58:49
Fixed in new patch...
scroggo_chromium
2016/04/29 19:48:14
It's not obvious to me that it is. See comments in
| |
| 193 } | |
| 194 } else { | |
| 195 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | |
| 196 } | |
| 150 setHasAlpha(true); | 197 setHasAlpha(true); |
| 151 } | 198 } |
| 152 | 199 |
| 153 } // namespace blink | 200 } // namespace blink |
| OLD | NEW |