un vietnamien bien tranquille

aving a time to read some notable documents: The spy who loved us – Thomas Bass, and The perfect spy – Larry Berman. At first, I’d thought: oh, all these stories I’ve knew quite well already, there’s no need to read more. But then I considered it’s good to be reflective, reading the same stories in another language, from other points of view.

I’d read these two books (in English), which contains quite some interpreting errors (most of them are unintentional I think) then I proceeded to their Vietnamese translations (which are really bad, lots of linguistic mistakes), but again another reflections of reflections. All readings confirmed my understanding about the Vietnamese legendary intelligence agent Phạm Xuân Ẩn, whose role is now recognized as crucially decisive in the second IndoChina war.

Espionage and Journalism

As the first IndoChina war was approaching its end, the Việt Minh leaders knew that it’s just a matter of time before the American get their hands in. They had lived and fought with the French long enough that they had extensively well understanding on their enemy, the same is not true for the Americans. During the 9 years of the first IndoChina war, Ẩn had already worked against the French, under his cousin Phạm Xuân Giai, head of South Vietnam’s Cinquième Bureau – department for psychological warfare, who was working for the French’s Deuxième Bureau.

In 1957, Phạm Xuân Ẩn was ordered to go to the States, studying journalism (as a cover), learning their language, culture, their way of thinking… a preparation that later turned out to have devastating effects. During the time in America (and even long before), Ẩn has developed a sympathy (if not admiration) for American people and culture, and at the same time, touting his horns in a war to come against them.

These two professions were very contradictory, but also very similar. The intelligence job involves collecting information, analyzing it, and jealously keeping it secret, like a cat covering its droppings. The journalist, on the other hand, collects information, analyzes it, and then publishes it to the world. (Phạm Xuân Ẩn)

Information and disinformation

Upon coming back (1959), Ẩn worked for several presses: Việt Tấn Xã, Reuters, Time… Among all journalists in Saigon at the time, Ẩn is considered to be the best informants: new – comers introduced with him for guidances, seasoned ones seeked him for tips. He had various sources in the governments, army officers, secret polices… he had the best ears on the ground for everything. He is dubbed: “the weatherman” who foretell the political atmosphere, generals consulted him before planning coup d’état, the Buddhist monks informed him in advance if they prepare a protestant self – burning.

He made very good friend and closed cooperation with Edward Lansdale, head of IndoChina CIA division, the legendary agent nick – named: the king – maker, who manipulated every puppets on the Southern political stage, yet Lansdale had never doubted it. People was thinking he could be a CIA agent, a French sûreté, a South VN secret police, or he could be both. But none ever thought of him working for the Red NLF.

After the war, upon learning about the fact, some of his colleagues have tried to prove that Ẩn could had been giving disinformation at times. In fact, all his written records at the Time magazine (where he worked for 10 years) proved the opposite. Had he done it, with all the overwhelming clandestine agents among the presses, things could have easily been cross – checked and that would betray Ẩn, the espionage. And he of course hadn’t made those preliminary mistakes.

The source had given me the story on condition that I shouldn’t reveal it before it happened. These are the ethics of the press. You have to observe them, no matter how tough it may be. These are also the ethics of an intelligence agent who knows the propaganda value of burning monks. (Phạm Xuân Ẩn)

Balance and Objective

One thing Ẩn learned in American news career is that: a writing must be well – balanced, not biased in any directions, and at the same time it has to be objective, giving useful information to help coming to some helpful conclusions. Yet the two are usually contradictory. Similarly, questions have been raised about the nature of a man who lived an extremely dangerous double life for 30 years, about the one who deeply admires American culture but fiercefully fights against them.

In fact, Ẩn made true friend to many American journalists, help them in many cases, many of whom still love him even after learning that he was a spy. Many would recall how he saved the life of Robert Sam Anson, the war correspondent who was arrested by the VC in Cambodia. Ẩn came closest to getting discovered when he promised to Anson’s wife (who was begging for help) that he would do everything he could, a dangerous remark which implies he really could do something. Anson was later released as per request Ẩn made to his superiors, a truth Anson would only know for sure years later.

