// // Created by Wouter Groeneveld on 10/07/20. // //! Plot a single pixel on a 8-bit buffer #include #include #include /*! \param x X-coord. \param y Y-coord. \param clr Color. \param dstBase Canvas pointer (halfword-aligned plz). \param dstP Canvas pitch in bytes. \note Slow as fuck. Inline plotting functionality if possible. */ void bmp8_plot(int x, int y, u32 clr, void *dstBase, uint dstP) { u16 *dstD= (u16*)(dstBase+y*dstP+(x&~1)); if(x&1) *dstD= (*dstD& 0xFF) | (clr<<8); else *dstD= (*dstD&~0xFF) | (clr&0xFF); } //! Draw a horizontal line on an 8bit buffer /*! \param x1 First X-coord. \param y Y-coord. \param x2 Second X-coord. \param clr Color index. \param dstBase Canvas pointer (halfword-aligned plz). \param dstP canvas pitch in bytes. \note Does normalization, but not bounds checks. */ void bmp8_hline(int x1, int y, int x2, u32 clr, void *dstBase, uint dstP) { // --- Normalize --- clr &= 0xFF; if(x2x2) { xstep= -1; dx= x1-x2; } else { xstep= +1; dx= x2-x1; } if(y1>y2) { ystep= -dstP; dy= y1-y2; } else { ystep= +dstP; dy= y2-y1; } // --- Drawing --- // NOTE: because xstep is alternating, you can do marvels // with mask-flips // NOTE: (mask>>31) is equivalent to (x&1) ? 0 : 1 if(dx>=dy) // Diagonal, slopeFx <= 1 { dd= 2*dy - dx; for(ii=dx; ii>=0; ii--) { dstL= (u16*)(addr - (mask>>31)); *dstL= (*dstL &~ mask) | (clr & mask); if(dd >= 0) { dd -= 2*dx; addr += ystep; } dd += 2*dy; addr += xstep; mask = ~mask; } } else // # Diagonal, slopeFx > 1 { dd= 2*dx - dy; for(ii=dy; ii>=0; ii--) { dstL= (u16*)(addr - (mask>>31)); *dstL= (*dstL &~ mask) | (clr & mask); if(dd >= 0) { dd -= 2*dy; addr += xstep; mask = ~mask; } dd += 2*dx; addr += ystep; } } } INLINE void m4_line(int x1, int y1, int x2, int y2, u8 clrid) { bmp8_line(x1, y1, x2, y2, clrid, vid_page, M4_WIDTH); }