Integrated the changes by PheeL for Caanoo support
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1629 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
91
src/op_c.c
91
src/op_c.c
@@ -2,6 +2,7 @@
|
||||
*/
|
||||
/* Grafx2 - The Ultimate 256-color bitmap paint program
|
||||
|
||||
Copyright 2010 A Filyanov
|
||||
Copyright 2007 Adrien Destugues
|
||||
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
|
||||
|
||||
@@ -30,6 +31,8 @@
|
||||
#include "op_c.h"
|
||||
#include "errors.h"
|
||||
|
||||
int Convert_24b_bitmap_to_256_fast(T_Bitmap256 dest,T_Bitmap24B source,int width,int height,T_Components * palette);
|
||||
|
||||
/// Convert RGB to HSL.
|
||||
/// Both input and output are in the 0..255 range to use in the palette screen
|
||||
void RGB_to_HSL(int r,int g,int b,byte * hr,byte * sr,byte* lr)
|
||||
@@ -1352,6 +1355,10 @@ static const byte precision_24b[]=
|
||||
// Give this one a 24b source, get back the 256c bitmap and its palette
|
||||
int Convert_24b_bitmap_to_256(T_Bitmap256 dest,T_Bitmap24B source,int width,int height,T_Components * palette)
|
||||
{
|
||||
#if defined(__GP2X__) || defined(__gp2x__) || defined(__WIZ__) || defined(__CAANOO__)
|
||||
return Convert_24b_bitmap_to_256_fast(dest, source, width, height, palette);
|
||||
|
||||
#else
|
||||
T_Conversion_table * table; // table de conversion
|
||||
int ip; // index de précision pour la conversion
|
||||
|
||||
@@ -1373,7 +1380,91 @@ int Convert_24b_bitmap_to_256(T_Bitmap256 dest,T_Bitmap24B source,int width,int
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//Really small, fast and ugly converter(just for handhelds)
|
||||
#include "global.h"
|
||||
#include "limits.h"
|
||||
#include "engine.h"
|
||||
#include "windows.h"
|
||||
|
||||
extern void Set_palette_fake_24b(T_Palette palette);
|
||||
|
||||
/// Really small, fast and dirty convertor(just for handhelds)
|
||||
int Convert_24b_bitmap_to_256_fast(T_Bitmap256 dest,T_Bitmap24B source,int width,int height,T_Components * palette)
|
||||
{
|
||||
T_Components * palette_fake24b;
|
||||
int px_pos, py_pos;
|
||||
int size, size_percent, size_percent_progress;
|
||||
int delta, delta_old;
|
||||
int i, idx, progress_counter;
|
||||
char progress_str[8];
|
||||
SDL_Rect pw;
|
||||
|
||||
Set_palette_fake_24b(palette);
|
||||
palette_fake24b = palette;
|
||||
|
||||
Open_window(80, 30, "Progress");
|
||||
pw.x = Window_pos_X;
|
||||
pw.y = Window_pos_Y;
|
||||
pw.w = Window_width * Menu_factor_X;
|
||||
pw.h = Window_height* Menu_factor_Y;
|
||||
Window_rectangle(pw.x, pw.y, pw.w, pw.h, MC_Light);
|
||||
px_pos = (pw.w / (2 * Menu_factor_X)) - 10;
|
||||
py_pos = (pw.h / (2 * Menu_factor_Y)) + 1;
|
||||
|
||||
progress_counter = 0;
|
||||
size = width*height;
|
||||
size_percent = size / 100;
|
||||
size_percent_progress = size - 1;
|
||||
|
||||
while(size--)
|
||||
{
|
||||
//Progress counter update
|
||||
if(size_percent_progress == size)
|
||||
{
|
||||
size_percent_progress = size - size_percent;
|
||||
progress_counter++;
|
||||
//Because of integer division it less of resolution and need to be checked for small files
|
||||
//(maybe you can do a more smart checking or use a float values)
|
||||
progress_counter = progress_counter > 100 ? 100 : progress_counter;
|
||||
snprintf(progress_str, sizeof(progress_str), "%d%%", progress_counter);
|
||||
Print_in_window(px_pos, py_pos, (const char *)progress_str, MC_Black, MC_Light);
|
||||
|
||||
SDL_LockSurface(Screen_SDL);
|
||||
SDL_UpdateRect(Screen_SDL, pw.x, pw.y, pw.w, pw.h);
|
||||
SDL_UnlockSurface(Screen_SDL);
|
||||
}
|
||||
|
||||
palette = palette_fake24b;
|
||||
delta = delta_old = INT_MAX;
|
||||
//Searching for most suitable colour in palette
|
||||
for(i=idx=0; i<256; i++)
|
||||
{
|
||||
//A HUGE field for optimizations lies here
|
||||
|
||||
//Compute delta beetween current and palette colours.
|
||||
//(calling function 3 times in a row is a lame, i know)
|
||||
delta = abs(source->R - palette->R) + abs(source->G - palette->G) + abs(source->B - palette->B);
|
||||
|
||||
if(delta < delta_old)
|
||||
{
|
||||
delta_old = delta;
|
||||
idx = i;
|
||||
//Most suitable color found - step out from loop
|
||||
if(delta == 0) break;
|
||||
}
|
||||
palette++;
|
||||
}
|
||||
//Set palette color index to destination bitmap
|
||||
*dest = idx;
|
||||
source++;
|
||||
dest++;
|
||||
}
|
||||
Close_window();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user