Saturday, September 11, 2010

Signs of (Road) Life

Even along the highways of the not-so-fast Indian road traffic, there can be seen quite a few imaginatively worded signs reminding drivers and riders of the speed limit and some interestingly worded cautions.

As an aside, consider why we even have these signs along the highway? I don't contend with the message of these signs but their placement. The only people who are moving slowly enough to read these signs sure don't need to read them. Not to mention that reading these signs may in fact may cause accidents (wonder why you don't see "Do Not Read Signs While Driving" signs...)
The only guys that these signs are directed at are traveling at close to warp speed anyway. So why even bother?
Perhaps the Highway Authority thinks that, on the off-chance that there is a traffic jam on the highway, these "speeders", who probably have low respect for authority and even lesser respect for anything "the man" might care to put up on a sign, might chance a glance upon them and suddenly and forever be changed?

Maybe these signs were put up so that whoever put these up can say that they tried?

Included below are the signs that I managed to capture on my way from Chennai to Bangalore (or Bengaluru). I humbly apologize for the low quality of these images beforehand. On my defense, I took these photos using a digital camera (Sony DSC HX-1) while traveling on a fast moving car, looking out through tinted windows and on an overcast day. Most of these shots were taken at dawn, dusk and at night.
Finally, after much-ado:





























For the above shots, I used the Manual mode and had to keep the ISO low and jiggle the shutter speed and aperture values so that the shots don't look grainy and, most importantly, avoid motion-blur.

And now for something somewhat different.
In the pitch black of the night, the limitations of the digital camera were becoming quite obvious. The heavy rain pouring down didn't help either. So I gave up with keeping the shutter speed high and dialed it way down low (1 to 5 secs) just for the hell of it. This resulted in quite an unexpected light-show and I was quite impressed with the results:




Wednesday, July 08, 2009

Enforcing a minimum of one check mark

Good evening, ladies and gentlemen. Here's a little code I tossed off recently in the Computer:

So, here's how I made sure that at least one check box remains checked in one of my forms. A quick search didn't turn out any vb.net samples for doing this, so here is my version so that I will have a source of copy-paste the next time I google :P

Private Sub dlgViewImageHistogram_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  chkRed.AutoCheck = False
  chkGreen.AutoCheck = False
  chkBlue.AutoCheck = False
  chkIntensity.AutoCheck = False
  chkIntensity.Checked = True
End Sub

Private Sub checkColor_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
chkRed.Click, chkGreen.Click, chkBlue.Click, chkIntensity.Click
  Dim checkCount As Integer
  For Each chkBox As Control In pnlChannels.Controls
    If Not TypeOf chkBox Is CheckBox Then Continue For
    checkCount = IIf(CType(chkBox, CheckBox).Checked, checkCount + 1, checkCount)
  Next

  If checkCount = 1 And sender.checked = True Then
    Exit Sub
  Else
    sender.checked = Not sender.checked
  End If

End Sub


Basically, you need to set the AutoCheck property of the checkboxes to 'false' to take over control of the setting of the 'Checked' property.
Also, make sure that you have at least one check box checked. I have put all the checkboxes in a Panel control. Maybe there's a better way of grouping the check boxes, but I haven't read up on it.

Monday, June 29, 2009

Bitmap cloning is not Bitmap cloning

Almost 7 years ago, I had a pet project called 'PBrush', a small paint program created in VB 6. It was where I experimented with implementing the Undo/Redo features, image processing (emboss/invert/edge-detection, etc) in addition to the standard tools found in MSPaint.
I lost the project files when my first RAID-0 array broke and I've forgotten about it since then. (Since then I don't keep my project files on a raid-0 array.)

So, here I am today trying to get back in touch with VB.net after quite some time working in the Java/JSP platform and out of nowhere, I am reminded of the old PBrush project of mine. Not surprising really, since I had the most fun working on that project, ya know, trying different things with pixels and coming up with names for them :) Good times.

So anyway, I downloaded VB.net 2008 express edition and began coding about a few days ago in my spare times. I've already got a couple of kernel-based filters for edge-detection (Sobel. Scharr) coded down using basic loops for now. I heard directx methods will be faster for this, so I might try to re-write these functions.

For now, I am using a PictureBox for the main display and pass its Image property to my functions that will do the image processing. I had it all working in a day. But, as these filters are time-consuming, I noticed that the form would go to 'Not Responding' state after about 3 seconds of processing. This turns out to be caused by the form and its child controls staying "invalided" for too long. That is, the controls want to re-paint themselves, but can't because of the current thread is busy executing the image proessing routine.
First I tried the good old Application.doEvents()
Turns out that this method is old alright but certainly not "good". Some call for its timely death, even, and I can see their point. After adding this method call, my functions were taking about ten times more time to complete. Online documentations say that this is expected behaviour(!). Called 're-entrancy', this function halts any method that's been running, processes form messages and, get this, re-enters the function that it interupted.

