For Seminar

Dependencies:   GR-PEACH_video GraphicsFramework R_BSP mbed-rtos mbed

Fork of RGA_HelloWorld by Renesas

rga_func.cpp

Committer:
1050186
Date:
2016-01-20
Revision:
1:a07212e32dcb
Parent:
0:84e4649e7707
Child:
3:841987280a7f

File content as of revision 1:a07212e32dcb:

/*
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include "mbed.h"
#include "rga_func.h"
#include "Images/BinaryImage_RZ_A1H.h"

#define ZOOM_SRC_CENTER_X                   (IMAGE_WIDTH_ZOOM_FUNC / 2)
#define ZOOM_SRC_CENTER_Y                   (IMAGE_HEIGHT_ZOOM_FUNC / 2)

Canvas2D_ContextClass canvas2d;

static animation_timing_function_t* accelerator;

void Set_RGAObject(frame_buffer_t* frmbuf_info) {
    errnum_t err;
    Canvas2D_ContextConfigClass config;

    config.frame_buffer = frmbuf_info;
    canvas2d = R_RGA_New_Canvas2D_ContextClass(config);
    err = R_OSPL_GetErrNum();
    if (err != 0) {
        printf("Line %d, error %d\n", __LINE__, err);
        while (1);
    }
}

void Get_AnimationTiming(char_t *timing_name) {
    R_Get_AnimationTimingFunction(timing_name, &accelerator);
}

void RGA_Func_ClrScreen(frame_buffer_t* frmbuf_info) {
    /* Clear the display in white */
    canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
}

void RGA_Func_DrawTopScreen(frame_buffer_t* frmbuf_info) {
    /* Draw a image */
    canvas2d.drawImage(TopScrn_jpg_File, 0, 0);

    /* Complete drawing */
    R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
}

void RGA_Func_DrawReturnButton(frame_buffer_t* frmbuf_info) {
    /* Draw a image */
    canvas2d.drawImage(RetBtn_jpg_File, 640, 10);

    /* Complete drawing */
    R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
}

void RGA_Func_DrawRectangle(frame_buffer_t* frmbuf_info) {
    /* Clear */
    canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
    /* Draw red rectangle */
    canvas2d.fillStyle = "#FF0000";
    canvas2d.fillRect(0, 0, 160, 240);
    canvas2d.fillRect(160, 240, 160, 240);
    /* Draw green rectangle */
    canvas2d.fillStyle = "#00FF00";
    canvas2d.fillRect(160, 0, 160, 240);
    canvas2d.fillRect(320, 240, 160, 240);
    /* Draw blue rectangle */
    canvas2d.fillStyle = "#0000FF";
    canvas2d.fillRect(320, 0, 160, 240);
    canvas2d.fillRect(480, 240, 160, 240);
    /* Draw black rectangle */
    canvas2d.fillStyle = "#000000";
    canvas2d.fillRect(480, 0, 160, 240);
    canvas2d.fillRect(640, 240, 160, 240);
    /* Draw write rectangle */
    canvas2d.fillStyle = "#FFFFFF";
    canvas2d.fillRect(640, 0, 160, 240);
    canvas2d.fillRect(0, 240, 160, 240);

    /* Complete drawing */
    R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
}

void RGA_Func_DrawImage(frame_buffer_t* frmbuf_info) {
    /* Clear */
    canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
    /* Draw the first image */
    canvas2d.drawImage(Flower_jpg_File, 100, 100);
    /* Draw the second image */
    if ((frmbuf_info->pixel_format == PIXEL_FORMAT_ARGB8888) || (frmbuf_info->pixel_format == PIXEL_FORMAT_XRGB8888)) {
        canvas2d.drawImage(Crystal_png_ARGB8888, 280, 70);
    } else if (frmbuf_info->pixel_format != PIXEL_FORMAT_YUV422) {
        canvas2d.drawImage(Crystal_png_ARGB4444, 280, 70);
    } else {
        canvas2d.drawImage(Crystal_png_File, 280, 70);
    }

    /* Complete drawing */
    R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
}

void RGA_Func_Dissolve(frame_buffer_t* frmbuf_info, float32_t global_alpha) {
    /* Dissolve = Fade Out + Fade In */
    /* Clear */
    canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
    /* fade Out */
    canvas2d.globalAlpha = 1.0f - global_alpha;
    canvas2d.drawImage(Flower_jpg_File, 100, 100);
    /* fade In */
    canvas2d.globalAlpha = global_alpha;
    canvas2d.drawImage(Landscape_jpg_File, 100, 100);

    canvas2d.globalAlpha = 1.0f;
    /* Complete drawing */
    R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
}

void RGA_Func_Scroll(frame_buffer_t* frmbuf_info, int src_width_pos) {
    /* Clear */
    canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
    /* Scroll from left to right */
    canvas2d.drawImage(Landscape_wide_jpg_File,
                        /* src */       src_width_pos, 25, IMG_DRAW_WIDTH, IMG_DRAW_HEIGHT,
                        /* dst */       100, 100, IMG_DRAW_WIDTH, IMG_DRAW_HEIGHT);

    /* Complete drawing */
    R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
}

void RGA_Func_Zoom(frame_buffer_t* frmbuf_info, int src_height_pos) {
    /* Clear */
    canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
    /* Zoom out */
    canvas2d.drawImage(Landscape_wide_jpg_File,
                        /* src X */     ZOOM_SRC_CENTER_X - (src_height_pos * IMG_DRAW_WIDTH / IMG_DRAW_HEIGHT),
                        /* src Y */     ZOOM_SRC_CENTER_Y - src_height_pos,
                        /* src W */     src_height_pos * 2 * IMG_DRAW_WIDTH / IMG_DRAW_HEIGHT,
                        /* src H */     src_height_pos * 2,
                        /* dst   */     100, 100, IMG_DRAW_WIDTH, IMG_DRAW_HEIGHT);

    /* Complete drawing */
    R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
}

void RGA_Func_Rotation(frame_buffer_t* frmbuf_info, graphics_matrix_float_t image_angle) {
    /* Rotate the image to the right */
    /* Clear */
    canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
    /* Move to drawing position */
    canvas2d.translate((100 + (IMG_DRAW_WIDTH / 2)), (100 + (IMG_DRAW_HEIGHT / 2)));
    /* Rotate */
    canvas2d.rotate(image_angle * (3.14159 / 180));
    /* Move to center to rotate */
    canvas2d.translate((-IMG_DRAW_WIDTH / 2), (-IMG_DRAW_HEIGHT / 2));
    canvas2d.drawImage(Flower_jpg_File, 0, 0);
    canvas2d.setTransform(1, 0, 0, 1, 0, 0);

    /* Complete drawing */
    R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
}

void RGA_Func_Accelerate(frame_buffer_t* frmbuf_info, float32_t relative_pos) {
    /* Do accelerated motion from right to left */
    int position;

    /* Clear */
    canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
    position = R_ANIMATION_TIMING_FUNCTION_GetValue(accelerator, relative_pos, 550.0f, 10.0f);
    canvas2d.drawImage(Flower_jpg_File, position, 100);

    /* Complete drawing */
    R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
}