Christmas TV treat courtesy of BBC BASIC!

for discussion of bbc basic for windows/sdl, brandy and more
Post Reply
Deleted User 9295

Christmas TV treat courtesy of BBC BASIC!

Post by Deleted User 9295 »

As the cat seems to be out of the bag (e.g. here) I can confirm that at Christmas there will be a televisual treat on BBC2 thanks to this BBC BASIC program (snippet):

Code: Select all

      REM Extract the chroma content from the source image by applying both
      REM horizontal and vertical filters.  The horizontal filter is a simple
      REM bandpass centered on colour subcarrier (4.433 MHz) and the vertical
      REM filters are bandpass with peaks at 72, 216 and 360 c/aph.

      REM The 72 c/aph component is multiplied by the 216 plus 360 c/aph
      REM components to generate a 288 c/aph component (with zero horizontal
      REM frequency) for use in measuring the vertical component of geometric
      REM distortion (the 360 c/aph is necessary for drwep3.y and drw20200.y)

      REM Finally the U and V chroma are separated using a diagonal filter.

      DEF PROCchroma

      PROCbpfilt(Raw%, Tsc%, SourceWidth%*SourceHeight%)

      PROCvfilt48(^coeff.cvbpf%(0), Tsc%-23*SourceWidth%, \
      \           SourceWidth%*SourceHeight%, Csc%) : REM 72+216 c/aph

      IF ChromaGain <> 0 THEN
        PROCvfilt48(^coeff.cv72f%(0), Tsc%-23*SourceWidth%, \
        \           SourceWidth%*SourceHeight%, C72%) : REM 72 c/aph
        PROCvfilt48(^coeff.cv216%(0), Tsc%-23*SourceWidth%, \
        \           SourceWidth%*SourceHeight%, C216%) : REM 216 c/aph
        PROCvfilt48(^coeff.cv360%(0), Tsc%-23*SourceWidth%, \
        \           SourceWidth%*SourceHeight%, C360%) : REM 360 c/aph
      ENDIF

      REM To protect the x-measurement from cross-colour we must ensure
      REM that the 72 c/aph and 216 c/aph components are pre-separated
      REM into U and V before being multiplied, otherwise 72 c/aph luma
      REM could mix with its 3rd harmonic to produce 144 c/aph 'chroma'.

      PROCproduct(C216%, C360%, C72%, C288%) : REM 216 & 360 summed

      PROCseparate(C72%, Uuf%, Vuf%)         : REM Uuf%, Vuf% temp 72

      IF Xmode% = 216 THEN
        PROCseparate(C216%, U144%, V144%)     : REM U144%, V144% temp 216
        PROCproduct(Uuf%, Uuf%, U144%, U144%) : REM Twice 72 * 216
        PROCproduct(Vuf%, Vuf%, V144%, V144%) : REM Twice 72 * 216
      ELSE
        PROCproduct(Uuf%, Uuf%, Uuf%, U144%)  : REM Twice 72 * 72
        PROCproduct(Vuf%, Vuf%, Vuf%, V144%)  : REM Twice 72 * 72
      ENDIF

      PROCseparate(Csc%, Uuf%, Vuf%)

      ENDPROC

      ;-------------------------------------------------------------------------

      REM Make U and V baseband chrominance (unfiltered) by rectifying the
      REM separated modulated U and V chroma and using quadrant map for sign.
      REM The post-demodulation low-pass filter happens in the down-scaling.

      DEF PROCdouv
      LOCAL line%

      REM Generate chrominance:
      FOR line% = 0 TO SourceHeight%-1
        PROCmakeuv(Uuf% + line%*SourceWidth%, \
        \          Vuf% + line%*SourceWidth%, \
        \          ^MapOut&(line% DIV YblockSize%,0))
      NEXT line%

      ENDPROC

      ;-------------------------------------------------------------------------

      REM Downscale the luminance and baseband chrominance from (typically)
      REM 1920x1080 to 720x576 using polyphase FIR filters (8 phases vertical
      REM and 3 phases horizontal).  The luminance filters preserve the full
      REM PAL bandwidth, but the chrominance filters deliberately remove the
      REM high frequencies, both as a post-demodulation filter and as the
      REM 'reconstruction filter' for the low (120 x 90) block resolution.

      DEF PROCscale
      LOCAL I%, F%, L%, P%, pp

      REM Vertical scaling:
      pp = 0
      FOR L% = 0 TO OutputHeight%-1
        I% = INT(pp)
        F% = 8*(pp-I%)
        PROCvfilter(^coeff.yvlpf%(7-F%,0), Lum%+(I%-15)*SourceWidth%, \
        \          SourceWidth%, Ytmp%+L%*SourceWidth%)
        IF ChromaGain <> 0 THEN
          PROCvfilter(^coeff.cvlpf%(7-F%,0), Uuf%+(I%-15)*SourceWidth%, \
          \          SourceWidth%, Utmp%+L%*SourceWidth%)
          PROCvfilter(^coeff.cvlpf%(7-F%,0), Vuf%+(I%-15)*SourceWidth%, \
          \          SourceWidth%, Vtmp%+L%*SourceWidth%)
        ENDIF
        pp += SourceHeight%/OutputHeight%
      NEXT L%

      REM Horizontal scaling:
      pp = 0
      FOR P% = 0 TO OutputWidth%-1
        I% = INT(pp)
        F% = 3*(pp-I%)
        PROChfilter(^coeff.yhlpf%(2-F%,0), Ytmp%+I%-15, SourceWidth%, Yout%+P%)
        IF ChromaGain <> 0 THEN
          PROChfilter(^coeff.chlpf%(2-F%,0), Utmp%+I%-15, SourceWidth%, Uout%+P%)
          PROChfilter(^coeff.chlpf%(2-F%,0), Vtmp%+I%-15, SourceWidth%, Vout%+P%)
        ENDIF
        pp += SourceWidth%/OutputWidth%
      NEXT P%

      ENDPROC

      ;-------------------------------------------------------------------------

      REM Measure the vertical component of the geometric distortion by cross-
      REM correlating a 288 c/aph signal with zero horizontal frequency (derived
      REM by multiplying the 72 c/aph and 216+360 c/aph components) against a
      REM 288 c/aph reference file.  Since one cycle of 288 c/aph corresponds
      REM to 3.75 HD lines only a 'modulo-4' result is produced; this must
      REM afterwards be 'disambiguated' to give an absolute vertical measurement.
      REM To improve the S/N ratio the correlation is performed over a 3x3
      REM 'macroblock' centered on the block of interest.

      DEF PROCyprocess
      LOCAL A%, B%, C%, D%, M%, N%, P%, R%, V%, W%, X%, Y%, Z%, c%(), sum
      DIM c%(3,Xblocks%-1,Yblocks%-1)
      IF Undistorted% sum = sum25 ELSE sum = sum9

      C% = XblockSize%
      D% = YblockSize%
      W% = SourceWidth%
      FOR Y% = 0 TO Yblocks%-1
        FOR X% = 0 TO Xblocks%-1
          P% = Y%*D%*W% + X%*C%
          A% = C288% + P%
          Z% = P% + Wref%
          FOR V% = 0 TO 3
            B% = Z% - V%*W%
            c%(V%,X%,Y%) = USR(correlate)
          NEXT
        NEXT
      NEXT Y%

      Cy%() = 0
      Dy%() = 128

      FOR Y% = 1 TO Yblocks%-2 : REM ignore edge blocks (filtering etc.)
        FOR X% = 1 TO Xblocks%-2 : REM ignore edge blocks (filtering etc.)
          M% = &80000000 : REM maximum
          FOR V% = 0 TO 3
            B% = ^c%(V%,X%,Y%)
            C% = USR(sum)
            IF C% > M% M% = C% : R% = V%
          NEXT
          B% = ^c%((R%+2)MOD4,X%,Y%)
          N% = USR(sum)
          Dy%(X%,Y%) = R%
          Cy%(X%,Y%) = ((M%-N%) DIV 3) >> ChromaScale% : REM So X and Y give similar CCs
        NEXT
      NEXT Y%

      PROCdisambiguate(Dy%(), Cy%(), Fy%(), Ythresh%)

      REM Even out positive and negative excursions:
      PROCbalance(Dy%(), Fy%())

      ENDPROC
