Add a bunch of markers into the tokens enum to make figuring out which token isnt...
[kugel-rb.git] / apps / recorder / resize.h
blobd71a3e7f1cb46cab159e5e3cc4b1656b2df9f5ff
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_rgb {
117 uint32_t r;
118 uint32_t g;
119 uint32_t b;
121 #endif
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)
128 uint32_t recip;
129 #else
130 uint32_t h_i_val;
131 uint32_t h_o_val;
132 uint32_t v_i_val;
133 uint32_t v_o_val;
134 #endif
135 struct bitmap *bm;
136 struct dim *src;
137 unsigned char *buf;
138 bool dither;
139 int len;
140 void *args;
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__
148 #else
149 #define IF_PIX_FMT(...)
150 #endif
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*);
156 #else
157 void (*output_row_32)(uint32_t,void*, struct scaler_context*);
158 #endif
159 unsigned int (*get_size)(struct bitmap *bm);
162 struct rowset;
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),
174 void *args);
176 #endif /* _RESIZE_H_ */