- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Not so bad, especially since there used to be some programs for converting bitmaps to some quasi-standard file format, was it XPM? The format was C syntax, so you could just include the C files in your program and have data at hand.
Some of us even equipped homebrew web browsers, very early on, to handle this incoming graphic format. Urp.
Admin
Admin
Admin
Did anyone mention this all makes sense for an embedded system? Just asking.
Admin
Not a WTF. It's for ease of change. If you want to modify the bitmap, all you have to do is change a few source lines and recompile.
Admin
Only everyone....
Admin
This is why many otherwise-talented C and C++ coders have not passed interviews at our company. You really need a different mindset when you're dealing with a system with 32k of Flash, 4k of RAM, and a 1MHz clock speed (which drops to 32kHz when you need to conserve power).
Some projects I've worked on, for example, had to keep function calls to a minimum because the overhead (both speed and stack space) was too expensive.
So I can see why this would be a WTF for the uninitiated, but in an embedded system, sometimes a good old hardcoded char array is the best way to go.
Admin
Output should be something like:
const char my_bmp_data[] = {0x42, 0x4d, 0x36, 0x0c, 0x00, ...snip... 0xed, 0x4d, 0x47, 0xf1};
I've never personally done it, but I came up with that command line for someone else trying to get a similarly binary format into source code.It's a little more compact with a const char *:
Output is something like:
const char * const my_bmp_data = "\x42\x4d\x36\x0c\x00...snip...\xed\x4d\x47\xf1";
Admin
Admin
That's assuming you're using GCC. I've used GCC for embedded ARM and AVR projects, but if you're dealing with a PIC, or an MSP430, or a Cypress PSoC, you're most likely using proprietary toolchains.
I agree that linking a binary image (provided it's a dead-simple uncompressed one) is the best way to go, though, if you have the option.
Admin
No definetly not. You are the first, thank you for your insight. It is a good thing you didn't bother to read the comments, that would have just slowed you down in posting this helpful perspective.
Admin
I think this is a real WTF. The proper way to do it is obviously to base64-encode the bitmap and store it in a CDATA section in an XML string in the source file.
Admin
If either storage or memory for libraries is a problem (like it usually is in embedded systems) then this is the normal thing to do. Also handy for displaying things like "error unable to load bitmaps" on a system that can not output text easily.
Admin
Admin
hah!
FOX toolkit does that! Or something like that...
Admin
You see this all the time in embedded systems because some boards don't have real operating systems with file support. So creating a fake file system for files like bitmaps and the like using giant arrays is pretty much your only choice.
The example given here is of code used across a large variety of boards, so it was written to work with the lowest common denominator.
Not a WTF.
Admin
It's EVE Online
Admin
The only WTF I see is that the orignal developer didn't cook the image enough when he encoded the data.
I see some structures for headers (color, size, offsets, etc) and palettes. The orignal developer should have optimizes the image for his display and dumped the meta data.
Admin
Admin
Yes. Everyone.
Admin
Johnny D. should probably stick to living in the cozy world of file systems, string builders and resource files if he thinks this is a WTF.
Most normal thing in the embedded world and I have written my share of binary file to C-code converters. Probably there was one in the lost makefile once.
TopTension
Admin
Too bad I can't mod you up for being insightful.
Admin
Of course! With crappy printouts in magazines where you often could not tell the difference between a B and an 8 :(
Made for painstaking typing followed by a swift and colourful crash on a ZX Spectrum.
Admin
I'm still calling this WTF as the original developer could have linked a binary file instead leaving it as a C file. This is by far the better solution as changing the bitmap would only require replacing the file instead of re-writing a C file. In addition you can specify in your linker script where you want the bitmap to be loaded in memory. Finally, manually editing file headers? Well I guess if your in windoze and your dealing with Mr. Gates idea of a bitmap..
Admin
I had the source for a bunch of the "VGA demos" that we used to trade on floppies back in the early 90s. Many of them were written just like this.
CAPTCHA: inhibeo - is TDWTF trying to tell me something?
Admin
Was there some part of "no filesystem" that you didn't understand?
Admin
I didn't know I had anything left in me to die.
Admin
Yeah, this code is fine.
Admittedly, the developer machine ideally would have linked in the bitmap at link time(prior to upload), but that probably wasn't available at the time or the developer didn't know about it.
Not a big deal. The Web 2.0 guys are getting their panties twisted tho', kinda funny to see...
Admin
We used to use that pattern when writing demos and intros back in the day. The only real reason was to end up with a single executable with no external filesystem dependencies. There's really no reason for such nonsense in the "real world", though. :)
Admin
JWZ's X-Screensaver does this (uses XDM) for its display as this is more secure than having separate image files. If this is a WTF, it's not in the technique itself but in the application of it.
Admin
[image]
for the curious... 26x24
Admin
Everyone keeps saying "EMBEDDED DEVICE WITH NO FILESYSTEM AND NEXT TO NO RESOURCES!!!!!!1111one!!", but I have to wonder how relevant that notion actually is anymore. Heck, even my cellphone has 256 MB of RAM, and a filesystem to manage a few gigs' worth of storage on a tiny storage chip that an infant could close their hand around. And at CES they just demoed a Droid-powered microwave! Are these fabled "embedded devices" actually still being created anymore? If so, what are they used for?
Admin
The fact that so many of you think this is a WTF is exactly why we hire people with embedded experience for embedded jobs. Normal desktop/app programmers have no idea what to do on machines with limited resources or which have no OS at all, so they can't architect anything properly. For instance, you don't do floating point math in interrupt routines (don't laugh, I've seen it attempted). You often don't have a filesystem to just load your data from. And your primitive linker may not support embedding arbitrary binary blobs in your target and/or giving your code the offset to them.
This is a perfectly valid, time tested way to do it within all these constraints - assuming you have some tool to output the code for you from the resource blob. If you're creating and maintaining it by hand then you may have a wtf on your hands.
Admin
Admin
as relevent as wasteing millions of dollars per year on additional memory and almost millions on software maintance.
Admin
If the application needs speed, the system has plenty of memory, maybe the embedded display works by pointing to a memory area where a bitmap is, then this solution works well.
I really don't see the WTF here. Or maybe I'm overlooking something...
Can you provide an example of a strictly better alternative?
captcha: haero
Admin
Ah the SMALL volume items, the larm systems, coffee machines, microwaves, distributed processing units in modern cars, let alone anything with a small graphic LCD or even SWITCHES that LCD displays that can change the caption on the switch.
The VAST bulk of microprocessors/controllers shipped by VOLUME are 4 and 8 bit processors, with next to no memory (ROM and RAM).
Captcha dolor - A devalued currency
Admin
Ouch my head hurts now after reading all the comments and understand < 0 portions of it; I sure am glad you guys are around to keep my washing machine with an LCD display (and a small splash screen), a car, a microwave, a calculator, a remote control, a power meter, an electric door lock, a card reader, a security camera, an automatic door, medical equipment, robots, signal processing devices, regular or cordless phones, heat pumps and A/C devices, hard drive controllers, rice cookers, electric ranges, ticket machines, wickets, planes, scrolling displays, interphones ... etc working.
Admin
It saves writing loader code and you have all your bitmaps linked into your program, instead of having to have a bunch of external files.
The GIMP can even generate this code.
Not really a WTF.
Admin
Hey I have seen desktop jockeys get that many errors because they forgot obvious compiler switches, like -
Do NOT include Standard C runtime Do not include Standard Math libraries for float Do not include stdio/printf/sprintf calls Do not limit the max integer to 16 or 8
Then over half is because the memory map ha overflowed.
Still designing embedded systems (since the early 1980's), from T-11, 6809, 8085 through H8 and beyond.
Captcha augue - more precise than vague
Admin
I wonder how many "Gizz'us a job" requests you get??
:-^
Captcha duis - rap speak for 'doing his [girlfriend/hoe]'
Admin
Reminds me of Basic listings of ancient magazines like Compute! and Family Computing.
Borland Turbo Pascal and C had BINOBJ.exe, converted binary files to objects to be linked directly to the executable.
That C listing is just "portable", but, I don't have a clue why the infamous .bmp format. Header is large, lots of unsupported variants (rle, os/2), and, pics are stored upside-down!
Admin
Look at the forefront of web technology: Data URLs for images all over the place. The c-bitmap is even better, because it is semantic.
Admin
So this is for a levitating tractor controller?
Admin
I sign my name under this one.
I've used XPM files for a long time. They are the easiest way to embed a simple image on an executable.
WTF is this WTF anyway ?
The real WTF would be (I know, this is used somewhere, just don't remember where):
Admin
Okay, but what is it? A tractor sitting on top of a tree moving to the left?
Admin
Embedding images into C code isn't WTF, it's actually fairly common. In fact, there's an entire file format designed to do specifically that, called XPM (X PixMap). GIMP imports and exports natively, and Qt at least "just does it." Doing bitmaps for icons this way sounds like a perfectly reasonable version of this pattern.
http://en.wikipedia.org/wiki/X_PixMap
Admin
WTF? That's a choking hazard!
PS,. that icon is like the greatest icon for "Launch photon torpedoes and energize tractor beam" that I have ever seen!
Admin
Absolutely NOT a WTF as has been stated over and over. This may be the first I've seen that I would like to be removed from the site. Prior commentators have already listed the reasons this is perfectly valid.
If there is a WTF, perhaps it's on the head of "Johnny D". If I were to guess, he's a young programmer with very little experience outside of Java or the likes.
Admin
Hear hear. Most of the projects I've worked on have had no OS at all, and I've hit Flash and/or RAM constraints dozens of times. Dynamic allocation? Sorry, there's no heap. Most of the processors have no floating point unit whatsoever, and you definitely don't have the space or time to emulate it, so you do your calculations using fixed-point tricks instead. Lookup tables are extremely common (for the same reason). And the best part: paying thousands of dollars for the tools, and having them be buggy and crash-prone anyway because there's really no competition out there.
Here's one example where the C-bitmap works extremely well... one project I've worked on has a 240x64 black-and-white LCD, and the memory map of the LCD has each byte equal a 1x8 column of pixels, with the MSB at the bottom. So you basically encode bitmaps as series of 8-pixel-tall strips of confetti. That sort of memory mapping makes conversion from any sort of other bitmap on the fly slow and wasteful.
It's really a totally different world when you're working under such limiting circumstances -- much more like application programming was during the days of the Apple //e and Commodore 64 than any sort of PC programming today.