source: rtems/c/src/lib/libbsp/arm/nds/libnds/source/arm9/image.c @ 32b8506

4.104.115
Last change on this file since 32b8506 was 32b8506, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 14:53:02

Whitespace removal.

  • Property mode set to 100644
File size: 12.2 KB
Line 
1/*---------------------------------------------------------------------------------
2        $Id$
3
4
5        Copyright (C) 2005
6                Michael Noland (joat)
7                Jason Rogers (dovoto)
8                Dave Murphy (WinterMute)
9
10        This software is provided 'as-is', without any express or implied
11        warranty.  In no event will the authors be held liable for any
12        damages arising from the use of this software.
13
14        Permission is granted to anyone to use this software for any
15        purpose, including commercial applications, and to alter it and
16        redistribute it freely, subject to the following restrictions:
17
18        1.      The origin of this software must not be misrepresented; you
19                must not claim that you wrote the original software. If you use
20                this software in a product, an acknowledgment in the product
21                documentation would be appreciated but is not required.
22        2.      Altered source versions must be plainly marked as such, and
23                must not be misrepresented as being the original software.
24        3.      This notice may not be removed or altered from any source
25                distribution.
26
27        $Log$
28        Revision 1.1  2008/04/16 18:37:32  joel
29        2008-04-16      Matthieu Bucchianeri <mbucchia@gmail.com>
30
31                * ChangeLog, Makefile.am, README, bsp_specs, configure.ac,
32                mk_libnds.sh, patch.libnds, preinstall.am, block/block.c,
33                clock/clock.c, console/console.c, coproc/coproc.S, coproc/coproc.c,
34                coproc/coproc.ld, dswifi/dswifi_license.txt, dswifi/makefile,
35                dswifi/arm7/makefile, dswifi/arm7/source/wifi_arm7.c,
36                dswifi/arm7/source/wifi_arm7.h, dswifi/arm9/makefile,
37                dswifi/arm9/source/sgIP.c, dswifi/arm9/source/sgIP.h,
38                dswifi/arm9/source/sgIP_ARP.c, dswifi/arm9/source/sgIP_ARP.h,
39                dswifi/arm9/source/sgIP_Config.h, dswifi/arm9/source/sgIP_DHCP.c,
40                dswifi/arm9/source/sgIP_DHCP.h, dswifi/arm9/source/sgIP_DNS.c,
41                dswifi/arm9/source/sgIP_DNS.h, dswifi/arm9/source/sgIP_Hub.c,
42                dswifi/arm9/source/sgIP_Hub.h, dswifi/arm9/source/sgIP_ICMP.c,
43                dswifi/arm9/source/sgIP_ICMP.h, dswifi/arm9/source/sgIP_IP.c,
44                dswifi/arm9/source/sgIP_IP.h, dswifi/arm9/source/sgIP_TCP.c,
45                dswifi/arm9/source/sgIP_TCP.h, dswifi/arm9/source/sgIP_UDP.c,
46                dswifi/arm9/source/sgIP_UDP.h, dswifi/arm9/source/sgIP_memblock.c,
47                dswifi/arm9/source/sgIP_memblock.h,
48                dswifi/arm9/source/sgIP_sockets.c, dswifi/arm9/source/sgIP_sockets.h,
49                dswifi/arm9/source/wifi_arm9.c, dswifi/arm9/source/wifi_arm9.h,
50                dswifi/common/source/dsregs.h, dswifi/common/source/spinlock.h,
51                dswifi/common/source/spinlock.s, dswifi/common/source/wifi_shared.h,
52                dswifi/include/dswifi7.h, dswifi/include/dswifi9.h,
53                dswifi/include/dswifi_version.h, dswifi/include/netdb.h,
54                dswifi/include/sgIP_errno.h, dswifi/include/netinet/in.h, fb/fb.c,
55                fb/fb.h, include/bsp.h, include/my_ipc.h, include/tm27.h,
56                include/types.h, include/sys/iosupport.h, irq/irq.c, irq/irq.h,
57                libfat/gba/include/fat.h, libfat/include/fat.h,
58                libfat/nds/include/fat.h, libfat/source/bit_ops.h,
59                libfat/source/cache.c, libfat/source/cache.h, libfat/source/common.h,
60                libfat/source/directory.c, libfat/source/directory.h,
61                libfat/source/fatdir.c, libfat/source/fatdir.h,
62                libfat/source/fatfile.c, libfat/source/fatfile.h,
63                libfat/source/file_allocation_table.c,
64                libfat/source/file_allocation_table.h, libfat/source/filetime.c,
65                libfat/source/filetime.h, libfat/source/libfat.c,
66                libfat/source/mem_allocate.h, libfat/source/partition.c,
67                libfat/source/partition.h, libfat/source/disc_io/disc.c,
68                libfat/source/disc_io/disc.h, libfat/source/disc_io/disc_io.h,
69                libfat/source/disc_io/io_cf_common.c,
70                libfat/source/disc_io/io_cf_common.h,
71                libfat/source/disc_io/io_dldi.h, libfat/source/disc_io/io_dldi.s,
72                libfat/source/disc_io/io_efa2.c, libfat/source/disc_io/io_efa2.h,
73                libfat/source/disc_io/io_fcsr.c, libfat/source/disc_io/io_fcsr.h,
74                libfat/source/disc_io/io_m3_common.c,
75                libfat/source/disc_io/io_m3_common.h,
76                libfat/source/disc_io/io_m3cf.c, libfat/source/disc_io/io_m3cf.h,
77                libfat/source/disc_io/io_m3sd.c, libfat/source/disc_io/io_m3sd.h,
78                libfat/source/disc_io/io_mpcf.c, libfat/source/disc_io/io_mpcf.h,
79                libfat/source/disc_io/io_njsd.c, libfat/source/disc_io/io_njsd.h,
80                libfat/source/disc_io/io_nmmc.c, libfat/source/disc_io/io_nmmc.h,
81                libfat/source/disc_io/io_sc_common.c,
82                libfat/source/disc_io/io_sc_common.h,
83                libfat/source/disc_io/io_sccf.c, libfat/source/disc_io/io_sccf.h,
84                libfat/source/disc_io/io_scsd.c, libfat/source/disc_io/io_scsd.h,
85                libfat/source/disc_io/io_scsd_s.s,
86                libfat/source/disc_io/io_sd_common.c,
87                libfat/source/disc_io/io_sd_common.h, libnds/Makefile.arm7,
88                libnds/Makefile.arm9, libnds/libnds_license.txt,
89                libnds/basicARM7/source/defaultARM7.c,
90                libnds/include/default_font_bin.h, libnds/include/gbfs.h,
91                libnds/include/nds.h, libnds/include/nds/bios.h,
92                libnds/include/nds/card.h, libnds/include/nds/dma.h,
93                libnds/include/nds/interrupts.h, libnds/include/nds/ipc.h,
94                libnds/include/nds/jtypes.h, libnds/include/nds/memory.h,
95                libnds/include/nds/registers_alt.h, libnds/include/nds/reload.h,
96                libnds/include/nds/system.h, libnds/include/nds/timers.h,
97                libnds/include/nds/arm7/audio.h, libnds/include/nds/arm7/clock.h,
98                libnds/include/nds/arm7/serial.h, libnds/include/nds/arm7/touch.h,
99                libnds/include/nds/arm9/background.h,
100                libnds/include/nds/arm9/boxtest.h, libnds/include/nds/arm9/cache.h,
101                libnds/include/nds/arm9/console.h,
102                libnds/include/nds/arm9/exceptions.h,
103                libnds/include/nds/arm9/image.h, libnds/include/nds/arm9/input.h,
104                libnds/include/nds/arm9/math.h, libnds/include/nds/arm9/ndsmotion.h,
105                libnds/include/nds/arm9/pcx.h, libnds/include/nds/arm9/postest.h,
106                libnds/include/nds/arm9/rumble.h, libnds/include/nds/arm9/sound.h,
107                libnds/include/nds/arm9/sprite.h, libnds/include/nds/arm9/trig_lut.h,
108                libnds/include/nds/arm9/video.h, libnds/include/nds/arm9/videoGL.h,
109                libnds/source/arm7/audio.c, libnds/source/arm7/clock.c,
110                libnds/source/arm7/microphone.c, libnds/source/arm7/spi.c,
111                libnds/source/arm7/touch.c, libnds/source/arm7/userSettings.c,
112                libnds/source/arm9/COS.bin, libnds/source/arm9/COS.s,
113                libnds/source/arm9/SIN.bin, libnds/source/arm9/SIN.s,
114                libnds/source/arm9/TAN.bin, libnds/source/arm9/TAN.s,
115                libnds/source/arm9/boxtest.c, libnds/source/arm9/console.c,
116                libnds/source/arm9/dcache.s, libnds/source/arm9/default_font.bin,
117                libnds/source/arm9/default_font.s,
118                libnds/source/arm9/exceptionHandler.S,
119                libnds/source/arm9/exceptionHandler.s,
120                libnds/source/arm9/exceptions.c, libnds/source/arm9/gurumeditation.c,
121                libnds/source/arm9/icache.s, libnds/source/arm9/image.c,
122                libnds/source/arm9/initSystem.c, libnds/source/arm9/keys.c,
123                libnds/source/arm9/ndsmotion.c, libnds/source/arm9/pcx.c,
124                libnds/source/arm9/rumble.c, libnds/source/arm9/sound.c,
125                libnds/source/arm9/system.c, libnds/source/arm9/touch.c,
126                libnds/source/arm9/video.c, libnds/source/arm9/videoGL.c,
127                libnds/source/common/biosCalls.s, libnds/source/common/card.c,
128                libnds/source/common/gbfs.c,
129                libnds/source/common/interruptDispatcher.s,
130                libnds/source/common/interrupts.c, rtc/rtc.c, sound/sound.c,
131                sound/sound.h, start/start.S, startup/linkcmds, startup/start.c,
132                timer/timer.c, tools/Makefile.am, tools/bin2s, tools/bin2s.c,
133                tools/configure.ac, tools/runtest,
134                tools/ndstool/include/arm7_sha1_homebrew.h,
135                tools/ndstool/include/arm7_sha1_nintendo.h,
136                tools/ndstool/include/banner.h, tools/ndstool/include/bigint.h,
137                tools/ndstool/include/crc.h, tools/ndstool/include/default_icon.h,
138                tools/ndstool/include/encryption.h, tools/ndstool/include/header.h,
139                tools/ndstool/include/hook.h, tools/ndstool/include/little.h,
140                tools/ndstool/include/loadme.h, tools/ndstool/include/logo.h,
141                tools/ndstool/include/ndscreate.h,
142                tools/ndstool/include/ndsextract.h, tools/ndstool/include/ndstool.h,
143                tools/ndstool/include/ndstree.h, tools/ndstool/include/overlay.h,
144                tools/ndstool/include/passme.h, tools/ndstool/include/passme_sram.h,
145                tools/ndstool/include/passme_vhd1.h,
146                tools/ndstool/include/passme_vhd2.h, tools/ndstool/include/raster.h,
147                tools/ndstool/include/sha1.h, tools/ndstool/include/types.h,
148                tools/ndstool/source/arm7_sha1_homebrew.c,
149                tools/ndstool/source/arm7_sha1_nintendo.c,
150                tools/ndstool/source/banner.cpp, tools/ndstool/source/bigint.cpp,
151                tools/ndstool/source/compile_date.c, tools/ndstool/source/crc.cpp,
152                tools/ndstool/source/default_icon.c,
153                tools/ndstool/source/encryption.cpp, tools/ndstool/source/header.cpp,
154                tools/ndstool/source/hook.cpp, tools/ndstool/source/loadme.c,
155                tools/ndstool/source/logo.cpp, tools/ndstool/source/ndscodes.cpp,
156                tools/ndstool/source/ndscreate.cpp,
157                tools/ndstool/source/ndsextract.cpp,
158                tools/ndstool/source/ndstool.cpp, tools/ndstool/source/ndstree.cpp,
159                tools/ndstool/source/passme.cpp, tools/ndstool/source/passme_sram.c,
160                tools/ndstool/source/raster.cpp, tools/ndstool/source/sha1.cpp,
161                touchscreen/README.reco, touchscreen/parser.c, touchscreen/reco.c,
162                touchscreen/reco.h, touchscreen/touchscreen.c,
163                touchscreen/touchscreen.h, wifi/compat.c, wifi/compat.h, wifi/wifi.c:
164                New files.
165
166        Revision 1.7  2007/01/19 14:46:00  wntrmute
167        name anonymous structs and unions for -std=c99
168
169        Revision 1.6  2005/10/11 05:05:26  dovoto
170        Added imageTileData(sImage* img) to allow loading of pcx as sprite data.
171        Updated pcx.c to set image bit per pixel field
172
173        Revision 1.5  2005/08/30 17:54:45  wntrmute
174        only include required headers
175
176        Revision 1.4  2005/08/22 08:10:35  wntrmute
177        reformatted for consistency
178
179        Revision 1.3  2005/08/11 14:53:00  desktopman
180        Added image24to16(sImage* img)
181
182        Revision 1.2  2005/08/01 23:18:22  wntrmute
183        adjusted headers for logging
184
185        Revision 1.1  2005/07/27 02:20:52  wntrmute
186        add image functions
187
188
189---------------------------------------------------------------------------------*/
190#include <nds/jtypes.h>
191#include <nds/arm9/image.h>
192#include <nds/dma.h>
193
194
195#include <malloc.h>
196
197//---------------------------------------------------------------------------------
198void image24to16(sImage* img) {
199//---------------------------------------------------------------------------------
200
201        int x;
202        int y;
203
204        u16* temp = (u16*)malloc(img->height*img->width*2);
205
206        for(y=0;y<img->height;y++)
207        {
208                for(x=0;x<img->width;x++)
209                        temp[x+y*img->width]=(1<<15)|RGB15(img->image.data8[x*3+y*img->width*3]>>3, \
210                        img->image.data8[x*3+y*img->width*3+1]>>3, img->image.data8[x*3+y*img->width*3+2]>>3);
211        }
212
213        free(img->image.data8);
214
215        img->bpp=16;
216        img->image.data16 = temp;
217}
218
219//---------------------------------------------------------------------------------
220void image8to16(sImage* img) {
221//---------------------------------------------------------------------------------
222        int i;
223
224        u16* temp = (u16*)malloc(img->height*img->width*2);
225
226        for(i = 0; i < img->height * img->width; i++)
227                temp[i] = img->palette[img->image.data8[i]] | (1<<15);
228
229        free (img->image.data8);
230        free (img->palette);
231
232        img->bpp = 16;
233        img->image.data16 = temp;
234}
235
236//---------------------------------------------------------------------------------
237void image8to16trans(sImage* img, u8 transparentColor) {
238//---------------------------------------------------------------------------------
239        int i;
240        u8 c;
241
242        u16* temp = (u16*)malloc(img->height*img->width*2);
243
244        for(i = 0; i < img->height * img->width; i++) {
245
246                c = img->image.data8[i];
247
248                if(c != transparentColor)
249                        temp[i] = img->palette[c] | (1<<15);
250                else
251                        temp[i] = img->palette[c];
252        }
253
254        free (img->image.data8);
255        free (img->palette);
256
257        img->bpp = 16;
258        img->image.data16 = temp;
259}
260//---------------------------------------------------------------------------------
261void imageTileData(sImage* img) {
262//---------------------------------------------------------------------------------
263        u32* temp;
264
265        int ix, iy, tx, ty;
266
267        int th, tw;
268
269        int i = 0;
270
271        //can only tile 8 bit data that is a multiple of 8 in dimention
272        if(img->bpp != 8 || (img->height & 3) != 0 || (img->width & 3) != 0) return;
273
274        th = img->height >> 3;
275        tw = img->width >> 3;
276
277        //buffer to hold data
278        temp = (u32*)malloc(img->height * img->width);
279
280        for(ty = 0; ty < th; ty++)
281                for(tx = 0; tx < tw; tx++)
282                        for(iy = 0; iy < 8; iy++)
283                                for(ix = 0; ix < 2; ix++)
284                                        temp[i++] = img->image.data32[ix + tx * 2 + (iy + ty * 8) * tw * 2 ];
285
286        free(img->image.data32);
287
288        img->image.data32 = temp;
289}
290
291//---------------------------------------------------------------------------------
292void imageDestroy(sImage* img) {
293//---------------------------------------------------------------------------------
294        if(img->image.data8) free (img->image.data8);
295        if(img->palette && img->bpp == 8) free (img->palette);
296}
Note: See TracBrowser for help on using the repository browser.