Pages

January 30, 2006

Pixels and Bit Twiddling, pt 1

I was discussing bit manipulation with somebody and it reminded me of one of my single favorite pixel munging routines. I've purposely omitted the NAME of the function - but its pretty cool ("One from the book", as Paul Erdos might say). And this one was really originally written (meaning he showed me the trick first) by the prime "PixelBoy" himself, Ben Weiss.

inline uint32 FUNCTION_NAME_OMITTED (uint32 a, uint32 b, uint32 mask=0x01010100)
{
uint32 s = (a + b);
uint32 c = (a ^ b ^ s) & mask;
return (s-c) (c-(c>>8));
}

Any guesses as to what it does?

I'll give you a hint: its a 32 bit pixel operation, but doesn't preserve alpha in this case (if only you could access the carry bit from plain old C ... ).... Just decoding what this did taught me a LOT about graphics coding, back in the day.

9 comments:

Dossy Shiobara said...

Combining the value of two pixels, then doing an XOR of the two pixels then XORed by their sum and clamped at 0xFF for each RGB value using the bitwise and of the 24-bit 0x01010100 mask to pick up the carry bit.

Looks like some pixel blending algorithm that lightens one pixel by the value of another? Probably useful in 3D shading, or maybe old-school 2D sprite animation.

Boy, it's been years since I've done any pixel-manipulation work. Brings back memories ...

Sree Kotay said...

Hey, not bad - actually, you pretty much nailed it (but then overthought it :P).

Its a saturated add - it'll simply add two rgb values, but clamp the results of each "channel" (i.e. each byte, for the lower 3 bytes - as I mentioned, doesn't QUITE work for the alpha channel) to 255 - with no compares required...

Anonymous said...

After preparing for many long months, Kel'Thuzad and his Cult of the Damned finally struck the first blow by releasing the plague of undeath upon Lordaeron.wow goldworld of warcraft goldwow power levelbuy wow goldwow goldworld of warcraft goldwow power levelbuy wow gold Uther and his fellow paladins investigated the infected regions in the hope of finding a way to stop the plague. Despite their efforts,wow goldworld of warcraft goldwow power levelbuy wow goldEverQuest 2 goldEverQuest 2 platbuy eq2 goldeq2 plat the plague continued to spread and threatened to tear the Alliance apart. As the ranks of the undead swept across Lordaeron, Final Fantasy XI gilffxi gilbuy cheap ffxi gilMaple Story Mesosmaplestory MesosMaple Story mesoLOTRO GoldLOTR GoldTerenas' only son, Prince Arthas, took up the fight against the Scourge. Arthas succeeded in killing Kel'Thuzad, but even so,Lord of the Rings Online GoldEverQuest 2 goldEverQuest 2 platbuy eq2 goldeq2 platFinal Fantasy XI gilffxi gilbuy cheap ffxi gil the undead ranks swelled with every soldier that fell defending the land. Frustrated and stymied by the seemingly unstoppable enemy, Maple Story Mesosmaplestory MesosMaple Story mesoLOTRO GoldLOTR GoldLord of the Rings Online GoldEverQuest 2 goldEverQuest 2 platArthas took increasingly extreme steps to conquer them. Finally Arthas' comrades warned him that he was losing his hold on his humanity. buy eq2 goldeq2 platFinal Fantasy XI gilffxi gilbuy cheap ffxi gilMaple Story Mesosmaplestory MesosMaple Story mesoArthas' fear and resolve proved to be his ultimate undoing. He tracked the plague's source to Northrend, intending to end its threat forever. LOTRO GoldLOTR GoldLord of the Rings Online GoldSilkroad goldsilkroad online goldSRO goldInstead, Prince Arthas eventually fell prey to the Lich King's tremendous power. Believing that it would save his people, Lineage 1 adenabuy Lineage 1 adenaL1 adenaLineage 2 adenabuy Lineage II adenaL2 adenadofus kamasArthas took up the cursed runeblade, Frostmourne. kamas dofuseve online iskeve iskbuy eve iskLineage 1 adenabuy Lineage 1 adenaL1 adenaLineage 2 adenaThough the sword did grant him unfathomable power, it also stole his soul and transformed him into the greatest of the Lich King's death knights.buy Lineage II adenaL2 adenadofus kamaskamas dofusLineage 1 adenabuy Lineage 1 adenaL1 adena With his soul cast aside and his sanity shattered, Arthas led the Scourge against his own kingdom. Ultimately, Arthas murdered his own father, Lineage 2 adenabuy Lineage II adenaL2 adenaeve online iskeve iskbuy eve iskKing Terenas, and crushed Lordaeron under the Lich King's iron heel. maple story mesosmaplestory mesosmaple story mesohero online goldimvu creditskal geonknight goldlast chaos goldlineage adenalineage 2 adenalord of the rings goldlotro goldwow goldwow power levelingwow powerlevelingffxi gilwow gold

