aboutsummaryrefslogtreecommitdiff
path: root/include/hm12.h
blob: c88a730f9195e33afc2506140f6074c1844af397 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * hm12.h - HM12 raw YUV 4:2:0 handling
 */
#ifndef PVR2_HM12_H
#define PVR2_HM12_H

#include <stdio.h>
#include <stddef.h>

/* 1 = apply the light luma filter to the raw planes (see hm12.c).  The -N
 * command-line flag clears it so the filter can be A/B'd against the
 * unfiltered picture on the same source. */
extern int hm12_filter;
extern int hm12_hfilter;

/* y4m interlace tag: 0 = progressive (Ip), 1 = top field first (It),
 * 2 = bottom field first (Ib).  Measured on this hardware the raw stream
 * is progressive - lines within a frame differ by 3.95 while the same
 * field across two frames differs by 13.98, i.e. the fields are not
 * separated in time - so Ip is the default.  Selectable for testing. */
extern int hm12_interlace;

/* Distance used by the vertical 1-2-1 pass.  1 = neighbouring lines
 * (right for progressive material), 2 = same field, two lines away
 * (right if the stream really were interlaced). */
extern int hm12_vstep;

/*
 * Luma-only output, for checking vertical-line artefacts.
 *
 * The user wants to confirm whether the "jaggedness" is really vertical
 * lines by looking at the Y plane on its own.  This writes a plain
 * greyscale YUV4MPEG2 at full 720x480: the luma goes in the Y slot and
 * both chroma planes are held neutral, so VLC (or ffmpeg) shows it as a
 * greyscale picture with no colour cast to confuse the reading.
 *
 * Returns 0 on success, -1 on failure.
 */
int  hm12_luma_open(const char *path);
int  hm12_luma_write(const unsigned char *y, int w, int h);
void hm12_luma_close(void);

/*
 * Per-plane debug output.
 *
 * An HM12 conversion can be subtly wrong - a swapped U/V pair, a chroma
 * tile of the wrong size, a missing de-interleave - and the composite
 * still looks like video, just with the wrong colours.  Dumping each
 * plane separately makes that obvious: the luma should be a sharp
 * picture, and the two chroma planes should trace the same shapes as the
 * luma (at half resolution) rather than scattering.
 *
 * YUV4MPEG2 is used rather than PGM so the result can just be opened in
 * VLC (which PGM is not).  Each plane is written as its own video with
 * the other two held at neutral, so a viewer shows it as greyscale:
 *
 *     PFX.Y.y4m   luma in the Y slot, U=V=128
 *     PFX.U.y4m   Cb in the U slot, Y=128, V=128
 *     PFX.V.y4m   Cr in the V slot, Y=128, U=128
 *     PFX.uv.y4m  (U-128)*4+128 in U and (V-128)*4+128 in V, so a single
 *                 view shows the colour cast direction: too blue means the
 *                 U/V pair is the wrong way round
 *
 * All four are full 720x480 YUV4MPEG2 files: the chroma planes are
 * upsampled to luma size so each file is a well-formed video of the same
 * dimensions (a 360x240 header carrying 720x480 data would be rejected by
 * the demuxer).
 *
 * Every frame is appended, so the files play straight through.
 *
 * Returns 0 on success, -1 on failure.
 */
int  hm12_planes_open(const char *prefix);
int  hm12_planes_write(const unsigned char *y, const unsigned char *u,
		       const unsigned char *v, int w, int h);
void hm12_planes_close(void);

void   hm12_de_macro_y(unsigned char *dst, unsigned char *src,
		       int dstride, int w, int h);
void   hm12_de_macro_uv(unsigned char *dstu, unsigned char *dstv,
			unsigned char *src, int dstride, int w, int h);
size_t hm12_frame_size(int w, int h);
int    hm12_write_y4m_header(FILE *f, int w, int h, unsigned int fps_num,
			     unsigned int fps_den);
int    hm12_write_frame_y4m(FILE *f, const unsigned char *hm12, int w, int h,
			    unsigned char *scratch);

#endif