Hopefully fix wrong colours on coldfire targets for certain scaling factors. EMAC...
[kugel-rb.git] / apps / recorder / resize.h
blob4e71fb8732021694d5f2e6b85e03477ef3a80653
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Akio Idehara
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _RESIZE_H_
22 #define _RESIZE_H_
23 #include "config.h"
24 #include "lcd.h"
25 #include "inttypes.h"
27 /****************************************************************
28 * resize_on_load()
30 * resize bitmap on load with scaling
32 * If HAVE_LCD_COLOR then this func use smooth scaling algorithm
33 * - downscaling both way use "Area Sampling"
34 * if IMG_RESIZE_BILINER or IMG_RESIZE_NEAREST is NOT set
35 * - otherwise "Bilinear" or "Nearest Neighbour"
37 * If !(HAVE_LCD_COLOR) then use simple scaling algorithm "Nearest Neighbour"
39 * return -1 for error
40 ****************************************************************/
42 /* nothing needs the on-stack buffer right now */
43 #define MAX_SC_STACK_ALLOC 0
44 #define HAVE_UPSCALER 1
46 #if defined(CPU_COLDFIRE)
47 #define SC_NUM 0x80000000U
48 #define SC_MUL_INIT \
49 unsigned long macsr_st = coldfire_get_macsr(); \
50 coldfire_set_macsr(EMAC_UNSIGNED);
51 #define SC_MUL_END coldfire_set_macsr(macsr_st);
52 #define SC_MUL(x, y) \
53 ({ \
54 unsigned long t; \
55 asm ("mac.l %[a], %[b], %%acc0\n\t" \
56 "move.l %%accext01, %[t]\n\t" \
57 "move.l #0, %%acc0\n\t" \
58 : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
59 t; \
61 #elif (CONFIG_CPU == SH7034)
62 #define SC_SHIFT 24
63 #endif
65 #ifndef SC_SHIFT
66 #define SC_SHIFT 32
67 #endif
69 #if SC_SHIFT == 24
70 #define SC_NUM 0x1000000U
71 #define SC_FIX 0
73 #ifndef SC_MUL
74 #define SC_MUL(x, y) ((x) * (y) >> 24)
75 #define SC_MUL_INIT
76 #define SC_MUL_END
77 #endif
79 #else /* SC_SHIFT == 32 */
80 #define SC_NUM 0x80000000U
81 #define SC_FIX 1
83 #ifndef SC_MUL
84 #define SC_MUL(x, y) ((x) * (uint64_t)(y) >> 32)
85 #define SC_MUL_INIT
86 #define SC_MUL_END
87 #endif
89 #endif
91 struct img_part {
92 int len;
93 #if !defined(HAVE_LCD_COLOR)
94 uint8_t *buf;
95 #else
96 struct uint8_rgb* buf;
97 #endif
100 #ifdef HAVE_LCD_COLOR
101 /* intermediate type used by the scaler for color output. greyscale version
102 uses uint32_t
104 struct uint32_rgb {
105 uint32_t r;
106 uint32_t g;
107 uint32_t b;
109 #endif
111 /* struct which contains various parameters shared between vertical scaler,
112 horizontal scaler, and row output
114 struct scaler_context {
115 uint32_t divisor;
116 uint32_t round;
117 struct bitmap *bm;
118 struct dim *src;
119 unsigned char *buf;
120 bool dither;
121 int len;
122 void *args;
123 struct img_part* (*store_part)(void *);
124 void (*output_row)(uint32_t,void*,struct scaler_context*);
125 bool (*h_scaler)(void*,struct scaler_context*, bool);
128 struct custom_format {
129 void (*output_row)(uint32_t,void*,struct scaler_context*);
130 unsigned int (*get_size)(struct bitmap *bm);
133 struct rowset;
134 int recalc_dimension(struct dim *dst, struct dim *src);
136 int resize_on_load(struct bitmap *bm, bool dither,
137 struct dim *src, struct rowset *tmp_row,
138 unsigned char *buf, unsigned int len,
139 const struct custom_format *cformat,
140 struct img_part* (*store_part)(void *args),
141 void *args);
143 #endif /* _RESIZE_H_ */