Monday, August 31, 2009

Some Important Laws Which Newton Forgot to State

Just for fun but I felt in my life that these laws always apply to me......with 100% efficiency. No chance of proving wrong these.

LAW OF QUEUE: If you change queues, the one you have left will start to move faster than the one you are in now.

**********

LAW OF TELEPHONE: When you dial a wrong number, you never get an engaged one.

**********

LAW OF MECHANICAL REPAIR : After your hands become coated with grease, your nose will begin to itch.

**********

LAW OF THE WORKSHOP: Any tool, when dropped, will roll to the least accessible corner.

**********

LAW OF THE ALIBI: If you tell the boss you were late for work because you had a flat tire, the next morning you will have a flat tire.

**********

BATH THEOREM: When the body is immersed in water, the telephone rings.

**********

LAW OF ENCOUNTERS: The probability of meeting someone you know increases when you are with someone you don't want to be seen with.

**********

LAW OF THE RESULT: When you try to prove to someone that a machine won't work, it will!

**********

LAW OF BIOMECHANICS: The severity of the itch is inversely proportional to the reach.

**********

THEATER RULE: People with the seats at the furthest from the aisle arrive last.

**********

LAW OF COFFEE: As soon as you sit down for a cup of hot coffee, your boss will ask you to do something which will last until the coffee is cold.

**********

Do they apply to u also....... ;)

Sunday, August 02, 2009

Real men program in C

A very good article on C. A quite good comparative study of various famous programming languages with C. This is an article from "Embedded.com" so the article is based around embedded systems. Here is this Real men program in C.

Hope you will enjoy it.

Wednesday, July 22, 2009

Exploring Intel processors for SIMD support

As we already know that there are various way to speed up the processes or applications by parallel operations like Single Instruction Multiple Data(SIMD), multithreading, pipelining, cache management etc. Here I tried to manage a list of specifying which Intel SIMD capability we can use as per processor specific. Although you can check this by using CPU-Z or playing with cpu_detect() function to read cpu-id.

MMX: Truly saying as in 2009, all current processors support MMX. It has 8 registers MM0-MM7 of 64 bit width. Just to maintain uniformity of blog, MMX support came with Intel® Pentium-MMX and from Pentium2 onwards every processors support it.

SSE: It was another big move in SIMD by having another 128 bit registers by Intel. It is good choice for Intel® Pentium3 and Intel® Pentium3m version.

SSE2:
Intel® Xeon®
Intel® Pentium4 (Willamette),
Intel® Pentium4m,
Intel® Pentium M,
Intel NetBurst-based CPUs (Pentium 4, Xeon, Celeron, Celeron D, Celeron M)
Intel Core-based CPUs (Core Duo, Core Solo)
Intel Core 2-based CPUs (Core 2 Duo, Core 2 Quad)
Intel Atom


SSE3:
Dual-Core Intel® Xeon® 70XX, 71XX, 50XX Series
Dual-Core Intel® Xeon® processor (ULV and LV) 1.66, 2.0, 2.16
Dual-Core Intel® Xeon® 2.8
Intel® Xeon® processors with SSE3 instruction set support
Intel® Core™ Duo
Intel® Core™ Solo
Intel® Pentium® dual-core processor T21XX, T20XX series
Intel® Pentium® processor Extreme Edition (but NOT Pentium 4 Extreme Edition)
Intel® Pentium® D
Intel® Pentium® 4 processors with SSE3 instruction set support (Since Prescott Versions)
Celeron 420, 430 and 440 and Celeron D
Intel Core 2 Quad edition
Atom


SSSE3:
Quad-Core Intel® Xeon® 73XX, 53XX, 32XX series
Dual-Core Intel® Xeon® 72XX, 53XX, 51XX, 30XX series
In tel® Core™ 2 Extreme 7XXX, 6XXX series
Intel® Core™ 2 Quad 6XXX series
Intel® Core™ 2 Duo 7XXX (except E7200), 6XXX, 5XXX, 4XXX series
Intel® Core™ 2 Solo 2XXX series
Intel® Pentium® dual-core processor E2XXX, T23XX series
Celeron 4xx Sequence Conroe-L
Celeron Dual Core E1200
Celeron M 500 series
Atom

SSE4.1:
Intel® Xeon® 74XX series
Quad-Core Intel® Xeon 54XX, 33XX series
Dual-Core Intel® Xeon 52XX, 31XX series
Intel® Core™ 2 Extreme 9XXX series
Intel® Core™ 2 Quad 9XXX series
Intel® Core™ 2 Duo 8XXX series
Intel® Core™ 2 Duo E7200 (Penryn )

SSE4.2:
Intel® Core™ i7 Processors (Nehalem)
Intel® Xeon® 55XX series

Now play with SIMD with different processors options available.

Tuesday, July 07, 2009

Banning Religious Names in Unholy things

One must say India is changing a lot nowadays.
Few days before the law Commission suggested repeal of Section 377 is not only major step taken recently, now the Goa government has banned all the liquor bars those are having any religious names.So those days are gone in Goa when after full day enjoyment in beaches, you think to hang out at Laxmi bar or St Anthony bar.


As per the news No cheer in God's name, Goa tells bar owners finance department has said: "No licensee having a licence for retail sale of India-made foreign liquor and country liquor and/or foreign liquor for consumption on premises shall carry out the business in the name and style which denotes any religious name." Even as per news opposition leader Manohar Parrikar said "God's name should be associated with good things. A bar is not a positive thing. Giving it god's name can hurt the sentiments of people. I don't think it is allowed anywhere in the country. The chances of unholy things happening in bars with holy names are high."

A big applause for Goa for doing this kinda work. I think this rule should apply to all over India not only Goa. If something is good and everybody accepting that, then why not apply everywhere.

Actually this news reminded me, one of my childhood memory. I guess many of adults who are almost of my age or more than me remember the "Laxmi Bomb". Remember at the time of "Diwali" we use this firecracker alot, Yea that one only.


Even I must say, "Laxmi" was very guaranteed crackers, very reliable, rare chance of spoiled one. Out of 10 boxes of crackers i used to buy 5 boxes of Laxmi (thinking 50% of sure success ;))



Around 2-3 years back I came to know that Government has banned that. Even I used to bring "Ganesh Bomb" also, that was also not available. Government banned all the crackers that has god or goddess name on it. The reason was I guess; the crackers had paper wrapped on it with name and image of god or goddess, so I should not describe what happened after explosion, I can only say it was really not religious things. I was very happy to hear that but at the same time my childhood mind was very disappointed after listening that news "What no Laxmi, no Ganesh........then what to buy, I dont have any faith on other bombs." ;)

Thursday, July 02, 2009

How to make DLL and DLL Application in Visual Studio

Dynamic Linking Library (DLL) has the following advantages:

1) Saves memory and reduces swapping. Many processes can use a single DLL simultaneously, sharing a single copy of the DLL in memory. In contrast, Windows must load a copy of the library code into memory for each application that is built with a static link library.

2) Saves disk space. Many applications can share a single copy of the DLL on disk. In contrast, each application built with a static link library has the library code linked into its executable image as a separate copy.

3) Upgrades to the DLL are easier. When the functions in a DLL change, the applications that use them do not need to be recompiled or relinked as long as the function arguments and return values do not change. In contrast, statically linked object code requires that the application be relinked when the functions change.

