image conversion

I was wondering if there is a way to turn images (jpeg, png, etc...) into two color (black and white) binary images for use with the TVOut library.

Thanks.

Thresholding an image is trivial, even on an Arduino.
Decoding a JPEG image is not.

Would any other formats work better? PNG, Tiff?

Also:
How can I load, say, a plain text file into an arduino program?

How can I load, say, a plain text file into an arduino program?

Well, first you need a file system. The Arduino doesn't have one. When you get over that hurdle, let us know.

Where does this plain text file live? How would you use it in the Arduino sketch?

I also know C++, so what I wanted to do was to be able to pass a variable from C++ into a file, and then to the Arduino. I just want to be able to read and/or write from/to a plain text file.
And it could live anywhere, really.

And it could live anywhere, really.

No, not really. The file can't live on the Arduino, because the Arduino does not have a file system or the hardware to support a file system.

I also know C++, so what I wanted to do was to be able to pass a variable from C++ into a file, and then to the Arduino.

C++ is a programming language. You can't pass a variable to a file from C++.

You can write an application that runs on the Arduino, or on a PC, using C++. If that application runs on a PC, it can write to a text file on the PC, and to a serial port.

If the Arduino is connected to the other end of the serial port, it can read the data written to the serial port.

Baum,

the TVout library is very, very primitive in handling pictures. Look a the code of the fs-bitmap function. All it does is write bytes as they are from an array in flash to the screen. Each bit is one pixel black or white, I didn't bother to check the bit order. The function itself only can use the picture saved in bitmap.h and the picture needs to have the exact size of the screen.

With GIMP you can create a black and white picture from a JPG, with following steps:

  • Colour->Threshhold:
    Convert the bitmap to 2 colours the way you want. If you do this with the Playmate of the month, the results will be ugly.
  • Image->Mode->Indexed ... Select "User black and white (1-bit palette)":
    That makes the next step easier.
  • Save As... Select as File Type: C source header (.h)
  • You now have a .h file where the bitmap is all 0 and 1, one per bit in the array header_data[].
  • Process header_data with a little program to pack all those 0 and 1 the way you need for the library. Hint: 8 values from header_data[] go into 1 byte for TVOut.

I hope that helps a little.

Korman

Thanks! But I was wondering if I could put that into a [C++] script, so that it could be automated. Example:
[This is Terminal Output]
Please enter path of JPG image: foo.jpg [ENTER]

Then convert it to Black and White and output to my TV.
I saw something a few days ago where a guy had hooked up a video camera to his arduino and then outputed two-color images to an 8x8 led display.

Probably yes, if you do all the processing on the PC and just transfer the bitmap in the most strange format TVout uses directly into the buffer display.screen uses. However, even at the default resolution if TVout, of 128x96 pixel, you run out of RAM on the ATmega328.

If you're heart is set on such a gimmick, better consider using another platform which offers you enough ram and perhaps a proper graphic card to write a TV overlay. Remember how limited the VIC20 was with its 3.5 kB RAM? You have 1 kB.

Korman

Then i guess I won't do that... maybe I'll just do it manually like you said before.
But I found a new project: I am going to salvage some parts from an old Apple keyboard and use it to make my own keyboard (I didn't have much luck with the PS/2 library).

1k on the 168, 2k on the 328 (which I hope today most are using):

If the TVOut library offered the means to draw from an array in fs-bitmap, rather than just a header file - and if there were enough SRAM space left over (maybe the res could be dropped instead); then in theory you could either stream the bitmap over the serial connection, or store the bitmap on an SD card (as a text file), and read it from there into the array and display it.

Something tells me though, that between the library for the SD card, and the library for TVOut, that memory is likely to be very slim indeed - it might not even be possible to combine both libraries as it is (I've never played with either; this is all guesswork). If it were possible, your sketch likely could do nothing else, I would imagine. There also may be limits in the TVOut library to drawing from an array (does it use an internal array to represent the frame buffer?)...

:stuck_out_tongue:

I am going to salvage some parts from an old Apple keyboard

This isn't an Apple IIe keyboard (or forbid - an Apple I keyboard!) - you might want to verify that it works, and then set it aside; whatever you do, don't disassemble it. If you must interface to it, do it in whatever manner that -doesn't- keep it from being used on an Apple computer. These keyboards are getting rare, and the price for these parts is starting the inevitable "climb thru the roof".

Seriously - you could end up damaging something that is worth a lot of money to a collector (or someone restoring such an old system)!

1k on the 168, 2k on the 328 (which I hope today most are using)

Yes, you're right. Although quite a few of the small 3.3V boards like the Lilypad still use the ATmega168.

Korman

cr0sh: My current resolution is 128*96, which come out to about 1.5kb. I have a 328 (I got it in July), so I should be fine...
And no, the keyboard isn't that old. It's from a PowerMac (~Year 2000) And it uses an ADB Port (4 pin connector exclusive for apple) which has long since been discontinued. It's been in my basement for 10+ years. Also, apple being apple, it wouldn't work on my arduino. You have to use some special code, which apple has obviously not realized, to get it to initiate. But there is ~50 working buttons and button covers, so I think it will be of better use to me reincarnated as a homemade keyboard.

If the TVOut library offered the means to draw from an array in [...] then in theory you could either stream the bitmap over the serial connection

That's actually quite possible and not so hard. From TVout.h:

class TVout {
[glow]public:[/glow]
        uint8_t * [glow]screen[/glow];
[...]
};

You can access the array directly and thus stream directly into the screen buffer from whatever source you like. If you stream the bytes read on the serial into the screen buffer, the image loading will have a certain BTX-like feeling but it'll work. It's worth a try.

For more ideas how that's going to work, take the function fs_bitmap as a sample, you'll find it in TVout.cpp.

Korman

So I just looked around TVout.cpp, the TVOut google site, but couldn't find anything on how to display bitmaps. Any help?

Reply #15 looks to be the way to go

Yes. But how would I direct the program to the correct bitmap. I have the .bmp on my computer, but how could I go about sending to the arduino program?

Serial.read() is your friend.

Don't take this code as gospel, I wrote without any testing and it misses a lot of error checking and control around all of this. But basically you'll want something like this.

for (int i = 0; i < myTVout.hres * myTVout.vres; i++) {
    while (! Serial.available()) ;
    myTVout.screen[i] = Serial.read();
}

This assumes myTVout is your TVout object and you checked first if the PC has just started to send a picture by some header.

On the PC your program needs to load the image with any of the standard libraries, reduce the size to 128*96, convert it to 1 bit monochrome and pack the bit in the way your TVout buffer needs it and send it out on the USB-Serial on which your Arduino is listening.

For this part a lot depends on what operating system you use, what's your preferred programming language and environment and similar stuff. I think this is more in the scope of a general programming forum and less an Arduino issue.

Korman