~ubuntu-branches/ubuntu/maverick/grafx2/maverick

« back to all changes in this revision

Viewing changes to src/pxsimple.c

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2010-03-22 12:07:47 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100322120747-g0jel6vf6mjkc53s
Tags: 2.2-1
* New upstream version, fixes FTBFS with binutils-gold. (Closes: #554742)
* Bump standards version to 3.8.4.
* debian/control: Add liblua5.1-0-dev and pkg-config to build depends.
* debian/rules: Drop dh_desktop call.
* debian/copyright: Update years.
* Switch to dpkg-source format version 3.0 (quilt).
* debian/watch: Added.
* Added patch to fix spelling errors in source code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim:expandtab:ts=2 sw=2:
 
2
*/
 
3
/*  Grafx2 - The Ultimate 256-color bitmap paint program
 
4
 
 
5
    Copyright 2008 Yves Rizoud
 
6
    Copyright 2008 Franck Charlet
 
7
    Copyright 2007 Adrien Destugues
 
8
    Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
 
9
 
 
10
    Grafx2 is free software; you can redistribute it and/or
 
11
    modify it under the terms of the GNU General Public License
 
12
    as published by the Free Software Foundation; version 2
 
13
    of the License.
 
14
 
 
15
    Grafx2 is distributed in the hope that it will be useful,
 
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
    GNU General Public License for more details.
 
19
 
 
20
    You should have received a copy of the GNU General Public License
 
21
    along with Grafx2; if not, see <http://www.gnu.org/licenses/>
 
22
*/
 
23
 
 
24
#include <string.h>
 
25
#include <stdlib.h>
 
26
#include <SDL.h>
 
27
#include "global.h"
 
28
#include "sdlscreen.h"
 
29
#include "misc.h"
 
30
#include "graph.h"
 
31
#include "pxsimple.h"
 
32
 
 
33
#ifdef __VBCC__
 
34
    #define __attribute__(x)
 
35
#endif
 
36
 
 
37
void Pixel_simple (word x,word y,byte color)
 
38
/* Affiche un pixel de la color aux coords x;y � l'�cran */
 
39
{
 
40
  *(Screen_pixels + x + y * VIDEO_LINE_WIDTH)=color;
 
41
}
 
42
 
 
43
byte Read_pixel_simple (word x,word y)
 
44
/* On retourne la couleur du pixel aux coords donn�es */
 
45
{
 
46
  return *( Screen_pixels + y * VIDEO_LINE_WIDTH + x );
 
47
}
 
48
 
 
49
void Block_simple (word start_x,word start_y,word width,word height,byte color)
 
50
/* On affiche un rectangle de la couleur donn�e */
 
51
{
 
52
  SDL_Rect rectangle;
 
53
  rectangle.x=start_x;
 
54
  rectangle.y=start_y;
 
55
  rectangle.w=width;
 
56
  rectangle.h=height;
 
57
  SDL_FillRect(Screen_SDL,&rectangle,color);
 
58
}
 
59
 
 
60
void Display_part_of_screen_simple (word width,word height,word image_width)
 
61
/* Afficher une partie de l'image telle quelle sur l'�cran */
 
62
{
 
63
  byte* dest=Screen_pixels; //On va se mettre en 0,0 dans l'�cran (dest)
 
64
  byte* src=Main_offset_Y*image_width+Main_offset_X+Main_screen; //Coords de d�part ds la source (src)
 
65
  int y;
 
66
 
 
67
  for(y=height;y!=0;y--)
 
68
  // Pour chaque ligne
 
69
  {
 
70
    // On fait une copie de la ligne
 
71
    memcpy(dest,src,width);
 
72
 
 
73
    // On passe � la ligne suivante
 
74
    src+=image_width;
 
75
    dest+=VIDEO_LINE_WIDTH;
 
76
  }
 
77
  //Update_rect(0,0,width,height);
 
78
}
 
79
 
 
80
void Pixel_preview_normal_simple (word x,word y,byte color)
 
81
/* Affichage d'un pixel dans l'�cran, par rapport au d�calage de l'image 
 
82
 * dans l'�cran, en mode normal (pas en mode loupe)
 
83
 * Note: si on modifie cette proc�dure, il faudra penser � faire �galement 
 
84
 * la modif dans la proc�dure Pixel_Preview_Loupe_SDL. */
 
85
{
 
86
//  if(x-Main_offset_X >= 0 && y - Main_offset_Y >= 0)
 
87
  Pixel_simple(x-Main_offset_X,y-Main_offset_Y,color);
 
88
}
 
89
 
 
90
void Pixel_preview_magnifier_simple  (word x,word y,byte color)
 
91
{
 
92
  // Affiche le pixel dans la partie non zoom�e
 
93
  Pixel_simple(x-Main_offset_X,y-Main_offset_Y,color);
 
94
  
 
95
  // Regarde si on doit aussi l'afficher dans la partie zoom�e
 
96
  if (y >= Limit_top_zoom && y <= Limit_visible_bottom_zoom
 
97
          && x >= Limit_left_zoom && x <= Limit_visible_right_zoom)
 
98
  {
 
99
    // On est dedans
 
100
    int height;
 
101
    int y_zoom = Main_magnifier_factor * (y-Main_magnifier_offset_Y);
 
102
 
 
103
    if (Menu_Y - y_zoom < Main_magnifier_factor)
 
104
      // On ne doit dessiner qu'un morceau du pixel
 
105
      // sinon on d�passe sur le menu
 
106
      height = Menu_Y - y_zoom;
 
107
    else
 
108
      height = Main_magnifier_factor;
 
109
 
 
110
    Block_simple(
 
111
      Main_magnifier_factor * (x-Main_magnifier_offset_X) + Main_X_zoom, 
 
112
      y_zoom, Main_magnifier_factor, height, color
 
113
      );
 
114
  }
 
115
}
 
116
 
 
117
void Horizontal_XOR_line_simple(word x_pos,word y_pos,word width)
 
118
{
 
119
  //On calcule la valeur initiale de dest:
 
120
  byte* dest=y_pos*VIDEO_LINE_WIDTH+x_pos+Screen_pixels;
 
121
 
 
122
  int x;
 
123
 
 
124
  for (x=0;x<width;x++)
 
125
    *(dest+x)=~*(dest+x);
 
126
}
 
127
 
 
128
void Vertical_XOR_line_simple(word x_pos,word y_pos,word height)
 
129
{
 
130
  int i;
 
131
  byte color;
 
132
  for (i=y_pos;i<y_pos+height;i++)
 
133
  {
 
134
    color=*(Screen_pixels+x_pos+i*VIDEO_LINE_WIDTH);
 
135
    *(Screen_pixels+x_pos+i*VIDEO_LINE_WIDTH)=~color;
 
136
  }
 
137
}
 
138
 
 
139
void Display_brush_color_simple(word x_pos,word y_pos,word x_offset,word y_offset,word width,word height,byte transp_color,word brush_width)
 
140
{
 
141
  // dest = Position � l'�cran
 
142
  byte* dest = Screen_pixels + y_pos * VIDEO_LINE_WIDTH + x_pos;
 
143
  // src = Position dans la brosse
 
144
  byte* src = Brush + y_offset * brush_width + x_offset;
 
145
 
 
146
  word x,y;
 
147
 
 
148
  // Pour chaque ligne
 
149
  for(y = height;y > 0; y--)
 
150
  {
 
151
    // Pour chaque pixel
 
152
    for(x = width;x > 0; x--)
 
153
    {
 
154
      // On v�rifie que ce n'est pas la transparence
 
155
      if(*src != transp_color)
 
156
      {
 
157
        *dest = *src;
 
158
      }
 
159
 
 
160
      // Pixel suivant
 
161
      src++; dest++;
 
162
    }
 
163
 
 
164
    // On passe � la ligne suivante
 
165
    dest = dest + VIDEO_LINE_WIDTH - width;
 
166
    src = src + brush_width - width;
 
167
  }
 
168
  Update_rect(x_pos,y_pos,width,height);
 
169
}
 
170
 
 
171
void Display_brush_mono_simple(word x_pos, word y_pos,
 
172
        word x_offset, word y_offset, word width, word height,
 
173
        byte transp_color, byte color, word brush_width)
 
174
/* On affiche la brosse en monochrome */
 
175
{
 
176
  byte* dest=y_pos*VIDEO_LINE_WIDTH+x_pos+Screen_pixels; // dest = adr Destination � 
 
177
      // l'�cran
 
178
  byte* src=brush_width*y_offset+x_offset+Brush; // src = adr ds 
 
179
      // la brosse
 
180
  int x,y;
 
181
 
 
182
  for(y=height;y!=0;y--)
 
183
  //Pour chaque ligne
 
184
  {
 
185
    for(x=width;x!=0;x--)
 
186
    //Pour chaque pixel
 
187
    {
 
188
      if (*src!=transp_color)
 
189
        *dest=color;
 
190
 
 
191
      // On passe au pixel suivant
 
192
      src++;
 
193
      dest++;
 
194
    }
 
195
 
 
196
    // On passe � la ligne suivante
 
197
    src+=brush_width-width;
 
198
    dest+=VIDEO_LINE_WIDTH-width;
 
199
  }
 
200
  Update_rect(x_pos,y_pos,width,height);
 
201
}
 
202
 
 
203
void Clear_brush_simple(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)
 
204
{
 
205
  byte* dest=Screen_pixels+x_pos+y_pos*VIDEO_LINE_WIDTH; //On va se mettre en 0,0 dans l'�cran (dest)
 
206
  byte* src = ( y_pos + Main_offset_Y ) * image_width + x_pos + Main_offset_X + Main_screen; //Coords de d�part ds la source (src)
 
207
  int y;
 
208
 
 
209
  for(y=height;y!=0;y--)
 
210
  // Pour chaque ligne
 
211
  {
 
212
    // On fait une copie de la ligne
 
213
    memcpy(dest,src,width);
 
214
 
 
215
    // On passe � la ligne suivante
 
216
    src+=image_width;
 
217
    dest+=VIDEO_LINE_WIDTH;
 
218
  }
 
219
  Update_rect(x_pos,y_pos,width,height);
 
220
}
 
221
 
 
222
// Affiche une brosse (arbitraire) � l'�cran
 
223
void Display_brush_simple(byte * brush, word x_pos,word y_pos,word x_offset,word y_offset,word width,word height,byte transp_color,word brush_width)
 
224
{
 
225
  // dest = Position � l'�cran
 
226
  byte* dest = Screen_pixels + y_pos * VIDEO_LINE_WIDTH + x_pos;
 
227
  // src = Position dans la brosse
 
228
  byte* src = brush + y_offset * brush_width + x_offset;
 
229
  
 
230
  word x,y;
 
231
  
 
232
  // Pour chaque ligne
 
233
  for(y = height;y > 0; y--)
 
234
  {
 
235
    // Pour chaque pixel
 
236
    for(x = width;x > 0; x--)
 
237
    {
 
238
      // On v�rifie que ce n'est pas la transparence
 
239
      if(*src != transp_color)
 
240
      {
 
241
        *dest = *src;
 
242
      }
 
243
 
 
244
      // Pixel suivant
 
245
      src++; dest++;
 
246
    }
 
247
 
 
248
    // On passe � la ligne suivante
 
249
    dest = dest + VIDEO_LINE_WIDTH - width;
 
250
    src = src + brush_width - width;
 
251
  }
 
252
}
 
253
 
 
254
void Remap_screen_simple(word x_pos,word y_pos,word width,word height,byte * conversion_table)
 
255
{
 
256
  // dest = coords a l'�cran
 
257
  byte* dest = Screen_pixels + y_pos * VIDEO_LINE_WIDTH + x_pos;
 
258
  int x,y;
 
259
 
 
260
  // Pour chaque ligne
 
261
  for(y=height;y>0;y--)
 
262
  {
 
263
    // Pour chaque pixel
 
264
    for(x=width;x>0;x--)
 
265
    {
 
266
      *dest = conversion_table[*dest];
 
267
      dest ++;
 
268
    }
 
269
 
 
270
    dest = dest + VIDEO_LINE_WIDTH - width;
 
271
  }
 
272
 
 
273
  Update_rect(x_pos,y_pos,width,height);
 
274
}
 
275
 
 
276
void Display_line_on_screen_simple(word x_pos,word y_pos,word width,byte * line)
 
277
/* On affiche toute une ligne de pixels. Utilis� pour les textes. */
 
278
{
 
279
  memcpy(Screen_pixels+x_pos+y_pos*VIDEO_LINE_WIDTH,line,width);
 
280
}
 
281
 
 
282
void Display_transparent_mono_line_on_screen_simple(
 
283
        word x_pos, word y_pos, word width, byte* line, 
 
284
        byte transp_color, byte color)
 
285
// Affiche une ligne � l'�cran avec une couleur + transparence.
 
286
// Utilis� par les brosses en mode zoom
 
287
{
 
288
  byte* dest = Screen_pixels+ y_pos * VIDEO_LINE_WIDTH + x_pos;
 
289
  int x;
 
290
  // Pour chaque pixel
 
291
  for(x=0;x<width;x++)
 
292
  {
 
293
    if (transp_color!=*line)
 
294
      *dest = color;
 
295
    line ++; // Pixel suivant
 
296
    dest++;
 
297
  }
 
298
}
 
299
 
 
300
void Read_line_screen_simple(word x_pos,word y_pos,word width,byte * line)
 
301
{
 
302
  memcpy(line,VIDEO_LINE_WIDTH * y_pos + x_pos + Screen_pixels,width);
 
303
}
 
304
 
 
305
void Display_part_of_screen_scaled_simple(
 
306
        word width, // width non zoom�e
 
307
        word height, // height zoom�e
 
308
        word image_width,byte * buffer)
 
309
{
 
310
  byte* src = Main_screen + Main_magnifier_offset_Y * image_width 
 
311
                      + Main_magnifier_offset_X;
 
312
  int y = 0; // Ligne en cours de traitement
 
313
 
 
314
  // Pour chaque ligne � zoomer
 
315
  while(1)
 
316
  {
 
317
    int x;
 
318
    
 
319
    // On �clate la ligne
 
320
    Zoom_a_line(src,buffer,Main_magnifier_factor,width);
 
321
    // On l'affiche Facteur fois, sur des lignes cons�cutives
 
322
    x = Main_magnifier_factor;
 
323
    // Pour chaque ligne
 
324
    do{
 
325
      // On affiche la ligne zoom�e
 
326
      Display_line_on_screen_simple(
 
327
        Main_X_zoom, y, width*Main_magnifier_factor,
 
328
        buffer
 
329
      );
 
330
      // On passe � la suivante
 
331
      y++;
 
332
      if(y==height)
 
333
      {
 
334
        Redraw_grid(Main_X_zoom,0,
 
335
          width*Main_magnifier_factor,height);
 
336
        Update_rect(Main_X_zoom,0,
 
337
          width*Main_magnifier_factor,height);
 
338
        return;
 
339
      }
 
340
      x--;
 
341
    }while (x > 0);
 
342
    src += image_width;
 
343
  }
 
344
// ATTENTION on n'arrive jamais ici !
 
345
}
 
346
 
 
347
void Display_transparent_line_on_screen_simple(word x_pos,word y_pos,word width,byte* line,byte transp_color)
 
348
{
 
349
  byte* src = line;
 
350
  byte* dest = Screen_pixels + y_pos * VIDEO_LINE_WIDTH + x_pos;
 
351
 
 
352
  word x;
 
353
 
 
354
  // Pour chaque pixel de la ligne
 
355
  for(x = width;x > 0;x--)
 
356
  {
 
357
    if(*src!=transp_color)
 
358
      *dest = *src;
 
359
    src++;
 
360
    dest++;
 
361
  }
 
362
}
 
363
 
 
364
// Affiche une partie de la brosse couleur zoom�e
 
365
void Display_brush_color_zoom_simple(word x_pos,word y_pos,
 
366
        word x_offset,word y_offset,
 
367
        word width, // width non zoom�e
 
368
        word end_y_pos,byte transp_color,
 
369
        word brush_width, // width r�elle de la brosse
 
370
        byte * buffer)
 
371
{
 
372
  byte* src = Brush+y_offset*brush_width + x_offset;
 
373
  word y = y_pos;
 
374
  byte bx;
 
375
 
 
376
  // Pour chaque ligne
 
377
  while(1)
 
378
  {
 
379
    Zoom_a_line(src,buffer,Main_magnifier_factor,width);
 
380
    // On affiche facteur fois la ligne zoom�e
 
381
    for(bx=Main_magnifier_factor;bx>0;bx--)
 
382
    {
 
383
      Display_transparent_line_on_screen_simple(x_pos,y,width*Main_magnifier_factor,buffer,transp_color);
 
384
      y++;
 
385
      if(y==end_y_pos)
 
386
      {
 
387
        return;
 
388
      }
 
389
    }
 
390
    src += brush_width;
 
391
  }
 
392
  // ATTENTION zone jamais atteinte
 
393
}
 
394
 
 
395
void Display_brush_mono_zoom_simple(word x_pos, word y_pos,
 
396
        word x_offset, word y_offset, 
 
397
        word width, // width non zoom�e 
 
398
        word end_y_pos,
 
399
        byte transp_color, byte color, 
 
400
        word brush_width, // width r�elle de la brosse
 
401
        byte * buffer
 
402
)
 
403
 
 
404
{
 
405
  byte* src = Brush + y_offset * brush_width + x_offset;
 
406
  int y=y_pos;
 
407
 
 
408
  //Pour chaque ligne � zoomer :
 
409
  while(1)
 
410
  {
 
411
    int bx;
 
412
    // src = Ligne originale
 
413
    // On �clate la ligne
 
414
    Zoom_a_line(src,buffer,Main_magnifier_factor,width);
 
415
 
 
416
    // On affiche la ligne Facteur fois � l'�cran (sur des
 
417
    // lignes cons�cutives)
 
418
    bx = Main_magnifier_factor;
 
419
 
 
420
    // Pour chaque ligne �cran
 
421
    do
 
422
    {
 
423
      // On affiche la ligne zoom�e
 
424
      Display_transparent_mono_line_on_screen_simple(
 
425
        x_pos, y, width * Main_magnifier_factor, 
 
426
        buffer, transp_color, color
 
427
      );
 
428
      // On passe � la ligne suivante
 
429
      y++;
 
430
      // On v�rifie qu'on est pas � la ligne finale
 
431
      if(y == end_y_pos)
 
432
      {
 
433
        Redraw_grid( x_pos, y_pos,
 
434
          width * Main_magnifier_factor, end_y_pos - y_pos );
 
435
        Update_rect( x_pos, y_pos,
 
436
          width * Main_magnifier_factor, end_y_pos - y_pos );
 
437
        return;
 
438
      }
 
439
      bx --;
 
440
    }
 
441
    while (bx > 0);
 
442
    
 
443
    // Passage � la ligne suivante dans la brosse aussi
 
444
    src+=brush_width;
 
445
  }
 
446
}
 
447
 
 
448
void Clear_brush_scaled_simple(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)
 
449
{
 
450
  // En fait on va recopier l'image non zoom�e dans la partie zoom�e !
 
451
  byte* src = Main_screen + y_offset * image_width + x_offset;
 
452
  int y = y_pos;
 
453
  int bx;
 
454
 
 
455
  // Pour chaque ligne � zoomer
 
456
  while(1){
 
457
    Zoom_a_line(src,buffer,Main_magnifier_factor,width);
 
458
 
 
459
    bx=Main_magnifier_factor;
 
460
 
 
461
    // Pour chaque ligne
 
462
    do{
 
463
      Display_line_on_screen_simple(x_pos,y,
 
464
        width * Main_magnifier_factor,buffer);
 
465
 
 
466
      // Ligne suivante
 
467
      y++;
 
468
      if(y==end_y_pos)
 
469
      {
 
470
        Redraw_grid(x_pos,y_pos,
 
471
          width*Main_magnifier_factor,end_y_pos-y_pos);
 
472
        Update_rect(x_pos,y_pos,
 
473
          width*Main_magnifier_factor,end_y_pos-y_pos);
 
474
        return;
 
475
      }
 
476
      bx--;
 
477
    }while(bx!=0);
 
478
 
 
479
    src+= image_width;
 
480
  }
 
481
}