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
47 /* perform 32x32->40 unsigned multiply, round off and return top 8 bits */
48 static inline uint32_t sc_mul_u32_rnd(uint32_t m
, uint32_t n
)
50 unsigned r
, t1
, t2
, t3
;
54 final result is (((a *c) << 32) + ((b * c + a * d) << 16) + b * d +
58 "swap.w %[m], %[t1]\n\t" /* t1 = ba */
59 "mulu %[m], %[n]\n\t" /* b * d */
60 "swap.w %[n], %[t3]\n\t" /* t3 = dc */
61 "sts macl, %[r]\n\t" /* r = b * d */
62 "mulu %[m], %[t3]\n\t" /* b * c */
64 "sts macl, %[t2]\n\t" /* t2 = b * c */
65 "mulu %[t1], %[t3]\n\t" /* a * c */
67 "sts macl, %[t3]\n\t" /* t3 = a * c */
68 "mulu %[t1], %[n]\n\t" /* a * d */
70 "sts macl, %[t2]\n\t" /* t2 = a * d */
72 "add %[t3], %[r]\n\t" /* r = ((b * d) >> 16) + (b * c + a * d) +
74 "add %[h], %[r]\n\t" /* round result */
75 "shlr16 %[r]\n\t" /* truncate result */
88 #elif defined(TEST_SH_MATH)
89 static inline uint32_t sc_mul_u32_rnd(uint32_t op1
, uint32_t op2
)
91 uint64_t tmp
= (uint64_t)op1
* op2
;
97 #define SC_OUT(n, c) (((n) + (1 << 23)) >> 24)
100 #define SC_OUT(n, c) (sc_mul_u32_rnd(n, (c)->recip))
105 #if !defined(HAVE_LCD_COLOR)
108 struct uint8_rgb
* buf
;
112 #ifdef HAVE_LCD_COLOR
113 /* intermediate type used by the scaler for color output. greyscale version
123 /* struct which contains various parameters shared between vertical scaler,
124 horizontal scaler, and row output
126 struct scaler_context
{
127 #if defined(CPU_SH) || defined(TEST_SH_MATH)
141 struct img_part
* (*store_part
)(void *);
142 void (*output_row
)(uint32_t,void*,struct scaler_context
*);
143 bool (*h_scaler
)(void*,struct scaler_context
*, bool);
146 #if defined(HAVE_LCD_COLOR)
147 #define IF_PIX_FMT(...) __VA_ARGS__
149 #define IF_PIX_FMT(...)
152 struct custom_format
{
153 void (*output_row_8
)(uint32_t,void*, struct scaler_context
*);
154 #if defined(HAVE_LCD_COLOR)
155 void (*output_row_32
[2])(uint32_t,void*, struct scaler_context
*);
157 void (*output_row_32
)(uint32_t,void*, struct scaler_context
*);
159 unsigned int (*get_size
)(struct bitmap
*bm
);
164 extern const struct custom_format format_native
;
166 int recalc_dimension(struct dim
*dst
, struct dim
*src
);
168 int resize_on_load(struct bitmap
*bm
, bool dither
,
169 struct dim
*src
, struct rowset
*tmp_row
,
170 unsigned char *buf
, unsigned int len
,
171 const struct custom_format
*cformat
,
172 IF_PIX_FMT(int format_index
,)
173 struct img_part
* (*store_part
)(void *args
),
176 #endif /* _RESIZE_H_ */