4) Provides after-market support. For example, a display driver DLL can be modified to support a display that was not available when the application was shipped.

5) Supports multi-language programs. Programs written in different programming languages can call the same DLL function as long as the programs follow the function's calling convention. The programs and the DLL function must be compatible in the following ways: the order in which the function expects its arguments to be pushed onto the stack, whether the function or the application is responsible for cleaning up the stack, and whether any arguments are passed in registers.

6)Eases the creation of international versions. By placing resources in a DLL, it is much easier to create international versions of an application. You can place the strings for each language version of your application in a separate resource DLL and have the different language versions load the appropriate resources.

A potential disadvantage to using DLLs is that the application is not self-contained; it depends on the existence of a separate DLL module.


With the use of dll's one application can use or perform multiple functionality by using multiple dll's. And another advantage is you dont have to give full code, just give applicxation .exe along with Library .dll and that 's enough to run the code.

To make an application by using dll, we need two different projects. One project will be Libarary for which we will make .dll and another will be appplication i.e. .exe file.

Ok let's start with Library project. Followings will be the steps:

1) Open visual studio and go to New Project. Choose "Win32 console project"
2) In application setting, choose DLL.


3) You will get 3 files in your project.
a) Dll_main.cpp b) stdafx.cpp and c) stdafx.h
you will also get some code already avaiable to those files. Just Keep it, those are required for compiler as an entry point to .dll



4) Now write your code or functions as usual only without main(). As main() will be in application project. Only thing is that the functions which will be avaialbe to applications, should to be exported. To export the function , you have to add "__declspec(dllexport)" before return type of function. I use define something like this

#define DLL_EXPORT __declspec(dllexport)

and header file will be


5) Other functions will be normal. no extra prefix. Just like I am using 'InsideHello()'in my DLL main.


6) Now go to project porpoety page, and to C/C++ section , and set "Not Using Precompiled Headers"



7) Now build the project, after successful build you will get ProjectName.lib and ProjectName.dll, so as for my case DLL_Lib.lib and DLL_Lib.dll. So you got your required .dll and .lib which we need for building application.

Now open new project for application. All settings will be normal as we do for usual .exe application.


and exported function of DLL_lib should be imported here by adding "__declspec(dllimport) " before return type of those function.


And now you have to add dependencies, for that go to property page and linker section and add as "input" the .llib file, for my case DLL_Lib.lib (which contain declarion of functions.)


And copy the .lib and .dll from the Library project in the folder where .sln is present of application project. That's it, now build the project, if build successful i.e. your application has taken .lib and .dll and can be used. So now for test, keep .exe application and .dll of lib anywhere, it will run properly.

Now if you want handle totally different functionality, by only one application, make diffrerent .dll's and use there functions in your application. just like i was testing, two .dll in one exe.both written separately, but later thought to use in one application.

Enjoy .dll applications now!!!!

Thursday, June 25, 2009

Back To Basics : YUV to RGB conversion (Color Space)

I know there are like hundreds of books and tutorials available which explain color space. But I also know that neither of those tutorials stop a new author to explain it again in different manner, more explanatory in more easy way, so nor Me.

I remember my first interview in video domain. I can still hear that voice.
"Ok tell me what will be the color if Y 128 and Cb and Cr are 0", I said "Gray"
"if Y is 0 and Cb and Cr are at 128 then color is ", I was not sure what to say....
"Ok all are in 128, so what will be color", I said "White" (It was my guess)

I must say that interviewer taught me a lot, At that time I was mostly working on understanding of H.264 standard. That was a hell work for me. So I was learning how to implement those algorithms but for basics of video thing I was just beginner.

ok, lets start the tutorial now.......

Color models are conversion formats from one model to another. There are RGB, YCbCr, YUV etc. RGB in formations comes though the capturing devices like cameras or scanners. RGB color space is generally used in computer graphics. And combination of these three colors will generate other colors like white, black, yellow, cyan etc.But in real world processing RGB model is not the efficient one. If each color represents with 8 bits/pixel than for RGB we need 24 bits/pixels. If we wish to modify intensity or color of one pixel, we have to read all three components, process it and then store back, NOT good in real time with processing wise as well as memory requirement wise. To solve that problem there are other color space/model which store the pixel information in intensity and color format, like using luma and two color difference which can be converted to RGB or from RGB to that formats. Most common is YUV format.

The basic equations for YUV are :
Y = 0.299R + 0.587G + 0.114B
U = 0.492 (B-Y)
U = 0.887 (R-Y)

and YUV to RGB are :
R = Y + 1.14V
G = Y - 0.395U - 0.581V
B = Y + 2.032U


RGB ranges 0 to 255 while Y has a range of 0 to 255, U ranges 0 to +/- 112 and V ranges 0 to +/-157. But these equations are generally scaled for better implementation in NTSC or PAL digital codec. And for 8 bit data YUV and RGB data are saturated between 0 to 255.

YCbCr is scaled and offset version of YUV model, where Y ranges 16-235, Cb and Cr ranges 16-240. But actually all saturated to 0-255 levels. Here are the equations:

Y = 0.257R + 0.504G + 0.098B + 16
Cb = -0.148R - 0.291G + 0.439B + 128
Cr = 0.439R - 0.368G - 0.071B +128

and YCbCr to RGB conversion equations are :
R = 1.164 (Y-16) + 1.596 (Cr-128)
G = 1.164 (Y-16) - 0.813 (Cr-128) - 0.391 (Cb - 128)
B = 1.164 (Y-16) + 2.018 (Cb- 128)

As per my interview Q & A I have to consider here to this YCbCr to RGB conversion. If you analyze properly YUV to RGB and YCbCR to RGB equations are almost the same. I simplified the equation for better to remember way for human being like me and specially should not be used in computer for implementation. (computer dont give interview ;))

Here is my approximate way for YCbCr to RGB conversion:

R = Y+ 1.5 (Cr-128)
G = Y - 0.8(Cr-128)
B = Y+ 2.0 (Cb-128)

Here is the table for color we will get with different value of YCbCr.

You dont have remember this table, just use above approximate equation and RGB Color Cube (shown below), you will have the answer in sec.



By the way, after these tutorial, here are my answers for previous questions.
1) what will be the color if Y 128 and Cb and Cr are 0 ? GREEN
2) If Y is 0 and Cb and Cr are at 128, what will be the color ? BLACK
3) All are in 128, so color will be ? WHITE

And this time 100% sure... :)

Sunday, June 14, 2009

Google Wave: A new way of Browsing

How many times you felt like you need multiple browsers to open various communication formats like 'email', 'chat', 'docs', 'blogs', 'youtube' etc. etc. while discussing with only one friend. You also might have thought Why I cant share all my docs in one place , so that everybody like my friend or team can see it and can discuss everything here at one browser in real time. Many times it happens to me like my friend tell me check this page or video or doc, he gives me link, I copy the link and open another browser and check it, sometimes link work and sometimes doesn't. Even if it works, he has to wait for me to finish reading it and come back to start discussion. Now while discussion we need to switch between the doc window and chat window multiple times, really frustrating........

Thanks to google that after few more months wait, this problem is going to resolved like forever. Google has launched the new open source product called 'Google Wave' . "Google Wave" is equal parts conversation and document, where people can communicate and work together with richly formatted text, photos, videos, maps, and more.



