On preview widgets for the Gradient tool (center & angle). Also includes some rudimentary bounds checking (optional) when accessing some kind of array.
This commit is contained in:
@@ -36,6 +36,7 @@ EditBuffer::~EditBuffer() {
|
||||
}
|
||||
|
||||
void EditBuffer::createBuffer(int width, int height) {
|
||||
//printf("Appel de createBuffer %d x %d\n", width, height);
|
||||
resize (width, height);
|
||||
}
|
||||
|
||||
@@ -76,30 +77,33 @@ EditUniqueID EditBuffer::getEditID() {
|
||||
else return EUID_None;
|
||||
}
|
||||
|
||||
// Resize buffers if they already exist
|
||||
void EditBuffer::resize(int newWidth, int newHeight) {
|
||||
EditSubscriber* subscriber = NULL;
|
||||
if (dataProvider && (subscriber = dataProvider->getCurrSubscriber())) {
|
||||
if (subscriber->getEditingType() == ET_OBJECTS) {
|
||||
if (objectMap && (objectMap->get_width() != newWidth || objectMap->get_height() != newHeight))
|
||||
objectMap->unreference();
|
||||
resize(newWidth, newHeight, dataProvider ? dataProvider->getCurrSubscriber() : NULL);
|
||||
}
|
||||
|
||||
if (!objectMap) {
|
||||
// Resize buffers if they already exist
|
||||
void EditBuffer::resize(int newWidth, int newHeight, EditSubscriber* newSubscriber) {
|
||||
if (newSubscriber) {
|
||||
if (newSubscriber->getEditingType() == ET_OBJECTS) {
|
||||
if (objectMap && (objectMap->get_width() != newWidth || objectMap->get_height() != newHeight))
|
||||
objectMap.clear();
|
||||
|
||||
if (!objectMap && newWidth && newHeight) {
|
||||
objectMap = Cairo::ImageSurface::create(Cairo::FORMAT_A8, newWidth, newHeight);
|
||||
}
|
||||
if (objectMode==OM_65535) {
|
||||
if (objectMap2) {
|
||||
if (objectMap2->get_width() != newWidth || objectMap2->get_height() != newHeight) {
|
||||
objectMap2->unreference();
|
||||
objectMap2.clear();
|
||||
}
|
||||
}
|
||||
if (!objectMap2) {
|
||||
if (!objectMap2 && newWidth && newHeight) {
|
||||
objectMap2 = Cairo::ImageSurface::create(Cairo::FORMAT_A8, newWidth, newHeight);
|
||||
}
|
||||
}
|
||||
// OM_255 -> deleting objectMap2, if any
|
||||
else if (objectMap2)
|
||||
objectMap2->unreference();
|
||||
objectMap2.clear();
|
||||
|
||||
// Should never happen!
|
||||
if (imgFloatBuffer) {
|
||||
@@ -115,8 +119,8 @@ void EditBuffer::resize(int newWidth, int newHeight) {
|
||||
}
|
||||
}
|
||||
|
||||
if (subscriber->getEditingType() == ET_PIPETTE) {
|
||||
if (subscriber->getEditBufferType() == BT_IMAGEFLOAT) {
|
||||
if (newSubscriber->getEditingType() == ET_PIPETTE) {
|
||||
if (newSubscriber->getEditBufferType() == BT_IMAGEFLOAT) {
|
||||
if (!imgFloatBuffer)
|
||||
imgFloatBuffer = new Imagefloat(newWidth, newHeight);
|
||||
else
|
||||
@@ -127,7 +131,7 @@ void EditBuffer::resize(int newWidth, int newHeight) {
|
||||
imgFloatBuffer = NULL;
|
||||
}
|
||||
|
||||
if (subscriber->getEditBufferType() == BT_LABIMAGE) {
|
||||
if (newSubscriber->getEditBufferType() == BT_LABIMAGE) {
|
||||
if (LabBuffer && (LabBuffer->W != newWidth && LabBuffer->H != newHeight)) {
|
||||
delete LabBuffer;
|
||||
LabBuffer = NULL;
|
||||
@@ -140,43 +144,49 @@ void EditBuffer::resize(int newWidth, int newHeight) {
|
||||
LabBuffer = NULL;
|
||||
}
|
||||
|
||||
if (subscriber->getEditBufferType() == BT_SINGLEPLANE_FLOAT) {
|
||||
if (newSubscriber->getEditBufferType() == BT_SINGLEPLANE_FLOAT) {
|
||||
singlePlaneBuffer.allocate(newWidth, newHeight);
|
||||
}
|
||||
else if (singlePlaneBuffer.data)
|
||||
singlePlaneBuffer.allocate(0,0);
|
||||
|
||||
// Should never happen!
|
||||
if (objectMap ) objectMap->unreference();
|
||||
if (objectMap2) objectMap2->unreference();
|
||||
if (objectMap ) objectMap.clear();
|
||||
if (objectMap2) objectMap2.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool EditBuffer::bufferCreated() {
|
||||
if (dataProvider && dataProvider->getCurrSubscriber()) {
|
||||
switch (dataProvider->getCurrSubscriber()->getEditBufferType()) {
|
||||
case (BT_IMAGEFLOAT):
|
||||
return imgFloatBuffer != NULL;
|
||||
case (BT_LABIMAGE):
|
||||
return LabBuffer != NULL;
|
||||
case (BT_SINGLEPLANE_FLOAT):
|
||||
return singlePlaneBuffer.data != NULL;
|
||||
EditSubscriber* subscriber;
|
||||
if (dataProvider && (subscriber = dataProvider->getCurrSubscriber())) {
|
||||
switch (subscriber->getEditingType()) {
|
||||
case ET_PIPETTE:
|
||||
switch (dataProvider->getCurrSubscriber()->getEditBufferType()) {
|
||||
case (BT_IMAGEFLOAT):
|
||||
return imgFloatBuffer != NULL;
|
||||
case (BT_LABIMAGE):
|
||||
return LabBuffer != NULL;
|
||||
case (BT_SINGLEPLANE_FLOAT):
|
||||
return singlePlaneBuffer.data != NULL;
|
||||
}
|
||||
break;
|
||||
case (ET_OBJECTS):
|
||||
return bool(objectMap);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned short EditBuffer::getObjectID(const Coord& location) {
|
||||
unsigned short id = 0;
|
||||
int EditBuffer::getObjectID(const Coord& location) {
|
||||
int id = 0;
|
||||
|
||||
if (objectMap)
|
||||
if (objectMap && location.x>0 && location.y>0 && location.x<objectMap->get_width() && location.y<objectMap->get_height()) {
|
||||
id = (unsigned short)(*( objectMap->get_data() + location.y * objectMap->get_stride() + location.x ));
|
||||
|
||||
if (objectMap2)
|
||||
id |= (unsigned short)(*( objectMap->get_data() + location.y * objectMap->get_stride() + location.x )) << 8;
|
||||
|
||||
return id;
|
||||
if (objectMap2)
|
||||
id |= (unsigned short)(*( objectMap->get_data() + location.y * objectMap->get_stride() + location.x )) << 8;
|
||||
}
|
||||
return id-1;
|
||||
}
|
||||
|
||||
void EditBuffer::getPipetteData(float* v, int x, int y, int squareSize) {
|
||||
|
Reference in New Issue
Block a user