1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
5<meta http-equiv="Content-Style-Type" content="text/css" />
6<title>DSP_Scaling</title>
7<link rel="stylesheet" href="../../css/nitro.css" type="text/css" />
8</head>
9<body>
10
11<h1>DSP_Scaling* <IMG src="../../image/TWL.gif" align="middle"></H1>
12<H2>Syntax</H2>
13
14<pre><code>
15BOOL DSP_ScalingAsyncEx(
16        const void* src,
17        void* dst,
18        u16 img_width,
19        u16 img_height,
20        f32 rx,
21        f32 ry,
22        DSPGraphicsScalingMode mode,
23        u16 x,
24        u16 y,
25        u16 width,
26        u16 height,
27        DSP_GraphicsCallback callback
28    );
29
30BOOL DSP_Scaling(src, dst, img_width, img_height, rx, ry, mode);
31BOOL DSP_ScalingEx(src, dst, img_width, img_height, rx, ry, mode, x, y, width, height);
32BOOL DSP_ScalingAsync(src, dst, img_width, img_height, rx, ry, mode, callback);
33</code></pre>
34
35<h2>Arguments</h2>
36<table style="width:100%">
37<tbody>
38<tr>
39<td style="width:13%"><CODE>src</CODE></td>
40<td style="width:87%">Buffer in main memory that holds the data to convert.</td>
41</tr>
42<tr>
43<td style="width:13%"><CODE>dst</CODE></td>
44<td style="width:87%">Buffer in main memory to hold the converted data.<br /><span style='color:Red'>You must allocate a buffer large enough to store the converted data.</span></td>
45</tr>
46<tr>
47<td style="width:13%"><CODE>img_width</CODE></td>
48<td style="width:87%">Width of the image to convert.</td>
49</tr>
50<tr>
51<td style="width:13%"><CODE>img_height</CODE></td>
52<td style="width:87%">Height of the image to convert.</td>
53</tr>
54<tr>
55<td style="width:13%"><CODE>rx</CODE></td>
56<td style="width:87%">Horizontal scaling factor.<br /><span style='color:Red'>Valid between 31 and 0.001. Decimals are truncated to three decimal places.</span></td>
57</tr>
58<tr>
59<td style="width:13%"><CODE>ry</CODE></td>
60<td style="width:87%">Vertical scaling factor.<br /><span style='color:Red'>Valid between 31 and 0.001. Decimals are truncated to three decimal places.</span>
61</td>
62</tr>
63<tr>
64<td style="width:13%"><CODE>mode</CODE></td>
65<td style="width:87%">Interpolation method for scaling up (expanding) or scaling down (shrinking). Specifies the <CODE>DSPGraphicsScalingMode</CODE> (described below).</td>
66</tr>
67<tr>
68<td style="width:13%"><CODE>x</CODE></td>
69<td style="width:87%">X-coordinate of the region to process, with the coordinate system origin (0,0) located at the upper-left of <CODE>src</CODE>.</td>
70</tr>
71<tr>
72<td style="width:13%"><CODE>y</CODE></td>
73<td style="width:87%">Y-coordinate of the region to process, with the coordinate system origin (0,0) located at the upper-left of <CODE>src</CODE>.</td>
74</tr>
75<tr>
76<td style="width:13%"><CODE>width</CODE></td>
77<td style="width:87%">Width of the region to process.</td>
78</tr>
79<tr>
80<td style="width:13%"><CODE>height</CODE></td>
81<td style="width:87%">Height of the region to process.</td>
82</tr>
83<tr>
84<td style="width:13%"><CODE>callback</CODE></td>
85<td style="width:87%">Callback function when processing ends.</td>
86</tr>
87</tbody>
88</table>
89
90<h2>Return Values</h2>
91<p>Returns <CODE>TRUE</CODE> when processing ends normally.<br>Returns <CODE>FALSE</CODE> when conversion did not end normally or the graphics component is already processing something.</p>
92
93<h2>Description</h2>
94<p>Uses the DSP to expand or shrink image data.</p>
95
96<p>The addresses indicated by <CODE>src</CODE> and <CODE>dst</CODE> must be 4-byte aligned.</p>
97<p>This function uses the AHB to transfer data between main memory and the DSP (WRAM-C). Data transfers between main memory and the DSP run at a lower priority than DMA data transfers, so AHB arbitration causes delays if another process uses frequent DMA transfers while scaling is being processed.</p>
98
99<p>The scaling is specified by a floating-point number (<CODE>f32</CODE>) that is converted internally to a fixed-point number and calculated. Due to loss of precision during floating-point calculations, the post-conversion size may differ from the intended value. However, you can use the <a href="DSP_Macro.html"><CODE>DSP_CALC_SCALING_SIZE</CODE></a> macro to calculate the post-conversion size that results from the <CODE>DSP_Scaling*</CODE> functions. We have also provided <a href="DSP_CalcScalingFactor.html"><code>DSP_CalcScalingFactor32</code></a>, a function that takes the post-conversion size as an argument and gets the scaling factors to pass to this function.
100</p>
101
102<p><span style='color:Red'>Note that there are restrictions in this function for values that can be specified as arguments because of design issues of the internal processes. For more information, see <B>Note</B>, below.</span></p>
103
104<p>
105The interpolation method used while processing is defined by <CODE>DSPGraphicsScalingMode</CODE> as follows.
106</p>
107<pre><code>
108typedef DSPWord DSPGraphicsScalingMode;
109#define DSP_GRAPHICS_SCALING_MODE_N_NEIGHBOR (DSPGraphicsScalingMode)0x0001
110#define DSP_GRAPHICS_SCALING_MODE_BILINEAR   (DSPGraphicsScalingMode)0x0002
111#define DSP_GRAPHICS_SCALING_MODE_BICUBIC    (DSPGraphicsScalingMode)0x0003
112</code></pre>
113<p>Starting from the top, these represent nearest-neighbor, bilinear, and bicubic interpolation. As a basic rule, processing time increases as you move down the list.
114</p>
115
116<p>When the asynchronous versions of this function (<CODE>*Async</CODE>) are run, the callback function registered as an argument is invoked to send a notification that conversion has finished. <span style='color:Red'>Callback functions are invoked by interrupts from the DSP. If interrupts have been prohibited by a function such as <A href="../../os/irq/OS_DisableIrq.html"><CODE>OS_DisableIrq</CODE></A>, completion notifications from the DSP are missed, and callbacks never return. Do not disable DSP interrupts from another process while asynchronous versions of this function are running.</span>
117</p>
118
119<p>With the <CODE>*Ex</CODE> versions of this function, you can specify an arbitrary region of the source image and process only that region.
120</p>
121
122<h2>Note</h2>
123<p>In the synchronous version, the <code>OS_Sleep</code> function waits for the process to complete. Therefore, call the <A href="../../os/thread/OS_InitThread.html"><CODE>OS_InitThread</CODE></A>, <A href="../../os/time/OS_InitTick.html"><CODE>OS_InitTick</CODE></A>, and <A href="../../os/alarm/OS_InitAlarm.html"><CODE>OS_InitAlarm</CODE></A> functions beforehand.</p>
124
125<p>Be careful because when the following conditions are met with this function, the internal DSP process does not end. If the conditions are met <a href="../../os/debug/SDK_ASSERT.html"><CODE>SDK_ASSERTMSG</CODE></a> is called.
126</p>
127
128<ul>
129<li>When the post-process data size is larger than the size of the original data
130<table style="width:80%">
131<tbody>
132<tr>
133<td style="width:55%"><B>mode</B></td><td><B>Condition</B></td>
134</tr>
135<tr>
136<td><CODE>DSP_GRAPHICS_SCALING_MODE_N_NEIGHBOR<br>DSP_GRAPHICS_SCALING_MODE_BILINEAR</CODE></td>
137<td>(Width of output data) (vertical scaling factor) &gt;=8192</td>
138</tr><tr>
139<td><CODE>DSP_GRAPHICS_SCALING_MODE_BICUBIC</CODE></td>
140<td>(Width of output data) (vertical scaling factor) &gt;=4096</td>
141</tr>
142</tbody>
143</table>
144
145<li>When the post-process data size is smaller than the size of the original data
146<table style="width:80%">
147<tbody>
148<tr>
149<td style="width:55%"><B>mode</B></td><td><B>Condition</B></td>
150</tr>
151<tr>
152<td><CODE>DSP_GRAPHICS_SCALING_MODE_N_NEIGHBOR<br>DSP_GRAPHICS_SCALING_MODE_BILINEAR</CODE></td>
153<td>(Width of input data) &gt;=8192 </td>
154<tr>
155<td><CODE>DSP_GRAPHICS_SCALING_MODE_BICUBIC</CODE></td>
156<td>(Width of input data) &gt;=4096 </td>
157</tr>
158</tbody>
159</table>
160</ul>
161
162<h2>See Also</h2>
163<p><a href="DSP_LoadGraphics.html"><CODE>DSP_LoadGraphics</CODE></a><BR> <a href="DSP_UnloadGraphics.html"><CODE>DSP_UnloadGraphics</CODE></a><BR> <a href="DSP_ScalingFx.html"><CODE>DSP_ScalingFx*</CODE></a><BR> <a href="../../os/irq/OS_DisableIrq.html"><CODE>OS_DisableIrq</CODE></a><BR> <a href="DSP_Macro.html"><CODE>DSP_CALC_SCALING_SIZE</CODE></a><BR> <a href="DSP_CalcScalingFactor.html"><CODE>DSP_CalcScalingFactor*</CODE></a></p>
164
165<h2>Revision History</h2>
166<p>
1672009/04/03 Added descriptions about the restrictions related to arguments in <B>Note</B>.<br> 2008/10/22 Added a note about changes in the synchronous function.<br> 2008/09/06 Added information on data transfer methods. <br>2008/08/28 Added information to <B>Description</B> about a function that calculates factors. Also added links and descriptions of the <CODE>fx32</CODE> version. <br>2008/08/18 Described how prohibiting DSP interrupts affect asynchronous versions. <br>2008/05/22 Initial version.
168</p>
169<hr><p>CONFIDENTIAL</p></body>
170</html>
171