All pastes #812242 Raw Edit

Miscellany

public c v1 · immutable
·published 2007-12-11 16:51 UTC
rendered paste body
/*************************************************************************** *             __________               __   ___. *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  / *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  < *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \ *                     \/            \/     \/    \/            \/ * $Id$ * * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/#include "plugin.h"/* welcome to the example rockbox plugin *//* This macros must always be included. Should be placed at the top by   convention, although the actual position doesn't matter */PLUGIN_HEADER/* here is a global api struct pointer. while not strictly necessary,   it's nice not to have to pass the api pointer in all function calls   in the plugin */static struct plugin_api* rb;static fb_data *b;void simple_resize_bitmap(struct bitmap *src, struct bitmap *dst){    const int srcw = src->width;    const int srch = src->height;    const int dstw = dst->width;    const int dsth = dst->height;    const fb_data *srcd = (fb_data*)(src->data);    const fb_data *dstd = (fb_data*)(dst->data);    const long xrstep = ((srcw-1) << 8) / (dstw-1);    const long yrstep = ((srch-1) << 8) / (dsth-1);    fb_data *src_row, *dst_row;    long xr, yr = 0;    int src_x, src_y, dst_x, dst_y;    for (dst_y=0; dst_y < dsth; dst_y++)    {        src_y = (yr >> 8);        src_row = (fb_data*)&srcd[src_y * srcw];        dst_row = (fb_data*)&dstd[dst_y * dstw];        for (xr=0,dst_x=0; dst_x < dstw; dst_x++)        {            src_x = (xr >> 8);            dst_row[dst_x] = src_row[src_x];            xr += xrstep;        }        yr += yrstep;    }}static struct bitmap input_bmp;static struct bitmap output_bmp;static fb_data *input_bmp_data[200*200];static fb_data *output_bmp_data[200*200];/* this is the plugin entry point */enum plugin_status plugin_start(struct plugin_api* api, void* parameter){    /* if you don't use the parameter, you can do like    this to avoid the compiler warning about it */    (void)parameter;    /* if you are using a global api pointer, don't forget to copy it!    otherwise you will get lovely "I04: IllInstr" errors... :-) */    rb = api;    b = rb->lcd_framebuffer;    rb->lcd_set_background(LCD_RGBPACK(0,0,0));    rb->lcd_clear_display(); // TODO: Optimizes this by e.g. invalidating rects    input_bmp.data = (char*)input_bmp_data;    output_bmp.data = (char*)output_bmp_data;    int ret = rb->read_bmp_file("/test.bmp", &input_bmp, sizeof(fb_data)*100*100, FORMAT_NATIVE);    int button;    output_bmp.width = 50;    output_bmp.height = 50;    DEBUGF("input_bmp_data starts at %p\n", input_bmp_data);    DEBUGF("output_bmp_data starts at %p\n", output_bmp_data);    while(1) {        rb->lcd_clear_display();         rb->lcd_bitmap(input_bmp_data, 0, 0, input_bmp.width, input_bmp.height);            simple_resize_bitmap(&input_bmp, &output_bmp);                rb->lcd_bitmap(output_bmp_data, 0, 0, output_bmp.width, output_bmp.height);                rb->lcd_update();        button = rb->button_get(true);        switch (button) {            case BUTTON_MENU:                return PLUGIN_OK;            case BUTTON_SCROLL_FWD:            case (BUTTON_SCROLL_FWD | BUTTON_REPEAT):                output_bmp.width += 2;                output_bmp.height += 2;                break;                            case BUTTON_SCROLL_BACK:            case (BUTTON_SCROLL_BACK | BUTTON_REPEAT):                output_bmp.width -= 2;                output_bmp.height -= 2;                break;        }    }    return PLUGIN_OK;}