Well, I said "no thank you. Don't come again" and started looking into putting the functions in separate threads instead.

Now, this is my first (not counting lab projects) project with threading. But it turns out that putting a function call into a separate thread is too easy. I used the BackgroundWorker class for doing this. Now, the functions work quite faster and the UI doesn't stay "invalidated" either. Seems perfect on the surface. But the devil is in the details, yes?

Yes. To better illustrate this point, let me give you a brief overview of the code.
So, I have a Picture box that holds the bitmap that needs processing. This control is also the one that is visible to the user, so it has to stay "validated". When an image filter is chosen by clicking on a menu item, I pass the Image object of the PictureBox to the appropriate function to be processed in the thread's DoWork method. Like so:

Dim bmpSrc as Bitmap
bmpSrc = pbMainDisplay.Image
e.Result = pdc.applyFilter(bmpSrc)


I noticed that "sometimes", when the BackgroundWorker is executing an image processing routine in the background, the Picture box will show a big red 'X' on it instead of the bitmap and an exception will be thrown stating "Bitmap region is already locked." on the line where I try to do a GetPixel().

I thought that it was simply a matter of adding a clone() method call on the Image property as this would create a new Image object instead of passing the reference to the Image. When this didn't work, I searched for every usage of the bitmap on the code and added the Clone() method call to it. Finally, when all the Image properties were adorned with the Clone() method, I ran the project again.... and met with the same problem, unchanged.

I looked up this issue online and found a similarly frustrated developer's blog entry on this. I gladly gave his method a try, like this:

Dim bmpSrc as Bitmap
bmpSrc = New Bitmap(pbMainDisplay.Image)
e.Result = pdc.applyFilter(taMain).Clone()


Unfortunately, this approach didn't work for me either.
Frustrated, I tried to either set the visibility of the Picture Box to false whenever the picture is being worked on by the background thread. But this would make the picture not visible to the user, which is ultimately not very "smooth".
So, for now, I have opted to intercept the paint events of the picture box and disallowing it whenever the background thread is busy, like so:


Private Sub pbMainDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbMainDisplay.Invalidated
If bwMain.IsBusy() Then
Exit Sub
End If
End Sub

It might be a workaround, but it's the only thing I've tried that works.


Update: 8th July, 2009

I have since moved the code that sets the Bitmap variable from the background worker's DoWork event to the method that calls the background worker instance's RunWorkerAsync() method, et voila, no stinkin workarounds required now.
It had been a matter of inter-thread chatter, I suppose, between the main application thread and the background worker.

Sunday, February 01, 2009

A bad case of upgraditis with a touch of Nehalem

The chronic (and costly) disease of upgradeitis has reared its ugly head again. And this time, it's the worst yet. The symptoms were all over the place, I just didn't realize it.

The Symptoms
It all started when my mouse finally decided to die on me. The shop-keeper said that my mouse is out of warranty period and there's no way of resurrecting my high-dpi pet. It had pined-for (and reached) the fjords. Fine, I said. It is time for a mouse upgrade anyway, I said. In the meanwhile, I am back to using my faltering old mouse.

I was researching (choices, choices) my next mouse when another peripheral, my Razer Barracuda HP-1 5.1 channel gaming headphones decided to act up and its front-left channel went silent, permanently. I was disgruntled at this and asked Razer web store for a refund instead of a replacement. I got my refund, but now I was without a high-end headphone pair. Fine, I said. It is time for a mouse upgrade and a high-end headphone pair upgrade, I said. In the meanwhile, I am back to using my old and so-so philips shp805 cans.

While all this was happening, I had noticed that my rig, especially after my new Dell 24" upgrade, was being brought to its knees by recent gaming titles. Playing at less than native resolutions and/or with decreased eye-candy might be an option for most, but not for me (of course, Crysis would be the one exception to this. For now.). This, of course, would entail upgrading the core system components, i.e., processor and video card.

My initial findings indicated that an upgrade to a quad core 45nm Penryn was the best upgrade path for now. But my current motherboard, the legendary Asus P5N32-E SLI, has iffy support for 45nm CPU s, and this of course calls for a motherboard upgrade, and possibly a memory upgrade, depending on the motherboard chipset or other factors as you will find out below.

