Skip to content

Commit

Permalink
libjpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Mar 5, 2020
1 parent dd4de1d commit 4200304
Show file tree
Hide file tree
Showing 67 changed files with 36,274 additions and 30 deletions.
37 changes: 37 additions & 0 deletions src/eez/libs/image/jpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <memory.h>
#include <assert.h>

#if defined(EEZ_PLATFORM_STM32)
#include <jpeglib.h>
#endif

#include "toojpeg.h"

#include <eez/system.h>
Expand Down Expand Up @@ -86,6 +90,14 @@ uint8_t *jpegDecode(const char *filePath, int *imageWidth, int *imageHeight) {
uint32_t fileSize;
uint32_t bytesRead;

#if defined(EEZ_PLATFORM_STM32)
struct jpeg_decompress_struct cinfo;
int rc;
int width;
int height;
int pixelSize;
#endif

eez::File file;
if (!file.open(filePath, FILE_OPEN_EXISTING | FILE_READ)) {
goto ErrorNoClose;
Expand All @@ -104,6 +116,30 @@ uint8_t *jpegDecode(const char *filePath, int *imageWidth, int *imageHeight) {

file.close();

#if defined(EEZ_PLATFORM_STM32)
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, g_fileData, fileSize);
rc = jpeg_read_header(&cinfo, TRUE);
if (rc != 1) {
goto ErrorNoClose;
}
jpeg_start_decompress(&cinfo);
width = cinfo.output_width;
height = cinfo.output_height;
pixelSize = cinfo.output_components;
if (width > 480 || height > 272 || pixelSize != 4) {
goto Error;
}
while (cinfo.output_scanline < cinfo.output_height) {
unsigned char *buffer_array[1];
buffer_array[0] = g_decodeBuffer + cinfo.output_scanline * width * pixelSize;
jpeg_read_scanlines(&cinfo, buffer_array, 1);

}
*imageWidth = width;
*imageHeight = height;
return g_decodeBuffer;
#else
g_decodeDynamicMemory = g_decodeBuffer;

njInit();
Expand All @@ -120,6 +156,7 @@ uint8_t *jpegDecode(const char *filePath, int *imageWidth, int *imageHeight) {
*imageHeight = njGetHeight();

return njGetImage();
#endif

Error:
file.close();
Expand Down
2 changes: 1 addition & 1 deletion src/eez/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int main(int argc, char **argv) {
/* Clear reset flags */
RCC->CSR |= RCC_CSR_RMVF;
}
MX_IWDG_Init();
//MX_IWDG_Init();

HAL_Init();
SystemClock_Config();
Expand Down
4 changes: 4 additions & 0 deletions src/third_party/stm32_truestudio/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FatFs/src"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/LwIP/src/include/compat/posix/net"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/LibJPEG/include"/>
</option>
<option id="com.atollic.truestudio.gcc.symbols.defined.1670122205" name="Defined symbols" superClass="com.atollic.truestudio.gcc.symbols.defined" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
Expand Down Expand Up @@ -197,6 +198,7 @@
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FatFs/src"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/LwIP/src/include/compat/posix/net"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/LibJPEG/include"/>
</option>
<option id="com.atollic.truestudio.exe.debug.toolchain.gpp.optimization.level.1860305798" name="Optimization Level" superClass="com.atollic.truestudio.exe.debug.toolchain.gpp.optimization.level" useByScannerDiscovery="false" value="com.atollic.truestudio.gpp.optimization.level.0g" valueType="enumerated"/>
<option id="com.atollic.truestudio.gpp.cppstandard.1842281748" name="C++ standard" superClass="com.atollic.truestudio.gpp.cppstandard" useByScannerDiscovery="false" value="com.atollic.truestudio.gpp.cppstandard.cpp0x" valueType="enumerated"/>
Expand Down Expand Up @@ -374,6 +376,7 @@
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FatFs/src"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/LwIP/src/include/compat/posix/net"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/LibJPEG/include"/>
</option>
<option id="com.atollic.truestudio.gcc.symbols.defined.1670122205" name="Defined symbols" superClass="com.atollic.truestudio.gcc.symbols.defined" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
Expand Down Expand Up @@ -494,6 +497,7 @@
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FatFs/src"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/LwIP/src/include/compat/posix/net"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/LibJPEG/include"/>
</option>
<option id="com.atollic.truestudio.gpp.cppstandard.1729714908" name="C++ standard" superClass="com.atollic.truestudio.gpp.cppstandard" useByScannerDiscovery="false" value="com.atollic.truestudio.gpp.cppstandard.cpp0x" valueType="enumerated"/>
<inputType id="com.atollic.truestudio.gpp.input.892002667" superClass="com.atollic.truestudio.gpp.input"/>
Expand Down
6 changes: 3 additions & 3 deletions src/third_party/stm32_truestudio/.mxproject

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions src/third_party/stm32_truestudio/Inc/jconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* jconfig.h
*
* Copyright (C) 1991-1994, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file documents the configuration options that are required to
* customize the JPEG software for a particular system.
*
* The actual configuration options for a particular installation are stored
* in jconfig.h. On many machines, jconfig.h can be generated automatically
* or copied from one of the "canned" jconfig files that we supply. But if
* you need to generate a jconfig.h file by hand, this file tells you how.
*
*/

/*
* these macros provide simple implementation of the system memory
* dependent portion of the JPEG memory manager. This implementation
* assumes that no backing-store files are needed: all required space
* can be obtained from malloc().
* This is very portable in the sense that it'll compile on almost anything,
* but you'd better have lots of main memory (or virtual memory) if you want
* to process big images.
* Note that the max_memory_to_use option is ignored by this implementation.
*/

/*Import File manager wrapping*/
#include "jdata_conf.h"

/*
* These symbols indicate the properties of your machine or compiler.
* #define the symbol if yes, #undef it if no.
*/

#define NO_GETENV
#undef USE_MSDOS_MEMMGR
#undef USE_MAC_MEMMGR
/*Enabling 'USE_HEAP_MEM' disables the use of 'temp files' from 'backing-store management' : refer to 'jmemsys.h' for details.
Moreover, this porting version does not proposed validated 'temp files' support : it is recommended to keep this macro 'defined'.*/
#define USE_HEAP_MEM
#define MAX_ALLOC_CHUNK 0x10000 /* 64kB */

/* Does your compiler support function prototypes?
* (If not, you also need to use ansi2knr, see install.txt)
*/
#define HAVE_PROTOTYPES

/* Does your compiler support the declaration "unsigned char" ?
* How about "unsigned short" ?
*/
#define HAVE_UNSIGNED_CHAR
#define HAVE_UNSIGNED_SHORT

/* Define "void" as "char" if your compiler doesn't know about type void.
* NOTE: be sure to define void such that "void *" represents the most general
* pointer type, e.g., that returned by malloc().
*/
/* #define void char */

/* Define "const" as empty if your compiler doesn't know the "const" keyword.
*/
/* #define const */

/* Define this if an ordinary "char" type is unsigned.
* If you're not sure, leaving it undefined will work at some cost in speed.
* If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal.
*/
#undef CHAR_IS_UNSIGNED

/* Define this if your system has an ANSI-conforming <stddef.h> file.
*/
#define HAVE_STDDEF_H

/* Define this if your system has an ANSI-conforming <stdlib.h> file.
*/
#define HAVE_STDLIB_H

/* Define this if your system does not have an ANSI/SysV <string.h>,
* but does have a BSD-style <strings.h>.
*/
#undef NEED_BSD_STRINGS

/* Define this if your system does not provide typedef size_t in any of the
* ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in
* <sys/types.h> instead.
*/
#undef NEED_SYS_TYPES_H

/* For 80x86 machines, you need to define NEED_FAR_POINTERS,
* unless you are using a large-data memory model or 80386 flat-memory mode.
* On less brain-damaged CPUs this symbol must not be defined.
* (Defining this symbol causes large data structures to be referenced through
* "far" pointers and to be allocated with a special version of malloc.)
*/
#undef NEED_FAR_POINTERS

/* Define this if your linker needs global names to be unique in less
* than the first 15 characters.
*/
#undef NEED_SHORT_EXTERNAL_NAMES

/* Although a real ANSI C compiler can deal perfectly well with pointers to
* unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
* and pseudo-ANSI compilers get confused. To keep one of these bozos happy,
* define INCOMPLETE_TYPES_BROKEN. This is not recommended unless you
* actually get "missing structure definition" warnings or errors while
* compiling the JPEG code.
*/
#undef INCOMPLETE_TYPES_BROKEN

/* Define "boolean" as unsigned char, not int, on Windows systems.
*/
#ifdef _WIN32
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif

/*
* The following options affect code selection within the JPEG library,
* but they don't need to be visible to applications using the library.
* To minimize application namespace pollution, the symbols won't be
* defined unless JPEG_INTERNALS has been defined.
*/

#ifdef JPEG_INTERNALS

/* Define this if your compiler implements ">>" on signed values as a logical
* (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift,
* which is the normal and rational definition.
*/
#undef RIGHT_SHIFT_IS_UNSIGNED

#endif /* JPEG_INTERNALS */

/*
* The remaining options do not affect the JPEG library proper,
* but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c).
* Other applications can ignore these.
*/

#ifdef JPEG_CJPEG_DJPEG

/* These defines indicate which image (non-JPEG) file formats are allowed. */

#define BMP_SUPPORTED /* BMP image file format */
#define GIF_SUPPORTED /* GIF image file format */
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
#undef RLE_SUPPORTED /* Utah RLE image file format */
#define TARGA_SUPPORTED /* Targa image file format */

/* Define this if you want to name both input and output files on the command
* line, rather than using stdout and optionally stdin. You MUST do this if
* your system can't cope with binary I/O to stdin/stdout. See comments at
* head of cjpeg.c or djpeg.c.
*/
#undef TWO_FILE_COMMANDLINE

/* Define this if your system needs explicit cleanup of temporary files.
* This is crucial under MS-DOS, where the temporary "files" may be areas
* of extended memory; on most other systems it's not as important.
*/
#undef NEED_SIGNAL_CATCHER

/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb").
* This is necessary on systems that distinguish text files from binary files,
* and is harmless on most systems that don't. If you have one of the rare
* systems that complains about the "b" spec, define this symbol.
*/
#undef DONT_USE_B_MODE

/* Define this if you want percent-done progress reports from cjpeg/djpeg.
*/
#undef PROGRESS_REPORT

#endif /* JPEG_CJPEG_DJPEG */
40 changes: 40 additions & 0 deletions src/third_party/stm32_truestudio/Inc/jdata_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
******************************************************************************
* File Name : jdata_conf.h
* Description : This file provides header to "jdata_conf.h" module.
* It implements also file based read/write functions.
*
******************************************************************************
*
* Copyright (c) 2019 STMicroelectronics. All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
**/

/* Includes ------------------------------------------------------------------*/

#include <stdio.h>

/*FreeRtos Api*/
#include "cmsis_os.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*This defines the memory allocation methods.*/
#define JMALLOC pvPortMalloc
#define JFREE vPortFree

/*This defines the File data manager type.*/
#undef JFILE

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Loading

0 comments on commit 4200304

Please sign in to comment.