The "GR-PEACH_Audio_Playback_7InchLCD_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.
Dependencies: GR-PEACH_video R_BSP TLV320_RBSP USBHost_custom
Fork of GR-PEACH_Audio_Playback_Sample by
disp_graphics.cpp
00001 /******************************************************************************* 00002 * DISCLAIMER 00003 * This software is supplied by Renesas Electronics Corporation and is only 00004 * intended for use with Renesas products. No other uses are authorized. This 00005 * software is owned by Renesas Electronics Corporation and is protected under 00006 * all applicable laws, including copyright laws. 00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING 00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT 00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. 00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS 00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE 00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR 00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE 00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 00016 * Renesas reserves the right, without notice, to make changes to this software 00017 * and to discontinue the availability of this software. By using this software, 00018 * you agree to the additional terms and conditions found by accessing the 00019 * following link: 00020 * http://www.renesas.com/disclaimer* 00021 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved. 00022 *******************************************************************************/ 00023 00024 #include "misratypes.h" 00025 #include "display.h" 00026 #include "disp_graphics.h" 00027 #include "img_tbl.h" 00028 00029 /*--- Macro definition ---*/ 00030 /* The number of bytes per pixel. */ 00031 #define BYTENUM_PER_PIXEL_ARGB8888 (4u) /* ARGB8888 : 1pixel = 4byte */ 00032 #define BYTENUM_PER_PIXEL_RGB888 (3u) /* RGB888 : 1pixel = 3byte */ 00033 00034 /* Alpha blend */ 00035 /* Minimum value of alpha blend. */ 00036 #define BLEND_MIN_VAL_ARGB8888 (0x00u) 00037 /* Maximum value of alpha blend. */ 00038 #define BLEND_MAX_VAL_ARGB8888 (0xFFu) 00039 /* In the case of this value, the background color is not blended. */ 00040 #define NOT_BLEND_VAL_ARGB8888 (BLEND_MAX_VAL_ARGB8888) 00041 00042 #define SHIFT_1BIT_SIZE (1u) 00043 #define SHIFT_1BYTE_SIZE (8u) 00044 #define SHIFT_2BYTE_SIZE (16u) 00045 #define SHIFT_3BYTE_SIZE (24u) 00046 00047 #define MASK_BIT_SIZE (0x01u) 00048 #define MASK_BYTE_SIZE (0xFFu) 00049 00050 #define MAX_LOOP_NUM (128) /* fail-safe processing. */ 00051 00052 #define COL_CLEAR (0x00000000u) 00053 00054 typedef uint32_t (*blend_func_t)(const uint32_t bg_col, const uint32_t fg_col); 00055 00056 static void set_bmp_rgb888(const dsp_tftlayer_t * const p_info, 00057 const int32_t start_x, const int32_t start_y, const dsp_bmpinf_t * const p_bmpinf); 00058 static void set_bmp_argb8888(const dsp_tftlayer_t * const p_info, const int32_t start_x, 00059 const int32_t start_y, const dsp_bmpinf_t * const p_bmpinf, const blend_func_t p_func); 00060 static uint32_t alpha_blend(const uint32_t bg_col, const uint32_t fg_col); 00061 static uint32_t get_fg_col(const uint32_t bg_col, const uint32_t fg_col); 00062 static void set_font(const dsp_tftlayer_t * const p_info, const int32_t start_x, 00063 const int32_t start_y, const uint32_t * const font_data, 00064 const uint32_t font_width, const uint32_t font_height); 00065 00066 void dsp_clear_all(const dsp_tftlayer_t * const p_info) 00067 { 00068 if (p_info != NULL) { 00069 dsp_clear_area(p_info, 0, 0, (int32_t)p_info->width, (int32_t)p_info->height); 00070 } 00071 } 00072 00073 void dsp_clear_area(const dsp_tftlayer_t * const p_info, const int32_t start_x, 00074 const int32_t start_y, const int32_t size_x, const int32_t size_y) 00075 { 00076 if (p_info != NULL) { 00077 dsp_fill_rect(p_info, start_x, start_y, size_x, size_y, COL_CLEAR); 00078 } 00079 } 00080 00081 void dsp_draw_picture(const dsp_tftlayer_t * const p_info, const int32_t start_x, 00082 const int32_t start_y, const int32_t pict_id, const int32_t pict_type) 00083 { 00084 int32_t type; 00085 00086 if ((p_info != NULL) && (pict_id >= 0) && (pict_id < DSP_IMG_TBL_SIZE)) { 00087 if (pict_type == DSP_IMG_FORM_AUTOSEL) { 00088 type = dsp_bitmap_tbl[pict_id].image_type; 00089 } else { 00090 type = pict_type; 00091 } 00092 00093 switch (type) { 00094 case DSP_IMG_FORM_RGB888: 00095 set_bmp_rgb888(p_info, start_x, start_y, &dsp_bitmap_tbl[pict_id]); 00096 break; 00097 case DSP_IMG_FORM_ARGB8888_NO_BLEND: 00098 set_bmp_argb8888(p_info, start_x, start_y, &dsp_bitmap_tbl[pict_id], &get_fg_col); 00099 break; 00100 case DSP_IMG_FORM_ARGB8888: 00101 default: 00102 set_bmp_argb8888(p_info, start_x, start_y, &dsp_bitmap_tbl[pict_id], &alpha_blend); 00103 break; 00104 } 00105 } 00106 return; 00107 } 00108 00109 void dsp_fill_rect(const dsp_tftlayer_t * const p_info, const int32_t start_x, 00110 const int32_t start_y, const int32_t size_x, const int32_t size_y, const uint32_t fg_col) 00111 { 00112 uint32_t *p_buff; /* Pointer to VRAM. */ 00113 uint32_t stride_pix; /* The horizontal number of bytes in VRAM. */ 00114 int32_t pos_x; /* The X position in VRAM. */ 00115 int32_t pos_y; /* The Y position in VRAM. */ 00116 00117 if (p_info != NULL) { 00118 /* Calculates the horizontal number of bytes. */ 00119 /* The horizontal number of bytes is a multiple of 4. */ 00120 /* VRAM */ 00121 stride_pix = p_info->stride / sizeof(uint32_t); 00122 for (pos_y = start_y; pos_y < (start_y + size_y); pos_y++) { 00123 if ((pos_y >= 0) && (pos_y < (int32_t)p_info->height)) { 00124 /* Sets the position of (0, pos_y) in VRAM. */ 00125 p_buff = &p_info->p_back_buf[stride_pix * (uint32_t)pos_y]; 00126 for (pos_x = start_x; pos_x < (start_x + size_x); pos_x++) { 00127 if((pos_x >= 0) && (pos_x < (int32_t)p_info->width)) { 00128 p_buff[pos_x] = fg_col; 00129 } 00130 } 00131 } 00132 } 00133 } 00134 return; 00135 } 00136 00137 void dsp_draw_text30x34(const dsp_tftlayer_t * const p_info, const int32_t start_x, 00138 const int32_t start_y, const char_t * const p_str) 00139 { 00140 const uint32_t *p_font_data; 00141 int32_t str_index; 00142 int32_t i; 00143 int32_t pos_x; 00144 const int32_t pos_y = start_y; 00145 const uint32_t pos_x_offset = DSP_IMG_WS_FONT30X34; 00146 uint32_t chr_code; 00147 const dsp_fntinf_t *p_font_info; 00148 00149 if ((p_info != NULL) && (p_str != NULL)) { 00150 str_index = 0; 00151 pos_x = start_x; 00152 while ((str_index < MAX_LOOP_NUM) && ((int32_t)p_str[str_index] != '\0')) { 00153 chr_code = (uint32_t)p_str[str_index]; 00154 for (i = 0; i < (int32_t)(sizeof(dsp_img_fonttbl30x34)/sizeof(dsp_img_fonttbl30x34[0])); i++) { 00155 p_font_info = &dsp_img_fonttbl30x34[i]; 00156 if ((chr_code >= p_font_info->start_char) && (chr_code <= p_font_info->end_char)) { 00157 p_font_data = &p_font_info->p_font[(chr_code - p_font_info->start_char) * DSP_IMG_HS_FONT30X34]; 00158 set_font(p_info, pos_x, pos_y, p_font_data, DSP_IMG_WS_FONT30X34, DSP_IMG_HS_FONT30X34); 00159 } 00160 } 00161 pos_x += (int32_t)pos_x_offset; 00162 str_index ++; 00163 } 00164 } 00165 } 00166 00167 void dsp_draw_text15x17(const dsp_tftlayer_t * const p_info, const int32_t start_x, 00168 const int32_t start_y, const char_t * const p_str) 00169 { 00170 const uint32_t *p_font_data; 00171 int32_t str_index; 00172 int32_t i; 00173 int32_t pos_x; 00174 const int32_t pos_y = start_y; 00175 const uint32_t pos_x_offset = DSP_IMG_WS_FONT15X17; 00176 uint32_t chr_code; 00177 const dsp_fntinf_t *p_font_info; 00178 00179 if ((p_info != NULL) && (p_str != NULL)) { 00180 str_index = 0; 00181 pos_x = start_x; 00182 while ((str_index < MAX_LOOP_NUM) && ((int32_t)p_str[str_index] != '\0')) { 00183 chr_code = (uint32_t)p_str[str_index]; 00184 for (i = 0; i < (int32_t)(sizeof(dsp_img_fonttbl15x17)/sizeof(dsp_img_fonttbl15x17[0])); i++) { 00185 p_font_info = &dsp_img_fonttbl15x17[i]; 00186 if ((chr_code >= p_font_info->start_char) && (chr_code <= p_font_info->end_char)) { 00187 p_font_data = &p_font_info->p_font[(chr_code - p_font_info->start_char) * DSP_IMG_HS_FONT15X17]; 00188 set_font(p_info, pos_x, pos_y, p_font_data, DSP_IMG_WS_FONT15X17, DSP_IMG_HS_FONT15X17); 00189 } 00190 } 00191 pos_x += (int32_t)pos_x_offset; 00192 str_index ++; 00193 } 00194 } 00195 } 00196 00197 /** Draws BMP image of the RGB888 format in VRAM. 00198 * 00199 * @param p_info Pointer to VRAM structure 00200 * @param start_x Display position X of BMP image 00201 * @param start_y Display position Y of BMP image 00202 * @param p_bmpinf Pointer to information of BMP image 00203 */ 00204 static void set_bmp_rgb888(const dsp_tftlayer_t * const p_info, 00205 const int32_t start_x, const int32_t start_y, const dsp_bmpinf_t * const p_bmpinf) 00206 { 00207 uint32_t *p_buff; /* Pointer to VRAM. */ 00208 uint32_t stride_pix; /* The horizontal number of bytes in VRAM. */ 00209 int32_t pos_x; /* The X position in VRAM. */ 00210 int32_t pos_y; /* The Y position in VRAM. */ 00211 const uint8_t *p_img; /* Pointer to BMP image. */ 00212 uint32_t img_h_byte; /* The horizontal number of bytes in the BMP image. */ 00213 uint32_t img_index; 00214 uint32_t cnt; 00215 uint32_t shift_num; 00216 uint32_t col_data; 00217 00218 if ((p_info != NULL) && (p_bmpinf != NULL)) { 00219 /* Calculates the horizontal number of bytes. */ 00220 /* The horizontal number of bytes is a multiple of 4. */ 00221 /* VRAM */ 00222 stride_pix = p_info->stride / sizeof(uint32_t); 00223 /* BMP image */ 00224 img_h_byte = (((BYTENUM_PER_PIXEL_RGB888 * p_bmpinf->size_x) + 00225 (sizeof(uint32_t) - 1u)) / sizeof(uint32_t)) * sizeof(uint32_t); 00226 for (pos_y = start_y; pos_y < (start_y + (int32_t)p_bmpinf->size_y); pos_y++) { 00227 if ((pos_y >= 0) && (pos_y < (int32_t)p_info->height)) { 00228 /* Sets the position of (0, pos_y) in VRAM. */ 00229 p_buff = &p_info->p_back_buf[stride_pix * (uint32_t)pos_y]; 00230 /* Sets the position of (start_x, pos_y) in BMP image. */ 00231 p_img = &p_bmpinf->p_image[img_h_byte * ((p_bmpinf->size_y - 1u) - (uint32_t)(pos_y - start_y))]; 00232 img_index = 0u; 00233 for (pos_x = start_x; pos_x < (start_x + (int32_t)p_bmpinf->size_x); pos_x++) { 00234 if((pos_x >= 0) && (pos_x < (int32_t)p_info->width)) { 00235 col_data = BLEND_MAX_VAL_ARGB8888 << SHIFT_3BYTE_SIZE; 00236 shift_num = 0u; 00237 for (cnt = 0u; cnt < BYTENUM_PER_PIXEL_RGB888; cnt++) { 00238 col_data |= ((uint32_t)p_img[img_index + cnt] << shift_num); 00239 shift_num += SHIFT_1BYTE_SIZE; 00240 } 00241 p_buff[pos_x] = col_data; 00242 } 00243 img_index += BYTENUM_PER_PIXEL_RGB888; 00244 } 00245 } 00246 } 00247 } 00248 } 00249 00250 /** Draws BMP image of the ARGB8888 format in VRAM. 00251 * 00252 * @param p_info Pointer to VRAM structure 00253 * @param start_x Display position X of BMP image 00254 * @param start_y Display position Y of BMP image 00255 * @param p_bmpinf Pointer to information of BMP image 00256 * @param p_func Pointer to the data blend function 00257 */ 00258 static void set_bmp_argb8888(const dsp_tftlayer_t * const p_info, const int32_t start_x, 00259 const int32_t start_y, const dsp_bmpinf_t * const p_bmpinf, const blend_func_t p_func) 00260 { 00261 uint32_t *p_buff; /* Pointer to VRAM. */ 00262 uint32_t stride_pix; /* The horizontal number of bytes in VRAM. */ 00263 int32_t pos_x; /* The X position in VRAM. */ 00264 int32_t pos_y; /* The Y position in VRAM. */ 00265 const uint8_t *p_img; /* Pointer to BMP image. */ 00266 uint32_t img_h_byte; /* The horizontal number of bytes in the BMP image. */ 00267 uint32_t img_index; 00268 uint32_t cnt; 00269 uint32_t shift_num; 00270 uint32_t col_data; 00271 00272 if ((p_info != NULL) && (p_bmpinf != NULL) && (p_func != NULL)) { 00273 /* Calculates the horizontal number of bytes. */ 00274 /* The horizontal number of bytes is a multiple of 4. */ 00275 /* VRAM */ 00276 stride_pix = p_info->stride / sizeof(uint32_t); 00277 /* BMP image */ 00278 img_h_byte = BYTENUM_PER_PIXEL_ARGB8888 * p_bmpinf->size_x; 00279 for (pos_y = start_y; pos_y < (start_y + (int32_t)p_bmpinf->size_y); pos_y++) { 00280 if ((pos_y >= 0) && (pos_y < (int32_t)p_info->height)) { 00281 /* Sets the position of (0, pos_y) in VRAM. */ 00282 p_buff = &p_info->p_back_buf[stride_pix * (uint32_t)pos_y]; 00283 /* Sets the position of (start_x, pos_y) in BMP image. */ 00284 p_img = &p_bmpinf->p_image[img_h_byte * ((p_bmpinf->size_y - 1u) - (uint32_t)(pos_y - start_y))]; 00285 img_index = 0u; 00286 for (pos_x = start_x; pos_x < (start_x + (int32_t)p_bmpinf->size_x); pos_x++) { 00287 if((pos_x >= 0) && (pos_x < (int32_t)p_info->width)) { 00288 col_data = 0; 00289 shift_num = 0u; 00290 for (cnt = 0; cnt < BYTENUM_PER_PIXEL_ARGB8888; cnt++) { 00291 col_data |= ((uint32_t)p_img[img_index + cnt] << shift_num); 00292 shift_num += SHIFT_1BYTE_SIZE; 00293 } 00294 p_buff[pos_x] = p_func(p_buff[pos_x],col_data); 00295 } 00296 img_index += BYTENUM_PER_PIXEL_ARGB8888; 00297 } 00298 } 00299 } 00300 } 00301 } 00302 00303 /** Blends foreground color with background color. 00304 * 00305 * @param bg_col Background color 00306 * @param fg_col Foreground color 00307 */ 00308 static uint32_t alpha_blend(const uint32_t bg_col, const uint32_t fg_col) 00309 { 00310 uint32_t ret_col; 00311 /* Blended data */ 00312 uint32_t new_b; 00313 uint32_t new_g; 00314 uint32_t new_r; 00315 uint32_t new_a; 00316 /* Background data */ 00317 uint32_t bg_b; 00318 uint32_t bg_g; 00319 uint32_t bg_r; 00320 uint32_t bg_a; 00321 /* Foreground data */ 00322 uint32_t fg_b; 00323 uint32_t fg_g; 00324 uint32_t fg_r; 00325 const uint32_t fg_a = (fg_col >> SHIFT_3BYTE_SIZE) & MASK_BYTE_SIZE; 00326 00327 if (fg_a == BLEND_MIN_VAL_ARGB8888) { 00328 /* The data is not blended. A background data is used. */ 00329 ret_col = bg_col; 00330 } else if (fg_a == BLEND_MAX_VAL_ARGB8888) { 00331 /* The data is not blended. A foreground data is used. */ 00332 ret_col = fg_col; 00333 } else { 00334 /* A background data and a foreground data is blended. */ 00335 /* Foreground data */ 00336 fg_b = (fg_col ) & MASK_BYTE_SIZE; 00337 fg_g = (fg_col >> SHIFT_1BYTE_SIZE) & MASK_BYTE_SIZE; 00338 fg_r = (fg_col >> SHIFT_2BYTE_SIZE) & MASK_BYTE_SIZE; 00339 00340 /* Background data */ 00341 bg_b = (bg_col ) & MASK_BYTE_SIZE; 00342 bg_g = (bg_col >> SHIFT_1BYTE_SIZE) & MASK_BYTE_SIZE; 00343 bg_r = (bg_col >> SHIFT_2BYTE_SIZE) & MASK_BYTE_SIZE; 00344 bg_a = (~fg_a ) & MASK_BYTE_SIZE; 00345 00346 /* Blended data */ 00347 /* The division calculation by 255 needs the long processing time. */ 00348 /* Therefore we execute the division calculation by 256 using shift calculation. */ 00349 /* An error in calculation occurs to divide it by 256, */ 00350 /* but an error is maximum 1 very small. */ 00351 new_b = ((fg_b * fg_a) + (bg_b * bg_a)) >> SHIFT_1BYTE_SIZE; 00352 new_g = ((fg_g * fg_a) + (bg_g * bg_a)) >> SHIFT_1BYTE_SIZE; 00353 new_r = ((fg_r * fg_a) + (bg_r * bg_a)) >> SHIFT_1BYTE_SIZE; 00354 new_a = fg_a; 00355 00356 ret_col = new_b; 00357 ret_col |= (new_g << SHIFT_1BYTE_SIZE); 00358 ret_col |= (new_r << SHIFT_2BYTE_SIZE); 00359 ret_col |= (new_a << SHIFT_3BYTE_SIZE); 00360 } 00361 return ret_col; 00362 } 00363 00364 /** Gets the foreground color. 00365 * 00366 * @param bg_col Background color 00367 * @param fg_col Foreground color 00368 */ 00369 static uint32_t get_fg_col(const uint32_t bg_col, const uint32_t fg_col) 00370 { 00371 UNUSED_ARG(bg_col); 00372 return fg_col; 00373 } 00374 00375 /** Draws font image in VRAM. 00376 * 00377 * @param p_info Pointer to VRAM structure 00378 * @param start_x Display position X of font image 00379 * @param start_y Display position Y of font image 00380 * @param font_data Pointer to font data 00381 * @param font_width The width of font data 00382 * @param font_height The height of font data 00383 */ 00384 static void set_font(const dsp_tftlayer_t * const p_info, const int32_t start_x, 00385 const int32_t start_y, const uint32_t * const font_data, 00386 const uint32_t font_width, const uint32_t font_height) 00387 { 00388 uint32_t *p_buff; 00389 uint32_t data_val; 00390 uint32_t stride_pix; 00391 int32_t pos_x; 00392 int32_t pos_y; 00393 00394 if ((p_info != NULL) && (font_data != NULL)) { 00395 /* Calculates the horizontal number of bytes. */ 00396 /* The horizontal number of bytes is a multiple of 4. */ 00397 stride_pix = p_info->stride / sizeof(uint32_t); 00398 for (pos_y = start_y; pos_y < (start_y + (int32_t)font_height); pos_y++) { 00399 if ((pos_y >= 0) && (pos_y < (int32_t)p_info->height)) { 00400 /* Sets the position of (0, pos_y) in VRAM. */ 00401 p_buff = &p_info->p_back_buf[stride_pix * (uint32_t)pos_y]; 00402 /* Sets the position of (start_x, pos_y) in font image. */ 00403 data_val = font_data[pos_y - start_y]; 00404 for (pos_x = start_x; pos_x < (start_x + (int32_t)font_width); pos_x++) { 00405 if ((data_val & MASK_BIT_SIZE) == DSP_IMG_FONT_FG_VAL) { 00406 if((pos_x >= 0) && (pos_x < (int32_t)p_info->width)) { 00407 p_buff[pos_x] = DSP_IMG_FONT_FG_COL; 00408 } 00409 } 00410 data_val >>= SHIFT_1BIT_SIZE; 00411 } 00412 } 00413 } 00414 } 00415 }
Generated on Tue Jul 12 2022 19:32:28 by 1.7.2