Subject: Is 257 some sort of magic number?

From: Tim Phipps <[email-masked]>
Date: Thu, 08 Aug 2002 15:18:06 +0100

OK->find . -name '*.h' -o -name '*.c' | xargs grep -n 257
./fvwm/ewmh_icons.c:343:                fg[0] = colors[0].blue/257;
./fvwm/ewmh_icons.c:344:                fg[1] = colors[0].green/257;
./fvwm/ewmh_icons.c:345:                fg[2] = colors[0].red/257;
./fvwm/ewmh_icons.c:346:                bg[0] = colors[1].blue/257;
./fvwm/ewmh_icons.c:347:                bg[1] = colors[1].green/257;
./fvwm/ewmh_icons.c:348:                bg[2] = colors[1].red/257;
./fvwm/ewmh_icons.c:425:                                        
c_new_icon[l++] = colors[k].blue/257;
./fvwm/ewmh_icons.c:426:                                        
c_new_icon[l++] = colors[k].green/257;
./fvwm/ewmh_icons.c:427:                                        
c_new_icon[l++] = colors[k].red/257;
./fvwm/ewmh_icons.c:454:                        c_new_icon[k] = 
(unsigned short)c.blue/257;
./fvwm/ewmh_icons.c:455:                        c_new_icon[k+1] = 
(unsigned short)c.green/257;
./fvwm/ewmh_icons.c:456:                        c_new_icon[k+2] = 
(unsigned short)c.red/257;
./libs/PictureGraphics.c:352:                                           
c.red/257,
./libs/PictureGraphics.c:353:                                           
c.green/257,
./libs/PictureGraphics.c:354:                                           
c.blue/257);
./libs/PictureImageLoader.c:535:                                c.blue = 
b * 257;
./libs/PictureImageLoader.c:536:                                c.green 
= g * 257;
./libs/PictureImageLoader.c:537:                                c.red = 
r * 257;
./libs/PictureUtils.c:324:      c->pixel = PictureRGBtoPixel(c->red/257, 
c->green/257, c->blue/257);
./libs/PictureUtils.c:415:              c.red = r*257;
./libs/PictureUtils.c:416:              c.green = g*257;
./libs/PictureUtils.c:417:              c.blue = b*257;
./libs/PictureUtils.c:444:              c->red/257, c->green/257, 
c->blue/257);

I can't help feeling that 257 is the wrong number for all this stuff and 
256 is the correct number. It might be better to just leave most of 
these things as unsigned shorts or pass XColor's around and convert to 
byte size pieces as late as possible.

/257 will take ages on any processor, /256 will take one cycle on most.

Cheers,
Tim.

--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: "Dmitry Yu. Bolkhovityanov" <[email-masked]>
Date: Fri, 9 Aug 2002 12:09:47 +0700

On Thu, 8 Aug 2002, Tim Phipps wrote:

[SNIP]
> /257 will take ages on any processor, /256 will take one cycle on most.

	257 is the correct scale factor for conversion between 8- and
16-bit colors: 257==0x101, so that e.g. 0xFF becomes 0xFFFF if multiplied
by 0x101, not 0x100.  Most of XFree86 code uses 0x101 as conversion factor
(see xc/{lib/X11/LRGB.c,programs/xcmsdb/xcmsdb.c}.  Of course, when
scaling from 16 down to 8 bits 256 will work almost as good as 257, but
unification-wise 257 is better.

	_________________________________________
	  Dmitry Yu. Bolkhovityanov
	  The Budker Institute of Nuclear Physics
	  Novosibirsk, Russia

---

From: Olivier Chapuis <[email-masked]>
Date: Thu, 8 Aug 2002 17:15:56 +0200

On Thu, Aug 08, 2002 at 03:18:06PM +0100, Tim Phipps wrote:
> [snip]

257 is magic in the sense that 255*257 = 65535. I will make the change.

> /257 will take ages on any processor, /256 will take one cycle on most.

Is ">> 8" may be faster?

Regards, Olivier

---

From: Dominik Vogt <[email-masked]>
Date: Fri, 9 Aug 2002 11:01:32 +0200

> > /257 will take ages on any processor, /256 will take one cycle on most.

As it requires only a shift operation instead of a division it's
definitely faster.

Bye

Dominik ^_^  ^_^

 --
Dominik Vogt, mail: [email-masked], phone: 0721/91374-382
Schlund + Partner AG, Erbprinzenstr. 4-12, D-76133 Karlsruhe
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Tim Phipps <[email-masked]>
Date: Fri, 09 Aug 2002 11:27:19 +0100

>unification-wise 257 is better.
OK, I see. Multiplying by 257 is OK anyway since the compiler should 
spit out a shift-or sequence but the conversion from 16 bit to 8 bit 
should be a shift (or /256 which the compiler will change to a shift).

Cheers,
Tim.