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