Graphics framework for GR-PEACH. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE
Dependents: ImageZoomInout_Sample ImageRotaion_Sample ImageScroll_Sample GR-PEACH_LCD_4_3inch_Save_to_USB ... more
License
When you use this library, we judge you have agreed to the following contents.
https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE
Note
If you import the GraphicsFramework library, please import GR-PEACH_video library and R_BSP library together.
JPEG Converter
The JPEG Converter driver implements encode and decode functionality which uses the JCU of the RZ/A Series.
Hello World!
Import programJCU_HelloWorld
Hello World for JCU(JPEG Codec Unit). JCU is JPEG codec unit of RZ/A1. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE
API
Import library
Data Structures |
|
struct | bitmap_buff_info_t |
Bitmap data setting struct.
More...
|
|
struct | encode_options_t |
Encode option setting.
More...
|
|
Public Types |
|
enum |
jpeg_conv_error_t
{
JPEG_CONV_OK = 0, JPEG_CONV_JCU_ERR = -1, JPEG_CONV_FORMA_ERR = -2, JPEG_CONV_PARAM_ERR = -3, JPEG_CONV_BUSY = -4, JPEG_CONV_PARAM_RANGE_ERR = -7 } |
Error codes. More... |
|
enum |
wr_rd_swa_t
{
WR_RD_WRSWA_NON = 0, WR_RD_WRSWA_8BIT = 1, WR_RD_WRSWA_16BIT = 2, WR_RD_WRSWA_16_8BIT = 3, WR_RD_WRSWA_32BIT = 4, WR_RD_WRSWA_32_8BIT = 5, WR_RD_WRSWA_32_16BIT = 6, WR_RD_WRSWA_32_16_8BIT = 7 } |
Write/Read image pixcel frame buffer swap setting. More... |
|
enum | wr_rd_format_t { WR_RD_YCbCr422 = 0x00, WR_RD_ARGB8888 = 0x01, WR_RD_RGB565 = 0x02 } |
Write/Read image pixcel format selects. More... |
|
enum | sub_sampling_t { SUB_SAMPLING_1_1 = 0x00, SUB_SAMPLING_1_2 = 0x01, SUB_SAMPLING_1_4 = 0x02, SUB_SAMPLING_1_8 = 0x03 } |
Thinning output image selects. More... |
|
enum | cbcr_offset_t { CBCR_OFFSET_0 = 0x00, CBCR_OFFSET_128 = 0x01 } |
Cb/Cr range selects for decode. More... |
|
Public Member Functions |
|
JPEG_Converter () | |
Constructor method of JPEG converter(encode/decode)
|
|
virtual | ~JPEG_Converter () |
Destructor method of JPEG converter(encode/decode)
|
|
JPEG_Converter::jpeg_conv_error_t | decode (void *pJpegBuff, bitmap_buff_info_t *psOutputBuff) |
Decode JPEG to rinear data.
|
|
JPEG_Converter::jpeg_conv_error_t | decode (void *pJpegBuff, bitmap_buff_info_t *psOutputBuff, decode_options_t *pOptions) |
JPEG data decode to bitmap.
|
|
JPEG_Converter::jpeg_conv_error_t | encode ( bitmap_buff_info_t *psInputBuff, void *pJpegBuff, size_t *pEncodeSize) |
Encode rinear data to JPEG.
|
|
JPEG_Converter::jpeg_conv_error_t | encode ( bitmap_buff_info_t *psInputBuff, void *pJpegBuff, size_t *pEncodeSize, encode_options_t *pOptions) |
Bitmap data encode to JPEG.
|
|
JPEG_Converter::jpeg_conv_error_t | SetQuality (const uint8_t qual) |
Set encode quality.
|
Correspondence file
A correspondence file of JPEG Converter is as the following table.
JPEG | Correspondence |
Width | >0(greater than 0) |
Height | >0(greater than 0) |
Color format | YCbCr444, YCbCr422, YCbCr420, YCbCr411 |
Bitmap | Correspondence |
Width | >0(greater than 0) |
Height | >0(greater than 0) |
Color format | YCbCr422 |
Notice
You run JPEG converter once destruction each time.
You set whether these JPEG files aren't input, or it check error setting decode(set in "flag" = true). The JPEG file which becomes correspondence outside will be the following condition.
- File besides the above-mentioned correspondence file.
- As information in the JPEG file, WIDTH or HEIGHT is larger than output buffer setting.
Buffer area is used encode/decode, set 8 bytes align and non-cash memory area. The output buffer when decoding, is made beyond the size decided in the size of the JPEG file, the format, setting of thinning out. You make output buffer for decode/encode to enough big size in order to stock this result. JPEG Converter, if you do not particularly perform specified, does not check size against the output data at the time of encoding and decoding. You set the output buffer so that there is no effect of corruption by the output data.
Color format
Color format in case to be converted from Bitmap to JPEG is either ARGB8888 or RGB555, YCbCr422.
Color format of the If you want to convert from JPEG file to Bitmap file is YCbCr422.
You correct "alpha(member of decode_options_t)" of setting and "output_cb_cr_offset(member of decode_options_t)" according to color format when decoding.
- example
decode to ARGB8888(WR_RD_ARGB8888 set in format member of bitmap_buff_info_t)
alpha = 0x01-0xFF
output_cb_cr_offset = CBCR_OFFSET_0
decode to YCbCr422(WR_RD_YCbCr422 set in format member of bitmap_buff_info_t)
alpha = 0
output_cb_cr_offset = CBCR_OFFSET_0 or CBCR_OFFSET_128
decode to RGB565(WR_RD_RGB565 set in format member of bitmap_buff_info_t)
alpha = 0
output_cb_cr_offset = CBCR_OFFSET_0
Decode/encode settings are optional
If omitted encode/decode settings, it will work with the following settings.
[Decode option setting (member of decode_options_t)]
- Vertical sub sampling is thinning output image to 1/1.
- Horizontal sub sampling is thinning output image to 1/1.
- Output data of Cb/Cr range is -128 to 127.
- Output data of swap in 8-bit units: 2-1-4-3-6-5-8-7.
- Alpha value of 0.
- JPEG format correspondence outside error check.
- It decode in a synchronous function.
[Encode option setting (member of encode_options_t)]
- DRI value is 0.
- Encoding JPEG file start width offset is 0.
- Encoding JPEG file start height offset is 0.
- Input data of Cb/Cr range of input data is -128 to 127.
- Input data swap in 8-bit units: 2-1-4-3-6-5-8-7.
- It don't check encode size.
- Quantization Y use default table(Quality75).
- Quantization C use default table(Quality75).
- Huffman Y DC use default table.
- Huffman C DC use default table.
- Huffman Y AC use default table.
- Huffman C AC use default table.
- It encode in a synchronous function.
Synchronous/asynchronous switching
Decoding and encoding setting to operate asynchronously by setting a callback function(decode_options_t and encode_options_t).
Quality
Quality changes are possible.
If you want to change the Quality, please specify the table made of Quality you want to change the address of the setting.
If you do not want to change the Quality, it will operate at Quality75.
RGA
The RGA library implements fast drawing functionality which uses the RGA of the RZ/A Series.
Supporting compiler is ARMCC, GCC ARM and IAR.
Hello World!
Import programRGA_HelloWorld
Hello World for RGA(Renesas Graphics Architecture). RGA is the Graphics Library of RZ/A1. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE
jcu/jcu_driver/JPEG_Coverter.cpp@1:7b90e31adc5b, 2015-10-09 (annotated)
- Committer:
- dkato
- Date:
- Fri Oct 09 08:01:56 2015 +0000
- Revision:
- 1:7b90e31adc5b
- Parent:
- 0:37e1e6a45ced
- Child:
- 7:df2bc72f7fb7
bug fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:37e1e6a45ced | 1 | /******************************************************************************* |
dkato | 0:37e1e6a45ced | 2 | * DISCLAIMER |
dkato | 0:37e1e6a45ced | 3 | * This software is supplied by Renesas Electronics Corporation and is only |
dkato | 0:37e1e6a45ced | 4 | * intended for use with Renesas products. No other uses are authorized. This |
dkato | 0:37e1e6a45ced | 5 | * software is owned by Renesas Electronics Corporation and is protected under |
dkato | 0:37e1e6a45ced | 6 | * all applicable laws, including copyright laws. |
dkato | 0:37e1e6a45ced | 7 | * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING |
dkato | 0:37e1e6a45ced | 8 | * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT |
dkato | 0:37e1e6a45ced | 9 | * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
dkato | 0:37e1e6a45ced | 10 | * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. |
dkato | 0:37e1e6a45ced | 11 | * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS |
dkato | 0:37e1e6a45ced | 12 | * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE |
dkato | 0:37e1e6a45ced | 13 | * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR |
dkato | 0:37e1e6a45ced | 14 | * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE |
dkato | 0:37e1e6a45ced | 15 | * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
dkato | 0:37e1e6a45ced | 16 | * Renesas reserves the right, without notice, to make changes to this software |
dkato | 0:37e1e6a45ced | 17 | * and to discontinue the availability of this software. By using this software, |
dkato | 0:37e1e6a45ced | 18 | * you agree to the additional terms and conditions found by accessing the |
dkato | 0:37e1e6a45ced | 19 | * following link: |
dkato | 0:37e1e6a45ced | 20 | * http://www.renesas.com/disclaimer* |
dkato | 0:37e1e6a45ced | 21 | * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved. |
dkato | 0:37e1e6a45ced | 22 | *******************************************************************************/ |
dkato | 0:37e1e6a45ced | 23 | |
dkato | 0:37e1e6a45ced | 24 | /**************************************************************************//** |
dkato | 0:37e1e6a45ced | 25 | * @file jpeg_coverter.cpp |
dkato | 0:37e1e6a45ced | 26 | * @version 1.00 |
dkato | 0:37e1e6a45ced | 27 | * $Rev: 1 $ |
dkato | 0:37e1e6a45ced | 28 | * $Date:: 2015-08-06 16:33:52 +0900#$ |
dkato | 0:37e1e6a45ced | 29 | * @brief Decodes JPEG data and encodes to JPEG data |
dkato | 0:37e1e6a45ced | 30 | ******************************************************************************/ |
dkato | 0:37e1e6a45ced | 31 | |
dkato | 0:37e1e6a45ced | 32 | /****************************************************************************** |
dkato | 0:37e1e6a45ced | 33 | Includes <System Includes> , "Project Includes" |
dkato | 0:37e1e6a45ced | 34 | ******************************************************************************/ |
dkato | 0:37e1e6a45ced | 35 | #include <string.h> |
dkato | 0:37e1e6a45ced | 36 | #include <stdio.h> |
dkato | 0:37e1e6a45ced | 37 | #include "r_typedefs.h" |
dkato | 0:37e1e6a45ced | 38 | #include "r_jcu_api.h" |
dkato | 0:37e1e6a45ced | 39 | #include "JPEG_Converter.h" |
dkato | 0:37e1e6a45ced | 40 | #include "converter_wrapper.h" |
dkato | 1:7b90e31adc5b | 41 | #include "mbed_error.h" |
dkato | 1:7b90e31adc5b | 42 | #include "rtos.h" |
dkato | 1:7b90e31adc5b | 43 | #include "Semaphore.h" |
dkato | 0:37e1e6a45ced | 44 | |
dkato | 0:37e1e6a45ced | 45 | |
dkato | 0:37e1e6a45ced | 46 | /****************************************************************************** |
dkato | 0:37e1e6a45ced | 47 | Typedef definitions |
dkato | 0:37e1e6a45ced | 48 | ******************************************************************************/ |
dkato | 0:37e1e6a45ced | 49 | |
dkato | 0:37e1e6a45ced | 50 | /****************************************************************************** |
dkato | 0:37e1e6a45ced | 51 | Macro definitions |
dkato | 0:37e1e6a45ced | 52 | ******************************************************************************/ |
dkato | 0:37e1e6a45ced | 53 | #define QUANTIZATION_TABLE_SIZE (64u) |
dkato | 0:37e1e6a45ced | 54 | #define HUFFMAN_TABLE_DC_SIZE (28u) |
dkato | 0:37e1e6a45ced | 55 | #define HUFFMAN_TABLE_AC_SIZE (178u) |
dkato | 0:37e1e6a45ced | 56 | #define JPEG_HEADER_LETTER_1 (0xFFu) |
dkato | 0:37e1e6a45ced | 57 | #define JPEG_HEADER_LETTER_2 (0xD8u) |
dkato | 0:37e1e6a45ced | 58 | #define ALPHA_VAL_MAX (0xFF) |
dkato | 0:37e1e6a45ced | 59 | #define LOC_KIND_COLOR_FORMAT (3u) |
dkato | 0:37e1e6a45ced | 60 | |
dkato | 0:37e1e6a45ced | 61 | #define ENC_SIZE_MAX (1024 * 30) |
dkato | 0:37e1e6a45ced | 62 | #define MASK_8BYTE (0xFFFFFFF8) |
dkato | 0:37e1e6a45ced | 63 | |
dkato | 0:37e1e6a45ced | 64 | /*[QuantizationTable_Y]*/ |
dkato | 0:37e1e6a45ced | 65 | /* Quality is IJG75 */ |
dkato | 0:37e1e6a45ced | 66 | static const uint8_t csaDefaultQuantizationTable_Y[QUANTIZATION_TABLE_SIZE] = { |
dkato | 0:37e1e6a45ced | 67 | 8, 6, 5, 8, 12, 20, 26, 31, |
dkato | 0:37e1e6a45ced | 68 | 6, 6, 7, 10, 13, 29, 30, 28, |
dkato | 0:37e1e6a45ced | 69 | 7, 7, 8, 12, 20, 29, 35, 28, |
dkato | 0:37e1e6a45ced | 70 | 7, 9, 11, 15, 26, 44, 40, 31, |
dkato | 0:37e1e6a45ced | 71 | 9, 11, 19, 28, 34, 55, 52, 39, |
dkato | 0:37e1e6a45ced | 72 | 12, 18, 28, 32, 41, 52, 57, 46, |
dkato | 0:37e1e6a45ced | 73 | 25, 32, 39, 44, 52, 61, 60, 51, |
dkato | 0:37e1e6a45ced | 74 | 36, 46, 48, 49, 56, 50, 52, 50 |
dkato | 0:37e1e6a45ced | 75 | }; |
dkato | 0:37e1e6a45ced | 76 | |
dkato | 0:37e1e6a45ced | 77 | /*[QuantizationTable_C]*/ |
dkato | 0:37e1e6a45ced | 78 | /* Quality is IJG75 */ |
dkato | 0:37e1e6a45ced | 79 | static const uint8_t csaDefaultQuantizationTable_C[QUANTIZATION_TABLE_SIZE] = { |
dkato | 0:37e1e6a45ced | 80 | 9, 9, 12, 24, 50, 50, 50, 50, |
dkato | 0:37e1e6a45ced | 81 | 9, 11, 13, 33, 50, 50, 50, 50, |
dkato | 0:37e1e6a45ced | 82 | 12, 13, 28, 50, 50, 50, 50, 50, |
dkato | 0:37e1e6a45ced | 83 | 24, 33, 50, 50, 50, 50, 50, 50, |
dkato | 0:37e1e6a45ced | 84 | 50, 50, 50, 50, 50, 50, 50, 50, |
dkato | 0:37e1e6a45ced | 85 | 50, 50, 50, 50, 50, 50, 50, 50, |
dkato | 0:37e1e6a45ced | 86 | 50, 50, 50, 50, 50, 50, 50, 50, |
dkato | 0:37e1e6a45ced | 87 | 50, 50, 50, 50, 50, 50, 50, 50 |
dkato | 0:37e1e6a45ced | 88 | }; |
dkato | 0:37e1e6a45ced | 89 | |
dkato | 0:37e1e6a45ced | 90 | /*[HuffmanTable_Y_DC]*/ |
dkato | 0:37e1e6a45ced | 91 | /* Example written in ITU-T T81 specification */ |
dkato | 0:37e1e6a45ced | 92 | static const uint8_t csaDefaultHuffmanTable_Y_DC[HUFFMAN_TABLE_DC_SIZE] = { |
dkato | 0:37e1e6a45ced | 93 | 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
dkato | 0:37e1e6a45ced | 94 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B |
dkato | 0:37e1e6a45ced | 95 | }; |
dkato | 0:37e1e6a45ced | 96 | |
dkato | 0:37e1e6a45ced | 97 | /*[HuffmanTable_C_DC]*/ |
dkato | 0:37e1e6a45ced | 98 | /* Example written in ITU-T T81 specification */ |
dkato | 0:37e1e6a45ced | 99 | static const uint8_t csaDefaultHuffmanTable_C_DC[HUFFMAN_TABLE_DC_SIZE] = { |
dkato | 0:37e1e6a45ced | 100 | 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
dkato | 0:37e1e6a45ced | 101 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B |
dkato | 0:37e1e6a45ced | 102 | }; |
dkato | 0:37e1e6a45ced | 103 | |
dkato | 0:37e1e6a45ced | 104 | /*[HuffmanTable_Y_AC]*/ |
dkato | 0:37e1e6a45ced | 105 | /* Example written in ITU-T T81 specification */ |
dkato | 0:37e1e6a45ced | 106 | static const uint8_t csaDefaultHuffmanTable_Y_AC[HUFFMAN_TABLE_AC_SIZE] = { |
dkato | 0:37e1e6a45ced | 107 | 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, |
dkato | 0:37e1e6a45ced | 108 | 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, |
dkato | 0:37e1e6a45ced | 109 | 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, |
dkato | 0:37e1e6a45ced | 110 | 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, |
dkato | 0:37e1e6a45ced | 111 | 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, |
dkato | 0:37e1e6a45ced | 112 | 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, |
dkato | 0:37e1e6a45ced | 113 | 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, |
dkato | 0:37e1e6a45ced | 114 | 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, |
dkato | 0:37e1e6a45ced | 115 | 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, |
dkato | 0:37e1e6a45ced | 116 | 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, |
dkato | 0:37e1e6a45ced | 117 | 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, |
dkato | 0:37e1e6a45ced | 118 | 0xF9, 0xFA |
dkato | 0:37e1e6a45ced | 119 | }; |
dkato | 0:37e1e6a45ced | 120 | |
dkato | 0:37e1e6a45ced | 121 | /*[HuffmanTable_C_AC]*/ |
dkato | 0:37e1e6a45ced | 122 | /* Example written in ITU-T T81 specification */ |
dkato | 0:37e1e6a45ced | 123 | static const uint8_t csaDefaultHuffmanTable_C_AC[HUFFMAN_TABLE_AC_SIZE] = { |
dkato | 0:37e1e6a45ced | 124 | 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, |
dkato | 0:37e1e6a45ced | 125 | 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, |
dkato | 0:37e1e6a45ced | 126 | 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, |
dkato | 0:37e1e6a45ced | 127 | 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, |
dkato | 0:37e1e6a45ced | 128 | 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, |
dkato | 0:37e1e6a45ced | 129 | 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, |
dkato | 0:37e1e6a45ced | 130 | 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
dkato | 0:37e1e6a45ced | 131 | 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, |
dkato | 0:37e1e6a45ced | 132 | 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, |
dkato | 0:37e1e6a45ced | 133 | 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, |
dkato | 0:37e1e6a45ced | 134 | 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, |
dkato | 0:37e1e6a45ced | 135 | 0xF9, 0xFA |
dkato | 0:37e1e6a45ced | 136 | }; |
dkato | 0:37e1e6a45ced | 137 | |
dkato | 1:7b90e31adc5b | 138 | typedef void (JPEG_CallbackFunc_t)(JPEG_Converter::jpeg_conv_error_t err_code); |
dkato | 1:7b90e31adc5b | 139 | |
dkato | 1:7b90e31adc5b | 140 | static uint32_t driver_ac_count = 0; |
dkato | 1:7b90e31adc5b | 141 | static bool jcu_error_flag; |
dkato | 1:7b90e31adc5b | 142 | static JPEG_CallbackFunc_t* pJPEG_ConverterCallback; |
dkato | 1:7b90e31adc5b | 143 | Semaphore jpeg_converter_semaphore(1); |
dkato | 1:7b90e31adc5b | 144 | |
dkato | 1:7b90e31adc5b | 145 | |
dkato | 1:7b90e31adc5b | 146 | /**************************************************************************//** |
dkato | 1:7b90e31adc5b | 147 | * @brief Callback function from JCU async mode |
dkato | 1:7b90e31adc5b | 148 | * @param[in] mbed_jcu_err_t err_code : JCU result |
dkato | 1:7b90e31adc5b | 149 | * @retval None |
dkato | 1:7b90e31adc5b | 150 | ******************************************************************************/ |
dkato | 1:7b90e31adc5b | 151 | void JPEG_CallbackFunction(mbed_jcu_err_t err_code) { |
dkato | 1:7b90e31adc5b | 152 | if (pJPEG_ConverterCallback != NULL) { |
dkato | 1:7b90e31adc5b | 153 | pJPEG_ConverterCallback((JPEG_Converter::jpeg_conv_error_t)err_code); |
dkato | 1:7b90e31adc5b | 154 | } |
dkato | 1:7b90e31adc5b | 155 | if (err_code != MBED_JCU_E_OK) { |
dkato | 1:7b90e31adc5b | 156 | jcu_error_flag = true; |
dkato | 1:7b90e31adc5b | 157 | } |
dkato | 1:7b90e31adc5b | 158 | jpeg_converter_semaphore.release(); // RELEASE |
dkato | 1:7b90e31adc5b | 159 | } /* End of callback function method () */ |
dkato | 0:37e1e6a45ced | 160 | |
dkato | 0:37e1e6a45ced | 161 | /**************************************************************************//** |
dkato | 0:37e1e6a45ced | 162 | * @brief Constructor of the JPEG_Converter class |
dkato | 0:37e1e6a45ced | 163 | * @param[in] None |
dkato | 0:37e1e6a45ced | 164 | * @retval None |
dkato | 0:37e1e6a45ced | 165 | ******************************************************************************/ |
dkato | 1:7b90e31adc5b | 166 | JPEG_Converter::JPEG_Converter(void) { |
dkato | 0:37e1e6a45ced | 167 | jcu_errorcode_t jcu_error; |
dkato | 0:37e1e6a45ced | 168 | |
dkato | 1:7b90e31adc5b | 169 | if (driver_ac_count == 0) { |
dkato | 1:7b90e31adc5b | 170 | jcu_error = R_JCU_Initialize(NULL); |
dkato | 1:7b90e31adc5b | 171 | if (jcu_error == JCU_ERROR_OK) { |
dkato | 1:7b90e31adc5b | 172 | driver_ac_count++; |
dkato | 1:7b90e31adc5b | 173 | jcu_error_flag = false; |
dkato | 1:7b90e31adc5b | 174 | } |
dkato | 1:7b90e31adc5b | 175 | } else { |
dkato | 1:7b90e31adc5b | 176 | driver_ac_count++; |
dkato | 0:37e1e6a45ced | 177 | } |
dkato | 0:37e1e6a45ced | 178 | } /* End of constructor method () */ |
dkato | 0:37e1e6a45ced | 179 | |
dkato | 0:37e1e6a45ced | 180 | /**************************************************************************//** |
dkato | 0:37e1e6a45ced | 181 | * @brief Destructor of the JPEG_Converter class |
dkato | 0:37e1e6a45ced | 182 | * @param[in] None |
dkato | 0:37e1e6a45ced | 183 | * @retval None |
dkato | 0:37e1e6a45ced | 184 | ******************************************************************************/ |
dkato | 1:7b90e31adc5b | 185 | JPEG_Converter::~JPEG_Converter(void) { |
dkato | 1:7b90e31adc5b | 186 | if (driver_ac_count > 0) { |
dkato | 1:7b90e31adc5b | 187 | driver_ac_count--; |
dkato | 1:7b90e31adc5b | 188 | if (driver_ac_count == 0) { |
dkato | 1:7b90e31adc5b | 189 | (void)R_JCU_Terminate(); |
dkato | 1:7b90e31adc5b | 190 | } |
dkato | 0:37e1e6a45ced | 191 | } |
dkato | 0:37e1e6a45ced | 192 | } /* End of destructor method () */ |
dkato | 0:37e1e6a45ced | 193 | |
dkato | 0:37e1e6a45ced | 194 | /**************************************************************************//** |
dkato | 0:37e1e6a45ced | 195 | * @brief JPEG data decode to bitmap |
dkato | 0:37e1e6a45ced | 196 | * @param[in] void* pJpegBuff : Input JPEG data address |
dkato | 0:37e1e6a45ced | 197 | * @param[in/out] bitmap_buff_info_t* psOutputBuff : Output bitmap data address |
dkato | 0:37e1e6a45ced | 198 | * @retval error code |
dkato | 0:37e1e6a45ced | 199 | ******************************************************************************/ |
dkato | 0:37e1e6a45ced | 200 | JPEG_Converter::jpeg_conv_error_t |
dkato | 1:7b90e31adc5b | 201 | JPEG_Converter::decode(void* pJpegBuff, bitmap_buff_info_t* psOutputBuff) { |
dkato | 1:7b90e31adc5b | 202 | decode_options_t Options; |
dkato | 0:37e1e6a45ced | 203 | |
dkato | 1:7b90e31adc5b | 204 | return (decode(pJpegBuff, psOutputBuff, &Options)); |
dkato | 0:37e1e6a45ced | 205 | } /* End of method decode() */ |
dkato | 0:37e1e6a45ced | 206 | |
dkato | 0:37e1e6a45ced | 207 | /**************************************************************************//** |
dkato | 0:37e1e6a45ced | 208 | * @brief JPEG data decode to bitmap |
dkato | 0:37e1e6a45ced | 209 | * @param[in] void* pJpegBuff : Input JPEG data address |
dkato | 0:37e1e6a45ced | 210 | * @param[in/out] bitmap_buff_info_t* psOutputBuff : Output bitmap data address |
dkato | 0:37e1e6a45ced | 211 | * @param[in] decode_options_t* pOptions : Decode option(Optional) |
dkato | 0:37e1e6a45ced | 212 | * @retval error code |
dkato | 0:37e1e6a45ced | 213 | ******************************************************************************/ |
dkato | 0:37e1e6a45ced | 214 | JPEG_Converter::jpeg_conv_error_t |
dkato | 1:7b90e31adc5b | 215 | JPEG_Converter::decode(void* pJpegBuff, bitmap_buff_info_t* psOutputBuff, decode_options_t* pOptions) { |
dkato | 0:37e1e6a45ced | 216 | jpeg_conv_error_t e; |
dkato | 0:37e1e6a45ced | 217 | jcu_errorcode_t jcu_error; |
dkato | 0:37e1e6a45ced | 218 | jcu_decode_param_t decode; |
dkato | 0:37e1e6a45ced | 219 | jcu_buffer_param_t buffer; |
dkato | 1:7b90e31adc5b | 220 | uint8_t* pBuff = (uint8_t *)pJpegBuff; |
dkato | 0:37e1e6a45ced | 221 | const jcu_async_status_t* status; |
dkato | 0:37e1e6a45ced | 222 | jcu_image_info_t image_info; |
dkato | 1:7b90e31adc5b | 223 | bool mutex_release = false; |
dkato | 0:37e1e6a45ced | 224 | |
dkato | 0:37e1e6a45ced | 225 | // Check JCU initialized |
dkato | 1:7b90e31adc5b | 226 | if (driver_ac_count > 0) { |
dkato | 1:7b90e31adc5b | 227 | size_t calc_height; |
dkato | 1:7b90e31adc5b | 228 | size_t calc_width; |
dkato | 0:37e1e6a45ced | 229 | |
dkato | 0:37e1e6a45ced | 230 | calc_height = psOutputBuff->height * (2 ^ pOptions->vertical_sub_sampling); |
dkato | 0:37e1e6a45ced | 231 | calc_width = psOutputBuff->width * (2 ^ pOptions->horizontal_sub_sampling); |
dkato | 0:37e1e6a45ced | 232 | |
dkato | 0:37e1e6a45ced | 233 | // Check input address |
dkato | 0:37e1e6a45ced | 234 | if ((pJpegBuff == NULL) || (psOutputBuff == NULL) || (pOptions == NULL)) { |
dkato | 0:37e1e6a45ced | 235 | e = JPEG_CONV_PARAM_ERR; // Input address error |
dkato | 0:37e1e6a45ced | 236 | goto fin; |
dkato | 0:37e1e6a45ced | 237 | } |
dkato | 0:37e1e6a45ced | 238 | // Check JPEG header |
dkato | 1:7b90e31adc5b | 239 | if (((uint32_t)(pBuff[0]) != JPEG_HEADER_LETTER_1) || |
dkato | 1:7b90e31adc5b | 240 | ((uint32_t)(pBuff[1]) != JPEG_HEADER_LETTER_2)) { |
dkato | 0:37e1e6a45ced | 241 | e = JPEG_CONV_FORMA_ERR; // JPEG data is not in ROM |
dkato | 0:37e1e6a45ced | 242 | goto fin; |
dkato | 0:37e1e6a45ced | 243 | } |
dkato | 1:7b90e31adc5b | 244 | // JCU Error reset |
dkato | 1:7b90e31adc5b | 245 | if (jcu_error_flag == true) { |
dkato | 1:7b90e31adc5b | 246 | (void)R_JCU_Terminate(); |
dkato | 1:7b90e31adc5b | 247 | (void)R_JCU_Initialize(NULL); |
dkato | 1:7b90e31adc5b | 248 | jcu_error_flag = false; |
dkato | 1:7b90e31adc5b | 249 | } |
dkato | 1:7b90e31adc5b | 250 | // Get mutex |
dkato | 1:7b90e31adc5b | 251 | if (pOptions->p_DecodeCallBackFunc == NULL) { |
dkato | 1:7b90e31adc5b | 252 | jpeg_converter_semaphore.wait(0xFFFFFFFFuL); // WAIT |
dkato | 1:7b90e31adc5b | 253 | } else { |
dkato | 1:7b90e31adc5b | 254 | if (!jpeg_converter_semaphore.wait(0)) { |
dkato | 1:7b90e31adc5b | 255 | e = JPEG_CONV_BUSY; // Busy |
dkato | 1:7b90e31adc5b | 256 | goto fin; |
dkato | 1:7b90e31adc5b | 257 | } |
dkato | 1:7b90e31adc5b | 258 | } |
dkato | 1:7b90e31adc5b | 259 | // Select decode |
dkato | 0:37e1e6a45ced | 260 | jcu_error = R_JCU_SelectCodec( JCU_DECODE ); |
dkato | 1:7b90e31adc5b | 261 | if (jcu_error != JCU_ERROR_OK) { |
dkato | 1:7b90e31adc5b | 262 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 263 | mutex_release = true; |
dkato | 0:37e1e6a45ced | 264 | goto fin; |
dkato | 0:37e1e6a45ced | 265 | } |
dkato | 0:37e1e6a45ced | 266 | |
dkato | 0:37e1e6a45ced | 267 | buffer.source.swapSetting = JCU_SWAP_LONG_WORD_AND_WORD_AND_BYTE; |
dkato | 0:37e1e6a45ced | 268 | buffer.source.address = (uint32_t *)pBuff; |
dkato | 0:37e1e6a45ced | 269 | buffer.lineOffset = (int16_t)psOutputBuff->width; |
dkato | 0:37e1e6a45ced | 270 | buffer.destination.address = (uint32_t *)psOutputBuff->buffer_address; |
dkato | 0:37e1e6a45ced | 271 | decode.decodeFormat = (jcu_decode_format_t)psOutputBuff->format; |
dkato | 0:37e1e6a45ced | 272 | buffer.destination.swapSetting = (jcu_swap_t)pOptions->output_swapsetting; |
dkato | 0:37e1e6a45ced | 273 | decode.outputCbCrOffset = (jcu_cbcr_offset_t)pOptions->output_cb_cr_offset; |
dkato | 0:37e1e6a45ced | 274 | decode.alpha = pOptions->alpha; |
dkato | 0:37e1e6a45ced | 275 | decode.horizontalSubSampling = (jcu_sub_sampling_t)pOptions->horizontal_sub_sampling; |
dkato | 0:37e1e6a45ced | 276 | decode.verticalSubSampling = (jcu_sub_sampling_t)pOptions->vertical_sub_sampling; |
dkato | 1:7b90e31adc5b | 277 | |
dkato | 1:7b90e31adc5b | 278 | jcu_error = R_JCU_SetDecodeParam(&decode, &buffer); |
dkato | 1:7b90e31adc5b | 279 | if (jcu_error != JCU_ERROR_OK) { |
dkato | 0:37e1e6a45ced | 280 | e = JPEG_CONV_FORMA_ERR; |
dkato | 1:7b90e31adc5b | 281 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 282 | jcu_error_flag = false; |
dkato | 0:37e1e6a45ced | 283 | goto fin; |
dkato | 0:37e1e6a45ced | 284 | } |
dkato | 0:37e1e6a45ced | 285 | |
dkato | 0:37e1e6a45ced | 286 | if (pOptions->check_jpeg_format != false) { |
dkato | 1:7b90e31adc5b | 287 | jcu_error = R_JCU_SetPauseForImageInfo(true); |
dkato | 1:7b90e31adc5b | 288 | if (jcu_error != JCU_ERROR_OK) { |
dkato | 0:37e1e6a45ced | 289 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 290 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 291 | jcu_error_flag = false; |
dkato | 0:37e1e6a45ced | 292 | goto fin; |
dkato | 0:37e1e6a45ced | 293 | } |
dkato | 0:37e1e6a45ced | 294 | } |
dkato | 1:7b90e31adc5b | 295 | if (pOptions->p_DecodeCallBackFunc == NULL) { |
dkato | 0:37e1e6a45ced | 296 | jcu_error = R_JCU_Start(); |
dkato | 1:7b90e31adc5b | 297 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 298 | if (jcu_error != JCU_ERROR_OK) { |
dkato | 0:37e1e6a45ced | 299 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 300 | jcu_error_flag = false; |
dkato | 0:37e1e6a45ced | 301 | goto fin; |
dkato | 0:37e1e6a45ced | 302 | } |
dkato | 1:7b90e31adc5b | 303 | if (pOptions->check_jpeg_format != false) { |
dkato | 1:7b90e31adc5b | 304 | R_JCU_GetAsyncStatus( &status ); |
dkato | 1:7b90e31adc5b | 305 | if (status -> IsPaused == false) { |
dkato | 1:7b90e31adc5b | 306 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 307 | jcu_error_flag = false; |
dkato | 1:7b90e31adc5b | 308 | goto fin; |
dkato | 1:7b90e31adc5b | 309 | } |
dkato | 1:7b90e31adc5b | 310 | if ((status->SubStatusFlags & JCU_SUB_INFOMATION_READY) == 0) { |
dkato | 1:7b90e31adc5b | 311 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 312 | jcu_error_flag = false; |
dkato | 1:7b90e31adc5b | 313 | goto fin; |
dkato | 1:7b90e31adc5b | 314 | } |
dkato | 1:7b90e31adc5b | 315 | jcu_error = R_JCU_GetImageInfo( &image_info ); |
dkato | 1:7b90e31adc5b | 316 | if (jcu_error != JCU_ERROR_OK) { |
dkato | 1:7b90e31adc5b | 317 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 318 | jcu_error_flag = false; |
dkato | 1:7b90e31adc5b | 319 | goto fin; |
dkato | 1:7b90e31adc5b | 320 | } |
dkato | 1:7b90e31adc5b | 321 | if ((image_info.width == 0u) || (image_info.height == 0u) || |
dkato | 1:7b90e31adc5b | 322 | (image_info.width > calc_width) || |
dkato | 1:7b90e31adc5b | 323 | (image_info.height > calc_height)) { |
dkato | 1:7b90e31adc5b | 324 | e = JPEG_CONV_FORMA_ERR; |
dkato | 1:7b90e31adc5b | 325 | jcu_error_flag = false; |
dkato | 1:7b90e31adc5b | 326 | goto fin; |
dkato | 1:7b90e31adc5b | 327 | } |
dkato | 1:7b90e31adc5b | 328 | if ((image_info.encodedFormat != JCU_JPEG_YCbCr444) && |
dkato | 1:7b90e31adc5b | 329 | (image_info.encodedFormat != JCU_JPEG_YCbCr422) && |
dkato | 1:7b90e31adc5b | 330 | (image_info.encodedFormat != JCU_JPEG_YCbCr420) && |
dkato | 1:7b90e31adc5b | 331 | (image_info.encodedFormat != JCU_JPEG_YCbCr411)) { |
dkato | 1:7b90e31adc5b | 332 | e = JPEG_CONV_FORMA_ERR; |
dkato | 1:7b90e31adc5b | 333 | jcu_error_flag = false; |
dkato | 1:7b90e31adc5b | 334 | goto fin; |
dkato | 1:7b90e31adc5b | 335 | } |
dkato | 1:7b90e31adc5b | 336 | jcu_error = R_JCU_Continue(JCU_IMAGE_INFO); |
dkato | 1:7b90e31adc5b | 337 | if (jcu_error != JCU_ERROR_OK) { |
dkato | 1:7b90e31adc5b | 338 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 339 | jcu_error_flag = false; |
dkato | 1:7b90e31adc5b | 340 | goto fin; |
dkato | 1:7b90e31adc5b | 341 | } |
dkato | 0:37e1e6a45ced | 342 | } |
dkato | 0:37e1e6a45ced | 343 | } else { |
dkato | 1:7b90e31adc5b | 344 | pJPEG_ConverterCallback = pOptions->p_DecodeCallBackFunc; |
dkato | 1:7b90e31adc5b | 345 | jcu_error = R_wrpper_set_decode_callback((mbed_CallbackFunc_t*)JPEG_CallbackFunction, (size_t)calc_width, calc_height); |
dkato | 1:7b90e31adc5b | 346 | if (jcu_error != JCU_ERROR_OK) { |
dkato | 1:7b90e31adc5b | 347 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 348 | mutex_release = true; |
dkato | 0:37e1e6a45ced | 349 | goto fin; |
dkato | 0:37e1e6a45ced | 350 | } |
dkato | 0:37e1e6a45ced | 351 | } |
dkato | 0:37e1e6a45ced | 352 | e = JPEG_CONV_OK; |
dkato | 0:37e1e6a45ced | 353 | } |
dkato | 0:37e1e6a45ced | 354 | else |
dkato | 0:37e1e6a45ced | 355 | { |
dkato | 0:37e1e6a45ced | 356 | e = JPEG_CONV_JCU_ERR; |
dkato | 0:37e1e6a45ced | 357 | } |
dkato | 0:37e1e6a45ced | 358 | fin: |
dkato | 1:7b90e31adc5b | 359 | if (mutex_release == true) { |
dkato | 1:7b90e31adc5b | 360 | jpeg_converter_semaphore.release(); // RELEASE |
dkato | 1:7b90e31adc5b | 361 | } |
dkato | 1:7b90e31adc5b | 362 | |
dkato | 0:37e1e6a45ced | 363 | return e; |
dkato | 0:37e1e6a45ced | 364 | } /* End of method decode() */ |
dkato | 0:37e1e6a45ced | 365 | |
dkato | 0:37e1e6a45ced | 366 | |
dkato | 0:37e1e6a45ced | 367 | /**************************************************************************//** |
dkato | 0:37e1e6a45ced | 368 | * @brief Bitmap data encode to JPEG |
dkato | 0:37e1e6a45ced | 369 | * @param[in] bitmap_buff_info_t* psInputBuff : Input bitmap data address |
dkato | 0:37e1e6a45ced | 370 | * @param[out] void* pJpegBuff : Output JPEG data address |
dkato | 0:37e1e6a45ced | 371 | * @param[out] size_t* pEncodeSize : Encode size address |
dkato | 0:37e1e6a45ced | 372 | * @retval error code |
dkato | 0:37e1e6a45ced | 373 | ******************************************************************************/ |
dkato | 0:37e1e6a45ced | 374 | JPEG_Converter::jpeg_conv_error_t |
dkato | 0:37e1e6a45ced | 375 | JPEG_Converter::encode(bitmap_buff_info_t* psInputBuff, void* pJpegBuff, size_t* pEncodeSize ) { |
dkato | 1:7b90e31adc5b | 376 | encode_options_t Options; |
dkato | 1:7b90e31adc5b | 377 | |
dkato | 1:7b90e31adc5b | 378 | return (encode(psInputBuff, pJpegBuff, pEncodeSize, &Options)); |
dkato | 0:37e1e6a45ced | 379 | } /* End of method encode() */ |
dkato | 0:37e1e6a45ced | 380 | |
dkato | 0:37e1e6a45ced | 381 | |
dkato | 0:37e1e6a45ced | 382 | /**************************************************************************//** |
dkato | 0:37e1e6a45ced | 383 | * @brief Bitmap data encode to JPEG |
dkato | 0:37e1e6a45ced | 384 | * @param[in] bitmap_buff_info_t* psInputBuff : Input bitmap data address |
dkato | 0:37e1e6a45ced | 385 | * @param[out] void* pJpegBuff : Output JPEG data address |
dkato | 0:37e1e6a45ced | 386 | * @param[out] size_t* pEncodeSize : Encode size address |
dkato | 1:7b90e31adc5b | 387 | * @param[in] encode_options_t* pOptions : Encode option(Optional) |
dkato | 0:37e1e6a45ced | 388 | * @retval error code |
dkato | 0:37e1e6a45ced | 389 | ******************************************************************************/ |
dkato | 0:37e1e6a45ced | 390 | JPEG_Converter::jpeg_conv_error_t |
dkato | 0:37e1e6a45ced | 391 | JPEG_Converter::encode(bitmap_buff_info_t* psInputBuff, void* pJpegBuff, size_t* pEncodeSize, encode_options_t* pOptions ) { |
dkato | 0:37e1e6a45ced | 392 | |
dkato | 0:37e1e6a45ced | 393 | jpeg_conv_error_t e; |
dkato | 0:37e1e6a45ced | 394 | jcu_errorcode_t jcu_error; |
dkato | 0:37e1e6a45ced | 395 | jcu_buffer_param_t buffer; |
dkato | 0:37e1e6a45ced | 396 | uint8_t* TableAddress; |
dkato | 0:37e1e6a45ced | 397 | jcu_encode_param_t encode; |
dkato | 1:7b90e31adc5b | 398 | jcu_count_mode_param_t count_para; |
dkato | 1:7b90e31adc5b | 399 | int32_t encode_count; |
dkato | 1:7b90e31adc5b | 400 | int32_t size_max_count = 1; |
dkato | 1:7b90e31adc5b | 401 | size_t BufferSize = pOptions->encode_buff_size; |
dkato | 1:7b90e31adc5b | 402 | const jcu_async_status_t* status; |
dkato | 1:7b90e31adc5b | 403 | bool mutex_release = false; |
dkato | 0:37e1e6a45ced | 404 | |
dkato | 0:37e1e6a45ced | 405 | // Check JCU initialized |
dkato | 1:7b90e31adc5b | 406 | if (driver_ac_count > 0) { |
dkato | 0:37e1e6a45ced | 407 | // Check input address |
dkato | 0:37e1e6a45ced | 408 | if ((pJpegBuff == NULL) || (psInputBuff == NULL) || (pEncodeSize == NULL)) { |
dkato | 0:37e1e6a45ced | 409 | e = JPEG_CONV_PARAM_ERR; // Input address error |
dkato | 0:37e1e6a45ced | 410 | goto fin; |
dkato | 0:37e1e6a45ced | 411 | } |
dkato | 1:7b90e31adc5b | 412 | // JCU Error reset |
dkato | 1:7b90e31adc5b | 413 | if (jcu_error_flag == true) { |
dkato | 1:7b90e31adc5b | 414 | (void)R_JCU_Terminate(); |
dkato | 1:7b90e31adc5b | 415 | (void)R_JCU_Initialize(NULL); |
dkato | 1:7b90e31adc5b | 416 | jcu_error_flag = false; |
dkato | 1:7b90e31adc5b | 417 | } |
dkato | 1:7b90e31adc5b | 418 | // Get mutex |
dkato | 1:7b90e31adc5b | 419 | if ( pOptions->p_EncodeCallBackFunc == NULL ) { |
dkato | 1:7b90e31adc5b | 420 | jpeg_converter_semaphore.wait(0xFFFFFFFFuL); // WAIT |
dkato | 1:7b90e31adc5b | 421 | } else { |
dkato | 1:7b90e31adc5b | 422 | if (!jpeg_converter_semaphore.wait(0)) { |
dkato | 1:7b90e31adc5b | 423 | e = JPEG_CONV_BUSY; // Busy |
dkato | 1:7b90e31adc5b | 424 | goto fin; |
dkato | 1:7b90e31adc5b | 425 | } |
dkato | 1:7b90e31adc5b | 426 | } |
dkato | 1:7b90e31adc5b | 427 | // Select encode |
dkato | 1:7b90e31adc5b | 428 | jcu_error = R_JCU_SelectCodec(JCU_ENCODE); |
dkato | 1:7b90e31adc5b | 429 | if (jcu_error != JCU_ERROR_OK) { |
dkato | 0:37e1e6a45ced | 430 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 431 | mutex_release = true; |
dkato | 0:37e1e6a45ced | 432 | goto fin; |
dkato | 0:37e1e6a45ced | 433 | } |
dkato | 0:37e1e6a45ced | 434 | /* Set tables */ |
dkato | 0:37e1e6a45ced | 435 | if ( pOptions->quantization_table_Y != NULL ) { |
dkato | 0:37e1e6a45ced | 436 | TableAddress = (uint8_t*)pOptions->quantization_table_Y; |
dkato | 0:37e1e6a45ced | 437 | } else { |
dkato | 0:37e1e6a45ced | 438 | TableAddress = (uint8_t*)csaDefaultQuantizationTable_Y; |
dkato | 0:37e1e6a45ced | 439 | } |
dkato | 0:37e1e6a45ced | 440 | jcu_error = R_JCU_SetQuantizationTable( JCU_TABLE_NO_0, (uint8_t*)TableAddress ); |
dkato | 0:37e1e6a45ced | 441 | if ( jcu_error != JCU_ERROR_OK ) { |
dkato | 0:37e1e6a45ced | 442 | e = JPEG_CONV_PARAM_RANGE_ERR; |
dkato | 1:7b90e31adc5b | 443 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 444 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 445 | goto fin; |
dkato | 0:37e1e6a45ced | 446 | } |
dkato | 0:37e1e6a45ced | 447 | if ( pOptions->quantization_table_C != NULL ) { |
dkato | 0:37e1e6a45ced | 448 | TableAddress = (uint8_t*)pOptions->quantization_table_C; |
dkato | 0:37e1e6a45ced | 449 | } else { |
dkato | 0:37e1e6a45ced | 450 | TableAddress = (uint8_t*)csaDefaultQuantizationTable_C; |
dkato | 0:37e1e6a45ced | 451 | } |
dkato | 0:37e1e6a45ced | 452 | jcu_error = R_JCU_SetQuantizationTable( JCU_TABLE_NO_1, (uint8_t*)TableAddress ); |
dkato | 0:37e1e6a45ced | 453 | if ( jcu_error != JCU_ERROR_OK ) { |
dkato | 0:37e1e6a45ced | 454 | e = JPEG_CONV_PARAM_RANGE_ERR; |
dkato | 1:7b90e31adc5b | 455 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 456 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 457 | goto fin; |
dkato | 0:37e1e6a45ced | 458 | } |
dkato | 0:37e1e6a45ced | 459 | if ( pOptions->huffman_table_Y_DC != NULL ) { |
dkato | 0:37e1e6a45ced | 460 | TableAddress = (uint8_t*)pOptions->huffman_table_Y_DC; |
dkato | 0:37e1e6a45ced | 461 | } else { |
dkato | 0:37e1e6a45ced | 462 | TableAddress = (uint8_t*)csaDefaultHuffmanTable_Y_DC; |
dkato | 0:37e1e6a45ced | 463 | } |
dkato | 0:37e1e6a45ced | 464 | jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_0, JCU_HUFFMAN_DC, (uint8_t*)TableAddress ); |
dkato | 0:37e1e6a45ced | 465 | if ( jcu_error != JCU_ERROR_OK ) { |
dkato | 0:37e1e6a45ced | 466 | e = JPEG_CONV_PARAM_RANGE_ERR; |
dkato | 1:7b90e31adc5b | 467 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 468 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 469 | goto fin; |
dkato | 0:37e1e6a45ced | 470 | } |
dkato | 0:37e1e6a45ced | 471 | if ( pOptions->huffman_table_C_DC != NULL ) { |
dkato | 0:37e1e6a45ced | 472 | TableAddress = (uint8_t*)pOptions->huffman_table_C_DC; |
dkato | 0:37e1e6a45ced | 473 | } else { |
dkato | 0:37e1e6a45ced | 474 | TableAddress = (uint8_t*)csaDefaultHuffmanTable_C_DC; |
dkato | 0:37e1e6a45ced | 475 | } |
dkato | 0:37e1e6a45ced | 476 | jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_1, JCU_HUFFMAN_DC, (uint8_t*)TableAddress ); |
dkato | 0:37e1e6a45ced | 477 | if ( jcu_error != JCU_ERROR_OK ) { |
dkato | 0:37e1e6a45ced | 478 | e = JPEG_CONV_PARAM_RANGE_ERR; |
dkato | 1:7b90e31adc5b | 479 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 480 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 481 | goto fin; |
dkato | 0:37e1e6a45ced | 482 | } |
dkato | 0:37e1e6a45ced | 483 | if ( pOptions->huffman_table_Y_AC != NULL ) { |
dkato | 0:37e1e6a45ced | 484 | TableAddress = (uint8_t*)pOptions->huffman_table_Y_AC; |
dkato | 0:37e1e6a45ced | 485 | } else { |
dkato | 0:37e1e6a45ced | 486 | TableAddress = (uint8_t*)csaDefaultHuffmanTable_Y_AC; |
dkato | 0:37e1e6a45ced | 487 | } |
dkato | 0:37e1e6a45ced | 488 | jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_0, JCU_HUFFMAN_AC, (uint8_t*)TableAddress ); |
dkato | 0:37e1e6a45ced | 489 | if ( jcu_error != JCU_ERROR_OK ) { |
dkato | 0:37e1e6a45ced | 490 | e = JPEG_CONV_PARAM_RANGE_ERR; |
dkato | 1:7b90e31adc5b | 491 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 492 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 493 | goto fin; |
dkato | 0:37e1e6a45ced | 494 | } |
dkato | 0:37e1e6a45ced | 495 | if ( pOptions->huffman_table_C_AC != NULL ) { |
dkato | 0:37e1e6a45ced | 496 | TableAddress = (uint8_t*)pOptions->huffman_table_C_AC; |
dkato | 0:37e1e6a45ced | 497 | } else { |
dkato | 0:37e1e6a45ced | 498 | TableAddress = (uint8_t*)csaDefaultHuffmanTable_C_AC; |
dkato | 0:37e1e6a45ced | 499 | } |
dkato | 0:37e1e6a45ced | 500 | jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_1, JCU_HUFFMAN_AC, (uint8_t*)TableAddress ); |
dkato | 0:37e1e6a45ced | 501 | if ( jcu_error != JCU_ERROR_OK ) { |
dkato | 0:37e1e6a45ced | 502 | e = JPEG_CONV_PARAM_RANGE_ERR; |
dkato | 1:7b90e31adc5b | 503 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 504 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 505 | goto fin; |
dkato | 0:37e1e6a45ced | 506 | } |
dkato | 0:37e1e6a45ced | 507 | |
dkato | 0:37e1e6a45ced | 508 | // JPEG encode |
dkato | 0:37e1e6a45ced | 509 | buffer.source.swapSetting = (jcu_swap_t)pOptions->input_swapsetting; |
dkato | 0:37e1e6a45ced | 510 | buffer.source.address = (uint32_t *)psInputBuff->buffer_address; |
dkato | 0:37e1e6a45ced | 511 | buffer.destination.swapSetting = JCU_SWAP_LONG_WORD_AND_WORD_AND_BYTE; |
dkato | 0:37e1e6a45ced | 512 | buffer.destination.address = (uint32_t *)pJpegBuff; |
dkato | 0:37e1e6a45ced | 513 | buffer.lineOffset = psInputBuff->width; |
dkato | 0:37e1e6a45ced | 514 | encode.encodeFormat = (jcu_jpeg_format_t)JCU_JPEG_YCbCr422; |
dkato | 0:37e1e6a45ced | 515 | encode.QuantizationTable[ JCU_ELEMENT_Y ] = JCU_TABLE_NO_0; |
dkato | 0:37e1e6a45ced | 516 | encode.QuantizationTable[ JCU_ELEMENT_Cb ] = JCU_TABLE_NO_1; |
dkato | 0:37e1e6a45ced | 517 | encode.QuantizationTable[ JCU_ELEMENT_Cr ] = JCU_TABLE_NO_1; |
dkato | 0:37e1e6a45ced | 518 | encode.HuffmanTable[ JCU_ELEMENT_Y ] = JCU_TABLE_NO_0; |
dkato | 0:37e1e6a45ced | 519 | encode.HuffmanTable[ JCU_ELEMENT_Cb ] = JCU_TABLE_NO_1; |
dkato | 0:37e1e6a45ced | 520 | encode.HuffmanTable[ JCU_ELEMENT_Cr ] = JCU_TABLE_NO_1; |
dkato | 0:37e1e6a45ced | 521 | encode.DRI_value = pOptions->DRI_value; |
dkato | 0:37e1e6a45ced | 522 | if ( pOptions->width != 0 ) { |
dkato | 0:37e1e6a45ced | 523 | encode.width = pOptions->width; |
dkato | 0:37e1e6a45ced | 524 | } else { |
dkato | 0:37e1e6a45ced | 525 | encode.width = psInputBuff->width; |
dkato | 0:37e1e6a45ced | 526 | } |
dkato | 0:37e1e6a45ced | 527 | if ( pOptions->height != 0 ) { |
dkato | 0:37e1e6a45ced | 528 | encode.height = pOptions->height; |
dkato | 0:37e1e6a45ced | 529 | } else { |
dkato | 0:37e1e6a45ced | 530 | encode.height = psInputBuff->height; |
dkato | 0:37e1e6a45ced | 531 | } |
dkato | 0:37e1e6a45ced | 532 | encode.inputCbCrOffset = (jcu_cbcr_offset_t)pOptions->input_cb_cr_offset; |
dkato | 0:37e1e6a45ced | 533 | jcu_error = R_JCU_SetEncodeParam( &encode, &buffer ); |
dkato | 0:37e1e6a45ced | 534 | if ( jcu_error != JCU_ERROR_OK ) { |
dkato | 0:37e1e6a45ced | 535 | e = JPEG_CONV_PARAM_RANGE_ERR; |
dkato | 1:7b90e31adc5b | 536 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 537 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 538 | goto fin; |
dkato | 0:37e1e6a45ced | 539 | } |
dkato | 1:7b90e31adc5b | 540 | if (pOptions->encode_buff_size > 0) { |
dkato | 0:37e1e6a45ced | 541 | |
dkato | 1:7b90e31adc5b | 542 | while(BufferSize > ENC_SIZE_MAX) { |
dkato | 1:7b90e31adc5b | 543 | size_max_count *= 2; |
dkato | 1:7b90e31adc5b | 544 | BufferSize /= 2; |
dkato | 1:7b90e31adc5b | 545 | } |
dkato | 1:7b90e31adc5b | 546 | BufferSize = BufferSize & MASK_8BYTE; |
dkato | 1:7b90e31adc5b | 547 | |
dkato | 1:7b90e31adc5b | 548 | count_para.inputBuffer.isEnable = false; |
dkato | 1:7b90e31adc5b | 549 | count_para.inputBuffer.isInitAddress = false; |
dkato | 1:7b90e31adc5b | 550 | count_para.inputBuffer.restartAddress = NULL; |
dkato | 1:7b90e31adc5b | 551 | count_para.inputBuffer.dataCount = 0; |
dkato | 1:7b90e31adc5b | 552 | count_para.outputBuffer.isEnable = true; |
dkato | 1:7b90e31adc5b | 553 | count_para.outputBuffer.isInitAddress = false; |
dkato | 1:7b90e31adc5b | 554 | count_para.outputBuffer.restartAddress = NULL; |
dkato | 1:7b90e31adc5b | 555 | count_para.outputBuffer.dataCount = BufferSize; |
dkato | 1:7b90e31adc5b | 556 | |
dkato | 1:7b90e31adc5b | 557 | R_JCU_SetCountMode(&count_para); |
dkato | 1:7b90e31adc5b | 558 | } else { |
dkato | 1:7b90e31adc5b | 559 | size_max_count = 0; |
dkato | 1:7b90e31adc5b | 560 | } |
dkato | 1:7b90e31adc5b | 561 | // Check async |
dkato | 1:7b90e31adc5b | 562 | if ( pOptions->p_EncodeCallBackFunc == NULL ) { |
dkato | 1:7b90e31adc5b | 563 | jcu_error = R_JCU_Start(); |
dkato | 1:7b90e31adc5b | 564 | mutex_release = true; |
dkato | 1:7b90e31adc5b | 565 | if ( jcu_error != JCU_ERROR_OK ) { |
dkato | 1:7b90e31adc5b | 566 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 567 | jcu_error_flag = true; |
dkato | 1:7b90e31adc5b | 568 | goto fin; |
dkato | 1:7b90e31adc5b | 569 | } |
dkato | 1:7b90e31adc5b | 570 | if (pOptions->encode_buff_size > 0) { |
dkato | 0:37e1e6a45ced | 571 | // Check Pause flag |
dkato | 0:37e1e6a45ced | 572 | R_JCU_GetAsyncStatus( &status ); |
dkato | 0:37e1e6a45ced | 573 | for ( encode_count = 1; (encode_count < size_max_count) && (status->IsPaused != false); encode_count++) { |
dkato | 1:7b90e31adc5b | 574 | if ((status->SubStatusFlags & JCU_SUB_ENCODE_OUTPUT_PAUSE) == 0) { |
dkato | 0:37e1e6a45ced | 575 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 576 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 577 | goto fin; |
dkato | 0:37e1e6a45ced | 578 | } |
dkato | 0:37e1e6a45ced | 579 | jcu_error = R_JCU_Continue( JCU_OUTPUT_BUFFER ); |
dkato | 0:37e1e6a45ced | 580 | if (jcu_error != JCU_ERROR_OK) { |
dkato | 0:37e1e6a45ced | 581 | e = JPEG_CONV_JCU_ERR; |
dkato | 1:7b90e31adc5b | 582 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 583 | goto fin; |
dkato | 0:37e1e6a45ced | 584 | } |
dkato | 0:37e1e6a45ced | 585 | R_JCU_GetAsyncStatus( &status ); |
dkato | 0:37e1e6a45ced | 586 | } |
dkato | 0:37e1e6a45ced | 587 | if (status->IsPaused != false) { |
dkato | 0:37e1e6a45ced | 588 | e = JPEG_CONV_PARAM_RANGE_ERR; |
dkato | 1:7b90e31adc5b | 589 | jcu_error_flag = true; |
dkato | 0:37e1e6a45ced | 590 | goto fin; |
dkato | 0:37e1e6a45ced | 591 | } |
dkato | 0:37e1e6a45ced | 592 | } |
dkato | 1:7b90e31adc5b | 593 | (void)R_JCU_GetEncodedSize(pEncodeSize); |
dkato | 1:7b90e31adc5b | 594 | } else { |
dkato | 1:7b90e31adc5b | 595 | pJPEG_ConverterCallback = pOptions->p_EncodeCallBackFunc; |
dkato | 1:7b90e31adc5b | 596 | jcu_error = R_wrpper_set_encode_callback((mbed_CallbackFunc_t*)JPEG_CallbackFunction, pEncodeSize, size_max_count); |
dkato | 0:37e1e6a45ced | 597 | if ( jcu_error != JCU_ERROR_OK ) { |
dkato | 0:37e1e6a45ced | 598 | e = JPEG_CONV_JCU_ERR; |
dkato | 0:37e1e6a45ced | 599 | goto fin; |
dkato | 0:37e1e6a45ced | 600 | } |
dkato | 0:37e1e6a45ced | 601 | } |
dkato | 0:37e1e6a45ced | 602 | e = JPEG_CONV_OK; |
dkato | 1:7b90e31adc5b | 603 | } else { |
dkato | 0:37e1e6a45ced | 604 | e = JPEG_CONV_PARAM_RANGE_ERR; |
dkato | 0:37e1e6a45ced | 605 | } |
dkato | 0:37e1e6a45ced | 606 | fin: |
dkato | 1:7b90e31adc5b | 607 | if (mutex_release == true) { |
dkato | 1:7b90e31adc5b | 608 | jpeg_converter_semaphore.release(); // RELEASE |
dkato | 1:7b90e31adc5b | 609 | } |
dkato | 0:37e1e6a45ced | 610 | |
dkato | 0:37e1e6a45ced | 611 | return e; |
dkato | 0:37e1e6a45ced | 612 | } /* End of method encode() */ |
dkato | 0:37e1e6a45ced | 613 |