improved Bitmap python bindings, added a Bitmap::getChannelName function
parent
77a220bee4
commit
7669f09d44
|
@ -356,6 +356,9 @@ public:
|
|||
/// Return whether this image has matching width and height
|
||||
inline bool isSquare() const { return m_size.x == m_size.y; }
|
||||
|
||||
/// Return a string representation of the name of a channel
|
||||
std::string getChannelName(int channelIndex) const;
|
||||
|
||||
/// Return whether this image has an alpha channel
|
||||
inline bool hasAlpha() const {
|
||||
return
|
||||
|
|
|
@ -349,6 +349,33 @@ size_t Bitmap::getBufferSize() const {
|
|||
return bytesPerRow * (size_t) m_size.y;
|
||||
}
|
||||
|
||||
std::string Bitmap::getChannelName(int idx) const {
|
||||
Assert(idx < m_channelCount);
|
||||
char name = '\0';
|
||||
|
||||
switch (m_pixelFormat) {
|
||||
case ELuminance: name = 'L'; break;
|
||||
case ELuminanceAlpha: name = "YA"[idx]; break;
|
||||
case ERGBA:
|
||||
case ERGB: name = "RGBA"[idx]; break;
|
||||
case EXYZA:
|
||||
case EXYZ: name = "XYZA"[idx]; break;
|
||||
case ESpectrumAlphaWeight:
|
||||
case ESpectrumAlpha:
|
||||
if (idx == m_channelCount-1)
|
||||
return m_pixelFormat == ESpectrumAlpha ? "A" : "W";
|
||||
else if (idx == m_channelCount-2 && m_pixelFormat == ESpectrumAlphaWeight)
|
||||
return "A";
|
||||
case ESpectrum:
|
||||
std::pair<Float, Float> coverage = Spectrum::getBinCoverage(idx);
|
||||
return formatString("%.2f-%.2fnm", coverage.first, coverage.second);
|
||||
default:
|
||||
Log(EError, "Unknown pixel format!");
|
||||
}
|
||||
|
||||
return std::string(1, name);
|
||||
}
|
||||
|
||||
void Bitmap::updateChannelCount() {
|
||||
switch (m_pixelFormat) {
|
||||
case ELuminance: m_channelCount = 1; break;
|
||||
|
|
|
@ -145,7 +145,6 @@ struct path_to_python_str {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
struct TSpectrum_to_Spectrum {
|
||||
static PyObject* convert(const TSpectrum<Float, SPECTRUM_SAMPLES> &spectrum) {
|
||||
return bp::incref(bp::object(Spectrum(spectrum)).ptr());
|
||||
|
@ -777,6 +776,7 @@ void export_core() {
|
|||
.def("getBytesPerComponent", &Bitmap::getBytesPerComponent)
|
||||
.def("getBytesPerPixel", &Bitmap::getBytesPerPixel)
|
||||
.def("getBufferSize", &Bitmap::getBufferSize)
|
||||
.def("getChannelName", &Bitmap::getChannelName)
|
||||
.def("getPixel", &Bitmap::getPixel, BP_RETURN_VALUE)
|
||||
.def("setPixel", &Bitmap::setPixel)
|
||||
.def("drawHLine", &Bitmap::drawHLine)
|
||||
|
@ -788,6 +788,7 @@ void export_core() {
|
|||
.def("convert", &bitmap_convert_2, BP_RETURN_VALUE)
|
||||
.def("convert", &bitmap_convert_3, BP_RETURN_VALUE)
|
||||
.def("convert", &bitmap_convert_4, BP_RETURN_VALUE)
|
||||
.def("rotateFlip", &Bitmap::rotateFlip, BP_RETURN_VALUE)
|
||||
.def("fromByteArray", &bitmap_fromByteArray)
|
||||
.def("toByteArray", &bitmap_toByteArray_1)
|
||||
.def("toByteArray", &bitmap_toByteArray_2);
|
||||
|
@ -827,6 +828,25 @@ void export_core() {
|
|||
.value("EAuto", Bitmap::EAuto)
|
||||
.export_values();
|
||||
|
||||
bp::enum_<Bitmap::ERotateFlipType>("ERotateFlipType")
|
||||
.value("ERotateNoneFlipNone", Bitmap::ERotateNoneFlipNone)
|
||||
.value("ERotate180FlipXY", Bitmap::ERotate180FlipXY)
|
||||
.value("ERotate90FlipNone", Bitmap::ERotate90FlipNone)
|
||||
.value("ERotate270FlipXY", Bitmap::ERotate270FlipXY)
|
||||
.value("ERotate180FlipNone", Bitmap::ERotate180FlipNone)
|
||||
.value("ERotateNoneFlipXY", Bitmap::ERotateNoneFlipXY)
|
||||
.value("ERotate270FlipNone", Bitmap::ERotate270FlipNone)
|
||||
.value("ERotate90FlipXY", Bitmap::ERotate90FlipXY)
|
||||
.value("ERotateNoneFlipX", Bitmap::ERotateNoneFlipX)
|
||||
.value("ERotate180FlipY", Bitmap::ERotate180FlipY)
|
||||
.value("ERotate90FlipX", Bitmap::ERotate90FlipX)
|
||||
.value("ERotate270FlipY", Bitmap::ERotate270FlipY)
|
||||
.value("ERotate180FlipX", Bitmap::ERotate180FlipX)
|
||||
.value("ERotateNoneFlipY", Bitmap::ERotateNoneFlipY)
|
||||
.value("ERotate270FlipX", Bitmap::ERotate270FlipX)
|
||||
.value("ERotate90FlipY", Bitmap::ERotate90FlipY)
|
||||
.export_values();
|
||||
|
||||
BP_SETSCOPE(coreModule);
|
||||
|
||||
BP_CLASS(FileResolver, Object, bp::init<>())
|
||||
|
|
Loading…
Reference in New Issue