B4A Library Jpeg library

Cameras on devices are getting higher in resolution but displaying those images is not possible owing to memory limitations on the device. This library can decode arbitrary areas of large images without having to read the entire image into memory.

Unfortunately this can be rather slow. One reason is because Jpegs are optimally compressed with variable length coding and so it is not possible to locate and "jump" to the required point in the file to begin decoding because this cannot be found without decompressing the entire file up to that point.

However the main reason this process can be slow is because versions of Android before 2.2 interpret the bytecodes of their programs at runtime. Versions 2.2 of Android and later have a Just In Time compiler that compiles the bytecodes to native code and, according to reports that I have read, provide a speed increase of 4 or 5 times. The CPUs used by typical Android devices are increasing in their processing speed which again should give a processing speed advantage to the most recent devices. So locating the spaceman's head in the demo takes about 7 seconds on my 600Mhz Android 2.1 phone and comes down to around one second on a 1Ghz Android 2.2 or later device.

EDIT :- Version 1.1 now posted. See post #22 for details.

Note that if you like to test it in rapid debug mode then you need to add #DebuggerForceStandardAssets: true to your project.
 

Attachments

  • Jpeg1.1.zip
    344 KB · Views: 1,830
Last edited by a moderator:

MarkoMylo

Member
Licensed User
Longtime User
I have problem when i use this library to load lot of parts of one big jpeg image (flags 100x100 from 1000x1000)

i need to create inputstream for every LoadJpegArea
for example:

In = File.OpenInput(File.DirRootExternal, "z.jpg")
bmp = jpg.LoadJpegArea(In,40,40,160,160)
In2 = File.OpenInput(File.DirRootExternal, "z.jpg")
bmp = jpg.LoadJpegArea(In2,40,40,160,160)
In3

etc etc
with every button press or imageview press or some other sub i need to open picture and to use another InputStream

this does not work:

In = File.OpenInput(File.DirRootExternal, "z.jpg")
bmp = jpg.LoadJpegArea(In,40,40,160,160)
bmp2 = jpg.LoadJpegArea(In,40,40,160,160)
iv1.SetBackgroundImage(bmp)
iv2.SetBackgroundImage(bmp2)

Same InputStream... give me some error!

PLEASE HELP!
 

Licht2002

Member
Licensed User
Longtime User
Thanks for this usefull libery.... it works great.

But ONE Question:

I capture a Bitmap from WebView -> i get a Bitmap:

' Now i store the Bitmap to Cache or Filesystem:
Dim out As OutputStream
out = File.OpenOutput(File.DirInternalCache, "picture.jpg", False)
bmp.WriteToStream(out, 100, "JPEG")
out.Close

Then i load it to "IN"
Dim In As InputStream
In = File.OpenInput(File.DirInternalCache,"picture.jpg")
bmp = jpg.LoadJpegArea(In,100,100,200,200)


Is it possible, to save the step "bmp.writeToStream" & "FileOpenInput" to handle the Bitmap directly in "jpg.Load"?

Thanks for your HELP

Sorry for my english.... i´m from Germany

Tom
 
Last edited:
Top