Skip to content

Commit

Permalink
nula: clamp the colours for previous commit to allowable range
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Fosdick committed Dec 16, 2017
1 parent 9a7382e commit fc8f15f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,15 @@ void mode7_makechars()
}
}

static inline int mode7_calc_nula_col(int fg, int bg, int weight, int black) {
int result = bg + (((fg - bg) * weight) / 15) - black;
if (result < 0)
result = 0;
else if (result > 255)
result = 255;
return result;
}

static void mode7_gen_nula_lookup(void) {
int bl_col, bl_red, bl_grn, bl_blu;
int fg_ix, fg_col, fg_red, fg_grn, fg_blu;
Expand Down Expand Up @@ -482,9 +491,9 @@ static void mode7_gen_nula_lookup(void) {
bg_grn = getg(bg_col);
bg_blu = getb(bg_col);
for (weight = 0; weight < 16; weight++) {
lu_red = bg_red + (((fg_red - bg_red) * weight) / 15) - bl_red;
lu_grn = bg_grn + (((fg_grn - bg_grn) * weight) / 15) - bl_grn;
lu_blu = bg_blu + (((fg_blu - bg_blu) * weight) / 15) - bl_blu;
lu_red = mode7_calc_nula_col(fg_red, bg_red, weight, bl_red);
lu_grn = mode7_calc_nula_col(fg_grn, bg_grn, weight, bl_grn);
lu_blu = mode7_calc_nula_col(fg_blu, bg_blu, weight, bl_blu);
mode7_lookup[fg_ix][bg_ix][weight] = makecol(lu_red, lu_grn, lu_blu);
}
}
Expand Down

0 comments on commit fc8f15f

Please sign in to comment.