OSDN Git Service

fix CSC region extraction.
[qtheora/main.git] / Lib / QTheoraEx / CSConverter.c
index 30cde92..20c3868 100644 (file)
@@ -18,31 +18,29 @@ void QT_CSConvert_YV12(
        UINT8* pb2 = pb1 + frame->Rasters * frame->Pitch / 4;
        UINT8* end;
 
-       const UINT8* s0 = output->Plane[0] + (output->CY     - 1) * output->CX;
-       const UINT8* s1 = output->Plane[2] + (output->CY / 2 - 1) * output->CX / 2;
-       const UINT8* s2 = output->Plane[1] + (output->CY / 2 - 1) * output->CX / 2;
+       INT32 r0 = output->CY - frame->Y;
 
-       pb0 += frame->Y * frame->Pitch + frame->X;
-       pb1 += frame->Y * frame->Pitch / 2 + frame->X / 2;
-       pb2 += frame->Y * frame->Pitch / 2 + frame->X / 2;
+       const UINT8* s0 = output->Plane[0] + frame->X + (r0     - 1) * output->CX;
+       const UINT8* s1 = output->Plane[2] + frame->X + (r0 / 2 - 1) * output->CX / 2;
+       const UINT8* s2 = output->Plane[1] + frame->X + (r0 / 2 - 1) * output->CX / 2;
 
-       end = pb0 + output->CY * frame->Pitch;
+       end = pb0 + frame->CY * frame->Pitch;
        while (pb0 < end) {
-               memcpy(pb0, s0, output->CX);
+               memcpy(pb0, s0, frame->CX);
                pb0 += frame->Pitch;
                s0  -= output->CX;
        }
 
-       end = pb1 + (output->CY / 2) * (frame->Pitch / 2);
+       end = pb1 + (frame->CY / 2) * (frame->Pitch / 2);
        while (pb1 < end) {
-               memcpy(pb1, s1, output->CX / 2);
+               memcpy(pb1, s1, frame->CX / 2);
                pb1 += frame->Pitch / 2;
                s1  -= output->CX / 2;
        }
 
-       end = pb2 + (output->CY / 2) * (frame->Pitch / 2);
+       end = pb2 + (frame->CY / 2) * (frame->Pitch / 2);
        while (pb2 < end) {
-               memcpy(pb2, s2, output->CX / 2);
+               memcpy(pb2, s2, frame->CX / 2);
                pb2 += frame->Pitch / 2;
                s2  -= output->CX / 2;
        }
@@ -52,17 +50,19 @@ void QT_CSConvert_YUY2(
        const QT_Output_t* output,
        QT_Frame_t*        frame)
 {
-       UINT8* pb  = (UINT8*)(frame->Frame) + frame->Y * frame->Pitch + frame->X;
-       UINT8* end = pb + output->CY * frame->Pitch;
+       UINT8* pb  = (UINT8*)(frame->Frame);
+       UINT8* end = pb + frame->CY * frame->Pitch;
 
-       const UINT8* s0 = output->Plane[0] + (output->CY     - 1) * output->CX;
-       const UINT8* s1 = output->Plane[1] + (output->CY / 2 - 1) * output->CX / 2;
-       const UINT8* s2 = output->Plane[2] + (output->CY / 2 - 1) * output->CX / 2;
+       INT32 r0 = output->CY - frame->Y;
+
+       const UINT8* s0 = output->Plane[0] + frame->X + (r0     - 1) * output->CX;
+       const UINT8* s1 = output->Plane[1] + frame->X + (r0 / 2 - 1) * output->CX / 2;
+       const UINT8* s2 = output->Plane[2] + frame->X + (r0 / 2 - 1) * output->CX / 2;
 
        for (; pb < end; pb += frame->Pitch * 2, s0 -= output->CX * 2, s1 -= output->CX / 2, s2 -= output->CX / 2) {
                UINT8* pb0 = pb;
                UINT8* pb1 = pb + frame->Pitch;
-               UINT8* pe0 = pb + output->CX * 2;
+               UINT8* pe0 = pb + frame->CX * 2;
 
                const UINT8* y0 = s0;
                const UINT8* y1 = s0 - output->CX;