Anonymous said...


perde
izolasyon
havalandırma
havalandirma
Sohbet
iso 9001
iso 14001
Söndürme
yangın söndürme cihazları
yangın dolapları
yangın tüpü
izalasyon
ısıtma soğutma
isitma sogutma
Aspirator
Aspiratör
Vantilatör
sohbetim
turizm işletme belgesi
turizm belgesi
turizm yatırım belgesi
Chat
sohbet odası
sohbet sitesi
türkiye sohbet
tr sohbet
tüm türkiye sohbet
arkadaş sohbet
türkiye sohpet
kızlarla sohbet
kızlarla sohpet
muhabbet
muhappet
kızlarla çet
çet
türkiye çet
çet sohpet
mırç
mirç
türkiye mirc
mirc
muhabbet
Sohbet Sitesi
Chat
Sohpet
Yangın
yangın güvenlik
yangın söndürme sistemleri
yangın tüpü dolum
yangın merdiveni
yangın çıkış kapısı 
Hava Soğutma
Hücreli Aspiratörler
Fanlar
Radyal Körükler
Toz Toplama
Soğutma Kulesi
Klima Santraller
Malzeme Nakil Vantilatörleri
iso 14001
iso 14001
iso 22000
iso 22000
haccp belgesi
haccp belgesi
yabancı oturma izni
ikamet tezkeresi
yabancı çalışma izni
yabancı personel çalışma izni
yabancı çalışma izni
yabancı personel çalışma izni
ohsas 18001
ohsas 18001
iso belgesi
iso 9001 belgesi
ohsas belgesi
ISO 9001
Teşvik Belgesi
Çocuk Bezi
Hasta Bezi
Makyaj Malzemeleri
Makyaj Temizleme Mendili
Kişisel Bakım
kolonyalı mendil
Islak mendil
Dudak Koruyucu
Temizlik Ürünleri
Göz Kalemi
Diyet Ürünleri
Süper Site
driver
Güvenlik Kamerası
Islak Mendil
Kolonyalı Mendil
Kolonyalı Mendil
JoyTurk
driver ara
web tasarım
Güvenlik Kamerası
paketleme
Kamera
Kamera Kurulum
Tatil
Tatil Yerleri
Tatil Beldeleri
Perde
Perde Modelleri
Kamera
Epilasyon
Emlak
Yaşam
Tatil
Video
Cilt Bakımı
video
süper
perde
jaluzi perde
stor perde
dikey perde
perde modelleri
jaluzi perde
stor perde
dikey perde
perde modelleri
magazin
haberler
spor haberleri
video
eğitim
Giyim

Anonymous said...

