[HN Gopher] NTSC encoding/decoding in C89 using only integers an... ___________________________________________________________________ NTSC encoding/decoding in C89 using only integers and fixed point math Author : davikr Score : 29 points Date : 2022-12-21 20:22 UTC (2 hours ago) (HTM) web link (github.com) (TXT) w3m dump (github.com) | userbinator wrote: | I know what NTSC is, but what exactly is it encoding to/from? | ADC-sampled composite video (at what samplerate?) to/from | RGB/YCbCr? | Dwedit wrote: | The first step for any NTSC decoder is to go to YIQ. From | there, you go to any other color space of your choice. | | This is mainly for decoding the composite video signal | generated by a computer or console. For example, the NES | generates a 12-step square wave for its video output, and you'd | decode that to YIQ then convert that to RGB. | anyfoo wrote: | NTSC and PAL are very fun. Using quadrature amplitude modulation | to add color to the monochrome signal in a backward compatible | way was so ingenious. PAL added things to make it better after | some learnt lessons with NTSC, foremost the 180deg phase shift | with each lines, which cancels out phase errors. | | (Fun facts: Because of that, countries with PAL instead of NTSC | never knew what a "tint control" on the TV was, and the nostalgic | 80s VHS look is also missing that blueish/purple color shift | there.) | | I wrote both an NTSC+PAL decoder in Matlab, and a PAL encoder in | an FPGA (also fixed point), which I use in an actual project as | composite video output. Decoders are harder and less | straightforward than encoders, with lots of optimizing potential, | because you need to filter the color signal out (I look forward | to seeing what this code did). If you really, truly understand | how NTSC and PAL work in their mathematical details, you may get | your mind blown away by reading about this decoder, which is | likely the best PAL decoder that ever existed: http://www.jim- | easterbrook.me.uk/pal/ | | Writing my own encoder and decoder was super enlightening, and | there are tons of details to nerd out on, e.g. when you get into | data that's encoded into the sync gap for Videotext, closed | captions, and other stuff. | phone8675309 wrote: | Explains the PAL region epithet for NTSC - Never Twice the Same | Color | anyfoo wrote: | Yep, that's the reason! The ingenious idea of using quantum | amplitude modulation unfortunately also meant that slight | phase shifts--which happen easily in broadcast TV--appear as | color errors. | | PAL fixed it by flipping the phase around every line. By | subtracting the current line from the previous line, the | phase error would cancel out (but is also more expensive | since you need to remember the last line, in a delay line or | memory[1]). So, always the same color. (But not ATSC, that's | something else entirely...) | | [1] Well, there wer supposedly "PAL simple" receivers in the | very beginning, where no processing of the phase flip was | done and your eye was supposed to average the difference out. | Probably looked terrible unless you were sitting really far | away... | [deleted] ___________________________________________________________________ (page generated 2022-12-21 23:00 UTC)