mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Finally correct fix for setPixel out of bounds error
This commit is contained in:
parent
8376081885
commit
a0ae751a5e
@ -579,12 +579,10 @@ void PictureFlowPrivate::resetSlides()
|
|||||||
|
|
||||||
static QImage prepareSurface(QImage img, int w, int h)
|
static QImage prepareSurface(QImage img, int w, int h)
|
||||||
{
|
{
|
||||||
Qt::TransformationMode mode = Qt::SmoothTransformation;
|
img = img.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
img = img.scaled(w, h, Qt::IgnoreAspectRatio, mode);
|
|
||||||
|
|
||||||
// slightly larger, to accommodate for the reflection
|
// slightly larger, to accommodate for the reflection
|
||||||
int hs = int(h * REFLECTION_FACTOR);
|
int hs = int(h * REFLECTION_FACTOR);
|
||||||
int hofs = 0;
|
|
||||||
|
|
||||||
// offscreen buffer: black is sweet
|
// offscreen buffer: black is sweet
|
||||||
QImage result(hs, w, QImage::Format_RGB16);
|
QImage result(hs, w, QImage::Format_RGB16);
|
||||||
@ -595,21 +593,20 @@ static QImage prepareSurface(QImage img, int w, int h)
|
|||||||
// (and much better and faster to work row-wise, i.e in one scanline)
|
// (and much better and faster to work row-wise, i.e in one scanline)
|
||||||
for(int x = 0; x < w; x++)
|
for(int x = 0; x < w; x++)
|
||||||
for(int y = 0; y < h; y++)
|
for(int y = 0; y < h; y++)
|
||||||
result.setPixel(hofs + y, x, img.pixel(x, y));
|
result.setPixel(y, x, img.pixel(x, y));
|
||||||
|
|
||||||
// create the reflection
|
// create the reflection
|
||||||
int ht = hs - h - hofs;
|
int ht = hs - h;
|
||||||
int hte = ht;
|
|
||||||
for(int x = 0; x < w; x++)
|
for(int x = 0; x < w; x++)
|
||||||
for(int y = 0; y < ht; y++)
|
for(int y = 0; y < ht; y++)
|
||||||
{
|
{
|
||||||
QRgb color = img.pixel(x, img.height()-y-1);
|
QRgb color = img.pixel(x, img.height()-y-1);
|
||||||
//QRgb565 color = img.scanLine(img.height()-y-1) + x*sizeof(QRgb565); //img.pixel(x, img.height()-y-1);
|
//QRgb565 color = img.scanLine(img.height()-y-1) + x*sizeof(QRgb565); //img.pixel(x, img.height()-y-1);
|
||||||
int a = qAlpha(color);
|
int a = qAlpha(color);
|
||||||
int r = qRed(color) * a / 256 * (hte - y) / hte * 3/5;
|
int r = qRed(color) * a / 256 * (ht - y) / ht * 3/5;
|
||||||
int g = qGreen(color) * a / 256 * (hte - y) / hte * 3/5;
|
int g = qGreen(color) * a / 256 * (ht - y) / ht * 3/5;
|
||||||
int b = qBlue(color) * a / 256 * (hte - y) / hte * 3/5;
|
int b = qBlue(color) * a / 256 * (ht - y) / ht * 3/5;
|
||||||
result.setPixel(h+hofs+y, x, qRgb(r, g, b));
|
result.setPixel(h+y, x, qRgb(r, g, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -801,9 +798,14 @@ QRect PictureFlowPrivate::renderCenterSlide(const SlideInfo &slide) {
|
|||||||
QRect rect(buffer.width()/2 - sw/2, 0, sw, h-1);
|
QRect rect(buffer.width()/2 - sw/2, 0, sw, h-1);
|
||||||
int left = rect.left();
|
int left = rect.left();
|
||||||
|
|
||||||
for(int x = 0; x < MIN(h-1, sh-1); x++)
|
if (left >= 0) {
|
||||||
for(int y = 0; y < sw; y++)
|
int xcon = MIN(h-1, sh-1);
|
||||||
buffer.setPixel(left + y, 1+x, src->pixel(x, y));
|
int ycon = MIN(sw, buffer.width() - left);
|
||||||
|
|
||||||
|
for(int x = 0; x < xcon; x++)
|
||||||
|
for(int y = 0; y < ycon; y++)
|
||||||
|
buffer.setPixel(left + y, 1+x, src->pixel(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user