isolate dependencies to SDL

Do not access directly the SDL_Surface Screen_pixels
use new functions Get_Screen_pixel_ptr() Set_Screen_pixel(),
Get_Screen_pixel()
And SetPalette()

Signed-off-by: Thomas Bernard <miniupnp@free.fr>
This commit is contained in:
Thomas Bernard
2018-05-26 23:49:19 +02:00
parent c6975afe94
commit 72fea0290f
21 changed files with 1006 additions and 440 deletions

View File

@@ -23,7 +23,6 @@
#include <string.h>
#include <stdlib.h>
#include <SDL.h>
#include "global.h"
#include "sdlscreen.h"
#include "misc.h"
@@ -38,45 +37,53 @@
void Pixel_tall (word x,word y,byte color)
/* Affiche un pixel de la color aux coords x;y à l'écran */
{
*(Screen_pixels + x + y*ZOOMY*VIDEO_LINE_WIDTH)=color;
*(Screen_pixels + x + (y*ZOOMY+1)*VIDEO_LINE_WIDTH)=color;
//*(Screen_pixels + x + y*ZOOMY*VIDEO_LINE_WIDTH)=color;
//*(Screen_pixels + x + (y*ZOOMY+1)*VIDEO_LINE_WIDTH)=color;
Set_Screen_pixel(x * ZOOMX, y * ZOOMY, color);
Set_Screen_pixel(x * ZOOMX, y * ZOOMY + 1, color);
}
byte Read_pixel_tall (word x,word y)
/* On retourne la couleur du pixel aux coords données */
{
return *( Screen_pixels + y*ZOOMY*VIDEO_LINE_WIDTH + x );
//return *( Screen_pixels + y*ZOOMY*VIDEO_LINE_WIDTH + x );
return Get_Screen_pixel(x * ZOOMX, y * ZOOMY);
}
void Block_tall (word start_x,word start_y,word width,word height,byte color)
/* On affiche un rectangle de la couleur donnée */
{
#if 0
SDL_Rect rectangle;
rectangle.x=start_x;
rectangle.y=start_y*ZOOMY;
rectangle.w=width;
rectangle.h=height*ZOOMY;
SDL_FillRect(Screen_SDL,&rectangle,color);
#endif
Screen_FillRect(start_x * ZOOMX, start_y * ZOOMY, width * ZOOMX, height * ZOOMY, color);
}
void Display_part_of_screen_tall (word width,word height,word image_width)
/* Afficher une partie de l'image telle quelle sur l'écran */
{
byte* dest=Screen_pixels; //On va se mettre en 0,0 dans l'écran (dest)
//On va se mettre en 0,0 dans l'écran (dest)
byte* src=Main.offset_Y*image_width+Main.offset_X+Main_screen; //Coords de départ ds la source (src)
int y;
for(y=height;y!=0;y--)
for(y = 0; y < height; y++)
// Pour chaque ligne
{
// On fait une copie de la ligne
memcpy(dest,src,width);
dest+=VIDEO_LINE_WIDTH;
memcpy(dest,src,width);
//memcpy(dest,src,width);
memcpy(Get_Screen_pixel_ptr(0, y * ZOOMY), src, width);
//dest+=VIDEO_LINE_WIDTH;
//memcpy(dest,src,width);
memcpy(Get_Screen_pixel_ptr(0, y * ZOOMY + 1), src, width);
// On passe à la ligne suivante
src+=image_width;
dest+=VIDEO_LINE_WIDTH;
//dest+=VIDEO_LINE_WIDTH;
}
//Update_rect(0,0,width,height);
}
@@ -121,14 +128,16 @@ void Pixel_preview_magnifier_tall (word x,word y,byte color)
void Horizontal_XOR_line_tall(word x_pos,word y_pos,word width)
{
//On calcule la valeur initiale de dest:
byte* dest=y_pos*ZOOMY*VIDEO_LINE_WIDTH+x_pos+Screen_pixels;
//byte* dest=y_pos*ZOOMY*VIDEO_LINE_WIDTH+x_pos+Screen_pixels;
byte *dest = Get_Screen_pixel_ptr(x_pos * ZOOMX, y_pos * ZOOMY);
int x;
for (x=0;x<width;x++)
*(dest+x)=xor_lut[*(dest+x)];
dest=(y_pos*ZOOMY+1)*VIDEO_LINE_WIDTH+x_pos+Screen_pixels;
//dest=(y_pos*ZOOMY+1)*VIDEO_LINE_WIDTH+x_pos+Screen_pixels;
dest = Get_Screen_pixel_ptr(x_pos * ZOOMX, y_pos * ZOOMY + 1);
for (x=0;x<width;x++)
*(dest+x)=xor_lut[*(dest+x)];
}
@@ -139,23 +148,26 @@ void Vertical_XOR_line_tall(word x_pos,word y_pos,word height)
byte color;
for (i=y_pos*ZOOMY;i<(y_pos+height)*ZOOMY;i++)
{
color=*(Screen_pixels+x_pos+i*VIDEO_LINE_WIDTH);
*(Screen_pixels+x_pos+i*VIDEO_LINE_WIDTH)=xor_lut[color];
//color=*(Screen_pixels+x_pos+i*VIDEO_LINE_WIDTH);
color = Get_Screen_pixel(x_pos, i);
//*(Screen_pixels+x_pos+i*VIDEO_LINE_WIDTH)=xor_lut[color];
Set_Screen_pixel(x_pos, i, xor_lut[color]);
}
}
void Display_brush_color_tall(word x_pos,word y_pos,word x_offset,word y_offset,word width,word height,byte transp_color,word brush_width)
{
// dest = Position à l'écran
byte* dest = Screen_pixels + y_pos*ZOOMY*VIDEO_LINE_WIDTH + x_pos;
// src = Position dans la brosse
byte* src = Brush + y_offset * brush_width + x_offset;
word x,y;
// Pour chaque ligne
for(y = height;y > 0; y--)
for(y = 0; y < height; y++)
{
byte *dest = Get_Screen_pixel_ptr(x_pos * ZOOMX, (y_pos+y) * ZOOMY);
byte *dest2 = Get_Screen_pixel_ptr(x_pos * ZOOMX, (y_pos+y) * ZOOMY + 1);
// Pour chaque pixel
for(x = width;x > 0; x--)
{
@@ -163,15 +175,15 @@ void Display_brush_color_tall(word x_pos,word y_pos,word x_offset,word y_offset,
if(*src != transp_color)
{
*dest = *src;
*(dest+VIDEO_LINE_WIDTH) = *src;
//*(dest+VIDEO_LINE_WIDTH) = *src;
*dest2 = *src;
}
// Pixel suivant
src++; dest++;
src++; dest++; dest2++;
}
// On passe à la ligne suivante
dest = dest + ZOOMY*VIDEO_LINE_WIDTH - width;
src = src + brush_width - width;
}
Update_rect(x_pos,y_pos,width,height);
@@ -182,56 +194,61 @@ void Display_brush_mono_tall(word x_pos, word y_pos,
byte transp_color, byte color, word brush_width)
/* On affiche la brosse en monochrome */
{
byte* dest=y_pos*ZOOMY*VIDEO_LINE_WIDTH+x_pos+Screen_pixels; // dest = adr Destination à
// l'écran
// dest = adr Destination à l'écran
byte* src=brush_width*y_offset+x_offset+Brush; // src = adr ds
// la brosse
int x,y;
for(y=height;y!=0;y--)
//Pour chaque ligne
for(y = 0; y < height; y++)
{
byte *dest = Get_Screen_pixel_ptr(x_pos * ZOOMX, (y_pos+y) * ZOOMY);
byte *dest2 = Get_Screen_pixel_ptr(x_pos * ZOOMX, (y_pos+y) * ZOOMY + 1);
for(x=width;x!=0;x--)
//Pour chaque pixel
{
if (*src!=transp_color)
{
*dest=color;
*(dest+VIDEO_LINE_WIDTH)=color;
//*(dest+VIDEO_LINE_WIDTH)=color;
*dest2 = color;
}
// On passe au pixel suivant
src++;
dest++;
dest2++;
}
// On passe à la ligne suivante
src+=brush_width-width;
dest+=ZOOMY*VIDEO_LINE_WIDTH-width;
//dest+=ZOOMY*VIDEO_LINE_WIDTH-width;
}
Update_rect(x_pos,y_pos,width,height);
}
void Clear_brush_tall(word x_pos,word y_pos,word x_offset,word y_offset,word width,word height,byte transp_color,word image_width)
{
byte* dest=Screen_pixels+x_pos+y_pos*ZOOMY*VIDEO_LINE_WIDTH; //On va se mettre en 0,0 dans l'écran (dest)
//On va se mettre en 0,0 dans l'écran (dest)
byte* src = ( y_pos + Main.offset_Y ) * image_width + x_pos + Main.offset_X + Main_screen; //Coords de départ ds la source (src)
int y;
(void)x_offset; // unused
(void)y_offset; // unused
(void)transp_color; // unused
for(y=height;y!=0;y--)
for(y=0; y<height; y++)
// Pour chaque ligne
{
byte *dest = Get_Screen_pixel_ptr(x_pos * ZOOMX, (y_pos+y) * ZOOMY);
// On fait une copie de la ligne
memcpy(dest,src,width);
dest+=VIDEO_LINE_WIDTH;
dest = Get_Screen_pixel_ptr(x_pos * ZOOMX, (y_pos+y) * ZOOMY + 1);
memcpy(dest,src,width);
// On passe à la ligne suivante
src+=image_width;
dest+=VIDEO_LINE_WIDTH;
//dest+=VIDEO_LINE_WIDTH;
}
Update_rect(x_pos,y_pos,width,height);
}
@@ -240,15 +257,16 @@ void Clear_brush_tall(word x_pos,word y_pos,word x_offset,word y_offset,word wid
void Display_brush_tall(byte * brush, word x_pos,word y_pos,word x_offset,word y_offset,word width,word height,byte transp_color,word brush_width)
{
// dest = Position à l'écran
byte* dest = Screen_pixels + y_pos*ZOOMY*VIDEO_LINE_WIDTH + x_pos;
// src = Position dans la brosse
byte* src = brush + y_offset * brush_width + x_offset;
word x,y;
// Pour chaque ligne
for(y = height;y > 0; y--)
for(y=0; y<height; y++)
{
byte *dest = Get_Screen_pixel_ptr(x_pos * ZOOMX, (y_pos+y) * ZOOMY);
byte *dest2 = Get_Screen_pixel_ptr(x_pos * ZOOMX, (y_pos+y) * ZOOMY + 1);
// Pour chaque pixel
for(x = width;x > 0; x--)
{
@@ -256,15 +274,14 @@ void Display_brush_tall(byte * brush, word x_pos,word y_pos,word x_offset,word y
if(*src != transp_color)
{
*dest = *src;
*(dest+VIDEO_LINE_WIDTH) = *src;
*dest2 = *src;
}
// Pixel suivant
src++; dest++;
src++; dest++; dest2++;
}
// On passe à la ligne suivante
dest = dest + VIDEO_LINE_WIDTH*ZOOMY - width;
src = src + brush_width - width;
}
}
@@ -272,12 +289,12 @@ void Display_brush_tall(byte * brush, word x_pos,word y_pos,word x_offset,word y
void Remap_screen_tall(word x_pos,word y_pos,word width,word height,byte * conversion_table)
{
// dest = coords a l'écran
byte* dest = Screen_pixels + y_pos*ZOOMY*VIDEO_LINE_WIDTH + x_pos;
int x,y;
// Pour chaque ligne
for(y=height*ZOOMY;y>0;y--)
for(y=0; y<height*ZOOMY; y++)
{
byte *dest = Get_Screen_pixel_ptr(x_pos * ZOOMX, y_pos * ZOOMY + y);
// Pour chaque pixel
for(x=width;x>0;x--)
{
@@ -285,7 +302,7 @@ void Remap_screen_tall(word x_pos,word y_pos,word width,word height,byte * conve
dest ++;
}
dest = dest + VIDEO_LINE_WIDTH - width;
//dest = dest + VIDEO_LINE_WIDTH - width;
}
Update_rect(x_pos,y_pos,width,height);
@@ -294,13 +311,16 @@ void Remap_screen_tall(word x_pos,word y_pos,word width,word height,byte * conve
void Display_line_on_screen_tall(word x_pos,word y_pos,word width,byte * line)
/* On affiche toute une ligne de pixels. Utilisé pour les textes. */
{
memcpy(Screen_pixels+x_pos+y_pos*ZOOMY*VIDEO_LINE_WIDTH,line,width);
memcpy(Screen_pixels+x_pos+(y_pos*ZOOMY+1)*VIDEO_LINE_WIDTH,line,width);
//memcpy(Screen_pixels+x_pos+y_pos*ZOOMY*VIDEO_LINE_WIDTH,line,width);
//memcpy(Screen_pixels+x_pos+(y_pos*ZOOMY+1)*VIDEO_LINE_WIDTH,line,width);
memcpy(Get_Screen_pixel_ptr(x_pos * ZOOMX, y_pos * ZOOMY), line, width);
memcpy(Get_Screen_pixel_ptr(x_pos * ZOOMX, y_pos * ZOOMY + 1), line, width);
}
void Read_line_screen_tall(word x_pos,word y_pos,word width,byte * line)
{
memcpy(line,VIDEO_LINE_WIDTH*ZOOMY*y_pos + x_pos + Screen_pixels,width);
//memcpy(line,VIDEO_LINE_WIDTH*ZOOMY*y_pos + x_pos + Screen_pixels,width);
memcpy(line, Get_Screen_pixel_ptr(x_pos * ZOOMX, y_pos * ZOOMY), width);
}
void Display_part_of_screen_scaled_tall(
@@ -365,7 +385,8 @@ void Display_brush_color_zoom_tall(word x_pos,word y_pos,
for(bx=Main.magnifier_factor;bx>0;bx--)
{
Display_transparent_line_on_screen_simple(x_pos,y*ZOOMY,width*Main.magnifier_factor,buffer,transp_color);
memcpy(Screen_pixels + (y*ZOOMY +1) * VIDEO_LINE_WIDTH + x_pos, Screen_pixels + y*ZOOMY*VIDEO_LINE_WIDTH + x_pos, width*Main.magnifier_factor);
//memcpy(Screen_pixels + (y*ZOOMY +1) * VIDEO_LINE_WIDTH + x_pos, Screen_pixels + y*ZOOMY*VIDEO_LINE_WIDTH + x_pos, width*Main.magnifier_factor);
memcpy(Get_Screen_pixel_ptr(x_pos, y * ZOOMY + 1), Get_Screen_pixel_ptr(x_pos, y * ZOOMY), width*Main.magnifier_factor);
y++;
if(y==end_y_pos)
{