|
@@ -1,113 +1,92 @@
|
1
|
|
-/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
|
2
|
|
-/*================================================================
|
|
1
|
+/*!
|
|
2
|
+ * \file include/tga.h
|
|
3
|
+ * \brief TGA image reader/writer
|
3
|
4
|
*
|
4
|
|
- * Project : Freyja
|
5
|
|
- * Author : Mongoose
|
6
|
|
- * Website : http://www.westga.edu/~stu7440/
|
7
|
|
- * Email : stu7440@westga.edu
|
8
|
|
- * Object :
|
9
|
|
- * License : GPL See file COPYING, also (C) 2000 Mongoose
|
10
|
|
- * Comments: TGA plug-in
|
11
|
|
- *
|
12
|
|
- *
|
13
|
|
- * This file was generated using Mongoose's C++
|
14
|
|
- * template generator script. <stu7440@westga.edu>
|
15
|
|
- *
|
16
|
|
- *-- History ------------------------------------------------
|
17
|
|
- *
|
18
|
|
- * 2000-10-15:
|
19
|
|
- * Mongoose - Created
|
20
|
|
- ================================================================*/
|
21
|
|
-
|
|
5
|
+ * \author Mongoose
|
|
6
|
+ * \author xythobuz
|
|
7
|
+ */
|
22
|
8
|
#ifndef _TGA_H
|
23
|
9
|
#define _TGA_H
|
24
|
10
|
|
25
|
11
|
#include <stdio.h>
|
26
|
12
|
|
27
|
|
-
|
28
|
|
-typedef enum
|
29
|
|
-{
|
30
|
|
- TGA_TYPE__NO_DATA = 0,
|
31
|
|
- TGA_TYPE__MAPPED = 1,
|
32
|
|
- TGA_TYPE__COLOR = 2,
|
33
|
|
- TGA_TYPE__GREYSCALE = 3,
|
34
|
|
- TGA_TYPE__MAPPED_RLE = 9,
|
35
|
|
- TGA_TYPE__COLOR_RLE = 10
|
36
|
|
- // TGA_TYPE__GREYSCALE_COMPRESSED = 11,
|
37
|
|
- // TGA_TYPE__COLOR_HUFFMAN_DELTA_RLE = 32,
|
38
|
|
- // TGA_TYPE__COLOR_HUFFMAN_DELTA_RLE_4PASS = 33
|
39
|
|
-
|
|
13
|
+/*!
|
|
14
|
+ * \brief Possible TGA image types
|
|
15
|
+ */
|
|
16
|
+typedef enum {
|
|
17
|
+ TGA_TYPE__NO_DATA = 0,
|
|
18
|
+ TGA_TYPE__MAPPED = 1,
|
|
19
|
+ TGA_TYPE__COLOR = 2,
|
|
20
|
+ TGA_TYPE__GREYSCALE = 3,
|
|
21
|
+ TGA_TYPE__MAPPED_RLE = 9,
|
|
22
|
+ TGA_TYPE__COLOR_RLE = 10
|
|
23
|
+ // TGA_TYPE__GREYSCALE_COMPRESSED = 11,
|
|
24
|
+ // TGA_TYPE__COLOR_HUFFMAN_DELTA_RLE = 32,
|
|
25
|
+ // TGA_TYPE__COLOR_HUFFMAN_DELTA_RLE_4PASS = 33
|
40
|
26
|
} tga_type_t;
|
41
|
27
|
|
|
28
|
+/*!
|
|
29
|
+ * \brief Data structure representing TGA file header
|
|
30
|
+ */
|
|
31
|
+typedef struct {
|
|
32
|
+ unsigned char comment_lenght; /*!< Number of bytes in comment */
|
|
33
|
+ unsigned char colormap_type; /*!< 0 No colormap; 1 Has colormap */
|
|
34
|
+ unsigned char image_type; /*!< 1 Colormapped; 2 Unmapped;
|
|
35
|
+ 9 Colormapped RLE; 10 Unmapped RLE */
|
|
36
|
+ unsigned short colormap_index; /*!< Index of first color map entry */
|
|
37
|
+ unsigned short colormap_lenght; /*!< Number of color map entries */
|
|
38
|
+ unsigned char colormap_bbp; /*!< 16, 24, or 32 bits per pixel format */
|
|
39
|
+ unsigned short origin_x; /*!< X coor of lower-left corner */
|
|
40
|
+ unsigned short origin_y; /*!< Y coor of lower-left corner */
|
|
41
|
+ unsigned short width; /*!< Width in pixels */
|
|
42
|
+ unsigned short height; /*!< Height in pixels */
|
|
43
|
+ unsigned char bpp; /*!< Number of bits in a pixel index */
|
|
44
|
+ unsigned char desc_flags; /*!< Various magic bits */
|
|
45
|
+} tga_t;
|
|
46
|
+
|
|
47
|
+/*!
|
|
48
|
+ * \brief Check if a file is a valid TGA image
|
|
49
|
+ * \param f file to be checked
|
|
50
|
+ * \returns 0 if valid, else error condition
|
|
51
|
+ */
|
|
52
|
+int tga_check(FILE *f);
|
|
53
|
+
|
|
54
|
+/*!
|
|
55
|
+ * \brief Load a TGA image from file
|
|
56
|
+ * \param f valid image file
|
|
57
|
+ * \param image Where the pixmap will be stored (or NULL)
|
|
58
|
+ * \param width where the width will be stored
|
|
59
|
+ * \param height where the height will be stored
|
|
60
|
+ * \param type where the type will be stored (tga_type_t)
|
|
61
|
+ * \returns 0 on success, else error condition
|
|
62
|
+ */
|
|
63
|
+int tga_load(FILE *f, unsigned char **image,
|
|
64
|
+ unsigned int *width, unsigned int *height, char *type);
|
|
65
|
+
|
|
66
|
+/*!
|
|
67
|
+ * \brief Save a pixel buffer into a file on disk
|
|
68
|
+ * \param f file in which image will be saved
|
|
69
|
+ * \param image pixmap to be stored
|
|
70
|
+ * \param width width of pixmap/image
|
|
71
|
+ * \param height height of pixmap/image
|
|
72
|
+ * \param type tga_type_t to use
|
|
73
|
+ * \returns 0 on success, else error condition
|
|
74
|
+ */
|
|
75
|
+int tga_save(FILE *f, unsigned char *image,
|
|
76
|
+ unsigned int width, unsigned int height, char type);
|
|
77
|
+
|
|
78
|
+/*!
|
|
79
|
+ * \brief Save a pixel buffer into a file on disk
|
|
80
|
+ * \param image pixmap to be stored
|
|
81
|
+ * \param width width of pixmap/image
|
|
82
|
+ * \param height height of pixmap/image
|
|
83
|
+ * \param type tga_type_t to use
|
|
84
|
+ * \param s format string for file path/name
|
|
85
|
+ * \returns 0 on success, else error condition
|
|
86
|
+ */
|
|
87
|
+int tga_save_filename(unsigned char *image,
|
|
88
|
+ unsigned int width, unsigned int height,
|
|
89
|
+ char type,
|
|
90
|
+ char *s, ...);
|
42
|
91
|
|
43
|
|
-typedef struct mtk_image_tga_s
|
44
|
|
-{
|
45
|
|
- unsigned char comment_lenght; /* Number of bytes in comment */
|
46
|
|
- unsigned char colormap_type; /* 0 No colormap; 1 Has colormap */
|
47
|
|
- unsigned char image_type; /* 1 Colormapped, 2 Unmapped;
|
48
|
|
- 9 Colormapped RLE; 10 Unmapped RLE */
|
49
|
|
-
|
50
|
|
- unsigned short colormap_index; /* Index of first color map entry */
|
51
|
|
- unsigned short colormap_lenght; /* Number of color map entries */
|
52
|
|
- unsigned char colormap_bbp; /* 16, 24, or 32 bits per pixel format */
|
53
|
|
-
|
54
|
|
- unsigned short origin_x; /* X coor of lower-left corner */
|
55
|
|
- unsigned short origin_y; /* Y coor of lower-left corner */
|
56
|
|
- unsigned short width; /* Width in pixels */
|
57
|
|
- unsigned short height; /* Height in pixels */
|
58
|
|
- unsigned char bpp; /* Number of bits in a pixel index */
|
59
|
|
- unsigned char desc_flags; /* Various magic bits */
|
60
|
|
-
|
61
|
|
-} mtk_image_tga_t;
|
62
|
|
-
|
63
|
|
-
|
64
|
|
- int mtk_image__tga_check(FILE *f);
|
65
|
|
- /*------------------------------------------------------
|
66
|
|
- * Pre : Filename is to be checked
|
67
|
|
- * Post : Returns 0 if valid, else error condition
|
68
|
|
- *
|
69
|
|
- *-- History ------------------------------------------
|
70
|
|
- *
|
71
|
|
- * 2001.04.01:
|
72
|
|
- * Mongoose - Created
|
73
|
|
- ------------------------------------------------------*/
|
74
|
|
-
|
75
|
|
- int mtk_image__tga_load(FILE *f, unsigned char **image,
|
76
|
|
- unsigned int *width, unsigned int *height, char *type);
|
77
|
|
- /*------------------------------------------------------
|
78
|
|
- * Pre : Filename is a valid image file
|
79
|
|
- * Post : Image is either a valid pixmap or NULL
|
80
|
|
- *
|
81
|
|
- *-- History ------------------------------------------
|
82
|
|
- *
|
83
|
|
- * 2001.04.01:
|
84
|
|
- * Mongoose - Created
|
85
|
|
- ------------------------------------------------------*/
|
86
|
|
-
|
87
|
|
- int mtk_image__tga_save(FILE *f, unsigned char *image,
|
88
|
|
- unsigned int width, unsigned int height, char type);
|
89
|
|
- /*------------------------------------------------------
|
90
|
|
- * Pre :
|
91
|
|
- * Post : Image is saved to diskfile if valid and can
|
92
|
|
- *
|
93
|
|
- *-- History ------------------------------------------
|
94
|
|
- *
|
95
|
|
- * 2001.04.01:
|
96
|
|
- * Mongoose - Created
|
97
|
|
- ------------------------------------------------------*/
|
98
|
|
-
|
99
|
|
-
|
100
|
|
- int mtk_image__tga_save_filename(unsigned char *image,
|
101
|
|
- unsigned int width, unsigned int height,
|
102
|
|
- char type,
|
103
|
|
- char *s, ...);
|
104
|
|
- /*------------------------------------------------------
|
105
|
|
- * Pre :
|
106
|
|
- * Post : Image is saved to diskfile if valid and can
|
107
|
|
- *
|
108
|
|
- *-- History ------------------------------------------
|
109
|
|
- *
|
110
|
|
- * 2003.07.11:
|
111
|
|
- * Mongoose - Created
|
112
|
|
- ------------------------------------------------------*/
|
113
|
92
|
#endif
|