He was a man of wisdom, courage, and clear – headed patriotism. He was also – even if it seems ironic to say this under the circumstances – a man of extraordinary integrity. He loved us at our best even while confronting us at our worst. (Daniel Ellsberg)

Strategy and Tactic

A pattern in Ẩn’s stories, as usual, as an amusing raconteur: I’m a strategic analyst, I was concentrating on background information and situation assessment. Yet it’s a reason he gives in order not to get into too much details that he wouldn’t want to release even in the next 50 years: that’s related to too many people, many have died, but some still alive with their relatives, there’s no reason to cause harm to them anyway (Ẩn has always been loyal and protective to his information sources, from either sides, many of which is built upon personal relations).

But Western researchers found this an “undeniable fact”: he’s been awarded with 16 medals, among which 2 are general (one “Hero of the People’s Army” medal, the highest military award in VN, and another medal for “50 years of Party’s service”), the other 14 are all credited to specific battles, 4 of which is apparently known: the Ấp Bắc battle (1963), the Tết offensive (1968), the Lam Sơn 1972 operation, and the final 1975 campaign. That gives some obvious hints on his role as a tactical adviser who devised detailed tactics to be used in various battles.

He would have had enough knowledge of the battlefield tactics, rules of engagement, logistics and battle – readiness of both the Vietnamese and Americans in that area at that time to give pretty good advice on the way to set up a trap for them. Certainly Ấp Bắc had the hallmarks of a trap. (Nick Turner)

Nguyễn Văn Tào (nom de guerre: Tư Cang), head of the H.63 spy ring, direct ‘boss’ of Phạm Xuân Ẩn, famous for his ability of pistol shooting with both hands, and never miss a shot.

Phạm Xuân Ẩn (nom de guerre: Hai Trung), the strategic analyzer whose information, documents, assessments… greatly changed the pace of war.

Nguyễn Văn Thương (nom de guerre: Hai Thương), one of the couriers who run Ẩn’s messages. He was arrested, tortured, both his 2 legs were cut off six times, each without any narcotic. He could had saved his life, but he chose to save the network.

How could someone so voluble and open about his life be a spy? How could someone so funny and pointed in his remarks about human stupidity be a Communist? …He was a divided man of utter integrity, someone who lived a lie and always told the truth. (Thomas Bass)

The spy who loved us – Thomas Bass
(pdf.tar.gz) (mobi.tar.gz)

Perfect spy – Larry Berman
(pdf.tar.gz) (mobi.tar.gz)

Communists and Nationalists

This is the point of hatred conflicting among Vietnamese communities for so many years. My point of view, which is also reflected tho – throughly throughout the books (can be seen as 2 American views) is that: the communists, they had an ideologue (no matter right or wrong it could be), and they had determinations. On that basics, they’d had detailed planning and extensive efforts to carry it out, and they’d made sacrifices to carry it out to the end. The same is not true with the so called southerners’ nationalism.

As long as the Americans were pumping money in, the Southern government staffs were trying to steal as much as possible, and pretend to be supportive to the Americans’ causes while avoiding fights and casualties on the battle fields. They’d lost, as they presented nothing, not nationalists, not even anti – communists, but only their own personal and family’s interests. The consequence can be seen clearly: the majority of southern people took side, they have always been sympathetic to the Communists’ national independence causes, although they’re not communists.

Communism and Patriotism

It would eventually become clear why so many people have made extreme efforts and sacrifices, it was not because of any ideology. Of the total 43 members of the H.63 espionage network, 25 were captured, tortured, many of them chose to die, but the network remained unbroken. They were couriers, who in 15 continuous years, ran the total 498 messages (reports) from Phạm Xuân Ẩn to the Iron Triangle Củ Chi, from where it would be delivered directly to the Politburo in Hà Nội. Ẩn always kept an poison pill in his pocket, ready for a death that was hanging over him for those 15 years.

