Hello There, Guest!
View New Posts  |  View Today's Posts
[C] Video Bandwidth Calculator

  • 0 Vote(s) - 0 Average


04-25-2016, 12:44 AM #1
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

Video Bandwidth Calculator
I wrote this quick little program in C to use for my own testing really, works pretty well though, might as well share the code here as simple as it is:



Code:
#include <stdio.h>

#define BITS_PER_CLOCK_COEFFICIENT 10

struct pixels
{
   unsigned int horizontal;
   unsigned int vertical;
};

int main(void)
{
   struct pixels px = { 2200, 1125 };
   double refresh_rate = 60.0;
   unsigned int bits_per_pixel = 8;

   fputs("HPx - Horizontal total pixels\n"
         "VPx - Vertical total pixels\n"
         "R   - Refresh rate (Hz)\n"
         "BP  - Bits/pixel (8/10/12/16)\n\n"
         "Enter: <HPx> <VTPx> <R> <BP>\n\t>> ", stdout);
   if (scanf(" %u %u %lf %u", &px.horizontal, &px.vertical, &refresh_rate, &bits_per_pixel) != 4)
   {
      fputs("ERROR: invalid usage\n", stderr);
      return 1;
   }

   putchar('\n');

   double color_depth_factor;
   unsigned int total_px;
   double bandwidth;

   total_px = px.horizontal * px.vertical;
   printf("Total pixels per frame: %u\n", total_px);

   total_px = (unsigned int)(total_px * refresh_rate);
   printf("Approx total pixels per second: %u\n", total_px);

   color_depth_factor = 1.00 + ((8 - bits_per_pixel) / 2 * 0.20);
   printf("Color depth factor: %f\n", color_depth_factor);

   bandwidth = total_px * BITS_PER_CLOCK_COEFFICIENT;
   printf("Bandwidth per channel: %.2f Gbps ", bandwidth / 10e8);
   printf("(%f)\n", bandwidth / 10e8);bandwidth *= 3.0;
   printf("Total bandwidth: %.2f Gbps ", bandwidth / 10e8);
   printf("(%f)\n", bandwidth / 10e8);

   return 0;
}

NOTE: Don't expect proper results if you think you're calculating video bandwidth for 1080p @ 60Hz and you put in 1920x1080 as the total horizontal and vertical pixels because this calculation involves the TOTAL pixels, not the active pixels. There are a certain number of pixels out of view that aren't displayed and so the calculation is actually 2200 and 1125 as shown in the test values before the scanf() call. You need to understand these blanking regions in order to be able to use this properly.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
   BMR Calculator BreShiE 5 4,048 02-02-2013, 04:57 PM
Last Post: AceInfinity
  Calculator (My first C++ project) Ghoster 9 12,459 12-28-2012, 03:38 PM
Last Post: KoBE
  Awesome Video Tutorial Ghoster 7 4,886 03-18-2012, 12:58 AM
Last Post: AceInfinity


Users browsing this thread: 1 Guest(s)