summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2006-09-05 11:12:17 -0700
committerH. Peter Anvin <hpa@zytor.com>2006-09-05 11:12:17 -0700
commit9fa728d60c73615041719cfc000c0e7426b2692e (patch)
treead2451e8e1d86728ce1a9fbbae0832b31d1c693f
parent6eecf1d470027b8af4a24e7e20a278b8aca95abc (diff)
downloadsyslinux-9fa728d60c73615041719cfc000c0e7426b2692e.tar.gz
tinyjpeg: add rgba32 and bgra32 formats
-rw-r--r--com32/lib/Makefile1
-rw-r--r--com32/lib/jpeg/bgra32.c377
-rw-r--r--com32/lib/jpeg/rgba32.c374
3 files changed, 752 insertions, 0 deletions
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index 44d94962..d84b7c60 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -57,6 +57,7 @@ LIBOBJS = \
\
jpeg/tinyjpeg.o jpeg/jidctflt.o jpeg/decode1.o jpeg/decode3.o \
jpeg/rgb24.o jpeg/bgr24.o jpeg/yuv420p.o jpeg/grey.o \
+ jpeg/rgba32.o jpeg/bgra32.o \
\
sys/x86_init_fpu.o math/pow.o math/strtod.o
diff --git a/com32/lib/jpeg/bgra32.c b/com32/lib/jpeg/bgra32.c
new file mode 100644
index 00000000..d6f97915
--- /dev/null
+++ b/com32/lib/jpeg/bgra32.c
@@ -0,0 +1,377 @@
+/*
+ * Small jpeg decoder library
+ *
+ * Copyright (c) 2006, Luc Saillard <luc@saillard.org>
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the author nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "tinyjpeg.h"
+#include "tinyjpeg-internal.h"
+
+/*******************************************************************************
+ *
+ * Colorspace conversion routine
+ *
+ *
+ * Note:
+ * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
+ * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
+ * The conversion equations to be implemented are therefore
+ * R = Y + 1.40200 * Cr
+ * G = Y - 0.34414 * Cb - 0.71414 * Cr
+ * B = Y + 1.77200 * Cb
+ *
+ ******************************************************************************/
+static unsigned char clamp(int i)
+{
+ if (i<0)
+ return 0;
+ else if (i>255)
+ return 255;
+ else
+ return i;
+}
+
+/**
+ * YCrCb -> BGRA32 (1x1)
+ * .---.
+ * | 1 |
+ * `---'
+ */
+static void YCrCB_to_BGRA32_1x1(struct jdec_private *priv)
+{
+ const unsigned char *Y, *Cb, *Cr;
+ unsigned char *p;
+ int i,j;
+ int offset_to_next_row;
+
+#define SCALEBITS 10
+#define ONE_HALF (1UL << (SCALEBITS-1))
+#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
+
+ p = priv->plane[0];
+ Y = priv->Y;
+ Cb = priv->Cb;
+ Cr = priv->Cr;
+ offset_to_next_row = priv->width*4 - 8*4;
+ for (i=0; i<8; i++) {
+
+ for (j=0;j<8;j++) {
+
+ int y, cb, cr;
+ int add_r, add_g, add_b;
+ int r, g , b, a;
+
+ y = (*Y++) << SCALEBITS;
+ cb = *Cb++ - 128;
+ cr = *Cr++ - 128;
+ add_r = FIX(1.40200) * cr + ONE_HALF;
+ add_g = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;
+ add_b = FIX(1.77200) * cb + ONE_HALF;
+
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ a = 255;
+ *p++ = a;
+
+ }
+
+ p += offset_to_next_row;
+ }
+
+#undef SCALEBITS
+#undef ONE_HALF
+#undef FIX
+
+}
+
+
+/*
+ * YCrCb -> BGRA32 (2x1)
+ * .-------.
+ * | 1 | 2 |
+ * `-------'
+ */
+static void YCrCB_to_BGRA32_2x1(struct jdec_private *priv)
+{
+ const unsigned char *Y, *Cb, *Cr;
+ unsigned char *p;
+ int i,j;
+ int offset_to_next_row;
+
+#define SCALEBITS 10
+#define ONE_HALF (1UL << (SCALEBITS-1))
+#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
+
+ p = priv->plane[0];
+ Y = priv->Y;
+ Cb = priv->Cb;
+ Cr = priv->Cr;
+ offset_to_next_row = priv->width*4 - 16*4;
+ for (i=0; i<8; i++) {
+
+ for (j=0; j<8; j++) {
+
+ int y, cb, cr;
+ int add_r, add_g, add_b;
+ int r, g , b, a;
+
+ cb = *Cb++ - 128;
+ cr = *Cr++ - 128;
+ add_r = FIX(1.40200) * cr + ONE_HALF;
+ add_g = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;
+ add_b = FIX(1.77200) * cb + ONE_HALF;
+
+ y = (*Y++) << SCALEBITS;
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ a = 255;
+ *p++ = a;
+
+ y = (*Y++) << SCALEBITS;
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ a = 255;
+ *p++ = a;
+
+ }
+
+ p += offset_to_next_row;
+ }
+
+#undef SCALEBITS
+#undef ONE_HALF
+#undef FIX
+
+}
+
+/*
+ * YCrCb -> BGRA32 (1x2)
+ * .---.
+ * | 1 |
+ * |---|
+ * | 2 |
+ * `---'
+ */
+static void YCrCB_to_BGRA32_1x2(struct jdec_private *priv)
+{
+ const unsigned char *Y, *Cb, *Cr;
+ unsigned char *p, *p2;
+ int i,j;
+ int offset_to_next_row;
+
+#define SCALEBITS 10
+#define ONE_HALF (1UL << (SCALEBITS-1))
+#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
+
+ p = priv->plane[0];
+ p2 = priv->plane[0] + priv->width*4;
+ Y = priv->Y;
+ Cb = priv->Cb;
+ Cr = priv->Cr;
+ offset_to_next_row = 2*priv->width*4 - 8*4;
+ for (i=0; i<8; i++) {
+
+ for (j=0; j<8; j++) {
+
+ int y, cb, cr;
+ int add_r, add_g, add_b;
+ int r, g , b, a;
+
+ cb = *Cb++ - 128;
+ cr = *Cr++ - 128;
+ add_r = FIX(1.40200) * cr + ONE_HALF;
+ add_g = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;
+ add_b = FIX(1.77200) * cb + ONE_HALF;
+
+ y = (*Y++) << SCALEBITS;
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ a = 255;
+ *p++ = a;
+
+ y = (Y[8-1]) << SCALEBITS;
+ b = (y + add_b) >> SCALEBITS;
+ *p2++ = clamp(b);
+ g = (y + add_g) >> SCALEBITS;
+ *p2++ = clamp(g);
+ r = (y + add_r) >> SCALEBITS;
+ *p2++ = clamp(r);
+ a = 255;
+ *p2++ = a;
+
+ }
+ Y += 8;
+ p += offset_to_next_row;
+ p2 += offset_to_next_row;
+ }
+
+#undef SCALEBITS
+#undef ONE_HALF
+#undef FIX
+
+}
+
+
+/*
+ * YCrCb -> BGRA32 (2x2)
+ * .-------.
+ * | 1 | 2 |
+ * |---+---|
+ * | 3 | 4 |
+ * `-------'
+ */
+static void YCrCB_to_BGRA32_2x2(struct jdec_private *priv)
+{
+ const unsigned char *Y, *Cb, *Cr;
+ unsigned char *p, *p2;
+ int i,j;
+ int offset_to_next_row;
+
+#define SCALEBITS 10
+#define ONE_HALF (1UL << (SCALEBITS-1))
+#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
+
+ p = priv->plane[0];
+ p2 = priv->plane[0] + priv->width*4;
+ Y = priv->Y;
+ Cb = priv->Cb;
+ Cr = priv->Cr;
+ offset_to_next_row = (priv->width*4*2) - 16*4;
+ for (i=0; i<8; i++) {
+
+ for (j=0;j<8;j++) {
+
+ int y, cb, cr;
+ int add_r, add_g, add_b;
+ int r, g , b, a;
+
+ cb = *Cb++ - 128;
+ cr = *Cr++ - 128;
+ add_r = FIX(1.40200) * cr + ONE_HALF;
+ add_g = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;
+ add_b = FIX(1.77200) * cb + ONE_HALF;
+
+ y = (*Y++) << SCALEBITS;
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ a = 255;
+ *p++ = a;
+
+ y = (*Y++) << SCALEBITS;
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ a = 255;
+ *p++ = a;
+
+ y = (Y[16-2]) << SCALEBITS;
+ b = (y + add_b) >> SCALEBITS;
+ *p2++ = clamp(b);
+ g = (y + add_g) >> SCALEBITS;
+ *p2++ = clamp(g);
+ r = (y + add_r) >> SCALEBITS;
+ *p2++ = clamp(r);
+ a = 255;
+ *p2++ = a;
+
+ y = (Y[16-1]) << SCALEBITS;
+ b = (y + add_b) >> SCALEBITS;
+ *p2++ = clamp(b);
+ g = (y + add_g) >> SCALEBITS;
+ *p2++ = clamp(g);
+ r = (y + add_r) >> SCALEBITS;
+ *p2++ = clamp(r);
+ a = 255;
+ *p2++ = a;
+ }
+ Y += 16;
+ p += offset_to_next_row;
+ p2 += offset_to_next_row;
+ }
+
+#undef SCALEBITS
+#undef ONE_HALF
+#undef FIX
+
+}
+
+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 * 3);
+ bytes_per_blocklines[0] = priv->width * 3;
+ bytes_per_mcu[0] = 3*8;
+
+ return !priv->components[0];
+}
+
+static const struct tinyjpeg_colorspace format_bgra32 =
+ {
+ {
+ YCrCB_to_BGRA32_1x1,
+ YCrCB_to_BGRA32_1x2,
+ YCrCB_to_BGRA32_2x1,
+ YCrCB_to_BGRA32_2x2,
+ },
+ tinyjpeg_decode_mcu_3comp_table,
+ initialize_bgra32
+ };
+
+const tinyjpeg_colorspace_t TINYJPEG_FMT_BGRA32 = &format_bgra32;
diff --git a/com32/lib/jpeg/rgba32.c b/com32/lib/jpeg/rgba32.c
new file mode 100644
index 00000000..2934bcd8
--- /dev/null
+++ b/com32/lib/jpeg/rgba32.c
@@ -0,0 +1,374 @@
+/*
+ * Small jpeg decoder library
+ *
+ * Copyright (c) 2006, Luc Saillard <luc@saillard.org>
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the author nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "tinyjpeg.h"
+#include "tinyjpeg-internal.h"
+
+/*******************************************************************************
+ *
+ * Colorspace conversion routine
+ *
+ *
+ * Note:
+ * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
+ * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
+ * The conversion equations to be implemented are therefore
+ * R = Y + 1.40200 * Cr
+ * G = Y - 0.34414 * Cb - 0.71414 * Cr
+ * B = Y + 1.77200 * Cb
+ *
+ ******************************************************************************/
+static unsigned char clamp(int i)
+{
+ if (i<0)
+ return 0;
+ else if (i>255)
+ return 255;
+ else
+ return i;
+}
+
+/**
+ * YCrCb -> RGBA32 (1x1)
+ * .---.
+ * | 1 |
+ * `---'
+ */
+static void YCrCB_to_RGBA32_1x1(struct jdec_private *priv)
+{
+ const unsigned char *Y, *Cb, *Cr;
+ unsigned char *p;
+ int i,j;
+ int offset_to_next_row;
+
+#define SCALEBITS 10
+#define ONE_HALF (1UL << (SCALEBITS-1))
+#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
+
+ p = priv->plane[0];
+ Y = priv->Y;
+ Cb = priv->Cb;
+ Cr = priv->Cr;
+ offset_to_next_row = priv->width*4 - 8*4;
+ for (i=0; i<8; i++) {
+
+ for (j=0;j<8;j++) {
+
+ int y, cb, cr;
+ int add_r, add_g, add_b;
+ int r, g , b, a;
+
+ y = (*Y++) << SCALEBITS;
+ cb = *Cb++ - 128;
+ cr = *Cr++ - 128;
+ add_r = FIX(1.40200) * cr + ONE_HALF;
+ add_g = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;
+ add_b = FIX(1.77200) * cb + ONE_HALF;
+
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ a = 255;
+ *p++ = a;
+ }
+
+ p += offset_to_next_row;
+ }
+
+#undef SCALEBITS
+#undef ONE_HALF
+#undef FIX
+
+}
+
+/**
+ * YCrCb -> RGBA32 (2x1)
+ * .-------.
+ * | 1 | 2 |
+ * `-------'
+ */
+static void YCrCB_to_RGBA32_2x1(struct jdec_private *priv)
+{
+ const unsigned char *Y, *Cb, *Cr;
+ unsigned char *p;
+ int i,j;
+ int offset_to_next_row;
+
+#define SCALEBITS 10
+#define ONE_HALF (1UL << (SCALEBITS-1))
+#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
+
+ p = priv->plane[0];
+ Y = priv->Y;
+ Cb = priv->Cb;
+ Cr = priv->Cr;
+ offset_to_next_row = priv->width*4 - 16*4;
+ for (i=0; i<8; i++) {
+
+ for (j=0; j<8; j++) {
+
+ int y, cb, cr;
+ int add_r, add_g, add_b;
+ int r, g , b, a;
+
+ y = (*Y++) << SCALEBITS;
+ cb = *Cb++ - 128;
+ cr = *Cr++ - 128;
+ add_r = FIX(1.40200) * cr + ONE_HALF;
+ add_g = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;
+ add_b = FIX(1.77200) * cb + ONE_HALF;
+
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ a = 255;
+ *p++ = a;
+
+ y = (*Y++) << SCALEBITS;
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ a = 255;
+ *p++ = a;
+ }
+
+ p += offset_to_next_row;
+ }
+
+#undef SCALEBITS
+#undef ONE_HALF
+#undef FIX
+
+}
+
+
+/**
+ * YCrCb -> RGBA32 (1x2)
+ * .---.
+ * | 1 |
+ * |---|
+ * | 2 |
+ * `---'
+ */
+static void YCrCB_to_RGBA32_1x2(struct jdec_private *priv)
+{
+ const unsigned char *Y, *Cb, *Cr;
+ unsigned char *p, *p2;
+ int i,j;
+ int offset_to_next_row;
+
+#define SCALEBITS 10
+#define ONE_HALF (1UL << (SCALEBITS-1))
+#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
+
+ p = priv->plane[0];
+ p2 = priv->plane[0] + priv->width*4;
+ Y = priv->Y;
+ Cb = priv->Cb;
+ Cr = priv->Cr;
+ offset_to_next_row = 2*priv->width*4 - 8*4;
+ for (i=0; i<8; i++) {
+
+ for (j=0; j<8; j++) {
+
+ int y, cb, cr;
+ int add_r, add_g, add_b;
+ int r, g , b, a;
+
+ cb = *Cb++ - 128;
+ cr = *Cr++ - 128;
+ add_r = FIX(1.40200) * cr + ONE_HALF;
+ add_g = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;
+ add_b = FIX(1.77200) * cb + ONE_HALF;
+
+ y = (*Y++) << SCALEBITS;
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ a = 255;
+ *p++ = a;
+
+ y = (Y[8-1]) << SCALEBITS;
+ r = (y + add_r) >> SCALEBITS;
+ *p2++ = clamp(r);
+ g = (y + add_g) >> SCALEBITS;
+ *p2++ = clamp(g);
+ b = (y + add_b) >> SCALEBITS;
+ *p2++ = clamp(b);
+ a = 255;
+ *p2++ = a;
+
+ }
+ Y += 8;
+ p += offset_to_next_row;
+ p2 += offset_to_next_row;
+ }
+
+#undef SCALEBITS
+#undef ONE_HALF
+#undef FIX
+
+}
+
+/**
+ * YCrCb -> RGBA32 (2x2)
+ * .-------.
+ * | 1 | 2 |
+ * |---+---|
+ * | 3 | 4 |
+ * `-------'
+ */
+static void YCrCB_to_RGBA32_2x2(struct jdec_private *priv)
+{
+ const unsigned char *Y, *Cb, *Cr;
+ unsigned char *p, *p2;
+ int i,j;
+ int offset_to_next_row;
+
+#define SCALEBITS 10
+#define ONE_HALF (1UL << (SCALEBITS-1))
+#define FIX(x) ((int)((x) * (1UL<<SCALEBITS) + 0.5))
+
+ p = priv->plane[0];
+ p2 = priv->plane[0] + priv->width*4;
+ Y = priv->Y;
+ Cb = priv->Cb;
+ Cr = priv->Cr;
+ offset_to_next_row = (priv->width*4*2) - 16*4;
+ for (i=0; i<8; i++) {
+
+ for (j=0;j<8;j++) {
+
+ int y, cb, cr;
+ int add_r, add_g, add_b;
+ int r, g , b, a;
+
+ cb = *Cb++ - 128;
+ cr = *Cr++ - 128;
+ add_r = FIX(1.40200) * cr + ONE_HALF;
+ add_g = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;
+ add_b = FIX(1.77200) * cb + ONE_HALF;
+
+ y = (*Y++) << SCALEBITS;
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ a = 255;
+ *p++ = a;
+
+ y = (*Y++) << SCALEBITS;
+ r = (y + add_r) >> SCALEBITS;
+ *p++ = clamp(r);
+ g = (y + add_g) >> SCALEBITS;
+ *p++ = clamp(g);
+ b = (y + add_b) >> SCALEBITS;
+ *p++ = clamp(b);
+ a = 255;
+ *p++ = a;
+
+ y = (Y[16-2]) << SCALEBITS;
+ r = (y + add_r) >> SCALEBITS;
+ *p2++ = clamp(r);
+ g = (y + add_g) >> SCALEBITS;
+ *p2++ = clamp(g);
+ b = (y + add_b) >> SCALEBITS;
+ *p2++ = clamp(b);
+ a = 255;
+ *p2++ = a;
+
+ y = (Y[16-1]) << SCALEBITS;
+ r = (y + add_r) >> SCALEBITS;
+ *p2++ = clamp(r);
+ g = (y + add_g) >> SCALEBITS;
+ *p2++ = clamp(g);
+ b = (y + add_b) >> SCALEBITS;
+ *p2++ = clamp(b);
+ a = 255;
+ *p2++ = a;
+ }
+ Y += 16;
+ p += offset_to_next_row;
+ p2 += offset_to_next_row;
+ }
+
+#undef SCALEBITS
+#undef ONE_HALF
+#undef FIX
+
+}
+
+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);
+ bytes_per_blocklines[0] = priv->width * 4;
+ bytes_per_mcu[0] = 4*8;
+
+ return !priv->components[0];
+}
+
+static const struct tinyjpeg_colorspace format_rgba32 =
+ {
+ {
+ YCrCB_to_RGBA32_1x1,
+ YCrCB_to_RGBA32_1x2,
+ YCrCB_to_RGBA32_2x1,
+ YCrCB_to_RGBA32_2x2,
+ },
+ tinyjpeg_decode_mcu_3comp_table,
+ initialize_rgba32
+ };
+
+const tinyjpeg_colorspace_t TINYJPEG_FMT_RGBA32 = &format_rgba32;