aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/jpeg
diff options
context:
space:
mode:
Diffstat (limited to 'com32/lib/jpeg')
-rw-r--r--com32/lib/jpeg/bgr24.c17
-rw-r--r--com32/lib/jpeg/bgra32.c21
-rw-r--r--com32/lib/jpeg/grey.c23
-rw-r--r--com32/lib/jpeg/rgb24.c17
-rw-r--r--com32/lib/jpeg/rgba32.c17
-rw-r--r--com32/lib/jpeg/tinyjpeg-internal.h1
-rw-r--r--com32/lib/jpeg/tinyjpeg.c38
-rw-r--r--com32/lib/jpeg/yuv420p.c39
8 files changed, 111 insertions, 62 deletions
diff --git a/com32/lib/jpeg/bgr24.c b/com32/lib/jpeg/bgr24.c
index 465d58e7..3f2f4f90 100644
--- a/com32/lib/jpeg/bgr24.c
+++ b/com32/lib/jpeg/bgr24.c
@@ -84,7 +84,7 @@ static void YCrCB_to_BGR24_1x1(struct jdec_private *priv)
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = priv->width*3 - 8*3;
+ offset_to_next_row = priv->bytes_per_row[0] - 8*3;
for (i=0; i<8; i++) {
for (j=0;j<8;j++) {
@@ -140,7 +140,7 @@ static void YCrCB_to_BGR24_2x1(struct jdec_private *priv)
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = priv->width*3 - 16*3;
+ offset_to_next_row = priv->bytes_per_row[0] - 16*3;
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
@@ -202,11 +202,11 @@ static void YCrCB_to_BGR24_1x2(struct jdec_private *priv)
#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
p = priv->plane[0];
- p2 = priv->plane[0] + priv->width*3;
+ p2 = priv->plane[0] + priv->bytes_per_row[0];
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = 2*priv->width*3 - 8*3;
+ offset_to_next_row = 2*priv->bytes_per_row[0] - 8*3;
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
@@ -270,11 +270,11 @@ static void YCrCB_to_BGR24_2x2(struct jdec_private *priv)
#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
p = priv->plane[0];
- p2 = priv->plane[0] + priv->width*3;
+ p2 = priv->plane[0] + priv->bytes_per_row[0];
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = (priv->width*3*2) - 16*3;
+ offset_to_next_row = 2*priv->bytes_per_row[0] - 16*3;
for (i=0; i<8; i++) {
for (j=0;j<8;j++) {
@@ -338,7 +338,10 @@ static int initialize_bgr24(struct jdec_private *priv,
{
if (priv->components[0] == NULL)
priv->components[0] = (uint8_t *)malloc(priv->width * priv->height * 3);
- bytes_per_blocklines[0] = priv->width * 3;
+ if (!priv->bytes_per_row[0])
+ priv->bytes_per_row[0] = priv->width * 3;
+
+ bytes_per_blocklines[0] = priv->bytes_per_row[0];
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 ba0db700..fe6b813a 100644
--- a/com32/lib/jpeg/bgra32.c
+++ b/com32/lib/jpeg/bgra32.c
@@ -84,7 +84,7 @@ static void YCrCB_to_BGRA32_1x1(struct jdec_private *priv)
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = priv->width*4 - 8*4;
+ offset_to_next_row = priv->bytes_per_row[0] - 8*4;
for (i=0; i<8; i++) {
for (j=0;j<8;j++) {
@@ -142,7 +142,7 @@ static void YCrCB_to_BGRA32_2x1(struct jdec_private *priv)
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = priv->width*4 - 16*4;
+ offset_to_next_row = priv->bytes_per_row[0] - 16*4;
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
@@ -208,11 +208,11 @@ static void YCrCB_to_BGRA32_1x2(struct jdec_private *priv)
#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
p = priv->plane[0];
- p2 = priv->plane[0] + priv->width*4;
+ p2 = priv->plane[0] + priv->bytes_per_row[0];
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = 2*priv->width*4 - 8*4;
+ offset_to_next_row = 2*priv->bytes_per_row[0] - 8*4;
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
@@ -280,11 +280,11 @@ static void YCrCB_to_BGRA32_2x2(struct jdec_private *priv)
#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
p = priv->plane[0];
- p2 = priv->plane[0] + priv->width*4;
+ p2 = priv->plane[0] + priv->bytes_per_row[0];
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = (priv->width*4*2) - 16*4;
+ offset_to_next_row = 2*priv->bytes_per_row[0] - 16*4;
for (i=0; i<8; i++) {
for (j=0;j<8;j++) {
@@ -351,12 +351,15 @@ static void YCrCB_to_BGRA32_2x2(struct jdec_private *priv)
}
static int initialize_bgra32(struct jdec_private *priv,
- unsigned int *bytes_per_blocklines,
- unsigned int *bytes_per_mcu)
+ 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);
- bytes_per_blocklines[0] = priv->width * 4;
+ if (!priv->bytes_per_row[0])
+ priv->bytes_per_row[0] = priv->width * 4;
+
+ bytes_per_blocklines[0] = priv->bytes_per_row[0];
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 edeb74a9..bb55b7e2 100644
--- a/com32/lib/jpeg/grey.c
+++ b/com32/lib/jpeg/grey.c
@@ -54,7 +54,7 @@ static void YCrCB_to_Grey_1x1(struct jdec_private *priv)
p = priv->plane[0];
y = priv->Y;
- offset_to_next_row = priv->width;
+ offset_to_next_row = priv->bytes_per_row[0];
for (i=0; i<8; i++) {
memcpy(p, y, 8);
@@ -74,14 +74,16 @@ static void YCrCB_to_Grey_2x1(struct jdec_private *priv)
const unsigned char *y;
unsigned char *p;
unsigned int i;
+ int offset_to_next_row;
p = priv->plane[0];
y = priv->Y;
+ offset_to_next_row = priv->bytes_per_row[0];
for (i=0; i<8; i++) {
memcpy(p, y, 16);
y += 16;
- p += priv->width;
+ p += offset_to_next_row;
}
}
@@ -99,14 +101,16 @@ static void YCrCB_to_Grey_1x2(struct jdec_private *priv)
const unsigned char *y;
unsigned char *p;
unsigned int i;
+ int offset_to_next_row;
p = priv->plane[0];
y = priv->Y;
+ offset_to_next_row = priv->bytes_per_row[0];
for (i=0; i<16; i++) {
memcpy(p, y, 8);
y += 8;
- p += priv->width;
+ p += offset_to_next_row;
}
}
@@ -123,24 +127,29 @@ static void YCrCB_to_Grey_2x2(struct jdec_private *priv)
const unsigned char *y;
unsigned char *p;
unsigned int i;
+ int offset_to_next_row;
p = priv->plane[0];
y = priv->Y;
+ offset_to_next_row = priv->bytes_per_row[0];
for (i=0; i<16; i++) {
memcpy(p, y, 16);
y += 16;
- p += priv->width;
+ p += offset_to_next_row;
}
}
static int initialize_grey(struct jdec_private *priv,
- unsigned int *bytes_per_blocklines,
- unsigned int *bytes_per_mcu)
+ 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);
- bytes_per_blocklines[0] = priv->width * 3;
+ if (!priv->bytes_per_row[0])
+ priv->bytes_per_row[0] = priv->width * 3;
+
+ bytes_per_blocklines[0] = priv->bytes_per_row[0];
bytes_per_mcu[0] = 3*8;
return !priv->components[0];
diff --git a/com32/lib/jpeg/rgb24.c b/com32/lib/jpeg/rgb24.c
index 65c06953..d3ee07a8 100644
--- a/com32/lib/jpeg/rgb24.c
+++ b/com32/lib/jpeg/rgb24.c
@@ -84,7 +84,7 @@ static void YCrCB_to_RGB24_1x1(struct jdec_private *priv)
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = priv->width*3 - 8*3;
+ offset_to_next_row = priv->bytes_per_row[0] - 8*3;
for (i=0; i<8; i++) {
for (j=0;j<8;j++) {
@@ -139,7 +139,7 @@ static void YCrCB_to_RGB24_2x1(struct jdec_private *priv)
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = priv->width*3 - 16*3;
+ offset_to_next_row = priv->bytes_per_row[0] - 16*3;
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
@@ -202,11 +202,11 @@ static void YCrCB_to_RGB24_1x2(struct jdec_private *priv)
#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
p = priv->plane[0];
- p2 = priv->plane[0] + priv->width*3;
+ p2 = priv->plane[0] + priv->bytes_per_row[0];
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = 2*priv->width*3 - 8*3;
+ offset_to_next_row = 2*priv->bytes_per_row[0] - 8*3;
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
@@ -269,11 +269,11 @@ static void YCrCB_to_RGB24_2x2(struct jdec_private *priv)
#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
p = priv->plane[0];
- p2 = priv->plane[0] + priv->width*3;
+ p2 = priv->plane[0] + priv->bytes_per_row[0];
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = (priv->width*3*2) - 16*3;
+ offset_to_next_row = 2*priv->bytes_per_row[0] - 16*3;
for (i=0; i<8; i++) {
for (j=0;j<8;j++) {
@@ -337,7 +337,10 @@ static int initialize_rgb24(struct jdec_private *priv,
{
if (priv->components[0] == NULL)
priv->components[0] = (uint8_t *)malloc(priv->width * priv->height * 3);
- bytes_per_blocklines[0] = priv->width * 3;
+ if (!priv->bytes_per_row[0])
+ priv->bytes_per_row[0] = priv->width * 3;
+
+ bytes_per_blocklines[0] = priv->bytes_per_row[0];
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 2934bcd8..2ad91125 100644
--- a/com32/lib/jpeg/rgba32.c
+++ b/com32/lib/jpeg/rgba32.c
@@ -84,7 +84,7 @@ static void YCrCB_to_RGBA32_1x1(struct jdec_private *priv)
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = priv->width*4 - 8*4;
+ offset_to_next_row = priv->bytes_per_row[0] - 8*4;
for (i=0; i<8; i++) {
for (j=0;j<8;j++) {
@@ -140,7 +140,7 @@ static void YCrCB_to_RGBA32_2x1(struct jdec_private *priv)
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = priv->width*4 - 16*4;
+ offset_to_next_row = priv->bytes_per_row[0] - 16*4;
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
@@ -206,11 +206,11 @@ static void YCrCB_to_RGBA32_1x2(struct jdec_private *priv)
#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
p = priv->plane[0];
- p2 = priv->plane[0] + priv->width*4;
+ p2 = priv->plane[0] + priv->bytes_per_row[0];
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = 2*priv->width*4 - 8*4;
+ offset_to_next_row = 2*priv->bytes_per_row[0] - 8*4;
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
@@ -277,11 +277,11 @@ static void YCrCB_to_RGBA32_2x2(struct jdec_private *priv)
#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
p = priv->plane[0];
- p2 = priv->plane[0] + priv->width*4;
+ p2 = priv->plane[0] + priv->bytes_per_row[0];
Y = priv->Y;
Cb = priv->Cb;
Cr = priv->Cr;
- offset_to_next_row = (priv->width*4*2) - 16*4;
+ offset_to_next_row = 2*priv->bytes_per_row[0] - 16*4;
for (i=0; i<8; i++) {
for (j=0;j<8;j++) {
@@ -353,7 +353,10 @@ static int initialize_rgba32(struct jdec_private *priv,
{
if (priv->components[0] == NULL)
priv->components[0] = (uint8_t *)malloc(priv->width * priv->height * 4);
- bytes_per_blocklines[0] = priv->width * 4;
+ if (!priv->bytes_per_row[0])
+ priv->bytes_per_row[0] = priv->width * 4;
+
+ bytes_per_blocklines[0] = priv->bytes_per_row[0];
bytes_per_mcu[0] = 4*8;
return !priv->components[0];
diff --git a/com32/lib/jpeg/tinyjpeg-internal.h b/com32/lib/jpeg/tinyjpeg-internal.h
index abad0844..a4145817 100644
--- a/com32/lib/jpeg/tinyjpeg-internal.h
+++ b/com32/lib/jpeg/tinyjpeg-internal.h
@@ -76,6 +76,7 @@ struct jdec_private
{
/* Public variables */
uint8_t *components[COMPONENTS];
+ unsigned int bytes_per_row[COMPONENTS];
unsigned int width, height; /* Size of the image */
unsigned int flags;
diff --git a/com32/lib/jpeg/tinyjpeg.c b/com32/lib/jpeg/tinyjpeg.c
index ca180a03..a93a5125 100644
--- a/com32/lib/jpeg/tinyjpeg.c
+++ b/com32/lib/jpeg/tinyjpeg.c
@@ -787,12 +787,6 @@ int tinyjpeg_decode(struct jdec_private *priv,
const decode_MCU_fct *decode_mcu_table;
convert_colorspace_fct convert_to_pixfmt;
- /* To keep gcc happy initialize some array */
- bytes_per_mcu[1] = 0;
- bytes_per_mcu[2] = 0;
- bytes_per_blocklines[1] = 0;
- bytes_per_blocklines[2] = 0;
-
decode_mcu_table = pixfmt->decode_mcu_table;
/* Fix: check return value */
@@ -864,15 +858,17 @@ void tinyjpeg_get_size(struct jdec_private *priv, unsigned int *width, unsigned
*height = priv->height;
}
-int tinyjpeg_get_components(struct jdec_private *priv, unsigned char **components)
+int tinyjpeg_get_components(struct jdec_private *priv, unsigned char **components, unsigned int ncomponents)
{
int i;
- for (i=0; priv->components[i] && i<COMPONENTS; i++)
+ if (ncomponents > COMPONENTS)
+ ncomponents = COMPONENTS;
+ for (i=0; i<ncomponents; i++)
components[i] = priv->components[i];
return 0;
}
-int tinyjpeg_set_components(struct jdec_private *priv, unsigned char **components, unsigned int ncomponents)
+int tinyjpeg_set_components(struct jdec_private *priv, unsigned char * const *components, unsigned int ncomponents)
{
int i;
if (ncomponents > COMPONENTS)
@@ -882,6 +878,30 @@ int tinyjpeg_set_components(struct jdec_private *priv, unsigned char **component
return 0;
}
+int tinyjpeg_get_bytes_per_row(struct jdec_private *priv,
+ unsigned int *bytes,
+ unsigned int ncomponents)
+{
+ int i;
+ if (ncomponents > COMPONENTS)
+ ncomponents = COMPONENTS;
+ for (i=0; i<ncomponents; i++)
+ bytes[i] = priv->bytes_per_row[i];
+ return 0;
+}
+
+int tinyjpeg_set_bytes_per_row(struct jdec_private *priv,
+ const unsigned int *bytes,
+ unsigned int ncomponents)
+{
+ int i;
+ if (ncomponents > COMPONENTS)
+ ncomponents = COMPONENTS;
+ for (i=0; i<ncomponents; i++)
+ priv->bytes_per_row[i] = bytes[i];
+ return 0;
+}
+
int tinyjpeg_set_flags(struct jdec_private *priv, int flags)
{
int oldflags = priv->flags;
diff --git a/com32/lib/jpeg/yuv420p.c b/com32/lib/jpeg/yuv420p.c
index 5411aa84..6d2bd056 100644
--- a/com32/lib/jpeg/yuv420p.c
+++ b/com32/lib/jpeg/yuv420p.c
@@ -60,8 +60,8 @@ static void YCrCB_to_YUV420P_1x1(struct jdec_private *priv)
for (i=0; i<8; i++)
{
memcpy(p, y, 8);
- p+=priv->width;
- y+=8;
+ p += priv->bytes_per_row[0];
+ y += 8;
}
p = priv->plane[1];
@@ -71,7 +71,7 @@ static void YCrCB_to_YUV420P_1x1(struct jdec_private *priv)
for (j=0; j<8; j+=2, s+=2)
*p++ = *s;
s += 8; /* Skip one line */
- p += priv->width/2 - 4;
+ p += priv->bytes_per_row[1] - 4;
}
p = priv->plane[2];
@@ -81,7 +81,7 @@ static void YCrCB_to_YUV420P_1x1(struct jdec_private *priv)
for (j=0; j<8; j+=2, s+=2)
*p++ = *s;
s += 8; /* Skip one line */
- p += priv->width/2 - 4;
+ p += priv->bytes_per_row[2] - 4;
}
}
@@ -102,7 +102,7 @@ static void YCrCB_to_YUV420P_2x1(struct jdec_private *priv)
for (i=0; i<8; i++)
{
memcpy(p, y1, 16);
- p += priv->width;
+ p += priv->bytes_per_row[0];
y1 += 16;
}
@@ -113,7 +113,7 @@ static void YCrCB_to_YUV420P_2x1(struct jdec_private *priv)
for (j=0; j<8; j+=1, s+=1)
*p++ = *s;
s += 8; /* Skip one line */
- p += priv->width/2 - 8;
+ p += priv->bytes_per_row[1] - 8;
}
p = priv->plane[2];
@@ -123,7 +123,7 @@ static void YCrCB_to_YUV420P_2x1(struct jdec_private *priv)
for (j=0; j<8; j+=1, s+=1)
*p++ = *s;
s += 8; /* Skip one line */
- p += priv->width/2 - 8;
+ p += priv->bytes_per_row[2] - 8;
}
}
@@ -147,7 +147,7 @@ static void YCrCB_to_YUV420P_1x2(struct jdec_private *priv)
for (i=0; i<16; i++)
{
memcpy(p, y, 8);
- p+=priv->width;
+ p+=priv->bytes_per_row[0];
y+=8;
}
@@ -157,7 +157,7 @@ static void YCrCB_to_YUV420P_1x2(struct jdec_private *priv)
{
for (j=0; j<8; j+=2, s+=2)
*p++ = *s;
- p += priv->width/2 - 4;
+ p += priv->bytes_per_row[1] - 4;
}
p = priv->plane[2];
@@ -166,7 +166,7 @@ static void YCrCB_to_YUV420P_1x2(struct jdec_private *priv)
{
for (j=0; j<8; j+=2, s+=2)
*p++ = *s;
- p += priv->width/2 - 4;
+ p += priv->bytes_per_row[2] - 4;
}
}
@@ -189,7 +189,7 @@ static void YCrCB_to_YUV420P_2x2(struct jdec_private *priv)
for (i=0; i<16; i++)
{
memcpy(p, y1, 16);
- p += priv->width;
+ p += priv->bytes_per_row[0];
y1 += 16;
}
@@ -199,7 +199,7 @@ static void YCrCB_to_YUV420P_2x2(struct jdec_private *priv)
{
memcpy(p, s, 8);
s += 8;
- p += priv->width/2;
+ p += priv->bytes_per_row[1];
}
p = priv->plane[2];
@@ -208,7 +208,7 @@ static void YCrCB_to_YUV420P_2x2(struct jdec_private *priv)
{
memcpy(p, s, 8);
s += 8;
- p += priv->width/2;
+ p += priv->bytes_per_row[2];
}
}
@@ -222,9 +222,16 @@ static int initialize_yuv420p(struct jdec_private *priv,
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);
- bytes_per_blocklines[0] = priv->width;
- bytes_per_blocklines[1] = priv->width/4;
- bytes_per_blocklines[2] = priv->width/4;
+ if (!priv->bytes_per_row[0])
+ priv->bytes_per_row[0] = priv->width;
+ if (!priv->bytes_per_row[1])
+ priv->bytes_per_row[1] = priv->width/2;
+ if (!priv->bytes_per_row[2])
+ priv->bytes_per_row[2] = priv->width/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;