User avatar
BigEd
Posts: 6261
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by BigEd »

Hurrah. I think the apposite phrase might be "You can't see the join!"
User avatar
richardtoohey
Posts: 4075
Joined: Thu Dec 29, 2011 5:13 am
Location: Tauranga, New Zealand
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by richardtoohey »

I assumed Morecambe and Wise but was hoping for more Dr Who discoveries. :D
User avatar
jgharston
Posts: 5319
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by jgharston »

But the images were still degraded, and while they might have contained
all the right frames, they were not necessarily in the right order.
Classic! :D

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
User avatar
Lardo Boffin
Posts: 2977
Joined: Thu Aug 06, 2015 7:47 am
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by Lardo Boffin »

:D :lol:
jgharston wrote: Tue Nov 23, 2021 7:23 pm
But the images were still degraded, and while they might have contained
all the right frames, they were not necessarily in the right order.
Classic! :D
=D>
Adventure Language on GitHub
Atom, issue 5, YARRB + video noise killer
Elk
A number of econetted (is that a word?) Beebs
BBC Master, Datacentre + HDD, pi co-proc, econet, NULA
Deleted User 9295

Re: Christmas TV treat courtesy of BBC BASIC!

Post by Deleted User 9295 »

Looks like it's going to be shown on BBC2 on Christmas Day (possibly at 7.45 pm but I'm not absolutely sure).

