Bladeren bron

Added utils/pixels

Thomas Buck 11 jaren geleden
bovenliggende
commit
0617cfc738
8 gewijzigde bestanden met toevoegingen van 74 en 31 verwijderingen
  1. 0
    1
      TODO.md
  2. 9
    9
      include/Texture.h
  3. 14
    0
      include/utils/pixel.h
  4. 23
    19
      src/Texture.cpp
  5. 1
    0
      src/utils/CMakeLists.txt
  6. 25
    0
      src/utils/pixel.cpp
  7. 1
    1
      src/utils/strings.cpp
  8. 1
    1
      src/utils/time.cpp

+ 0
- 1
TODO.md Bestand weergeven

10
     * Rewrite Console and use operator << to write to the console?
10
     * Rewrite Console and use operator << to write to the console?
11
 * SDL_TTF 2.0.12+ can do line breaks, use it: http://stackoverflow.com/questions/17847818/how-to-do-line-breaks-and-line-wrapping-with-sdl-ttf/18418688#18418688
11
 * SDL_TTF 2.0.12+ can do line breaks, use it: http://stackoverflow.com/questions/17847818/how-to-do-line-breaks-and-line-wrapping-with-sdl-ttf/18418688#18418688
12
 * Mesh has 2 different approaches of storing the same data (eg. mColors and mColorArray), but half of ‘em isn’t implemented. Unify this, probably even reusing the Mesh class for the model_meshes...
12
 * Mesh has 2 different approaches of storing the same data (eg. mColors and mColorArray), but half of ‘em isn’t implemented. Unify this, probably even reusing the Mesh class for the model_meshes...
13
-* glTexImage2D has alignment requirements?!?! https://www.khronos.org/opengles/sdk/1.1/docs/man/glTexImage2D.xml
14
 
13
 
15
 ## Changes
14
 ## Changes
16
 
15
 

+ 9
- 9
include/Texture.h Bestand weergeven

9
 #ifndef _TEXTURE_H
9
 #ifndef _TEXTURE_H
10
 #define _TEXTURE_H
10
 #define _TEXTURE_H
11
 
11
 
12
-#include <stdio.h>
13
-
14
 /*!
12
 /*!
15
  * \brief Texture registry
13
  * \brief Texture registry
16
  */
14
  */
18
 public:
16
 public:
19
 
17
 
20
     enum ColorMode {
18
     enum ColorMode {
21
-        GREYSCALE = 1,
19
+        GREYSCALE,
22
         RGB,
20
         RGB,
23
         RGBA,
21
         RGBA,
24
-        ARGB
22
+        ARGB,
23
+        BGR,
24
+        BGRA
25
     };
25
     };
26
 
26
 