In a simple form Google Wave is nothing but a combination of gmail, gtalk, google docs, blogger, google map, video etc etc. truly saying a combo of all, and even I can say more than that. As it is open source product, so it is also a platform with a rich set of open APIs (google wave API )that allow developers to embed waves in other web services and to build extensions that work inside waves.



Google Wave has been designed by the founders of Where 2 Tech, a start-up acquired by Google to create a cutting-edge mapping service, which later became Google Maps. According to Lars Rasmussen "In Google Wave you create a wave and add people to it. Everyone on your wave can use richly formatted text, photos, gadgets, and even feeds from other sources on the web. They can insert a reply or edit the wave directly. It's concurrent rich-text editing, where you see on your screen nearly instantly what your fellow collaborators are typing in your wave. That means Google Wave is just as well suited for quick messages as for persistent content -- it allows for both collaboration and communication. You can also use "playback" to rewind the wave to see how it evolved."



It includes a rich text editor and other functions like desktop drag-and-drop (which, for example, lets you drag a set of photos right into a wave).



You can add person, chat with them, share videos, discuss about location all in real time.


As "Wave" has google wave extension so it means there are a numbers of applications available that can be used and there will be mutiple users available for interaction like playing online games such as sudoku, scramble, chess etc.


One more interesting thing is you have google map available there, so ask your friends to join for party and give the location in "Wave" using google map, get their reply immediately. Something like this.



Believe me there are a lot many other stuffs too, when you will use it , you will just say "Awesome". To know more about it, check my "Important links" sections at the last of this post.

PS: Google Wave is currently available in a developer preview as the APIs and product continue to evolve. Accounts on the developer sandbox will be given out to people intending to build with the Google Wave APIs prior to the public release.

So if you are developer and want to contribute, go get your "Wave" or wait for release mode for a few months. if you'd like to be notified when we launch Google Wave as a public product, you can sign up at here.

Important links:

1) Google Wave
2) Google Wave Developer Blog
3) Intoducing the Google Wave APIs
4) Google Wave Code Blog
5) About Google Wave
6) Google Wave: A Complete Guide
7) Google Wave Extensions: An Inside Look

Thursday, June 11, 2009

How to include YASM in Visual Studio 2005

Playing with SIMD or assembly is very enjoyable thing, you will love coding here. But believe me actual fun starts when you use on NASM or YASM to write assembly rather than working with IA32 inline (__Asm{...}) assembly development coding method. YASM has included some more features than NASM but the real issue with NASM is the limited debugging formats. Debugger available in NASM are for 'stabs'and 'dwarf2' only. If you work on visual studio than NASM no use. NASM will assemble the code but you can not debug the code. So the best choice is YASM.


YASM can be downloaded from here. YASM supports various output format and supports debug formats 'stabs', 'dwarf2' and 'CodeView (cv)' check this. So it can be included in Visual Studio 2005 for assembly/SIMD code development.

So today we will discuss about how to include YASM assembler in visual studio 2005 project. We will go step by step for better understanding. So here we goes:

1) Download the latest YASM.exe, if donwloaded Yasm executable binary is not named as yasm.exe; we have to rename it yasm.exe.

2) Go to directory "Program Files\Microsoft Visual Studio 8\VC\bin" where all VC related binaries are kept already and put yasm.exe into it.

3) Now you need file named as 'yasm.rules'. To get this, download latest source code of YASM. Actually you can build yasm.exe with this source project also, but I am not concern with that today . Now locate folder "\Mkfiles\vc8" in yasm folder, you will find 'yasm.rules' file there.

4) To use custom build tool of visual studio 2005, copy 'yasm.rules' file to "Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults".

5) Now simply write your assembly in a file added to your project with file extension '.asm'

6) To assemble a file with Yasm, select the Property Page for the file and the select Yasm Assembler in the Tool dialog entry. Then add following line to 'Misc' section in 'command line' menu of property page :-

Debug mode : yasm -f win32 -g cv8 -o "$(IntDir)\$(InputName)".obj "$(InputPath)"
Release Mode : yasm -f win32 -o "$(IntDir)\$(InputName)".obj "$(InputPath)"

Press Apply and you are done. Now enjoy SIMD/assembly with YASM in Visual studio 2005.
I hope, you will find this article useful.

Useful links:

1) YASM in Wiki
2) YASM Home page
3) Latest version for download
4) YASM Documentation
5) YASM in VS 2005

Sunday, June 07, 2009

Clip Signed Data To Arbitrary Unsigned Range in SIMD/Assembly

This post is again dedicated to Video domain. But I certainly can say there are various other applications too where we can use it.

Clipping is very simple algorithm as it name indicates, we clip our data to certain range. There will be High value and Low value. If data value is less than Low value, assign data to Low and if data value goes upper than High value assign data to High. something like this:

Clip(Data,Low,High) = if Data is less than Low then data = Low, else if Data is greater than High then data= High , else data = Data ------------(1)

In video domain, after IDCT operation we get signed data for pixel, which should be technically unsigned data type. Here we do clip operation for pixel data, and limit the data between unsigned data type range, and in normal situation pixel bit depth is 8 (i.e unsigned char). So equ. (1) becomes :


Clip(Data,0,255) =if Data is less than 0 then data = 0, else if Data is greater than 255 data= 255, else data = Data ------------------------(2)


But pixel bit-depth is not limited to 8. As I mentioned in my previous post "H264:How to do conversion from 8 bits to 14 bits bit depth support" under the label "Video", H.264 support till 14 bit bit-depth, when you don't want to compromise with quality, go for higher bit -depth. And here pixel data type will be 'unsigned short'. Now we have to modify the 'Clip' function for higher bit-depth. And this time it is not fixed to 8 and not even 14, rather it can vary from 8 to 14 depends upon the YUV input bit-depth for encoder and luma or chroma bit-depth information (bit_depth_luma_minus8 and bit_depth_chroma_minus8) from input H.264 coded video input for decoder. So lets do this clipping in generic form. And remember Low value will be 0 always only High value will change. So equ (2) modified as :

High = (1^Pixel_Bit_Depth)-1
Clip(Data, 0, High) = if Data is less than 0 then data = 0, else if Data is greater than High then data= High , else data = Data ------------------------(3)

There are other optimized ways too for equ.(3), but that's not my concern as of today. so moving ahead for SIMD/assembly (MMX/SSE/SSE2). Now how to achieve the same operation in assembly. Actually if bit-depth is 8 then there is a single instruction available in SIMD as :

packuswb Rx0, Rx0 ;Considered data is in Rx0 (mm/xmm) SIMD register (if pixel type is unsigned char)

or if Rx1 is '0' then

paddusb Rx0, Rx1

if you want to saturate for unsigned short then we have

paddusw Rx0, Rx1

But that is not our case, so we have to go by other way. As we have data type 'unsigned short ' and Max value will be (1^Pixel_Bit_Depth)-1 , So here we goes :

unsigned short High = (1^Pixel_Bit_Depth)-1
unsigned short Range = 0x8000;
unsigned short Low = 0x7FFF - High;
unsigned short MaxHigh = 0xFFFF - High;

movdqu Rx1, Range
movdqu Rx2, Low
movdqu Rx3, MaxHigh
paddw Rx0, Rx1
paddusw Rx0, Rx2 ;Add unsigned saturation with Low
psubusw Rx0, Rx3 ;Subtract unsigned saturation with MaxHigh