Many who survived the war found themselves disillusioned with the post – war living, finding that the new regime has become even more corrupted than the previous one, and that is not what they were fighting for. Yet they were fighting not for any individual, any ideology, any government… Many failed to realize it is patriotism in the truest and deepest meaning! Phạm Xuân Ẩn to the last year of his life, works as an consultant to TC2 (the Vietnamese equivalence of Deuxième Bureau), who doesn’t understand and doesn’t trust him, but badly need his razor – sharp analyses and assessments.

Lessons learnt

If something can be learnt from Phạm Xuân Ẩn’s life, it’s something about cultural understanding. While most VC has very limited knowledge about American culture and values, they’d succeeded in cultivating at least one spy who could think like an American, a spy who loved Americans and was loved by them in return. That way he can get deep into the adversary’s mind and soul, and know the way to defeat them.

It’s all about understanding, the French had stayed in Vietnam for a considerable amount of time, they’d learnt to divide and conquer the Vietnamese, a job they’d done excellently. It took a few generations to absorb their culture, to gain enough understanding to have successful retaliations. What the American had done in Vietnam to some extent was repeating things the French had done already, in a far larger scale.

Those above are indeed the small part of the lessons. Ẩn said: the American are very good at collecting and analyzing information, but they don’t know what to do with them (at least in scopes of the Vietnam war). Similarly, we can say: the Vietnamese know how to obtain a victory (or it supposes to be called so), but then they don’t know what to do with it. Phạm Xuân Ẩn in person is a talkative one, he can talk about his thinking all day.

But as a spy, a strategic analyzer, he is actually a very quite Vietnamese, who had much more profound thoughts and understanding but can’t say it out. Lots of our own problems are briefly reflected throughout the American books, but they’re not recognized tho – throughly by our own people… Things get passed silently in our sleeping – pleasing minds until another war, another revolution that is… just pending.

hoàn kiếm turtle

Ai đi về Bắc xin thăm hỏi,
Hồn cũ anh hùng đất Cổ Loa.
Hoàn Kiếm hồ xưa Linh Quy hỡi,
Bao giờ mang kiếm trả dân ta?

This could be the last living turtle in Hoàn Kiếm lake and among the lone 4 surviving individuals (2 in China and 2 in Vietnam). The specie is known to be the largest soft – shell turtle in the world.

In 1967, this turtle died (the body preserved at Ngọc Sơn temple), leaving the turtle above the last one. His post – mortem measures: 2.1 x 1.2 meter in size, 250 kg in weight, estimated age at 400 years.

ecently, there’s been much activities on protecting the last specimen of turtle living in Hoàn Kiếm lake. Preserving efforts are being taken place to: improve his living conditions and try to mate him with similar turtles in the hope of producing offspring. All Vietnamese was taught at elementary school legends behind this sacred Hoàn Kiếm turtle. And through out our history, the turtle appeared at crucial moments for not just one time… It’s the Golden Turtle who assisted King An Dương Vương in building the ancient citadel of Cổ Loa (~ 257 BC).

The turtle later helped the king in creating a multi – shot crossbow that destroyed the Northern invaders… In the last “known” advent, the Golden Turtle was sent to reclaim the Heaven’s Will Sword, which was given to Lê Lợi who carried out a 10 years resistance war and regained Vietnam’s independence. Much like King Arthur and his sword Excalibur, myths on a sword with super power sent to assist the hero is unlikely. However, the story’s moral is much more likely and profound indeed:

One year after winning, declaring independence and becoming the Emperor (1428 AD), Lê Lợi goes for boating on a lake near his palace. In the mist of the lake, the Golden Turtle appears, advances toward the boat and asks the emperor to return the sword. It suddenly became clear to Lê Lợi that the sword was only lent to him to carry out his duty, as a powerful weapon in war time, but it now must be returned to its owner, lest it would harm him and his country if misused as it’s not the appropriate tool in peace time.

Lê Lợi draws the sword out and hands it to the Golden Turtle, who grasps it with his mouth, then disappears into deep water. Aftermath, the lake was renamed Hoàn Kiếm, which means: lake of the Returned Sword (or Sword lake for short in spoken language), now at the center of Hà Nội, Việt Nam’s capital. Wise old men argue that if this only remaining sacred creature is going to die, then who would reclaim the hammer and sickle – ☭ ? 😀

