Skip to content

Commit

Permalink
Merge pull request #446 from atsampson/chromaactive
Browse files Browse the repository at this point in the history
Use VideoParameters::first/lastActiveFrameLine directly in more places
  • Loading branch information
Simon Inns committed Jan 27, 2020
2 parents 06a88e4 + a4c8110 commit fdc4c7b
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 130 deletions.
14 changes: 2 additions & 12 deletions tools/ld-analyse/tbcsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,23 +555,13 @@ QImage TbcSource::generateQImage(qint32 firstFieldNumber, qint32 secondFieldNumb
firstField.data = sourceVideo.getVideoField(firstFieldNumber);
secondField.data = sourceVideo.getVideoField(secondFieldNumber);

qint32 firstActiveLine, lastActiveLine;
RGBFrame rgbFrame;

// Decode colour for the current frame, to RGB 16-16-16 interlaced output
RGBFrame rgbFrame;
if (videoParameters.isSourcePal) {
// PAL source

firstActiveLine = palColourConfiguration.firstActiveLine;
lastActiveLine = palColourConfiguration.lastActiveLine;

rgbFrame = palColour.decodeFrame(firstField, secondField);
} else {
// NTSC source

firstActiveLine = ntscColour.getConfiguration().firstActiveLine;
lastActiveLine = ntscColour.getConfiguration().lastActiveLine;

rgbFrame = ntscColour.decodeFrame(firstField, secondField);
}

Expand All @@ -582,7 +572,7 @@ QImage TbcSource::generateQImage(qint32 firstFieldNumber, qint32 secondFieldNumb
frameImage.fill(Qt::black);

// Copy the RGB16-16-16 data into the RGB888 QImage
for (qint32 y = firstActiveLine; y < lastActiveLine; y++) {
for (qint32 y = videoParameters.firstActiveFrameLine; y < videoParameters.lastActiveFrameLine; y++) {
for (qint32 x = videoParameters.activeVideoStart; x < videoParameters.activeVideoEnd; x++) {
qint32 pixelOffset = ((y * videoParameters.fieldWidth) + x) * 3;

Expand Down
28 changes: 12 additions & 16 deletions tools/ld-chroma-decoder/comb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ void Comb::updateConfiguration(const LdDecodeMetaData::VideoParameters &_videoPa
// Set the frame height
frameHeight = ((videoParameters.fieldHeight * 2) - 1);

// Set the first and last active line
configuration.firstActiveLine = videoParameters.firstActiveFrameLine;
configuration.lastActiveLine = videoParameters.lastActiveFrameLine;

configurationSet = true;
}

Expand Down Expand Up @@ -214,7 +210,7 @@ inline bool Comb::GetLinePhase(FrameBuffer *frameBuffer, qint32 lineNumber)

void Comb::split1D(FrameBuffer *frameBuffer)
{
for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
// Get a pointer to the line's data
const quint16 *line = frameBuffer->rawbuffer.data() + (lineNumber * videoParameters.fieldWidth);

Expand All @@ -233,16 +229,16 @@ void Comb::split2D(FrameBuffer *frameBuffer)
// Dummy black line.
static constexpr qreal blackLine[911] = {0};

for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
// Get pointers to the surrounding lines.
// If a line we need is outside the active area, use blackLine instead.
const qreal *previousLine = blackLine;
if (lineNumber - 2 >= configuration.firstActiveLine) {
if (lineNumber - 2 >= videoParameters.firstActiveFrameLine) {
previousLine = frameBuffer->clpbuffer[0].pixel[lineNumber - 2];
}
const qreal *currentLine = frameBuffer->clpbuffer[0].pixel[lineNumber];
const qreal *nextLine = blackLine;
if (lineNumber + 2 < configuration.lastActiveLine) {
if (lineNumber + 2 < videoParameters.lastActiveFrameLine) {
nextLine = frameBuffer->clpbuffer[0].pixel[lineNumber + 2];
}

Expand Down Expand Up @@ -299,7 +295,7 @@ void Comb::split3D(FrameBuffer *currentFrame, FrameBuffer *previousFrame)
previousFrame = currentFrame;
}

for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
const quint16 *currentLine = currentFrame->rawbuffer.data() + (lineNumber * videoParameters.fieldWidth);
const quint16 *previousLine = previousFrame->rawbuffer.data() + (lineNumber * videoParameters.fieldWidth);

Expand All @@ -315,7 +311,7 @@ void Comb::splitIQ(FrameBuffer *frameBuffer)
// Clear the target frame YIQ buffer
frameBuffer->yiqBuffer.clear();

for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
// Get a pointer to the line's data
const quint16 *line = frameBuffer->rawbuffer.data() + (lineNumber * videoParameters.fieldWidth);
bool linePhase = GetLinePhase(frameBuffer, lineNumber);
Expand Down Expand Up @@ -359,7 +355,7 @@ void Comb::filterIQ(YiqBuffer &yiqBuffer)
auto iFilter(f_colorlpi);
auto qFilter(configuration.colorlpf_hq ? f_colorlpi : f_colorlpq);

for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
iFilter.clear();
qFilter.clear();

Expand Down Expand Up @@ -406,7 +402,7 @@ void Comb::doCNR(YiqBuffer &yiqBuffer)
QVector<YIQ> hplinef;
hplinef.resize(videoParameters.fieldWidth + 32);

for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
// Filters not cleared from previous line

for (qint32 h = videoParameters.activeVideoStart; h <= videoParameters.activeVideoEnd; h++) {
Expand Down Expand Up @@ -446,7 +442,7 @@ void Comb::doYNR(YiqBuffer &yiqBuffer)
QVector<YIQ> hplinef;
hplinef.resize(videoParameters.fieldWidth + 32);

for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
// Filter not cleared from previous line

for (qint32 h = videoParameters.activeVideoStart; h <= videoParameters.activeVideoEnd; h++) {
Expand Down Expand Up @@ -478,7 +474,7 @@ RGBFrame Comb::yiqToRgbFrame(const YiqBuffer &yiqBuffer, qreal burstLevel)
RGB rgb(videoParameters.white16bIre, videoParameters.black16bIre, configuration.whitePoint100, configuration.blackAndWhite, burstLevel);

// Perform YIQ to RGB conversion
for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
// Get a pointer to the line
quint16 *linePointer = rgbOutputFrame.data() + (videoParameters.fieldWidth * 3 * lineNumber);

Expand Down Expand Up @@ -506,7 +502,7 @@ void Comb::overlayOpticalFlowMap(const FrameBuffer &frameBuffer, RGBFrame &rgbFr
// opticalFlow.motionK(motionKMap);

// Overlay the optical flow map on the output RGB
for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
// Get a pointer to the line
quint16 *linePointer = rgbFrame.data() + (videoParameters.fieldWidth * 3 * lineNumber);

Expand All @@ -533,7 +529,7 @@ void Comb::overlayOpticalFlowMap(const FrameBuffer &frameBuffer, RGBFrame &rgbFr
void Comb::adjustY(FrameBuffer *frameBuffer, YiqBuffer &yiqBuffer)
{
// remove color data from baseband (Y)
for (qint32 lineNumber = configuration.firstActiveLine; lineNumber < configuration.lastActiveLine; lineNumber++) {
for (qint32 lineNumber = videoParameters.firstActiveFrameLine; lineNumber < videoParameters.lastActiveFrameLine; lineNumber++) {
bool linePhase = GetLinePhase(frameBuffer, lineNumber);

for (qint32 h = videoParameters.activeVideoStart; h < videoParameters.activeVideoEnd; h++) {
Expand Down
5 changes: 0 additions & 5 deletions tools/ld-chroma-decoder/comb.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ class Comb
bool use3D = false;
bool showOpticalFlowMap = false;

// Interlaced line 40 is NTSC line 21 (the closed-caption line before the first active half-line)
qint32 firstActiveLine = 40;
// Interlaced line 524 is NTSC line 263 (the last active half-line).
qint32 lastActiveLine = 525;

qreal cNRLevel = 0.0;
qreal yNRLevel = 1.0;
};
Expand Down
11 changes: 4 additions & 7 deletions tools/ld-chroma-decoder/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ qint32 Decoder::getLookAhead() const
return 0;
}

void Decoder::setVideoParameters(Decoder::Configuration &config, const LdDecodeMetaData::VideoParameters &videoParameters,
qint32 firstActiveLine, qint32 lastActiveLine) {

void Decoder::setVideoParameters(Decoder::Configuration &config, const LdDecodeMetaData::VideoParameters &videoParameters) {
config.videoParameters = videoParameters;
config.firstActiveLine = firstActiveLine;
config.lastActiveLine = lastActiveLine;
config.topPadLines = 0;
config.bottomPadLines = 0;

Expand All @@ -65,7 +61,8 @@ void Decoder::setVideoParameters(Decoder::Configuration &config, const LdDecodeM
// Insert empty padding lines so the height is divisible by 8
qint32 outputHeight;
while (true) {
outputHeight = config.topPadLines + (config.lastActiveLine - config.firstActiveLine) + config.bottomPadLines;
const qint32 numActiveLines = videoParameters.lastActiveFrameLine - videoParameters.firstActiveFrameLine;
outputHeight = config.topPadLines + numActiveLines + config.bottomPadLines;
if ((outputHeight % 8) == 0) {
break;
}
Expand Down Expand Up @@ -97,7 +94,7 @@ RGBFrame Decoder::cropOutputFrame(const Decoder::Configuration &config, const RG
}

// Copy the active region from the decoded image
for (qint32 y = config.firstActiveLine; y < config.lastActiveLine; y++) {
for (qint32 y = config.videoParameters.firstActiveFrameLine; y < config.videoParameters.lastActiveFrameLine; y++) {
croppedData.append(outputData.mid((y * config.videoParameters.fieldWidth * 3) + (activeVideoStart * 3),
outputLineLength));
}
Expand Down
5 changes: 1 addition & 4 deletions tools/ld-chroma-decoder/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,13 @@ class Decoder {
struct Configuration {
// Parameters computed from the video metadata
LdDecodeMetaData::VideoParameters videoParameters;
qint32 firstActiveLine;
qint32 lastActiveLine;
qint32 topPadLines;
qint32 bottomPadLines;
};

// Compute the output frame size in Configuration, adjusting the active
// video region as required
static void setVideoParameters(Configuration &config, const LdDecodeMetaData::VideoParameters &videoParameters,
qint32 firstActiveLine, qint32 lastActiveLine);
static void setVideoParameters(Configuration &config, const LdDecodeMetaData::VideoParameters &videoParameters);

// Crop a full decoded frame to the output frame size
static RGBFrame cropOutputFrame(const Configuration &config, const RGBFrame &outputData);
Expand Down
10 changes: 4 additions & 6 deletions tools/ld-chroma-decoder/framecanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,19 @@
// pre-C++17 compilers
constexpr FrameCanvas::RGB FrameCanvas::green;

FrameCanvas::FrameCanvas(RGBFrame &_rgbFrame, const LdDecodeMetaData::VideoParameters &_videoParameters,
qint32 _firstActiveLine, qint32 _lastActiveLine)
: rgbData(_rgbFrame.data()), rgbSize(_rgbFrame.size()),
videoParameters(_videoParameters), firstActiveLine(_firstActiveLine), lastActiveLine(_lastActiveLine)
FrameCanvas::FrameCanvas(RGBFrame &_rgbFrame, const LdDecodeMetaData::VideoParameters &_videoParameters)
: rgbData(_rgbFrame.data()), rgbSize(_rgbFrame.size()), videoParameters(_videoParameters)
{
}

qint32 FrameCanvas::top()
{
return firstActiveLine;
return videoParameters.firstActiveFrameLine;
}

qint32 FrameCanvas::bottom()
{
return lastActiveLine;
return videoParameters.lastActiveFrameLine;
}

qint32 FrameCanvas::left()
Expand Down
5 changes: 1 addition & 4 deletions tools/ld-chroma-decoder/framecanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class FrameCanvas {
public:
// rgbFrame is the frame to draw upon, and videoParameters gives its dimensions.
// (Both parameters are captured by reference, not copied.)
FrameCanvas(RGBFrame &rgbFrame, const LdDecodeMetaData::VideoParameters &videoParameters,
qint32 firstActiveLine, qint32 lastActiveLine);
FrameCanvas(RGBFrame &rgbFrame, const LdDecodeMetaData::VideoParameters &videoParameters);

// Return the edges of the active area.
qint32 top();
Expand Down Expand Up @@ -65,8 +64,6 @@ class FrameCanvas {
quint16 *rgbData;
qint32 rgbSize;
const LdDecodeMetaData::VideoParameters &videoParameters;
qint32 firstActiveLine;
qint32 lastActiveLine;
};

#endif
15 changes: 2 additions & 13 deletions tools/ld-chroma-decoder/monodecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,9 @@

bool MonoDecoder::configure(const LdDecodeMetaData::VideoParameters &videoParameters) {
// This decoder works for both PAL and NTSC.
// Get the active line range from either Comb or PalColour.
qint32 firstActiveLine, lastActiveLine;
if (videoParameters.isSourcePal) {
PalColour::Configuration palConfig;
firstActiveLine = palConfig.firstActiveLine;
lastActiveLine = palConfig.lastActiveLine;
} else {
Comb::Configuration combConfig;
firstActiveLine = combConfig.firstActiveLine;
lastActiveLine = combConfig.lastActiveLine;
}

// Compute cropping parameters
setVideoParameters(config, videoParameters, firstActiveLine, lastActiveLine);
setVideoParameters(config, videoParameters);

return true;
}
Expand Down Expand Up @@ -72,7 +61,7 @@ void MonoThread::decodeFrames(const QVector<SourceField> &inputFields, qint32 st

for (qint32 fieldIndex = startIndex, frameIndex = 0; fieldIndex < endIndex; fieldIndex += 2, frameIndex++) {
// Interlace the active lines of the two input fields to produce an output frame
for (qint32 y = config.firstActiveLine; y < config.lastActiveLine; y++) {
for (qint32 y = config.videoParameters.firstActiveFrameLine; y < config.videoParameters.lastActiveFrameLine; y++) {
const SourceVideo::Data &inputFieldData = (y % 2) == 0 ? inputFields[fieldIndex].data : inputFields[fieldIndex + 1].data;

// Each quint16 input becomes three quint16 outputs
Expand Down
2 changes: 1 addition & 1 deletion tools/ld-chroma-decoder/ntscdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool NtscDecoder::configure(const LdDecodeMetaData::VideoParameters &videoParame
}

// Compute cropping parameters
setVideoParameters(config, videoParameters, config.combConfig.firstActiveLine, config.combConfig.lastActiveLine);
setVideoParameters(config, videoParameters);

return true;
}
Expand Down
15 changes: 5 additions & 10 deletions tools/ld-chroma-decoder/palcolour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ void PalColour::updateConfiguration(const LdDecodeMetaData::VideoParameters &_vi
// Build the look-up tables
buildLookUpTables();

// Set the frame area
configuration.firstActiveLine = videoParameters.firstActiveFrameLine;
configuration.lastActiveLine = videoParameters.lastActiveFrameLine;

if (configuration.chromaFilter == transform2DFilter || configuration.chromaFilter == transform3DFilter) {
// Create the Transform PAL filter
if (configuration.chromaFilter == transform2DFilter) {
Expand All @@ -127,8 +123,7 @@ void PalColour::updateConfiguration(const LdDecodeMetaData::VideoParameters &_vi
}

// Configure the filter
transformPal->updateConfiguration(videoParameters, configuration.firstActiveLine, configuration.lastActiveLine,
configuration.transformMode, configuration.transformThreshold,
transformPal->updateConfiguration(videoParameters, configuration.transformMode, configuration.transformThreshold,
configuration.transformThresholds);
}

Expand Down Expand Up @@ -305,8 +300,8 @@ void PalColour::decodeField(const SourceField &inputField, const double *chromaD
// Pointer to the composite signal data
const quint16 *compPtr = inputField.data.data();

const qint32 firstLine = inputField.getFirstActiveLine(configuration.firstActiveLine);
const qint32 lastLine = inputField.getLastActiveLine(configuration.lastActiveLine);
const qint32 firstLine = inputField.getFirstActiveLine(videoParameters);
const qint32 lastLine = inputField.getLastActiveLine(videoParameters);
for (qint32 fieldLine = firstLine; fieldLine < lastLine; fieldLine++) {
LineInfo line(fieldLine);

Expand Down Expand Up @@ -410,8 +405,8 @@ void PalColour::decodeLine(const SourceField &inputField, const ChromaSample *ch

// Get pointers to the surrounding lines of input data.
// If a line we need is outside the active area, use blackLine instead.
const qint32 firstLine = inputField.getFirstActiveLine(configuration.firstActiveLine);
const qint32 lastLine = inputField.getLastActiveLine(configuration.lastActiveLine);
const qint32 firstLine = inputField.getFirstActiveLine(videoParameters);
const qint32 lastLine = inputField.getLastActiveLine(videoParameters);
const ChromaSample *in0, *in1, *in2, *in3, *in4, *in5, *in6;
in0 = chromaData + (line.number * videoParameters.fieldWidth);
in1 = (line.number - 1) < firstLine ? blackLine : (chromaData + ((line.number - 1) * videoParameters.fieldWidth));
Expand Down
5 changes: 0 additions & 5 deletions tools/ld-chroma-decoder/palcolour.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ class PalColour : public QObject
qint32 showPositionX = 200;
qint32 showPositionY = 200;

// Interlaced line 44 is PAL line 23 (the first active half-line)
qint32 firstActiveLine = 44;
// Interlaced line 619 is PAL line 623 (the last active half-line)
qint32 lastActiveLine = 620;

qint32 getThresholdsSize() const;
qint32 getLookBehind() const;
qint32 getLookAhead() const;
Expand Down
2 changes: 1 addition & 1 deletion tools/ld-chroma-decoder/paldecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool PalDecoder::configure(const LdDecodeMetaData::VideoParameters &videoParamet
}

// Compute cropping parameters
setVideoParameters(config, videoParameters, config.pal.firstActiveLine, config.pal.lastActiveLine);
setVideoParameters(config, videoParameters);

return true;
}
Expand Down
10 changes: 5 additions & 5 deletions tools/ld-chroma-decoder/sourcefield.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ struct SourceField {
}

// Return the first/last active line numbers within this field's data,
// given the first/last frame line numbers.
qint32 getFirstActiveLine(qint32 firstActiveFrameLine) const {
return (firstActiveFrameLine + 1 - getOffset()) / 2;
// given the video parameters.
qint32 getFirstActiveLine(const LdDecodeMetaData::VideoParameters &videoParameters) const {
return (videoParameters.firstActiveFrameLine + 1 - getOffset()) / 2;
}
qint32 getLastActiveLine(qint32 lastActiveFrameLine) const {
return (lastActiveFrameLine + 1 - getOffset()) / 2;
qint32 getLastActiveLine(const LdDecodeMetaData::VideoParameters &videoParameters) const {
return (videoParameters.lastActiveFrameLine + 1 - getOffset()) / 2;
}
};

Expand Down
3 changes: 0 additions & 3 deletions tools/ld-chroma-decoder/transformpal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ TransformPal::~TransformPal()
}

void TransformPal::updateConfiguration(const LdDecodeMetaData::VideoParameters &_videoParameters,
qint32 _firstActiveLine, qint32 _lastActiveLine,
TransformPal::TransformMode _mode, double threshold,
const QVector<double> &_thresholds)
{
videoParameters = _videoParameters;
firstActiveLine = _firstActiveLine;
lastActiveLine = _lastActiveLine;
mode = _mode;

// Resize thresholds to match the number of FFT bins we will consider in
Expand Down
Loading

0 comments on commit fdc4c7b

Please sign in to comment.