Skip to content

Commit 0bd1fec

Browse files
committed
Fix/implement cursor
1 parent bec6d47 commit 0bd1fec

File tree

7 files changed

+49
-14
lines changed

7 files changed

+49
-14
lines changed

src/CDI/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4141
endif()
4242

4343
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
44-
target_compile_options(CeDImu PRIVATE -Wnrvo)
44+
# target_compile_options(CeDImu PRIVATE -Wnrvo)
4545
# target_link_options(CeDImu PUBLIC -fsanitize=address -static-libasan)
4646
target_link_libraries(CeDImu PRIVATE stdc++fs stdc++exp)
4747
endif()

src/CDI/Video/RendererSIMD.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../common/panic.hpp"
44
#include "../common/utils.hpp"
55
#include "../common/VideoSIMD.hpp"
6+
#include "../common/VideoU32.hpp"
67

78
#include <cstring>
89

@@ -65,7 +66,8 @@ const Plane& RendererSIMD::RenderFrame() noexcept
6566
if(m_cursorEnabled)
6667
{
6768
DrawCursor();
68-
Video::paste(m_screen.data(), m_screen.m_width, m_screen.m_height, m_cursorPlane.data(), m_cursorPlane.m_width, m_cursorPlane.m_height, m_cursorX, m_cursorY);
69+
// TODO: double resolution
70+
Video::paste(m_screenARGB.data(), m_screen.m_width, m_screen.m_height, m_cursorPlaneARGB.data(), m_cursorPlaneARGB.m_width, m_cursorPlaneARGB.m_height, m_cursorX >> 1, m_cursorY);
6971
}
7072

7173
// TODO: this should be on the GUI side.
@@ -161,7 +163,7 @@ void RendererSIMD::DrawCursor() noexcept
161163
{
162164
FixedPixelSIMD pixel{&*it, stdx::element_aligned};
163165

164-
for(int x = m_cursorPlaneARGB.m_width, pix = 0; --x >= 0; pix++)
166+
for(int x = m_cursorPlaneARGB.m_width - 1, pix = 0; --x >= 0; pix++)
165167
{
166168
const uint16_t mask = (1 << x);
167169
if(m_cursorPatterns[pattern] & mask)

src/CDI/Video/RendererSoftware.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const Plane& RendererSoftware::RenderFrame() noexcept
6262
if(m_cursorEnabled)
6363
{
6464
DrawCursor();
65-
Video::paste(m_screen.data(), m_screen.m_width, m_screen.m_height, m_cursorPlane.data(), m_cursorPlane.m_width, m_cursorPlane.m_height, m_cursorX, m_cursorY);
65+
Video::paste(m_screen.data(), m_screen.m_width, m_screen.m_height, m_cursorPlane.data(), m_cursorPlane.m_width, m_cursorPlane.m_height, m_cursorX >> 1, m_cursorY);
6666
}
6767

6868
m_lineNumber = 0;

src/CDI/Video/RendererSoftwareU32.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const Plane& RendererSoftwareU32::RenderFrame() noexcept
6464
if(m_cursorEnabled)
6565
{
6666
DrawCursor();
67-
Video::paste(m_screen.data(), m_screen.m_width, m_screen.m_height, m_cursorPlane.data(), m_cursorPlane.m_width, m_cursorPlane.m_height, m_cursorX, m_cursorY);
67+
// TODO: double resolution
68+
Video::paste(m_screenARGB.data(), m_screen.m_width, m_screen.m_height, m_cursorPlaneARGB.data(), m_cursorPlaneARGB.m_width, m_cursorPlaneARGB.m_height, m_cursorX >> 1, m_cursorY);
6869
}
6970

7071
// TODO: this should be on the GUI side.
@@ -137,20 +138,18 @@ void RendererSoftwareU32::DrawCursor() noexcept
137138
const Pixel color = backdropCursorColorToARGB(m_cursorColor);
138139
const Pixel black{0};
139140

140-
int pattern = 0;
141-
for(PlaneU32::iterator it = m_cursorPlaneARGB.begin(); it < m_cursorPlaneARGB.end();)
141+
PlaneU32::iterator it = m_cursorPlaneARGB.begin();
142+
for(int y = 0; y < m_cursorPlaneARGB.m_height; ++y)
142143
{
143-
for(int x = 0; x < m_cursorPlaneARGB.m_width; ++x)
144+
for(int x = m_cursorPlaneARGB.m_width - 1; x >= 0; --x)
144145
{
145146
const uint16_t mask = (1 << x);
146-
if(m_cursorPatterns[pattern] & mask)
147+
if(m_cursorPatterns[y] & mask)
147148
*it = color;
148149
else
149150
*it = black;
150151
++it;
151152
}
152-
153-
++pattern;
154153
}
155154
}
156155

src/CDI/common/Video.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,12 @@ void paste(uint8_t* dst, const uint16_t dstWidth, const uint16_t dstHeight, cons
344344
const uint8_t* srcRow = src + srcWidth * 4 * sy;
345345
for(uint16_t dx = xOffset, sx = 0; dx < dstWidth && sx < srcWidth; dx++, sx++)
346346
{
347-
dstRow[dx * 3] = (srcRow[sx * 4 + 1] * srcRow[sx * 4] + dstRow[dx * 3] * (255 - srcRow[sx * 4])) / 255;
348-
dstRow[dx * 3 + 1] = (srcRow[sx * 4 + 2] * srcRow[sx * 4] + dstRow[dx * 3 + 1] * (255 - srcRow[sx * 4])) / 255;
349-
dstRow[dx * 3 + 2] = (srcRow[sx * 4 + 3] * srcRow[sx * 4] + dstRow[dx * 3 + 2] * (255 - srcRow[sx * 4])) / 255;
347+
if(srcRow[sx * 4] != 0) // Alpha is either 0 or 255.
348+
{
349+
dstRow[dx * 3] = srcRow[sx * 4 + 1];
350+
dstRow[dx * 3 + 1] = srcRow[sx * 4 + 2];
351+
dstRow[dx * 3 + 2] = srcRow[sx * 4 + 3];
352+
}
350353
}
351354
}
352355
}