the godfather

et everyone knows this film, and almost everyone loves it, I really like to watch it from time to time too: The GodFather. Of the three parts of the movie: I (1972), II (1974) and III (1990), the previous ones are more enjoyable in my opinion, hardly can something grow under the shadow of a big tree, and this is no exception.

I especially like the 1st part, it introduces fresh and detailed colors and sounds into the world of Italian and Sicilian: their songs, music, customs, relationships, language, personalities… Some scenes in the film have become classical and canonical metaphors for many situations in life. They are even using this movie as examples for lessons on running a business, some quotes from the film:

– Vito Corleone: I’m gonna make him an offer he can’t refuse.

– Tom Hagen: Your father wouldn’t want to hear this Sonny! This is business, not personal! – Sonny Corleone: They shoot my father and it’s business, my ass! – Tom Hagen: Even shooting your father was business, not personal, Sonny! – Sonny Corleone: Well, business is going to have to suffer then!

– Vito Corleone: [to Michael Corleone] Listen, whoever comes to you with this Barzini meeting, he’s the traitor. Don’t forget that. (I really like this wise idea too)

– Tessio: [to Tom Hagen] Tell Mike it was only business, I always liked him. – Tom Hagen: He understands that. – Tessio: Can you get me off the hook, Tom? For old times’ sake? – Tom Hagen: [shakes his head] Can’t do it, Sally.

– Michael Corleone: Just don’t tell me you’re innocent! It doesn’t make me angry, it insults my intelligence!

russian movies

ome recently seen (in the past few weeks) post – Soviet Russian war movies: Admiral (2008), Attack on Leningrad (2009) and Brest Fortress (2010). I can’t say anything rather than: marvelous! Both these three films should be on top of greatest war films, in many aspects: acting, costume and makeup, sound & music… comparable to any other war films ever made in the West. CGI (Computer Generated Imagery) is really good but maybe still a bit after that of Hollywood.

Russian cinema has made excellent advances, less propagandic, less rigid patterns, closer to real people in real life… that the things that made the films worth watching! In my opinion, of the series of three, the later the more interesting ones (though others may have their own different idea and evaluation).

Admiral (2008)

The films recites the life of Aleksandr Kolchak, admiral of the Russian Empire Navy. Kolchak himself was a complex character, living in a complex time: a famed Polar explorer, a valorous naval commander, a passionate lover, and eventually the Supreme Governor of the anti – communist White forces. No longer ruled by a dictatorial doctrine, Russia is now seeking to bring back true images of an extremely harsh period in her history.

The film starts with glorious feats of Kolchak commanding a destroyer in the Navy, his bravery in battles, his love affair with Anna Timiryova… and then the Red October came. Kolchak becomes the Supreme Ruler of the White Russia, who fought against the Bolshevik. Kolchak has far less success as a political leader than as a naval commander, he was finally arrested and executed by the Red. After decades of being vilified by the Soviet government, Kolchak is still now a controversial figure though there’re been rehabilitation movements to restore the place he deserves in Russian history.

Attack on Leningrad (2009)

An English journalist (of Russian origin) was trapped in the besieged city of Leningrad, the war correspondent Kate Davis was assumed dead but find herself among the starving people of the city struggling for their own survival. With the help of a kind and idealistic police women Nina Tsvetnova, they live through the 900 days in that sieged hell where food shortage only permits a ration of 125 gram of bread for each person a day. Encirclement around the city was almost completed, the only supply route through lake Ladoga was called the Road of Life (and also the Road of Death).

Nina Tsvetnova later guides a soldier group attempting to re – establish the supply route across the frozen surface of the lake. As a reward, she is permitted to bring members of her family out of the city. Nina along with the journalist take one child out with them. They succeeded but decide to return to help another child. Both two women died in the terrible city but saved two children out of the 1.5 million civil death toll, half of the city’s population.

Brest Fortress (2010)

