emandude777
Posts: 2
Joined: Fri Jun 18, 2021 3:02 pm

I want to create an "On Air" sign for my studio.

Fri Jun 18, 2021 7:23 pm

Hello,
I'm very inexperienced with most things pi related. The most I've done is RetroPi and Kodi a while back.

I currently have a Raspberry Pi Zero W and a Pi 2 and an old VGA screen laying around.

I want to create a Raspberry Pi based sign for my studio that can flip through 3 different states shown on the VGA screen based on button presses. Those three states would be "Quiet! On Air", "Knock Please" and "Recording in Progress". I would assume these can be done easily with the Pi just showing a JPG that I could design that says those things.
My main problem is implementation. How would I, from startup, show a black screen, but when I press the corresponding button, the correct photo will show on screen indefinately until another button is pressed, overriding it and showing the new corresponding photo instead.

I have only very basic knowledge in C++, so any help would be appreciated.

drtechno
Posts: 261
Joined: Fri Apr 09, 2021 6:33 pm

Re: I want to create an "On Air" sign for my studio.

Sat Jun 19, 2021 1:32 am

Well in c you have to download a library to use. This c++ code uses the library called libjpeg :

Code: Select all

#include <jpeglib.h>

int loadJpg(const char* Name) {
  unsigned char a, r, g, b;
  int width, height;
  struct jpeg_decompress_struct cinfo;
  struct jpeg_error_mgr jerr;

  FILE * infile;        /* source file */
  JSAMPARRAY pJpegBuffer;       /* Output row buffer */
  int row_stride;       /* physical row width in output buffer */
  if ((infile = fopen(Name, "rb")) == NULL) {
    fprintf(stderr, "can't open %s\n", Name);
    return 0;
  }
  cinfo.err = jpeg_std_error(&jerr);
  jpeg_create_decompress(&cinfo);
  jpeg_stdio_src(&cinfo, infile);
  (void) jpeg_read_header(&cinfo, TRUE);
  (void) jpeg_start_decompress(&cinfo);
  width = cinfo.output_width;
  height = cinfo.output_height;

  unsigned char * pDummy = new unsigned char [width*height*4];
  unsigned char * pTest = pDummy;
  if (!pDummy) {
    printf("NO MEM FOR JPEG CONVERT!\n");
    return 0;
  }
  row_stride = width * cinfo.output_components;
  pJpegBuffer = (*cinfo.mem->alloc_sarray)
    ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);

  while (cinfo.output_scanline < cinfo.output_height) {
    (void) jpeg_read_scanlines(&cinfo, pJpegBuffer, 1);
    for (int x = 0; x < width; x++) {
      a = 0; // alpha value is not supported on jpg
      r = pJpegBuffer[0][cinfo.output_components * x];
      if (cinfo.output_components > 2) {
        g = pJpegBuffer[0][cinfo.output_components * x + 1];
        b = pJpegBuffer[0][cinfo.output_components * x + 2];
      } else {
        g = r;
        b = r;
      }
      *(pDummy++) = b;
      *(pDummy++) = g;
      *(pDummy++) = r;
      *(pDummy++) = a;
    }
  }
  fclose(infile);
  (void) jpeg_finish_decompress(&cinfo);
  jpeg_destroy_decompress(&cinfo);

  BMap = (int*)pTest; 
  Height = height;
  Width = width;
  Depth = 32;
}

User avatar
rpdom
Posts: 18886
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: I want to create an "On Air" sign for my studio.

Sat Jun 19, 2021 9:15 am

The first problem you will have is connecting your Pi to a VGA screen. The Pi does not have a VGA output, so you will need an Active HDMI to VGA convertor (not just a cable - those don't work).

As for displaying signs, well I'd use any graphics package to generate some images of each sign I want displayed, then use "fbi" to display that image on the screen. You don't even need to have the desktop version of Raspberry Pi OS installed, that will work with the "Lite" version.

The code would be simpler to write in Python as there are examples of how to react to button presses all over the place. Start your program automatically at boot and display a blank image to start with, Then replace that with the one you wnat when the button is pressed.
Unreadable squiggle

emandude777
Posts: 2
Joined: Fri Jun 18, 2021 3:02 pm

Re: I want to create an "On Air" sign for my studio.

Sat Jun 19, 2021 3:17 pm

Thank you both for your help so far. I'll see what I can do with what you mentioned. (also related to the VGA thing, I was planning on using, if I use the RP2 that is, to utilize the analog 3.5mm output to VGA, that cable is cheaper and it doesn't have to be the best looking thing ever.)

Return to “Other projects”