From 969bd93381d35197e8b1f83a5528be4cbf3f0dc2 Mon Sep 17 00:00:00 2001 From: YourMJK Date: Sat, 24 Feb 2024 11:16:40 +0100 Subject: [PATCH 1/5] Fix checks for forced display and cropped using `t_compositionObject.objectCroppedFlag` --- main.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index e0f7a36..699339d 100644 --- a/main.cpp +++ b/main.cpp @@ -923,9 +923,13 @@ int main(int32_t argc, char** argv) std::printf(" + Object ID: %u\n", object.objectID); std::printf(" + Window ID: %u\n", object.windowID); std::printf(" + Position: %u,%u\n", object.objectHorPos, object.objectVerPos); - if (object.objectCroppedFlag == 0x40) { - std::printf(" + Object cropped: True\n"); - // TODO: Print crop fields + if (object.objectCroppedFlag & 0x40) { + std::printf(" + Forced display: True\n"); + } + if (object.objectCroppedFlag & 0x80) { + std::printf(" + Cropped: True\n"); + std::printf(" + Cropped position: %u,%u\n", object.objCropHorPos, object.objCropVerPos); + std::printf(" + Cropped size: %ux%u\n", object.objCropWidth, object.objCropHeight); } } } @@ -944,7 +948,7 @@ int main(int32_t argc, char** argv) } for (int i = 0; i < pcs.numCompositionObject; i++) { - if (pcs.compositionObject[i].objectCroppedFlag == 0x40) { + if (pcs.compositionObject[i].objectCroppedFlag & 0x80) { std::fprintf(stderr, "Object Cropped Flag set at timestamp %s! Implement it!\n", timestampString); } @@ -1063,7 +1067,7 @@ int main(int32_t argc, char** argv) t_compositionObject *object = &pcs.compositionObject[j]; if (object->windowID != window->windowID) continue; - if (object->objectCroppedFlag == 0x40) { + if (object->objectCroppedFlag & 0x80) { std::fprintf(stderr, "Object Cropped Flag set at timestamp %s! Crop fields are not supported yet.\n", timestampString); /* object->objCropHorPos += clampedDeltaX; From 2ab5782e94ce30d9220555cb4d0fc25f9f4a8cc8 Mon Sep 17 00:00:00 2001 From: YourMJK Date: Sat, 24 Feb 2024 11:20:38 +0100 Subject: [PATCH 2/5] Implement reading and writing of composition object crop fields and their modification in move mode --- main.cpp | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/main.cpp b/main.cpp index 699339d..ca6be11 100644 --- a/main.cpp +++ b/main.cpp @@ -253,12 +253,10 @@ t_PCS ReadPCS(uint8_t* buffer) { pcs.compositionObject[i].objectCroppedFlag = *(uint8_t*) &buffer[bufferStartIdx + 3]; pcs.compositionObject[i].objectHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 4]); pcs.compositionObject[i].objectVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 6]); - /* - pcs.compositionObject.objCropHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 8]); - pcs.compositionObject.objCropVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 10]); - pcs.compositionObject.objCropWidth = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 12]); - pcs.compositionObject.objCropHeight = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 14]); - */ + pcs.compositionObject[i].objCropHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 8]); + pcs.compositionObject[i].objCropVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 10]); + pcs.compositionObject[i].objCropWidth = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 12]); + pcs.compositionObject[i].objCropHeight = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 14]); } return pcs; @@ -277,19 +275,16 @@ void WritePCS(t_PCS pcs, uint8_t* buffer) { for (int i = 0; i < pcs.numCompositionObject; i++) { size_t bufferStartIdx = 11 + (size_t)i * 8; - *((uint16_t*)(&buffer[bufferStartIdx + 0])) = swapEndianness(pcs.compositionObject[i].objectID); - *((uint8_t*) (&buffer[bufferStartIdx + 2])) = pcs.compositionObject[i].windowID; - *((uint8_t*) (&buffer[bufferStartIdx + 3])) = pcs.compositionObject[i].objectCroppedFlag; - *((uint16_t*)(&buffer[bufferStartIdx + 4])) = swapEndianness(pcs.compositionObject[i].objectHorPos); - *((uint16_t*)(&buffer[bufferStartIdx + 6])) = swapEndianness(pcs.compositionObject[i].objectVerPos); + *((uint16_t*)(&buffer[bufferStartIdx + 0])) = swapEndianness(pcs.compositionObject[i].objectID); + *((uint8_t*) (&buffer[bufferStartIdx + 2])) = pcs.compositionObject[i].windowID; + *((uint8_t*) (&buffer[bufferStartIdx + 3])) = pcs.compositionObject[i].objectCroppedFlag; + *((uint16_t*)(&buffer[bufferStartIdx + 4])) = swapEndianness(pcs.compositionObject[i].objectHorPos); + *((uint16_t*)(&buffer[bufferStartIdx + 6])) = swapEndianness(pcs.compositionObject[i].objectVerPos); + *((uint16_t*)(&buffer[bufferStartIdx + 8])) = swapEndianness(pcs.compositionObject[i].objCropHorPos); + *((uint16_t*)(&buffer[bufferStartIdx + 10])) = swapEndianness(pcs.compositionObject[i].objCropVerPos); + *((uint16_t*)(&buffer[bufferStartIdx + 12])) = swapEndianness(pcs.compositionObject[i].objCropWidth); + *((uint16_t*)(&buffer[bufferStartIdx + 14])) = swapEndianness(pcs.compositionObject[i].objCropHeight); } - - /* - *((uint16_t*)(&buffer[bufferStartIdx + 8])) = swapEndianness(pcs.compositionObject.objCropHorPos); - *((uint16_t*)(&buffer[bufferStartIdx + 10])) = swapEndianness(pcs.compositionObject.objCropVerPos); - *((uint16_t*)(&buffer[bufferStartIdx + 12])) = swapEndianness(pcs.compositionObject.objCropWidth); - *((uint16_t*)(&buffer[bufferStartIdx + 14])) = swapEndianness(pcs.compositionObject.objCropHeight); - */ } t_PDS ReadPDS(uint8_t* buffer, size_t segment_size) { @@ -1068,11 +1063,8 @@ int main(int32_t argc, char** argv) if (object->windowID != window->windowID) continue; if (object->objectCroppedFlag & 0x80) { - std::fprintf(stderr, "Object Cropped Flag set at timestamp %s! Crop fields are not supported yet.\n", timestampString); - /* object->objCropHorPos += clampedDeltaX; object->objCropVerPos += clampedDeltaY; - */ } object->objectHorPos += clampedDeltaX; object->objectVerPos += clampedDeltaY; From 22c1950130dce492cfb27c988cc166c483f690a1 Mon Sep 17 00:00:00 2001 From: YourMJK Date: Sat, 24 Feb 2024 11:24:41 +0100 Subject: [PATCH 3/5] Rename `t_compositionObject.objectCroppedFlag` to `objectCroppedAndForcedFlag` --- main.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/main.cpp b/main.cpp index ca6be11..35aa130 100644 --- a/main.cpp +++ b/main.cpp @@ -106,7 +106,7 @@ struct t_WDS { struct t_compositionObject { uint16_t objectID; uint8_t windowID; - uint8_t objectCroppedFlag; + uint8_t objectCroppedAndForcedFlag; uint16_t objectHorPos; uint16_t objectVerPos; uint16_t objCropHorPos; @@ -248,15 +248,15 @@ t_PCS ReadPCS(uint8_t* buffer) { for (int i = 0; i < pcs.numCompositionObject; i++) { size_t bufferStartIdx = 11 + (size_t)i * 8; - pcs.compositionObject[i].objectID = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 0]); - pcs.compositionObject[i].windowID = *(uint8_t*) &buffer[bufferStartIdx + 2]; - pcs.compositionObject[i].objectCroppedFlag = *(uint8_t*) &buffer[bufferStartIdx + 3]; - pcs.compositionObject[i].objectHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 4]); - pcs.compositionObject[i].objectVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 6]); - pcs.compositionObject[i].objCropHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 8]); - pcs.compositionObject[i].objCropVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 10]); - pcs.compositionObject[i].objCropWidth = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 12]); - pcs.compositionObject[i].objCropHeight = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 14]); + pcs.compositionObject[i].objectID = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 0]); + pcs.compositionObject[i].windowID = *(uint8_t*) &buffer[bufferStartIdx + 2]; + pcs.compositionObject[i].objectCroppedAndForcedFlag = *(uint8_t*) &buffer[bufferStartIdx + 3]; + pcs.compositionObject[i].objectHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 4]); + pcs.compositionObject[i].objectVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 6]); + pcs.compositionObject[i].objCropHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 8]); + pcs.compositionObject[i].objCropVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 10]); + pcs.compositionObject[i].objCropWidth = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 12]); + pcs.compositionObject[i].objCropHeight = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 14]); } return pcs; @@ -277,7 +277,7 @@ void WritePCS(t_PCS pcs, uint8_t* buffer) { *((uint16_t*)(&buffer[bufferStartIdx + 0])) = swapEndianness(pcs.compositionObject[i].objectID); *((uint8_t*) (&buffer[bufferStartIdx + 2])) = pcs.compositionObject[i].windowID; - *((uint8_t*) (&buffer[bufferStartIdx + 3])) = pcs.compositionObject[i].objectCroppedFlag; + *((uint8_t*) (&buffer[bufferStartIdx + 3])) = pcs.compositionObject[i].objectCroppedAndForcedFlag; *((uint16_t*)(&buffer[bufferStartIdx + 4])) = swapEndianness(pcs.compositionObject[i].objectHorPos); *((uint16_t*)(&buffer[bufferStartIdx + 6])) = swapEndianness(pcs.compositionObject[i].objectVerPos); *((uint16_t*)(&buffer[bufferStartIdx + 8])) = swapEndianness(pcs.compositionObject[i].objCropHorPos); @@ -918,10 +918,10 @@ int main(int32_t argc, char** argv) std::printf(" + Object ID: %u\n", object.objectID); std::printf(" + Window ID: %u\n", object.windowID); std::printf(" + Position: %u,%u\n", object.objectHorPos, object.objectVerPos); - if (object.objectCroppedFlag & 0x40) { + if (object.objectCroppedAndForcedFlag & 0x40) { std::printf(" + Forced display: True\n"); } - if (object.objectCroppedFlag & 0x80) { + if (object.objectCroppedAndForcedFlag & 0x80) { std::printf(" + Cropped: True\n"); std::printf(" + Cropped position: %u,%u\n", object.objCropHorPos, object.objCropVerPos); std::printf(" + Cropped size: %ux%u\n", object.objCropWidth, object.objCropHeight); @@ -943,7 +943,7 @@ int main(int32_t argc, char** argv) } for (int i = 0; i < pcs.numCompositionObject; i++) { - if (pcs.compositionObject[i].objectCroppedFlag & 0x80) { + if (pcs.compositionObject[i].objectCroppedAndForcedFlag & 0x80) { std::fprintf(stderr, "Object Cropped Flag set at timestamp %s! Implement it!\n", timestampString); } @@ -1061,8 +1061,7 @@ int main(int32_t argc, char** argv) for (int j = 0; j < pcs.numCompositionObject; j++) { t_compositionObject *object = &pcs.compositionObject[j]; if (object->windowID != window->windowID) continue; - - if (object->objectCroppedFlag & 0x80) { + if (object->objectCroppedAndForcedFlag & 0x80) { object->objCropHorPos += clampedDeltaX; object->objCropVerPos += clampedDeltaY; } From 249d42affbc498490e73fa9e646483cb288b55ea Mon Sep 17 00:00:00 2001 From: YourMJK Date: Mon, 26 Feb 2024 00:33:22 +0100 Subject: [PATCH 4/5] Fix condition for `object_cropped_flag` in kaitai structure file --- sup-parser.ksy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sup-parser.ksy b/sup-parser.ksy index d062f5e..5f25ac9 100644 --- a/sup-parser.ksy +++ b/sup-parser.ksy @@ -109,16 +109,16 @@ types: type: u2 - id: obj_crop_hor_pos type: u2 - if: object_cropped_flag == 0x40 + if: object_cropped_flag & 0x80 != 0 - id: obj_crop_ver_pos type: u2 - if: object_cropped_flag == 0x40 + if: object_cropped_flag & 0x80 != 0 - id: obj_crop_width type: u2 - if: object_cropped_flag == 0x40 + if: object_cropped_flag & 0x80 != 0 - id: obj_crop_height type: u2 - if: object_cropped_flag == 0x40 + if: object_cropped_flag & 0x80 != 0 windows_object_type: seq: From aa93db34f740baaeee24141861b4df3a69477b10 Mon Sep 17 00:00:00 2001 From: MonoS Date: Mon, 26 Feb 2024 11:12:02 +0100 Subject: [PATCH 5/5] Better handle cropped flag when reading/writing And use an enum to list the possible values --- main.cpp | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/main.cpp b/main.cpp index 35aa130..8a0f94f 100644 --- a/main.cpp +++ b/main.cpp @@ -39,6 +39,12 @@ struct t_crop { uint16_t bottom; }; +enum e_objectFlags : uint8_t { + none = 0x00, + forced = 0x40, + cropped = 0x80 +}; + enum e_cutMergeFormat : uint8_t { secut = 0, //"[1000-2000] [3000-4000]" both inclusive vapoursynth = 1, //"[1000:2001] [3000:4001]" start inclusive, end exclusive @@ -245,18 +251,21 @@ t_PCS ReadPCS(uint8_t* buffer) { pcs.paletteID = *(uint8_t*) &buffer[9]; pcs.numCompositionObject = *(uint8_t*) &buffer[10]; + size_t bufferStartIdx = 11; for (int i = 0; i < pcs.numCompositionObject; i++) { - size_t bufferStartIdx = 11 + (size_t)i * 8; - pcs.compositionObject[i].objectID = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 0]); pcs.compositionObject[i].windowID = *(uint8_t*) &buffer[bufferStartIdx + 2]; pcs.compositionObject[i].objectCroppedAndForcedFlag = *(uint8_t*) &buffer[bufferStartIdx + 3]; pcs.compositionObject[i].objectHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 4]); pcs.compositionObject[i].objectVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 6]); - pcs.compositionObject[i].objCropHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 8]); - pcs.compositionObject[i].objCropVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 10]); - pcs.compositionObject[i].objCropWidth = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 12]); - pcs.compositionObject[i].objCropHeight = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 14]); + if (pcs.compositionObject[i].objectCroppedAndForcedFlag & e_objectFlags::cropped){ + pcs.compositionObject[i].objCropHorPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 8]); + pcs.compositionObject[i].objCropVerPos = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 10]); + pcs.compositionObject[i].objCropWidth = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 12]); + pcs.compositionObject[i].objCropHeight = swapEndianness(*(uint16_t*)&buffer[bufferStartIdx + 14]); + bufferStartIdx += 8; + } + bufferStartIdx += 8; } return pcs; @@ -272,18 +281,21 @@ void WritePCS(t_PCS pcs, uint8_t* buffer) { *((uint8_t*) (&buffer[9])) = pcs.paletteID; *((uint8_t*) (&buffer[10])) = pcs.numCompositionObject; + size_t bufferStartIdx = 11; for (int i = 0; i < pcs.numCompositionObject; i++) { - size_t bufferStartIdx = 11 + (size_t)i * 8; - *((uint16_t*)(&buffer[bufferStartIdx + 0])) = swapEndianness(pcs.compositionObject[i].objectID); *((uint8_t*) (&buffer[bufferStartIdx + 2])) = pcs.compositionObject[i].windowID; *((uint8_t*) (&buffer[bufferStartIdx + 3])) = pcs.compositionObject[i].objectCroppedAndForcedFlag; *((uint16_t*)(&buffer[bufferStartIdx + 4])) = swapEndianness(pcs.compositionObject[i].objectHorPos); *((uint16_t*)(&buffer[bufferStartIdx + 6])) = swapEndianness(pcs.compositionObject[i].objectVerPos); - *((uint16_t*)(&buffer[bufferStartIdx + 8])) = swapEndianness(pcs.compositionObject[i].objCropHorPos); - *((uint16_t*)(&buffer[bufferStartIdx + 10])) = swapEndianness(pcs.compositionObject[i].objCropVerPos); - *((uint16_t*)(&buffer[bufferStartIdx + 12])) = swapEndianness(pcs.compositionObject[i].objCropWidth); - *((uint16_t*)(&buffer[bufferStartIdx + 14])) = swapEndianness(pcs.compositionObject[i].objCropHeight); + if (pcs.compositionObject[i].objectCroppedAndForcedFlag & e_objectFlags::cropped){ + *((uint16_t*)(&buffer[bufferStartIdx + 8])) = swapEndianness(pcs.compositionObject[i].objCropHorPos); + *((uint16_t*)(&buffer[bufferStartIdx + 10])) = swapEndianness(pcs.compositionObject[i].objCropVerPos); + *((uint16_t*)(&buffer[bufferStartIdx + 12])) = swapEndianness(pcs.compositionObject[i].objCropWidth); + *((uint16_t*)(&buffer[bufferStartIdx + 14])) = swapEndianness(pcs.compositionObject[i].objCropHeight); + bufferStartIdx += 8; + } + bufferStartIdx += 8; } } @@ -918,10 +930,10 @@ int main(int32_t argc, char** argv) std::printf(" + Object ID: %u\n", object.objectID); std::printf(" + Window ID: %u\n", object.windowID); std::printf(" + Position: %u,%u\n", object.objectHorPos, object.objectVerPos); - if (object.objectCroppedAndForcedFlag & 0x40) { + if (object.objectCroppedAndForcedFlag & e_objectFlags::forced) { std::printf(" + Forced display: True\n"); } - if (object.objectCroppedAndForcedFlag & 0x80) { + if (object.objectCroppedAndForcedFlag & e_objectFlags::cropped) { std::printf(" + Cropped: True\n"); std::printf(" + Cropped position: %u,%u\n", object.objCropHorPos, object.objCropVerPos); std::printf(" + Cropped size: %ux%u\n", object.objCropWidth, object.objCropHeight); @@ -943,7 +955,7 @@ int main(int32_t argc, char** argv) } for (int i = 0; i < pcs.numCompositionObject; i++) { - if (pcs.compositionObject[i].objectCroppedAndForcedFlag & 0x80) { + if (pcs.compositionObject[i].objectCroppedAndForcedFlag & e_objectFlags::cropped) { std::fprintf(stderr, "Object Cropped Flag set at timestamp %s! Implement it!\n", timestampString); } @@ -1061,7 +1073,7 @@ int main(int32_t argc, char** argv) for (int j = 0; j < pcs.numCompositionObject; j++) { t_compositionObject *object = &pcs.compositionObject[j]; if (object->windowID != window->windowID) continue; - if (object->objectCroppedAndForcedFlag & 0x80) { + if (object->objectCroppedAndForcedFlag & e_objectFlags::cropped) { object->objCropHorPos += clampedDeltaX; object->objCropVerPos += clampedDeltaY; }