Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NTSC-J support to ld-chroma-encoder #754

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tools/ld-chroma-decoder/encoder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ int main(int argc, char *argv[])
QCoreApplication::translate("main", "chroma-mode"));
parser.addOption(chromaOption);

// Option to disable 7.5 IRE setup, as in NTSC-J (--no-setup)
QCommandLineOption setupOption(QStringList() << "no-setup",
QCoreApplication::translate("main", "NTSC only. Do not add 7.5 IRE setup (as in NTSC-J)"));
parser.addOption(setupOption);

// -- Positional arguments --

// Positional argument to specify input video file
Expand Down Expand Up @@ -129,6 +134,8 @@ int main(int argc, char *argv[])
}
}

bool addSetup = !parser.isSet(setupOption);

ChromaMode chromaMode = WIDEBAND_YUV;
QString chromaName;
if (parser.isSet(chromaOption)) {
Expand Down Expand Up @@ -168,7 +175,7 @@ int main(int argc, char *argv[])
// Encode the data
LdDecodeMetaData metaData;
if( system == NTSC ) {
NTSCEncoder encoder(rgbFile, tbcFile, metaData, chromaMode);
NTSCEncoder encoder(rgbFile, tbcFile, metaData, chromaMode, addSetup);
if (!encoder.encode()) {
return -1;
}
Expand Down
12 changes: 5 additions & 7 deletions tools/ld-chroma-decoder/encoder/ntscencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
#include <array>
#include <cmath>

NTSCEncoder::NTSCEncoder(QFile &_rgbFile, QFile &_tbcFile, LdDecodeMetaData &_metaData, ChromaMode &_chromaMode)
: rgbFile(_rgbFile), tbcFile(_tbcFile), metaData(_metaData), chromaMode(_chromaMode)
NTSCEncoder::NTSCEncoder(QFile &_rgbFile, QFile &_tbcFile, LdDecodeMetaData &_metaData, ChromaMode &_chromaMode, bool &_addSetup)
: rgbFile(_rgbFile), tbcFile(_tbcFile), metaData(_metaData), chromaMode(_chromaMode), addSetup(_addSetup)
{
// NTSC subcarrier frequency [Poynton p511]
videoParameters.fSC = 315.0e6 / 88.0;
Expand Down Expand Up @@ -94,9 +94,7 @@ NTSCEncoder::NTSCEncoder(QFile &_rgbFile, QFile &_tbcFile, LdDecodeMetaData &_me
// White level, black level, and blanking level, extended to 16 bits
// [SMPTE p2, Poynton p517]
videoParameters.white16bIre = 0xC800;
const qint32 blankingIre = 0x3C00;
const qint32 ntscSetup = 0x0A80; // 10.5 * 256
videoParameters.black16bIre = blankingIre + ntscSetup; // (60 + 10.5) * 256
videoParameters.black16bIre = blankingIre + (addSetup ? setupIreOffset : 0);
videoParameters.fieldWidth = 910;
videoParameters.fieldHeight = 263;
videoParameters.isMapped = false;
Expand Down Expand Up @@ -284,9 +282,9 @@ static constexpr auto uvFilter = makeFIRFilter(uvFilterCoeffs);

void NTSCEncoder::encodeLine(qint32 fieldNo, qint32 frameLine, const quint16 *rgbData, QVector<quint16> &outputLine)
{
// Resize the output line and fill with black
// Resize the output line and fill with blanking
outputLine.resize(videoParameters.fieldWidth);
outputLine.fill(videoParameters.black16bIre - 0x0A80);
outputLine.fill(blankingIre);

// Skip encoding the last (dummy) frameLine
if (frameLine == 525)
Expand Down
6 changes: 5 additions & 1 deletion tools/ld-chroma-decoder/encoder/ntscencoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum ChromaMode {
class NTSCEncoder
{
public:
NTSCEncoder(QFile &rgbFile, QFile &tbcFile, LdDecodeMetaData &metaData, ChromaMode &chromaMode);
NTSCEncoder(QFile &rgbFile, QFile &tbcFile, LdDecodeMetaData &metaData, ChromaMode &chromaMode, bool &addSetup);

// Encode RGB stream to NTSC.
// Returns true on success; on failure, prints an error and returns false.
Expand All @@ -51,10 +51,14 @@ class NTSCEncoder
bool encodeField(qint32 fieldNo);
void encodeLine(qint32 fieldNo, qint32 frameLine, const quint16 *rgbData, QVector<quint16> &outputLine);

const qint32 blankingIre = 0x3C00;
const qint32 setupIreOffset = 0x0A80; // 10.5 * 256

QFile &rgbFile;
QFile &tbcFile;
LdDecodeMetaData &metaData;
ChromaMode chromaMode;
bool addSetup;

LdDecodeMetaData::VideoParameters videoParameters;
qint32 activeWidth;
Expand Down