在智能機(jī)中,圖像處理多通過(guò)專有DSP進(jìn)行相關(guān)的編解碼。為了顯示圖像,需要對(duì)圖像進(jìn)行解碼,在智能終端中,具體的解碼過(guò)程通常都需要借助aDSP來(lái)實(shí)現(xiàn)。下圖所示為圖像的解碼過(guò)程。

圖像解碼過(guò)程
在Android中,圖像的解碼均是基于ImageDecoder基類的,為了進(jìn)行解碼,需要通過(guò)BitmapFactory:: decodeStream()方法對(duì)輸入流進(jìn)行處理。下面是BitmapFactory:: decodeStream()方法的實(shí)現(xiàn):
代碼5-10 BitmapFactory:: decodeStream()的實(shí)現(xiàn)
public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts)
{
if (is==null) {
return null;
}
if (!is.markSupported()) {
is=new BufferedInputStream(is, 16 * 1024);//創(chuàng)建一個(gè)緩沖
}
is.mark(1024);
Bitmap bm;
if (is instanceof AssetManager.AssetInputStream) {
return null;
} else {
try {
bm=new Bitmap(is); //進(jìn)行解碼
} catch (IOException e) {
return null;
}
}
return finishDecode(bm, outPadding, opts);
}
private static Bitmap finishDecode(Bitmap bm, Rect outPadding, Options opts) {
if (bm==null || opts==null) {
return bm;
}
final int density=opts.inDensity;
if (density==0) {
return bm;
}
bm.setDensity(density); //設(shè)置密度
final int targetDensity=opts.inTargetDensity;
if (targetDensity==0 || density==targetDensity
|| density==opts.inScreenDensity) {
return bm;
}
byte[] np=bm.getNinePatchChunk();
final boolean isNinePatch=false; //np != null && NinePatch.isNinePatchChunk(np);
if (opts.inScaled || isNinePatch) {
float scale=targetDensity / (float)density; //伸縮因子
final Bitmap oldBitmap=bm;
bm=Bitmap.createScaledBitmap(oldBitmap, (int) (bm.getWidth() * scale + 0.5f),(int) (bm.getHeight() * scale + 0.5f), true);//創(chuàng)建伸縮圖像
oldBitmap.recycle();
if (isNinePatch) {
bm.setNinePatchChunk(np);
}
bm.setDensity(targetDensity); //設(shè)置密度
}
return bm;
}
終的解碼工作則是通過(guò)SGL引擎來(lái)進(jìn)行的,關(guān)于SGL引擎的更多內(nèi)容,可以參考之前的免費(fèi)資Android Skia 渲染概述及Android Skia圖形渲染等內(nèi)容。