File size: 7,991 Bytes
00e6582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Copyright (c) 2026 Ethan Mortonson.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef IMAGE_H
#define IMAGE_H
#include <stdlib.h>
#include <GL/glew.h>"
#include "stdio.h"
#include "../physics/vector.h"
#include "../physics/physics.h"

#pragma pack(push, 1)
typedef struct {
    uint16_t width;
    uint16_t height;
} RawHeader;
#pragma pack(pop)

    struct _TwoD_Sprite_Object
    {
        GLuint Texture_ID;
        int RGBA_Image_Size;
        unsigned char Texture_Made;
        unsigned char* RGB_Canvas;
        unsigned char* RGBA_Canvas;
        float* Vertices;
        float* Texture_Vertices;

        int Width;
        int Height;
        float Cel_X_Division; //If 8 frames, this is 1/8 = 0.125
        float Cel_Y_Division; //If 8 frames, this is 1/8 = 0.125
        int Number_Of_Animations;

        int Current_Start_Cel;
        int Current_End_Cel;
        int Current_Cel;

        struct _TwoD_Sprite_Animation_Parameters* Animations;
    };

    struct _TwoD_Sprite_Animation_Header
    {
        char Sprite_Sheet_Filename[256];
        char Sprite_Sheet_Alpha_Channel_Filename[256];
        int Width;
        int Height;
        float Cel_X_Division; //If 8 frames, this is 1/8 = 0.125
        float Cel_Y_Division; //If 8 frames, this is 1/8 = 0.125
        int Number_Of_Animations;
        int Offset_To_Animations;
    };

    struct _TwoD_Sprite_Animation_Parameters
    {
        int Is_A_Billboard;
        int Number_Of_Frames;
        int Cel_X_ID; //If I want to start mid-animation.
        int Cel_Y_ID;
        float Animation_Speed;
        int Loop;
        float Rotational_Velocity;
        float Rotational_Acceleration;
        float Billboard_Scale;
        float Scale_Velocity;
        float Scale_Acceleration;

        float x;
        float y;
        float z;

        float dx;
        float dy;
        float dz;

        float ddx;
        float ddy;
        float ddz;

        int Loop_Motion_Once_Too_Far;
        float Maximum_Distance_From_Origin;

        float Start_x;
        float Start_y;
        float Start_z;

        float Rotation;
    };

    struct _Palette_Color
    {
        unsigned char R;
        unsigned char G;
        unsigned char B;
        unsigned char Transparency;
    };
    struct _Palette
    {
        struct _Palette_Color Colors[16];
    };

    struct _Palette_Binary_Output_Surface
    {
        int Width;
        int Height;
        unsigned char* Pixels;
        //w * h /2 rounded up
        // 4 bits per pixel
        // 1-3 = 8 colors from palette
        // 4 = is transparent?
    };
    struct _Image
    {
        GLuint Texture_ID;
        int RGBA_Image_Size;
        unsigned char Texture_Made;
        int x;
        int y;
        int Width;
        int Height;
        unsigned char* RGB_Canvas;
        unsigned char* RGBA_Canvas;
        float* Vertices;
        float* Texture_Vertices;
    };


    struct _Image* Create_Image();
    void Destroy_Image(struct _Image* Image);
    void Load_Image(struct _Image* Image, const char* Filename);
    void Initialize_Binary_Output_Surface(struct _Image* Image);
    void Palettize_Image();

    void Load_Binary_Output_Surface(struct _Image* Image, const char* Filename);
    void Render_Image(struct _Image* Image, float _x, float _y, int Alpha_Present);

    void Render_Animated_Image(struct _Image* Image, float _x, float _y, int Alpha_Present, int Cell_Width, int Cell_Height, int Cell_Y, int Frame, float Rate);

    void Create_BIN();
    void Load_BIN();

    unsigned char* Convert_RGB_To_RGBA(unsigned char* Input, int Input_Width, int Input_Height);

    void Copy_Pixel(int Color_Depth, unsigned char* Source, unsigned char* Destination, int Source_Width, int Source_Height, int Destination_Width, int Destination_Height, int Source_X, int Source_Y, int Destination_X, int Destination_Y);
    void Copy_Pixel_Alpha(int Color_Depth, unsigned char* Source, unsigned char* Destination, int Source_Width, int Source_Height, int Destination_Width, int Destination_Height, int Source_X, int Source_Y, int Destination_X, int Destination_Y);
    void Copy_Row(int Color_Depth, unsigned char* Source, unsigned char* Destination, int Source_Width, int Source_Height, int Destination_Width, int Destination_Height, int Source_X, int Source_Y, int Destination_X, int Destination_Y, int N_Pixels_To_Copy); //do Copy Pixel Width times
    void Copy_Section(int Color_Depth, unsigned char* Source, unsigned char* Destination, int Source_Width, int Source_Height, int Destination_Width, int Destination_Height, int Source_X, int Source_Y, int Destination_X, int Destination_Y, int N_Pixels_To_Copy, int Rows_To_Copy); //do Copy_Row Height times

    void Change_Three_Color_And_Alpha_Bit_Palette(unsigned char* RGB_Canvas, unsigned char New_Colors[8]);
void Change_Palette(struct _Image* Image, struct _Palette Old_Colors, struct _Palette New_Colors);

void Load_Palette(struct _Palette* P, const char* Filename);
void Write_Palette(const char* Filename);


void Render_Billboard(struct _Image* Image, float _x, float _y, Vector Camera_Vector, int Alpha_Present);

    void New_Copy_Section(int Color_Depth, unsigned char* Source, unsigned char* Destination, int Source_Width, int Source_Height, int Destination_Width, int Destination_Height, int Source_X, int Source_Y, int Destination_X, int Destination_Y, int N_Pixels_To_Copy, int Rows_To_Copy); //do Copy_Row Height

    void Render_Image_With_Vertex_Color(struct _Image* Image, float _x, float _y, int Alpha_Present, float R, float G, float B);

    void Render_Image_As_Billboard(struct _Image* Image, float _x, float _y, float _z, int Alpha_Present, float Scale);

void Write_TwoD_Sprite_Animation(const char* Filename);
void Load_TwoD_Sprite_Animation(struct _TwoD_Sprite_Object* TwoD_Sprite_Object, const char* Filename, unsigned int ID);
void Render_TwoD_Sprite_Animation(struct _TwoD_Sprite_Object* TwoD_Sprite_Object, float x, float y);
void Process_TwoD_Sprite_Animation(struct _TwoD_Sprite_Object* TwoD_Sprite_Object);
void Update_TwoD_Sprite_Animation(float New_Animation_Speed,
        int New_Loop,
        float New_Rotational_Velocity,
        float New_Rotational_Acceleration,
        float New_Billboard_Scale,
        float New_Scale_Velocity,
        float New_Scale_Acceleration,

        float New_x,
        float New_y,
        float New_z,

        float New_dx,
        float New_dy,
        float New_dz,

        float New_ddx,
        float New_ddy,
        float New_ddz);

void Load_Image_And_Convert_To_Bitmap(const char* Filename, const char* Output);
void Load_Bitmap_And_Convert_To_Image(const char* Filename, struct _Image* Image);

void BMPtoSEI(const char* Filename, const char* Output_Filename);
void Load_Transparent_Image(struct _Image* Image, const char* Filename, const char* Transparency_Map_Filename);

void Render_Image_At_Size(struct _Image* Image, float _x, float _y, float Width, float Height, int Alpha_Present);

#endif /* IMAGE_H */