Update Beast installation instructions to use beastpatcher and remove instructions...
[kugel-rb.git] / apps / recorder / resize.h
blob4ea4eaa9a06dff9e72c58fc74495e1abef913c3f
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 /* multiply two unsigned 32 bit values and return the top 32 bit
63 * of the 64 bit result */
64 static inline unsigned sc_mul32(unsigned a, unsigned b)
66 unsigned r, t1, t2, t3;
68 asm (
69 "swap.w %[a], %[t1] \n" /* t1 = ba */
70 "mulu %[t1], %[b] \n" /* a * d */
71 "swap.w %[b], %[t3] \n" /* t3 = dc */
72 "sts macl, %[t2] \n" /* t2 = a * d */
73 "mulu %[t1], %[t3] \n" /* a * c */
74 "sts macl, %[r] \n" /* hi = a * c */
75 "mulu %[a], %[t3] \n" /* b * c */
76 "clrt \n"
77 "sts macl, %[t3] \n" /* t3 = b * c */
78 "addc %[t2], %[t3] \n" /* t3 += t2, carry -> t2 */
79 "movt %[t2] \n"
80 "mulu %[a], %[b] \n" /* b * d */
81 "mov %[t3], %[t1] \n" /* t1t3 = t2t3 << 16 */
82 "xtrct %[t2], %[t1] \n"
83 "shll16 %[t3] \n"
84 "sts macl, %[t2] \n" /* lo = b * d */
85 "clrt \n" /* hi.lo += t1t3 */
86 "addc %[t3], %[t2] \n"
87 "addc %[t1], %[r] \n"
88 : /* outputs */
89 [r] "=&r"(r),
90 [t1]"=&r"(t1),
91 [t2]"=&r"(t2),
92 [t3]"=&r"(t3)
93 : /* inputs */
94 [a] "r" (a),
95 [b] "r" (b)
97 return r;
99 #define SC_MUL(x, y) sc_mul32(x, y)
100 #define SC_MUL_INIT
101 #define SC_MUL_END
102 #endif
104 #ifndef SC_SHIFT
105 #define SC_SHIFT 32
106 #endif
108 #if SC_SHIFT == 24
109 #define SC_NUM 0x1000000U
110 #define SC_FIX 0
112 #ifndef SC_MUL
113 #define SC_MUL(x, y) ((x) * (y) >> 24)
114 #define SC_MUL_INIT
115 #define SC_MUL_END
116 #endif
118 #else /* SC_SHIFT == 32 */
119 #define SC_NUM 0x80000000U
120 #define SC_FIX 1
122 #ifndef SC_MUL
123 #define SC_MUL(x, y) ((x) * (uint64_t)(y) >> 32)
124 #define SC_MUL_INIT
125 #define SC_MUL_END
126 #endif
128 #endif
130 struct img_part {
131 int len;
132 #if !defined(HAVE_LCD_COLOR)
133 uint8_t *buf;
134 #else
135 struct uint8_rgb* buf;
136 #endif
139 #ifdef HAVE_LCD_COLOR
140 /* intermediate type used by the scaler for color output. greyscale version
141 uses uint32_t
143 struct uint32_rgb {
144 uint32_t r;
145 uint32_t g;
146 uint32_t b;
148 #endif
150 /* struct which contains various parameters shared between vertical scaler,
151 horizontal scaler, and row output
153 struct scaler_context {
154 uint32_t divisor;
155 uint32_t round;
156 struct bitmap *bm;
157 struct dim *src;
158 unsigned char *buf;
159 bool dither;
160 int len;
161 void *args;
162 struct img_part* (*store_part)(void *);
163 void (*output_row)(uint32_t,void*,struct scaler_context*);
164 bool (*h_scaler)(void*,struct scaler_context*, bool);
167 struct custom_format {
168 void (*output_row)(uint32_t,void*,struct scaler_context*);
169 unsigned int (*get_size)(struct bitmap *bm);
172 struct rowset;
173 int recalc_dimension(struct dim *dst, struct dim *src);
175 int resize_on_load(struct bitmap *bm, bool dither,
176 struct dim *src, struct rowset *tmp_row,
177 unsigned char *buf, unsigned int len,
178 const struct custom_format *cformat,
179 struct img_part* (*store_part)(void *args),
180 void *args);
182 #endif /* _RESIZE_H_ */