clear the screen on startup.
int tinyjpeg_decode(struct jdec_private *priv, tinyjpeg_colorspace_t pixel_format);
const char *tinyjpeg_get_errorstring(struct jdec_private *priv);
void tinyjpeg_get_size(struct jdec_private *priv, unsigned int *width, unsigned int *height);
-int tinyjpeg_get_components(struct jdec_private *priv, unsigned char **components);
-int tinyjpeg_set_components(struct jdec_private *priv, unsigned char **components, unsigned int ncomponents);
+int tinyjpeg_get_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 tinyjpeg_get_bytes_per_row(struct jdec_private *priv, unsigned int *bytes, unsigned int ncomponents);
+int tinyjpeg_set_bytes_per_row(struct jdec_private *priv, const unsigned int *bytes, unsigned int ncomponents);
int tinyjpeg_set_flags(struct jdec_private *priv, int flags);
#ifdef __cplusplus
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++) {
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++) {
#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++) {
#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++) {
{
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];
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++) {
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++) {
#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++) {
#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++) {
}
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];
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);
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;
}
}
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;
}
}
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];
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++) {
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++) {
#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++) {
#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++) {
{
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];
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++) {
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++) {
#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++) {
#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++) {
{
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];
{
/* Public variables */
uint8_t *components[COMPONENTS];
+ unsigned int bytes_per_row[COMPONENTS];
unsigned int width, height; /* Size of the image */
unsigned int flags;
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 */
*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)
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;
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];
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];
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;
}
}
for (i=0; i<8; i++)
{
memcpy(p, y1, 16);
- p += priv->width;
+ p += priv->bytes_per_row[0];
y1 += 16;
}
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];
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;
}
}
for (i=0; i<16; i++)
{
memcpy(p, y, 8);
- p+=priv->width;
+ p+=priv->bytes_per_row[0];
y+=8;
}
{
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];
{
for (j=0; j<8; j+=2, s+=2)
*p++ = *s;
- p += priv->width/2 - 4;
+ p += priv->bytes_per_row[2] - 4;
}
}
for (i=0; i<16; i++)
{
memcpy(p, y1, 16);
- p += priv->width;
+ p += priv->bytes_per_row[0];
y1 += 16;
}
{
memcpy(p, s, 8);
s += 8;
- p += priv->width/2;
+ p += priv->bytes_per_row[1];
}
p = priv->plane[2];
{
memcpy(p, s, 8);
s += 8;
- p += priv->width/2;
+ p += priv->bytes_per_row[2];
}
}
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;
size_t length_of_file = filesize(fp);
unsigned int width, height;
int rv = -1;
- unsigned char *components[3], *in_row_ptr;
- uint32_t *out_row_ptr;
- int bytes_per_row, copy_bytes;
- int i;
+ unsigned char *components[1];
+ unsigned int bytes_per_row[1];
jpeg_file = malloc(length_of_file);
if (!jpeg_file)
goto err;
tinyjpeg_get_size(jdec, &width, &height);
- if (width > 4096 || height > 4096)
+ if (width > VIDEO_X_SIZE || height > VIDEO_Y_SIZE)
goto err;
- tinyjpeg_decode(jdec, TINYJPEG_FMT_BGRA32);
- tinyjpeg_get_components(jdec, components);
-
- bytes_per_row = width << 2;
- copy_bytes = min(width, (unsigned int)VIDEO_X_SIZE) << 2;
- in_row_ptr = components[0];
- out_row_ptr = (uint32_t *)&__vesacon_background[0];
+ components[0] = (void *)&__vesacon_background[0];
+ tinyjpeg_set_components(jdec, components, 1);
+ bytes_per_row[0] = VIDEO_X_SIZE << 2;
+ tinyjpeg_set_bytes_per_row(jdec, bytes_per_row, 1);
- for (i = 0; i < (int)height; i++) {
- memcpy(out_row_ptr, in_row_ptr, copy_bytes);
- in_row_ptr += bytes_per_row;
- out_row_ptr += VIDEO_X_SIZE;
- }
+ tinyjpeg_decode(jdec, TINYJPEG_FMT_BGRA32);
rv = 0;
err:
+ /* Don't use tinyjpeg_free() here, since we didn't allow tinyjpeg
+ to allocate the frame buffer */
if (jdec)
- tinyjpeg_free(jdec);
+ free(jdec);
+
if (jpeg_file)
free(jpeg_file);
/* Now set video mode */
rm.eax.w[0] = 0x4F02; /* Set SVGA video mode */
- rm.ebx.w[0] = mode | 0xC000; /* Don't clear video RAM, use linear fb */
+ rm.ebx.w[0] = mode | 0x4000; /* Clear video RAM, use linear fb */
__intcall(0x10, &rm, &rm);
if ( rm.eax.w[0] != 0x004F ) {
rm.eax.w[0] = 0x0003; /* Set regular text mode */