| 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 <ranges> |
| 28 |
#include <span> |
| 29 |
#include "gr.h" |
| 30 |
#include "grdef.h" |
| 31 |
|
| 32 |
namespace dcx { |
| 33 |
|
| 34 |
#if DXX_USE_OGL |
| 35 |
namespace { |
| 36 |
#endif |
| 37 |
void gr_uscanline(grs_canvas &canvas, const unsigned x1, const unsigned x2, const unsigned y, const uint8_t color) |
| 38 |
{ |
| 39 |
switch(canvas.cv_bitmap.get_type()) |
| 40 |
{ |
| 41 |
case bm_mode::linear: |
| 42 |
#if DXX_USE_OGL |
| 43 |
case bm_mode::ogl: |
| 44 |
#endif |
| 45 |
{ |
| 46 |
const auto count = x2 - x1 + 1; |
| 47 |
const std::span<uint8_t> data{&canvas.cv_bitmap.get_bitmap_data()[canvas.cv_bitmap.bm_rowsize * y + x1], count}; |
| 48 |
if (const auto r{gr_fade_table.valid_index(canvas.cv_fade_level)}) |
| 49 |
std::ranges::transform(data, data.begin(), [&t = gr_fade_table[*r]](const uint8_t c) { return t[c]; }); |
| 50 |
else |
| 51 |
std::ranges::fill(data, color); |
| 52 |
} |
| 53 |
break; |
| 54 |
case bm_mode::ilbm: |
| 55 |
case bm_mode::rgb15: |
| 56 |
break; |
| 57 |
} |
| 58 |
} |
| 59 |
#if DXX_USE_OGL |
| 60 |
} |
| 61 |
#endif |
| 62 |
|
| 63 |
void gr_scanline(grs_canvas &canvas, int x1, int x2, const unsigned y, const uint8_t color) |
| 64 |
{ |
| 65 |
const auto maxy = (canvas.cv_bitmap.bm_h - 1); |
| 66 |
if (y >= maxy) |
| 67 |
return; |
| 68 |
|
| 69 |
if (x2 < x1) |
| 70 |
std::swap(x1, x2); |
| 71 |
|
| 72 |
const auto maxx = (canvas.cv_bitmap.bm_w - 1); |
| 73 |
if (x1 > maxx) return; |
| 74 |
if (x2 < MINX) return; |
| 75 |
|
| 76 |
if (x1 < MINX) x1 = MINX; |
| 77 |
if (x2 > maxx) x2 = maxx; |
| 78 |
gr_uscanline(canvas, x1, x2, y, color); |
| 79 |
} |
| 80 |
|
| 81 |
} |