Power Situation
Now there's another reason that enticed me to consider a motherboard upgrade, and that is the power consumption and, in-turn, the heat situation. The 680i chipset of nvidia that is in my motherboard is a sucker for watts and produces so much heat that I am still amazed that the solder hasn't melted and run off the motherboard. High power draw also decreases the UPS's on-battery time, which is made all the more important now because of the recent scheduled power-cuts happening all over Tamil Nadu. Another smaller issue is of the electricity bill. To give you a clue of why this may be a concern, take a look at the current system power draw as I type this blog post:
Free Image Hosting at www.ImageShack.us

All these reasons create a case against the current generation (65nm fabrication) mother board/CPU combination and the move toward a more recent (45nm) componentary. So, I had almost decided on the Intel Q9450 CPU on a P45/780i chipset, with the possibility of moving to a power-efficient DDR3 memory modules. And hence I went about trawling the inter-wibble for reviews on the various brands of the chipsetery. I had selected the CPU, but the choice of motherboard and memory was a lot tough to make. Inter-wibbling after a day of work, I took about a month's time looking around for the perfect deals or looking up on some fault or the other that someone in a forum would report regarding one of my components.
Many a times I had filled up the online shopping carts with a motherboard or a RAM module and come close to clicking on the checkout button. I have also asked most of the shops in Ritchie street for the best deals on the components. I heard that Intel was slashing the price of the CPUs. So I waited for that.

In the interim period of this waiting game did I hear of the arrival of Nehalem (pronounced NAH-HAY-LEM. Bet you didn't pronounce it that way till now. I wasn't either!) CPUs "next month". So I decided to wait some more. In the PC Hardware universe, or heck the entire electronics universe, those who wait will get better products at a better price, but at the price of owning an aged hardware that has also depreciated in resale value. And to live in India is to live a year in the past, as most electronic gadgetery is not deemed suitable for Indian consumption (unless at a heavy premium) until it's novelty has been well worn off in the rest of the World. But to heck with resale value, I decided to wait.

Fast-forward a couple of months, now I have committed to a Core i7 (920) CPU (previously codenamed Nehalem), a X58 chipset motherboard (MSI Eclipse) and 6GB of DDR3 low volt memory modules (G.skill 3x2GB 1600MHz 8-8-8-21 @1.6-1.65V PI-Black series). And about the ageing vide0 card that is my Geforce 8800GTX; it's predecessor will be a pre-SLI ed monster called GTX 295. Yep, after loathing SLI, mainly for its chance of not working in non-SLI-supported games and too much hot-air (literally) for non-linear performance gain (2 cards for around 150% perf increase), I am finally (and tentatively) getting on the SLI-bandwagon. Bring on the kool-aid.


Now, sharp readers might've noticed that the choice of a 130Watt TDP Core i7 processor and a bleeding-edge SLI graphics card are in direct opposition to the points I mentioned under Power Situation. But, the truth is that, because these are bleeding edge componentry, they have good power saving features that make them the very power efficient (i7 , especially, consumes lesser power than any contemporary quad-core processors out there) in IDLE state. Since my computer spends most of its time idly downloading torrents, this is the state in which it will spend most of its time. The LOAD power consumption, is, of course, is among the most power hungry of all. But I really don't care about this as the time spent in fully loaded condition is very small. You get the idea.


That leaves me with the Mouse and Headphones in my shopping list:

After my bad experience with headphones that only vibrate your noggin in the name of "bass", I am forever apprehensive of headphones with so-called "sub-woofers". I am currently researching on the subject of Headphones. Maybe, I could go for a "virtual surround" or Dolby Headphones. Still a lot to research on this subject so I will provide an update when I know more about the choices.

I am almost done with the mouse selection though. It could be the much revered game mouse, the Logitech MX518, or it could be the new champion Logitech G9. Or perhaps it could be the new-kid-on-the-block Microsoft Sidewinder mouse. Razer's DA, CH, Lachesis, etc are dead reptiles to me. While I ponder the choices, I also catch a glimpse of some great keyboards (mmm... MS Reclusa... Oooh, Razer Lycosa...). Come to think of it, I am kinda about the non-illuminated keys on my Microsoft Multimedia keyboard...

Monday, March 03, 2008

What is 24 inches, and grows on me?

...If you guessed that it is my new Dell 2407WFP-HC LCD monitor, you were spot-on. Otherwise, well, I am flattered ;)

It's been so long since I last blogged, so let me show you a few thousand words.
Here are some shots taken from my Motorola ROKR E6

Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com


