1
/* Grafx2 - The Ultimate 256-color bitmap paint program
3
Copyright 2008 Yves Rizoud
4
Copyright 2008 Franck Charlet
5
Copyright 2007 Adrien Destugues
6
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
8
Grafx2 is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License
10
as published by the Free Software Foundation; version 2
13
Grafx2 is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with Grafx2; if not, see <http://www.gnu.org/licenses/>
26
#include "sdlscreen.h"
34
void Pixel_wide2 (word x,word y,byte color)
35
/* Affiche un pixel de la color aux coords x;y � l'�cran */
37
*(Screen_pixels + x * ZOOMX + y*ZOOMY * VIDEO_LINE_WIDTH)=color;
38
*(Screen_pixels + x * ZOOMX + y*ZOOMY * VIDEO_LINE_WIDTH + 1)=color;
39
*(Screen_pixels + x * ZOOMX + y*ZOOMY * VIDEO_LINE_WIDTH + 2)=color;
40
*(Screen_pixels + x * ZOOMX + y*ZOOMY * VIDEO_LINE_WIDTH + 3)=color;
41
*(Screen_pixels + x * ZOOMX + (y*ZOOMY+1) * VIDEO_LINE_WIDTH)=color;
42
*(Screen_pixels + x * ZOOMX + (y*ZOOMY+1) * VIDEO_LINE_WIDTH + 1)=color;
43
*(Screen_pixels + x * ZOOMX + (y*ZOOMY+1) * VIDEO_LINE_WIDTH + 2)=color;
44
*(Screen_pixels + x * ZOOMX + (y*ZOOMY+1) * VIDEO_LINE_WIDTH + 3)=color;
47
byte Read_pixel_wide2 (word x,word y)
48
/* On retourne la couleur du pixel aux coords donn�es */
50
return *( Screen_pixels + y * ZOOMY * VIDEO_LINE_WIDTH + x * ZOOMX);
53
void Block_wide2 (word start_x,word start_y,word width,word height,byte color)
54
/* On affiche un rectangle de la couleur donn�e */
57
rectangle.x=start_x*ZOOMX;
58
rectangle.y=start_y*ZOOMY;
59
rectangle.w=width*ZOOMX;
60
rectangle.h=height*ZOOMY;
61
SDL_FillRect(Screen_SDL,&rectangle,color);
64
void Display_part_of_screen_wide2 (word width,word height,word image_width)
65
/* Afficher une partie de l'image telle quelle sur l'�cran */
67
byte* dest=Screen_pixels; //On va se mettre en 0,0 dans l'�cran (dest)
68
byte* src=Main_offset_Y*image_width+Main_offset_X+Main_screen; //Coords de d�part ds la source (src)
72
for(y=height;y!=0;y--)
75
// On fait une copie de la ligne
76
for (dy=width;dy>0;dy--)
78
*(dest+3)=*(dest+2)=*(dest+1)=*dest=*src;
82
// On double la ligne qu'on vient de copier
83
memcpy(dest-width*ZOOMX+VIDEO_LINE_WIDTH,dest-width*ZOOMX,width*ZOOMX);
85
// On passe � la ligne suivante
86
src+=image_width-width;
87
dest+=VIDEO_LINE_WIDTH*ZOOMY - width*ZOOMX;
89
//Update_rect(0,0,width,height);
92
void Pixel_preview_normal_wide2 (word x,word y,byte color)
93
/* Affichage d'un pixel dans l'�cran, par rapport au d�calage de l'image
94
* dans l'�cran, en mode normal (pas en mode loupe)
95
* Note: si on modifie cette proc�dure, il faudra penser � faire �galement
96
* la modif dans la proc�dure Pixel_Preview_Loupe_SDL. */
98
// if(x-Main_offset_X >= 0 && y - Main_offset_Y >= 0)
99
Pixel_wide2(x-Main_offset_X,y-Main_offset_Y,color);
102
void Pixel_preview_magnifier_wide2 (word x,word y,byte color)
104
// Affiche le pixel dans la partie non zoom�e
105
Pixel_wide2(x-Main_offset_X,y-Main_offset_Y,color);
107
// Regarde si on doit aussi l'afficher dans la partie zoom�e
108
if (y >= Limit_top_zoom && y <= Limit_visible_bottom_zoom
109
&& x >= Limit_left_zoom && x <= Limit_visible_right_zoom)
113
int y_zoom = Main_magnifier_factor * (y-Main_magnifier_offset_Y);
115
if (Menu_Y - y_zoom < Main_magnifier_factor)
116
// On ne doit dessiner qu'un morceau du pixel
117
// sinon on d�passe sur le menu
118
height = Menu_Y - y_zoom;
120
height = Main_magnifier_factor;
123
Main_magnifier_factor * (x-Main_magnifier_offset_X) + Main_X_zoom,
124
y_zoom, Main_magnifier_factor, height, color
129
void Horizontal_XOR_line_wide2(word x_pos,word y_pos,word width)
131
//On calcule la valeur initiale de dest:
132
byte* dest=y_pos*ZOOMY*VIDEO_LINE_WIDTH+x_pos*ZOOMX+Screen_pixels;
136
for (x=0;x<width*ZOOMX;x+=ZOOMX)
137
*(dest+x+VIDEO_LINE_WIDTH+3)=*(dest+x+VIDEO_LINE_WIDTH+2)=*(dest+x+VIDEO_LINE_WIDTH+1)=*(dest+x+VIDEO_LINE_WIDTH)=*(dest+x+3)=*(dest+x+2)=*(dest+x+1)=*(dest+x)=~*(dest+x);
140
void Vertical_XOR_line_wide2(word x_pos,word y_pos,word height)
143
byte *dest=Screen_pixels+x_pos*ZOOMX+y_pos*VIDEO_LINE_WIDTH*ZOOMY;
144
for (i=height;i>0;i--)
146
*(dest+VIDEO_LINE_WIDTH+3)=*(dest+VIDEO_LINE_WIDTH+2)=*(dest+VIDEO_LINE_WIDTH+1)=*(dest+VIDEO_LINE_WIDTH)=*(dest+3)=*(dest+2)=*(dest+1)=*(dest)=~*(dest);
147
dest+=VIDEO_LINE_WIDTH*ZOOMY;
151
void Display_brush_color_wide2(word x_pos,word y_pos,word x_offset,word y_offset,word width,word height,byte transp_color,word brush_width)
153
// dest = Position � l'�cran
154
byte* dest = Screen_pixels + y_pos * ZOOMY * VIDEO_LINE_WIDTH + x_pos * ZOOMX;
155
// src = Position dans la brosse
156
byte* src = Brush + y_offset * brush_width + x_offset;
161
for(y = height;y > 0; y--)
164
for(x = width;x > 0; x--)
166
// On v�rifie que ce n'est pas la transparence
167
if(*src != transp_color)
169
*(dest+VIDEO_LINE_WIDTH+3) = *(dest+VIDEO_LINE_WIDTH+2) = *(dest+VIDEO_LINE_WIDTH+1) = *(dest+VIDEO_LINE_WIDTH) = *(dest+3) = *(dest+2) = *(dest+1) = *dest = *src;
177
// On passe � la ligne suivante
178
dest = dest + VIDEO_LINE_WIDTH*ZOOMY - width*ZOOMX;
179
src = src + brush_width - width;
181
Update_rect(x_pos,y_pos,width,height);
184
void Display_brush_mono_wide2(word x_pos, word y_pos,
185
word x_offset, word y_offset, word width, word height,
186
byte transp_color, byte color, word brush_width)
187
/* On affiche la brosse en monochrome */
189
byte* dest=y_pos*ZOOMY*VIDEO_LINE_WIDTH+x_pos*ZOOMX+Screen_pixels; // dest = adr destination �
191
byte* src=brush_width*y_offset+x_offset+Brush; // src = adr ds
195
for(y=height;y!=0;y--)
198
for(x=width;x!=0;x--)
201
if (*src!=transp_color)
202
*(dest+VIDEO_LINE_WIDTH+3)=*(dest+VIDEO_LINE_WIDTH+2)=*(dest+VIDEO_LINE_WIDTH+1)=*(dest+VIDEO_LINE_WIDTH)=*(dest+3)=*(dest+2)=*(dest+1)=*dest=color;
204
// On passe au pixel suivant
209
// On passe � la ligne suivante
210
src+=brush_width-width;
211
dest+=VIDEO_LINE_WIDTH*ZOOMY-width*ZOOMX;
213
Update_rect(x_pos,y_pos,width,height);
216
void Clear_brush_wide2(word x_pos,word y_pos,__attribute__((unused)) word x_offset,__attribute__((unused)) word y_offset,word width,word height,__attribute__((unused))byte transp_color,word image_width)
218
byte* dest=Screen_pixels+x_pos*ZOOMX+y_pos*ZOOMY*VIDEO_LINE_WIDTH; //On va se mettre en 0,0 dans l'�cran (dest)
219
byte* src = ( y_pos + Main_offset_Y ) * image_width + x_pos + Main_offset_X + Main_screen; //Coords de d�part ds la source (src)
223
for(y=height;y!=0;y--)
226
for(x=width;x!=0;x--)
229
*(dest+VIDEO_LINE_WIDTH+3)=*(dest+VIDEO_LINE_WIDTH+2)=*(dest+VIDEO_LINE_WIDTH+1)=*(dest+VIDEO_LINE_WIDTH)=*(dest+3)=*(dest+2)=*(dest+1)=*dest=*src;
231
// On passe au pixel suivant
236
// On passe � la ligne suivante
237
src+=image_width-width;
238
dest+=VIDEO_LINE_WIDTH*ZOOMY-width*ZOOMX;
240
Update_rect(x_pos,y_pos,width,height);
243
// Affiche une brosse (arbitraire) � l'�cran
244
void Display_brush_wide2(byte * brush, word x_pos,word y_pos,word x_offset,word y_offset,word width,word height,byte transp_color,word brush_width)
246
// dest = Position � l'�cran
247
byte* dest = Screen_pixels + y_pos * ZOOMY * VIDEO_LINE_WIDTH + x_pos * ZOOMX;
248
// src = Position dans la brosse
249
byte* src = brush + y_offset * brush_width + x_offset;
254
for(y = height;y > 0; y--)
257
for(x = width;x > 0; x--)
259
// On v�rifie que ce n'est pas la transparence
260
if(*src != transp_color)
262
*(dest+VIDEO_LINE_WIDTH+3)=*(dest+VIDEO_LINE_WIDTH+2)=*(dest+VIDEO_LINE_WIDTH+1)=*(dest+VIDEO_LINE_WIDTH)=*(dest+3)=*(dest+2)=*(dest+1)=*dest=*src;
269
// On passe � la ligne suivante
270
dest = dest + VIDEO_LINE_WIDTH*ZOOMY - width*ZOOMX;
271
src = src + brush_width - width;
275
void Remap_screen_wide2(word x_pos,word y_pos,word width,word height,byte * conversion_table)
277
// dest = coords a l'�cran
278
byte* dest = Screen_pixels + y_pos * ZOOMY * VIDEO_LINE_WIDTH + x_pos * ZOOMX;
282
for(y=height;y>0;y--)
287
*(dest+VIDEO_LINE_WIDTH+3)=*(dest+VIDEO_LINE_WIDTH+2)=*(dest+VIDEO_LINE_WIDTH+1)=*(dest+VIDEO_LINE_WIDTH)=*(dest+3)=*(dest+2)=*(dest+1)=*dest=
288
conversion_table[*dest];
292
dest = dest + VIDEO_LINE_WIDTH*ZOOMY - width*ZOOMX;
295
Update_rect(x_pos,y_pos,width,height);
298
void Display_line_on_screen_fast_wide2(word x_pos,word y_pos,word width,byte * line)
299
/* On affiche toute une ligne de pixels telle quelle. */
300
/* Utilis�e si le buffer contient d�ja des pixel doubl�s. */
302
memcpy(Screen_pixels+x_pos*ZOOMX+y_pos*ZOOMY*VIDEO_LINE_WIDTH,line,width*ZOOMX);
303
memcpy(Screen_pixels+x_pos*ZOOMX+(y_pos*ZOOMY+1)*VIDEO_LINE_WIDTH,line,width*ZOOMX);
306
void Display_line_on_screen_wide2(word x_pos,word y_pos,word width,byte * line)
307
/* On affiche une ligne de pixels en les doublant. */
311
dest=Screen_pixels+x_pos*ZOOMX+y_pos*ZOOMY*VIDEO_LINE_WIDTH;
314
*(dest+VIDEO_LINE_WIDTH+3)=*(dest+VIDEO_LINE_WIDTH+2)=*(dest+VIDEO_LINE_WIDTH+1)=*(dest+VIDEO_LINE_WIDTH)=*(dest+3)=*(dest+2)=*(dest+1)=*dest=*line;
319
void Display_transparent_mono_line_on_screen_wide2(
320
word x_pos, word y_pos, word width, byte* line,
321
byte transp_color, byte color)
322
// Affiche une ligne � l'�cran avec une couleur + transparence.
323
// Utilis� par les brosses en mode zoom
325
byte* dest = Screen_pixels+ y_pos*VIDEO_LINE_WIDTH + x_pos*ZOOMX;
330
if (transp_color!=*line)
332
*(dest+3)=*(dest+2)=*(dest+1)=*dest=color;
334
line ++; // Pixel suivant
339
void Read_line_screen_wide2(word x_pos,word y_pos,word width,byte * line)
341
memcpy(line,VIDEO_LINE_WIDTH*ZOOMY * y_pos + x_pos * ZOOMX + Screen_pixels,width*ZOOMX);
344
void Display_part_of_screen_scaled_wide2(
345
word width, // width non zoom�e
346
word height, // height zoom�e
347
word image_width,byte * buffer)
349
byte* src = Main_screen + Main_magnifier_offset_Y * image_width
350
+ Main_magnifier_offset_X;
351
int y = 0; // Ligne en cours de traitement
353
// Pour chaque ligne � zoomer
358
// On �clate la ligne
359
Zoom_a_line(src,buffer,Main_magnifier_factor*ZOOMX,width);
360
// On l'affiche Facteur fois, sur des lignes cons�cutives
361
x = Main_magnifier_factor/**ZOOMY*/;
364
// On affiche la ligne zoom�e
365
Display_line_on_screen_fast_wide2(
366
Main_X_zoom, y, width*Main_magnifier_factor,
369
// On passe � la suivante
371
if(y==height/**ZOOMY*/)
373
Redraw_grid(Main_X_zoom,0,
374
width*Main_magnifier_factor,height);
375
Update_rect(Main_X_zoom,0,
376
width*Main_magnifier_factor,height);
383
// ATTENTION on n'arrive jamais ici !
386
// Affiche une partie de la brosse couleur zoom�e
387
void Display_brush_color_zoom_wide2(word x_pos,word y_pos,
388
word x_offset,word y_offset,
389
word width, // width non zoom�e
390
word end_y_pos,byte transp_color,
391
word brush_width, // width r�elle de la brosse
394
byte* src = Brush+y_offset*brush_width + x_offset;
401
Zoom_a_line(src,buffer,Main_magnifier_factor,width);
402
// On affiche facteur fois la ligne zoom�e
403
for(bx=Main_magnifier_factor;bx>0;bx--)
405
byte* line_src = buffer;
406
byte* dest = Screen_pixels + y*ZOOMY * VIDEO_LINE_WIDTH + x_pos * ZOOMX;
408
// Pour chaque pixel de la ligne
409
for(x = width*Main_magnifier_factor;x > 0;x--)
411
if(*line_src!=transp_color)
413
*(dest+3)=*(dest+2)=*(dest+1)=*dest = *line_src;
419
memcpy(Screen_pixels + (y*ZOOMY+1)*VIDEO_LINE_WIDTH + x_pos*ZOOMX, Screen_pixels + y*ZOOMY*VIDEO_LINE_WIDTH + x_pos*ZOOMX, width*ZOOMX*Main_magnifier_factor);
428
// ATTENTION zone jamais atteinte
431
void Display_brush_mono_zoom_wide2(word x_pos, word y_pos,
432
word x_offset, word y_offset,
433
word width, // width non zoom�e
435
byte transp_color, byte color,
436
word brush_width, // width r�elle de la brosse
441
byte* src = Brush + y_offset * brush_width + x_offset;
444
//Pour chaque ligne � zoomer :
448
// src = Ligne originale
449
// On �clate la ligne
450
Zoom_a_line(src,buffer,Main_magnifier_factor,width);
452
// On affiche la ligne Facteur fois � l'�cran (sur des
453
// lignes cons�cutives)
454
bx = Main_magnifier_factor*ZOOMY;
456
// Pour chaque ligne �cran
459
// On affiche la ligne zoom�e
460
Display_transparent_mono_line_on_screen_wide2(
461
x_pos, y, width * Main_magnifier_factor,
462
buffer, transp_color, color
464
// On passe � la ligne suivante
466
// On v�rifie qu'on est pas � la ligne finale
467
if(y == end_y_pos*ZOOMY)
469
Redraw_grid( x_pos, y_pos,
470
width * Main_magnifier_factor, end_y_pos - y_pos );
471
Update_rect( x_pos, y_pos,
472
width * Main_magnifier_factor, end_y_pos - y_pos );
479
// Passage � la ligne suivante dans la brosse aussi
484
void Clear_brush_scaled_wide2(word x_pos,word y_pos,word x_offset,word y_offset,word width,word end_y_pos,__attribute__((unused)) byte transp_color,word image_width,byte * buffer)
487
// En fait on va recopier l'image non zoom�e dans la partie zoom�e !
488
byte* src = Main_screen + y_offset * image_width + x_offset;
492
// Pour chaque ligne � zoomer
494
Zoom_a_line(src,buffer,Main_magnifier_factor*ZOOMX,width);
496
bx=Main_magnifier_factor;
501
Display_line_on_screen_fast_wide2(x_pos,y,
502
width * Main_magnifier_factor,buffer);
508
Redraw_grid(x_pos,y_pos,
509
width*Main_magnifier_factor,end_y_pos-y_pos);
510
Update_rect(x_pos,y_pos,
511
width*Main_magnifier_factor,end_y_pos-y_pos);