(Note above code instructions are for SSE2 but applied for MMX too, also I tried to wrote for one pixel data, to use SIMD advantage properly some data shuffling is required, here my intention was to give idea, not the complete code for cut n paste.)

Enjoy!!!!

Calvin Hobbes Math Atheist


A very good one from calvin and hobbes. I must say, you will enjoy it too.

I am posting it to share with you so that this religion will grow. ...
And FYI I am Math Atheist too.....

Wednesday, June 03, 2009

From Unreality Magzine...

I was just stumbling through various sites and got this article. And felt that I should shares with you. The article is named as :

The 10 Most Visually Stunning Movies of the Last 10 Years

According to Publisher these are the movies which change the way we view movies. These movies are visually unforgettable with their heavily loaded graphics magics.

And from video codec point of view also, the movies listed here are great test vectors for video compression encoder tools. Specially like 300, The Matrix Reloaded, Transformer.


Just check this article and see the movie list .... with some movie snaps...
If you didn't watch those...update your 'must watching movie' list.. ;)

And on this list ... I want to add some more movies like
1) The Lord Of The Rings
2) The Fountain (it is in my 'must watching movie' list, I saw it's trailer and that's awesome )

What's your views say........
Want to add some more movies ...

Thursday, May 28, 2009

White Tiger is Black...


One month back when I went to Crossword, just to feel fresh n happy. As I already told in my previous post library or book shops are my favorite place. And there is no other good place in Bangalore than Crossword. As soon as I entered there was bulk amount of one book only, lying everywhere, came under new arrival and also as Crossword recommended section. Why will not somebody recommend you the book, which has shortlisted for "Man Booker Prize". Yea I am talking about "The White Tiger", author Arvind Adiga.


And I got more anxious to read that too when my close friend bought that book. Final 2-3 days before I stole some time from my schedule and just yesterday I finished reading the novel. And I have only one sentence in review for this novel. And the sentence is: "What a ****** joke"

It is a story about Balram Halwai aka munna aka white Tigher aka Country Mouse aka Ashok Sharma born in a village, son of ricksaw puller. In his journey from working in Tea shop to Owner of Taxi Company having 26 Toyata Qualis, he started his life as servant ,then philosopher, then driver, then cook, then gardener, then murderer and then entrepreneur(as author says). He says all his story in seven night starting from Laxmangarh (berth place) to Bangalore (current location) to Wen Jiabao from Beijiing by writing a letter to him.

I really felt cheated after reading that book. I didn't like the concept at all. According to me author insulted India, it's culture, hindu gods and also at the same time he compared everything with China, what he wanted to show us I didn't get. Author pointed out all the problems we have in India. He even added corruption till president level...that's shame. I don't think for any kind of corruption/illegal work you have to go till president of India, our ministers are much capable for all those thing. Author shown how landlord in village behave with villagers or with their servants. He also told so many bad stuffs about Delhi, Gurgaon, it's hotels. Author did lots of research by going all those dark area in village and even dark side of Delhi kind of city. According to him all drives who work/drive car for rich people are highly dangerous, according to him, you should not trust a single driver in India. According to him, even if a good person become driver, the whole drive community will force him to convert into Bad one.


I feel nowadays everybody wants to gain fame or money by ripping off the band-aid of India. You write/show movie with all dirty stuff about India and you will become famous. It's upto you how much famous you want to see yourself, just show that deep India's bad stuff. And I request you Mr. Author don't tell a murderer an Entrepreneur, you are unknowingly increasing the Entrepreneur number in India I don't know by twice, thrice or 10 or 100 times from actual Entrepreneur number. Even I am thinking all actual Entrepreneur are now looking for new English word. And dear Mr. Author I do accept there are lot many problems in India, things should change but for all these good things, people should educate, they should read first. According to me even novel is a good source of knowledge, as I learned many things after I started reading novels but one thing is for sure Mr. Author this book is worst and I learned nothing from this . Your novel forced me to write a proper review on it. I will never ever recommend this book to anybody.


And one more thing Mr. Author, we Hindus have 36,000,000 gods, you know why? Because we count/treat every kind of species in this world as GODs, and one way or other almost all kind of creature in this world has it's own role in nature and we worship nature, it's not that Human has copyright to be treated as GOD.

Thursday, May 21, 2009

SSE2 Vs SSSE3

As you already know that I am a bit busy with learning intel SIMD like mmx, sse2 , ssse3 etc stuff. I am enjoying SIMD and playing with all these MMX, SSE versions.While working with SSSE3 after sse2 or sse3, I thought what is the advantage of SSSE3 over SSE2? Some people even ask me why there is not a dramatic change in performance after adding SSSE3. I knew the answer but thought to do some more R&D on it.

And here is my view....

I will start with some brief intro of SSE versions and also as I am in video field I will talk about integer operations only that will be my primary concern as of now.

SSE2 instructions are an extension of the SIMD introduced with the MMX technology and the SSE extensions.The key benefits of SSE2 are that both MMX ans SSE2 instructions can work on 8 XMM (128-bit, XMM0- XMM7) register along with the MMX registers (mm0-mm7), and that SSE instructions now support 64-bit floating-point values. So there was huge change between MMX and SSE2(or SSE). Now because of XMM registers instead of playing with 8 bytes, we can play 16 bytes simultaneously. So improving the performance just by double from the MMX assembly or 16 times from the C code. There are some instructions we are missing in MMX assembly which are present in SSE2 like paddsb/w, movapd,movupd, pshufw/d ,pavgb/w etc, which are very much helpful here in video compression.

While SSSE3 (Supplemental Streaming SIMD Extension 3) is an extension of SSE3 or I should say revision of SSE3. In SSE3(13 new instructions) the most notable change is the capability to work horizontally in a register, as opposed to the more or less strictly vertical operation of all previous SSE instructions. There are instructions to add and subtract the multiple values stored within a single register have been added. But note those are not for Integer operations only floating point, that's why I am talking about SSSE3.

SSSE3 contains 16 new discrete instructions over SSE3. Each can act on 64-bit MMX or 128-bit XMM registers. Therefore, Intel's manuals has 32 new instructions.The instructions are PSIGNB/W/D, PABSB/W/D, PALIGNR, PSHUFB, PMULHRSW, PMADDUBSW, PHSUBW/D, PHSUBSW, PHADDW/D and PHADDSW.So if you these, the processing block or registers are same as SSE2, no new registers.

By using SSSE3 the only advantage in video compression side integer operations is horizontally processing. So by SSSE3 we can add/subtract the data within the registers instead of adding or subtracting with other registers. So I feel SSSE3 only removes some overheads and save some cycles by using horizontal operations if your video code is having that kind of module like SAD, SSD and all, but there are be many places where transition from MMX to SSE2 gives huge improvement in performance but transition from SSE2 to SSSE3 may not give you even noticeable change. Even there will be lots of functions where SSSE3 will not be required over SSE2 in code. As to work vertically (between two registers) we sometimes do some data manipulations by padding 0's or by shuffling data between registers, and then process the data like addition/multiplication etc., those shuffling or padding are overheads that can be avoided here in SSSE3.

I guess we should not think that each next generation of SIMD will just magically double the performance of the code same like MMX to SSE/SSE2. Function module (like DCT, SAD etc.) and data fetching to those functions matters a lot to decide which SIMD we should use .... SSE2 or SSSE3 for better performance. So before converting any new code from SSE2 to SSSE3, just stop for a moment, have a close look on the module and then choose SSE2 Vs SSSE3.

