File:PAL timing visualisation 1.png

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file (1,280 × 625 pixels, file size: 4 KB, MIME type: image/png)

Captions

Captions

Add a one-line explanation of what this file represents

Summary

[edit]
Description
English: see below
Date
Source Own work
Author Sloyment

PAL timing visualisation

[edit]

This is a series of five images:

The first image is a timing diagram of a 625 line PAL video signal. The lines (1, 2, 3, … 625) are shown here in their chronological order. Every pixel in the diagram equals 0.05 µs. A complete line is 64 µs long, the entire frame takes 40 ms. In the diagram, you can see:
██ the horizontal and vertical synchronisation pulses (below black level)
██ blanking time (front porch, back porch etc. at black level)
██ the color burst (10 periods of 4.43 MHz), and
██ the picture area.
On an actual monitor, the lines are written interlaced, so they appear in the order 313, 1, 314, 2, 315, 3, … 311, 624, 312, 625. The picture area of the signal (blue) will be shown with a 4:3 aspect ratio.
If the horizontal synchronisation in the monitor is delayed, the picture will move to the left, and if the vertical synchronisation in the monitor is delayed, the picture will move upwards. This technique called “pulse-cross” circuit is used to show the synchronisation pulses and the color burst on the screen for testing purposes. In this simulated example, the vertical sync was delayed by 10.24 ms (160 lines) and the horizontal sync by 42 µs (ca. 65 %).
Only a fraction of the signal is normally seen on the screen at a time, as a CRT monitor need some time for the horizontal and the vertical retrace. A lot of the video signal is thus hidden.
With the delay enabled, the signals outside the picture area become visible on the screen.

Source code

[edit]
Images 1–3 have been created from a script.
Images 2 and 3 have been rescaled to 945×625 in GIMP afterwards.
Images 4 and 5 are edited versions of images 2 and 3.
// Author:           Sloyment
// License:          Creative Commons Zero
// Compile and run:  
//   sudo apt-get install libgd-dev
//   gcc PAL.c -lgd 
//   ./a.out

#include <stdlib.h>
#include "gd.h"

int main () { 

  int timings[] = {
    235, 235, 90, 230, 255,   1685, 315, 155,  // 32.00 µs
    235,                      2495, 315, 155   // 32.00 µs
  };

  // 0: sync, 1: black, 2: burst, 3: picture

  int lt1[][12] = {                //  index  
    {0,0,1,2,1,3,3,3,  3,3,3,1},   //  0:  line with picture info
    {0,0,1,2,1,1,1,1,  1,1,1,1},   //  1:  line without picture info
    {0,0,1,2,1,1,1,1,  3,3,3,1},   //  2:  second half only (23)
    {0,0,1,2,1,3,3,1,  0,1,1,1},   //  3:  first half only (623)
    {0,0,0,0,0,0,1,1,  0,0,1,1},   //  4:  long pulses
    {0,1,1,1,1,1,1,1,  0,1,1,1},   //  5:  short pulses
    {0,0,0,0,0,0,1,1,  0,1,1,1},   //  6:  long–short (3)
    {0,1,1,1,1,1,1,1,  0,0,1,1},   //  7:  short–long (313)
    {0,1,1,1,1,1,1,1,  1,1,1,1}    //  8:  one short pulse (318)
  };

  int lt2[] = { 
    -1, // numbering starts with 1
    4,4,6,5,5, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,2,0,0, 0,0,0,0,0,  //    1– 30      
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //   31– 60      
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //   61– 90      
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //   91–120        
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  121–150
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  151–180
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  181–210
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  211–240
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  241–270
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  271–300
    0,0,0,0,0, 0,0,0,0,0, 5,5,7,4,4, 5,5,8,1,1, 1,1,1,1,1, 1,1,1,1,1,  //  301–330    
    1,1,1,1,1, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  331–360
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  361–390
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  391–420
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  421–450
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  451–480
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  481–510
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  511–540
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  541–570
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,  //  571–600
    0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,3,5,5              //  601–625
  };
  int a,b,c,d,e;

  // workaround
  int * data = malloc(1280*625*4 * sizeof(int));
  int * signal = data;
  int * img1[625];
  int * img2[625];
  int * img3[625];
  for (a=0;a<625;a++) {
    b=a*1280; c=1280*625;
    img1[a] = data + (b+c); c+=1280*625;
    img2[a] = data + (b+c); c+=1280*625;
    img3[a] = data + (b+c);
  }

  //  int signal[625*1280]; // 0.05 µs per pixel
  //  int img1[625][1280]; // 0.05 µs per pixel
  //  int img2[625][1280]; // 0.05 µs per pixel
  //  int img3[625][1280]; // 0.05 µs per pixel

  for (a=1;a<=625;a++) {  // count the scan lines from 1..625
    for (b=0,c=0;b<12;b++) {
      d = lt1[lt2[a]][b];
      e = c + (timings[b]/5);
      for (;c<e;c++) {
        signal[(a-1)*1280+c] = d;
  } } }

  for (a=1;a<=625;a++) {
    for (b=0;b<1280;b++) {
      d = (a-1)*1280+b; 
      img1[a-1][b] = signal[d];
      c = (a<313)? a*2-1 : a*2-626; // deinterlace: 313, 1, 314, 2, 315 … 312, 625
      img2[c][b] = signal[d];
      d += (4+144+12)*1280 + 840;  // add delay: 10282 µs
      d %= 1280 * 625;  // wrap
      img3[c][b] = signal[d];
  } }

  {  // begin GD stuff
    gdImagePtr im = gdImageCreateTrueColor(1280, 625);
    int x,y;

    void im_save(char filename[]){
      FILE *f1;					
      f1 = fopen(filename, "wb");
      gdImagePng(im, f1);
      fclose(f1);  
    }

    inline void px(int x, int y, int color) {
      int r,g,b;        // translate to actual colors:
                        // 0: sync, 1: black, 2: burst, 3: picture
      if (color==0) {  r=0;    g=0;    b=0;    }
      if (color==1) {  r=64;   g=64;   b=64;   } 
      if (color==2) {  r=192;  g=128;  b=0;    } 
      if (color==3) {  r=128;  g=192;  b=255;  }
      im->tpixels[y][x]=(r<<16)|(g<<8)|b;
    }

    for (y=0;y<625;y++) for (x=0;x<1280;x++) px (x,y,img1[y][x]);
    im_save ("PAL timing visualisation 1.png");
    for (y=0;y<625;y++) for (x=0;x<1280;x++) px (x,y,img2[y][x]);
    im_save ("PAL timing visualisation 2.png");
    for (y=0;y<625;y++) for (x=0;x<1280;x++) px (x,y,img3[y][x]);
    im_save ("PAL timing visualisation 3.png");

    gdImageDestroy(im);
  }  // end GD stuff

  free (data);
  return 0;
}

Licensing

[edit]
I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current17:45, 3 January 2017Thumbnail for version as of 17:45, 3 January 20171,280 × 625 (4 KB)Sloyment (talk | contribs)User created page with UploadWizard

Metadata