fixup! feat(core): basic support for jpeg rendering

tychovrahe/jpeg/basic
tychovrahe 1 year ago
parent ad9a9de1b0
commit 74e3a0a4ed

@ -179,7 +179,7 @@ SOURCE_MOD += [
'embed/extmod/modtrezorui/fonts/font_bitmap.c',
'embed/extmod/modtrezorui/modtrezorui.c',
'embed/extmod/modtrezorui/qr-code-generator/qrcodegen.c',
'embed/extmod/modtrezorui/tjpgd/src/tjpgd.c',
'embed/extmod/modtrezorui/tjpgd/tjpgd.c',
'vendor/micropython/lib/uzlib/adler32.c',
'vendor/micropython/lib/uzlib/crc32.c',
'vendor/micropython/lib/uzlib/tinflate.c',

@ -175,7 +175,7 @@ SOURCE_MOD += [
'embed/extmod/modtrezorui/fonts/font_bitmap.c',
'embed/extmod/modtrezorui/modtrezorui.c',
'embed/extmod/modtrezorui/qr-code-generator/qrcodegen.c',
'embed/extmod/modtrezorui/tjpgd/src/tjpgd.c',
'embed/extmod/modtrezorui/tjpgd/tjpgd.c',
'vendor/micropython/lib/uzlib/adler32.c',
'vendor/micropython/lib/uzlib/crc32.c',
'vendor/micropython/lib/uzlib/tinflate.c',

@ -20,7 +20,7 @@
#define _GNU_SOURCE
#include "qr-code-generator/qrcodegen.h"
#include "tjpgd/src/tjpgd.h"
#include "tjpgd/tjpgd.h"
#include "uzlib.h"

@ -1,77 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="description" content="Open souece JPEG decompressor module for embedded projects">
<link rel="start" title="Site Top" href="../../">
<link rel="up" title="Freewares" href="../../fsw_e.html">
<link rel="stylesheet" href="css_e.css" type="text/css" media="screen" title="ELM Default">
<title>TJpgDec - Tiny JPEG Decompressor</title>
</head>
<body>
<h1>TJpgDec - Tiny JPEG Decompressor</h1>
<hr>
<div class="abst">
<img src="en/jpeg.jpeg" class="rset" width="250" height="250" alt="layer">
<p>TJpgDec is a generic JPEG image decompressor module that highly optimized for small embedded systems. It works with very low memory consumption, so that it can be incorporated into tiny microcontrollers, such as AVR, 8051, PIC, Z80, Cortex-M0 and etc.</p>
<h4>Features</h4>
<ul>
<li>Platform independent. Written in plain C (C99).</li>
<li>Easy to use master mode operation.</li>
<li>Fully re-entrant architecture.</li>
<li>Configurable optimization level for both 8/16-bit and 32-bit MCU.</li>
<li>Very small memory footprint:
<ul>
<li>3.5K bytes of RAM for work area independent of image dimensions.</li>
<li>3.5-8.5K bytes of ROM for text and constants.</li>
</ul>
</li>
<li>Output format:
<ul>
<li>Pixel format: RGB888, RGB565 or Grayscale pre-configurable.</li>
<li>Scaling ratio: 1/1, 1/2, 1/4 or 1/8 selectable on decompression.</li>
</ul>
</li>
</ul>
</div>
<div class="para">
<h3>Application Interface</h3>
<p>There are two API functions to analyze and decompress the JPEG image.</p>
<ul>
<li><a href="en/prepare.html">jd_prepare</a> - Prepare decompression of the JPEG image</li>
<li><a href="en/decomp.html">jd_decomp</a> - Execute decompression of the JPEG image</li>
</ul>
</div>
<div class="para">
<h3>I/O functions</h3>
<p>To input the JPEG data and output the decompressed image, TJpgDec requires two user defined I/O functions. These are called back from the TJpgDec module in the decompression process.</p>
<ul>
<li><a href="en/input.html">Input Funciotn</a> - Read JPEG data from the input stream</li>
<li><a href="en/output.html">Output Function</a> - Output the decompressed image to the destination object</li>
</ul>
</div>
<div class="para">
<h3>Resources</h3>
<p>The TJpgDec module is a free software opened for education, research and development. You can use, modify and/or redistribute it for personal projects or commercial products without any restriction under your responsibility.</p>
<ul>
<li>Getting Started: <a href="en/appnote.html">TJpgDec Application Note</a></li>
<li>Download: <a href="http://elm-chan.org/fsw/tjpgd/archives.html">Archives</a></li>
<li><a href="https://github.com/lovyan03/ESP32_ScreenShotReceiver">TJpgDec highly optimized for ESP32 MCUs by lovyan03</a></li>
</ul>
</div>
<hr>
<p class="foot"><a href="../../fsw_e.html">Return</a></p>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

@ -1,60 +0,0 @@
* {margin: 0; padding: 0; border-width: 0;}
body {margin: 8px; background-color: #e0ffff; font-color: black; font-family: serif; line-height: 133%; max-width: 1024px;}
a:link {color: blue;}
a:visited {color: darkmagenta;}
a:hover {background-color: #a0ffff;}
a:active {color: darkmagenta; overflow: hidden; outline:none; position: relative; top: 1px; left: 1px;}
abbr {border-width: 1px;}
p {margin: 0 0 0.3em 1em;}
em {font-style: normal; font-weight: bold; margin: 0 0.1em;}
pre em {font-style: italic; font-weight: normal;}
strong {}
pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; font-size: 85%; font-family: "Consolas", "Courier New", monospace; background-color: white;}
pre span.c {color: green;}
pre span.k {color: blue;}
tt {margin: 0 0.2em; font-size: 85%; font-family: "Consolas", "Courier New", monospace; }
tt.arg {font-style: italic;}
ol {margin: 0 2.5em;}
ul {margin: 0 2em;}
dl {margin: 0 1em;}
dt {font-size: 85%; font-family: "Consolas", "Courier New", monospace;}
dl.par dt {margin: 0.5em 0 0 0 ; font-style: italic; }
dl.ret dt {margin: 0.5em 0 0 0 ; }
dd {margin: 0 2em;}
hr {border-width: 1px; margin: 1em;}
div.abst {font-family: sans-serif;}
div.para {clear: both; font-family: serif;}
div.ret a {font-size: 85%; font-family: "Consolas", "Courier New", monospace; }
.equ {text-indent: 0; margin: 1em 2em 1em;}
.indent {margin-left: 2em;}
.rset {float: right; margin: 0 0 0.5em 0.5em;}
.lset {float: left; margin: 0 0.5em 0.5em 0.5em;}
ul.flat li {list-style-type: none; margin: 0;}
a.imglnk img {border: 1px solid;}
.iequ {white-space: nowrap; font-weight: bold;}
.clr {clear: both;}
.it {font-style: italic;}
.mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap}
h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;}
p.hdd {float: right; text-align: right; margin-top: 0.5em;}
hr.hds {clear: both; margin-bottom: 1em;}
h2 {font-size: 2em; font-family: sans-serif; background-color: #d8d8FF; padding: 0.5em 0.5em; margin: 0 0 0.5em;}
h3 {font-size: 1.5em; font-family: sans-serif; margin: 1.5em 0 0.5em;}
h4 {font-size: 1.2em; font-family: sans-serif; margin: 1em 0 0.2em;}
h5 {font-size: 1em; font-family: sans-serif; margin: 0.5em 0 0em;}
small {font-size: 80%;}
.indent {margin-left: 2em;}
/* Tables */
table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; }
th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top; white-space: nowrap;}
td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
table.lst td:first-child {font-size: 85%; font-family: "Consolas", "Courier New", monospace;}
table.lst2 td {font-size: 85%; font-family: "Consolas", "Courier New", monospace;}
table caption {font-family: sans-serif; font-weight: bold;}
tr.lst3 td { border-width: 2px 1px 1px; }
p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;}

