Fix crash while rotating several thumbnails in File Browser

Fix issue #4858 and possibly #5310
This commit is contained in:
Hombre 2019-09-03 22:18:20 +02:00
parent bb97a30058
commit ce04447c7a
4 changed files with 66 additions and 24 deletions

View File

@ -1483,6 +1483,7 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT
delete labView;
delete baseImg;
/*
// calculate scale
if (params.coarse.rotate == 90 || params.coarse.rotate == 270) {
myscale = scale * thumbImg->getWidth() / fh;
@ -1491,19 +1492,20 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT
}
myscale = 1.0 / myscale;
/* // apply crop
if (params.crop.enabled) {
int ix = 0;
for (int i=0; i<fh; i++)
for (int j=0; j<fw; j++)
if (i<params.crop.y/myscale || i>(params.crop.y+params.crop.h)/myscale || j<params.crop.x/myscale || j>(params.crop.x+params.crop.w)/myscale) {
readyImg->data[ix++] /= 3;
readyImg->data[ix++] /= 3;
readyImg->data[ix++] /= 3;
}
else
ix += 3;
}*/
// apply crop
if (params.crop.enabled) {
int ix = 0;
for (int i=0; i<fh; i++)
for (int j=0; j<fw; j++)
if (i<params.crop.y/myscale || i>(params.crop.y+params.crop.h)/myscale || j<params.crop.x/myscale || j>(params.crop.x+params.crop.w)/myscale) {
readyImg->data[ix++] /= 3;
readyImg->data[ix++] /= 3;
readyImg->data[ix++] /= 3;
}
else
ix += 3;
}
*/
return readyImg;
}

View File

