2018-10-31 01:50:35 +00:00
|
|
|
//
|
|
|
|
// ScanTarget.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 30/10/2018.
|
|
|
|
// Copyright © 2018 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-11-04 01:54:25 +00:00
|
|
|
#ifndef Outputs_Display_ScanTarget_h
|
|
|
|
#define Outputs_Display_ScanTarget_h
|
|
|
|
|
|
|
|
#include <cstddef>
|
2018-11-07 03:23:38 +00:00
|
|
|
#include <cstdint>
|
2018-10-31 01:50:35 +00:00
|
|
|
|
|
|
|
namespace Outputs {
|
2018-11-04 01:54:25 +00:00
|
|
|
namespace Display {
|
|
|
|
|
|
|
|
enum class Type {
|
|
|
|
PAL50,
|
|
|
|
NTSC60
|
|
|
|
};
|
|
|
|
|
2018-11-03 23:58:44 +00:00
|
|
|
struct Rect {
|
|
|
|
struct Point {
|
|
|
|
float x, y;
|
|
|
|
} origin;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
float width, height;
|
|
|
|
} size;
|
|
|
|
|
2018-11-04 03:40:39 +00:00
|
|
|
Rect() : origin({0.0f, 0.0f}), size({1.0f, 1.0f}) {}
|
2018-11-03 23:58:44 +00:00
|
|
|
Rect(float x, float y, float width, float height) :
|
|
|
|
origin({x, y}), size({width, height}) {}
|
|
|
|
};
|
|
|
|
|
2018-10-31 01:50:35 +00:00
|
|
|
enum class ColourSpace {
|
|
|
|
/// YIQ is the NTSC colour space.
|
|
|
|
YIQ,
|
|
|
|
|
|
|
|
/// YUV is the PAL colour space.
|
|
|
|
YUV
|
|
|
|
};
|
|
|
|
|
2018-11-22 19:36:46 +00:00
|
|
|
enum class DisplayType {
|
2018-11-16 02:02:46 +00:00
|
|
|
RGB,
|
|
|
|
SVideo,
|
|
|
|
CompositeColour,
|
|
|
|
CompositeMonochrome
|
|
|
|
};
|
|
|
|
|
2018-11-07 03:23:38 +00:00
|
|
|
/*!
|
|
|
|
Enumerates the potential formats of input data.
|
|
|
|
*/
|
|
|
|
enum class InputDataType {
|
|
|
|
|
|
|
|
// The luminance types can be used to feed only two video pipelines:
|
|
|
|
// black and white video, or composite colour.
|
|
|
|
|
|
|
|
Luminance1, // 1 byte/pixel; any bit set => white; no bits set => black.
|
|
|
|
Luminance8, // 1 byte/pixel; linear scale.
|
|
|
|
|
2018-11-29 04:40:22 +00:00
|
|
|
PhaseLinkedLuminance8, // 4 bytes/pixel; each byte is an individual 8-bit luminance
|
|
|
|
// value and which value is output is a function of
|
|
|
|
// colour subcarrier phase — byte 0 defines the first quarter
|
|
|
|
// of each colour cycle, byte 1 the next quarter, etc. This
|
|
|
|
// format is intended to permit replay of sampled original data.
|
|
|
|
|
2018-11-07 03:23:38 +00:00
|
|
|
// The luminance plus phase types describe a luminance and the phase offset
|
|
|
|
// of a colour subcarrier. So they can be used to generate a luminance signal,
|
|
|
|
// or an s-video pipeline.
|
|
|
|
|
2018-11-23 03:43:42 +00:00
|
|
|
Luminance8Phase8, // 2 bytes/pixel; first is luminance, second is phase.
|
2018-11-07 03:23:38 +00:00
|
|
|
// Phase is encoded on a 192-unit circle; anything
|
|
|
|
// greater than 192 implies that the colour part of
|
|
|
|
// the signal should be omitted.
|
|
|
|
|
|
|
|
// The RGB types can directly feed an RGB pipeline, naturally, or can be mapped
|
|
|
|
// to phase+luminance, or just to luminance.
|
|
|
|
|
|
|
|
Red1Green1Blue1, // 1 byte/pixel; bit 0 is blue on or off, bit 1 is green, bit 2 is red.
|
|
|
|
Red2Green2Blue2, // 1 byte/pixel; bits 0 and 1 are blue, bits 2 and 3 are green, bits 4 and 5 are blue.
|
|
|
|
Red4Green4Blue4, // 2 bytes/pixel; first nibble is red, second is green, third is blue.
|
|
|
|
Red8Green8Blue8, // 4 bytes/pixel; first is red, second is green, third is blue, fourth is vacant.
|
|
|
|
};
|
|
|
|
|
|
|
|
inline size_t size_for_data_type(InputDataType data_type) {
|
|
|
|
switch(data_type) {
|
|
|
|
case InputDataType::Luminance1:
|
|
|
|
case InputDataType::Luminance8:
|
|
|
|
case InputDataType::Red1Green1Blue1:
|
|
|
|
case InputDataType::Red2Green2Blue2:
|
|
|
|
return 1;
|
|
|
|
|
2018-11-23 03:43:42 +00:00
|
|
|
case InputDataType::Luminance8Phase8:
|
2018-11-07 03:23:38 +00:00
|
|
|
case InputDataType::Red4Green4Blue4:
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case InputDataType::Red8Green8Blue8:
|
2018-11-29 04:40:22 +00:00
|
|
|
case InputDataType::PhaseLinkedLuminance8:
|
2018-11-07 03:23:38 +00:00
|
|
|
return 4;
|
2019-01-26 01:21:24 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
2018-11-07 03:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-24 03:34:38 +00:00
|
|
|
inline DisplayType natural_display_type_for_data_type(InputDataType data_type) {
|
|
|
|
switch(data_type) {
|
2019-01-26 01:21:24 +00:00
|
|
|
default:
|
2018-11-24 03:34:38 +00:00
|
|
|
case InputDataType::Luminance1:
|
|
|
|
case InputDataType::Luminance8:
|
2018-11-29 04:40:22 +00:00
|
|
|
case InputDataType::PhaseLinkedLuminance8:
|
2018-11-24 03:34:38 +00:00
|
|
|
return DisplayType::CompositeColour;
|
|
|
|
|
|
|
|
case InputDataType::Red1Green1Blue1:
|
|
|
|
case InputDataType::Red2Green2Blue2:
|
|
|
|
case InputDataType::Red4Green4Blue4:
|
|
|
|
case InputDataType::Red8Green8Blue8:
|
|
|
|
return DisplayType::RGB;
|
|
|
|
|
|
|
|
case InputDataType::Luminance8Phase8:
|
|
|
|
return DisplayType::SVideo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 01:50:35 +00:00
|
|
|
/*!
|
|
|
|
Provides an abstract target for 'scans' i.e. continuous sweeps of output data,
|
|
|
|
which are identified by 2d start and end coordinates, and the PCM-sampled data
|
|
|
|
that is output during the sweep.
|
|
|
|
|
|
|
|
Additional information is provided to allow decoding (and/or encoding) of a
|
|
|
|
composite colour feed.
|
|
|
|
|
|
|
|
Otherwise helpful: the ScanTarget vends all allocated memory. That should allow
|
|
|
|
for use of shared memory where available.
|
|
|
|
*/
|
|
|
|
struct ScanTarget {
|
|
|
|
|
|
|
|
/*
|
|
|
|
This top section of the interface deals with modal settings. A ScanTarget can
|
|
|
|
assume that the modals change very infrequently.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct Modals {
|
2018-11-07 03:23:38 +00:00
|
|
|
/// Describes the format of input data.
|
|
|
|
InputDataType input_data_type;
|
2018-10-31 01:50:35 +00:00
|
|
|
|
2018-11-30 00:29:28 +00:00
|
|
|
struct InputDataTweaks {
|
|
|
|
/// If using the PhaseLinkedLuminance8 data type, this value provides an offset
|
|
|
|
/// to add to phase before indexing the supplied luminances.
|
|
|
|
float phase_linked_luminance_offset = 0.0f;
|
|
|
|
|
|
|
|
} input_data_tweaks;
|
|
|
|
|
2018-11-22 19:36:46 +00:00
|
|
|
/// Describes the type of display that the data is being shown on.
|
2018-11-24 03:54:52 +00:00
|
|
|
DisplayType display_type = DisplayType::SVideo;
|
2018-11-22 19:36:46 +00:00
|
|
|
|
2018-11-03 23:58:44 +00:00
|
|
|
/// If being fed composite data, this defines the colour space in use.
|
2018-10-31 01:50:35 +00:00
|
|
|
ColourSpace composite_colour_space;
|
2018-11-03 23:58:44 +00:00
|
|
|
|
2018-11-05 02:06:25 +00:00
|
|
|
/// Provides an integral clock rate for the duration of "a single line", specifically
|
|
|
|
/// for an idealised line. So e.g. in NTSC this will be for the duration of 227.5
|
|
|
|
/// colour clocks, regardless of whether the source actually stretches lines to
|
|
|
|
/// 228 colour cycles, abbreviates them to 227 colour cycles, etc.
|
|
|
|
int cycles_per_line;
|
|
|
|
|
|
|
|
/// Sets a GCD for the durations of pixels coming out of this device. This with
|
|
|
|
/// the @c cycles_per_line are offered for sizing of intermediary buffers.
|
|
|
|
int clocks_per_pixel_greatest_common_divisor;
|
2018-11-03 23:58:44 +00:00
|
|
|
|
2018-11-13 23:33:44 +00:00
|
|
|
/// Provides the number of colour cycles in a line, as a quotient.
|
|
|
|
int colour_cycle_numerator, colour_cycle_denominator;
|
|
|
|
|
2018-11-03 23:58:44 +00:00
|
|
|
/// Provides a pre-estimate of the likely number of left-to-right scans per frame.
|
|
|
|
/// This isn't a guarantee, but it should provide a decent-enough estimate.
|
|
|
|
int expected_vertical_lines;
|
|
|
|
|
|
|
|
/// Provides an additional restriction on the section of the display that is expected
|
|
|
|
/// to contain interesting content.
|
|
|
|
Rect visible_area;
|
|
|
|
|
2018-11-05 02:06:25 +00:00
|
|
|
/// Describes the usual gamma of the output device these scans would appear on.
|
2018-11-22 19:36:46 +00:00
|
|
|
float intended_gamma = 2.2f;
|
2018-11-05 02:06:25 +00:00
|
|
|
|
2018-11-30 00:29:28 +00:00
|
|
|
/// Provides a brightness multiplier for the display output.
|
|
|
|
float brightness = 1.0f;
|
|
|
|
|
2018-11-05 02:06:25 +00:00
|
|
|
/// Specifies the range of values that will be output for x and y coordinates.
|
|
|
|
struct {
|
|
|
|
uint16_t x, y;
|
|
|
|
} output_scale;
|
2018-10-31 01:50:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Sets the total format of input data.
|
2018-11-03 23:58:44 +00:00
|
|
|
virtual void set_modals(Modals) = 0;
|
2018-10-31 01:50:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
This second section of the interface allows provision of the streamed data, plus some control
|
|
|
|
over the streaming.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Defines a scan in terms of its two endpoints.
|
|
|
|
*/
|
|
|
|
struct Scan {
|
|
|
|
struct EndPoint {
|
|
|
|
/// Provide the coordinate of this endpoint. These are fixed point, purely fractional
|
2018-11-05 02:06:25 +00:00
|
|
|
/// numbers, relative to the scale provided in the Modals.
|
2018-10-31 01:50:35 +00:00
|
|
|
uint16_t x, y;
|
|
|
|
|
|
|
|
/// Provides the offset, in samples, into the most recently allocated write area, of data
|
|
|
|
/// at this end point.
|
|
|
|
uint16_t data_offset;
|
|
|
|
|
|
|
|
/// For composite video, provides the angle of the colour subcarrier at this endpoint.
|
|
|
|
///
|
|
|
|
/// This is a slightly weird fixed point, being:
|
|
|
|
///
|
|
|
|
/// * a six-bit fractional part;
|
|
|
|
/// * a nine-bit integral part; and
|
|
|
|
/// * a sign.
|
|
|
|
///
|
|
|
|
/// Positive numbers indicate that the colour subcarrier is 'running positively' on this
|
|
|
|
/// line; i.e. it is any NTSC line or an appropriate swing PAL line, encoded as
|
|
|
|
/// x*cos(a) + y*sin(a).
|
|
|
|
///
|
|
|
|
/// Negative numbers indicate a 'negative running' colour subcarrier; i.e. it is one of
|
|
|
|
/// the phase alternated lines of PAL, encoded as x*cos(a) - y*sin(a), or x*cos(-a) + y*sin(-a),
|
|
|
|
/// whichever you prefer.
|
|
|
|
///
|
|
|
|
/// It will produce undefined behaviour if signs differ on a single scan.
|
|
|
|
int16_t composite_angle;
|
2019-01-06 04:09:17 +00:00
|
|
|
|
|
|
|
/// Gives the number of cycles since the most recent horizontal retrace ended.
|
|
|
|
uint16_t cycles_since_end_of_horizontal_retrace;
|
2018-10-31 01:50:35 +00:00
|
|
|
} end_points[2];
|
|
|
|
|
|
|
|
/// For composite video, dictates the amplitude of the colour subcarrier as a proportion of
|
2018-11-03 23:58:44 +00:00
|
|
|
/// the whole, as determined from the colour burst. Will be 0 if there was no colour burst.
|
2018-10-31 01:50:35 +00:00
|
|
|
uint8_t composite_amplitude;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Requests a new scan to populate.
|
|
|
|
///
|
|
|
|
/// @return A valid pointer, or @c nullptr if insufficient further storage is available.
|
2018-11-11 00:52:57 +00:00
|
|
|
virtual Scan *begin_scan() = 0;
|
2018-10-31 01:50:35 +00:00
|
|
|
|
2018-11-11 00:52:57 +00:00
|
|
|
/// Requests a new scan to populate.
|
|
|
|
virtual void end_scan() {}
|
|
|
|
|
|
|
|
/// Finds the first available storage of at least @c required_length pixels in size which is
|
|
|
|
/// suitably aligned for writing of @c required_alignment number of samples at a time.
|
2018-10-31 01:50:35 +00:00
|
|
|
///
|
2018-11-11 00:52:57 +00:00
|
|
|
/// Calls will be paired off with calls to @c end_data.
|
2018-10-31 01:50:35 +00:00
|
|
|
///
|
|
|
|
/// @returns a pointer to the allocated space if any was available; @c nullptr otherwise.
|
2018-11-11 00:52:57 +00:00
|
|
|
virtual uint8_t *begin_data(size_t required_length, size_t required_alignment = 1) = 0;
|
2018-10-31 01:50:35 +00:00
|
|
|
|
2018-11-11 00:52:57 +00:00
|
|
|
/// Announces that the owner is finished with the region created by the most recent @c begin_data
|
2018-10-31 01:50:35 +00:00
|
|
|
/// and indicates that its actual final size was @c actual_length.
|
2018-11-07 03:23:38 +00:00
|
|
|
///
|
2018-11-11 00:52:57 +00:00
|
|
|
/// It is required that every call to begin_data be paired with a call to end_data.
|
|
|
|
virtual void end_data(size_t actual_length) {}
|
2018-10-31 01:50:35 +00:00
|
|
|
|
2019-02-03 20:07:22 +00:00
|
|
|
/// Tells the scan target that its owner is about to change; this is a hint that existing
|
|
|
|
/// data and scan allocations should be invalidated.
|
|
|
|
virtual void will_change_owner() {}
|
|
|
|
|
2018-11-07 03:23:38 +00:00
|
|
|
/// Marks the end of an atomic set of data. Drawing is best effort, so the scan target should either:
|
|
|
|
///
|
|
|
|
/// (i) output everything received since the previous submit; or
|
|
|
|
/// (ii) output nothing.
|
|
|
|
///
|
2018-11-11 00:52:57 +00:00
|
|
|
/// If there were any allocation failures — i.e. any nullptr responses to begin_data or
|
|
|
|
/// begin_scan — then (ii) is a required response. But a scan target may also need to opt for (ii)
|
2018-11-07 03:23:38 +00:00
|
|
|
/// for any other reason.
|
2018-10-31 01:50:35 +00:00
|
|
|
///
|
|
|
|
/// The ScanTarget isn't bound to take any drawing action immediately; it may sit on submitted data for
|
|
|
|
/// as long as it feels is appropriate subject to an @c flush.
|
2018-11-07 03:23:38 +00:00
|
|
|
virtual void submit() = 0;
|
2018-10-31 01:50:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
ScanTargets also receive notification of certain events that may be helpful in processing, particularly
|
|
|
|
for synchronising internal output to the outside world.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum class Event {
|
2018-11-11 00:52:57 +00:00
|
|
|
BeginHorizontalRetrace,
|
|
|
|
EndHorizontalRetrace,
|
|
|
|
|
|
|
|
BeginVerticalRetrace,
|
|
|
|
EndVerticalRetrace,
|
2018-10-31 01:50:35 +00:00
|
|
|
};
|
|
|
|
|
2019-01-06 04:09:17 +00:00
|
|
|
/*!
|
|
|
|
Provides a hint that the named event has occurred.
|
|
|
|
|
|
|
|
@param event The event.
|
|
|
|
@param is_visible @c true if the output stream is visible immediately after this event; @c false otherwise.
|
|
|
|
@param location The location of the event.
|
2019-01-12 03:02:15 +00:00
|
|
|
@param composite_amplitude The amplitude of the colour burst on this line (0, if no colour burst was found).
|
2019-01-06 04:09:17 +00:00
|
|
|
*/
|
2019-01-12 03:02:15 +00:00
|
|
|
virtual void announce(Event event, bool is_visible, const Scan::EndPoint &location, uint8_t composite_amplitude) {}
|
2018-10-31 01:50:35 +00:00
|
|
|
};
|
|
|
|
|
2018-11-15 02:52:57 +00:00
|
|
|
/*!
|
|
|
|
Provides a null target for scans.
|
|
|
|
*/
|
|
|
|
struct NullScanTarget: public ScanTarget {
|
|
|
|
void set_modals(Modals) {}
|
|
|
|
Scan *begin_scan() { return nullptr; }
|
|
|
|
uint8_t *begin_data(size_t required_length, size_t required_alignment = 1) { return nullptr; }
|
|
|
|
void submit() {}
|
|
|
|
|
|
|
|
static NullScanTarget singleton;
|
|
|
|
};
|
|
|
|
|
2018-10-31 01:50:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-04 01:54:25 +00:00
|
|
|
#endif /* Outputs_Display_ScanTarget_h */
|