aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-08-09 14:35:08 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-08-09 14:35:08 -0700
commit4b9ef3210bfe249acc1b63dadf6cf009275a9eaa (patch)
tree1d0e76b4d251509cb6b9ca5e29842bf5deddfdb9
parentca49c72894c52d770bd7c2669337b32fe83c6c2e (diff)
downloadsyslinux.git-4b9ef3210bfe249acc1b63dadf6cf009275a9eaa.tar.gz
syslinux.git-4b9ef3210bfe249acc1b63dadf6cf009275a9eaa.tar.xz
syslinux.git-4b9ef3210bfe249acc1b63dadf6cf009275a9eaa.zip
tinyjpeg: fix yuv420p, correct some of the initalization code
Fix the yuv420p in the presence of partial pixels (if we have an odd number of pixels in this mode, we include the chroma pixel.) Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--com32/lib/jpeg/bgr24.c6
-rw-r--r--com32/lib/jpeg/bgra32.c6
-rw-r--r--com32/lib/jpeg/grey.c6
-rw-r--r--com32/lib/jpeg/rgb24.c6
-rw-r--r--com32/lib/jpeg/rgba32.c6
-rw-r--r--com32/lib/jpeg/tinyjpeg.c6
-rw-r--r--com32/lib/jpeg/yuv420p.c100
7 files changed, 77 insertions, 59 deletions
diff --git a/com32/lib/jpeg/bgr24.c b/com32/lib/jpeg/bgr24.c
index d72e29b2..855b855f 100644
--- a/com32/lib/jpeg/bgr24.c
+++ b/com32/lib/jpeg/bgr24.c
@@ -347,12 +347,12 @@ static int initialize_bgr24(struct jdec_private *priv,
unsigned int *bytes_per_blocklines,
unsigned int *bytes_per_mcu)
{
- if (priv->components[0] == NULL)
- priv->components[0] = (uint8_t *)malloc(priv->width * priv->height * 3);
if (!priv->bytes_per_row[0])
priv->bytes_per_row[0] = priv->width * 3;
+ if (!priv->components[0])
+ priv->components[0] = malloc(priv->height * priv->bytes_per_row[0]);
- bytes_per_blocklines[0] = priv->bytes_per_row[0];
+ bytes_per_blocklines[0] = priv->bytes_per_row[0] << 3;
bytes_per_mcu[0] = 3*8;
return !priv->components[0];
diff --git a/com32/lib/jpeg/bgra32.c b/com32/lib/jpeg/bgra32.c
index 1aa1835b..9a1ab309 100644
--- a/com32/lib/jpeg/bgra32.c
+++ b/com32/lib/jpeg/bgra32.c
@@ -364,12 +364,12 @@ static int initialize_bgra32(struct jdec_private *priv,
unsigned int *bytes_per_blocklines,
unsigned int *bytes_per_mcu)
{
- if (priv->components[0] == NULL)
- priv->components[0] = (uint8_t *)malloc(priv->width * priv->height * 4);
if (!priv->bytes_per_row[0])
priv->bytes_per_row[0] = priv->width * 4;
+ if (!priv->components[0])
+ priv->components[0] = malloc(priv->height * priv->bytes_per_row[0]);
- bytes_per_blocklines[0] = priv->bytes_per_row[0];
+ bytes_per_blocklines[0] = priv->bytes_per_row[0] << 3;
bytes_per_mcu[0] = 4*8;
return !priv->components[0];
diff --git a/com32/lib/jpeg/grey.c b/com32/lib/jpeg/grey.c
index 2f114744..6710ede6 100644
--- a/com32/lib/jpeg/grey.c
+++ b/com32/lib/jpeg/grey.c
@@ -91,12 +91,12 @@ static int initialize_grey(struct jdec_private *priv,
unsigned int *bytes_per_blocklines,
unsigned int *bytes_per_mcu)
{
- if (priv->components[0] == NULL)
- priv->components[0] = (uint8_t *)malloc(priv->width * priv->height);
if (!priv->bytes_per_row[0])
priv->bytes_per_row[0] = priv->width;
+ if (!priv->components[0])
+ priv->components[0] = malloc(priv->height * priv->bytes_per_row[0]);
- bytes_per_blocklines[0] = priv->bytes_per_row[0];
+ bytes_per_blocklines[0] = priv->bytes_per_row[0] << 3;
bytes_per_mcu[0] = 8;
return !priv->components[0];
diff --git a/com32/lib/jpeg/rgb24.c b/com32/lib/jpeg/rgb24.c
index 49a080de..e1481f31 100644
--- a/com32/lib/jpeg/rgb24.c
+++ b/com32/lib/jpeg/rgb24.c
@@ -346,12 +346,12 @@ static int initialize_rgb24(struct jdec_private *priv,
unsigned int *bytes_per_blocklines,
unsigned int *bytes_per_mcu)
{
- if (priv->components[0] == NULL)
- priv->components[0] = (uint8_t *)malloc(priv->width * priv->height * 3);
if (!priv->bytes_per_row[0])
priv->bytes_per_row[0] = priv->width * 3;
+ if (priv->components[0] == NULL)
+ priv->components[0] = malloc(priv->height * priv->bytes_per_row[0]);
- bytes_per_blocklines[0] = priv->bytes_per_row[0];
+ bytes_per_blocklines[0] = priv->bytes_per_row[0] << 3;
bytes_per_mcu[0] = 3*8;
return !priv->components[0];
diff --git a/com32/lib/jpeg/rgba32.c b/com32/lib/jpeg/rgba32.c
index da08344d..d04f0f13 100644
--- a/com32/lib/jpeg/rgba32.c
+++ b/com32/lib/jpeg/rgba32.c
@@ -364,12 +364,12 @@ static int initialize_rgba32(struct jdec_private *priv,
unsigned int *bytes_per_blocklines,
unsigned int *bytes_per_mcu)
{
- if (priv->components[0] == NULL)
- priv->components[0] = (uint8_t *)malloc(priv->width * priv->height * 4);
if (!priv->bytes_per_row[0])
priv->bytes_per_row[0] = priv->width * 4;
+ if (!priv->components[0])
+ priv->components[0] = malloc(priv->height * priv->bytes_per_row[0]);
- bytes_per_blocklines[0] = priv->bytes_per_row[0];
+ bytes_per_blocklines[0] = priv->bytes_per_row[0] << 3;
bytes_per_mcu[0] = 4*8;
return !priv->components[0];
diff --git a/com32/lib/jpeg/tinyjpeg.c b/com32/lib/jpeg/tinyjpeg.c
index a9395a5d..3c6070f4 100644
--- a/com32/lib/jpeg/tinyjpeg.c
+++ b/com32/lib/jpeg/tinyjpeg.c
@@ -917,9 +917,9 @@ int tinyjpeg_decode(struct jdec_private *priv,
resync(priv);
/* Don't forget to that block can be either 8 or 16 lines */
- bytes_per_blocklines[0] <<= yshift_by_mcu;
- bytes_per_blocklines[1] <<= yshift_by_mcu;
- bytes_per_blocklines[2] <<= yshift_by_mcu;
+ bytes_per_blocklines[0] <<= yshift_by_mcu-3;
+ bytes_per_blocklines[1] <<= yshift_by_mcu-3;
+ bytes_per_blocklines[2] <<= yshift_by_mcu-3;
bytes_per_mcu[0] <<= xshift_by_mcu-3;
bytes_per_mcu[1] <<= xshift_by_mcu-3;
diff --git a/com32/lib/jpeg/yuv420p.c b/com32/lib/jpeg/yuv420p.c
index 0c84cada..c512089c 100644
--- a/com32/lib/jpeg/yuv420p.c
+++ b/com32/lib/jpeg/yuv420p.c
@@ -35,8 +35,6 @@
* yuv420p.c
*/
-/**** XXXX: THIS IS NOT YET CONVERTED TO HANDLE PARTIAL MCUS ****/
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -74,19 +72,21 @@ static void YCrCB_to_YUV420P_1x1(struct jdec_private *priv, int sx, int sy)
p = priv->plane[0];
y = priv->Y;
- for (i=0; i<8; i++)
+ for (i = sy; i > 0; i--)
{
- memcpy(p, y, 8);
+ memcpy(p, y, sx);
p += priv->bytes_per_row[0];
- y+=8;
+ y += 8;
}
p = priv->plane[1];
s = priv->Cb;
- for (i=0; i<8; i+=2)
+ for (i = sy; i > 0; i--)
{
- for (j=0; j<8; j+=2, s+=2)
+ for (j = sx; j >= 0; j -= 2) {
*p++ = *s;
+ s += 2;
+ }
s += 8; /* Skip one line */
p += priv->bytes_per_row[1] - 4;
}
@@ -95,8 +95,10 @@ static void YCrCB_to_YUV420P_1x1(struct jdec_private *priv, int sx, int sy)
s = priv->Cr;
for (i=0; i<8; i+=2)
{
- for (j=0; j<8; j+=2, s+=2)
+ for (j = sx; j >= 0; j -= 2) {
*p++ = *s;
+ s += 2;
+ }
s += 8; /* Skip one line */
p += priv->bytes_per_row[2] - 4;
}
@@ -116,27 +118,29 @@ static void YCrCB_to_YUV420P_2x1(struct jdec_private *priv, int sx, int sy)
p = priv->plane[0];
y1 = priv->Y;
- for (i=0; i<8; i++)
+ for (i = sy; i > 0; i--)
{
- memcpy(p, y1, 16);
+ memcpy(p, y1, sx);
p += priv->bytes_per_row[0];
y1 += 16;
}
+ sx = (sx+1) >> 1;
+
p = priv->plane[1];
s = priv->Cb;
- for (i=0; i<8; i+=2)
+ for (i = sy; i > 0; i -= 2)
{
- memcpy(p, s, 8);
+ memcpy(p, s, sx);
s += 16; /* Skip one line */
p += priv->bytes_per_row[1];
}
p = priv->plane[2];
s = priv->Cr;
- for (i=0; i<8; i+=2)
+ for (i = sy; i > 0; i -= 2)
{
- memcpy(p, s, 8);
+ memcpy(p, s, sx);
s += 16; /* Skip one line */
p += priv->bytes_per_row[2];
}
@@ -154,34 +158,40 @@ static void YCrCB_to_YUV420P_2x1(struct jdec_private *priv, int sx, int sy)
static void YCrCB_to_YUV420P_1x2(struct jdec_private *priv, int sx, int sy)
{
const unsigned char *s, *y;
- unsigned char *p;
+ unsigned char *p, *pr;
int i,j;
p = priv->plane[0];
y = priv->Y;
- for (i=0; i<16; i++)
+ for (i = sy; i > 0; i++)
{
- memcpy(p, y, 8);
+ memcpy(p, y, sx);
p+=priv->bytes_per_row[0];
y+=8;
}
- p = priv->plane[1];
+ pr = priv->plane[1];
s = priv->Cb;
- for (i=0; i<8; i++)
+ for (i = sy; i > 0; i -= 2)
{
- for (j=0; j<8; j+=2, s+=2)
+ p = pr;
+ for (j = sx; j > 0; j -= 2) {
*p++ = *s;
- p += priv->bytes_per_row[1] - 4;
+ s += 2;
+ }
+ pr += priv->bytes_per_row[1];
}
- p = priv->plane[2];
+ pr = priv->plane[2];
s = priv->Cr;
for (i=0; i<8; i++)
{
- for (j=0; j<8; j+=2, s+=2)
+ p = pr;
+ for (j = sx; j > 0; j -= 2) {
*p++ = *s;
- p += priv->bytes_per_row[2] - 4;
+ s += 2;
+ }
+ pr += priv->bytes_per_row[2] - 4;
}
}
@@ -201,27 +211,29 @@ static void YCrCB_to_YUV420P_2x2(struct jdec_private *priv, int sx, int sy)
p = priv->plane[0];
y1 = priv->Y;
- for (i=0; i<16; i++)
+ for (i = sy; i > 0; i--)
{
- memcpy(p, y1, 16);
+ memcpy(p, y1, sx);
p += priv->bytes_per_row[0];
y1 += 16;
}
+ sx = (sx+1) >> 1;
+
p = priv->plane[1];
s = priv->Cb;
- for (i=0; i<8; i++)
+ for (i = sy; i > 0; i -= 2)
{
- memcpy(p, s, 8);
+ memcpy(p, s, sx);
s += 8;
p += priv->bytes_per_row[1];
}
p = priv->plane[2];
s = priv->Cr;
- for (i=0; i<8; i++)
+ for (i = sy; i > 0; i -= 2)
{
- memcpy(p, s, 8);
+ memcpy(p, s, sx);
s += 8;
p += priv->bytes_per_row[2];
}
@@ -231,26 +243,32 @@ static int initialize_yuv420p(struct jdec_private *priv,
unsigned int *bytes_per_blocklines,
unsigned int *bytes_per_mcu)
{
- if (priv->components[0] == NULL)
- priv->components[0] = (uint8_t *)malloc(priv->width * priv->height);
- if (priv->components[1] == NULL)
- priv->components[1] = (uint8_t *)malloc(priv->width * priv->height/4);
- if (priv->components[2] == NULL)
- priv->components[2] = (uint8_t *)malloc(priv->width * priv->height/4);
+ int half_height = (priv->height + 1) >> 2;
+ int half_width = (priv->width + 1) >> 2;
+
if (!priv->bytes_per_row[0])
priv->bytes_per_row[0] = priv->width;
+ if (!priv->components[0])
+ priv->components[0] = malloc(priv->height * priv->bytes_per_row[0]);
+
if (!priv->bytes_per_row[1])
- priv->bytes_per_row[1] = priv->width/2;
+ priv->bytes_per_row[1] = half_width;
+ if (!priv->components[1])
+ priv->components[1] = malloc(half_height * priv->bytes_per_row[1]);
+
if (!priv->bytes_per_row[2])
- priv->bytes_per_row[2] = priv->width/2;
+ priv->bytes_per_row[2] = half_width;
+ if (!priv->components[2])
+ priv->components[2] = malloc(half_height * priv->bytes_per_row[2]);
- bytes_per_blocklines[0] = priv->bytes_per_row[0];
- bytes_per_blocklines[1] = priv->bytes_per_row[1]/2;
- bytes_per_blocklines[2] = priv->bytes_per_row[2]/2;
bytes_per_mcu[0] = 8;
bytes_per_mcu[1] = 4;
bytes_per_mcu[2] = 4;
+ bytes_per_blocklines[0] = priv->width << 3;
+ bytes_per_blocklines[1] = half_width << 2;
+ bytes_per_blocklines[2] = half_width << 2;
+
/* Return nonzero on failure */
return !priv->components[0] || !priv->components[1] || !priv->components[2];
}