Enjoy SIMD optimization.

Friday, April 17, 2009

NGVC (H.265) Is On The way

While the whole multimedia world trying very hard to become mature in H.264, the bestcompression video standard till today, the new baby is in under development phase and named as 'The Next Generation Video Coding' (NCVG). In 2005 it was started by VCEG as consideration to 'H.264+'. Then after study it changed to H.265 a brand new standard instead of an extension of H.264 as a long-term video coding standard. And now latest VCEG meeting it has came up as 'NGVC' project (next-generation video coding) with backward compatibility. It is expected to be finalized in 2009-2010.

The goal of this standardization will be as follows:

1. Coding efficiency:

* NGVC should be capable of providing a bit rate reduction of 50% at the same subjective quality

2. Complexity:

* NGVC should be capable of operating with a complexity ranging from 50% to 3 times H.264/MPEG-4 AVC High Profile.

* When operated at a complexity of 50% compared to H.264/MPEG-4 AVC High Profile, NGVC should provide a 25% bit rate savings compared to H.264/MPEG-4 AVC High Profile at equivalent subjective quality.

3. Applications:

* Low-delay interactive video communications
* Surveillance
* Streaming
* Broadcast
* Digital cinema and large-screen digital imagery
* Mobile video entertainment
* Storage-based video application (camcorders, camera phones, computer files, disc media, download-and-play, etc)


KTA (key technical area) is developed as the software platform, which uses JM11 as the baseline and continuously integrates promising coding tools. The tools adopted in KTA are listed as below:

* 2-D non-separable adaptive interpolation filter (AIF) [AD08]
* separable AIF [C-0219-E]
* directional AIF [AG21]
* motion compensation with 1/8-pel motion vectors [AD09]
* adaptive prediction error coding (APEC) in spatial and frequency domain [AD07]
* adaptive quantization matrix selection (AQMS) [AD06]
* competition-based scheme for motion vector selection and coding [AC06]
* mode-dependent transform customization for intra coding [AG11]

All these techniques improve the coding performance by multi-pass encoding.

The latest published KTA software is JM11.0KTA2.3 (download here ). Some new technologies have been adopted by KTA software since July 2008. Those KTA coding tools involve the following areas:

1. Architecture

Internal Bit Depth Increasing
Extended Block Size (or called Super-MacroBlock) (C123)

2. Transformation and Quantization

Mode-Dependent Directional Transform
Very Large Block Transform
Adaptive Prediction Error Coding
Improved Adaptive Quantization Matrix Selection
Rate-Distortion-Optimization Quantization (RDO-Q)
Adaptive QP

3. Entropy Coding

Parallel Entropy Coding

4. Adaptive Loop Filter

Block/Quadtree-based Adaptive Loop Filter (C181)

5. Motion Coding

Motion Vector Prediction Competition
One-eighth-sample Motion Vector Resolution

6. Inter-Prediction

Adaptive Interpolation Filters
Separable Adaptive Interpolation Filters
Directional Adaptive Interpolation Filters
Enhanced Adaptive Interpolation Filter
Enhanced Directional Adaptive Interpolation Filter
Fixed Directional Interpolation Filters
Special Filter Positions
High Precision Filters
Switched Interpolation Filters with Offsets

These are some related helpful links:

1) ITU-T SG16’s homepage
2) The latest version of KTA is JM11.0KTA2.3 (Download here) and the latest test conditions are specified in [AH10].
3) H265.net forum instead use this H.265.net (modifying after a valuable comment...thanks for rectifying me)


So be ready to see new fun in video coding.

Thursday, April 16, 2009

That's why I LOVE Google

It's really really great. As we all know it's election time for Lok Sabha in India. So as a citizen of India after waiting in queue for 3-4 times around 3 hours each time, I got my Electronic Voter Id Card too. Since today onwards voting has been started. But as I was not knowing my voting booth where I can go and cast my vote. I decided to do some googling and thought of , first I will have to search for 3-4 official site by google and then I have to search again on those sites to identify my voting booth kind of tedicious work.

So I gave in google this quote "voting booth in karnataka" for search . And I got the second result is Voting For Election 2009 . Ya this is the google database page. And it's really awesome. Here not only you can find your vooting booth id but also you can check your all personal details (if official site has updated it...as google took data from there) , Parliamentary constituency, last time parliamnet members, development data, latest election news.......etc etc. I just love it.The only issue is the listed city for personal details are less. The cities are Delhi, Bangalore, Kolkata, Mumbai, Nagpur, and Pune. Hey even though if you are not belonging to these cities other than your personal details you can check other informations.

So check this page and enjoy and do contribute to Election as it decides your fututre in one way or another.

Voting For Election 2009

Sunday, April 05, 2009

March-April Update (MMX Techonoly/NASM/YASM)

I see that my planned tasks are completely frozen from last one month. Many things happened in last month which stopped my scheduled work. I had to go out of town for 15 Days, when I came back there was huge amount of work in my office. Not only huge, the overall whole work is new for me. So I am not at all getting anytime for my blog. Actually I do find a little bit time to write blog but I dont have time to do my planned technical KEP as per scheduled. But the good thing is as I told earlier I doing some new things in work, at least that is satisfactory and I am enjoying there.

Presently I am working on MMX technology. I am quite busy in writing MMX assemblies. Basically it is SIMD (single instruction multiple data) technology where we use 64 bit 8 MMX registers (MM0-MM7) to process data. So if we have data of 'char' type so we can process 8 data simlataneously.There are various instructions which Pack or unpack multiple data and operations for 1 Quand Word(64 bit), 2 Double Word(32 bit), 4 Word(16 bit) or 8 Byte(8 bit) data depends upon how we handle the data.It's quite interesting.

Now for MMX instruction assemblies I am also learning the IA32 assembler, NASM (Netwide Assembler) and also YASM. The IA32 architecture is good but not sufficient as it will support only Intel architecture ( 80x86 assembler) and writing code as inline __asm {...} without using MACRO, repeat (loop) feature is highly tedious job. NASM is an 80x86 assembler designed for portability and modularity. It supports a range of object file formats, including Linux and NetBSD/FreeBSD a.out ,ELF , COFF , Microsoft 16-bit OBJ and Win32 . It will also output plain binary files. Its syntax is designed to be simple and easy to understand, similar to Intel’s but less complex. It supports Pentium , P6 , MMX , 3DNow! , SSE and SSE2 opcodes, and has macro capability.

While Yasm is a (mostly) BSD-licensed assembler that is designed from the ground up to allow for multiple assembler syntaxes to be supported (e.g. NASM, GNU AS, etc.) in addition to multiple output object formats and multiple instruction sets. Its modular architecture allows additional object formats, debug formats, and syntaxes to be added relatively easily. It has matched and exceeded NASM’s capabilities, incorporating features such as supporting the 64-bit AMD64 architecture, parsing GNU AS syntax, and generating STABS, DWARF2, and CodeView 8(Not availlable in NASM) debugging information.

so I will be a little bit busy for this month too I feel, then I will check my status and will reschedule my KEP.

Tuesday, March 10, 2009

Password Security

