annotate src/dmimage.c @ 1135:73808dce89e6

Disable formats other than PNG and JPEG from stb_image.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 04 Mar 2015 08:50:08 +0200
parents e06abfde6c39
children 2e728c38a386
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Bitmap image conversion and loading
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
950
88d9440afad0 Use dmzlib module in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
5 * (C) Copyright 2012-2015 Tecnic Software productions (TNSP)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmimage.h"
950
88d9440afad0 Use dmzlib module in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
8 #include "dmzlib.h"
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
1135
73808dce89e6 Disable formats other than PNG and JPEG from stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
10 // Formats
73808dce89e6 Disable formats other than PNG and JPEG from stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
11 #define STBI_ONLY_JPEG 1
73808dce89e6 Disable formats other than PNG and JPEG from stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
12 #define STBI_ONLY_PNG 1
73808dce89e6 Disable formats other than PNG and JPEG from stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
13 //#define STBI_NO_HDR 1
73808dce89e6 Disable formats other than PNG and JPEG from stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
14
73808dce89e6 Disable formats other than PNG and JPEG from stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
15 // Other options, etc.
1046
7e54b2d08ce7 Add special debug error message function/macro that can be
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
16 #ifndef DM_DEBUG
900
df2a9c635175 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 899
diff changeset
17 #define STBI_NO_FAILURE_STRINGS 1
1046
7e54b2d08ce7 Add special debug error message function/macro that can be
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
18 #endif
900
df2a9c635175 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 899
diff changeset
19 #define STBI_FAILURE_USERMSG 1
df2a9c635175 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 899
diff changeset
20
899
63fd1801f983 Mangle new stb_image to our purposes.
Matti Hamalainen <ccr@tnsp.org>
parents: 870
diff changeset
21 #define STB_IMAGE_IMPLEMENTATION 1
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 #define STBI_NO_STDIO 1
899
63fd1801f983 Mangle new stb_image to our purposes.
Matti Hamalainen <ccr@tnsp.org>
parents: 870
diff changeset
23
63fd1801f983 Mangle new stb_image to our purposes.
Matti Hamalainen <ccr@tnsp.org>
parents: 870
diff changeset
24 #define STBI_MALLOC(sz) dmMalloc(sz)
63fd1801f983 Mangle new stb_image to our purposes.
Matti Hamalainen <ccr@tnsp.org>
parents: 870
diff changeset
25 #define STBI_REALLOC(p,sz) dmRealloc(p,sz)
63fd1801f983 Mangle new stb_image to our purposes.
Matti Hamalainen <ccr@tnsp.org>
parents: 870
diff changeset
26 #define STBI_FREE(p) dmFree(p)
63fd1801f983 Mangle new stb_image to our purposes.
Matti Hamalainen <ccr@tnsp.org>
parents: 870
diff changeset
27
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #include "stb_image.c"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 SDL_Surface *dmCreateRGBSurfaceFrom(void *data, const int width, const int height, const int depth, const int pitch, const int rmask, const int gmask, const int bmask, const int amask)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
757
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
33 // Create source surface from given data
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
34 SDL_Surface *tmp = SDL_CreateRGBSurfaceFrom(data, width, height, depth, pitch, bmask, gmask, rmask, amask);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
757
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
36 // Result surface component orders as masks
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
37 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
38 Uint32
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
39 Xrmask = 0xff000000,
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
40 Xgmask = 0x00ff0000,
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
41 Xbmask = 0x0000ff00,
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
42 Xamask = 0x000000ff;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
43 #else
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44 Uint32
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
45 Xrmask = 0x000000ff,
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
46 Xgmask = 0x0000ff00,
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
47 Xbmask = 0x00ff0000,
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
48 Xamask = 0xff000000;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
49 #endif
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
50
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
51 // Create result conversion surface
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
52 SDL_Surface
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
53 *result = NULL,
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
54 *pixtmp = SDL_CreateRGBSurface(
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
55 SDL_SWSURFACE | SDL_SRCALPHA, 16, 16, 32, Xrmask, Xgmask, Xbmask, Xamask);
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
56
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 if (tmp != NULL && pixtmp != NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 {
757
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
59 // Convert surface
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 result = SDL_ConvertSurface(tmp, pixtmp->format, SDL_SWSURFACE | SDL_SRCALPHA);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 SDL_FreeSurface(tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 if (pixtmp != NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 SDL_FreeSurface(pixtmp);
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1080
diff changeset
65
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 return result;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 SDL_Surface *dmCreatePaletteSurfaceFrom(void *data, const int width, const int height, const int pitch)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 int yc;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 Uint8 *dst, *src;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 SDL_Surface *result;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 result = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8, 0,0,0,0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 if (result == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 return NULL;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1080
diff changeset
78
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 dst = result->pixels;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 src = data;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 for (yc = 0; yc < height; yc++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 memcpy(dst, src, width * sizeof(Uint8));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 dst += result->pitch;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 src += pitch;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 return result;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 static int dmSTBIread(void *user, char *data, int size)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 return dmfread(data, 1, size, (DMResource *) user);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
899
63fd1801f983 Mangle new stb_image to our purposes.
Matti Hamalainen <ccr@tnsp.org>
parents: 870
diff changeset
99 static void dmSTBIskip(void *user, int n)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 dmfseek((DMResource *) user, n, SEEK_CUR);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 static int dmSTBIeof(void *user)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 return dmfeof((DMResource *) user);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 static const stbi_io_callbacks dmSTBICallbacks =
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 dmSTBIread,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 dmSTBIskip,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 dmSTBIeof,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 SDL_Surface *dmLoadImage(DMResource *file)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 Uint32 rmask, gmask, bmask, amask;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 SDL_Surface *result = NULL;
963
1ffc48d0feaf Initialize variables so that we don't get garbage in error situations.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
123 int width = 0, height = 0, comp = 0;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 Uint8 *data;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
1042
c71fcf44b678 Image resources may get decoded multiple times, so seek to node start.
Matti Hamalainen <ccr@tnsp.org>
parents: 963
diff changeset
126 dmfseek(file, 0, SEEK_SET);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 data = stbi_load_from_callbacks(&dmSTBICallbacks, file, &width, &height, &comp, 0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 if (data == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 {
1080
76b7d1d20545 Change message to debug.
Matti Hamalainen <ccr@tnsp.org>
parents: 1048
diff changeset
131 dmErrorDBGMsg(
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 950
diff changeset
132 "Error decoding image resource %p '%s' [%d, %d, %d]: %s\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 file, file->filename, width, height, comp, stbi_failure_reason());
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 return NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 switch (comp)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 case 4:
757
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
141 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
142 rmask = 0xff000000;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
143 gmask = 0x00ff0000;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
144 bmask = 0x0000ff00;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
145 amask = 0x000000ff;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
146 #else
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
147 rmask = 0x000000ff;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
148 gmask = 0x0000ff00;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
149 bmask = 0x00ff0000;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
150 amask = 0xff000000;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
151 #endif
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
152 result = dmCreateRGBSurfaceFrom(data, width, height, comp * 8,
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
153 width * comp, rmask, gmask, bmask, amask);
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
154 break;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
155
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 case 3:
757
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
157 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
158 rmask = 0x00ff0000;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
159 gmask = 0x0000ff00;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
160 bmask = 0x000000ff;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
161 amask = 0x00000000;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
162 #else
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
163 rmask = 0x000000ff;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
164 gmask = 0x0000ff00;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
165 bmask = 0x00ff0000;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
166 amask = 0x00000000;
dd59a650a318 Fix 24-bit surface conversions in image loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
167 #endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 result = dmCreateRGBSurfaceFrom(data, width, height, comp * 8,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 width * comp, rmask, gmask, bmask, amask);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 case 1:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 result = dmCreatePaletteSurfaceFrom(data, width, height, width * comp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1080
diff changeset
176
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 stbi_image_free(data);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 if (result == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 {
1048
509e6ed3a24e Finishing touches to the DM_DEBUG stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 1046
diff changeset
181 dmErrorDBGMsg(
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 950
diff changeset
182 "Format conversion failed for image resource %p '%s' [%d, %d, %d].\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 file, file->filename, width, height, comp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 return result;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 }