opuntiaOS - an operating system targeting x86 and ARMv7
at master 1.8 kB view raw
1/* 2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors. 3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com> 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9#include <libg/PixelBitmap.h> 10 11namespace LG { 12 13PixelBitmap::PixelBitmap(Color* buffer, size_t width, size_t height, PixelBitmapFormat format) 14 : m_data(buffer) 15 , m_bounds(0, 0, width, height) 16 , m_should_free(false) 17 , m_format(format) 18{ 19} 20 21PixelBitmap::PixelBitmap(size_t width, size_t height, PixelBitmapFormat format) 22 : m_bounds(0, 0, width, height) 23 , m_data((Color*)malloc(sizeof(Color) * width * height)) 24 , m_should_free(true) 25 , m_format(format) 26{ 27} 28 29PixelBitmap::PixelBitmap(const PixelBitmap& bitmap) 30 : m_data(nullptr) 31 , m_bounds(bitmap.m_bounds) 32 , m_should_free(bitmap.m_should_free) 33 , m_format(bitmap.m_format) 34{ 35 if (m_should_free) { 36 size_t len = width() * height() * sizeof(Color); 37 m_data = (Color*)malloc(len); 38 memcpy((uint8_t*)m_data, (uint8_t*)bitmap.m_data, len); 39 } else { 40 m_data = bitmap.m_data; 41 } 42} 43 44PixelBitmap::PixelBitmap(PixelBitmap&& moved_bitmap) noexcept 45 : m_data(moved_bitmap.m_data) 46 , m_bounds(moved_bitmap.m_bounds) 47 , m_should_free(moved_bitmap.m_should_free) 48 , m_format(moved_bitmap.m_format) 49{ 50 moved_bitmap.m_data = nullptr; 51 moved_bitmap.bounds().set_width(0); 52 moved_bitmap.bounds().set_height(0); 53 moved_bitmap.m_should_free = false; 54} 55 56void PixelBitmap::resize(size_t width, size_t height) 57{ 58 clear(); 59 bounds().set_width(width); 60 bounds().set_height(height); 61 m_data = (Color*)malloc(sizeof(Color) * width * height); 62 m_should_free = true; 63} 64 65} // namespace LG