1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
27 /****************************************************************
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"
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
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) \
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)); \
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
;
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 */
77 "sts macl, %[t3] \n" /* t3 = b * c */
78 "addc %[t2], %[t3] \n" /* t3 += t2, carry -> t2 */
80 "mulu %[a], %[b] \n" /* b * d */
81 "mov %[t3], %[t1] \n" /* t1t3 = t2t3 << 16 */
82 "xtrct %[t2], %[t1] \n"
84 "sts macl, %[t2] \n" /* lo = b * d */
85 "clrt \n" /* hi.lo += t1t3 */
86 "addc %[t3], %[t2] \n"
99 #define SC_MUL(x, y) sc_mul32(x, y)
109 #define SC_NUM 0x1000000U
113 #define SC_MUL(x, y) ((x) * (y) >> 24)
118 #else /* SC_SHIFT == 32 */
119 #define SC_NUM 0x80000000U
123 #define SC_MUL(x, y) ((x) * (uint64_t)(y) >> 32)
132 #if !defined(HAVE_LCD_COLOR)
135 struct uint8_rgb
* buf
;
139 #ifdef HAVE_LCD_COLOR
140 /* intermediate type used by the scaler for color output. greyscale version
150 /* struct which contains various parameters shared between vertical scaler,
151 horizontal scaler, and row output
153 struct scaler_context
{
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
);
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
),
182 #endif /* _RESIZE_H_ */