Brest fortress was the strong hold which accounts for 5% of total Germany losses in the first phase of their Russia invasion. When German started the war, the Russian was unprepared, under – powered and defeated easily, their army was in all the way to retreat, except for this fortress. Defensed by a small unit, a regiment formation of soldiers along with their families, the fortress stands for almost a month when German has already advanced hundreds of miles into Soviet territory, leaving the point an isolated symbolically heroic fortification.

Yet they fight to the last man without any food, medical and ammunition supply, without any reinforcement. Alexander Akimov, a 15 year old young cadet of the fortress lived through the bloodshed resistance, trying to help other soldiers and his girlfriend Anya. He is the lone survivor to recall the story. The film is indeed beautiful: it concentrates on normal people, their daily lives and activities, their love, hate and humanly feelings… their choices and fates against the brutalities of war!

12 angry men

ne of the films I’ve really enjoyed recently, having some free times during the new year holiday to “re – master” some classics. Yes, it is truly a classical master – piece! Off 95 minutes of the picture, almost 90 min is spent in just a single room, with 12 men discussing, arguing, debating… There’s not even a single frame for flashbacks, visualizations or imagined scenes or such things, a 2 – hour continuous hard talk between 12 jurors of a trial’s jury, to decide in a murder case whether a boy is guilty or not.

Although some scenarios in the film are quite predictable, and some details are somewhat illogical (those that could hardly occur in real world), the fascinating part of the film is about the diversity of the jury board: 12 men from different backgrounds, ages, professions… different personalities, their logic systems, their value scales… and their prejudices. Some just doesn’t care, some is more or less “a yes man”, flipping sides at any times, some just want to kill the boy cause he grew up in slum, and slum is where crime was born…

Only one man has the braveness that leads him (and later the whole board) to the truth! The film gets to the core of the American juridical system, and helps explaining why the country has a strong democracy: democratic is built upon the votes (decision making) of a mass, it’s the quality, the responsibility of the mass that decide outcomes. The film also helps explaining why in some countries, dictatorship is the only thing that’s possible. That is, eventually, people get the ruling system, the kind of government they’ve wanted!

bánh chưng

ọi năm, đa số những đồ ăn Tết đều do trong nhà tự làm: bánh, mứt các loại, nem chả, rượu… ngày trước có những năm trong nhà tự làm đến cả chục loại bánh mứt khác nhau, hai ba loại rượu! Thật không có dịp nào để thể hiện khả năng DIY (Do It Yourself) như là dịp Tết!

Nhưng càng năm càng bớt dần, với tất cả mọi người, thời gian càng lúc càng ít lại. Thế nên Tết nhứt cũng bớt về số lượng, bớt luôn cả sự cầu kỳ, những năm gần đây thì chỉ còn làm tượng trưng vài loại. Nhưng cũng mất hẳn một ngày gói và nấu bánh chưng, bánh làm theo kiểu Huế, bé tí ti vừa đủ cho một người trong một lần ăn, kích cỡ mỗi cạnh vào khoảng 10 cm.

Ở Huế có những nhà thậm chí còn làm nhỏ hơn, chỉ khoảng 8cm. Có thể so sánh với cặp bánh chưng làm theo kích thước điển hình kiểu miền Bắc do nhà bên cạnh làm tặng (16 ~ 17 cm). Đem cặp bánh nhà làm tặng đáp lễ thì hẳn người ta sẽ ngạc nhiên phải biết! Bánh chưng làm kiểu miền Nam thậm chí còn có thể to hơn đến 20 ~ 22 cm.


The classical SVG example rendered using a thin OpenVG layer on top of OpenGL (or Quartz) on a Mac. This is also to say goodbye to the old Lunar year (year of the tiger) that is ending!

inished with my survey on vectorial graphics, in details, about rendering SVG using Quartz, OpenGL (ES) on Mac, iOS and some Android flatforms. I’d had the chances to systematize more my knowledge on vectorial: path, stroke, anti – aliasing, solid, gradient and pattern fill, etc… Todays, people’s all talking about 3D, OpenGL, DirectX, etc… While few mentions much about 2D stuffs, I’ve traced back some historical evolution paths, since I believe that it’s through history would we understand technologies.

