summaryrefslogtreecommitdiff
path: root/apps/codecs/lib/tlsf/src/target.h
blob: 1afd62aef20978e7fb998d11be68266fb834f062 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef _TARGET_H_
#define _TARGET_H_

#include <pthread.h>

#define TLSF_MLOCK_T            pthread_mutex_t
#define TLSF_CREATE_LOCK(l)     pthread_mutex_init (l, NULL)
#define TLSF_DESTROY_LOCK(l)    pthread_mutex_destroy(l)
#define TLSF_ACQUIRE_LOCK(l)    pthread_mutex_lock(l)
#define TLSF_RELEASE_LOCK(l)    pthread_mutex_unlock(l)

#endif
='#n55'>55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
/***************************************************************************
*             __________               __   ___.
*   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
*   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
*   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
*   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
*                     \/            \/     \/    \/            \/
* $Id$
*
* Copyright (C) 2005 Kevin Ferrare
*
* Fire demo plugin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/

#include "plugin.h"
#include "lib/helper.h"

#include "lib/pluginlib_actions.h"
#include "lib/fixedpoint.h"

#ifndef HAVE_LCD_COLOR
#include "lib/grey.h"
#endif

#if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
/* Archos has not enough plugin RAM for full-width fire :( */
#define FIRE_WIDTH 106
#define FIRE_XPOS 3
#else
#define FIRE_WIDTH LCD_WIDTH
#define FIRE_XPOS 0
#endif

#ifndef HAVE_LCD_COLOR
GREY_INFO_STRUCT
        static unsigned char draw_buffer[FIRE_WIDTH];

#endif

/* Key assignement */
const struct button_mapping* plugin_contexts[]= {
    pla_main_ctx,
#if defined(HAVE_REMOTE_LCD)
    pla_remote_ctx,
#endif
};

#define FIRE_QUIT                   PLA_CANCEL
#define FIRE_SWITCH_FLAMES_TYPE     PLA_LEFT
#define FIRE_SWITCH_FLAMES_MOVING   PLA_RIGHT

#ifdef HAVE_SCROLLWHEEL
#define FIRE_INCREASE_MULT          PLA_SCROLL_FWD
#define FIRE_INCREASE_MULT_REP      PLA_SCROLL_FWD_REPEAT
#define FIRE_DECREASE_MULT          PLA_SCROLL_BACK
#define FIRE_DECREASE_MULT_REP      PLA_SCROLL_BACK_REPEAT
#else
#define FIRE_INCREASE_MULT          PLA_UP
#define FIRE_INCREASE_MULT_REP      PLA_UP_REPEAT
#define FIRE_DECREASE_MULT          PLA_DOWN
#define FIRE_DECREASE_MULT_REP      PLA_DOWN_REPEAT
#endif

#define MIN_FLAME_VALUE 0
#define COOL_MAX (440/LCD_HEIGHT+2)

#ifndef HAVE_LCD_COLOR
static unsigned char palette[256];

static void color_palette_init(unsigned char* palette)
{
    int i;
    for(i=0;i<=160;i++)//palette[i]=(3/2)*i
        palette[i]=(i*3)/2;

    /* 'regular' fire doesn't exceed this value */
    for(;i<=255;i++)//palette[i]=(3/20)*i+216
        palette[i]=(i*3+20*217)/20;
}
#else

static fb_data palette[256];

/*
 * Color palette generation algorithm taken from
 * the "The Demo Effects Collection" GPL project
 * Copyright (C) 2002 W.P. van Paassen
 */
static void color_palette_init(fb_data* palette)
{
    int i;
    for (i = 0; i < 32; i++){
        /* black to blue, 32 values*/
        palette[i]=LCD_RGBPACK(0, 0, 2*i);

        /* blue to red, 32 values*/
        palette[i +  32]=LCD_RGBPACK(8*i, 0, 64 - 2*i);

        /* red to yellow, 32 values*/
        palette[i +  64]=LCD_RGBPACK(255, 8*i, 0);

        /* yellow to white, 162 values */
        palette[i +  96]=LCD_RGBPACK(255, 255,   0 + 4*i);
        palette[i + 128]=LCD_RGBPACK(255, 255,  64 + 4*i);
        palette[i + 160]=LCD_RGBPACK(255, 255, 128 + 4*i);
        palette[i + 192]=LCD_RGBPACK(255, 255, 192 + i);
        palette[i + 224]=LCD_RGBPACK(255, 255, 224 + i);
    }
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
    rb->lcd_pal256_update_pal(palette);
#endif
}

#endif

static void tab_init_rand(unsigned char *tab, unsigned int tab_size,
                          int rand_max)
{
    unsigned char *end = tab + tab_size;

    while(tab < end)
        *tab++ = (unsigned char)rb->rand() % rand_max;
}

struct fire {
    unsigned char fire[LCD_HEIGHT+3][FIRE_WIDTH];
    unsigned char cooling_map[LCD_HEIGHT][FIRE_WIDTH];
    int flames_type;
    bool moving;
    unsigned int mult;
};
/* makes the instance a global variable since it's too big to fit on the target's stack */
static struct fire fire;

static inline void fire_convolve(struct fire* fire)
{
    unsigned int pixel_value;
    unsigned int cooling_value;
    unsigned char *ptr, *end, *cool;
    unsigned int mult=fire->mult;

    rb->yield();
    /* Convolve the pixels and handle cooling (to add nice shapes effects later) */
    cool = &fire->cooling_map[0][0];
    ptr = &fire->fire[0][0];
    end = ptr + LCD_HEIGHT*FIRE_WIDTH;

    switch (fire->flames_type){
        case 0:
            do{
                pixel_value = ptr[FIRE_WIDTH-1]  /* fire[y+1][x-1] */
                        + ptr[2*FIRE_WIDTH]  /* fire[y+2][x] */
                        + ptr[FIRE_WIDTH+1]  /* fire[y+1][x+1] */
                        + ptr[3*FIRE_WIDTH]; /* fire[y+3][x] */
                pixel_value = FMULU(pixel_value, mult) >> 10;

                cooling_value = *cool++;