I just purchased this month (Feb)'Digit' magazine and started with the 'Editorial'. The article was based on previous month issue 'SECURITY' special. That issue had a article 'A forward you should ignore' which little bit explain How to hack Gmail passwords of others account. And unfortunately as of now the Digit Team has more than 1000 passwords of other people and their personal information those who tried to hack their own passwords or their close friends.They did a harmless data mining to those passwords and found various amusing ways and astonishing stupid ways people keep their passwords. Here are some poor ways people keep their passwords, so I am keeping it in Dont's.

Dont's:
1) password should not be 'password'
2) dont keep password which is easy to type like 'qwerty', '123456' or 'abcdefg'
3) We know that your phone number is unique one but anyone who has ever called you could potentially hack your account.
4) same rules apply for postal codes.
5) Celebrities names or any names are never good for passwords, so dont ever use 'iloveaamir', 'Johnloveyou', 'ram123' or 'michel1984'

Here are some of the ways you should do...
Do's:
1) Use alphanumeric and if possible use even punctuations.
2) Use combination of lower and upper cases.
3) Genrate some kind of rules for your passwords which can be changed periodically.
4) In addition to Rule of Passwords try to make rule for the particular site basis also. The beauty of this kind of rule is you dont have to remember lots of passwords, just remember the rule. Even if dont use the id for long time, you dont have to remember what password you used to have next time when you log in.
5) Even if you change your passwords frequently dont use only one passwords for all sites user id.

P.S.: Digit team found one very interesting password, that I cant resist to laugh after reading it 'iamloser'(millions of user, millions of mind)

And one more important thing....If a hacker really wants to hack your ID, you can do just NOTHING that's the fact ,but atleast dont convert naive to hacker.

Thursday, February 19, 2009

Streaming Media

I was stumbling with old 'Digit Achieves' and I got article which caught my eyes as it was named as 'Streaming Media'. So let's elaborate more on this.

As the Internet speed is getting better and better nowadays watching videos , listening songs online from the sites like youtube, google video, mp3air etc have also increased by the internet user, without knowing how it really works? I guess end user for any technology never care how does that system work but NOT everyone. So let's dig what happens actually when we play multimedia in our browser.

Define Streaming :

Streaming media is streaming video with sound. With streaming video or streaming media, a Web user does not have to wait to download a large file before seeing the video or hearing the sound. Instead, the media is sent in a continuous stream and is played as it arrives. The user needs a player, which is a special program that compresses and sends video data to the display and audio data to speakers. A player can be either an integral part of a browser or downloaded from the software maker's Web site.


The technology and protocols used for streaming are different from used for viewing web pages or for downloading files. It is the technique of continuous and steady digital data (audio/video/graphics) transfer as packet in real time from a data server through the Internet to user's computer. Media files can be played in browser by using any embedded plugins or any media player. Smoothness of media stream is based on internet speed. Different quality may be available for different internet speed connection like glitches in frame or no sound for slow speed connection.

Compression method for media file is essential feature which decide the seamless streaming. Lossy compression formats for audio like mp3, aac, WMA etc. and video formats like mpeg2, mpeg4, h.264, vc-1 etc are used for encoding and converting those large media files to smaller size with compromised quality and so we get .mov , .rm etc. files.

RealNetworks, QuickTime, Windows media and Macromedia Flash are the most popular streaming technologies and many broadcasters (data server providers) assume that the player plugins are already installed in viewer/listener browser.

Streaming methods :

So streaming technology this encompasses media content, the streaming server, plugins and codec software. Streaming is of two types – progressive and real time (live). In progressive streaming, the media file can be viewed or listened while the file is being downloaded. In the case of packet loss, re-retransmission of lost packets are possible. Media files streamed in progressive manner get stored temporarily in viewer's hard drive e.g. HTTP streaming. In the case of HTTP streaming a request for data remains open even after the data is received by the client, so that server can respond at any time.

In real-time streaming, media contents get downloaded temporarily to the user's computer and gives live broadcast of media contents which is entirely depends upon the internet connection speed user has otherwise transmission of media would break.

Media streaming can also be categories as 'on demand ' or 'live'. In the case of on demand, the media files are stored in server for a long period of time and can be transmitted based on user request while live streams are only available at particular time like live TV broadcast. But nowadays due to increase performance and lower cost of the technologies mostly HYBRID (live and latter on demand ) systems are more popular. So now while watching live cricket match , you can pause it and restart from the same place through on demand method.

Transmission Protocols:

For streaming the there are a lots of transmission protocols are available like Transmission Control Protocol (TCP), User Datagram Protocol (UDP), Real Time Streaming Protocol (RTSP) and Real Time Protocol (RTP). TCP provides guaranties for the transmission of every bit by giving reliable connection. However UDP is more preferable than TCP for providing continuous transmission of data rather than re-transmission of lost packets. Some glitches might observed while packet loss but that can be recovered or minimized by various error-correction techniques. RTSP and RTP are mostly used in internet for media transmission. These can be used for unicast (one to one communication) or multicast (one to many communication).

PS: For hands on streaming your own media files, just play with VLC player (my favorite one).

Here are some other useful links:

1)Streaming media
2)How Streaming Video and Audio Work
3)List of streaming media systems

Thursday, February 12, 2009

Bacics Of Linux

As per my last blog I had scheduled the first one week duration for "Basics Of Linux". And I am feeling good that I finished this even before the schedule. I read the book "Introduction to Unix" .The book was quite simple and good. It starts with 'History of Unix ' and then 'Unix structure' expalining in brief about kernel, file/directory structure. Afterwards while explaining about 'terminal' and sh/ksh/csh/bash etc , it slowly switched to unix/linux command.

Commands are pretty much categories like the first category is "Directory navigation and control" which explain the command like pwd, cd, ls etc including their options. next is "File maintenance" commands are cp, mv, chmod, chown etc and then "Display" like echo, cat, more, less, pg, head ,tail etc commands

Next category is 'System Resources & printing' commands are like df, du, ps, kill, who whereis, which, date etc. I didn't read 'printing' related commands, it felt redundant to me presently so I skipped that. After that 'Shells' start which continues with 'Test processing ' commands with regular expressions grep, sed, gawk and other useful commands cmp, diff, sort, wc, touch, file , tar etc. The book ends with Shell Programming for learning purpose. This explains shell scripts, parameters/variables, here documents and control commands if, do -while , switch, test etc.


Actually from last 4-5 months I am also using 'Ubuntu Hardy' in my laptop, so I was so called using linux but I was working in Windows manner by NOT at all using 'Terminal' except for enabling my bluetooth mouse by 'hidd --search' command.

Now for my advance course of Linux I am planning to read another unix book "Unix Systems Programming" which explains how to design and implement reliable UNIX software and through coverage of files, signals, semaphores, POSIX threads and client server communication. I dont know how far i can proceed... ;)

And as my next task is "Basics of DirectShow" so I will be back to my Vista. Let's see how things goes there...

Monday, February 09, 2009

Task Planned

In my previous blog "1st evening of Year 2009" I mentioned some tasks I planned to do this year, although after observing the number of tasks in the list some may say "it's insane to stretch these task to entire year"

I accept that but I also do believe that If you are going for long jump, you have to start with small steps. Lots of work are there in my real job and I am learning much there too, but I am gradually feeling that only counting the number of tasks I have to do is NOT sufficient. And I will be always busy in my job, actually they will keep me busy always that's what they give us compensation/salary.. :)

