2006-03-20 16:43:15 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
2013-02-24 02:39:48 +00:00
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
2006-03-20 16:43:15 +00:00
|
|
|
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
2009-11-30 22:42:55 +00:00
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Graphical routines for drawing solid scanlines.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-08-08 02:44:27 +00:00
|
|
|
#include <algorithm>
|
2006-03-20 16:43:15 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include "gr.h"
|
|
|
|
#include "grdef.h"
|
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:23 +00:00
|
|
|
|
2020-12-26 21:17:29 +00:00
|
|
|
namespace {
|
|
|
|
|
2021-09-19 10:53:48 +00:00
|
|
|
static void gr_linear_darken(uint8_t *const dest, const gr_fade_level darkening_level, const unsigned count, const gft_array1 &fade_table)
|
2016-02-10 03:58:05 +00:00
|
|
|
{
|
|
|
|
auto &t = fade_table[darkening_level];
|
|
|
|
const auto predicate = [&](const uint8_t c) { return t[c]; };
|
2014-08-08 02:44:27 +00:00
|
|
|
std::transform(dest, dest + count, dest, predicate);
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
2009-11-30 22:42:55 +00:00
|
|
|
|
2020-12-26 21:17:29 +00:00
|
|
|
}
|
|
|
|
|
2014-11-30 22:09:22 +00:00
|
|
|
#define gr_linear_stosd(D,C,N) memset(D,C,N)
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2016-09-24 18:06:11 +00:00
|
|
|
#if DXX_USE_OGL
|
2020-12-26 21:17:29 +00:00
|
|
|
namespace {
|
2006-03-20 16:43:15 +00:00
|
|
|
#endif
|
2016-12-29 03:27:08 +00:00
|
|
|
void gr_uscanline(grs_canvas &canvas, const unsigned x1, const unsigned x2, const unsigned y, const uint8_t color)
|
2016-02-10 03:58:05 +00:00
|
|
|
{
|
2016-12-29 03:27:08 +00:00
|
|
|
switch(canvas.cv_bitmap.get_type())
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
2016-05-28 17:31:26 +00:00
|
|
|
case bm_mode::linear:
|
2016-09-24 18:06:11 +00:00
|
|
|
#if DXX_USE_OGL
|
2016-05-28 17:31:26 +00:00
|
|
|
case bm_mode::ogl:
|
2006-03-20 16:43:15 +00:00
|
|
|
#endif
|
2016-02-10 03:58:05 +00:00
|
|
|
{
|
2016-12-29 03:27:08 +00:00
|
|
|
const auto data = &canvas.cv_bitmap.get_bitmap_data()[canvas.cv_bitmap.bm_rowsize * y + x1];
|
|
|
|
const auto cv_fade_level = canvas.cv_fade_level;
|
2016-02-10 03:58:05 +00:00
|
|
|
const auto count = x2 - x1 + 1;
|
2021-09-19 10:53:48 +00:00
|
|
|
if (!gr_fade_table.valid_index(cv_fade_level))
|
2016-02-12 04:02:28 +00:00
|
|
|
gr_linear_stosd(data, static_cast<uint8_t>(color), count);
|
2016-02-10 03:58:05 +00:00
|
|
|
else
|
|
|
|
gr_linear_darken(data, cv_fade_level, count, gr_fade_table);
|
|
|
|
}
|
2006-03-20 16:43:15 +00:00
|
|
|
break;
|
2021-09-12 16:20:52 +00:00
|
|
|
case bm_mode::ilbm:
|
|
|
|
case bm_mode::rgb15:
|
|
|
|
break;
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-26 21:17:29 +00:00
|
|
|
#if DXX_USE_OGL
|
|
|
|
}
|
|
|
|
#endif
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2016-12-29 03:27:08 +00:00
|
|
|
void gr_scanline(grs_canvas &canvas, int x1, int x2, const unsigned y, const uint8_t color)
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
2016-12-29 03:27:08 +00:00
|
|
|
const auto maxy = (canvas.cv_bitmap.bm_h - 1);
|
|
|
|
if (y >= maxy)
|
2016-02-10 03:58:05 +00:00
|
|
|
return;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2016-02-10 03:58:05 +00:00
|
|
|
if (x2 < x1)
|
|
|
|
std::swap(x1, x2);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2016-12-29 03:27:08 +00:00
|
|
|
const auto maxx = (canvas.cv_bitmap.bm_w - 1);
|
|
|
|
if (x1 > maxx) return;
|
2006-03-20 16:43:15 +00:00
|
|
|
if (x2 < MINX) return;
|
|
|
|
|
|
|
|
if (x1 < MINX) x1 = MINX;
|
2016-12-29 03:27:08 +00:00
|
|
|
if (x2 > maxx) x2 = maxx;
|
|
|
|
gr_uscanline(canvas, x1, x2, y, color);
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
2015-12-05 22:57:23 +00:00
|
|
|
|
|
|
|
}
|