Skip to content

Commit

Permalink
camera: fix x-flip crustiness
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Oct 2, 2022
1 parent 3f45735 commit af9a77b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
27 changes: 20 additions & 7 deletions src/DSi_Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,16 +505,29 @@ int Camera::TransferScanline(u32* buffer, int maxlen)
if (FrameReadMode & (1<<1))
sy = 479 - sy;

for (int dx = 0; dx < retlen; dx++)
if (FrameReadMode & (1<<0))
{
if (dx >= maxlen) break;
for (int dx = 0; dx < retlen; dx++)
{
if (dx >= maxlen) break;

int sx = (dx * 640) / FrameWidth;
if (!(FrameReadMode & (1<<0)))
sx = 639 - sx;
int sx = (dx * 640) / FrameWidth;

u32 pixel3 = FrameBuffer[sy*320 + sx];
buffer[dx] = pixel3;
u32 val = FrameBuffer[sy*320 + sx];
buffer[dx] = val;
}
}
else
{
for (int dx = 0; dx < retlen; dx++)
{
if (dx >= maxlen) break;

int sx = 638 - ((dx * 640) / FrameWidth);

u32 val = FrameBuffer[sy*320 + sx];
buffer[dx] = (val & 0xFF00FF00) | ((val >> 16) & 0xFF) | ((val & 0xFF) << 16);
}
}

TransferY++;
Expand Down
32 changes: 25 additions & 7 deletions src/frontend/qt_sdl/CameraManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,10 @@ void CameraManager::feedFrame_NV12(u8* planeY, u8* planeUV, int width, int heigh

void CameraManager::copyFrame_Straight(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight, bool xflip, bool yuv)
{
u32 alpha = 0xFF000000;

if (yuv)
{
swidth /= 2;
dwidth /= 2;
alpha = 0;
}

for (int dy = 0; dy < dheight; dy++)
Expand All @@ -465,7 +462,19 @@ void CameraManager::copyFrame_Straight(u32* src, int swidth, int sheight, u32* d
int sx = (dx * swidth) / dwidth;
if (xflip) sx = swidth-1 - sx;

dst[(dy * dwidth) + dx] = src[(sy * swidth) + sx] | alpha;
u32 val = src[(sy * swidth) + sx];

if (yuv)
{
if (xflip)
val = (val & 0xFF00FF00) |
((val >> 16) & 0xFF) |
((val & 0xFF) << 16);
}
else
val |= 0xFF000000;

dst[(dy * dwidth) + dx] = val;
}
}
}
Expand Down Expand Up @@ -530,13 +539,22 @@ void CameraManager::copyFrame_YUVtoRGB(u32* src, int swidth, int sheight, u32* d
for (int dx = 0; dx < dwidth; dx+=2)
{
int sx = (dx * swidth) / dwidth;
if (xflip) sx = swidth-1 - sx;
if (xflip) sx = swidth-2 - sx;

u32 val = src[(sy*swidth + sx) / 2];

int y1 = val & 0xFF;
int y1, y2;
if (xflip)
{
y1 = (val >> 16) & 0xFF;
y2 = val & 0xFF;
}
else
{
y1 = val & 0xFF;
y2 = (val >> 16) & 0xFF;
}
int u = (val >> 8) & 0xFF;
int y2 = (val >> 16) & 0xFF;
int v = (val >> 24) & 0xFF;

u -= 128; v -= 128;
Expand Down

0 comments on commit af9a77b

Please sign in to comment.