Log in

No account? Create an account
couldn't sleep - brad's life — LiveJournal [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

couldn't sleep [Jul. 26th, 2002|03:59 am]
Brad Fitzpatrick
I was stuck on something earlier so I decided to sleep on it.

I didn't make it that far .... I couldn't sleep and I figured out what I wanted to do, so I'm back on the computer.

Ever read the GIF spec? So trivial! Funny quotes like:
The logical screen width and height can both be larger than the physical display. How images larger than the physical display are handled is implementation dependent and can take advantage of hardware characteristics (e.g. Macintosh scrolling windows). Otherwise images can be clipped to the edges of the display.

Anyway, I solved what I set out to do... modifying the GIF palette on-the-fly as it leaves the webserver without using something dumb & heavy like ImageMagick decoding its entire raster data into memory first. It was fucking trivial: byte 10 has packed in it a color map flag and the color depth. the palette starts at byte 13 with r, g, b bytes for each entry.

What was bugging me earlier was that I was caring about caching modified versions of the GIFs on the server side, but then I got realizing the GIF spec is probably simple and it'd be less code/disk/stress to just "make it" on the fly all the time. I was thinking making it all the time would be heavy, but it's probably a hundred times lighter than all the db lookups I'd be doing to find the cached version. Rad.

Now to do the same for PNG, though I've skimmed some of that spec and it's a little more daunting. Like, I seem to recall different containers and those containers being checksummed? We'll see.

(or I could sleep......)

[User Picture]From: supersat
2002-07-26 04:20 am (UTC)
Sleep is for the week.

P.S. Be sure to suck this for all the BJs you can get.
(Reply) (Thread)
(Deleted comment)
[User Picture]From: supersat
2002-07-26 04:33 am (UTC)



I am tired.

However, I am not going to sleep.
(Reply) (Parent) (Thread)
[User Picture]From: firelegend
2002-07-26 06:54 am (UTC)
Do people use PNG's yet? My PNG's are HUGE, becaus I use fireworks, and a fireworks file *is* a PNG. It has layers and everything. I have never actually tried to export a compressed PNG, I suppose all the new browsers support it now.

Anways, very interesting entry.
(Reply) (Thread)
[User Picture]From: mart
2002-07-26 08:48 am (UTC)

People who get worked up about patents and freedom of information use PNG. Also, people who like alphatransparency use PNG. Everyone else still uses GIF, and where more colours are desired, JPEG.

(Reply) (Parent) (Thread)
From: evan
2002-07-26 09:00 am (UTC)
JPEG introduces artifacts, GIF is limited to 256 colors. PNG is good for high-color sharp images.
(Reply) (Parent) (Thread)
[User Picture]From: firelegend
2002-07-26 10:24 am (UTC)
lets all one-up each other with our knowledge of image compression :)

(Reply) (Parent) (Thread)
[User Picture]From: mart
2002-07-26 10:41 am (UTC)

I've seen people who still use JPEG at very low compression settings rather than using PNG. They are mostly designer-types who don't appreciate PNG yet. (Most likely, they've not noticed alpha-transparency and thus haven't jumped on the slow-rendering-transparent-junk bandwagon.)

(Reply) (Parent) (Thread)
From: evan
2002-07-26 10:51 am (UTC)


Well, that and IE 5.5 (?) doesn't support the full alpha channel. :(
(Reply) (Parent) (Thread)
[User Picture]From: jwz
2002-07-26 01:59 pm (UTC)
Now to do the same for PNG, though I've skimmed some of that spec and it's a little more daunting.

What? You mean a file format was invented within the last ten years that isn't built around XML and DTDs? Stop that crazy talk!

(Reply) (Thread)
[User Picture]From: brad
2002-07-26 02:54 pm (UTC)
I know. :-(

I loved working with GIF:

So easy!!

The inserted code in bold:

my $disk_file = FB::gpic_disk_file($g);
my $fh = Apache::File->new($disk_file);

if (%pal_colors) {
my $gifdata; # buffer for header & global palette table read($fh, $gifdata, 13+3*255);
while (my ($idx, $c) = each %pal_colors) {
substr($gifdata, 13+$idx*3+$_, 1) = chr($c->[$_]) for (0..2);

# just send the file $r->send_fd($fh);
return OK;
(Reply) (Parent) (Thread)
[User Picture]From: way2tired
2002-07-29 07:33 am (UTC)
Where did you find the specs?
(Reply) (Thread)