27
     enum TextureFlag {
27
     enum TextureFlag {
40
     ~Texture();
40
     ~Texture();
41
 
41
 
42
     /*!
42
     /*!
43
+     * \brief Resets all texture data
44
+     */
45
+    void reset();
46
+
47
+    /*!
43
      * \brief Generates a texture buffer with (width * height * 4) bytes.
48
      * \brief Generates a texture buffer with (width * height * 4) bytes.
44
      * \param rgba 32bpp RGBA color to fill into buffer
49
      * \param rgba 32bpp RGBA color to fill into buffer
45
      * \param width width of newly allocated buffer, power of 2, pref same as height
50
      * \param width width of newly allocated buffer, power of 2, pref same as height
125
     int loadPCX(const char *filename);
130
     int loadPCX(const char *filename);
126
 
131
 
127
     /*!
132
     /*!
128
-     * \brief Resets all texture data
129
-     */
130
-    void reset();
131
-
132
-    /*!
133
      * \brief Sets an option flag
133
      * \brief Sets an option flag
134
      * \param flag flag to set
134
      * \param flag flag to set
135
      */
135
      */

+ 14
- 0
include/utils/pixel.h Bestand weergeven

1
+/*!
2
+ * \file include/utils/pixel.h
3
+ * \brief Pixel buffer utilities
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _UTILS_PIXEL_H_
9
+#define _UTILS_PIXEL_H_
10
+
11
+void argb2rgba32(unsigned char *image, unsigned int w, unsigned int h);
12
+
13
+#endif
14
+

+ 23
- 19
src/Texture.cpp Bestand weergeven

13
 
13
 
14
 #include "global.h"
14
 #include "global.h"
15
 #include "utils/pcx.h"
15
 #include "utils/pcx.h"
16
+#include "utils/pixel.h"
16
 #include "utils/strings.h"
17
 #include "utils/strings.h"
17
 #include "utils/tga.h"
18
 #include "utils/tga.h"
18
 #include "Texture.h"
19
 #include "Texture.h"
164
     return id;
165
     return id;
165
 }
166
 }
166
 
167
 
167
-void convertARGB32bppToRGBA32bpp(unsigned char *image,
168
-        unsigned int w, unsigned int h) {
169
-    unsigned int i, size = w * h;
170
-
171
-    assert(image != NULL);
172
-    assert(w > 0);
173
-    assert(h > 0);
174
-
175
-    for (i = 0; i < size; ++i) {
176
-        /* 32-bit ARGB to RGBA */
177
-        unsigned char swap = image[(i * 4) + 3];
178
-        image[(i * 4)] = image[(i * 4) + 1];
179
-        image[(i * 4) + 1] = image[(i * 4) + 2];
180
-        image[(i * 4) + 2] = image[(i * 4) + 3];
181
-        image[(i * 4) + 3] = swap;
182
-    }
183
-}
184
-
185
 int Texture::loadBufferSlot(unsigned char *image,
168
 int Texture::loadBufferSlot(unsigned char *image,
186
         unsigned int width, unsigned int height,
169
         unsigned int width, unsigned int height,
187
         ColorMode mode, unsigned int bpp,
170
         ColorMode mode, unsigned int bpp,
205
             bytes = 1;
188
             bytes = 1;
206
             glcMode = GL_LUMINANCE;
189
             glcMode = GL_LUMINANCE;
207
             break;
190
             break;
191
+
208
         case RGB:
192
         case RGB:
209
             if (bpp != 24) {
193
             if (bpp != 24) {
210
                 printf("Texture::Load ERROR Unsupported RGB, %i bpp\n", bpp);
194
                 printf("Texture::Load ERROR Unsupported RGB, %i bpp\n", bpp);
213
             bytes = 3;
197
             bytes = 3;
214
             glcMode = GL_RGB;
198
             glcMode = GL_RGB;
215
             break;
199
             break;
200
+
216
         case ARGB:
201
         case ARGB:
217
             if (bpp == 32) {
202
             if (bpp == 32) {
218
-                convertARGB32bppToRGBA32bpp(image, width, height);
203
+                argb2rgba32(image, width, height);
219
             } else {
204
             } else {
220
                 printf("Texture::Load ERROR Unsupported ARGB, %i bpp\n", bpp);
205
                 printf("Texture::Load ERROR Unsupported ARGB, %i bpp\n", bpp);
221
                 return -1;
206
                 return -1;
223
             bytes = 4;
208
             bytes = 4;
224
             glcMode = GL_RGBA;
209
             glcMode = GL_RGBA;
225
             break;
210
             break;
211
+
226
         case RGBA:
212
         case RGBA:
227
             if (bpp != 32) {
213
             if (bpp != 32) {
228
                 printf("Texture::Load ERROR Unsupported RGBA, %i bpp\n", bpp);
214
                 printf("Texture::Load ERROR Unsupported RGBA, %i bpp\n", bpp);
231
             bytes = 4;
217
             bytes = 4;
232
             glcMode = GL_RGBA;
218
             glcMode = GL_RGBA;
233
             break;
219
             break;
220
+
221
+        case BGR:
222
+            if (bpp != 24) {
223
+                printf("Texture::Load ERROR Unsupported BGR, %i bpp\n", bpp);
224
+                return -1;
225
+            }
226
+            bytes = 3;
227
+            glcMode = GL_BGR_EXT;
228
+            break;
229
+
230
+        case BGRA:
231
+            if (bpp != 32) {
232
+                printf("Texture::Load ERROR Unsupported BGRA, %i bpp\n", bpp);
233
+                return -1;
234
+            }
235
+            bytes = 4;
236
+            glcMode = GL_BGRA_EXT;
237
+            break;
234
     }
238
     }
235
 
239
 
236
     glClearColor(0.0, 0.0, 0.0, 0.0);
240
     glClearColor(0.0, 0.0, 0.0, 0.0);

+ 1
- 0
src/utils/CMakeLists.txt Bestand weergeven

1
 # Source files
1
 # Source files
2
 set (UTIL_SRCS ${UTIL_SRCS} "pcx.cpp")
2
 set (UTIL_SRCS ${UTIL_SRCS} "pcx.cpp")
3
+set (UTIL_SRCS ${UTIL_SRCS} "pixel.cpp")
3
 set (UTIL_SRCS ${UTIL_SRCS} "strings.cpp")
4
 set (UTIL_SRCS ${UTIL_SRCS} "strings.cpp")
4
 set (UTIL_SRCS ${UTIL_SRCS} "tga.cpp")
5
 set (UTIL_SRCS ${UTIL_SRCS} "tga.cpp")
5
 set (UTIL_SRCS ${UTIL_SRCS} "time.cpp")
6
 set (UTIL_SRCS ${UTIL_SRCS} "time.cpp")

+ 25
- 0
src/utils/pixel.cpp Bestand weergeven

1
+/*!
2
+ * \file src/utils/pixel.cpp
3
+ * \brief Pixel buffer utilities
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "utils/pixel.h"
10
+
11
+void argb2rgba32(unsigned char *image, unsigned int w, unsigned int h) {
12
+    assert(image != nullptr);
13
+    assert(w > 0);
14
+    assert(h > 0);
15
+
16
+    for (unsigned int i = 0; i < (w * h); ++i) {
17
+        /* 32-bit ARGB to RGBA */
18
+        unsigned char swap = image[(i * 4) + 3];
19
+        image[(i * 4)] = image[(i * 4) + 1];
20
+        image[(i * 4) + 1] = image[(i * 4) + 2];
21
+        image[(i * 4) + 2] = image[(i * 4) + 3];
22
+        image[(i * 4) + 3] = swap;
23
+    }
24
+}
25
+

+ 1
- 1
src/utils/strings.cpp Bestand weergeven

1
 /*!
1
 /*!
2
- * \file include/utils/strings.h
2
+ * \file src/utils/strings.cpp
3
  * \brief String handling utilities
3
  * \brief String handling utilities
4
  *
4
  *
5
  * \author xythobuz
5
  * \author xythobuz

+ 1
- 1
src/utils/time.cpp Bestand weergeven

1
 /*!
1
 /*!
2
- * \file include/utils/time.h
2
+ * \file src/utils/time.cpp
3
  * \brief Time handling utilities
3
  * \brief Time handling utilities
4
  *
4
  *
5
  * \author xythobuz
5
  * \author xythobuz

Laden…
Annuleren
Opslaan