~ubuntu-branches/debian/jessie/gpaint/jessie

« back to all changes in this revision

Viewing changes to src/rgb.c

  • Committer: Bazaar Package Importer
  • Author(s): Goedson Teixeira Paixao
  • Date: 2002-03-17 12:27:19 UTC
  • Revision ID: james.westby@ubuntu.com-20020317122719-a6mowwhvvtbmcxow
Tags: upstream-0.2.2
ImportĀ upstreamĀ versionĀ 0.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
    Copyright 2000  Li-Cheng (Andy) Tai
 
4
 
 
5
    This program is free software; you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License as published by
 
7
    the Free Software Foundation; either version 2 of the License, or
 
8
    (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program; if not, write to the Free Software
 
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
*/
 
19
 
 
20
 
 
21
#include "rgb.h"
 
22
 
 
23
inline void set_rgb_pixel(unsigned char *rgb,  int rowstride, int pixelsize, int width, int height, int x, int y, unsigned char r, unsigned char g, unsigned char b)
 
24
{
 
25
 
 
26
   unsigned char *p = rgb + rowstride * y + x * 3;
 
27
   if (x >= width) 
 
28
      return;
 
29
   if (y >= height)
 
30
      return;   
 
31
   if (x < 0)
 
32
      return;
 
33
   if (y < 0)
 
34
      return;
 
35
   *p = r;
 
36
   *(p + 1) = g;
 
37
   *(p + 2) = b;
 
38
}
 
39
 
 
40
     
 
41
/* Draw a rectangle on the screen */
 
42
void draw_brush( image_buf *ibuf,
 
43
                        int    x,
 
44
                        int    y, 
 
45
                        int width, 
 
46
                        int height)
 
47
{
 
48
  GdkRectangle update_rect;
 
49
  
 
50
  int tx, ty;
 
51
  int iwidth = image_buf_width(ibuf);
 
52
  int iheight = image_buf_height(ibuf);
 
53
  int rowstride = image_buf_rowstride(ibuf);
 
54
  int pixelsize = image_buf_pixelsize(ibuf);
 
55
  unsigned char *rgb = image_buf_rgbbuf(ibuf);
 
56
  
 
57
  update_rect.x = x - width / 2;
 
58
  update_rect.y = y - height / 2;
 
59
  update_rect.width = width;
 
60
  update_rect.height = height;
 
61
  
 
62
  for (ty = (int) y - height / 2; ty < (int) y + height / 2; ty++)
 
63
     for (tx = (int) x - width / 2; tx < (int) x + width / 2; tx++)
 
64
        set_rgb_pixel(rgb, rowstride, pixelsize, iwidth, iheight, tx, ty, 255, 255, 0);
 
65
        
 
66
 
 
67
  gtk_widget_draw (ibuf->drawing_area, &update_rect);
 
68
}
 
69