[url=http://buy-aoc-gold.rgtrcredit.com/][color=#800080][b]Age Of Conan Gold [/b][/color][/url][url=http://www.aocsale.com/][color=#800080][b]Age Of Conan Gold [/b][/color][/url][url=http://www.buy-cheap-aoc-gold.com/][color=#800080][b]Age Of Conan Gold[/b][/color][/url][url=http://www.buy-cheap-aoc-gold.com/][color=#800080][b]buy age of conan gold [/b][/color][/url]
[url=http://www.aocsale.com/][color=#800080][b]buy age of conan gold[/b][/color][/url][url=http://buy-aoc-gold.rgtrcredit.com/][color=#800080][b]buy age of conan gold [/b][/color][/url][url=http://www.buyfastgold.com/][color=#800080][b]aoc gold [/b][/color][/url][url=http://buy-aoc-gold.hellgate-pd.com/][color=#800080][b]aoc gold [/b][/color][/url][url=http://www.buyfastgold.com/][color=#800080][b]aoc gold[/b][/color][/url]
[url=http://buy-aoc-gold.hellgate-pd.com/][color=#800080][b] buy aoc gold [/b][/color][/url][url=http://www.buyfastgold.com/][color=#800080][b] buy aoc gold[/b][/color][/url]


http://www.buyfastgold.com

http://www.buy-cheap-aoc-gold.com

http://www.aocsale.com

http://buy-aoc-gold.hellgate-pd.com

http://buy-aoc-gold.rgtrcredit.com



Age Of Conan Gold     Age Of Conan Gold       Age Of Conan Gold     buy age of conan gold  
buy age of conan gold   buy age of conan gold          aoc gold             aoc gold             aoc gold
 buy aoc gold      buy aoc gold

Anonymous said...

wow goldwow goldaoc goldwow gold cheap wow gold are all in gamelee.

Anonymous said...

world of warcraft goldbuy wow goldcheap wow goldwow power levelingwow powerlevelingwow levelingworld of warcraft goldbuy wow goldcheap wow goldwow power levelingwow powerlevelingbuy wow goldcheap wow goldwow power levelingwow powerlevelingEverQuest 2 goldeq2 platrunescape goldrunescape moneyEverQuest 2 goldeq2 platLOTRO GoldLOTR Goldlord of the ring goldMaple Story MesosMaple Story mesomaplestory Mesosmaplestory Mesosilkroad online goldLineage 1 adenaGranado Espada goldSilkroad goldbuy silkroad goldflyff penyabuy flyff goldflyff moneyfinal fantasy xi gilffxi gilEverQuest platbuy eq goldEverQuest goldeq plateq goldAge of Conan goldage of conan power levelingEverQuest platbuy eq goldEverQuest goldeq plateq goldrunescape goldrunescape moneyEverQuest 2 plateq2 platCity of Heroes influencecoh influenceCity of Villains infamyCOV infamylineage 1 adenalineage adenamaple Story mesosmaplestory mesosmaplestory mesoMaple Story mesopotbs doubloonragnarok zenyro zenyrappelz rupeerappelz goldstar wars galaxies creditsswg creditssilkroad goldsilk road goldsword of the new world vistales of pirates goldtibia moneyvanguard goldage of conan goldage of conan power levelingage of conan goldage of conan power levelingage of conan goldage of conan power levelingage of conan goldage of conan power levelingage of conan goldage of conan power levelingage of conan goldage of conan power levelingaoc goldaoc goldaoc goldaoc goldaoc power levelingaoc levelingage of conan power levelingAge of Conan goldaoc power levelingaoc levelingage of conan power levelingAge of Conan goldaoc power levelingbuy ffxi gilage conan goldbuy ffxi gilbuy ffxi gilbuy ffxi gilage conan goldage conan gold

Anonymous said...

腿部曲线杭州装饰
装潢公司
杭州搬家公司
杭州装饰公司
杭州家政公司
杭州空调维修
杭州装修公司
办公室装修
杭州空调维修
杭州厂房装修
杭州空调维修
杭州家装
写字楼装饰
杭州空调维修
装修公司
杭州中央空调维修
杭州开锁
杭州搬家
杭州装饰网
杭州空调销售
杭州办公室装修
杭州管道疏通
杭州家政
杭州装修
杭州水电维修
杭州装饰公司
杭州补漏公司
杭州室内装修
杭州格力中央空调销售
杭州搬家
杭州店面装修
杭州空调维修
杭州空调维修公司
杭州房屋装修
家政公司
杭州写字楼装修
杭州装饰
杭州家装公司
杭州空调维修网
杭州家政
杭州装修设计
杭州中央空调维修
杭州装饰公司
杭州开锁公司
杭州空调拆装
杭州装饰
杭州中央空调维修如何保持腿部健美

Anonymous said...

<a href=" http://seo.cuteseo.cn/" >搜索引擎优化</a>
<a href=" http://kangjie.cn/NewsInfo.asp?id=146" >木门</a>
<a href=" http://kangjie.cn/NewsInfo.asp?id=147" >推拉门</a>
<a href=" http://kangjie.cn/NewsInfo.asp?id=147" >推拉门</a>
<a href=" http://www.tongchuang2008.com/" >翻译公司</a>
<a href=" http://www.tongchuang2008.com/" >北京翻译公司</a>
<a href=" http://www.tongchuang2008.com/" >英语翻译</a>
<a href=" http://www.hdssw.com" >花店</a>
<a href=" http://www.cnnb315.com" >装修大学</a>


<a href="http://www.htsky168.com/" >短信猫</a>
<a href="http://www.bjksjy.cn/" >北京儿童医院</a>
<a href="http://www.bjksjy.cn/" >北京协和医院</a>
<a href="http://www.bjksjy.cn/" >北京同仁医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=184" >北京儿童医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=185" >北京协和医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=178" >北京同仁医院</a>

<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=196" >北京医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=194" >北京大学口腔医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=193" > 北京天坛医院 </a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=192" >北京空军总医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=191" >北京广安门医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=190" >中国人民解放军总医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=189" >北京大学第三医院 </a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=188" >北京阜外心血管病医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=187" >北京中医医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=186" >北京肿瘤医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=175" >北京积水潭医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=174" >北京安贞医院</a>
<a href="http://www.bjksjy.cn/mymy_menzhen.asp?id=173" >北京宣武医院 </a>

<a href="http://www.bqgl.cn " >北京租车</a>
<a href="http://www.bqgl.cn " >租车</a>
<a href="http://www.bqgl.cn " >汽车租凭</a>
<a href="http://www.bqgl.cn/index_gsjj.asp" >北京北汽国际旅行社</a>
<a href="http://www.bqgl.cn/index_xwzx.asp" >北京北汽国际旅行社</a>
<a href="http://www.bqgl.cn/index_cxzs.asp" >北京北汽国际旅行社</a>
<a href="http://www.bqgl.cn/index_sxlc.asp" >北京北汽国际旅行社</a>
<a href="http://www.bqgl.cn/index_zcbj.asp" >北京北汽国际旅行社</a>
<a href="http://www.bqgl.cn/index_fwkh.asp" >北京北汽国际旅行社</a>
<a href="http://www.bqgl.cn/liuyan/" >北京北汽国际旅行社</a>
<a href="http://www.bqgl.cn/index_lxwm.asp" >北京北汽国际旅行社</a>
<a href="http://www.bqgl.cn/index_lypd.asp" >北京北汽国际旅行社</a>

<a href="http://www.2dd88.cn " >江西二手车</a>
<a href="http://www.2dd88.cn " >南昌二手车</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%C4%CF%B2%FD%CA%D0" >南昌市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%BE%C5%BD%AD%CA%D0" >九江市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%BE%B0%B5%C2%D5%F2%CA%D0" >景德镇市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%C6%BC%CF%E7%CA%D0" >萍乡市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%D0%C2%D3%E0%CA%D0" >新余市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%C9%CF%C8%C4%CA%D0" >上饶市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%D3%A5%CC%B6%CA%D0" >鹰潭市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%BC%AA%B0%B2%CA%D0" >吉安市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%B8%D3%D6%DD%CA%D0" >赣州市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%B8%A7%D6%DD%CA%D0" >抚州市</a>
<a href="http://www.2dd88.cn/sell_car_search.asp?provice_shi=%D2%CB%B4%BA%CA%D0" >宜春市</a>
<a href="http://www.2dd88.cn/car_sell_add.asp" >我要卖车</a>
<a href="http://www.2dd88.cn/sell_car_list.asp" >我要买车</a>
<a href="http://www.2dd88.cn/school_car.asp" >驾车</a>
<a href="http://www.2dd88.cn/zl_car_list.asp" >租车</a>
<a href="http://www.2dd88.cn/news/" >资讯</a>
<a href="http://www.2dd88.cn/question.asp" >爱车问答</a>
<a href="http://www.2dd88.cn/pc/" >拼车</a>
<a href="http://www.2dd88.cn/mm/" >香车美女</a>
<a href="http://www.2dd88.cn/allcar.asp" >汽车品牌</a>