LCDInfo.com
http://forum.lcdinfo.com/

Command line tool for showing image files on the USBD480
http://forum.lcdinfo.com/viewtopic.php?f=19&t=2644
Page 1 of 1

Author:  Henri [ Thu Apr 09, 2009 15:38 ]
Post subject:  Command line tool for showing image files on the USBD480

Here is a simple command line program to show image files on the USBD480 display. No programming knowledge required to use this one.

You can just call it like this "usbd480_showimage myimage.bmp"

It uses the FreeImage library for loading the images so for a list of supported image formats you should check the FreeImage website: http://freeimage.sourceforge.net/features.html
Most common formats should be supported.

You can download the tool here:

http://www.lcdinfo.com/usbd480/software ... wimage.zip

Author:  Henri [ Thu Apr 09, 2009 15:40 ]
Post subject: 

And here is also the source code if someone wants to have a look or make modifications. As you can see it's not very complicated.

Code:
// usbd480_showimage.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"

#include "FreeImage.h"
#include "USBD480_lib.h"

int _tmain(int argc, char* argv[])
{
   FIBITMAP *dib = NULL;
   FIBITMAP *dib_565 = NULL;
   FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
   unsigned char *data;
   DisplayInfo myDisplay;
   char fileName[1024];
   int slen;

   if(argc>1)
   {
      slen = strlen(argv[1]);

      if(slen>=1024)
         return 0;

      strncpy(fileName, argv[1], 1024);
      printf("Showing file: %s\n", fileName);
   }
   else
   {
      printf("Give the file name as a parameter.\n");
      printf("Example: usbd480_showimage myimage.bmp\n");
      return 0;
   }

   int displays = USBD480_GetNumberOfDisplays();

   if(displays < 1)
   {
      fprintf(stdout, "No displays found\n\r");
      return 0;
   }

   int ret = USBD480_GetDisplayConfiguration(0, &myDisplay);

   ret = USBD480_Open(&myDisplay,  0);
   if(ret != USBD480_OK)
   {      
      fprintf(stdout, "Unable to open display\n\r");
   }

   // check the file signature and deduce its format
   // (the second argument is currently not used by FreeImage)
   fif = FreeImage_GetFileType(fileName, 0);
   if(fif == FIF_UNKNOWN)
   {
      // no signature ?
      // try to guess the file format from the file extension
      fif = FreeImage_GetFIFFromFilename(fileName);
   }
   // check that the plugin has reading capabilities ...
   if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif))
   {
      // ok, let's load the file
      dib = FreeImage_Load(fif, fileName, 0);
   }

   if (dib != NULL)
   {
      //fwprintf(stdout, L"dib ok w: %d h: %d\n", FreeImage_GetWidth(dib), FreeImage_GetHeight(dib));

      if(FreeImage_GetWidth(dib)!=480 || FreeImage_GetHeight(dib)!=272)
      {
         printf("Image size needs to be 480 x 272 pixels");
         return 0;
      }

      dib_565 = FreeImage_ConvertTo16Bits565(dib);

      unsigned char *bits = FreeImage_GetBits(dib_565);

      data = (unsigned char*)malloc(262144);

      unsigned char* inv_bits = (unsigned char *)bits+480*271*2;
      unsigned char* data_ptr = data;

      // the bitmap lines are stored upside down so invert them here and place to the data buffer
      int i, j;
      for(i=0;i<272;i++)
      {
         for(j=0;j<480;j++)
         {
            *data_ptr++ = *inv_bits++;   
            *data_ptr++ = *inv_bits++;
         }
         inv_bits-=480*2*2;
      }

      
      USBD480_SetAddress(&myDisplay, 0);
      USBD480_SetFrameStartAddress(&myDisplay, 0);
      USBD480_DrawFullScreen(&myDisplay, data);
      USBD480_Close(&myDisplay);

      if(data)
         free(data);

      // free the dib
      if(dib)
         FreeImage_Unload(dib);
      if(dib_565)
         FreeImage_Unload(dib_565);
   }
   else
   {
      fprintf(stdout, "NULL dib?\n");
   }

   return 0;
}

Page 1 of 1 All times are UTC + 2 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/