9 #include "surfacedescriptor.h"
12 #include <nap/resource.h>
13 #include <utility/dllexport.h>
14 #include <nap/signalslot.h>
20 struct SurfaceDescriptor;
80 bool empty()
const {
return mData.empty(); }
85 int getWidth()
const {
return mSurfaceDescriptor.getWidth(); }
90 int getHeight()
const {
return mSurfaceDescriptor.getHeight(); }
105 const void*
getData()
const {
return mData.data(); }
110 size_t getSizeInBytes()
const;
139 std::unique_ptr<BaseColor> makePixel()
const;
168 void getPixel(
int x,
int y,
BaseColor& outPixel)
const;
183 T getPixel(
int x,
int y)
const;
197 void setPixel(
int x,
int y,
const BaseColor& color);
212 void setPixelColor(
int x,
int y,
const T& color);
222 template<
typename Type>
233 template<
typename Type>
244 template<
typename Type>
255 template<
typename Type>
266 template<
typename Type>
277 template<
typename Type>
296 void updatePixelFormat();
302 T* getPixelData(
unsigned int x,
unsigned int y)
const
312 unsigned char* data_ptr = (
unsigned char*)(mData.data()) + offset;
313 return (T*)(data_ptr);
325 template<
typename Type>
326 void getRGBColorData(
int x,
int y,
RGBColor<Type*>& outColorData)
const;
337 template<
typename Type>
349 template<
typename Type>
361 template<
typename Type>
372 template<
typename Type>
383 template<
typename Type>
399 std::vector<uint8_t> mData;
427 template<
typename Type>
431 getRGBAColorData<Type>(x, y, color_data);
440 template<
typename Type>
444 getRGBColorData<Type>(x, y, color_data);
452 template<
typename Type>
456 getColorValueData<Type>(x, y, channel, color_value);
461 template<
typename Type>
465 getRGBColor<Type>(x, y, color);
470 template<
typename Type>
474 getRGBAColor<Type>(x, y, color);
479 template<
typename Type>
480 void nap::Bitmap::getRGBAColorData(
int x,
int y,
RGBAColor<Type*>& outColor)
const
485 Type* pixel_data = getPixelData<Type>(x, y);
508 template<
typename Type>
509 RGBAColor<Type*> nap::Bitmap::getRGBAColorData(
int x,
int y)
const
511 RGBAColor<Type*> rcolor;
512 getRGBAColorData<Type>(x, y, rcolor);
517 template<
typename Type>
518 void nap::Bitmap::getRGBColorData(
int x,
int y, RGBColor<Type*>& outColor)
const
520 assert(mSurfaceDescriptor.
getNumChannels() >= outColor.getNumberOfChannels());
521 assert(outColor.getValueType() == RTTI_OF(Type));
523 Type* pixel_data = getPixelData<Type>(x, y);
545 template<
typename Type>
546 RGBColor<Type*> nap::Bitmap::getRGBColorData(
int x,
int y)
const
548 RGBColor<Type*> rcolor;
549 getRGBColorData<Type>(x, y, rcolor);
554 template<
typename Type>
555 void nap::Bitmap::getColorValueData(
int x,
int y,
nap::EColorChannel channel, RColor<Type*>& outValue)
const
557 assert(outValue.getValueType() == RTTI_OF(Type));
558 assert(
static_cast<int>(channel) < mSurfaceDescriptor.
getNumChannels());
560 int idx =
static_cast<int>(channel);
572 Type* pixel_data = getPixelData<Type>(x, y);
577 template<
typename Type>
581 getColorValue<Type>(x, y, channel, rvalue);
586 template<
typename Type>
590 getColorValueData(x, y, channel, rvalue);
599 std::unique_ptr<BaseColor> pixel = makePixel();
600 getPixel(x, y, *pixel);
603 if (pixel->get_type().is_derived_from(RTTI_OF(T)))
605 return *(
static_cast<T*
>(pixel.get()));
608 return pixel->convert<T>();
615 if (color.getValueType() == mValueType && !(color.isPointer()))
617 setPixel(x, y, color);
621 std::unique_ptr<BaseColor> new_pixel = makePixel();
623 source_color.
convert(*new_pixel);
624 setPixel(x, y, *new_pixel);
629 void nap::Bitmap::setPixelData(
int x,
int y,
const nap::BaseColor& color)
633 assert(mValueType == color.getValueType());
634 assert(!color.isPointer());
636 switch (color.getNumberOfChannels())