Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * Portions of this file are copyright Rebirth contributors and licensed as
3
 * described in COPYING.txt.
4
 * Portions of this file are copyright Parallax Software and licensed
5
 * according to the Parallax license below.
6
 * See COPYING.txt for license details.
7
 
8
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9
SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
10
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12
IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14
FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
16
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
18
*/
19
 
20
/*
21
 *
22
 * Graphical routines for drawing solid scanlines.
23
 *
24
 */
25
 
26
#include <algorithm>
27
#include <string.h>
28
#include "gr.h"
29
#include "grdef.h"
30
 
31
namespace dcx {
32
 
33
static void gr_linear_darken(uint8_t *const dest, unsigned darkening_level, unsigned count, const gft_array1 &fade_table)
34
{
35
        auto &t = fade_table[darkening_level];
36
        const auto predicate = [&](const uint8_t c) { return t[c]; };
37
        std::transform(dest, dest + count, dest, predicate);
38
}
39
 
40
#define gr_linear_stosd(D,C,N)  memset(D,C,N)
41
 
42
#if DXX_USE_OGL
43
static
44
#endif
45
void gr_uscanline(grs_canvas &canvas, const unsigned x1, const unsigned x2, const unsigned y, const uint8_t color)
46
{
47
        switch(canvas.cv_bitmap.get_type())
48
                {
49
                case bm_mode::linear:
50
#if DXX_USE_OGL
51
                case bm_mode::ogl:
52
#endif
53
                        {
54
                                const auto data = &canvas.cv_bitmap.get_bitmap_data()[canvas.cv_bitmap.bm_rowsize * y + x1];
55
                                const auto cv_fade_level = canvas.cv_fade_level;
56
                                const auto count = x2 - x1 + 1;
57
                                if (cv_fade_level >= gr_fade_table.size())
58
                                        gr_linear_stosd(data, static_cast<uint8_t>(color), count);
59
                                else
60
                                        gr_linear_darken(data, cv_fade_level, count, gr_fade_table);
61
                        }
62
                        break;
63
                }
64
}
65
 
66
void gr_scanline(grs_canvas &canvas, int x1, int x2, const unsigned y, const uint8_t color)
67
{
68
        const auto maxy = (canvas.cv_bitmap.bm_h - 1);
69
        if (y >= maxy)
70
                return;
71
 
72
        if (x2 < x1)
73
                std::swap(x1, x2);
74
 
75
        const auto maxx = (canvas.cv_bitmap.bm_w - 1);
76
        if (x1 > maxx) return;
77
        if (x2 < MINX) return;
78
 
79
        if (x1 < MINX) x1 = MINX;
80
        if (x2 > maxx) x2 = maxx;
81
        gr_uscanline(canvas, x1, x2, y, color);
82
}
83
 
84
}