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

Dependencies:   GR-PEACH_video GraphicsFramework R_BSP LCD_shield_config

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rga_func.cpp Source File

rga_func.cpp

00001 /*
00002 Permission is hereby granted, free of charge, to any person obtaining a copy
00003 of this software and associated documentation files (the "Software"), to deal
00004 in the Software without restriction, including without limitation the rights
00005 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00006 copies of the Software, and to permit persons to whom the Software is
00007 furnished to do so, subject to the following conditions:
00008 
00009 The above copyright notice and this permission notice shall be included in
00010 all copies or substantial portions of the Software.
00011 
00012 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00013 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00014 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00015 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00016 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00018 THE SOFTWARE.
00019 */
00020 
00021 #include "mbed.h"
00022 #include "rga_func.h"
00023 #include "Images/BinaryImage_RZ_A1H.h"
00024 
00025 #define ZOOM_SRC_CENTER_X                   (IMAGE_WIDTH_ZOOM_FUNC / 2)
00026 #define ZOOM_SRC_CENTER_Y                   (IMAGE_HEIGHT_ZOOM_FUNC / 2)
00027 
00028 #define CRYSTAL_DIAMETER                    (93)
00029 
00030 Canvas2D_ContextClass canvas2d;
00031 
00032 static animation_timing_function_t* accelerator;
00033 
00034 void Set_RGAObject(frame_buffer_t* frmbuf_info) {
00035     errnum_t err;
00036     Canvas2D_ContextConfigClass config;
00037 
00038     config.frame_buffer = frmbuf_info;
00039     canvas2d = R_RGA_New_Canvas2D_ContextClass(config);
00040     err = R_OSPL_GetErrNum();
00041     if (err != 0) {
00042         printf("Line %d, error %d\n", __LINE__, err);
00043         while (1);
00044     }
00045 }
00046 
00047 void RGA_Func_DrawTopScreen(frame_buffer_t* frmbuf_info) {
00048     /* Clear */
00049     canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
00050 
00051     /* Draw a image */
00052     canvas2d.drawImage(TopScrn_jpg_File, 0, 0);
00053 
00054     /* Complete drawing */
00055     R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
00056 }
00057 
00058 void RGA_Func_DrawRectangle(frame_buffer_t* frmbuf_info, draw_rectangle_pos_t * pos, int pos_num) {
00059     int cnt;
00060 
00061     /* Clear */
00062     canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
00063 
00064     /* Draw description */
00065     canvas2d.drawImage(decs_swipe_jpg_File, 230, 400);
00066 
00067     /* Draw rectangle */
00068     for (cnt = 0; cnt < pos_num; cnt++) {
00069         canvas2d.fillStyle = pos->style;
00070         canvas2d.fillRect(pos->x, pos->y, pos->w, pos->h);
00071         pos++;
00072     }
00073 
00074     /* Draw return button */
00075     canvas2d.drawImage(RetBtn_jpg_File, 640, 10);
00076 
00077     /* Complete drawing */
00078     R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
00079 }
00080 
00081 void RGA_Func_DrawImage(frame_buffer_t* frmbuf_info, int x, int y) {
00082     int draw_pos_x = x - (CRYSTAL_DIAMETER / 2);
00083     int draw_pos_y = y - (CRYSTAL_DIAMETER / 2);
00084 
00085     /* Clear */
00086     canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
00087 
00088     /* Draw description */
00089     canvas2d.drawImage(decs_swipe_jpg_File, 230, 400);
00090 
00091     /* Draw the first image */
00092     canvas2d.drawImage(Flower_jpg_File, 100, 100);
00093 
00094     /* Draw the second image */
00095     if ((frmbuf_info->pixel_format == PIXEL_FORMAT_ARGB8888) || (frmbuf_info->pixel_format == PIXEL_FORMAT_XRGB8888)) {
00096         canvas2d.drawImage(Crystal_png_ARGB8888, draw_pos_x, draw_pos_y);
00097     } else if (frmbuf_info->pixel_format != PIXEL_FORMAT_YUV422) {
00098         canvas2d.drawImage(Crystal_png_ARGB4444, draw_pos_x, draw_pos_y);
00099     } else {
00100         canvas2d.drawImage(Crystal_png_File, draw_pos_x, draw_pos_y);
00101     }
00102 
00103     /* Draw return button */
00104     canvas2d.drawImage(RetBtn_jpg_File, 640, 10);
00105 
00106     /* Complete drawing */
00107     R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
00108 }
00109 
00110 void RGA_Func_Dissolve(frame_buffer_t* frmbuf_info, float32_t global_alpha) {
00111     /* Dissolve = Fade Out + Fade In */
00112     /* Clear */
00113     canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
00114 
00115     /* Draw description */
00116     canvas2d.drawImage(decs_swipe_side_jpg_File, 140, 400);
00117 
00118     /* fade Out */
00119     canvas2d.globalAlpha = 1.0f - global_alpha;
00120     canvas2d.drawImage(Flower_jpg_File, 100, 100);
00121 
00122     /* fade In */
00123     canvas2d.globalAlpha = global_alpha;
00124     canvas2d.drawImage(Landscape_jpg_File, 100, 100);
00125 
00126     canvas2d.globalAlpha = 1.0f;
00127 
00128     /* Draw return button */
00129     canvas2d.drawImage(RetBtn_jpg_File, 640, 10);
00130 
00131     /* Complete drawing */
00132     R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
00133 }
00134 
00135 void RGA_Func_Scroll(frame_buffer_t* frmbuf_info, int src_width_pos) {
00136     /* Clear */
00137     canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
00138 
00139     /* Draw description */
00140     canvas2d.drawImage(decs_swipe_side_jpg_File, 140, 400);
00141 
00142     /* Scroll from left to right */
00143     canvas2d.drawImage(Landscape_wide_jpg_File,
00144                         /* src */       src_width_pos, 25, IMG_DRAW_WIDTH, IMG_DRAW_HEIGHT,
00145                         /* dst */       100, 100, IMG_DRAW_WIDTH, IMG_DRAW_HEIGHT);
00146 
00147     /* Draw return button */
00148     canvas2d.drawImage(RetBtn_jpg_File, 640, 10);
00149 
00150     /* Complete drawing */
00151     R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
00152 }
00153 
00154 void RGA_Func_Zoom(frame_buffer_t* frmbuf_info, int src_height_pos) {
00155     /* Clear */
00156     canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
00157 
00158     /* Draw description */
00159     canvas2d.drawImage(decs_swipe_side_jpg_File, 140, 400);
00160 
00161     /* Zoom out */
00162     canvas2d.drawImage(Landscape_wide_jpg_File,
00163                         /* src X */     ZOOM_SRC_CENTER_X - (src_height_pos * IMG_DRAW_WIDTH / IMG_DRAW_HEIGHT),
00164                         /* src Y */     ZOOM_SRC_CENTER_Y - src_height_pos,
00165                         /* src W */     src_height_pos * 2 * IMG_DRAW_WIDTH / IMG_DRAW_HEIGHT,
00166                         /* src H */     src_height_pos * 2,
00167                         /* dst   */     100, 100, IMG_DRAW_WIDTH, IMG_DRAW_HEIGHT);
00168 
00169     /* Draw return button */
00170     canvas2d.drawImage(RetBtn_jpg_File, 640, 10);
00171 
00172     /* Complete drawing */
00173     R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
00174 }
00175 
00176 void RGA_Func_Rotation(frame_buffer_t* frmbuf_info, graphics_matrix_float_t image_angle) {
00177     /* Rotate the image to the right */
00178     /* Clear */
00179     canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
00180 
00181     /* Draw description */
00182     canvas2d.drawImage(decs_swipe_side_jpg_File, 140, 400);
00183 
00184     /* Move to drawing position */
00185     canvas2d.translate((100 + (IMG_DRAW_WIDTH / 2)), (100 + (IMG_DRAW_HEIGHT / 2)));
00186 
00187     /* Rotate */
00188     canvas2d.rotate(image_angle * (3.14159 / 180));
00189 
00190     /* Move to center to rotate */
00191     canvas2d.translate((-IMG_DRAW_WIDTH / 2), (-IMG_DRAW_HEIGHT / 2));
00192     canvas2d.drawImage(Flower_jpg_File, 0, 0);
00193     canvas2d.setTransform(1, 0, 0, 1, 0, 0);
00194 
00195     /* Draw return button */
00196     canvas2d.drawImage(RetBtn_jpg_File, 640, 10);
00197 
00198     /* Complete drawing */
00199     R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
00200 }
00201 
00202 void RGA_Func_Accelerate(frame_buffer_t* frmbuf_info, int animation_timing, float32_t relative_pos) {
00203     /* Do accelerated motion from right to left */
00204     int position;
00205 
00206     /* Clear */
00207     canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
00208 
00209     if (relative_pos == 0.0f) {
00210         switch (animation_timing) {
00211             case ANIMATION_TIMING_EASE:
00212                 R_Get_AnimationTimingFunction("ease", &accelerator);
00213                 break;
00214             case ANIMATION_TIMING_LINEAR:
00215                 R_Get_AnimationTimingFunction("linear", &accelerator);
00216                 break;
00217             case ANIMATION_TIMING_EASE_IN:
00218                 R_Get_AnimationTimingFunction("ease-in", &accelerator);
00219                 break;
00220             case ANIMATION_TIMING_EASE_OUT:
00221                 R_Get_AnimationTimingFunction("ease-out", &accelerator);
00222                 break;
00223             case ANIMATION_TIMING_EASE_IN_OUT:
00224             default:
00225                 R_Get_AnimationTimingFunction("ease-in-out", &accelerator);
00226                 break;
00227         }
00228     }
00229 
00230     /* Draw rectangle */
00231     canvas2d.fillStyle = "#0000FF";  /* blue */
00232     switch (animation_timing) {
00233         case ANIMATION_TIMING_EASE:
00234             canvas2d.fillRect(17, 420, 136, 10);
00235             break;
00236         case ANIMATION_TIMING_LINEAR:
00237             canvas2d.fillRect(173, 420, 136, 10);
00238             break;
00239         case ANIMATION_TIMING_EASE_IN:
00240             canvas2d.fillRect(330, 420, 136, 10);
00241             break;
00242         case ANIMATION_TIMING_EASE_OUT:
00243             canvas2d.fillRect(487, 420, 136, 10);
00244             break;
00245         case ANIMATION_TIMING_EASE_IN_OUT:
00246         default:
00247             canvas2d.fillRect(644, 420, 136, 10);
00248             break;
00249     }
00250 
00251     /* Draw button */
00252     canvas2d.drawImage(animetion_timing_jpg_File, 0, 370);
00253 
00254     position = R_ANIMATION_TIMING_FUNCTION_GetValue(accelerator, relative_pos, 550.0f, 10.0f);
00255     canvas2d.drawImage(Flower_jpg_File, position, 100);
00256 
00257     /* Draw return button */
00258     canvas2d.drawImage(RetBtn_jpg_File, 640, 10);
00259 
00260     /* Complete drawing */
00261     R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
00262 }