But I have to be quite serious, regular and more important sincere for success of my Knowledge Enhancement Program (KEP). And now I am feeling why deadline is very important in any work...(Generally I consider deadline is not a noun but is a Verb for employee "either the project will be died(Finished) by that time or employee...")

But I have to work in proper schedule time...kind of deadline. So I did some kind of time allotment for a few of my tasks. I will try to stick with this.

1) Basics of Linux -- One week
2) Basics of DirectShow -- One week
3) Advance Linux -- One week
4) YUV show project in DirectShow --Two week

Saturday, January 31, 2009

I am a HINDU

Sometimes back I got this in my mail and after reading this; I felt that I should shares this with others too. It's story but gives actual backbone thinking of Hinduism. It will take your few minutes but worth to spend it. There is no offense for any Religion, as every religion says the same things "God is everywhere "; only the way is different.


Four years ago, I was flying from JFK NY Airport to SFO to attend a meeting at Monterey, CA. An American girl was sitting on the right side, near window seat. It indeed was a long journey - it would take nearly seven hours!

I was surprised to see the young girl reading a Bible - unusual of young Americans! (Later I came to know that September 11 has changed mind-set of lot of US citizens. They suddenly turned religious, it seemed.)

After some time she smiled and we had few acquaintances talk. I told her that I am from India. Then suddenly the girl asked: 'What's your faith?'

'What?' I didn't understand the question.

'I mean, what's your religion? Are you a Christian? Or a Muslim?'

'No!' I replied, 'I am neither Christian nor Muslim'.

Apparently she appeared shocked to listen to that. 'Then who are you…?'

'I am a Hindu', I said.

She looked at me as if she is seeing a caged animal. She could not understand what I was talking about.

A common man in Europe or US know about Christianity and Islam, as they are the leading religions of the world today. But a Hindu, what?

I explained to her - I am born to a Hindu father and Hindu mother. Therefore, I am a Hindu by birth.

'Who is your prophet?' she asked.

'We don't have a prophet,' I replied.

'What's your Holy Book?'

'We don't have a single Holy Book, but we have hundreds and thousands of philosophical and sacred scriptures,' I replied.

'Oh, come on…at least tell me who is your God?' Girl said.

'What do you mean by that?' I asked.

'Like we have Yahweh and Muslims have Allah - don't you have a God?' Again girl asked me.

I thought for a moment. Muslims and Christians believe one God (Male God) who created the world and takes an interest in the humans who inhabit it. Her mind is conditioned with that kind of belief. According to her (or anybody who doesn't know about Hinduism), a religion need to have one Prophet, one Holy book and one God. The mind is so conditioned and rigidly narrowed down to such a notion that anything else is not acceptable. I understood her perception and concept about faith. You can't compare Hinduism with any of the present leading religions where you have to believe in one concept of god.


I tried to explain to her “You can believe in one god and you can be a Hindu. You may believe in multiple deities and still you can be a Hindu. What's more - you may not believe in god at all, still you can be a Hindu. An atheist can also be a Hindu.”

This sounded very crazy to her. She couldn't imagine a religion so unorganized, still surviving for thousands of years, even after onslaught from foreign forces.

'I don't understand…but it seems very interesting. Are you religious?' Girl asked.

What can I tell to this American girl? I thought. I said: “I do not go to temple regularly. I do not make any regular rituals. I have learned some of the rituals in my younger days. I still enjoy doing it sometimes.”

'Enjoy? Are you not afraid of God?'

'God is a friend. No- I am not afraid of God. Nobody has made any compulsions on me to perform these rituals regularly.'

She thought for a while and then asked: 'Have you ever thought of converting to any other religion?'

“Why should I? Even if I challenge some of the rituals and faith in Hinduism, nobody can convert me from Hinduism. Because, being a Hindu allows me to think independently and objectively, without conditioning… I remain as a Hindu never by force, but choice.” I told her .

I told her that Hinduism is not a religion, but a set of beliefs and practices. It is not a religion like Christianity or Islam because it is not founded by any one person or does not have an organized controlling body like the Church or the Order, I added. There is no institution or authority.

'So, you don't believe in God?' she wanted everything in black and white.

“I didn't say that. I do not discard the divine reality. Our scripture, or Sruthis or Smrithis - Vedas and Upanishads or the Gita - say God might be there or he might not be there. But we pray to that supreme abstract authority (Para Brahma) that is the creator of this universe.” I explained to her.

After few moments thought again girl asked me, 'Why can't you believe in one personal God?'

“We have a concept - abstract - not a personal god. The concept or notion of a personal God, hiding behind the clouds of secrecy, telling us irrational stories through few men whom he sends as messengers, demanding us to worship him or punish us, does not make sense. I don't think that God is as silly as an autocratic emperor who wants others to respect him or fear him.' I told her that such notions are just fancies of less educated human imagination and fallacies, adding that generally ethnic religious practitioners in Hinduism believe in personal gods. The entry level Hinduism has over-whelming superstitions too. The philosophical side of Hinduism negates all superstitions” I explained her a bit more.

'Good that you agree God might exist. You told that you pray. What is your prayer then?'

'Loka Samastha Sukino Bhavantu. Om Shanti, Shanti, Shanti,'

'Funny,' she laughed, 'What does it mean?'

“May all the beings in all the worlds be happy. Om Peace, Peace, Peace.”

“Hmm…very interesting. I want to learn more about this religion. It is so democratic, broad-minded and free…' she exclaimed.

'The fact is Hinduism is a religion of the individual, for the individual and by the individual with its roots in the Vedas and the Bhagavad-Gita. It is all about an individual approaching a personal God in an individual way according to his temperament and inner evolution - it is as simple as that.'

“How does anybody convert to Hinduism?”

“'Nobody can convert you to Hinduism, because it is not a religion, but a set of beliefs and practices. Everything is acceptable in Hinduism because there is no single authority or organization either to accept it or to reject it or to oppose it on behalf of Hinduism. If you look for meaning in life, don't look for it in religions; don't go from one cult to another or from one guru to the next.

For a real seeker, I told her, Bible itself gives guidelines when it says 'Kingdom of God is within you.' I reminded her of Christ's teaching about the love that we have for each other. That is where you can find the meaning of life. Loving each and every creation of the God is absolute and real. 'Isavasyam idam sarvam' Isam (the God) is present (inhabits) here everywhere - nothing exists separate from the God, because God is present everywhere. Respect every living being and non-living things as God. That's what Hinduism teaches you.

Hinduism is referred to as Sanathana Dharma, the eternal faith. It is based on the practice of Dharma, the code of life. The most important aspect of Hinduism is being truthful to oneself. Hinduism has no monopoly on ideas. It is open to all. Hindus believe in one God (not a personal one) expressed in different forms. For them, God is timeless and formless entity.

Ancestors of today's Hindus believe in eternal truths and cosmic laws and these truths are opened to anyone who seeks them. But there is a section of Hindus who are either superstitious or turned fanatic to make this an organized religion like others. The British coin the word 'Hindu' and considered it as a religion.

I said: 'Religions have become an MLM (multi-level-marketing) industry that has been trying to expand the market share by conversion. The biggest business in today's world is Spirituality. Hinduism is no exception…

And I am a Hindu because it doesn't condition my mind with any faith system............. '

Memories...

These are some photos taken by me from my Nokia 6535 mobile which has VGA camera. Old memories of my Post graduation days.




























Thursday, January 29, 2009

H264:How to do conversion from 8 bits to 14 bit support

There are lots of professional applications which require higher bit depth support like studio application, HD application. In H.264 out of 11 profiles there are 7 profiles which supports more than 8 bits bit depth starting from High10 which supports 10 bits bit depth. There are High 444 Predictive and some related profiles which support upto 14 bits. Anyway the conversion procedure wise both are pretty much same except the specific values.

One more things we should keep in mind that bit depth may be different for Luma and Chroma components(both Cb and Cr will be of same bit depth).

So here I am describing the process conversion of encoder/decoder for than 8 bits, lets say specific to 14 bits support. For simplification I am taking both Luma and Chomra compo nets are of equal bit depth of BitDepth =14.So for this case BitDepthY = BitDepthC = BitDepth.

Note:For standardization reason, before that you must support at least main profile.I will put corresponding equation with equation number from the standard version ITU-T Rec. H.264 (11/2007) .

1)Generally for pixel variables we use 'char', first thing is convert this to 'short'

