Skip to content

Commit

Permalink
Changed mediaApp and added JPG viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
MiLeG committed Jan 9, 2019
1 parent e2ee5cd commit 3765b5c
Show file tree
Hide file tree
Showing 13 changed files with 3,535 additions and 19 deletions.
346 changes: 329 additions & 17 deletions src/MAKERphone.cpp

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/MAKERphone.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extern HardwareSerial Serial1;
//Fonts and sprites to use
#include "utility/Free_Fonts.h"
#include "utility/sprites.c"

#include "utility/JPEGDecoder.h"

//Setup for MP3 playback

Expand Down Expand Up @@ -271,7 +271,21 @@ class MAKERphone:public Buttons, public GUI
void listMP3(const char * dirname, uint8_t levels);
void mp3player(String songName);
void mediaApp();
int8_t mediaMenu(String* title, uint8_t length);
void mediaMenuDrawBox(String title, uint8_t i, int32_t y);
void mediaMenuDrawCursor(uint8_t i, int32_t y, bool pressed);
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string);
String mediaItems[3] = {
"Music",
"Photo",
"Video",
};
String photoFiles[255];
void listPhotos(const char *dirname, uint8_t levels);
void drawJpeg(String filename, int xpos, int ypos);
void jpegRender(int xpos, int ypos);
void jpegInfo();
uint8_t photoCount = 0;

//Contacts app
void contactsMenuDrawBox(String contact, String number, uint8_t i, int32_t y);
Expand Down
1 change: 0 additions & 1 deletion src/TFT_eSPI/TFT_eSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5201,7 +5201,6 @@ void TFT_eSprite::pushImage(int32_t x, int32_t y, uint32_t w, uint32_t h, uint1
}
}


