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(); }
112 size_t getSizeInBytes()
const;
136 std::unique_ptr<BaseColor> makePixel()
const;
165 void getPixel(
int x,
int y,
BaseColor& outPixel)
const;
180 T getPixel(
int x,
int y)
const;
194 void setPixel(
int x,
int y,
const BaseColor& color);
209 void setPixelColor(
int x,
int y,
const T& color);
219 template<
typename Type>
230 template<
typename Type>
241 template<
typename Type>
252 template<
typename Type>
263 template<
typename Type>
274 template<
typename Type>
293 void updatePixelFormat();
299 T* getPixelData(
unsigned int x,
unsigned int y)
const
309 unsigned char* data_ptr = (
unsigned char*)(mData.data()) + offset;
310 return (T*)(data_ptr);
322 template<
typename Type>
323 void getRGBColorData(
int x,
int y,
RGBColor<Type*>& outColorData)
const;
334 template<
typename Type>
346 template<
typename Type>
358 template<
typename Type>
369 template<
typename Type>
380 template<
typename Type>
396 std::vector<uint8_t> mData;
424 template<
typename Type>
428 getRGBAColorData<Type>(x, y, color_data);
437 template<
typename Type>
441 getRGBColorData<Type>(x, y, color_data);
449 template<
typename Type>
453 getColorValueData<Type>(x, y, channel, color_value);
458 template<
typename Type>
462 getRGBColor<Type>(x, y, color);
467 template<
typename Type>
471 getRGBAColor<Type>(x, y, color);
476 template<
typename Type>
477 void nap::Bitmap::getRGBAColorData(
int x,
int y,
RGBAColor<Type*>& outColor)
const
482 Type* pixel_data = getPixelData<Type>(x, y);
505 template<
typename Type>
506 RGBAColor<Type*> nap::Bitmap::getRGBAColorData(
int x,
int y)
const
508 RGBAColor<Type*> rcolor;
509 getRGBAColorData<Type>(x, y, rcolor);
514 template<
typename Type>
515 void nap::Bitmap::getRGBColorData(
int x,
int y, RGBColor<Type*>& outColor)
const
517 assert(mSurfaceDescriptor.
getNumChannels() >= outColor.getNumberOfChannels());
518 assert(outColor.getValueType() == RTTI_OF(Type));
520 Type* pixel_data = getPixelData<Type>(x, y);
542 template<
typename Type>
543 RGBColor<Type*> nap::Bitmap::getRGBColorData(
int x,
int y)
const
545 RGBColor<Type*> rcolor;
546 getRGBColorData<Type>(x, y, rcolor);
551 template<
typename Type>
552 void nap::Bitmap::getColorValueData(
int x,
int y,
nap::EColorChannel channel, RColor<Type*>& outValue)
const
554 assert(outValue.getValueType() == RTTI_OF(Type));
555 assert(
static_cast<int>(channel) < mSurfaceDescriptor.
getNumChannels());
557 int idx =
static_cast<int>(channel);
569 Type* pixel_data = getPixelData<Type>(x, y);
574 template<
typename Type>
578 getColorValue<Type>(x, y, channel, rvalue);
583 template<
typename Type>
587 getColorValueData(x, y, channel, rvalue);
596 std::unique_ptr<BaseColor> pixel = makePixel();
597 getPixel(x, y, *pixel);
600 if (pixel->get_type().is_derived_from(RTTI_OF(T)))
602 return *(
static_cast<T*
>(pixel.get()));
605 return pixel->convert<T>();
612 if (color.getValueType() == mValueType && !(color.isPointer()))
614 setPixel(x, y, color);
618 std::unique_ptr<BaseColor> new_pixel = makePixel();
620 source_color.
convert(*new_pixel);
621 setPixel(x, y, *new_pixel);
626 void nap::Bitmap::setPixelData(
int x,
int y,
const nap::BaseColor& color)
630 assert(mValueType == color.getValueType());
631 assert(!color.isPointer());
633 switch (color.getNumberOfChannels())