//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// #include "Extensions/BsPixelDataEx.h" #include "Wrappers/BsScriptColor.h" namespace bs { SPtr PixelDataEx::create(const PixelVolume& volume, PixelFormat format) { SPtr pixelData = bs_shared_ptr_new(volume, format); pixelData->allocateInternalBuffer(); return pixelData; } SPtr PixelDataEx::create(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format) { SPtr pixelData = bs_shared_ptr_new(width, height, depth, format); pixelData->allocateInternalBuffer(); return pixelData; } Color PixelDataEx::getPixel(const SPtr& thisPtr, int x, int y, int z) { if (!checkIsLocked(thisPtr)) return thisPtr->getColorAt(x, y, z); else return Color(); } void PixelDataEx::setPixel(const SPtr& thisPtr, const Color& value, int x, int y, int z) { if (!checkIsLocked(thisPtr)) thisPtr->setColorAt(value, x, y, z); } Vector PixelDataEx::getPixels(const SPtr& thisPtr) { if (!checkIsLocked(thisPtr)) return Vector(); return thisPtr->getColors(); } void PixelDataEx::setPixels(const SPtr& thisPtr, const Vector& value) { if (!checkIsLocked(thisPtr)) return; thisPtr->setColors(value); } Vector PixelDataEx::getRawPixels(const SPtr& thisPtr) { if (!checkIsLocked(thisPtr)) return Vector(); Vector output(thisPtr->getSize()); memcpy(output.data(), thisPtr->getData(), thisPtr->getSize()); return output; } void PixelDataEx::setRawPixels(const SPtr& thisPtr, const Vector& value) { if (!checkIsLocked(thisPtr)) return; UINT32 arrayLen = (UINT32)value.size(); if (thisPtr->getSize() != arrayLen) { LOGERR("Unable to set colors, invalid array size.") return; } UINT8* data = thisPtr->getData(); memcpy(data, value.data(), thisPtr->getSize()); } bool PixelDataEx::checkIsLocked(const SPtr& thisPtr) { if (thisPtr->isLocked()) { LOGWRN("Attempting to access a locked pixel data buffer."); return true; } return false; } }