@ -1,234 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>TJpgDec Module Application Note</title>
</head>
<body>
<h1>TJpgDec Module Application Note</h1>
<ol class="toc">
<li><a href="#use">How to Use</a></li>
<li><a href="#limits">Limits</a></li>
<li><a href="#memory">Memory Usage</a></li>
<li><a href="#opt">Options</a></li>
<li><a href="#license">About TJpgDec License</a></li>
</ol>
<hr>
<div class="para" id="use">
<h3>How to Use</h3>
<p>First of all, you should build and run the sample program shown below. This is a typical usage of TJpgDec module and it helps to narrow down the problem on debugging.</p>
<p>The decompression session is divided in two stages. The first stage is to analyze the JPEG image and the second stage is to decompress it.</p>
<ol>
<li>Initialize input stream. (e.g. open a file)</li>
<li>Allocate JPEG decompression object and work area.</li>
<li>Call <em>jd_prepare()</em> to analyze and prepare to decompress the JPEG image.</li>
<li>Initialize output device with the image info in the decompression object.</li>
<li>Call <em>jd_decomp()</em> to decompress the JPEG image.</li>
</ol>
<h4>System Organization</h4>
<p><img src="p1.png" width="420" height="280" alt=""></p>
<h4>Example</h4>
<pre>
<span class="c">/*------------------------------------------------*/</span>
<span class="c">/* TJpgDec Quick Evaluation Program for PCs */</span>
<span class="c">/*------------------------------------------------*/</span>
<span class="k">#include</span> &lt;stdio.h&gt;
<span class="k">#include</span> &lt;string.h&gt;
<span class="k">#include</span> "tjpgd.h"
<span class="c">/* Bytes per pixel of image output */</span>
<span class="k">#define</span> N_BPP (3 - JD_FORMAT)
<span class="c">/* Session identifier for input/output functions (name, members and usage are as user defined) */</span>
<span class="c"><span class="k">typedef struct</span></span> {
FILE *fp; <span class="c">/* Input stream */</span>
uint8_t *fbuf; <span class="c">/* Output frame buffer */</span>
unsigned int wfbuf; <span class="c">/* Width of the frame buffer [pix] */</span>
} IODEV;
<span class="c">/*------------------------------*/</span>
<span class="c">/* User defined input funciton */</span>
<span class="c">/*------------------------------*/</span>
size_t in_func ( <span class="c">/* Returns number of bytes read (zero on error) */</span>
JDEC* jd, <span class="c">/* Decompression object */</span>
uint8_t* buff, <span class="c">/* Pointer to the read buffer (null to remove data) */</span>
size_t nbyte <span class="c">/* Number of bytes to read/remove */</span>
)
{
IODEV *dev = (IODEV*)jd-&gt;device; <span class="c">/* Session identifier (5th argument of jd_prepare function) */</span>
<span class="k">if</span> (buff) { <span class="c">/* Raad data from imput stream */</span>
<span class="k">return</span> fread(buff, 1, nbyte, dev-&gt;fp);
} <span class="k">else</span> { <span class="c">/* Remove data from input stream */</span>
<span class="k">return</span> fseek(dev-&gt;fp, nbyte, SEEK_CUR) ? 0 : nbyte;
}
}
<span class="c">/*------------------------------*/</span>
<span class="c">/* User defined output funciton */</span>
<span class="c">/*------------------------------*/</span>
int out_func ( <span class="c">/* Returns 1 to continue, 0 to abort */</span>
JDEC* jd, <span class="c">/* Decompression object */</span>
void* bitmap, <span class="c">/* Bitmap data to be output */</span>
JRECT* rect <span class="c">/* Rectangular region of output image */</span>
)
{
IODEV *dev = (IODEV*)jd-&gt;device; <span class="c">/* Session identifier (5th argument of jd_prepare function) */</span>
uint8_t *src, *dst;
uint16_t y, bws;
unsigned int bwd;
<span class="c">/* Progress indicator */</span>
<span class="k">if</span> (rect-&gt;left == 0) {
printf("\r%lu%%", (rect-&gt;top &lt;&lt; jd-&gt;scale) * 100UL / jd-&gt;height);
}
<span class="c">/* Copy the output image rectangle to the frame buffer */</span>
src = (uint8_t*)bitmap; <span class="c">/* Output bitmap */</span>
dst = dev-&gt;fbuf + N_BPP * (rect-&gt;top * dev-&gt;wfbuf + rect-&gt;left); <span class="c">/* Left-top of rectangle in the frame buffer */</span>
bws = N_BPP * (rect-&gt;right - rect-&gt;left + 1); <span class="c">/* Width of the rectangle [byte] */</span>
bwd = N_BPP * dev-&gt;wfbuf; <span class="c">/* Width of the frame buffer [byte] */</span>
<span class="k">for</span> (y = rect-&gt;top; y &lt;= rect-&gt;bottom; y++) {
memcpy(dst, src, bws); <span class="c">/* Copy a line */</span>
src += bws; dst += bwd; <span class="c">/* Next line */</span>
}
<span class="k">return</span> 1; <span class="c">/* Continue to decompress */</span>
}
<span class="c">/*------------------------------*/</span>
<span class="c">/* Program Main */</span>
<span class="c">/*------------------------------*/</span>
int main (int argc, char* argv[])
{
JRESULT res; <span class="c">/* Result code of TJpgDec API */</span>
JDEC jdec; <span class="c">/* Decompression object */</span>
void *work; <span class="c">/* Pointer to the work area */</span>
size_t sz_work = 3500; <span class="c">/* Size of work area */</span>
IODEV devid; <span class="c">/* Session identifier */</span>
<span class="c">/* Initialize input stream */</span>
<span class="k">if</span> (argc &lt; 2) <span class="k">return</span> -1;
devid.fp = fopen(argv[1], "rb");
<span class="k">if</span> (!devid.fp) <span class="k">return</span> -1;
<span class="c">/* Prepare to decompress */</span>
work = (void*)malloc(sz_work);
res = <span class="b">jd_prepare</span>(&amp;jdec, in_func, work, sz_work, &amp;devid);
<span class="k">if</span> (res == JDR_OK) {
<span class="c">/* It is ready to dcompress and image info is available here */</span>
printf("Image size is %u x %u.\n%u bytes of work ares is used.\n", jdec.width, jdec.height, sz_work - jdec.sz_pool);
<span class="c">/* Initialize output device */</span>
devid.fbuf = (uint8_t*)malloc(N_BPP * jdec.width * jdec.height); <span class="c">/* Create frame buffer for output image */</span>
devid.wfbuf = jdec.width;
res = <span class="b">jd_decomp</span>(&amp;jdec, out_func, 0); <span class="c">/* Start to decompress with 1/1 scaling */</span>
<span class="k">if</span> (res == JDR_OK) {
<span class="c">/* Decompression succeeded. You have the decompressed image in the frame buffer here. */</span>
printf("\rDecompression succeeded.\n");
} <span class="k">else</span> {
printf("jd_decomp() failed (rc=%d)\n", res);
}
free(devid.fbuf); <span class="c">/* Discard frame buffer */</span>
} <span class="k">else</span> {
printf("jd_prepare() failed (rc=%d)\n", res);
}
free(work); <span class="c">/* Discard work area */</span>
fclose(devid.fp); <span class="c">/* Close the JPEG file */</span>
<span class="k">return</span> res;
}
</pre>
</div>
<div class="para" id="limits">
<h3>Limits</h3>
<ul>
<li>JPEG standard: Baseline only. Progressive and Lossless JPEG format are not supported.</li>
<li>Image size: Upto 65520 x 65520 pixels.</li>
<li>Colorspace: Y-Cb-Cr (color) and Grayscale (monochrome).</li>
<li>Sampling factor: 4:4:4, 4:2:2, 4:2:2(V) or 4:2:0 for color image.</li>
</ul>
</div>
<div class="para" id="memory">
<h3>Memory Usage</h3>
<p>These are the memory usage of some platforms at default configuration. Each compilations are optimized in code size.</p>
<table class="lst2">
<tr><th></th><th>AVR</th><th>PIC24</th><th>CM0</th><th>IA-32</th></tr>
<tr><td>Compiler</td><td>GCC</td><td>C30</td><td>GCC</td><td>MSC</td></tr>
<tr class="lst3"><td>text+const</td><td>6.1k</td><td>5.1k</td><td>3.1k</td><td>3.7k</td></tr>
</table>
<p>TJpgDec requires a work area upto 3100 bytes for most JPEG images. It exactly depends on what parameter has been used to create the JPEG image to be decompressed. The 3100 bytes is the maximum memory requirement in default configuration and it varies depends on <tt>JD_SZBUF</tt> and <tt>JD_FASTDECODE</tt>.</p>
</div>
<div class="para" id="opt">
<h3>Options</h3>
<p>TJpgDec has some configuration options on output format, performance and memory usage. These options are in <tt>tjpgdcnf.h</tt>.</p>
<dl>
<dt>JD_SZBUF</dt>
<dd>This option speficies how many bytes read from input stream at a time. TJpgDec alignes each read request to the buffer size, so that 512, 1024, 2048... byte is ideal to read data from the storage device.</dd>
<dt>JD_FORMAT</dt>
<dd>This option speficies the output pixel format. 0:RGB888, 1:RGB565 or 2:Grayscale.</dd>
<dt>JD_USE_SCALE</dt>
<dd>This option switches output scaling feature. When enabled (1), the output image can be descaled on decompression. The descaling ratio is specified in <tt>jd_decomp</tt> function.</dd>
<dt>JD_FASTDECODE</dt>
<dd><img class="rset" src="opt.png" width="512" height="264" alt="">This option switches the decompression algorithm. How this option affects the performance is highly depends on the processor architectre as shown in right image. The Lv.0 is the basic optimization in minimal memory usage suitable for 8/16-bit processors. The Lv.1 depends on 32-bit barrel shifter and is suitable for 32-bit processors. It requires additional 320 bytes of work area. The Lv.2 enables the table conversion for huffman decoding. It requires additional <tt>6 &lt;&lt; HUFF_BITS</tt>, 6144 by default, bytes of work area.</dd>
<dt>JD_TBLCLIP</dt>
<dd>This option switches to use table conversion for saturation alithmetics. It requires 1024 bytes of code size.</dd>
</dl>
</div>
<div class="para" id="license">
<h3>About TJpgDec License</h3>
<p>This is a copy of the TJpgDec license document that included in the source codes.</p>
<pre>
/*----------------------------------------------------------------------------/
/ TJpgDec - Tiny JPEG Decompressor R0.xx (C)ChaN, 20xx
/-----------------------------------------------------------------------------/
/ The TJpgDec is a generic JPEG decompressor module for tiny embedded systems.
/ This is a free software that opened for education, research and commercial
/ developments under license policy of following terms.
/
/ Copyright (C) 20xx, ChaN, all right reserved.
/
/ * The TJpgDec module is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
/ personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
/ * Redistributions of source code must retain the above copyright notice.
/
/----------------------------------------------------------------------------*/</pre>
<p>Therefore TJpgDec license is one of the BSD-style license but there is a significant difference. Because TJpgDec is for embedded projects, so that the conditions for redistributions in binary form, such as embedded code, hex file and binary library, are not specified in order to maximize its usability. The documentation of the distributions may or may not include about TJpgDec and its license document. Of course TJpgDec is compatible with the projects under GNU GPL. When redistribute TJpgDec with any modification, the license can also be changed to GNU GPL or any BSD-style license.</p>
</div>
<p class="foot"><a href="../00index.html">Return</a></p>
</body>
</html>

