00001
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028
00029 #include "images.h"
00030 #include "resources.h"
00031 #include "main.h"
00032 #include "sdlengine.h"
00033 #include "music.h"
00034 #include "hqrdepack.h"
00035
00036
00038 void adeline_logo()
00039 {
00040 play_midi_music(31,0);
00041 hqr_get_entry(workVideoBuffer,HQR_RESS_FILE,RESSHQR_ADELINEIMG);
00042 copy_screen(workVideoBuffer, frontVideoBuffer);
00043 hqr_get_entry(palette,HQR_RESS_FILE,RESSHQR_ADELINEPAL);
00044 convert_pal_2_RGBA(palette, paletteRGBA);
00045 fade_in(paletteRGBA);
00046 delay(7000);
00047 fade_out(paletteRGBA);
00048 }
00049
00051 void load_menu_image()
00052 {
00053 hqr_get_entry(workVideoBuffer, HQR_RESS_FILE, RESSHQR_MENUIMG);
00054 copy_screen(workVideoBuffer, frontVideoBuffer);
00055 hqr_get_entry(palette, HQR_RESS_FILE, RESSHQR_MAINPAL);
00056 convert_pal_2_RGBA(palette, paletteRGBA);
00057 fade_in(paletteRGBA);
00058 set_palette(paletteRGBA);
00059 }
00060
00063 void load_image(int index)
00064 {
00065 hqr_get_entry(workVideoBuffer, HQR_RESS_FILE, index);
00066 copy_screen(workVideoBuffer, frontVideoBuffer);
00067 hqr_get_entry(palette, HQR_RESS_FILE, index+1);
00068 convert_pal_2_RGBA(palette, paletteRGBA);
00069 fade_in(paletteRGBA);
00070 set_palette(paletteRGBA);
00071 }
00072
00076 void load_image_delay(int index, int time)
00077 {
00078 hqr_get_entry(workVideoBuffer, HQR_RESS_FILE, index);
00079 copy_screen(workVideoBuffer, frontVideoBuffer);
00080 hqr_get_entry(palette, HQR_RESS_FILE, index+1);
00081 convert_pal_2_RGBA(palette, paletteRGBA);
00082 fade_in(paletteRGBA);
00083 delay(1000*time);
00084 fade_out(paletteRGBA);
00085 }
00086
00090 void convert_pal_2_RGBA(unsigned char * palSource, unsigned char * palDest)
00091 {
00092 int i;
00093
00094 for (i = 0; i < NUMOFCOLORS; i++)
00095 {
00096 palDest[0] = palSource[0];
00097 palDest[1] = palSource[1];
00098 palDest[2] = palSource[2];
00099 palDest+=4;
00100 palSource+=3;
00101 }
00102 }
00103
00106 void fade_in(unsigned char * palette)
00107 {
00108 if(cfgfile.CrossFade)
00109 cross_fade(frontVideoBuffer, palette);
00110 else
00111 fade_2_pal(palette);
00112 }
00113
00116 void fade_out(unsigned char * palette)
00117 {
00118
00119
00120
00121
00122 if(!cfgfile.CrossFade)
00123 fade_2_black(palette);
00124 }
00125
00132 int cross_dot(int modifier, int color, int param, int intensity)
00133 {
00134 if (!param)
00135 return (color);
00136 return (((color - modifier) * intensity) / param) + modifier;
00137 }
00138
00145 void adjust_palette(unsigned char R, unsigned char G, unsigned char B, unsigned char * palette, int intensity)
00146 {
00147 unsigned char localPalette[NUMOFCOLORS*4];
00148 unsigned char *newR;
00149 unsigned char *newG;
00150 unsigned char *newB;
00151 unsigned char *newA;
00152
00153 int local;
00154 int counter = 0;
00155 int i;
00156
00157 local = intensity;
00158
00159 newR = &localPalette[0];
00160 newG = &localPalette[1];
00161 newB = &localPalette[2];
00162 newA = &localPalette[3];
00163
00164 for (i = 0; i < NUMOFCOLORS; i++)
00165 {
00166 *newR = cross_dot(R, palette[counter], 100, local);
00167 *newG = cross_dot(G, palette[counter + 1], 100, local);
00168 *newB = cross_dot(B, palette[counter + 2], 100, local);
00169 *newA = 0;
00170
00171 newR += 4;
00172 newG += 4;
00173 newB += 4;
00174 newA += 4;
00175
00176 counter += 4;
00177 }
00178
00179 set_palette(localPalette);
00180 }
00181
00184 void fade_2_black(unsigned char *palette)
00185 {
00186 int i = 0;
00187
00188 if (palReseted == 0)
00189 {
00190 for (i = 100; i >= 0; i -= 3)
00191 {
00192 adjust_palette(0, 0, 0, (unsigned char *) palette, i);
00193 fps_cycles(50);
00194 }
00195 }
00196
00197 palReseted = 1;
00198 }
00199
00202 void fade_2_pal(unsigned char *palette)
00203 {
00204 int i = 100;
00205
00206 for (i = 0; i <= 100; i += 3)
00207 {
00208 adjust_palette(0, 0, 0, (unsigned char *) palette, i);
00209 fps_cycles(50);
00210 }
00211
00212 set_palette( (unsigned char*)palette );
00213
00214 palReseted = 0;
00215
00216 }
00217
00219 void black_2_white()
00220 {
00221 unsigned char palette[NUMOFCOLORS*4];
00222 int i;
00223
00224 i = 256;
00225 for (i = 0; i < NUMOFCOLORS; i += 3)
00226 {
00227 memset(palette, i, 1024);
00228
00229 set_palette(palette);
00230 }
00231 }
00232
00234 void set_back_pal()
00235 {
00236 memset(palette, 0, NUMOFCOLORS*3);
00237 memset(paletteRGBA, 0, NUMOFCOLORS*4);
00238
00239 set_palette(paletteRGBA);
00240
00241 palReseted = 1;
00242 }
00243
00247 void copy_screen(unsigned char * source, unsigned char * destination)
00248 {
00249 int w,h;
00250 if(SCALE==1)
00251 memcpy(destination, source, SCREEN_WIDTH*SCREEN_HEIGHT);
00252 else if (SCALE==2)
00253 for(h=0; h<SCREEN_HEIGHT/SCALE; h++)
00254 {
00255 for(w=0; w<SCREEN_WIDTH/SCALE; w++)
00256 {
00257 *destination++ = *source;
00258 *destination++ = *source++;
00259 }
00260 memcpy(destination,destination-SCREEN_WIDTH,SCREEN_WIDTH);
00261 destination+=SCREEN_WIDTH;
00262 }
00263
00264 }
00265
00267 void clear_screen()
00268 {
00269 memset(frontVideoBuffer, 0, SCREEN_WIDTH*SCREEN_HEIGHT);
00270 }