I have the code compiled from the developer site for displaying something on the screen, but I'm a bit unfamiliar with the way the display works. I have a 128x32 graphic in Photoshop that I want to display with that program, but I have no clue what format to save the file in. Does that program look for a standard graphic type, or does it need a conversion to something non-standard first?That sample program just blits from stdin to display in display's raw format, which is 4-bits a pixel (little-endian).
I'm using a TGA loader for my own apps, but as the TGA loader is heavily dependent on the other stuff I've done, it's not easy to copy&paste it here. So I took the same sample from dev-site and added the 8-bit -> 4-bit conversion to it, so that you can load raw files with the
attached example. But if you consider programming anything in larger scale, I would suggest to write a proper image reader.
So, to get your image to the display:
1) compile the attached program
2) make your image 128x32 sized (image can use all 256 grayscales)
3) after your image is ready, go to Image/Mode/Grayscale in Photoshop
4) go to File/Save As, choose the .RAW format
5) use the default options, header being 0 sized
6) transfer the image to empeg (file size should be 4096 bytes)
7) run "blitraw < pic.raw" on your empeg, if you named the attached program as blitraw and image as pic.raw
This is the easiest way to get your own image to empeg's display but also the most unsophisticated way to do it. It relies that the raw image file has no palette and that 0 means black and 255 white, on color indices. And it only works with 128x32 images.
PS. Okay, the attachments still does not work.. I'll attach the source code manually to end of this message.
Kim
----------------------------------------------------------
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#define BLIT(fd) ioctl((fd), _IO('d', 0))
#define DISPLAY(fd, x) ioctl((fd), _IOW('d', 1, int), (x))
int main(int argc, char *argv[])
{
int fd;
caddr_t dmap;
int i = 0, j = 0;
char cBuffer[ 4096 ];
char cLeft = 0, cRight = 0;
fd = open("/dev/display", O_RDWR);
if(fd == -1)
return 1;
dmap = mmap(0, 2048, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (dmap == (caddr_t) -1)
return 2;
if( read( STDIN_FILENO, cBuffer, 4096 ) == -1 )
return -1;
// shuffle bits
for( i = 0; i < 4096; i+=2, ++j )
{
cLeft = cBuffer[ i ] >> 6;
cRight = cBuffer[ i+1 ] >> 6;
dmap[ j ] = (cRight << 4) | cLeft;
}
BLIT(fd);
DISPLAY(fd, 1);
if (munmap(dmap, 2048) == -1 || close(fd) == -1)
return 3;
return 0;
}