M&W_crout.jpg
nicolagiacobbe
Posts: 215
Joined: Tue Jul 03, 2007 10:40 am
Location: italy
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by nicolagiacobbe »

Wonderful job. Will it be possible to read the entire code that did the job?
P.S. Not having lived there in those times I don't have the faintest idea what is the show about, something along the 'Bottom' style, I reckon.
User avatar
jgharston
Posts: 5319
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by jgharston »

I think the closest to "today's" Morecombe & Wise are Ant & Dec.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
Deleted User 9295

Re: Christmas TV treat courtesy of BBC BASIC!

Post by Deleted User 9295 »

bbc2_schedule.png
iamaran
Posts: 586
Joined: Tue Mar 14, 2006 8:08 pm
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by iamaran »

Richard Russell wrote: Sun Dec 05, 2021 11:16 pm Looks like it's going to be shown on BBC2 on Christmas Day (possibly at 7.45 pm but I'm not absolutely sure).
Correct on all counts!
User avatar
Rich Talbot-Watkins
Posts: 2054
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by Rich Talbot-Watkins »

I hope you're going to get a credit, Richard. I think I remember there being some kind of animosity between you and the Colour Recovery Group, but none of this would have been possible in the first place without your amazing tech.
Deleted User 9295

Re: Christmas TV treat courtesy of BBC BASIC!

Post by Deleted User 9295 »

Rich Talbot-Watkins wrote: Wed Dec 08, 2021 11:12 am I think I remember there being some kind of animosity between you and the Colour Recovery Group
To the extent that there was any "animosity" it certainly wasn't between me and the group as a whole. Indeed it was members of that group (particularly Andrew Browne and Andrew Steer) who did the seminal work, without which I would never have taken an interest or been able to take things further.

Indeed it's they who should probably feel aggrieved that their contribution has largely been forgotten, and they get no mention in the credits. A record of their work can still be found at the Web Archive; it's noteworthy that Andrew Steer was able to reduce the cross-colour - something I've never been able to do - but never revealed his technique!
User avatar
lurkio
Posts: 4351
Joined: Wed Apr 10, 2013 12:30 am
Location: Doomawangara
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by lurkio »

A great piece of colour recovery, and a nice acknowledgement after the end credits.

:) =D> =D>
Soruk
Posts: 1136
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Christmas TV treat courtesy of BBC BASIC!

Post by Soruk »

Richard, if you're still reading this board, very well done. I enjoyed the episode and the colour work was brilliant.
Matrix Brandy BASIC VI (work in progress) The Distillery (another work in progress) Note Quiz (New educational software for the BBC and modern kit)
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
Post Reply

Return to “modern implementations of classic programming languages”