aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Thomas2009-07-07 14:04:18 +0000
committerScott Thomas2009-07-07 14:04:18 +0000
commitbd87b653aca29c593cadcdedfc2208cec51456aa (patch)
tree41e411ab458bc71eacf9d140eabefe376c22ee9a
parent131aaefa0c52393ecbfbb756eb9acad0505a2924 (diff)
downloadscummvm-rg350-bd87b653aca29c593cadcdedfc2208cec51456aa.tar.gz
scummvm-rg350-bd87b653aca29c593cadcdedfc2208cec51456aa.tar.bz2
scummvm-rg350-bd87b653aca29c593cadcdedfc2208cec51456aa.zip
Properly handle odd-sized JPEG files (ie, those not a multiple of 8 pixels)
svn-id: r42220
-rw-r--r--graphics/jpeg.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/graphics/jpeg.cpp b/graphics/jpeg.cpp
index ce31eb0175..0ad2cf7699 100644
--- a/graphics/jpeg.cpp
+++ b/graphics/jpeg.cpp
@@ -354,6 +354,13 @@ bool JPEG::readSOS() {
// Read all the scan MCUs
uint16 xMCU = _w / (_maxFactorH * 8);
uint16 yMCU = _h / (_maxFactorV * 8);
+
+ // Check for non- multiple-of-8 dimensions
+ if (_w % 8 != 0)
+ xMCU++;
+ if (_h % 8 != 0)
+ yMCU++;
+
bool ok = true;
for (int y = 0; ok && (y < yMCU); y++)
for (int x = 0; ok && (x < xMCU); x++)
@@ -478,12 +485,21 @@ bool JPEG::readDataUnit(uint16 x, uint16 y) {
// Convert coordinates from MCU blocks to pixels
x <<= 3;
y <<= 3;
- for (int j = 0; j < 8; j++) {
+
+ // Handle non- multiple-of-8 dimensions
+ byte xLim = 8;
+ byte yLim = 8;
+ if (x*scalingH + 8 > _w)
+ xLim -= (x*scalingH + 8 - _w);
+ if (y*scalingV + 8 > _h)
+ yLim -= (y*scalingV + 8 - _h);
+
+ for (int j = 0; j < yLim; j++) {
for (int sV = 0; sV < scalingV; sV++) {
// Get the beginning of the block line
byte *ptr = (byte *)_currentComp->surface.getBasePtr(x * scalingH, (y + j) * scalingV + sV);
- for (int i = 0; i < 8; i++) {
+ for (int i = 0; i < xLim; i++) {
for (uint8 sH = 0; sH < scalingH; sH++) {
*ptr = (byte)(result[j * 8 + i]);
ptr++;