File: bitmap.cpp

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 (125 lines) | stat: -rw-r--r-- 3,450 bytes parent folder | download
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* 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)
>
void bitmapPut(
  SrcType *src, int srcWidth, srcHeight, 
  DestType *dest, int destWidth, int destHeight,
  int srcX,int srcY,int destX, int destY, int width,int height) {
*/

#include "bitmap.h"
#include "symbol.h"
#include "font.h"
#include "syna.h"

static int span[SymbolCount][2] = {
  {1,25},
  {32,55},
  {63,78},
  {86,109},
  {116,140},
  {147,172},
  {176,201},
  {206,216},
  {224,246},
  {266,289},
  {300,332},
  {338,373},

  {524,538},
  {386,391},
  {401,415},
  {419,430},
  {432,446},
  {447,461},
  {462,476},
  {480,492},
  {493,507},
  {508,522},

  {545,552},
  {559,568},
  {575,584}
};

struct Entry {
  unsigned char blue;
  unsigned char red;
  Entry(unsigned char b,unsigned char r) : blue(b), red(r) { }
};

Entry maxBlue(unsigned char src,Entry dest) 
  { return Entry(src > dest.blue ? src : dest.blue,dest.red); }
Entry halfBlue(unsigned char src,Entry dest) 
  { return Entry(src/2 > dest.blue ? src/2 : dest.blue,dest.red); }
Entry maxRed(unsigned char src,Entry dest) 
  { return Entry(dest.blue,src > dest.red ? src : dest.red); }
Entry halfRed(unsigned char src,Entry dest) 
  { return Entry(dest.blue,src/2 > dest.red ? src/2 : dest.red); }

template <Entry (*transfer)(unsigned char,Entry)>
struct PutSymbol {
  static void go(int x,int y,int id) {
    BitmapPut<unsigned char,Entry,transfer>
     ::go(
            Symbols,SYMBOLSWIDTH,SYMBOLSHEIGHT,
            (Entry*)output,outWidth,outHeight,
            span[id][0],0,
            x-(span[id][1]-span[id][0]>>1),y,
            span[id][1]-span[id][0],SYMBOLSHEIGHT);
  }
};

void putSymbol(int x,int y,int id,TransferType typ) {
  switch(typ) {
    case HalfBlue : PutSymbol<halfBlue>::go(x,y,id); break;
    case MaxBlue : PutSymbol<maxBlue>::go(x,y,id); break;
    case HalfRed  :  PutSymbol<halfRed>::go(x,y,id); break;
    case MaxRed  :  PutSymbol<maxRed>::go(x,y,id); break;
    default      : error("Invalid transfer operation.\n");
  }
}

void putChar(unsigned char character,int x,int y,int red,int blue) {
  Entry *ptr = ((Entry*)output) + x + y*outWidth;
  Entry put(blue,red);
  int i,j;
  for(i=0;i<8;i++,ptr += outWidth-8)
    for(j=0;j<8;j++,ptr++)
      if (font[character*8+i] & (128>>j))
        *ptr = put;
}

void putString(char *string,int x,int y,int red,int blue) {
  if (x < 0 || y < 0 || y >= outHeight-8)
    return;
  for(;*string && x <= outWidth-8;string++,x+=8)
    putChar((unsigned char)(*string),x,y,red,blue);
}