Add an unsigned 32*32->top32 bit multiply for resizing on SH1, and switch to 32 bit...
[kugel-rb.git] / apps / recorder / resize.h
blobd1dabaae092daa8256dc6405c48817bc3dac4634
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" /* t2t3 <<= 16 */
82 "xtrct %[t2], %[t1] \n"
83 "mov %[t1], %[t2] \n"
84 "shll16 %[t3] \n"
85 "sts macl, %[t1] \n" /* lo = b * d */
86 "clrt \n" /* hi.lo += t2t3 */
87 "addc %[t3], %[t1] \n"
88 "addc %[t2], %[r] \n"
89 : /* outputs */
90 [r] "=&r"(r),
91 [t1]"=&r"(t1),
92 [t2]"=&r"(t2),
93 [t3]"=&r"(t3)
94 : /* inputs */
95 [a] "r" (a),
96 [b] "r" (b)
98 return r;
100 #define SC_MUL(x, y) sc_mul32(x, y)
101 #define SC_MUL_INIT
102 #define SC_MUL_END
103 #endif
105 #ifndef SC_SHIFT
106 #define SC_SHIFT 32
107 #endif
109 #if SC_SHIFT == 24
110 #define SC_NUM 0x1000000U
111 #define SC_FIX 0
113 #ifndef SC_MUL
114 #define SC_MUL(x, y) ((x) * (y) >> 24)
115 #define SC_MUL_INIT
116 #define SC_MUL_END
117 #endif
119 #else /* SC_SHIFT == 32 */
120 #define SC_NUM 0x80000000U
121 #define SC_FIX 1
123 #ifndef SC_MUL
124 #define SC_MUL(x, y) ((x) * (uint64_t)(y) >> 32)
125 #define SC_MUL_INIT
126 #define SC_MUL_END
127 #endif
129 #endif
131 struct img_part {
132 int len;
133 #if !defined(HAVE_LCD_COLOR)
134 uint8_t *buf;
135 #else
136 struct uint8_rgb* buf;
137 #endif
140 #ifdef HAVE_LCD_COLOR
141 /* intermediate type used by the scaler for color output. greyscale version
142 uses uint32_t
144 struct uint32_rgb {
145 uint32_t r;
146 uint32_t g;
147 uint32_t b;
149 #endif
151 /* struct which contains various parameters shared between vertical scaler,
152 horizontal scaler, and row output
154 struct scaler_context {
155 uint32_t divisor;
156 uint32_t round;
157 struct bitmap *bm;
158 struct dim *src;
159 unsigned char *buf;
160 bool dither;
161 int len;
162 void *args;
163 struct img_part* (*store_part)(void *);
164 void (*output_row)(uint32_t,void*,struct scaler_context*);
165 bool (*h_scaler)(void*,struct scaler_context*, bool);
168 struct custom_format {
169 void (*output_row)(uint32_t,void*,struct scaler_context*);
170 unsigned int (*get_size)(struct bitmap *bm);
173 struct rowset;
174 int recalc_dimension(struct dim *dst, struct dim *src);
176 int resize_on_load(struct bitmap *bm, bool dither,
177 struct dim *src, struct rowset *tmp_row,
178 unsigned char *buf, unsigned int len,
179 const struct custom_format *cformat,
180 struct img_part* (*store_part)(void *args),
181 void *args);
183 #endif /* _RESIZE_H_ */