src/CDI/common/VideoU32.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,33 @@ void decodeDYUVU32(Pixel* dst, const uint16_t pixel, uint32_t& previous) noexcep
298298
matrixRGBU32(&dst[1], y2, u2, v2);
299299
}
300300

301+
/** \brief Copy the ARGB pixels to an ARGB plane.
302+
*
303+
* \param dst The destination ARGB plane.
304+
* \param dstWidth The width of the destination plane.
305+
* \param dstHeight The height of the destination plane.
306+
* \param src The source ARGB plane.
307+
* \param srcWidth The width of the source plane.
308+
* \param srcHeight The width of the source plane.
309+
* \param xOffset The x offset in pixels where the paste will occur on dst.
310+
* \param yOffset The y offset in pixels where the paste will occur on dst.
311+
*
312+
* If the source does not fit in the destination, only the pixels that fit in the destination are copied.
313+
*/
314+
void paste(Pixel* dst, const uint16_t dstWidth, const uint16_t dstHeight, const Pixel* src, const uint16_t srcWidth, const uint16_t srcHeight, const uint16_t xOffset, const uint16_t yOffset)
315+
{
316+
for(uint16_t dy = yOffset, sy = 0; dy < dstHeight && sy < srcHeight; ++dy, ++sy)
317+
{
318+
Pixel* dstRow = dst + dstWidth * dy;
319+
const Pixel* srcRow = src + srcWidth * sy;
320+
for(uint16_t dx = xOffset, sx = 0; dx < dstWidth && sx < srcWidth; ++dx, ++sx)
321+
{
322+
if((srcRow[sx] & 0xFF'00'00'00) != 0) // Alpha is either 0 or 255.
323+
{
324+
dstRow[dx] = srcRow[sx];
325+
}
326+
}
327+
}
328+
}
329+
301330
} // namespace Video

src/CDI/common/VideoU32.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ constexpr void decodeCLUTU32(Pixel* dst, const uint8_t pixel, const uint32_t* CL
6767
*dst = CLUTTable[pixel]; // We don't care about transparency for CLUT.
6868
}
6969

70+
void paste(Pixel* dst, const uint16_t dstWidth, const uint16_t dstHeight, const Pixel* src, const uint16_t srcWidth, const uint16_t srcHeight, const uint16_t xOffset = 0, const uint16_t yOffset = 0);
71+
7072
} // namespace Video
7173

7274
#endif // CDI_COMMON_VIDEOU32_HPP

0 commit comments

Comments
 (0)