1 | /*--------------------------------------------------------------------------------- |
---|
2 | |
---|
3 | Copyright (C) 2005 |
---|
4 | Michael Noland (joat) |
---|
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 | ---------------------------------------------------------------------------------*/ |
---|
26 | #include <nds/jtypes.h> |
---|
27 | #include <nds/arm9/image.h> |
---|
28 | #include <nds/dma.h> |
---|
29 | |
---|
30 | |
---|
31 | #include <malloc.h> |
---|
32 | |
---|
33 | //--------------------------------------------------------------------------------- |
---|
34 | void image24to16(sImage* img) { |
---|
35 | //--------------------------------------------------------------------------------- |
---|
36 | |
---|
37 | int x; |
---|
38 | int y; |
---|
39 | |
---|
40 | u16* temp = (u16*)malloc(img->height*img->width*2); |
---|
41 | |
---|
42 | for(y=0;y<img->height;y++) |
---|
43 | { |
---|
44 | for(x=0;x<img->width;x++) |
---|
45 | temp[x+y*img->width]=(1<<15)|RGB15(img->image.data8[x*3+y*img->width*3]>>3, \ |
---|
46 | img->image.data8[x*3+y*img->width*3+1]>>3, img->image.data8[x*3+y*img->width*3+2]>>3); |
---|
47 | } |
---|
48 | |
---|
49 | free(img->image.data8); |
---|
50 | |
---|
51 | img->bpp=16; |
---|
52 | img->image.data16 = temp; |
---|
53 | } |
---|
54 | |
---|
55 | //--------------------------------------------------------------------------------- |
---|
56 | void image8to16(sImage* img) { |
---|
57 | //--------------------------------------------------------------------------------- |
---|
58 | int i; |
---|
59 | |
---|
60 | u16* temp = (u16*)malloc(img->height*img->width*2); |
---|
61 | |
---|
62 | for(i = 0; i < img->height * img->width; i++) |
---|
63 | temp[i] = img->palette[img->image.data8[i]] | (1<<15); |
---|
64 | |
---|
65 | free (img->image.data8); |
---|
66 | free (img->palette); |
---|
67 | |
---|
68 | img->bpp = 16; |
---|
69 | img->image.data16 = temp; |
---|
70 | } |
---|
71 | |
---|
72 | //--------------------------------------------------------------------------------- |
---|
73 | void image8to16trans(sImage* img, u8 transparentColor) { |
---|
74 | //--------------------------------------------------------------------------------- |
---|
75 | int i; |
---|
76 | u8 c; |
---|
77 | |
---|
78 | u16* temp = (u16*)malloc(img->height*img->width*2); |
---|
79 | |
---|
80 | for(i = 0; i < img->height * img->width; i++) { |
---|
81 | |
---|
82 | c = img->image.data8[i]; |
---|
83 | |
---|
84 | if(c != transparentColor) |
---|
85 | temp[i] = img->palette[c] | (1<<15); |
---|
86 | else |
---|
87 | temp[i] = img->palette[c]; |
---|
88 | } |
---|
89 | |
---|
90 | free (img->image.data8); |
---|
91 | free (img->palette); |
---|
92 | |
---|
93 | img->bpp = 16; |
---|
94 | img->image.data16 = temp; |
---|
95 | } |
---|
96 | //--------------------------------------------------------------------------------- |
---|
97 | void imageTileData(sImage* img) { |
---|
98 | //--------------------------------------------------------------------------------- |
---|
99 | u32* temp; |
---|
100 | |
---|
101 | int ix, iy, tx, ty; |
---|
102 | |
---|
103 | int th, tw; |
---|
104 | |
---|
105 | int i = 0; |
---|
106 | |
---|
107 | //can only tile 8 bit data that is a multiple of 8 in dimention |
---|
108 | if(img->bpp != 8 || (img->height & 3) != 0 || (img->width & 3) != 0) return; |
---|
109 | |
---|
110 | th = img->height >> 3; |
---|
111 | tw = img->width >> 3; |
---|
112 | |
---|
113 | //buffer to hold data |
---|
114 | temp = (u32*)malloc(img->height * img->width); |
---|
115 | |
---|
116 | for(ty = 0; ty < th; ty++) |
---|
117 | for(tx = 0; tx < tw; tx++) |
---|
118 | for(iy = 0; iy < 8; iy++) |
---|
119 | for(ix = 0; ix < 2; ix++) |
---|
120 | temp[i++] = img->image.data32[ix + tx * 2 + (iy + ty * 8) * tw * 2 ]; |
---|
121 | |
---|
122 | free(img->image.data32); |
---|
123 | |
---|
124 | img->image.data32 = (unsigned int *)temp; |
---|
125 | } |
---|
126 | |
---|
127 | //--------------------------------------------------------------------------------- |
---|
128 | void imageDestroy(sImage* img) { |
---|
129 | //--------------------------------------------------------------------------------- |
---|
130 | if(img->image.data8) free (img->image.data8); |
---|
131 | if(img->palette && img->bpp == 8) free (img->palette); |
---|
132 | } |
---|