dxx-rebirth/common/2d/pixel.cpp

83 lines
2.3 KiB
C++
Raw Normal View History

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
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.
*/
2006-03-20 16:43:15 +00:00
/*
*
* Graphical routines for setting a pixel.
*
*/
#include "u_mem.h"
#include "gr.h"
#include "grdef.h"
#if DXX_USE_OGL
2006-03-20 16:43:15 +00:00
#include "ogl_init.h"
#endif
2015-12-13 18:00:49 +00:00
namespace dcx {
2015-12-05 22:57:23 +00:00
2017-03-11 19:56:23 +00:00
void gr_upixel(grs_bitmap &cv_bitmap, const unsigned x, const unsigned y, const uint8_t color)
2006-03-20 16:43:15 +00:00
{
2017-03-11 19:56:23 +00:00
switch (cv_bitmap.get_type())
2006-03-20 16:43:15 +00:00
{
#if DXX_USE_OGL
2016-05-28 17:31:26 +00:00
case bm_mode::ogl:
2017-03-11 19:56:23 +00:00
ogl_upixelc(cv_bitmap, x, y, color);
return;
2006-03-20 16:43:15 +00:00
#endif
2016-05-28 17:31:26 +00:00
case bm_mode::linear:
2017-03-11 19:56:23 +00:00
cv_bitmap.get_bitmap_data()[cv_bitmap.bm_rowsize * y + x] = color;
2006-03-20 16:43:15 +00:00
return;
}
2006-03-20 16:43:15 +00:00
}
2017-03-11 19:56:23 +00:00
void gr_pixel(grs_bitmap &cv_bitmap, const unsigned x, const unsigned y, const uint8_t color)
2006-03-20 16:43:15 +00:00
{
2017-03-11 19:56:23 +00:00
if (unlikely(x >= cv_bitmap.bm_w || y >= cv_bitmap.bm_h))
2015-05-09 17:39:00 +00:00
return;
2017-03-11 19:56:23 +00:00
gr_upixel(cv_bitmap, x, y, color);
2006-03-20 16:43:15 +00:00
}
2017-01-01 00:45:44 +00:00
#if !DXX_USE_OGL
#define gr_bm_upixel(C,B,X,Y,C2) gr_bm_upixel(B,X,Y,C2)
#endif
static inline void gr_bm_upixel(grs_canvas &canvas, grs_bitmap &bm, const uint_fast32_t x, const uint_fast32_t y, const uint8_t color)
2006-03-20 16:43:15 +00:00
{
2015-07-25 23:10:47 +00:00
switch (bm.get_type())
2006-03-20 16:43:15 +00:00
{
#if DXX_USE_OGL
2016-05-28 17:31:26 +00:00
case bm_mode::ogl:
2017-03-11 19:56:23 +00:00
ogl_upixelc(canvas.cv_bitmap, bm.bm_x + x, bm.bm_y + y, color);
return;
2006-03-20 16:43:15 +00:00
#endif
2016-05-28 17:31:26 +00:00
case bm_mode::linear:
2014-12-02 03:24:38 +00:00
bm.get_bitmap_data()[bm.bm_rowsize*y+x] = color;
2006-03-20 16:43:15 +00:00
return;
}
2006-03-20 16:43:15 +00:00
}
2017-01-01 00:45:44 +00:00
void gr_bm_pixel(grs_canvas &canvas, grs_bitmap &bm, const uint_fast32_t x, const uint_fast32_t y, const uint8_t color)
2006-03-20 16:43:15 +00:00
{
2015-05-09 17:39:00 +00:00
if (unlikely(x >= bm.bm_w || y >= bm.bm_h))
return;
2017-01-01 00:45:44 +00:00
gr_bm_upixel(canvas, bm, x, y, color);
2006-03-20 16:43:15 +00:00
}
2015-12-05 22:57:23 +00:00
}