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.

JPEGCorrespondence
Width>0(greater than 0)
Height>0(greater than 0)
Color formatYCbCr444, YCbCr422, YCbCr420, YCbCr411
BitmapCorrespondence
Width>0(greater than 0)
Height>0(greater than 0)
Color formatYCbCr422

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

Committer:
dkato
Date:
Thu Oct 27 02:03:38 2016 +0000
Revision:
7:df2bc72f7fb7
Parent:
1:7b90e31adc5b
Child:
13:1ee2176ef13f
Supports mbed os 5.

Who changed what in which revision?

UserRevisionLine numberNew 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 7:df2bc72f7fb7 37 #include "rtos.h"
dkato 0:37e1e6a45ced 38 #include "r_typedefs.h"
dkato 0:37e1e6a45ced 39 #include "r_jcu_api.h"
dkato 0:37e1e6a45ced 40 #include "JPEG_Converter.h"
dkato 0:37e1e6a45ced 41 #include "converter_wrapper.h"
dkato 0:37e1e6a45ced 42
dkato 0:37e1e6a45ced 43 /******************************************************************************
dkato 0:37e1e6a45ced 44 Typedef definitions
dkato 0:37e1e6a45ced 45 ******************************************************************************/
dkato 0:37e1e6a45ced 46
dkato 0:37e1e6a45ced 47 /******************************************************************************
dkato 0:37e1e6a45ced 48 Macro definitions
dkato 0:37e1e6a45ced 49 ******************************************************************************/
dkato 0:37e1e6a45ced 50 #define QUANTIZATION_TABLE_SIZE (64u)
dkato 0:37e1e6a45ced 51 #define HUFFMAN_TABLE_DC_SIZE (28u)
dkato 0:37e1e6a45ced 52 #define HUFFMAN_TABLE_AC_SIZE (178u)
dkato 0:37e1e6a45ced 53 #define JPEG_HEADER_LETTER_1 (0xFFu)
dkato 0:37e1e6a45ced 54 #define JPEG_HEADER_LETTER_2 (0xD8u)
dkato 0:37e1e6a45ced 55 #define ALPHA_VAL_MAX (0xFF)
dkato 0:37e1e6a45ced 56 #define LOC_KIND_COLOR_FORMAT (3u)
dkato 0:37e1e6a45ced 57
dkato 0:37e1e6a45ced 58 #define ENC_SIZE_MAX (1024 * 30)
dkato 0:37e1e6a45ced 59 #define MASK_8BYTE (0xFFFFFFF8)
dkato 0:37e1e6a45ced 60
dkato 0:37e1e6a45ced 61 /*[QuantizationTable_Y]*/
dkato 0:37e1e6a45ced 62 /* Quality is IJG75 */
dkato 0:37e1e6a45ced 63 static const uint8_t csaDefaultQuantizationTable_Y[QUANTIZATION_TABLE_SIZE] = {
dkato 0:37e1e6a45ced 64 8, 6, 5, 8, 12, 20, 26, 31,
dkato 0:37e1e6a45ced 65 6, 6, 7, 10, 13, 29, 30, 28,
dkato 0:37e1e6a45ced 66 7, 7, 8, 12, 20, 29, 35, 28,
dkato 0:37e1e6a45ced 67 7, 9, 11, 15, 26, 44, 40, 31,
dkato 0:37e1e6a45ced 68 9, 11, 19, 28, 34, 55, 52, 39,
dkato 0:37e1e6a45ced 69 12, 18, 28, 32, 41, 52, 57, 46,
dkato 0:37e1e6a45ced 70 25, 32, 39, 44, 52, 61, 60, 51,
dkato 0:37e1e6a45ced 71 36, 46, 48, 49, 56, 50, 52, 50
dkato 0:37e1e6a45ced 72 };
dkato 0:37e1e6a45ced 73
dkato 0:37e1e6a45ced 74 /*[QuantizationTable_C]*/
dkato 0:37e1e6a45ced 75 /* Quality is IJG75 */
dkato 0:37e1e6a45ced 76 static const uint8_t csaDefaultQuantizationTable_C[QUANTIZATION_TABLE_SIZE] = {
dkato 0:37e1e6a45ced 77 9, 9, 12, 24, 50, 50, 50, 50,
dkato 0:37e1e6a45ced 78 9, 11, 13, 33, 50, 50, 50, 50,
dkato 0:37e1e6a45ced 79 12, 13, 28, 50, 50, 50, 50, 50,
dkato 0:37e1e6a45ced 80 24, 33, 50, 50, 50, 50, 50, 50,
dkato 0:37e1e6a45ced 81 50, 50, 50, 50, 50, 50, 50, 50,
dkato 0:37e1e6a45ced 82 50, 50, 50, 50, 50, 50, 50, 50,
dkato 0:37e1e6a45ced 83 50, 50, 50, 50, 50, 50, 50, 50,
dkato 0:37e1e6a45ced 84 50, 50, 50, 50, 50, 50, 50, 50
dkato 0:37e1e6a45ced 85 };
dkato 0:37e1e6a45ced 86
dkato 0:37e1e6a45ced 87 /*[HuffmanTable_Y_DC]*/
dkato 0:37e1e6a45ced 88 /* Example written in ITU-T T81 specification */
dkato 0:37e1e6a45ced 89 static const uint8_t csaDefaultHuffmanTable_Y_DC[HUFFMAN_TABLE_DC_SIZE] = {
dkato 0:37e1e6a45ced 90 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
dkato 0:37e1e6a45ced 91 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B
dkato 0:37e1e6a45ced 92 };
dkato 0:37e1e6a45ced 93
dkato 0:37e1e6a45ced 94 /*[HuffmanTable_C_DC]*/
dkato 0:37e1e6a45ced 95 /* Example written in ITU-T T81 specification */
dkato 0:37e1e6a45ced 96 static const uint8_t csaDefaultHuffmanTable_C_DC[HUFFMAN_TABLE_DC_SIZE] = {
dkato 0:37e1e6a45ced 97 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
dkato 0:37e1e6a45ced 98 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B
dkato 0:37e1e6a45ced 99 };
dkato 0:37e1e6a45ced 100
dkato 0:37e1e6a45ced 101 /*[HuffmanTable_Y_AC]*/
dkato 0:37e1e6a45ced 102 /* Example written in ITU-T T81 specification */
dkato 0:37e1e6a45ced 103 static const uint8_t csaDefaultHuffmanTable_Y_AC[HUFFMAN_TABLE_AC_SIZE] = {
dkato 0:37e1e6a45ced 104 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D,
dkato 0:37e1e6a45ced 105 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
dkato 0:37e1e6a45ced 106 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0,
dkato 0:37e1e6a45ced 107 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28,
dkato 0:37e1e6a45ced 108 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
dkato 0:37e1e6a45ced 109 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
dkato 0:37e1e6a45ced 110 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
dkato 0:37e1e6a45ced 111 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
dkato 0:37e1e6a45ced 112 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5,
dkato 0:37e1e6a45ced 113 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2,
dkato 0:37e1e6a45ced 114 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
dkato 0:37e1e6a45ced 115 0xF9, 0xFA
dkato 0:37e1e6a45ced 116 };
dkato 0:37e1e6a45ced 117
dkato 0:37e1e6a45ced 118 /*[HuffmanTable_C_AC]*/
dkato 0:37e1e6a45ced 119 /* Example written in ITU-T T81 specification */
dkato 0:37e1e6a45ced 120 static const uint8_t csaDefaultHuffmanTable_C_AC[HUFFMAN_TABLE_AC_SIZE] = {
dkato 0:37e1e6a45ced 121 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77,
dkato 0:37e1e6a45ced 122 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
dkato 0:37e1e6a45ced 123 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0,
dkato 0:37e1e6a45ced 124 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26,
dkato 0:37e1e6a45ced 125 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
dkato 0:37e1e6a45ced 126 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
dkato 0:37e1e6a45ced 127 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
dkato 0:37e1e6a45ced 128 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5,
dkato 0:37e1e6a45ced 129 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3,
dkato 0:37e1e6a45ced 130 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA,
dkato 0:37e1e6a45ced 131 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
dkato 0:37e1e6a45ced 132 0xF9, 0xFA
dkato 0:37e1e6a45ced 133 };
dkato 0:37e1e6a45ced 134
dkato 1:7b90e31adc5b 135 typedef void (JPEG_CallbackFunc_t)(JPEG_Converter::jpeg_conv_error_t err_code);
dkato 1:7b90e31adc5b 136
dkato 1:7b90e31adc5b 137 static uint32_t driver_ac_count = 0;
dkato 1:7b90e31adc5b 138 static bool jcu_error_flag;
dkato 1:7b90e31adc5b 139 static JPEG_CallbackFunc_t* pJPEG_ConverterCallback;
dkato 1:7b90e31adc5b 140 Semaphore jpeg_converter_semaphore(1);
dkato 1:7b90e31adc5b 141
dkato 1:7b90e31adc5b 142
dkato 1:7b90e31adc5b 143 /**************************************************************************//**
dkato 1:7b90e31adc5b 144 * @brief Callback function from JCU async mode
dkato 1:7b90e31adc5b 145 * @param[in] mbed_jcu_err_t err_code : JCU result
dkato 1:7b90e31adc5b 146 * @retval None
dkato 1:7b90e31adc5b 147 ******************************************************************************/
dkato 1:7b90e31adc5b 148 void JPEG_CallbackFunction(mbed_jcu_err_t err_code) {
dkato 1:7b90e31adc5b 149 if (pJPEG_ConverterCallback != NULL) {
dkato 1:7b90e31adc5b 150 pJPEG_ConverterCallback((JPEG_Converter::jpeg_conv_error_t)err_code);
dkato 1:7b90e31adc5b 151 }
dkato 1:7b90e31adc5b 152 if (err_code != MBED_JCU_E_OK) {
dkato 1:7b90e31adc5b 153 jcu_error_flag = true;
dkato 1:7b90e31adc5b 154 }
dkato 1:7b90e31adc5b 155 jpeg_converter_semaphore.release(); // RELEASE
dkato 1:7b90e31adc5b 156 } /* End of callback function method () */
dkato 0:37e1e6a45ced 157
dkato 0:37e1e6a45ced 158 /**************************************************************************//**
dkato 0:37e1e6a45ced 159 * @brief Constructor of the JPEG_Converter class
dkato 0:37e1e6a45ced 160 * @param[in] None
dkato 0:37e1e6a45ced 161 * @retval None
dkato 0:37e1e6a45ced 162 ******************************************************************************/
dkato 1:7b90e31adc5b 163 JPEG_Converter::JPEG_Converter(void) {
dkato 0:37e1e6a45ced 164 jcu_errorcode_t jcu_error;
dkato 0:37e1e6a45ced 165
dkato 1:7b90e31adc5b 166 if (driver_ac_count == 0) {
dkato 1:7b90e31adc5b 167 jcu_error = R_JCU_Initialize(NULL);
dkato 1:7b90e31adc5b 168 if (jcu_error == JCU_ERROR_OK) {
dkato 1:7b90e31adc5b 169 driver_ac_count++;
dkato 1:7b90e31adc5b 170 jcu_error_flag = false;
dkato 1:7b90e31adc5b 171 }
dkato 1:7b90e31adc5b 172 } else {
dkato 1:7b90e31adc5b 173 driver_ac_count++;
dkato 0:37e1e6a45ced 174 }
dkato 0:37e1e6a45ced 175 } /* End of constructor method () */
dkato 0:37e1e6a45ced 176
dkato 0:37e1e6a45ced 177 /**************************************************************************//**
dkato 0:37e1e6a45ced 178 * @brief Destructor of the JPEG_Converter class
dkato 0:37e1e6a45ced 179 * @param[in] None
dkato 0:37e1e6a45ced 180 * @retval None
dkato 0:37e1e6a45ced 181 ******************************************************************************/
dkato 1:7b90e31adc5b 182 JPEG_Converter::~JPEG_Converter(void) {
dkato 1:7b90e31adc5b 183 if (driver_ac_count > 0) {
dkato 1:7b90e31adc5b 184 driver_ac_count--;
dkato 1:7b90e31adc5b 185 if (driver_ac_count == 0) {
dkato 1:7b90e31adc5b 186 (void)R_JCU_Terminate();
dkato 1:7b90e31adc5b 187 }
dkato 0:37e1e6a45ced 188 }
dkato 0:37e1e6a45ced 189 } /* End of destructor method () */
dkato 0:37e1e6a45ced 190
dkato 0:37e1e6a45ced 191 /**************************************************************************//**
dkato 0:37e1e6a45ced 192 * @brief JPEG data decode to bitmap
dkato 0:37e1e6a45ced 193 * @param[in] void* pJpegBuff : Input JPEG data address
dkato 0:37e1e6a45ced 194 * @param[in/out] bitmap_buff_info_t* psOutputBuff : Output bitmap data address
dkato 0:37e1e6a45ced 195 * @retval error code
dkato 0:37e1e6a45ced 196 ******************************************************************************/
dkato 0:37e1e6a45ced 197 JPEG_Converter::jpeg_conv_error_t
dkato 1:7b90e31adc5b 198 JPEG_Converter::decode(void* pJpegBuff, bitmap_buff_info_t* psOutputBuff) {
dkato 1:7b90e31adc5b 199 decode_options_t Options;
dkato 0:37e1e6a45ced 200
dkato 1:7b90e31adc5b 201 return (decode(pJpegBuff, psOutputBuff, &Options));
dkato 0:37e1e6a45ced 202 } /* End of method decode() */
dkato 0:37e1e6a45ced 203
dkato 0:37e1e6a45ced 204 /**************************************************************************//**
dkato 0:37e1e6a45ced 205 * @brief JPEG data decode to bitmap
dkato 0:37e1e6a45ced 206 * @param[in] void* pJpegBuff : Input JPEG data address
dkato 0:37e1e6a45ced 207 * @param[in/out] bitmap_buff_info_t* psOutputBuff : Output bitmap data address
dkato 0:37e1e6a45ced 208 * @param[in] decode_options_t* pOptions : Decode option(Optional)
dkato 0:37e1e6a45ced 209 * @retval error code
dkato 0:37e1e6a45ced 210 ******************************************************************************/
dkato 0:37e1e6a45ced 211 JPEG_Converter::jpeg_conv_error_t
dkato 1:7b90e31adc5b 212 JPEG_Converter::decode(void* pJpegBuff, bitmap_buff_info_t* psOutputBuff, decode_options_t* pOptions) {
dkato 0:37e1e6a45ced 213 jpeg_conv_error_t e;
dkato 0:37e1e6a45ced 214 jcu_errorcode_t jcu_error;
dkato 0:37e1e6a45ced 215 jcu_decode_param_t decode;
dkato 0:37e1e6a45ced 216 jcu_buffer_param_t buffer;
dkato 1:7b90e31adc5b 217 uint8_t* pBuff = (uint8_t *)pJpegBuff;
dkato 0:37e1e6a45ced 218 const jcu_async_status_t* status;
dkato 0:37e1e6a45ced 219 jcu_image_info_t image_info;
dkato 1:7b90e31adc5b 220 bool mutex_release = false;
dkato 0:37e1e6a45ced 221
dkato 0:37e1e6a45ced 222 // Check JCU initialized
dkato 1:7b90e31adc5b 223 if (driver_ac_count > 0) {
dkato 1:7b90e31adc5b 224 size_t calc_height;
dkato 1:7b90e31adc5b 225 size_t calc_width;
dkato 0:37e1e6a45ced 226
dkato 0:37e1e6a45ced 227 calc_height = psOutputBuff->height * (2 ^ pOptions->vertical_sub_sampling);
dkato 0:37e1e6a45ced 228 calc_width = psOutputBuff->width * (2 ^ pOptions->horizontal_sub_sampling);
dkato 0:37e1e6a45ced 229
dkato 0:37e1e6a45ced 230 // Check input address
dkato 0:37e1e6a45ced 231 if ((pJpegBuff == NULL) || (psOutputBuff == NULL) || (pOptions == NULL)) {
dkato 0:37e1e6a45ced 232 e = JPEG_CONV_PARAM_ERR; // Input address error
dkato 0:37e1e6a45ced 233 goto fin;
dkato 0:37e1e6a45ced 234 }
dkato 0:37e1e6a45ced 235 // Check JPEG header
dkato 1:7b90e31adc5b 236 if (((uint32_t)(pBuff[0]) != JPEG_HEADER_LETTER_1) ||
dkato 1:7b90e31adc5b 237 ((uint32_t)(pBuff[1]) != JPEG_HEADER_LETTER_2)) {
dkato 0:37e1e6a45ced 238 e = JPEG_CONV_FORMA_ERR; // JPEG data is not in ROM
dkato 0:37e1e6a45ced 239 goto fin;
dkato 0:37e1e6a45ced 240 }
dkato 1:7b90e31adc5b 241 // JCU Error reset
dkato 1:7b90e31adc5b 242 if (jcu_error_flag == true) {
dkato 1:7b90e31adc5b 243 (void)R_JCU_Terminate();
dkato 1:7b90e31adc5b 244 (void)R_JCU_Initialize(NULL);
dkato 1:7b90e31adc5b 245 jcu_error_flag = false;
dkato 1:7b90e31adc5b 246 }
dkato 1:7b90e31adc5b 247 // Get mutex
dkato 1:7b90e31adc5b 248 if (pOptions->p_DecodeCallBackFunc == NULL) {
dkato 1:7b90e31adc5b 249 jpeg_converter_semaphore.wait(0xFFFFFFFFuL); // WAIT
dkato 1:7b90e31adc5b 250 } else {
dkato 1:7b90e31adc5b 251 if (!jpeg_converter_semaphore.wait(0)) {
dkato 1:7b90e31adc5b 252 e = JPEG_CONV_BUSY; // Busy
dkato 1:7b90e31adc5b 253 goto fin;
dkato 1:7b90e31adc5b 254 }
dkato 1:7b90e31adc5b 255 }
dkato 1:7b90e31adc5b 256 // Select decode
dkato 0:37e1e6a45ced 257 jcu_error = R_JCU_SelectCodec( JCU_DECODE );
dkato 1:7b90e31adc5b 258 if (jcu_error != JCU_ERROR_OK) {
dkato 1:7b90e31adc5b 259 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 260 mutex_release = true;
dkato 0:37e1e6a45ced 261 goto fin;
dkato 0:37e1e6a45ced 262 }
dkato 0:37e1e6a45ced 263
dkato 0:37e1e6a45ced 264 buffer.source.swapSetting = JCU_SWAP_LONG_WORD_AND_WORD_AND_BYTE;
dkato 0:37e1e6a45ced 265 buffer.source.address = (uint32_t *)pBuff;
dkato 0:37e1e6a45ced 266 buffer.lineOffset = (int16_t)psOutputBuff->width;
dkato 0:37e1e6a45ced 267 buffer.destination.address = (uint32_t *)psOutputBuff->buffer_address;
dkato 0:37e1e6a45ced 268 decode.decodeFormat = (jcu_decode_format_t)psOutputBuff->format;
dkato 0:37e1e6a45ced 269 buffer.destination.swapSetting = (jcu_swap_t)pOptions->output_swapsetting;
dkato 0:37e1e6a45ced 270 decode.outputCbCrOffset = (jcu_cbcr_offset_t)pOptions->output_cb_cr_offset;
dkato 0:37e1e6a45ced 271 decode.alpha = pOptions->alpha;
dkato 0:37e1e6a45ced 272 decode.horizontalSubSampling = (jcu_sub_sampling_t)pOptions->horizontal_sub_sampling;
dkato 0:37e1e6a45ced 273 decode.verticalSubSampling = (jcu_sub_sampling_t)pOptions->vertical_sub_sampling;
dkato 1:7b90e31adc5b 274
dkato 1:7b90e31adc5b 275 jcu_error = R_JCU_SetDecodeParam(&decode, &buffer);
dkato 1:7b90e31adc5b 276 if (jcu_error != JCU_ERROR_OK) {
dkato 0:37e1e6a45ced 277 e = JPEG_CONV_FORMA_ERR;
dkato 1:7b90e31adc5b 278 mutex_release = true;
dkato 1:7b90e31adc5b 279 jcu_error_flag = false;
dkato 0:37e1e6a45ced 280 goto fin;
dkato 0:37e1e6a45ced 281 }
dkato 0:37e1e6a45ced 282
dkato 0:37e1e6a45ced 283 if (pOptions->check_jpeg_format != false) {
dkato 1:7b90e31adc5b 284 jcu_error = R_JCU_SetPauseForImageInfo(true);
dkato 1:7b90e31adc5b 285 if (jcu_error != JCU_ERROR_OK) {
dkato 0:37e1e6a45ced 286 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 287 mutex_release = true;
dkato 1:7b90e31adc5b 288 jcu_error_flag = false;
dkato 0:37e1e6a45ced 289 goto fin;
dkato 0:37e1e6a45ced 290 }
dkato 0:37e1e6a45ced 291 }
dkato 1:7b90e31adc5b 292 if (pOptions->p_DecodeCallBackFunc == NULL) {
dkato 0:37e1e6a45ced 293 jcu_error = R_JCU_Start();
dkato 1:7b90e31adc5b 294 mutex_release = true;
dkato 1:7b90e31adc5b 295 if (jcu_error != JCU_ERROR_OK) {
dkato 0:37e1e6a45ced 296 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 297 jcu_error_flag = false;
dkato 0:37e1e6a45ced 298 goto fin;
dkato 0:37e1e6a45ced 299 }
dkato 1:7b90e31adc5b 300 if (pOptions->check_jpeg_format != false) {
dkato 1:7b90e31adc5b 301 R_JCU_GetAsyncStatus( &status );
dkato 1:7b90e31adc5b 302 if (status -> IsPaused == false) {
dkato 1:7b90e31adc5b 303 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 304 jcu_error_flag = false;
dkato 1:7b90e31adc5b 305 goto fin;
dkato 1:7b90e31adc5b 306 }
dkato 1:7b90e31adc5b 307 if ((status->SubStatusFlags & JCU_SUB_INFOMATION_READY) == 0) {
dkato 1:7b90e31adc5b 308 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 309 jcu_error_flag = false;
dkato 1:7b90e31adc5b 310 goto fin;
dkato 1:7b90e31adc5b 311 }
dkato 1:7b90e31adc5b 312 jcu_error = R_JCU_GetImageInfo( &image_info );
dkato 1:7b90e31adc5b 313 if (jcu_error != JCU_ERROR_OK) {
dkato 1:7b90e31adc5b 314 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 315 jcu_error_flag = false;
dkato 1:7b90e31adc5b 316 goto fin;
dkato 1:7b90e31adc5b 317 }
dkato 1:7b90e31adc5b 318 if ((image_info.width == 0u) || (image_info.height == 0u) ||
dkato 1:7b90e31adc5b 319 (image_info.width > calc_width) ||
dkato 1:7b90e31adc5b 320 (image_info.height > calc_height)) {
dkato 1:7b90e31adc5b 321 e = JPEG_CONV_FORMA_ERR;
dkato 1:7b90e31adc5b 322 jcu_error_flag = false;
dkato 1:7b90e31adc5b 323 goto fin;
dkato 1:7b90e31adc5b 324 }
dkato 1:7b90e31adc5b 325 if ((image_info.encodedFormat != JCU_JPEG_YCbCr444) &&
dkato 1:7b90e31adc5b 326 (image_info.encodedFormat != JCU_JPEG_YCbCr422) &&
dkato 1:7b90e31adc5b 327 (image_info.encodedFormat != JCU_JPEG_YCbCr420) &&
dkato 1:7b90e31adc5b 328 (image_info.encodedFormat != JCU_JPEG_YCbCr411)) {
dkato 1:7b90e31adc5b 329 e = JPEG_CONV_FORMA_ERR;
dkato 1:7b90e31adc5b 330 jcu_error_flag = false;
dkato 1:7b90e31adc5b 331 goto fin;
dkato 1:7b90e31adc5b 332 }
dkato 1:7b90e31adc5b 333 jcu_error = R_JCU_Continue(JCU_IMAGE_INFO);
dkato 1:7b90e31adc5b 334 if (jcu_error != JCU_ERROR_OK) {
dkato 1:7b90e31adc5b 335 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 336 jcu_error_flag = false;
dkato 1:7b90e31adc5b 337 goto fin;
dkato 1:7b90e31adc5b 338 }
dkato 0:37e1e6a45ced 339 }
dkato 0:37e1e6a45ced 340 } else {
dkato 1:7b90e31adc5b 341 pJPEG_ConverterCallback = pOptions->p_DecodeCallBackFunc;
dkato 1:7b90e31adc5b 342 jcu_error = R_wrpper_set_decode_callback((mbed_CallbackFunc_t*)JPEG_CallbackFunction, (size_t)calc_width, calc_height);
dkato 1:7b90e31adc5b 343 if (jcu_error != JCU_ERROR_OK) {
dkato 1:7b90e31adc5b 344 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 345 mutex_release = true;
dkato 0:37e1e6a45ced 346 goto fin;
dkato 0:37e1e6a45ced 347 }
dkato 0:37e1e6a45ced 348 }
dkato 0:37e1e6a45ced 349 e = JPEG_CONV_OK;
dkato 0:37e1e6a45ced 350 }
dkato 0:37e1e6a45ced 351 else
dkato 0:37e1e6a45ced 352 {
dkato 0:37e1e6a45ced 353 e = JPEG_CONV_JCU_ERR;
dkato 0:37e1e6a45ced 354 }
dkato 0:37e1e6a45ced 355 fin:
dkato 1:7b90e31adc5b 356 if (mutex_release == true) {
dkato 1:7b90e31adc5b 357 jpeg_converter_semaphore.release(); // RELEASE
dkato 1:7b90e31adc5b 358 }
dkato 1:7b90e31adc5b 359
dkato 0:37e1e6a45ced 360 return e;
dkato 0:37e1e6a45ced 361 } /* End of method decode() */
dkato 0:37e1e6a45ced 362
dkato 0:37e1e6a45ced 363
dkato 0:37e1e6a45ced 364 /**************************************************************************//**
dkato 0:37e1e6a45ced 365 * @brief Bitmap data encode to JPEG
dkato 0:37e1e6a45ced 366 * @param[in] bitmap_buff_info_t* psInputBuff : Input bitmap data address
dkato 0:37e1e6a45ced 367 * @param[out] void* pJpegBuff : Output JPEG data address
dkato 0:37e1e6a45ced 368 * @param[out] size_t* pEncodeSize : Encode size address
dkato 0:37e1e6a45ced 369 * @retval error code
dkato 0:37e1e6a45ced 370 ******************************************************************************/
dkato 0:37e1e6a45ced 371 JPEG_Converter::jpeg_conv_error_t
dkato 0:37e1e6a45ced 372 JPEG_Converter::encode(bitmap_buff_info_t* psInputBuff, void* pJpegBuff, size_t* pEncodeSize ) {
dkato 1:7b90e31adc5b 373 encode_options_t Options;
dkato 1:7b90e31adc5b 374
dkato 1:7b90e31adc5b 375 return (encode(psInputBuff, pJpegBuff, pEncodeSize, &Options));
dkato 0:37e1e6a45ced 376 } /* End of method encode() */
dkato 0:37e1e6a45ced 377
dkato 0:37e1e6a45ced 378
dkato 0:37e1e6a45ced 379 /**************************************************************************//**
dkato 0:37e1e6a45ced 380 * @brief Bitmap data encode to JPEG
dkato 0:37e1e6a45ced 381 * @param[in] bitmap_buff_info_t* psInputBuff : Input bitmap data address
dkato 0:37e1e6a45ced 382 * @param[out] void* pJpegBuff : Output JPEG data address
dkato 0:37e1e6a45ced 383 * @param[out] size_t* pEncodeSize : Encode size address
dkato 1:7b90e31adc5b 384 * @param[in] encode_options_t* pOptions : Encode option(Optional)
dkato 0:37e1e6a45ced 385 * @retval error code
dkato 0:37e1e6a45ced 386 ******************************************************************************/
dkato 0:37e1e6a45ced 387 JPEG_Converter::jpeg_conv_error_t
dkato 0:37e1e6a45ced 388 JPEG_Converter::encode(bitmap_buff_info_t* psInputBuff, void* pJpegBuff, size_t* pEncodeSize, encode_options_t* pOptions ) {
dkato 0:37e1e6a45ced 389
dkato 0:37e1e6a45ced 390 jpeg_conv_error_t e;
dkato 0:37e1e6a45ced 391 jcu_errorcode_t jcu_error;
dkato 0:37e1e6a45ced 392 jcu_buffer_param_t buffer;
dkato 0:37e1e6a45ced 393 uint8_t* TableAddress;
dkato 0:37e1e6a45ced 394 jcu_encode_param_t encode;
dkato 1:7b90e31adc5b 395 jcu_count_mode_param_t count_para;
dkato 1:7b90e31adc5b 396 int32_t encode_count;
dkato 1:7b90e31adc5b 397 int32_t size_max_count = 1;
dkato 1:7b90e31adc5b 398 size_t BufferSize = pOptions->encode_buff_size;
dkato 1:7b90e31adc5b 399 const jcu_async_status_t* status;
dkato 1:7b90e31adc5b 400 bool mutex_release = false;
dkato 0:37e1e6a45ced 401
dkato 0:37e1e6a45ced 402 // Check JCU initialized
dkato 1:7b90e31adc5b 403 if (driver_ac_count > 0) {
dkato 0:37e1e6a45ced 404 // Check input address
dkato 0:37e1e6a45ced 405 if ((pJpegBuff == NULL) || (psInputBuff == NULL) || (pEncodeSize == NULL)) {
dkato 0:37e1e6a45ced 406 e = JPEG_CONV_PARAM_ERR; // Input address error
dkato 0:37e1e6a45ced 407 goto fin;
dkato 0:37e1e6a45ced 408 }
dkato 1:7b90e31adc5b 409 // JCU Error reset
dkato 1:7b90e31adc5b 410 if (jcu_error_flag == true) {
dkato 1:7b90e31adc5b 411 (void)R_JCU_Terminate();
dkato 1:7b90e31adc5b 412 (void)R_JCU_Initialize(NULL);
dkato 1:7b90e31adc5b 413 jcu_error_flag = false;
dkato 1:7b90e31adc5b 414 }
dkato 1:7b90e31adc5b 415 // Get mutex
dkato 1:7b90e31adc5b 416 if ( pOptions->p_EncodeCallBackFunc == NULL ) {
dkato 1:7b90e31adc5b 417 jpeg_converter_semaphore.wait(0xFFFFFFFFuL); // WAIT
dkato 1:7b90e31adc5b 418 } else {
dkato 1:7b90e31adc5b 419 if (!jpeg_converter_semaphore.wait(0)) {
dkato 1:7b90e31adc5b 420 e = JPEG_CONV_BUSY; // Busy
dkato 1:7b90e31adc5b 421 goto fin;
dkato 1:7b90e31adc5b 422 }
dkato 1:7b90e31adc5b 423 }
dkato 1:7b90e31adc5b 424 // Select encode
dkato 1:7b90e31adc5b 425 jcu_error = R_JCU_SelectCodec(JCU_ENCODE);
dkato 1:7b90e31adc5b 426 if (jcu_error != JCU_ERROR_OK) {
dkato 0:37e1e6a45ced 427 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 428 mutex_release = true;
dkato 0:37e1e6a45ced 429 goto fin;
dkato 0:37e1e6a45ced 430 }
dkato 0:37e1e6a45ced 431 /* Set tables */
dkato 0:37e1e6a45ced 432 if ( pOptions->quantization_table_Y != NULL ) {
dkato 0:37e1e6a45ced 433 TableAddress = (uint8_t*)pOptions->quantization_table_Y;
dkato 0:37e1e6a45ced 434 } else {
dkato 0:37e1e6a45ced 435 TableAddress = (uint8_t*)csaDefaultQuantizationTable_Y;
dkato 0:37e1e6a45ced 436 }
dkato 0:37e1e6a45ced 437 jcu_error = R_JCU_SetQuantizationTable( JCU_TABLE_NO_0, (uint8_t*)TableAddress );
dkato 0:37e1e6a45ced 438 if ( jcu_error != JCU_ERROR_OK ) {
dkato 0:37e1e6a45ced 439 e = JPEG_CONV_PARAM_RANGE_ERR;
dkato 1:7b90e31adc5b 440 mutex_release = true;
dkato 1:7b90e31adc5b 441 jcu_error_flag = true;
dkato 0:37e1e6a45ced 442 goto fin;
dkato 0:37e1e6a45ced 443 }
dkato 0:37e1e6a45ced 444 if ( pOptions->quantization_table_C != NULL ) {
dkato 0:37e1e6a45ced 445 TableAddress = (uint8_t*)pOptions->quantization_table_C;
dkato 0:37e1e6a45ced 446 } else {
dkato 0:37e1e6a45ced 447 TableAddress = (uint8_t*)csaDefaultQuantizationTable_C;
dkato 0:37e1e6a45ced 448 }
dkato 0:37e1e6a45ced 449 jcu_error = R_JCU_SetQuantizationTable( JCU_TABLE_NO_1, (uint8_t*)TableAddress );
dkato 0:37e1e6a45ced 450 if ( jcu_error != JCU_ERROR_OK ) {
dkato 0:37e1e6a45ced 451 e = JPEG_CONV_PARAM_RANGE_ERR;
dkato 1:7b90e31adc5b 452 mutex_release = true;
dkato 1:7b90e31adc5b 453 jcu_error_flag = true;
dkato 0:37e1e6a45ced 454 goto fin;
dkato 0:37e1e6a45ced 455 }
dkato 0:37e1e6a45ced 456 if ( pOptions->huffman_table_Y_DC != NULL ) {
dkato 0:37e1e6a45ced 457 TableAddress = (uint8_t*)pOptions->huffman_table_Y_DC;
dkato 0:37e1e6a45ced 458 } else {
dkato 0:37e1e6a45ced 459 TableAddress = (uint8_t*)csaDefaultHuffmanTable_Y_DC;
dkato 0:37e1e6a45ced 460 }
dkato 0:37e1e6a45ced 461 jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_0, JCU_HUFFMAN_DC, (uint8_t*)TableAddress );
dkato 0:37e1e6a45ced 462 if ( jcu_error != JCU_ERROR_OK ) {
dkato 0:37e1e6a45ced 463 e = JPEG_CONV_PARAM_RANGE_ERR;
dkato 1:7b90e31adc5b 464 mutex_release = true;
dkato 1:7b90e31adc5b 465 jcu_error_flag = true;
dkato 0:37e1e6a45ced 466 goto fin;
dkato 0:37e1e6a45ced 467 }
dkato 0:37e1e6a45ced 468 if ( pOptions->huffman_table_C_DC != NULL ) {
dkato 0:37e1e6a45ced 469 TableAddress = (uint8_t*)pOptions->huffman_table_C_DC;
dkato 0:37e1e6a45ced 470 } else {
dkato 0:37e1e6a45ced 471 TableAddress = (uint8_t*)csaDefaultHuffmanTable_C_DC;
dkato 0:37e1e6a45ced 472 }
dkato 0:37e1e6a45ced 473 jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_1, JCU_HUFFMAN_DC, (uint8_t*)TableAddress );
dkato 0:37e1e6a45ced 474 if ( jcu_error != JCU_ERROR_OK ) {
dkato 0:37e1e6a45ced 475 e = JPEG_CONV_PARAM_RANGE_ERR;
dkato 1:7b90e31adc5b 476 mutex_release = true;
dkato 1:7b90e31adc5b 477 jcu_error_flag = true;
dkato 0:37e1e6a45ced 478 goto fin;
dkato 0:37e1e6a45ced 479 }
dkato 0:37e1e6a45ced 480 if ( pOptions->huffman_table_Y_AC != NULL ) {
dkato 0:37e1e6a45ced 481 TableAddress = (uint8_t*)pOptions->huffman_table_Y_AC;
dkato 0:37e1e6a45ced 482 } else {
dkato 0:37e1e6a45ced 483 TableAddress = (uint8_t*)csaDefaultHuffmanTable_Y_AC;
dkato 0:37e1e6a45ced 484 }
dkato 0:37e1e6a45ced 485 jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_0, JCU_HUFFMAN_AC, (uint8_t*)TableAddress );
dkato 0:37e1e6a45ced 486 if ( jcu_error != JCU_ERROR_OK ) {
dkato 0:37e1e6a45ced 487 e = JPEG_CONV_PARAM_RANGE_ERR;
dkato 1:7b90e31adc5b 488 mutex_release = true;
dkato 1:7b90e31adc5b 489 jcu_error_flag = true;
dkato 0:37e1e6a45ced 490 goto fin;
dkato 0:37e1e6a45ced 491 }
dkato 0:37e1e6a45ced 492 if ( pOptions->huffman_table_C_AC != NULL ) {
dkato 0:37e1e6a45ced 493 TableAddress = (uint8_t*)pOptions->huffman_table_C_AC;
dkato 0:37e1e6a45ced 494 } else {
dkato 0:37e1e6a45ced 495 TableAddress = (uint8_t*)csaDefaultHuffmanTable_C_AC;
dkato 0:37e1e6a45ced 496 }
dkato 0:37e1e6a45ced 497 jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_1, JCU_HUFFMAN_AC, (uint8_t*)TableAddress );
dkato 0:37e1e6a45ced 498 if ( jcu_error != JCU_ERROR_OK ) {
dkato 0:37e1e6a45ced 499 e = JPEG_CONV_PARAM_RANGE_ERR;
dkato 1:7b90e31adc5b 500 mutex_release = true;
dkato 1:7b90e31adc5b 501 jcu_error_flag = true;
dkato 0:37e1e6a45ced 502 goto fin;
dkato 0:37e1e6a45ced 503 }
dkato 0:37e1e6a45ced 504
dkato 0:37e1e6a45ced 505 // JPEG encode
dkato 0:37e1e6a45ced 506 buffer.source.swapSetting = (jcu_swap_t)pOptions->input_swapsetting;
dkato 0:37e1e6a45ced 507 buffer.source.address = (uint32_t *)psInputBuff->buffer_address;
dkato 0:37e1e6a45ced 508 buffer.destination.swapSetting = JCU_SWAP_LONG_WORD_AND_WORD_AND_BYTE;
dkato 0:37e1e6a45ced 509 buffer.destination.address = (uint32_t *)pJpegBuff;
dkato 0:37e1e6a45ced 510 buffer.lineOffset = psInputBuff->width;
dkato 0:37e1e6a45ced 511 encode.encodeFormat = (jcu_jpeg_format_t)JCU_JPEG_YCbCr422;
dkato 0:37e1e6a45ced 512 encode.QuantizationTable[ JCU_ELEMENT_Y ] = JCU_TABLE_NO_0;
dkato 0:37e1e6a45ced 513 encode.QuantizationTable[ JCU_ELEMENT_Cb ] = JCU_TABLE_NO_1;
dkato 0:37e1e6a45ced 514 encode.QuantizationTable[ JCU_ELEMENT_Cr ] = JCU_TABLE_NO_1;
dkato 0:37e1e6a45ced 515 encode.HuffmanTable[ JCU_ELEMENT_Y ] = JCU_TABLE_NO_0;
dkato 0:37e1e6a45ced 516 encode.HuffmanTable[ JCU_ELEMENT_Cb ] = JCU_TABLE_NO_1;
dkato 0:37e1e6a45ced 517 encode.HuffmanTable[ JCU_ELEMENT_Cr ] = JCU_TABLE_NO_1;
dkato 0:37e1e6a45ced 518 encode.DRI_value = pOptions->DRI_value;
dkato 0:37e1e6a45ced 519 if ( pOptions->width != 0 ) {
dkato 0:37e1e6a45ced 520 encode.width = pOptions->width;
dkato 0:37e1e6a45ced 521 } else {
dkato 0:37e1e6a45ced 522 encode.width = psInputBuff->width;
dkato 0:37e1e6a45ced 523 }
dkato 0:37e1e6a45ced 524 if ( pOptions->height != 0 ) {
dkato 0:37e1e6a45ced 525 encode.height = pOptions->height;
dkato 0:37e1e6a45ced 526 } else {
dkato 0:37e1e6a45ced 527 encode.height = psInputBuff->height;
dkato 0:37e1e6a45ced 528 }
dkato 0:37e1e6a45ced 529 encode.inputCbCrOffset = (jcu_cbcr_offset_t)pOptions->input_cb_cr_offset;
dkato 0:37e1e6a45ced 530 jcu_error = R_JCU_SetEncodeParam( &encode, &buffer );
dkato 0:37e1e6a45ced 531 if ( jcu_error != JCU_ERROR_OK ) {
dkato 0:37e1e6a45ced 532 e = JPEG_CONV_PARAM_RANGE_ERR;
dkato 1:7b90e31adc5b 533 mutex_release = true;
dkato 1:7b90e31adc5b 534 jcu_error_flag = true;
dkato 0:37e1e6a45ced 535 goto fin;
dkato 0:37e1e6a45ced 536 }
dkato 1:7b90e31adc5b 537 if (pOptions->encode_buff_size > 0) {
dkato 0:37e1e6a45ced 538
dkato 1:7b90e31adc5b 539 while(BufferSize > ENC_SIZE_MAX) {
dkato 1:7b90e31adc5b 540 size_max_count *= 2;
dkato 1:7b90e31adc5b 541 BufferSize /= 2;
dkato 1:7b90e31adc5b 542 }
dkato 1:7b90e31adc5b 543 BufferSize = BufferSize & MASK_8BYTE;
dkato 1:7b90e31adc5b 544
dkato 1:7b90e31adc5b 545 count_para.inputBuffer.isEnable = false;
dkato 1:7b90e31adc5b 546 count_para.inputBuffer.isInitAddress = false;
dkato 1:7b90e31adc5b 547 count_para.inputBuffer.restartAddress = NULL;
dkato 1:7b90e31adc5b 548 count_para.inputBuffer.dataCount = 0;
dkato 1:7b90e31adc5b 549 count_para.outputBuffer.isEnable = true;
dkato 1:7b90e31adc5b 550 count_para.outputBuffer.isInitAddress = false;
dkato 1:7b90e31adc5b 551 count_para.outputBuffer.restartAddress = NULL;
dkato 1:7b90e31adc5b 552 count_para.outputBuffer.dataCount = BufferSize;
dkato 1:7b90e31adc5b 553
dkato 1:7b90e31adc5b 554 R_JCU_SetCountMode(&count_para);
dkato 1:7b90e31adc5b 555 } else {
dkato 1:7b90e31adc5b 556 size_max_count = 0;
dkato 1:7b90e31adc5b 557 }
dkato 1:7b90e31adc5b 558 // Check async
dkato 1:7b90e31adc5b 559 if ( pOptions->p_EncodeCallBackFunc == NULL ) {
dkato 1:7b90e31adc5b 560 jcu_error = R_JCU_Start();
dkato 1:7b90e31adc5b 561 mutex_release = true;
dkato 1:7b90e31adc5b 562 if ( jcu_error != JCU_ERROR_OK ) {
dkato 1:7b90e31adc5b 563 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 564 jcu_error_flag = true;
dkato 1:7b90e31adc5b 565 goto fin;
dkato 1:7b90e31adc5b 566 }
dkato 1:7b90e31adc5b 567 if (pOptions->encode_buff_size > 0) {
dkato 0:37e1e6a45ced 568 // Check Pause flag
dkato 0:37e1e6a45ced 569 R_JCU_GetAsyncStatus( &status );
dkato 0:37e1e6a45ced 570 for ( encode_count = 1; (encode_count < size_max_count) && (status->IsPaused != false); encode_count++) {
dkato 1:7b90e31adc5b 571 if ((status->SubStatusFlags & JCU_SUB_ENCODE_OUTPUT_PAUSE) == 0) {
dkato 0:37e1e6a45ced 572 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 573 jcu_error_flag = true;
dkato 0:37e1e6a45ced 574 goto fin;
dkato 0:37e1e6a45ced 575 }
dkato 0:37e1e6a45ced 576 jcu_error = R_JCU_Continue( JCU_OUTPUT_BUFFER );
dkato 0:37e1e6a45ced 577 if (jcu_error != JCU_ERROR_OK) {
dkato 0:37e1e6a45ced 578 e = JPEG_CONV_JCU_ERR;
dkato 1:7b90e31adc5b 579 jcu_error_flag = true;
dkato 0:37e1e6a45ced 580 goto fin;
dkato 0:37e1e6a45ced 581 }
dkato 0:37e1e6a45ced 582 R_JCU_GetAsyncStatus( &status );
dkato 0:37e1e6a45ced 583 }
dkato 0:37e1e6a45ced 584 if (status->IsPaused != false) {
dkato 0:37e1e6a45ced 585 e = JPEG_CONV_PARAM_RANGE_ERR;
dkato 1:7b90e31adc5b 586 jcu_error_flag = true;
dkato 0:37e1e6a45ced 587 goto fin;
dkato 0:37e1e6a45ced 588 }
dkato 0:37e1e6a45ced 589 }
dkato 1:7b90e31adc5b 590 (void)R_JCU_GetEncodedSize(pEncodeSize);
dkato 1:7b90e31adc5b 591 } else {
dkato 1:7b90e31adc5b 592 pJPEG_ConverterCallback = pOptions->p_EncodeCallBackFunc;
dkato 1:7b90e31adc5b 593 jcu_error = R_wrpper_set_encode_callback((mbed_CallbackFunc_t*)JPEG_CallbackFunction, pEncodeSize, size_max_count);
dkato 0:37e1e6a45ced 594 if ( jcu_error != JCU_ERROR_OK ) {
dkato 0:37e1e6a45ced 595 e = JPEG_CONV_JCU_ERR;
dkato 0:37e1e6a45ced 596 goto fin;
dkato 0:37e1e6a45ced 597 }
dkato 0:37e1e6a45ced 598 }
dkato 0:37e1e6a45ced 599 e = JPEG_CONV_OK;
dkato 1:7b90e31adc5b 600 } else {
dkato 0:37e1e6a45ced 601 e = JPEG_CONV_PARAM_RANGE_ERR;
dkato 0:37e1e6a45ced 602 }
dkato 0:37e1e6a45ced 603 fin:
dkato 1:7b90e31adc5b 604 if (mutex_release == true) {
dkato 1:7b90e31adc5b 605 jpeg_converter_semaphore.release(); // RELEASE
dkato 1:7b90e31adc5b 606 }
dkato 0:37e1e6a45ced 607
dkato 0:37e1e6a45ced 608 return e;
dkato 0:37e1e6a45ced 609 } /* End of method encode() */
dkato 0:37e1e6a45ced 610