/***************************************************************************************
** Function name: pushImage
** Description: push 565 colour FLASH (PROGMEM) image into a defined area
Expand Down
1 change: 1 addition & 0 deletions src/utility/JPEGDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "JPEGDecoder/src/JPEGDecoder.h"
53 changes: 53 additions & 0 deletions src/utility/JPEGDecoder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Arduino JPEGDecoder library
===========

This Arduino library supports the rendering of Jpeg files stored both on SD card and in arrays within program memory (FLASH) onto a TFT display. In addition images stored in the SPIFFS Flash filing system or "PROGMEM" arrays can be used with the ESP8266 processor. Use the ESP8266 board Core 2.3.0 in the Arduino IDE to avoid File definition conflicts if the SPIFFS and SD libraries are used together.

The library works on the Arduino Due, ESP32 and ESP8266 (e.g. NodeMCU 1.0). Users have also reported success with the STM32 based processor boards.

Example images can be found in the "extras" folder.

Jpeg files in the "Progressive" format (where image data is compressed in multiple passes with progressively higher detail) are not supported since this would require much more memory, or too many Inverse Discrete Cosine Transform's for typical embedded systems.

High Jpeg compression ratios work best on images with smooth colour changes, however the Baboon40.jpg image at only 23.8 KBytes renders quite nicely. Typically a 480x320 image can be compressed without much degradation to less than 32 KBytes, in comparison a 24 bit BMP image would occupy 461 KBytes! For comaprison the 480 x 320 Mouse480 image has been to compressed to a mere 6.45 Kbytes!

When storing the jpeg in a memory array bear in mind the Arduino has a maximum 32767 byte limit for the maximum size of an array (32 KBytes minus 1 byte).

The decompression of Jpeg images needs more RAM than an UNO provides, thus this library is targetted at processors with more RAM. The library has been tested with Arduino Due and ESP8266/ESP32 based boards.

The decompression of Jpegs involves a lot of maths, so it takes a Due about ~1.3s to render a fullscreen (480x320 pixel) image and the Mega will take ~5s to do the same. The time for smaller images will reduce roughly pro-rata with the total pixel count. An ESP8266 running at 160MHz and 40MHz SPI coupled to a 320x240 ILI9341 display can render a Jpeg in as little as 240ms.

This library supports either the SD library (and SdFat for Due). The SdFat allows a bit-bashed SPI interface to an SD Card which can be convenient for example on pins 50, 51 and 52 of a Due (on Mega these are hardware SPI).

The library has been tested with the 1.8.1 version of the Arduino IDE and may generate error messages at compile time on other versions because "#ifdef \_\_AVR\_\_" is used to distinguish between the Mega and Due and select the correct libraries.

The library has been tested with 3.2" and 3.0" displays based on the HX8357B, HX8357C and ILI9481 driver chips with a 16 bit parallel interface. Adapting the example sketch for other TFT drivers and their graphics libraries should be quite easy if they support either setWindow() or SetAddrWindow() and pushColor() functions as found in the Adafruit_GFX library.

On a Mega the number of images stored in FLASH must be limited because it they are large enough to push the executable code start over the 64K 16 bit address limit then the Mega will fail to boot even though the sketch compiles and uploads correctly. This is a limitation imposed by the Arduino environment not this library! The Arduino Mega is not recommended as it does not reliably decode some jpeg images possibly due to a shortage of RAM. The Due will work fine with much bigger image sets in FLASH.

The ESP8266 and ESP32 has been tested with an ILI9341 library using the SPI interface, with Jpeg images stored in SPIFFS and in Flash arrays.

SD and SPIFFS filenames can be in String or character array format. File handles can also be used.

This library has been based on the excellent picojpeg code and the Arduino library port by Makoto Kurauchi here:
https://github.com/MakotoKurauchi/JPEGDecoder


Makoto's original Readme below:
==============================

JPEG Decoder for Arduino

概要
----
Arduino 用 JPEG デコーダです。デコーダ部には [picojpeg](https://code.google.com/p/picojpeg/) を使用しています。

サンプルコード
----
###SerialCsvOut

SD カード上の JPEG ファイルをブロックごとにデコードし、シリアルから CSV を出力します。

変更履歴
----
V0.01 - 最初のリリース
35 changes: 35 additions & 0 deletions src/utility/JPEGDecoder/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#######################################
# Syntax Coloring Map
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################

JPEGDecoder KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

JpegDec KEYWORD2
pImage KEYWORD2
width KEYWORD2
height KEYWORD2
comps KEYWORD2
MCUSPerRow KEYWORD2
MCUSPerCol KEYWORD2
scanType KEYWORD2
MCUWidth KEYWORD2
MCUHeight KEYWORD2
MCUx KEYWORD2
MCUy KEYWORD2
JPEGDecoder KEYWORD2
decode KEYWORD2
decodeFile KEYWORD2
decodeSdFile KEYWORD2
decodeFsFile KEYWORD2
decodeArray KEYWORD2
available KEYWORD2
abort KEYWORD2
read KEYWORD2
readSwappedBytes KEYWORD2
29 changes: 29 additions & 0 deletions src/utility/JPEGDecoder/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "JPEGDecoder",
"version": "1.7.9",
"keywords": "jpeg, jpg, decoder, TFT",
"description": "A JPEG decoder library, tested on Mega, Due and ESP8266",
"repository":
{
"type": "git",
"url": "https://github.com/Bodmer/JPEGDecoder.git"
},
"authors":
[
{
"name": "Bodmer",
"email": "[email protected]",
"maintainer": true
},
{
"name": "Makoto Kurauchi",
"url": "http://yushakobo.jp"
},
{
"name": "Rich Geldreich",
"email": "[email protected]"
}
],
"frameworks": "arduino",
"platforms": ["atmelavr","atmelsam","espressif8266"]
}
10 changes: 10 additions & 0 deletions src/utility/JPEGDecoder/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=JPEGDecoder
version=1.7.9
author=Bodmer <[email protected]>, Makoto Kurauchi, Rich Geldreich
maintainer=Bodmer
sentence= Jpeg decoder tested with Arduino Mega, Arduino Due and ESP8266 based NodeMCU 1.0
paragraph=Decodes jpeg images stored in arrays, SD card files and SPIFFS files
category=Display
url=https://github.com/Bodmer/JPEGDecoder
architectures=*
includes=JPEGDecoder.h
Loading

0 comments on commit 3765b5c

Please sign in to comment.