@ -1,64 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="TJpgDec" href="../00index.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>TJpgDec - jd_decomp</title>
</head>
<body>
<div class="para func">
<h2>jd_decomp</h2>
<p>The jd_decomp function decompress the JPEG image and output it as pixel data.</p>
<pre>
JRESULT jd_decomp (
JDEC* <em>jdec</em>, <span class="c">/* Pointer to valid decompression object */</span>
int(*<em>outfunc</em>)(JDEC*,void*,JRECT*), <span class="c">/* Pointer to output function */</span>
uint8_t <em>scale</em> <span class="c">/* Scaling factor */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>jdec</dt>
<dd>Specifies the valid decompressor object.</dd>
<dt>outfunc</dt>
<dd>Specifies the user defined <a href="output.html">data output function</a>. The <tt>jd_decomp</tt> function calls this function to output the decompressed JPEG image in pre-defined pixel format.</dd>
<dt>scale</dt>
<dd>Specifies scaling factor N for output. The output image is descaled to 1/2<sup>N</sup> (N = 0 to 3). When scaling feature is disabled (<tt>JD_USE_SCALE == 0</tt>), it must be 0.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<dl class="ret">
<dt>JDR_OK</dt>
<dd>Function succeeded.</dd>
<dt>JDR_INTR</dt>
<dd>The decompression process was interrupted by output function.</dd>
<dt>JDR_INP</dt>
<dd>An error occured in input function due to hard error or wrong stream termination.</dd>
<dt>JDR_PAR</dt>
<dd>Parameter error. Given scale factor is invalid.</dd>
<dt>JDR_FMT1</dt>
<dd>Data format error. The input JPEG data can be collapted.</dd>
</dl>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>jd_decomp</tt> function is the second stage of a JPEG decompression session. It decompresses the input JPEG stream and outputs it via user defined output function. After this function, the decompressor object is no longer valid.</p>
<p>The scaling factor can be specified on decompresson. It descales the size of the output image by 1/2, 1/4 or 1/8. For example, when decompress a JPEG image of 1024x768 in 1/4 scaling, the decmopressed image will be output in 256x192. The scaling ratio of 1/2 and 1/4 will slightly decrease the decompression speed compared to 1/1 due to averaging process. However scaling ratio of 1/8 will 2-3 times faster than 1/1, because IDCT and averaging process for each block can be skipped. This characteristic is sutable to create thumbnails.</p>
</div>
<p class="foot"><a href="../00index.html">Return</a></p>
</body>
</html>

@ -1,53 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="TJpgDec" href="../00index.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>TJpgDec - Input Function</title>
</head>
<body>
<div class="para func">
<h2>Input Function</h2>
<p>User defined input function to read data from input stream.</p>
<pre>
size_t in_func (
JDEC* <em>jdec</em>, <span class="c">/* Pointer to the decompression object */</span>
uint8_t* <em>buff</em>, <span class="c">/* Pointer to buffer to store the read data */</span>
size_t <em>ndata</em> <span class="c">/* Number of bytes to read/remove */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>jdec</dt>
<dd>Decompression object of this session.</dd>
<dt>buff</dt>
<dd>Points the read buffer to store the data read form the input stream. A null pointer specifies to remove the data from the input stream.</dd>
<dt>ndata</dt>
<dd>Number of bytes to read/remove from the input stream.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>Returns number of bytes read/removed. If any value not expected is returned, the <tt>jd_prepare</tt> and <tt>jd_decomp</tt> function aborts with JDR_INP.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>This function is the data input interface of the TJpgDec module. The corresponding decompression session can be identified by the session identifier <tt>jdec->device</tt> passed to the 5th argument of <tt>jd_prepare</tt> function.</p>
</div>
<p class="foot"><a href="../00index.html">Return</a></p>
</body>
</html>

@ -1,46 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="TJpgDec" href="../00index.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>TjpgDec - JDEC</title>
</head>
<body>
<div class="para">
<h2>JDEC</h2>
<p>The <tt>JDEC</tt> structure holds the data, pointer and flags to manage the decompression session. Application program must not change any member in this structure.</p>
<pre>
<span class="k">typedef</span> <span class="k">struct</span> JDEC JDEC;
<span class="k">struct</span> JDEC {
size_t dctr; <span class="c">/* Number of bytes available in the input buffer */</span>
uint8_t* dptr; <span class="c">/* Current data read ptr */</span>
uint8_t* inbuf; <span class="c">/* Bit stream input buffer */</span>
uint8_t dmsk; <span class="c">/* Current bit in the current read byte */</span>
uint8_t scale; <span class="c">/* Output scaling ratio */</span>
uint8_t msx, msy; <span class="c">/* MCU size in unit of block (width, height) */</span>
uint8_t qtid[3]; <span class="c">/* Quantization table ID of each component */</span>
uint8_t ncomp; <span class="c">/* Number of color components (1:grayscale, 3:color) */</span>
int16_t dcv[3]; <span class="c">/* Previous DC element of each component */</span>
uint16_t nrst; <span class="c">/* Restart inverval */</span>
uint16_t width, height; <span class="c">/* Size of the input image (pixel) */</span>
uint8_t* huffbits[2][2]; <span class="c">/* Huffman bit distribution tables [yc][dcac] */</span>
uint16_t* huffcode[2][2]; <span class="c">/* Huffman code word tables [yc][dcac] */</span>
uint8_t* huffdata[2][2]; <span class="c">/* Huffman decoded data tables [yc][dcac] */</span>
int32_t* qttbl[4]; <span class="c">/* De-quaitizer tables [id] */</span>
void* workbuf; <span class="c">/* Working buffer for IDCT and RGB output */</span>
uint8_t* mcubuf; <span class="c">/* Working buffer for the MCU */</span>
void* pool; <span class="c">/* Pointer to available memory pool */</span>
size_t sz_pool; <span class="c">/* Size of momory pool (bytes available) */</span>
size_t (*infunc)(JDEC*, uint8_t*, size_t); <span class="c">/* Pointer to jpeg stream input function */</span>
void* device; <span class="c">/* Pointer to I/O device identifiler for the session */</span>
};
</pre>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

@ -1,60 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="TJpgDec" href="../00index.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>TJpgDec - Output Function</title>
</head>
<body>
<div class="para func">
<h2>Output Function</h2>
<p>User defined output function to write decompressed pixels to the output device.</p>
<pre>
int out_func (
JDEC* <em>jdec</em>, <span class="c">/* Pointer to the decompression object */</span>
void* <em>bitmap</em>, <span class="c">/* Bitmap to be output */</span>
JRECT* <em>rect</em> <span class="c">/* Rectangle to output */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>jdec</dt>
<dd>Decompression object of this session.</dd>
<dt>bitmap</dt>
<dd>Decompressed image to be output.</dd>
<dt>rect</dt>
<dd>Specifies output rectangle where in the image. Type is defined in <tt>tjpgd.h</tt></dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>Normally returns 1. It lets TJpgDec to continue the decompressing process. If a 0 is returned, <tt>jd_decomp</tt> function aborts with JDR_INTR. This is useful to interrupt the decompression process.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>This function is the data output interface of the TJpgDec module. The corresponding decompression session can be identified by the session identifier <tt>jdec->device</tt> passed to the 5th argument of <tt>jd_prepare</tt> function.</p>
<p>The bitmap is sent to the frame buffer or display device in this function. The first pixel in the bitmap is the left-top of the rectangular, the second one is next right and last pixel is the bottom-right of the rectangle. Because the JPEG image is compressed and streamed in unit of MCU (Minimum Coded Unit), TJpgDec outputs the image in MCU by MCU. The size of MCU depends on the sampling factor of JPEG compression, typically in 8x8, 16x8 or 16x16, but the rectangles on right end and bottom end of the image will be clipped.</p>
<p>The output pixel format is defined by <tt>JD_FORMAT</tt> option in the <tt>tjpgdcnf.h</tt> as shown below.</p>
<table class="lst">
<tr><th><tt>JD_FORMAT</tt></th><th>Pixel Format</th></tr>
<tr><td>0 (RGB888)</td><td><tt>uint8_t bitmap[] = {R1, G1, B1, R2, G2, B2, ....</tt></td></tr>
<tr><td>1 (RGB565)</td><td><tt>uint16_t bitmap[] = {rrrrrggggggbbbbb, ....</tt></td></tr>
<tr><td>2 (Grayscale)</td><td><tt>uint8_t bitmap[] = {Y1, Y2, Y3, ....</tt></td></tr>
</table>
</div>
<p class="foot"><a href="../00index.html">Return</a></p>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

@ -1,69 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="TJpgDec" href="../00index.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>TJpgDec - jd_prepare</title>
</head>
<body>
<div class="para func">
<h2>jd_prepare</h2>
<p>The jd_prepare function analyzes the JPEG data and create a decompression object for subsequnet decompression process.</p>
<pre>
JRESULT jd_prepare (
JDEC* <em>jdec</em>, <span class="c">/* Pointer to blank decompression object */</span>
size_t (*<em>infunc</em>)(JDEC*, uint8_t*, size_t), <span class="c">/* Pointer to input function */</span>
void* <em>work</em>, <span class="c">/* Pointer to the work area */</span>
size_t <em>sz_work</em>, <span class="c">/* Size of the work area */</span>
void* <em>device</em> <span class="c">/* Session identifier for the session */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>jdec</dt>
<dd>Specifies the <a href="jdec.html">decompression object</a> to be initialized. The decompression object is used by subsequent decompression process.</dd>
<dt>input</dt>
<dd>Pointer to the user defined <a href="input.html">data input function</a>. The <tt>jd_prepare</tt> and <tt>jd_decomp</tt> function call this function to read the JPEG data from the input stream.</dd>
<dt>work</dt>
<dd>Pointer to the work area for this session. It should be aligned to the word boundary, or it can result a hard fault on some processors.</dd>
<dt>sz_work</dt>
<dd>Size of the work area in unit of byte. TJpgDec requires upto 3092 bytes of work area depends on the built-in parameter tables of the JPEG image to deccompress.</dd>
<dt>device</dt>
<dd>Pointer to the user defined session identifier for this session. It is stored to the member <tt>device</tt> in the decompression object. It can be refered by I/O functions to identify the corresponding session. If this feature is not needed, set null and do not care about this.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<dl class="ret">
<dt>JDR_OK</dt>
<dd>Function succeeded and the decompression object is valid.</dd>
<dt>JDR_INP</dt>
<dd>An error occured in input function due to a hard error or wrong stream termination.</dd>
<dt>JDR_MEM1</dt>
<dd>Insufficient work area for this JPEG image.</dd>
<dt>JDR_MEM2</dt>
<dd>Insufficient input buffer for this JPEG image. JD_SZBUF may be too small.</dd>
<dt>JDR_FMT1</dt>
<dd>Data format error. The JPEG data can be collapted.</dd>
<dt>JDR_FMT3</dt>
<dd>Not supported JPEG standard. May be a progressive JPEG image.</dd>
</dl>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The jd_prepare function is the first stage of a JPEG decompression session. It analyzes the JPEG image and create parameter tables for decompression. After the function succeeded, the session gets ready to decompress the JPEG image by the jd_decomp fnction. The application program can refer the dimensions of the JPEG image stored in the decompression object. These information will be used to configure the output device and parameters for subsequent decompression stage.</p>
</div>
<p class="foot"><a href="../00index.html">Return</a></p>
</body>
</html>
Loading…
Cancel
Save