File: bitmap.h

package info (click to toggle)
synaesthesia 1.4-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 252 kB
  • ctags: 301
  • sloc: ansic: 2,098; cpp: 1,387; makefile: 92; sh: 1
file content (80 lines) | stat: -rw-r--r-- 2,096 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Synaesthesia - program to display sound graphically
   Copyright (C) 1997  Paul Francis Harrison

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
  Free Software Foundation; either version 2 of the License, or (at your
  option) any later version.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  675 Mass Ave, Cambridge, MA 02139, USA.

  The author may be contacted at:
    pfh@yoyo.cc.monash.edu.au
  or
    27 Bond St., Mt. Waverley, 3149, Melbourne, Australia
*/

template <
  class SrcType,
  class DestType,
  DestType (*transfer)(SrcType,DestType)
>
struct BitmapPut {
static void go(
  SrcType *src, int srcWidth, int srcHeight, 
  DestType *dest, int destWidth, int destHeight,
  int srcX,int srcY,int destX, int destY, int width,int height) {

  if (srcX < 0) {
    destX -= srcX;
    width += srcX;
    srcX   = 0;
  }
  if (srcY < 0) {
    destY -= srcY;
    height+= srcY;
    srcY   = 0;
  }
  if (destX < 0) {
    srcX  -= destX;
    width += destX;
    destX  = 0; 
  }
  if (destY < 0) {
    srcY  -= destY;
    height+= destY;
    destY  = 0;
  }

  if (srcX+width > srcWidth) {
    width = srcWidth - srcX;
  }
  if (srcY+height > srcHeight) {
    height = srcHeight - srcY;
  }
  if (destX+width > destWidth) {
    width = destWidth - destX; 
  }
  if (destY+height > destHeight) {
    height = destHeight - destY;
  }

  if (width <= 0 || height <= 0) return;

  int srcSkip = srcWidth - width, destSkip = destWidth - width;
  int i;
  src  += srcX  + srcY  * srcWidth;
  dest += destX + destY * destWidth;

  for(;height--;src+=srcSkip,dest+=destSkip)
    for(i=width;i--;src++,dest++)
      *dest = transfer(*src,*dest);
}};