2)Change all your variables related to pixel/samples for 'short' like arrays, pointers, file read , file write , memcpy etc.

3)Change your 'clip' functions for pixels according bit depth for both Luma and Chroma components.
Clip1Y( x ) = Clip3( 0, ( 1 << BitDepthY ) – 1, x ) (5-3)
Clip1C( x ) = Clip3( 0, ( 1 << BitDepthC ) – 1, x ) (5-4)

4)Now decoder has to know the bit depth of the pixels so it has to read 'bit_depth_luma_minus8 ' and 'bit_depth_chroma_minus8 ' in the SPS header. With these parameters find out 'BitDepthY ' and 'QpBdOffsetY ' and similarly for chroma components.
BitDepthY = 8 + bit_depth_luma_minus8 (7-2)
QpBdOffsetY = 6 * bit_depth_luma_minus8 (7-3)

And
BitDepthC = 8 + bit_depth_chroma_minus8 (7-4)
QpBdOffsetC = 6 * ( bit_depth_chroma_minus8 + residual_colour_transform_flag ) (7-5)

In the encoder side the 'bit_depth_luma_minus8 ' and 'bit_depth_chroma_minus8 ' should be send in the SPS header to .264 bitstream.

5)As now each sample has bit depth of BitDepthY for luma and BitDepthC for chroma components , the PCM samples of I_PCM should be accordingly modified.

6)For intra prediction DC prediction mode value will change according to BitDepth.
pred4x4L[ x, y ] = ( 1 << ( BitDepthY – 1 ) ) (8-52)
pred8x8L[ x, y ] = ( 1 << ( BitDepthY – 1 ) ) (8-96)
predL[ x, y ] = ( 1 << ( BitDepthY – 1 ) ), with x, y = 0..15 (8-123)

And as well as Chroma components
predC[ x + xO, y + yO ] = ( 1 << ( BitDepthC – 1 ) ), with x, y = 0..3. (8-139)
predC[ x + xO, y + yO ] = ( 1 << ( BitDepthC – 1 ) ), with x, y = 0..3. (8-142)
predC[ x + xO, y + yO ] = ( 1 << ( BitDepthC – 1 ) ), with x, y = 0..3. (8-145)

7)If you are using prediction weights then some work we have to do here also.
o0C = luma_offset_l0[ refIdxL0WP ] * ( 1 << ( BitDepthY – 8 ) ) (8-295)
o1C = luma_offset_l1[ refIdxL1WP ] * ( 1 << ( BitDepthY – 8 ) ) (8-296)

And for chroma components
o0C = chroma_offset_l0[ refIdxL0WP ][ iCbCr ] * ( 1 << ( BitDepthC – 8 ) ) (8-300)
o1C = chroma_offset_l1[ refIdxL1WP ][ iCbCr ] * ( 1 << ( BitDepthC – 8 ) ) (8-301)

8)As bit depth of pixels has changed so it will affect a lot to quantization.

1.'pic_init_qp_minus26' range will be now -(26 + QpBdOffsetY ) to +25, inclusive.

2.SliceQPY will be in the range of -QpBdOffsetY to +51, inclusive.
SliceQPY = 26 + pic_init_qp_minus26 + slice_qp_delta (7-28)

So if we have bit depth of 14 so our SliceQPY will be in the range of -36 to +51.

3.'mb_qp_delta' will be in the range of –( 26 + QpBdOffsetY / 2) to +( 25 + QpBdOffsetY / 2 )
The value of QPY is derived as
QPY = ( ( QPY,PREV + mb_qp_delta + 52 + 2 * QpBdOffsetY ) % ( 52 + QpBdOffsetY ) ) - QpBdOffsetY (7-35)

And the working QP for luma components will be QP'Y , which is derived as
QP'Y = QPY + QpBdOffsetY (7-36)

Remember QP quantisation parameter values QPY is always in the range of –QpBdOffsetY to 51, inclusive. QP quantisation parameter values QPC is always in the range of –QpBdOffsetC to 51, inclusive.

4.For the chroma quantization parameters the value of QPC is determined from the current value of QPY (NOT QP'Y)and the value of 'chroma_qp_index_offset' (for Cb) or 'second_chroma_qp_index_offset' (for Cr).

If the chroma component is the Cb component, qPOffset is
qPOffset = chroma_qp_index_offset (8-315)

Otherwise (the chroma component is the Cr component), qPOffset is
qPOffset = second_chroma_qp_index_offset (8-316)

The value of qPI for each chroma component is derived as
qPI = Clip3( –QpBdOffsetC, 51, QPY + qPOffset ) (8-317)

And QPC = Chroma Quantization table[qPI]

Finally
The value of QP'C for the chroma components will be
QP'C = QPC + QpBdOffsetC (8-318)

5.The variable qP for quantization wil be QP'Y for luma components and QP'C for chorma components.

9)The bit depth also affect in deblocking process.

1.For average quantization parameter qPav the qPp and qPq will be correspond to QPY for chromaEdgeFlag equal to 0 (luma components) and QPC for chromaEdgeFlag equal to 1 (choma components).

2.Threshold variables a and ß will vary as
If chromaEdgeFlag is equal to 0,
a = a' * (1 << ( BitDepthY – 8 ) ) (8-466)
ß = ß' * (1 << ( BitDepthY – 8 ) ) (8-467)

Otherwise (chromaEdgeFlag is equal to 1),
a = a' * (1 << ( BitDepthC – 8 ) ) (8-468)
ß = ß' * (1 << ( BitDepthC – 8 ) ) (8-469)

3.Threshold variable tC0 will vary as
If chromaEdgeFlag is equal to 0,
tC0 = t'C0 * (1 << ( BitDepthY – 8 ) ) (8-476)

Otherwise (chromaEdgeFlag is equal to 1),
tC0 = t'C0 * (1 << ( BitDepthC – 8 ) ) (8-477)

So now we are ready for professional applications with 14 bits bit depth support for higher quality and by providing best compression with the power of H.264.

Tip for the topic: As you changed all pixel related data types to 'short' to support mote than 8 bits bit depth, just check for input which has 8 bits bit depth only. Is your code working fine???

I guess you dont want two different code base for 8 bits and more than 8 bits.Think hard and think naturally...you definitely dont need two different code base... ;)