In the beginning, there was… PostScript

It was John Warnock who kindled the idea, he joined Xerox in 1978 and an early version of PostScript (named InterPress) became the language to drive a laser printer. Laser printer was then a revolutionary device, which offers extraordinary graphics compared to the capability of dot or matrix printers. Warnock left and founded Adobe in 1982, the company that produced well – known graphics softwares including Illustrator, king of the vectorial editors.

Then there was DPS, PDF and Quartz

But it was Steve Job who realized the superiority of PostScript and urged John Warnock to popularize it. When Steve Jobs left Apple and started NeXT, he co – developed with Adobe DPS – Display PostScript, a derivative of PostScript – the language that drives the NeXT computer’s graphics system. When Steve has got back to Apple, DPS then evolved into what is now known as PDF, and Quartz is the C binding that bridges traditional Unix programmers to the Mac graphics world.

The X window system

The X’s designers also started with a PostScript RedBook in hand. But due to various reasons including the lack of in – depth consensus about vectorial, X maintains until now low level of PostScript support. The X server can only handle basic PostScript commands (it can’t even draw splines). X took a hybrid approach using both vectorial and raster – based solutions to the problem. Also the Unix root has an impact: X is the only true client/server windowing system to the current day.

Until now, the NeXT computer remains an idealistic symbol, pure vectorial remains a pursuit, perhaps for higher – standard devices, such as with this Backbone:

Backbone is an attempt (our attempt) at creating a Really Good Desktop. The metric we use for “Really Good” is our own. In short, to us, to carry on the NeXTSTEP® and OPENSTEP® spirit!

The Windows’ GDI

Born to be the youngest of all graphics systems, GDI learns nothing from it predecessors. Neither it is device and resolution independent (like Macs) nor a true client/server system (like X). GDI sticks to screen and the pixel unit with quite a lot implementation flaws. These flaws won’t become obvious until we come to serious editing, publishing and printing: text documents and graphics designs would never has the on – screen – display and printing qualities we would expect, though various 3rd party softwares would come to rescue somewhat the situations.

Then, things change with time

The 2D graphics systems on Mac, Windows, Unix… all has different origins, and all targets different real – world problem domains. All has hardware acceleration to various levels and qualities, and it’s hard to compare them in some cases. To the present day, no system is known to keep the original idealistic model that uses pure PostScript: X has been mixed from the beginning, Mac & iOS have switched to raster to some extent, GDI is essentially pixel – based. Then come the wind of change! It would be another story, another evolution path, but today, 3D hardwares has become quite popular with reasonable prices. It’s counter – intuitive to treat 2D as a separate part from 3D, and the trend is merging 2D to become a subset of 3D rendering. However, the process hasn’t been very easy, it would take some more time to reach maturity:

  • WPF (Windows Presentation Foundation): first came with Windows Vista, GDI now runs as part of DirectX 3D rendering environment. Vista was not a success indeed!

  • QuartzGL: Quartz2D runs on top of OpenGL since OS X 10.2 (Jaguar). However, QuartzGL is not enabled by default even in the current version (10.6 – Snow Leopard) since it’s still quite buggy.

  • GLX & AIGLX: both has some implementation problems and is competing to each other to become the official 3D extension for X.

Taken an arbitrary GDI’s API (such as MoveTo, LineTo…) we can see the parameters’ type is integer, which is in reality the pixel unit. The Quartz’s counterparts are always in float, a virtual unit so that the APIs can be device and resolution independent.
The so called “GDI printer” is actually a bitmap device, it lacks a PostScript interpreter and hence need to be attached to a computer to do the actual computing. Reason is obvious: cheapness, adding a PostScript interpreter would significantly raise the cost!

home servers

The C-Media usb board adds a cheap (~ $5) sound solution to the Debian box, sound quality is fair enough for “ad-hoc” listening (comparable to that of AC97 on-board chip, and for serious music, there’s already the home media player).

