1 /* 2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. 3 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 11 * The above copyright notice and this permission notice shall be included in all 12 * copies or substantial portions of the Software. 13 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 * SOFTWARE. 21 */ 22 23 #ifndef VBITMAP_H 24 #define VBITMAP_H 25 26 #include "vrect.h" 27 #include <vsharedptr.h> 28 29 V_BEGIN_NAMESPACE 30 31 class VBitmap { 32 public: 33 enum class Format: uchar { 34 Invalid, 35 Alpha8, 36 ARGB32, 37 ARGB32_Premultiplied 38 }; 39 40 VBitmap() = default; 41 VBitmap(size_t w, size_t h, VBitmap::Format format); 42 VBitmap(uchar *data, size_t w, size_t h, size_t bytesPerLine, VBitmap::Format format); 43 void reset(uchar *data, size_t w, size_t h, size_t stride, VBitmap::Format format); 44 void reset(size_t w, size_t h, VBitmap::Format format=Format::ARGB32_Premultiplied); 45 size_t stride() const; 46 size_t width() const; 47 size_t height() const; 48 size_t depth() const; 49 VBitmap::Format format() const; 50 bool valid() const; 51 uchar * data(); 52 uchar * data() const; 53 VRect rect() const; 54 VSize size() const; 55 void fill(uint pixel); 56 void updateLuma(); 57 private: 58 struct Impl { 59 std::unique_ptr<uchar[]> mOwnData{nullptr}; 60 uchar * mRoData{nullptr}; 61 uint mWidth{0}; 62 uint mHeight{0}; 63 uint mStride{0}; 64 uchar mDepth{0}; 65 VBitmap::Format mFormat{VBitmap::Format::Invalid}; 66 ImplImpl67 explicit Impl(size_t width, size_t height, VBitmap::Format format) 68 { 69 reset(width, height, format); 70 } ImplImpl71 explicit Impl(uchar *data, size_t w, size_t h, size_t bytesPerLine, VBitmap::Format format) 72 { 73 reset(data, w, h, bytesPerLine, format); 74 } rectImpl75 VRect rect() const { return VRect(0, 0, mWidth, mHeight);} sizeImpl76 VSize size() const { return VSize(mWidth, mHeight); } strideImpl77 size_t stride() const { return mStride; } widthImpl78 size_t width() const { return mWidth; } heightImpl79 size_t height() const { return mHeight; } dataImpl80 uchar * data() { return mRoData ? mRoData : mOwnData.get(); } formatImpl81 VBitmap::Format format() const { return mFormat; } 82 void reset(uchar *, size_t, size_t, size_t, VBitmap::Format); 83 void reset(size_t, size_t, VBitmap::Format); 84 static uchar depth(VBitmap::Format format); 85 void fill(uint); 86 void updateLuma(); 87 }; 88 89 rc_ptr<Impl> mImpl; 90 }; 91 92 V_END_NAMESPACE 93 94 #endif // VBITMAP_H 95