Image rotation Sample. This program uses GraphicsFramework library and L3GD20 sensor.

Dependencies:   GR-PEACH_video GraphicsFramework L3GD20 R_BSP mbed-rtos mbed

Fork of RGA_HelloWorld by Renesas

About L3GD20

L3GD20 is a 3-axis gyroscope sensor and can be controlled by using theI2C.

About wiring

SensorGR-PEACH
VDD3.3V
SCLD15
SDAD14
SA03.3V
CS3.3V
GNDGND
Committer:
1050186
Date:
Wed Jan 20 08:09:15 2016 +0000
Revision:
1:a07212e32dcb
Parent:
0:84e4649e7707
Child:
3:841987280a7f
Modify macro definition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
1050186 0:84e4649e7707 1 /*
1050186 0:84e4649e7707 2 Permission is hereby granted, free of charge, to any person obtaining a copy
1050186 0:84e4649e7707 3 of this software and associated documentation files (the "Software"), to deal
1050186 0:84e4649e7707 4 in the Software without restriction, including without limitation the rights
1050186 0:84e4649e7707 5 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1050186 0:84e4649e7707 6 copies of the Software, and to permit persons to whom the Software is
1050186 0:84e4649e7707 7 furnished to do so, subject to the following conditions:
1050186 0:84e4649e7707 8
1050186 0:84e4649e7707 9 The above copyright notice and this permission notice shall be included in
1050186 0:84e4649e7707 10 all copies or substantial portions of the Software.
1050186 0:84e4649e7707 11
1050186 0:84e4649e7707 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1050186 0:84e4649e7707 13 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1050186 0:84e4649e7707 14 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1050186 0:84e4649e7707 15 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1050186 0:84e4649e7707 16 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1050186 0:84e4649e7707 17 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1050186 0:84e4649e7707 18 THE SOFTWARE.
1050186 0:84e4649e7707 19 */
1050186 0:84e4649e7707 20
1050186 0:84e4649e7707 21 #include "mbed.h"
1050186 0:84e4649e7707 22 #include "rga_func.h"
1050186 0:84e4649e7707 23 #include "Images/BinaryImage_RZ_A1H.h"
1050186 0:84e4649e7707 24
1050186 1:a07212e32dcb 25 #define ZOOM_SRC_CENTER_X (IMAGE_WIDTH_ZOOM_FUNC / 2)
1050186 1:a07212e32dcb 26 #define ZOOM_SRC_CENTER_Y (IMAGE_HEIGHT_ZOOM_FUNC / 2)
1050186 0:84e4649e7707 27
1050186 0:84e4649e7707 28 Canvas2D_ContextClass canvas2d;
1050186 0:84e4649e7707 29
1050186 0:84e4649e7707 30 static animation_timing_function_t* accelerator;
1050186 0:84e4649e7707 31
1050186 0:84e4649e7707 32 void Set_RGAObject(frame_buffer_t* frmbuf_info) {
1050186 0:84e4649e7707 33 errnum_t err;
1050186 0:84e4649e7707 34 Canvas2D_ContextConfigClass config;
1050186 0:84e4649e7707 35
1050186 0:84e4649e7707 36 config.frame_buffer = frmbuf_info;
1050186 0:84e4649e7707 37 canvas2d = R_RGA_New_Canvas2D_ContextClass(config);
1050186 0:84e4649e7707 38 err = R_OSPL_GetErrNum();
1050186 0:84e4649e7707 39 if (err != 0) {
1050186 0:84e4649e7707 40 printf("Line %d, error %d\n", __LINE__, err);
1050186 0:84e4649e7707 41 while (1);
1050186 0:84e4649e7707 42 }
1050186 0:84e4649e7707 43 }
1050186 0:84e4649e7707 44
1050186 0:84e4649e7707 45 void Get_AnimationTiming(char_t *timing_name) {
1050186 0:84e4649e7707 46 R_Get_AnimationTimingFunction(timing_name, &accelerator);
1050186 0:84e4649e7707 47 }
1050186 0:84e4649e7707 48
1050186 0:84e4649e7707 49 void RGA_Func_ClrScreen(frame_buffer_t* frmbuf_info) {
1050186 0:84e4649e7707 50 /* Clear the display in white */
1050186 0:84e4649e7707 51 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
1050186 0:84e4649e7707 52 }
1050186 0:84e4649e7707 53
1050186 0:84e4649e7707 54 void RGA_Func_DrawTopScreen(frame_buffer_t* frmbuf_info) {
1050186 0:84e4649e7707 55 /* Draw a image */
1050186 0:84e4649e7707 56 canvas2d.drawImage(TopScrn_jpg_File, 0, 0);
1050186 0:84e4649e7707 57
1050186 0:84e4649e7707 58 /* Complete drawing */
1050186 0:84e4649e7707 59 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
1050186 0:84e4649e7707 60 }
1050186 0:84e4649e7707 61
1050186 0:84e4649e7707 62 void RGA_Func_DrawReturnButton(frame_buffer_t* frmbuf_info) {
1050186 0:84e4649e7707 63 /* Draw a image */
1050186 0:84e4649e7707 64 canvas2d.drawImage(RetBtn_jpg_File, 640, 10);
1050186 0:84e4649e7707 65
1050186 0:84e4649e7707 66 /* Complete drawing */
1050186 0:84e4649e7707 67 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
1050186 0:84e4649e7707 68 }
1050186 0:84e4649e7707 69
1050186 0:84e4649e7707 70 void RGA_Func_DrawRectangle(frame_buffer_t* frmbuf_info) {
1050186 0:84e4649e7707 71 /* Clear */
1050186 0:84e4649e7707 72 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
1050186 0:84e4649e7707 73 /* Draw red rectangle */
1050186 0:84e4649e7707 74 canvas2d.fillStyle = "#FF0000";
1050186 0:84e4649e7707 75 canvas2d.fillRect(0, 0, 160, 240);
1050186 0:84e4649e7707 76 canvas2d.fillRect(160, 240, 160, 240);
1050186 0:84e4649e7707 77 /* Draw green rectangle */
1050186 0:84e4649e7707 78 canvas2d.fillStyle = "#00FF00";
1050186 0:84e4649e7707 79 canvas2d.fillRect(160, 0, 160, 240);
1050186 0:84e4649e7707 80 canvas2d.fillRect(320, 240, 160, 240);
1050186 0:84e4649e7707 81 /* Draw blue rectangle */
1050186 0:84e4649e7707 82 canvas2d.fillStyle = "#0000FF";
1050186 0:84e4649e7707 83 canvas2d.fillRect(320, 0, 160, 240);
1050186 0:84e4649e7707 84 canvas2d.fillRect(480, 240, 160, 240);
1050186 0:84e4649e7707 85 /* Draw black rectangle */
1050186 0:84e4649e7707 86 canvas2d.fillStyle = "#000000";
1050186 0:84e4649e7707 87 canvas2d.fillRect(480, 0, 160, 240);
1050186 0:84e4649e7707 88 canvas2d.fillRect(640, 240, 160, 240);
1050186 0:84e4649e7707 89 /* Draw write rectangle */
1050186 0:84e4649e7707 90 canvas2d.fillStyle = "#FFFFFF";
1050186 0:84e4649e7707 91 canvas2d.fillRect(640, 0, 160, 240);
1050186 0:84e4649e7707 92 canvas2d.fillRect(0, 240, 160, 240);
1050186 0:84e4649e7707 93
1050186 0:84e4649e7707 94 /* Complete drawing */
1050186 0:84e4649e7707 95 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
1050186 0:84e4649e7707 96 }
1050186 0:84e4649e7707 97
1050186 0:84e4649e7707 98 void RGA_Func_DrawImage(frame_buffer_t* frmbuf_info) {
1050186 0:84e4649e7707 99 /* Clear */
1050186 0:84e4649e7707 100 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
1050186 0:84e4649e7707 101 /* Draw the first image */
1050186 0:84e4649e7707 102 canvas2d.drawImage(Flower_jpg_File, 100, 100);
1050186 0:84e4649e7707 103 /* Draw the second image */
1050186 0:84e4649e7707 104 if ((frmbuf_info->pixel_format == PIXEL_FORMAT_ARGB8888) || (frmbuf_info->pixel_format == PIXEL_FORMAT_XRGB8888)) {
1050186 0:84e4649e7707 105 canvas2d.drawImage(Crystal_png_ARGB8888, 280, 70);
1050186 0:84e4649e7707 106 } else if (frmbuf_info->pixel_format != PIXEL_FORMAT_YUV422) {
1050186 0:84e4649e7707 107 canvas2d.drawImage(Crystal_png_ARGB4444, 280, 70);
1050186 0:84e4649e7707 108 } else {
1050186 0:84e4649e7707 109 canvas2d.drawImage(Crystal_png_File, 280, 70);
1050186 0:84e4649e7707 110 }
1050186 0:84e4649e7707 111
1050186 0:84e4649e7707 112 /* Complete drawing */
1050186 0:84e4649e7707 113 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
1050186 0:84e4649e7707 114 }
1050186 0:84e4649e7707 115
1050186 0:84e4649e7707 116 void RGA_Func_Dissolve(frame_buffer_t* frmbuf_info, float32_t global_alpha) {
1050186 0:84e4649e7707 117 /* Dissolve = Fade Out + Fade In */
1050186 0:84e4649e7707 118 /* Clear */
1050186 0:84e4649e7707 119 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
1050186 0:84e4649e7707 120 /* fade Out */
1050186 0:84e4649e7707 121 canvas2d.globalAlpha = 1.0f - global_alpha;
1050186 0:84e4649e7707 122 canvas2d.drawImage(Flower_jpg_File, 100, 100);
1050186 0:84e4649e7707 123 /* fade In */
1050186 0:84e4649e7707 124 canvas2d.globalAlpha = global_alpha;
1050186 0:84e4649e7707 125 canvas2d.drawImage(Landscape_jpg_File, 100, 100);
1050186 0:84e4649e7707 126
1050186 0:84e4649e7707 127 canvas2d.globalAlpha = 1.0f;
1050186 0:84e4649e7707 128 /* Complete drawing */
1050186 0:84e4649e7707 129 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
1050186 0:84e4649e7707 130 }
1050186 0:84e4649e7707 131
1050186 0:84e4649e7707 132 void RGA_Func_Scroll(frame_buffer_t* frmbuf_info, int src_width_pos) {
1050186 0:84e4649e7707 133 /* Clear */
1050186 0:84e4649e7707 134 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
1050186 0:84e4649e7707 135 /* Scroll from left to right */
1050186 0:84e4649e7707 136 canvas2d.drawImage(Landscape_wide_jpg_File,
1050186 0:84e4649e7707 137 /* src */ src_width_pos, 25, IMG_DRAW_WIDTH, IMG_DRAW_HEIGHT,
1050186 0:84e4649e7707 138 /* dst */ 100, 100, IMG_DRAW_WIDTH, IMG_DRAW_HEIGHT);
1050186 0:84e4649e7707 139
1050186 0:84e4649e7707 140 /* Complete drawing */
1050186 0:84e4649e7707 141 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
1050186 0:84e4649e7707 142 }
1050186 0:84e4649e7707 143
1050186 0:84e4649e7707 144 void RGA_Func_Zoom(frame_buffer_t* frmbuf_info, int src_height_pos) {
1050186 0:84e4649e7707 145 /* Clear */
1050186 0:84e4649e7707 146 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
1050186 0:84e4649e7707 147 /* Zoom out */
1050186 0:84e4649e7707 148 canvas2d.drawImage(Landscape_wide_jpg_File,
1050186 0:84e4649e7707 149 /* src X */ ZOOM_SRC_CENTER_X - (src_height_pos * IMG_DRAW_WIDTH / IMG_DRAW_HEIGHT),
1050186 0:84e4649e7707 150 /* src Y */ ZOOM_SRC_CENTER_Y - src_height_pos,
1050186 0:84e4649e7707 151 /* src W */ src_height_pos * 2 * IMG_DRAW_WIDTH / IMG_DRAW_HEIGHT,
1050186 0:84e4649e7707 152 /* src H */ src_height_pos * 2,
1050186 0:84e4649e7707 153 /* dst */ 100, 100, IMG_DRAW_WIDTH, IMG_DRAW_HEIGHT);
1050186 0:84e4649e7707 154
1050186 0:84e4649e7707 155 /* Complete drawing */
1050186 0:84e4649e7707 156 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
1050186 0:84e4649e7707 157 }
1050186 0:84e4649e7707 158
1050186 0:84e4649e7707 159 void RGA_Func_Rotation(frame_buffer_t* frmbuf_info, graphics_matrix_float_t image_angle) {
1050186 0:84e4649e7707 160 /* Rotate the image to the right */
1050186 0:84e4649e7707 161 /* Clear */
1050186 0:84e4649e7707 162 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
1050186 0:84e4649e7707 163 /* Move to drawing position */
1050186 0:84e4649e7707 164 canvas2d.translate((100 + (IMG_DRAW_WIDTH / 2)), (100 + (IMG_DRAW_HEIGHT / 2)));
1050186 0:84e4649e7707 165 /* Rotate */
1050186 0:84e4649e7707 166 canvas2d.rotate(image_angle * (3.14159 / 180));
1050186 0:84e4649e7707 167 /* Move to center to rotate */
1050186 0:84e4649e7707 168 canvas2d.translate((-IMG_DRAW_WIDTH / 2), (-IMG_DRAW_HEIGHT / 2));
1050186 0:84e4649e7707 169 canvas2d.drawImage(Flower_jpg_File, 0, 0);
1050186 0:84e4649e7707 170 canvas2d.setTransform(1, 0, 0, 1, 0, 0);
1050186 0:84e4649e7707 171
1050186 0:84e4649e7707 172 /* Complete drawing */
1050186 0:84e4649e7707 173 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
1050186 0:84e4649e7707 174 }
1050186 0:84e4649e7707 175
1050186 0:84e4649e7707 176 void RGA_Func_Accelerate(frame_buffer_t* frmbuf_info, float32_t relative_pos) {
1050186 0:84e4649e7707 177 /* Do accelerated motion from right to left */
1050186 0:84e4649e7707 178 int position;
1050186 0:84e4649e7707 179
1050186 0:84e4649e7707 180 /* Clear */
1050186 0:84e4649e7707 181 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
1050186 0:84e4649e7707 182 position = R_ANIMATION_TIMING_FUNCTION_GetValue(accelerator, relative_pos, 550.0f, 10.0f);
1050186 0:84e4649e7707 183 canvas2d.drawImage(Flower_jpg_File, position, 100);
1050186 0:84e4649e7707 184
1050186 0:84e4649e7707 185 /* Complete drawing */
1050186 0:84e4649e7707 186 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
1050186 0:84e4649e7707 187 }