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 that will 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'>This is valid between 31 and 0.001. Decimals will be 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'>This is valid between 31 and 0.001. Decimals will be 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 <SPAN class="argument">src</SPAN> and <SPAN class="argument">dst</SPAN> 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 <code><a href="DSP_Macro.html">DSP_CALC_SCALING_SIZE</a></code> macro to calculate the post-conversion size that will result 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>
103The interpolation method used while processing is defined by <CODE>DSPGraphicsScalingMode</CODE> as follows.
104</p>
105<pre><code>
106typedef DSPWord DSPGraphicsScalingMode;
107#define DSP_GRAPHICS_SCALING_MODE_N_NEIGHBOR (DSPGraphicsScalingMode)0x0001
108#define DSP_GRAPHICS_SCALING_MODE_BILINEAR   (DSPGraphicsScalingMode)0x0002
109#define DSP_GRAPHICS_SCALING_MODE_BICUBIC    (DSPGraphicsScalingMode)0x0003
110</code></pre>
111<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.
112</p>
113
114<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 will be missed and callbacks will not be called. Do not disable DSP interrupts from another process while asynchronous versions of this function are running.</span>
115</p>
116
117<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.
118</p>
119
120<h2>Note</h2>
121<p>In the synchronous version, the <code>OS_Sleep</code> function waits for the process to complete. Therefore, call the <code><A href="../../os/thread/OS_InitThread.html">OS_InitThread</A>, <A href="../../os/time/OS_InitTick.html">OS_InitTick</A>, and <A href="../../os/alarm/OS_InitAlarm.html">OS_InitAlarm</A></code> functions beforehand.</p>
122
123<h2>See Also</h2>
124<p><code><a href="DSP_CalcScalingFactor.html">DSP_CalcScalingFactor*</a><BR> <a href="DSP_Macro.html">DSP_CALC_SCALING_SIZE</a><BR> <a href="DSP_LoadGraphics.html">DSP_LoadGraphics</a><BR><a href="DSP_ScalingFx.html">DSP_ScalingFx*</a><BR> <a href="DSP_UnloadGraphics.html">DSP_UnloadGraphics</a><BR><a href="../../os/irq/OS_DisableIrq.html">OS_DisableIrq</a></code></p>
125
126<h2>Revision History</h2>
127<p>
1282008/10/22 Added a note about changes inside the synchronous function.<br>2008/09/06 Added information on data transfer methods. <br>2008/08/28 Added information to <B>Description</B> on a function that calculates factors. Also added links and descriptions of the <CODE>fx32</CODE> version. <br>2008/08/19 Described how prohibiting DSP interrupts affects asynchronous versions. <br>2008/05/22 Initial version.
129</p>
130<hr><p>CONFIDENTIAL</p></body>
131</html>
132