Searching \ for '[PIC] C30 Macros' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'C30 Macros'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] C30 Macros'
2007\10\30@112646 by Harold Hallikainen

face
flavicon
face
I've got a function that converts an 8 bit monochrome pixel level to a 16
bit color value. I'd like to speed it up by using an 256 word array of
constants and just index into the array. I can't figure out how to tell
C30 to define the array without writing calculating out every value by
hand. I could, I guess, fill a table in RAM, then reference that, but it
seems like a waste of RAM. So, is there some sort of for-next loop I can
write that the preprocessor will expand out? I only see stuff about
conditionals at http://gcc.gnu.org/onlinedocs/cpp/ . Nothing about
looping. Ideas? Existing function is below.

THANKS!


Harold

void DisplayWriteNextPixelMono(uint8_t color){
// Spread incoming 8 bit monochrome out to 16 bit color
union{
 struct{
   uint16_t blue: 5;    // 5 bits of blue
   uint16_t green : 6;   // 6 bits of green
   uint16_t red: 5;      // 5 bits of red
 };
 uint16_t u16b;        // 16 bit rgb word
}color16;
 color16.blue=color>>3;    // build 16 bit word from incoming color
 color16.green=color>>2;
 color16.red=color>>3;
 DisplayWriteNextPixel(color16.u16b); // send it
};


--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

2007\10\30@130752 by John Temples

flavicon
face
On Tue, 30 Oct 2007, Harold Hallikainen wrote:

> I've got a function that converts an 8 bit monochrome pixel level to a 16
> bit color value. I'd like to speed it up by using an 256 word array of
> constants and just index into the array. I can't figure out how to tell
> C30 to define the array without writing calculating out every value by
> hand. I could, I guess, fill a table in RAM, then reference that, but it
> seems like a waste of RAM.

If you're really concerned about speed, RAM will be faster.

> So, is there some sort of for-next loop I can
> write that the preprocessor will expand out?

No, you can't loop with the preprocessor.  For something like this, I
would write a macro that generates one table entry, then use a simple
awk script to generate the table filled with invocations of the macro.

--
John W. Temples, III

2007\10\30@132151 by wouter van ooijen

face picon face
> So, is there some sort of for-next
> loop I can write that the preprocessor will expand out?

Not that I know, not in the standard C preprocessor.

But nobody forces you to write it all out, after all, that is what
computer are made for!

a line of Python:
  for i in range ( 0, 255 ): print "/* %03d */ %d,\n" % ( i, i / 16 ),

redirect this to a file conv.i, put in your C file

  unsigned char conv[ 256 ] = {
     %include "conv.i"
     };

If you use make you can even arrange for changes in the generator code
to cause it to be re-applied, and the C file re-compiled.

Instead of Python you can use tcl, awk, perl or even C.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu




2007\10\30@133822 by Nicola Perotto

picon face


wouter van ooijen wrote:
> Instead of Python you can use tcl, awk, perl or even C.
>
>  
Often i use Excel to generate table and save to ascii file.


2007\10\30@161541 by Harold Hallikainen

face
flavicon
face

{Quote hidden}

Thanks! I did write a single macro, then did a cut and paste, then went
back and modified the argument (only 256 of them) by hand. Code below.
I'll try running from ram and see how much of a speed change there is.

Thanks!

Harold

sample code:

#define color16(mono8)
((mono8<<8)&0b1111100000000000)|((mono8<<3)&0b11111100000)|(mono8>>3)

const uint16_t ColorFromMono[]={
 color16(0),
 color16(1),
 color16(2), ...



--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

2007\10\31@054429 by Alan B. Pearce

face picon face
>> Instead of Python you can use tcl, awk, perl or even C.
>>
> >  
>Often i use Excel to generate table and save to ascii file.

I have done that too.

More... (looser matching)
- Last day of these posts
- In 2007 , 2008 only
- Today
- New search...