@ -255,17 +255,20 @@ void FileBrowserEntry::_updateImage(rtengine::IImage8* img, double s, const rten
const bool resize = !preview || prew != img->getWidth();
prew = img->getWidth ();
GThreadLock lock;
// Check if image has been rotated since last time
rotated = preview && newLandscape != landscape;
if (resize) {
delete [] preview;
if (preview) {
delete [] preview;
}
preview = new guint8 [prew * preh * 3];
}
memcpy(preview, img->getData(), prew * preh * 3);
{
GThreadLock lock;
updateBackBuffer ();
}
}
landscape = newLandscape;
@ -318,24 +321,36 @@ bool FileBrowserEntry::motionNotify (int x, int y)
cropParams->y = action_y + (y - press_y) / scale;
cropParams->h += oy - cropParams->y;
cropgl->cropHeight1Resized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio);
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
} else if (state == SResizeH2 && cropgl) {
cropParams->h = action_y + (y - press_y) / scale;
cropgl->cropHeight2Resized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio);
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
} else if (state == SResizeW1 && cropgl) {
int ox = cropParams->x;
cropParams->x = action_x + (x - press_x) / scale;
cropParams->w += ox - cropParams->x;
cropgl->cropWidth1Resized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio);
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
} else if (state == SResizeW2 && cropgl) {
cropParams->w = action_x + (x - press_x) / scale;
cropgl->cropWidth2Resized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio);
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
} else if (state == SResizeTL && cropgl) {
int ox = cropParams->x;
@ -345,7 +360,10 @@ bool FileBrowserEntry::motionNotify (int x, int y)
cropParams->y = action_y + (y - press_y) / scale;
cropParams->h += oy - cropParams->y;
cropgl->cropTopLeftResized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio);
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
} else if (state == SResizeTR && cropgl) {
cropParams->w = action_x + (x - press_x) / scale;
@ -353,7 +371,10 @@ bool FileBrowserEntry::motionNotify (int x, int y)
cropParams->y = action_y + (y - press_y) / scale;
cropParams->h += oy - cropParams->y;
cropgl->cropTopRightResized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio);
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
} else if (state == SResizeBL && cropgl) {
int ox = cropParams->x;
@ -361,19 +382,28 @@ bool FileBrowserEntry::motionNotify (int x, int y)
cropParams->w += ox - cropParams->x;
cropParams->h = action_y + (y - press_y) / scale;
cropgl->cropBottomLeftResized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio);
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
} else if (state == SResizeBR && cropgl) {
cropParams->w = action_x + (x - press_x) / scale;
cropParams->h = action_y + (y - press_y) / scale;
cropgl->cropBottomRightResized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio);
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
} else if (state == SCropMove && cropgl) {
cropParams->x = action_x + (x - press_x) / scale;
cropParams->y = action_y + (y - press_y) / scale;
cropgl->cropMoved (cropParams->x, cropParams->y, cropParams->w, cropParams->h);
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
} else if (state == SCropSelecting && cropgl) {
int cx1 = press_x, cy1 = press_y;
@ -396,7 +426,10 @@ bool FileBrowserEntry::motionNotify (int x, int y)
cropParams->h = cy1 - cy2 + 1;
}
{
MYREADERLOCK(l, lockRW);
updateBackBuffer ();
}
parent->redrawNeeded (this);
}
@ -564,6 +597,7 @@ bool FileBrowserEntry::releaseNotify (int button, int type, int bstate, int x, i
bool FileBrowserEntry::onArea (CursorArea a, int x, int y)
{
MYREADERLOCK(l, lockRW);
if (!drawable || !preview) {
return false;
}
@ -764,6 +798,8 @@ void FileBrowserEntry::drawStraightenGuide (Cairo::RefPtr<Cairo::Context> cr)
int y2 = action_y;
int x2 = action_x;
{
MYREADERLOCK(l, lockRW);
if (x2 < prex + ofsX + startx) {
y2 = y1 - (double)(y1 - y2) * (x1 - (prex + ofsX + startx)) / (x1 - x2);
x2 = prex + ofsX + startx;
@ -779,6 +815,7 @@ void FileBrowserEntry::drawStraightenGuide (Cairo::RefPtr<Cairo::Context> cr)
x2 = x1 - (double)(x1 - x2) * (y1 - (preh + prey + ofsY + starty - 1)) / (y1 - y2);
y2 = preh + prey + ofsY + starty - 1;
}
}
cr->set_line_width (1.5);
cr->set_source_rgb (1.0, 1.0, 1.0);

View File

@ -494,6 +494,7 @@ void ThumbBrowserEntryBase::resize (int h)
height = h;
int old_preh = preh;
int old_prew = prew;
// dimensions of the button set
int bsw = 0, bsh = 0;
@ -555,9 +556,11 @@ void ThumbBrowserEntryBase::resize (int h)
width = bsw + 2 * sideMargin + 2 * borderWidth;
}
if (preh != old_preh) {
delete [] preview;
preview = nullptr;
if (preh != old_preh || prew != old_prew) { // if new thumbnail height or new orientation
if (preview) {
delete [] preview;
preview = nullptr;
}
refreshThumbnailImage ();
} else if (backBuffer) {
backBuffer->setDirty(true); // This will force a backBuffer update on queue_draw

View File

@ -49,17 +49,17 @@ class Thumbnail
rtengine::Thumbnail* tpp;
int tw, th; // dimensions of timgdata (it stores tpp->width and tpp->height in processed mode for simplicity)
float imgRatio; // hack to avoid rounding error
// double scale; // portion of the sizes of the processed thumbnail image and the full scale image
// double scale; // portion of the sizes of the processed thumbnail image and the full scale image
const std::unique_ptr<rtengine::procparams::ProcParams> pparams;
bool pparamsValid;
bool imageLoading;
// these are the data of the result image of the last getthumbnailimage call (for caching purposes)
unsigned char* lastImg;
int lastW;
int lastH;
double lastScale;
unsigned char* lastImg; // pointer to the processed and scaled base ImageIO image
int lastW; // non rotated width of the cached ImageIO image
int lastH; // non rotated height of the cached ImageIO image
double lastScale; // scale of the cached ImageIO image
// exif & date/time strings
Glib::ustring exifString;