uite a long time it takes me to finish and “stabilize” all these “home servers”… and finally here it is… On the left, you can see: #1: the 650 Watt UPS that provides about 3 hours of un – interrupted electricity for the whole system, #2: the WAP54G Access Point (hacked with OpenWRT), #3: the Comtrend ADSL router, #4: the LinkStation CHL (Debian Lenny: print server, 1T disk space for samba share, bittorrent server), #5: the LinkStation Duo (Debian Lenny: 1T of RAID-1 disk space for important data, SVN, Web, VPN servers (for remote access) and MPD music servers), #6: speakers.

All these miniature machines help streaming lossless music and HD video to the media player (LT-H90LAN – another Linux box resides in the living room). Except for the router (which is specialized hardware & firmware OEM-ed by Comtrend to FPT – the local ISP), all others devices runs Debian or another Linux variant. The total power consumption of the whole system is less than 50 Watt. Future computers would consume less than 1/10th of power compared to today’s ones… Power is the key, less power means less heat, less noise, more stable and more durable… the factors that make successful home services!

polynomial texture mapping

The “specimen”, an oil painting of Bửu Chỉ, the prestigious Vietnamese painter.

The lighting vector (u, v, z) in the (x, y, z) coordination system as showed in the image above (the “right hand rule”): origin at center of the picture, x points to the right, y points upward and z points toward the camera.

Result: the (medical) infrared light source turned out to be a very bad choice

f you’re into computer graphics, you probably could have learned about normal mapping, bump mapping… Last week, a colleague told me about Polynomial Texture Mapping, then the experiment below was what I was doing as an exercise to learn about this PTM. In essence, PTM could produce extraordinary effects due to the fact that it makes use of many lighting data collected in real – world condition (check out some examples on the HP’s PTM page).

To make a PTM (using tools from HP Lab), you would need to photograph the “specimen” under many light directions, then combine all together in one “texture” (using PTMfitter) in which pixel values are computed from the collected data (polynomial function).

Input to the PTMfitter is a file listing images and their lighting vector (u, v, z). Note that (u, v, z) must be a normalized vector although PTMfitter only uses (u, v) at the moment. (Getting PTMfitter to run under Linux is quite tricky since it’s linked against an very out – dated version of libstdc++).

~/ptm/ptm_11a.jpg -0.894427191 0 0.447213595
~/ptm/ptm_12a.jpg -0.707106781 0 0.707106781
~/ptm/ptm_13a.jpg -0.447213595 0 0.894427191
~/ptm/ptm_14a.jpg 0.447213595 0 0.894427191

Output is the .ptm file that can be viewed with PTMviewer. The effect is really impressive, much more realistic than the normal, bump mapping usually seen. Let verify the difference, here is the .ptm and the .pl files, you would need to download PTMviewer from HP Lab (there’re versions for Wins, Linux and Mac).

We can also use PTM to create the DOF (Depth of Field) effect. The vector (u, v, z) in this case is not lighting direction anymore but the focus point the camera is shooting at. This technique is quite useful since DOF is very expensive to compute in graphics application, and this gonna be my next experiment!

buffalo duo

My Buffalo, a 400 MHz, power-efficient ARM system (it consumes about 17W on average). The duo: two SATA disks (1TB each) running in RAID-1 configuration. The system can also act as a print server: most cheap home laser printer are not stand-alone device (lacking PostScript capability) and need to be attached to a PC in order to print, instead we can connect printer to this Buffalo box via usb and serve printing over network.

y newest toy: a Buffalo LinkStation Duo Network Attached Storage (NAS – or a poor man’s home server). Had thought about this long ago but don’t have time till now to dig a little bit low-level to get the thing to work! Basically what I want to have is a miniature general-purpose home server, which would run continuously 24/7. But you know with the temperature and electricity conditions here in HCMC, most PC would surely break down if let running continuously for a few months. The idea is to hack this NAS device to run Debian and turn it into a hybrid system: NAS (file server, torrent, UPnP…) and a home server which would handle a little more extra tasks. I took me a whole night to figure out how to do it.

