~silwol/freenukum/trunk

« back to all changes in this revision

Viewing changes to src/fn_tile.c

  • Committer: Wolfgang Silbermayr
  • Date: 2009-02-19 07:53:17 UTC
  • Revision ID: wolfgang@silbermayr.at-20090219075317-yvff1vfn2lkcu2u0
fntile basically integrated into backdrop loading

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
FnTile * fn_tile_load(
51
51
    int fd,
52
52
    fn_environment_t * env,
53
 
    fn_tileheader_t * h)
 
53
    fn_tileheader_t * h,
 
54
    gboolean has_transparency)
54
55
{
 
56
  guint width = h->width * 8;
 
57
  guint height = h->height;
 
58
 
55
59
  FnTile * tile = fn_tile_new_with_environment(
56
 
      h->width,
57
 
      h->height,
 
60
      width,
 
61
      height,
58
62
      env);
59
 
  guchar * data = g_new(guchar, h->width * h->height * 4);
 
63
 
 
64
  guchar * data = g_new(guchar, width * height * 4);
60
65
 
61
66
  guchar readbuf[5];
62
67
 
63
 
  guint num_loads = h->width * h->height / 8;
 
68
  guint num_loads = width * height / 8;
64
69
  guint num_read = 0;
65
70
  guchar * iter = data;
66
71
 
80
85
      guchar red_pixel    = ((red_row    >> (7-i)) & 1);
81
86
      guchar green_pixel  = ((green_row  >> (7-i)) & 1);
82
87
      guchar blue_pixel   = ((blue_row   >> (7-i)) & 1);
83
 
      guchar opaque_pixel = ((opaque_row >> (7-i)) & 1);
 
88
      guchar opaque_pixel = (
 
89
          has_transparency ?
 
90
          ((opaque_row >> (7-i)) & 1) :
 
91
          1);
84
92
      guchar ugly_yellow  = (
85
93
          red_pixel == 1 &&
86
94
          green_pixel == 1 &&
87
95
          blue_pixel == 0 &&
88
 
          bright_pixel == 1) ? 1 : 0;
 
96
          bright_pixel == 0) ? 1 : 0;
89
97
 
90
98
      guchar * red    = iter;
91
99
      guchar * green  = iter + 1;
92
100
      guchar * blue   = iter + 2;
93
101
      guchar * opaque = iter + 3;
94
102
 
95
 
      *red =    red_pixel    * 0x54 * (2 + bright_pixel);
96
 
      *green =  green_pixel  * 0x54 * (2 + bright_pixel - ugly_yellow);
97
 
      *blue  =  blue_pixel   * 0x54 * (2 + bright_pixel);
 
103
      *red =    0x54 * (red_pixel   * 2 + bright_pixel);
 
104
      *green =  0x54 * (green_pixel * 2 + bright_pixel - ugly_yellow);
 
105
      *blue  =  0x54 * (blue_pixel  * 2 + bright_pixel);
98
106
      *opaque = opaque_pixel * 0xFF;
99
107
      iter += 4;
100
108
    }