|
Of course! It should be:
if (!condition) {
}
|
|
|
|
|
// need to do something if conditions are right otherwise don't
if( condition )
{
do something
}
return
|
|
|
|
|
Agreed.
I like to avoid (complex) negative conditions; so I might have:
if ( negative condition as a positive) {
else {
return;
}
(Don't like your braces tho ... bad Feng Shui)
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I've been writing a little graphics library for C++ capable IoT devices.
The first thing I wanted to do was make JPEG loading work. I did that. I can't load JPEGs into memory all at once on such a little device so it required me to implement my own stream classes because std::iostream is too bloated and way to hard to implement over a simple memory buffer, even if it wasn't bloated because of the templates. On PCs I don't mind, but on these IoT things how much space your code takes up matters, and not just in RAM. So the JPEGs required a stream library.
In terms of getting things onto the displays, there is no unified driver or hardware interface for any display adapters, so now my graphics library requires a tiny interface a bit like DirectDraw.
And because device i/o is slow, it would be impossible to do anything without being able to exploit any asynchronous DMA capabilities of the hardware available, so *now* my library requires abstract interfaces to provide an asynchronous graphics operations model
All this elephanting code. And that's before I even start writing actual drivers for say an ILI9341 or an RA8875 LCD hardware controller.
Heck that's before I even start implementing basic things like line drawing and filling, or heaven forbid, fonts.
*headdesk*
I love coding for these little things because you're so close to the metal, but when you want to go your own way with something, because existing offerings are too heavy or limited, you have to start over from scratch.
Real programmers use butterflies
|
|
|
|
|
But you have the knowledge of what's required - you know you'll do it eventually so you might as well get on with it
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
Well, if you want a really graphic description then you may have to use some rather graphic langua . . . oops - that's not what you meant.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
I've always liked doing that.
What I don't like is programming in a straight-jacket, as you seem to be. I work with CUDA these days and it definitely has its limitations but not nearly as severe as your little things do. My limitations are things like, I only have 8GB of VRAM and 2304 cores to work with - how am I ever going to make it fit? Luckily, my answer is buy a better card if we have to. You don't seem to have that option available, unfortunately.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Coding with no RAM builds character!
Real programmers use butterflies
|
|
|
|
|
Yes, but it's a bit too masochistic for my tastes.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
I like the creativity it requires.
Here I get called back with rectangles I'm getting from "converting" a jpeg - in this case into a raw rgb565BE bitmap form, compatible with the frame buffer of the LCD display I'm using. I'm them telling the device to do a DMA transfer from the ram I just gave it, in effect, loading the JPEG onto the display one rectangle at a time:
jpg_state js;
js.tft=&tft;
js.dma_space=dma_space;
js.size = dma_size;
io::file_stream inp("/spiffs/warhol320x240.jpg",file_mode::read);
jpeg::convert(
inp,
[](const rect16& rect,size16 size,const rgb888* bitmap, const void* state){
jpg_state s = *((jpg_state*)state);
const rgb888* end = bitmap+(sizeof(rgb888)*rect.width()*rect.height());
assert((((end-bitmap)/sizeof(rgb888))*sizeof(rgb565))<=s.size);
uint16_t* buf=(uint16_t*)s.dma_space;
while(bitmap!=end) {
rgb565 col = color::reduce(*bitmap++);
*(buf++)=env::platform::mkbe(col.value);
}
return result::success==s.tft->write(rect,s.dma_space);
},
&js);
Real programmers use butterflies
|
|
|
|
|
Many moons ago (Before Windows), I wrote graphics packages for the CGA, EGA, and Hercules. These ran on the IBM PC (640KB, 8088at 4.77 MHz) with reasonable performance. This, despite arcane addressing and slow I/O.
Even if I/O is slow, how difficult could it be to write graphics packages for a 32-bit processor with tons (8 mega bytes!) of memory?
Without going into details, perhaps you're over-engineering the problem. For example, unless there is a specific requirement for supporting JPEG images in runtime, why not convert them offline to a more amenable format? I am certain that many other shortcuts are possible if you think of the problems in the right way.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Daniel Pfeffer wrote: For example, unless there is a specific requirement for supporting JPEG images in runtime, why not convert them offline to a more amenable format?
I thought about it. But then I remembered that 320*240*16 is a really big number, and my flash storage size isn't a much bigger number, even on the ESP32 which is fairly generous.
But actually, that's not the main reason I support it. I support it because SD cards and cameras exist for these monsters and both typically can produce or source pictures or frames in JPEG format
I wrote the JPEG library. I have andy warhols sunglassed face starting at me from inside the ESP32 Wrover Kit's LCD and rippling weirdly under the effect I'm running right now.
If it makes you feel any better, I thought about supporting PNG too, before catching myself.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: I love coding for these little things because you're so close to the metal, but when you want to go your own way with something, because existing offerings are too heavy or limited, you have to start over from scratch. Something about cake and eating it too comes to mind .
I've implemented a couple graphics libraries in my time. Instead of run-time polymorphism, try build-time polymorphism. Instead of a device 'driver' that has to be all things to all people, have a device-specific bottom layer with an interface that's sufficiently generic for the graphics library's purposes, but no more than that. This device layer provides only essential primitives: line drawing, curve drawing if you need it, region fills, essentially only the device coordinate primitives you might want. A lot of Bresenham's algorithms are useful here. I've not implemented significant text capabilities, but there are primitive operations for that the device layer can provide (draw a block of pixels, for example). Since footprint is a concern, the device layer should be granular in a way that lets the linker prune parts that aren't used.
Needless to say, K.I.S.S. should be your guide here.
Software Zen: delete this;
|
|
|
|
|
I'm on the fence about using templates for that. flash program space is almost more valuable than RAM so templates are problematic because of the code bloat they tend to introduce. I'm not fully opposed to them in this case, and i've used one or two little ones (mainly for templating a piece of hardware's physical pin assignments) but I haven't been doing any generic programming as a rule.
The driver does exactly what you're talking about. And the challenge is coming up with something high level enough that it satisfies the better devices in terms of being able to use their hardware features like line drawing, without incurring a bunch of overhead for most drivers that don't have it and typically just deal in bltting.
My attempted approach right now is to build the fundamentals into the library such that the compiler and linker can eliminate what's not used - for example, if your hardware supports line drawing the software won't link the line drawing code into the library.
I'm doing this by creating static helpers that do basic drawing. The drivers call the hardware or return a not_supported result. If it's not supported, a canvas can fallback on using the software, at which point it will be included in the final source.
This is tricky. The other thing I'm running into is if I expose a canvas from a given bitmap, then I have to support any graphics features used by that canvas in software, since no video card is involved, leading to potential inclusion of much of the library under many situations. =(
Real programmers use butterflies
|
|
|
|
|
March 14 (3-14) is national pi day!
Get me coffee and no one gets hurt!
|
|
|
|
|
What! It'll be stale and nasty with soggy pastry that sticks to the roof your mouth.
Make it on the day, it's the best way to enjoy them ... Scotch Pie; Pork Pie; Snake and Pygmy Pie; Chicken, BACON, and Mushroom pie; all damn good!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Quote: Pygmy Pie You bake pygmies into pies?
Get me coffee and no one gets hurt!
|
|
|
|
|
Well, you can Devil[^] them as well ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Snake and Pygmy no less!
Does the snake have to consume the Pygmy first or are the ingredients separate?
If you can't laugh at yourself - ask me and I will do it for you.
|
|
|
|
|
My grandmother made a great steak and kidney pie. Well, as long as you didn't have to smell the kidneys cooking.
She was from Bolton.
If you can keep your head while those about you are losing theirs, perhaps you don't understand the situation.
|
|
|
|
|
Judging by the list of things you apparently consider as edible I can only deduce that the UK has been too close to France for too long.
Better had you been assimilated by the Borg.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
The reason they started an empire was so some of them could get away from their mothers cooking!
If you can't laugh at yourself - ask me and I will do it for you.
|
|
|
|
|
OriginalGriff wrote: Scotch Pie I'm salivating just thinking of that.
|
|
|
|
|
Pi is filth! Tau is the only true path!
|
|
|
|
|
e is the truth and the light! (8 out of 10 clubbers can't be wrong.)
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|