I was, and still am to an extent, averse to upgrading to an LCD especially mostly because there is not one LCD monitor that can boast of the color reproduction, viewing angle, contrast or response time of a CRT monitor. Maybe, with the future SED (technically not an LCD), OLED or Laser monitors, this can change. But, at present, CRT monitors own LCDs.

In addition, my 2407WFP-HC monitor has inverse-ghosting issues. With a bit of tweaking the color controls of the monitor, I have minimized, but not eradicated this problem. I'll probably give a call to a dell rep sometime about this issue and try my luck with a replacement monitor. I am just post-poning that bit of hassle when I get really annoyed by that effect. So far, only Counter-Strike: Source suffers most from this ailment.

But, LCDs do have their own aces up their sleeve. The things that sold me were low power consumption and widescreen aspect ratio.


If you had asked me on Jan 1st 2008 what my resolution for this year will be, I would've probably said 1920x1200 :)
If you know your definitions and resolutions, 'Full High Definition' or 'Full HD' is 1920x1080 and the 2407 can go up to 1920x1200; Gaming in greater than HD resolutions is something else.

Here we go again with the pictures:
First, some night shots of my Ye Olde Samsung 997MB 19"(r.i.p) desktop for screen real-estate comparison.
Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com


And now, say hello to my new best friend:
Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com

Note the size of the iTunes player in the CRT and in the new screen. That's the difference and that's exactly what I wanted.

Here's something else I wanted too: Widescreen HD gaming. While lotsa real-estate can make any gamer giddy as a school girl, LCDs come with built-in "motion-blur" and in some cases, like mine, a bit of (inverse)ghosting. While free motion-blur may sound like a good thing, the effect gets real annoying real soon. But, once you get over these minor gripes, the extra viewport area really gets to you, in a good way.

Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com


Ofcourse, widescreen HD movies never looked this good in my old CRT. But, here are a few snaps from the really unworthy camera on my ROKR E6:

Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com Free Image Hosting at allyoucanupload.com


Where do I go from here? Unless I upgrade my video card (or go SLI, tri-SLI or quad-SLI), I guess I am stuck with 24" and lower screens. All the recent video cards released after the 8800GTX (which I have) make for a pathetic upgrade.
No, the only option left for me is to volt-mod this card and OC the hell out of it. I've made up my mind on this and I've already got all of the parts, at quite some cost as they had to be bought from an US store. It's just a matter of time, lots of it.

Monday, November 26, 2007

My weird associatives

It's been so long since I last posted. So here's a short come-back post:

I don't know how most people's mind works, so I cannot pretend (but I said it anyway :) ) and say that most of us have trouble with remembering some simple concept but can cope with some relatively complex concept. Try as you might, you may not be able to remember, say, stalagmite and stalagtite. You think you've got it after a few tries but, after a few days, you are scratching your head again.

I heard of one anecdote involving a sea captain who had such an, let's say, "affliction". It goes like this: This venerable old captain who is much feared and respected by his mates had a wierd habit of taking a walk on the, er, poop-deck every morn with a shoebox in his hand. He would not let anyone see what's inside his shoebox and would even deny the existence of it. But every morn he would take a walk and would look inside the shoebox as he walked. It seemed that whatever was in the shoebox was the most priced possession in his life.
But, one day, the cap'n dies and his mateys all storm his cabin to finally solve the mystery of what's in the shoebox. But to their great disappointment, they only find a piece of parchment that said in the captain's own handwriting:
Starboard = Right
Port = Left


I do not know if that little anecdote really happened, but I have my own "shoebox" of trivial things that I keep forgetting. For most of the things, I probably look up in a dictioinary. For a select few, I have a small associative-thing going on in my mind. Here are some of the words and the associated feeling/word I use to remember the word:

Apogee(farthest point in an orbit)----> loneliness->horror (Apogee was the company behind the "Duke Nukem" series - a space horror FPS)
Perigee(nearest point in an orbit)----> none (the opposite of apogee, probably. Which means that I have to remember apogee to know the meaning of Perigee!)

Accent Aigu( the french ´) ----> 'Aigu' sounds like "Eagle", and hence the symbol itself can be looked at as an eagle taking-off toward the sky (land to sky).
Accent grave( the french `)---> Basically, it's the eagle from "aigu" doing a plunge of death, and 'grave' means "deathly"(in english atleast). So you can see where this is going.

Roman numerals "VI, VII,VIII, XI, etc" ----> These are all 5+1, 5+2, 5+3, 10+1, etc. Basically, a large number (V, X) followed by a small number gets added.
Other numerals "IV, IX" -----> none (opposites of the above rule)


Ofcourse, there are quite a few more, I am sure. But I can't seem to remember them....