Merge pull request #1187 from kwagyeman/kwabena/jpeg_speedup_2

Keep JPEG core on during script execution
This commit is contained in:
Ibrahim Abd Elkader 2021-02-25 02:37:24 +02:00 committed by GitHub
commit 586a1440d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 26 deletions

View File

@ -21,7 +21,9 @@
void imlib_init_all()
{
// Nothing for now.
#if (OMV_HARDWARE_JPEG == 1)
imlib_jpeg_compress_init();
#endif
}
void imlib_deinit_all()
@ -29,6 +31,9 @@ void imlib_deinit_all()
#ifdef IMLIB_ENABLE_DMA2D
imlib_draw_row_deinit_all();
#endif
#if (OMV_HARDWARE_JPEG == 1)
imlib_jpeg_compress_deinit();
#endif
}
/////////////////

View File

@ -27,6 +27,7 @@
#include "fmath.h"
#include "collections.h"
#include "imlib_config.h"
#include "omv_boardconfig.h"
#define IM_LOG2_2(x) (((x) & 0x2ULL) ? ( 2 ) : 1) // NO ({ ... }) !
#define IM_LOG2_4(x) (((x) & 0xCULL) ? ( 2 + IM_LOG2_2((x) >> 2)) : IM_LOG2_2(x)) // NO ({ ... }) !
@ -1070,6 +1071,10 @@ bool bmp_read_geometry(FIL *fp, image_t *img, const char *path, bmp_read_setting
void bmp_read_pixels(FIL *fp, image_t *img, int n_lines, bmp_read_settings_t *rs);
void bmp_read(image_t *img, const char *path);
void bmp_write_subimg(image_t *img, const char *path, rectangle_t *r);
#if (OMV_HARDWARE_JPEG == 1)
void imlib_jpeg_compress_init();
void imlib_jpeg_compress_deinit();
#endif
bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc);
int jpeg_clean_trailing_bytes(int bpp, uint8_t *data);
void jpeg_read_geometry(FIL *fp, image_t *img, const char *path, jpg_read_settings_t *rs);

View File

@ -180,7 +180,9 @@ typedef struct _jpeg_enc {
};
} jpeg_enc_t;
static uint8_t mcubuf[512];
static JPEG_HandleTypeDef JPEG_Handle = {.Instance = JPEG};
static JPEG_ConfTypeDef JPEG_Config = {};
static uint8_t mcubuf[192];
static jpeg_enc_t jpeg_enc;
static uint8_t *get_mcu()
@ -316,11 +318,6 @@ bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc)
mp_uint_t start = mp_hal_ticks_ms();
#endif
// Init the HAL JPEG driver
JPEG_HandleTypeDef JPEG_Handle = {0};
JPEG_Handle.Instance = JPEG;
HAL_JPEG_Init(&JPEG_Handle);
uint32_t pad_w = src->w;
if (pad_w % 8 != 0) {
pad_w += (8 - (pad_w % 8));
@ -344,23 +341,23 @@ bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc)
JPEG_Info.ImageQuality = quality;
switch (src->bpp) {
case 0:
case 1:
case IMAGE_BPP_BINARY:
case IMAGE_BPP_GRAYSCALE:
jpeg_enc.mcu_size = JPEG_444_GS_MCU_SIZE;
JPEG_Info.ColorSpace = JPEG_GRAYSCALE_COLORSPACE;
JPEG_Info.ChromaSubsampling = JPEG_444_SUBSAMPLING;
break;
case 2:
case 3:
case IMAGE_BPP_RGB565:
case IMAGE_BPP_BAYER:
jpeg_enc.mcu_size = JPEG_444_YCBCR_MCU_SIZE;
JPEG_Info.ColorSpace = JPEG_YCBCR_COLORSPACE;
JPEG_Info.ChromaSubsampling = JPEG_444_SUBSAMPLING;
break;
}
if (HAL_JPEG_ConfigEncoding(&JPEG_Handle, &JPEG_Info) != HAL_OK) {
// Initialization error
return true;
if (memcmp(&JPEG_Config, &JPEG_Info, sizeof(JPEG_ConfTypeDef))) {
HAL_JPEG_ConfigEncoding(&JPEG_Handle, &JPEG_Info);
memcpy(&JPEG_Config, &JPEG_Info, sizeof(JPEG_ConfTypeDef));
}
// NOTE: output buffer size is stored in dst->bpp
@ -381,11 +378,21 @@ bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc)
printf("time: %u ms\n", mp_hal_ticks_ms() - start);
#endif
HAL_JPEG_DeInit(&JPEG_Handle);
return jpeg_enc.overflow;
}
void imlib_jpeg_compress_init()
{
HAL_JPEG_Init(&JPEG_Handle);
}
void imlib_jpeg_compress_deinit()
{
memset(&JPEG_Config, 0, sizeof(JPEG_ConfTypeDef));
HAL_JPEG_Abort(&JPEG_Handle);
HAL_JPEG_DeInit(&JPEG_Handle);
}
#else
// Software JPEG implementation.
#define FIX_0_382683433 ((int32_t) 98)

View File

@ -117,11 +117,6 @@ void HAL_MspInit(void)
__GPIOK_CLK_ENABLE();
#endif
#if defined (OMV_HARDWARE_JPEG)
/* Enable JPEG clock */
__HAL_RCC_JPEG_CLK_ENABLE();
#endif
/* Enable DMA clocks */
__DMA1_CLK_ENABLE();
__DMA2_CLK_ENABLE();
@ -131,11 +126,6 @@ void HAL_MspInit(void)
__HAL_RCC_MDMA_CLK_ENABLE();
#endif
#if defined(OMV_HARDWARE_JPEG)
// Enable JPEG clock
__HAL_RCC_JPGDECEN_CLK_ENABLE();
#endif
#if defined(DCMI_RESET_PIN) || defined(DCMI_PWDN_PIN) || defined(DCMI_FSYNC_PIN)
/* Configure DCMI GPIO */
GPIO_InitTypeDef GPIO_InitStructure;
@ -400,6 +390,20 @@ void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef *hdma2d)
__HAL_RCC_DMA2D_CLK_DISABLE();
}
#if (OMV_HARDWARE_JPEG == 1)
void HAL_JPEG_MspInit(JPEG_HandleTypeDef *hjpeg)
{
__HAL_RCC_JPEG_CLK_ENABLE();
}
void HAL_JPEG_MspDeInit(JPEG_HandleTypeDef *hjpeg)
{
__HAL_RCC_JPEG_FORCE_RESET();
__HAL_RCC_JPEG_RELEASE_RESET();
__HAL_RCC_JPEG_CLK_DISABLE();
}
#endif
#if defined(OMV_LCD_CONTROLLER) && (!defined(OMV_DSI_CONTROLLER))
typedef struct {
GPIO_TypeDef *port;