mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-12-22 18:39:18 +00:00
[CHG] GRRLIB_GetPixelFromFB now use a real way to get it ;)
[ADD] GRRLIB_SetPixelToFB
This commit is contained in:
parent
46a2297aa6
commit
04cec42e7c
2 changed files with 25 additions and 37 deletions
|
@ -104,9 +104,8 @@ INLINE u32 GRRLIB_GetPixelFromtexImg (const int x, const int y,
|
|||
INLINE void GRRLIB_SetPixelTotexImg (const int x, const int y,
|
||||
GRRLIB_texImg *tex, const u32 color);
|
||||
|
||||
INLINE void GRRLIB_GetPixelFromFB (int x, int y,
|
||||
u8 *R1, u8 *G1, u8 *B1,
|
||||
u8 *R2, u8 *G2, u8 *B2);
|
||||
INLINE u32 GRRLIB_GetPixelFromFB (int x, int y);
|
||||
INLINE void GRRLIB_SetPixelToFB (int x, int y, u32 pokeColor);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// GRRLIB_settings.h - Rendering functions
|
||||
|
|
|
@ -67,44 +67,33 @@ void GRRLIB_SetPixelTotexImg (const int x, const int y,
|
|||
|
||||
/**
|
||||
* Reads a pixel directly from the FrontBuffer.
|
||||
* Since the FB is stored in YCbCr,
|
||||
* @param x The x-coordinate within the FB.
|
||||
* @param y The y-coordinate within the FB.
|
||||
* @param R1 A pointer to a variable receiving the first Red value.
|
||||
* @param G1 A pointer to a variable receiving the first Green value.
|
||||
* @param B1 A pointer to a variable receiving the first Blue value.
|
||||
* @param R2 A pointer to a variable receiving the second Red value.
|
||||
* @param G2 A pointer to a variable receiving the second Green value.
|
||||
* @param B2 A pointer to a variable receiving the second Blue value.
|
||||
*/
|
||||
INLINE
|
||||
void GRRLIB_GetPixelFromFB (int x, int y,
|
||||
u8 *R1, u8 *G1, u8 *B1,
|
||||
u8 *R2, u8 *G2, u8 *B2) {
|
||||
u32 Buffer;
|
||||
u8 *Colors;
|
||||
u32 GRRLIB_GetPixelFromFB (int x, int y) {
|
||||
GXColor peekColor;
|
||||
u32 MyColor;
|
||||
|
||||
// Position Correction
|
||||
if (x > (rmode->fbWidth/2)) { x = (rmode->fbWidth/2); }
|
||||
if (x < 0) { x = 0; }
|
||||
if (y > rmode->efbHeight) { y = rmode->efbHeight; }
|
||||
if (y < 0) { y = 0; }
|
||||
GX_PeekARGB(x, y, &peekColor);
|
||||
MyColor = RGBA(peekColor.r,peekColor.g,peekColor.b,peekColor.a);
|
||||
|
||||
// Preparing FB for reading
|
||||
Buffer = ((u32 *)xfb[fb])[y*(rmode->fbWidth/2)+x];
|
||||
Colors = (u8 *) &Buffer;
|
||||
|
||||
/** Color channel:
|
||||
Colors[0] = Y1
|
||||
Colors[1] = Cb
|
||||
Colors[2] = Y2
|
||||
Colors[3] = Cr */
|
||||
|
||||
*R1 = GRRLIB_ClampVar8( 1.164 * (Colors[0] - 16) + 1.596 * (Colors[3] - 128) );
|
||||
*G1 = GRRLIB_ClampVar8( 1.164 * (Colors[0] - 16) - 0.813 * (Colors[3] - 128) - 0.392 * (Colors[1] - 128) );
|
||||
*B1 = GRRLIB_ClampVar8( 1.164 * (Colors[0] - 16) + 2.017 * (Colors[1] - 128) );
|
||||
|
||||
*R2 = GRRLIB_ClampVar8( 1.164 * (Colors[2] - 16) + 1.596 * (Colors[3] - 128) );
|
||||
*G2 = GRRLIB_ClampVar8( 1.164 * (Colors[2] - 16) - 0.813 * (Colors[3] - 128) - 0.392 * (Colors[1] - 128) );
|
||||
*B2 = GRRLIB_ClampVar8( 1.164 * (Colors[2] - 16) + 2.017 * (Colors[1] - 128) );
|
||||
return (MyColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a pixel directly from the FrontBuffer.
|
||||
* @param x The x-coordinate within the FB.
|
||||
* @param y The y-coordinate within the FB.
|
||||
*/
|
||||
INLINE
|
||||
void GRRLIB_SetPixelToFB (int x, int y, u32 pokeColor) {
|
||||
GXColor MyColor;
|
||||
|
||||
MyColor.r=R(pokeColor);
|
||||
MyColor.g=G(pokeColor);
|
||||
MyColor.b=B(pokeColor);
|
||||
MyColor.a=A(pokeColor);
|
||||
|
||||
GX_PokeARGB(x, y, MyColor);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue