Bump version numbers for 3.13
[maemo-rb.git] / apps / recorder / resize.h
blob7e0a991eea92576c42238c7da1128952c2b2f1aa
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_SH)
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;
51 unsigned h = 1 << 15;
52 /* notation:
53 m = ab, n = cd
54 final result is (((a *c) << 32) + ((b * c + a * d) << 16) + b * d +
55 (1 << 31)) >> 32
57 asm (
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 */
63 "shlr16 %[r]\n\t"
64 "sts macl, %[t2]\n\t" /* t2 = b * c */
65 "mulu %[t1], %[t3]\n\t" /* a * c */
66 "add %[t2], %[r]\n\t"
67 "sts macl, %[t3]\n\t" /* t3 = a * c */
68 "mulu %[t1], %[n]\n\t" /* a * d */
69 "shll16 %[t3]\n\t"
70 "sts macl, %[t2]\n\t" /* t2 = a * d */
71 "add %[t2], %[r]\n\t"
72 "add %[t3], %[r]\n\t" /* r = ((b * d) >> 16) + (b * c + a * d) +
73 ((a * c) << 16) */
74 "add %[h], %[r]\n\t" /* round result */
75 "shlr16 %[r]\n\t" /* truncate result */
76 : /* outputs */
77 [r] "=&r"(r),
78 [t1]"=&r"(t1),
79 [t2]"=&r"(t2),
80 [t3]"=&r"(t3)
81 : /* inputs */
82 [h] "r" (h),
83 [m] "r" (m),
84 [n] "r" (n)
86 return r;
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;
92 tmp += 1LU << 31;
93 tmp >>= 32;
94 return tmp;
96 #else
97 #define SC_OUT(n, c) (((n) + (1 << 23)) >> 24)
98 #endif
99 #ifndef SC_OUT
100 #define SC_OUT(n, c) (sc_mul_u32_rnd(n, (c)->recip))
101 #endif
103 struct img_part {
104 int len;
105 #if !defined(HAVE_LCD_COLOR)
106 uint8_t *buf;
107 #else
108 struct uint8_rgb* buf;
109 #endif
112 #ifdef HAVE_LCD_COLOR
113 /* intermediate type used by the scaler for color output. greyscale version
114 uses uint32_t
116 struct uint32_argb {
117 uint32_t r;
118 uint32_t g;
119 uint32_t b;
120 uint32_t a;
122 #endif
124 /* struct which contains various parameters shared between vertical scaler,
125 horizontal scaler, and row output
127 struct scaler_context {
128 #if defined(CPU_SH) || defined(TEST_SH_MATH)
129 uint32_t recip;
130 #else
131 uint32_t h_i_val;
132 uint32_t h_o_val;
133 uint32_t v_i_val;
134 uint32_t v_o_val;
135 #endif
136 struct bitmap *bm;
137 struct dim *src;
138 unsigned char *buf;
139 bool dither;
140 int len;
141 void *args;
142 struct img_part* (*store_part)(void *);
143 void (*output_row)(uint32_t,void*,struct scaler_context*);
144 bool (*h_scaler)(void*,struct scaler_context*, bool);
147 #if defined(HAVE_LCD_COLOR)
148 #define IF_PIX_FMT(...) __VA_ARGS__
149 #else
150 #define IF_PIX_FMT(...)
151 #endif
153 struct custom_format {
154 void (*output_row_8)(uint32_t,void*, struct scaler_context*);
155 #if defined(HAVE_LCD_COLOR)
156 void (*output_row_32[2])(uint32_t,void*, struct scaler_context*);
157 #else
158 void (*output_row_32)(uint32_t,void*, struct scaler_context*);
159 #endif
160 unsigned int (*get_size)(struct bitmap *bm);
163 struct rowset;
165 extern const struct custom_format format_native;
167 int recalc_dimension(struct dim *dst, struct dim *src);
169 int resize_on_load(struct bitmap *bm, bool dither,
170 struct dim *src, struct rowset *tmp_row,
171 unsigned char *buf, unsigned int len,
172 const struct custom_format *cformat,
173 IF_PIX_FMT(int format_index,)
174 struct img_part* (*store_part)(void *args),
175 void *args);
177 #endif /* _RESIZE_H_ */