1.   Boot the device via tftp, using u-boot, the universal bootloader. We need to to erase the HDD’s partition table (with something like: dd if=/dev/zero of=/dev/sd[a/b] count=1) to force the device into tftp boot.

2.   Telnet to the device and prepare the disks: using fdisk to apply a same partition structure to both two disks (/dev/sda and /dev/sdb) with the usual Linux FS: /boot, /swap, /(root), and /data). The disk structure would appear like this:

Device Boot Start End Blocks Id System
/dev/sda1 1 6 48163 fd Linux raid
/dev/sda2 7 1200 9590805 fd Linux raid
/dev/sda4 1201 60801 478745032 85 Linux extended
/dev/sda5 1201 1329 1036161 82 Linux swap
/dev/sda6 1330 60801 477708808 fd Linux raid

3.   Setup the RAID-1 (one-to-one mirror) structure, you can see that we mirror /boot (sda1, sdb1), /(root) (sda2, sdb2), and /data (sda6, sdb6), there’s no need to mirror /swap:

mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/sda1 /dev/sdb1
mdadm –create /dev/md1 –level=1 –raid-devices=2 /dev/sda2 /dev/sdb2
mdadm –create /dev/md2 –level=1 –raid-devices=2 /dev/sda6 /dev/sdb6

4.   Install Debian (Lenny) using debootstrap, a very handy tool to install Debian directly from a repository. DeBootStrap pulls the packages over network, build a new rootfs, after chroot-ing to the newly build system, pull and build the kernel from source. After that, we can use regular Debian commands to update, configure network, add softwares, etc… After rebooting, we’d got a brand new Debian with 1TB of RAID-1 disk space, which runs flawlessly and which is ready to serve my various automation tasks!

Notes: installing Debian would void the warranty and could easily brick your device, use the information at your own risk. The steps here are just summary, there’s been various try and fail to get the thing done, e.g: we need priorly to have binutils, wget, zlib and libssl binaries for debootstrap to work (download the deb files from Lenny’s repository, extract and copy over the Buffalo), after debootstrap-ing, I forgot to set the root password, and unable to login when the machine reboot, thus having to start the whole process over again 🙁 . For further details, please consult the Buffalo NAS community.

UPDATE, Nov 18th, 2010

For a NAS which runs 24/7, it’s critical to monitor system status (temperature and the moving parts). I wrote this little fand script, a daemon to monitor hard disk temperature and adjust the fan’s speed accordingly. HDD’s temperature can be retrieved using smartmontools (most hard disk nowadays has S.M.A.R.T capabilities). And fan control on Buffalo LS Duo is done via the gpio module (thanks to talent hackers on the Buffalo NAS forum), something like this:

# values can be ‘off’, ‘slow’, ‘fast’ and ‘full’
$ echo ‘slow’ > /proc/linkstation/gpio/fan

I’ve defined some thresholds, in a tropical country like VN, room temperature around 30° ~ 35° (Celsius) is a common thing, so if the HDD’s temperature is below 35°, we would turn off the fan. If it is between 35° ~ 40°, the fan speed would be ‘slow’, from 40° to 45°, the fan will be turned to ‘fast’, and if temperature excesses 45°, fan speed is set to ‘full’. Well, and even if 50° is reached, we would send a notification email (via sendmail) and shutdown the system. If you find it interesting, here is the fand scripts.

UPDATE, Nov 20th, 2010 (THE REAL DUO)

To pair with the Link-Station NAS is its cousin also from Buffalo, the Link-Theater LT-H90LAN. The LT-H90LAN reads media from Samba shares or DLNA server via LAN and is a 720p and 1080i HD-ready device. Although not Full-HD (1080p), that’s enough for my need (I don’t have a Full-HD TV in my house anyhow, maybe I’m waiting for 3D home video). It’s quite pleasing to enjoy good video quality and excellent audio in your living room, all streaming from a central NAS. The box also runs a variant of Linux (though hacking can be a pain, I would only left the device untouched for safe). This is one further step toward an all-Linux-devices home (thought I should buy an OpenMoko phone then).