2008年12月24日 星期三

nano-X JPEG display problem

1.畫面顯示只有256色

Disable fast jpeg

include/device.h

#define FASTJPEG 0  /* =1 fot temp quick jpeg 8bpp*/

2.載入大檔案時 nano-X 結束.

# /tmp/nxview /phone/media/picture/DSC_0251.JPG
Improper call to JPEG library in state 202
nxclient: lost connection to Nano-X server

Trace之後發現是memory不夠了,malloc失敗.
之後nano-X操作jpeglib的程序有問題

engine/image_jpeg.c

int
GdDecodeJPEG(buffer_t * src, PMWIMAGEHDR pimage, PSD psd, MWBOOL fast_grayscale)
{
.....
.....
.....
    /* Step 5: Start decompressor */
    jpeg_start_decompress (&cinfo);

    /* Step 6: while (scan lines remain to be read) */
    while(cinfo.output_scanline < cinfo.output_height) {
        JSAMPROW rowptr[1];
        rowptr[0] = (JSAMPROW)(pimage->imagebits +
            cinfo.output_scanline * pimage->pitch);
        jpeg_read_scanlines (&cinfo, rowptr, 1);
    }
    ret = 1;
#if 1 /*Modify by Steve*/ <<--改到這裡就OK啦
  /* Step 7: Finish decompression */
  jpeg_finish_decompress (&cinfo);
#endif
err:
#if 0 /*Modify by Steve*/ <<--就是這裡囉
    /* Step 7: Finish decompression */
    jpeg_finish_decompress (&cinfo);
#endif
    /* Step 8: Release JPEG decompression object */
    jpeg_destroy_decompress (&cinfo);

    /* May want to check to see whether any corrupt-data
     * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
     */
    return ret;
}
#endif /* MW_FEATURE_IMAGES && defined(HAVE_JPEG_SUPPORT)*/

3.圖檔太大會因為memory不夠而無法顯示

解決方式是在jepglib decompress 時作 scaling

engine/image_jpeg.c

int
GdDecodeJPEG(buffer_t * src, PMWIMAGEHDR pimage, PSD psd, MWBOOL fast_grayscale)
{
.....
.....
.....

    jpeg_calc_output_dimensions(&cinfo);

#if 1
  int wfac, hfac, fac;
  wfac = cinfo.output_width / psd->xres;
  hfac = cinfo.output_height / psd->yres;
  fac = wfac;
  if(fac > hfac)
    fac = hfac;
  if(fac > 8) fac = 8;  /* 1/8 */
  else if(fac > 4)  fac = 4;  /* 1/4 */
  else if(fac > 2)  fac = 2;  /* 1/2 */
  else fac = 1; /*No scaling*/

  cinfo.scale_num = 1;
  cinfo.scale_denom = fac;
  cinfo.dct_method = JDCT_FASTEST;
  cinfo.do_fancy_upsampling = FALSE;

  jpeg_calc_output_dimensions(&cinfo);
#endif

.....
.....
.....
}
#endif /* MW_FEATURE_IMAGES && defined(HAVE_JPEG_SUPPORT)*/



沒有留言:

張貼留言