View Single Post
Old 04-16-2013, 06:19 PM   #167
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Quote:
Originally Posted by dimasic View Post
Lua's type conversion made me crazy. But when my code has made screenshot with its own colors, I suddenly noticed that the code is almost identical to the NuPogodi's code (after he made some corrections).

In resulting file the high and the low bits are still equal, so the tiny loss of contrast in highlights should be. But who cares?
Lua's type conversion ? ?
What type conversion ?
It is 8-bit clean strings.

If the high nibble == the low nibble (which it does) on reading from the frame buffer just divide the byte by 16 (right shift 4).
That gives 0 ... 15 right justified in the byte.

If the high nibble == 0 and data is in low nibble from you pbm file on writing, just duplicate the low for bits ( val + (val * 16)) in the byte to be written.

Not exactly brain surgery here - just simple math.
Even easier if using Lua 5.2 (which has bit ops) or your using the Lua 5.1 on the Kindles (just load the luabit library for bit ops).
knc1 is offline   Reply With Quote