From c16ca291fb0f251b90cf79a01820c53371e3a7d6 Mon Sep 17 00:00:00 2001 From: Guosong Zhou Date: Thu, 13 Jul 2017 10:36:56 +0000 Subject: PD#146719: camera: fix camera license Change-Id: Ib4e80f824e29135f0c93a8b16d15ffe3c067be27 Signed-off-by: Guosong Zhou --- diff --git a/Android.mk b/Android.mk index b98237a..822195f 100644 --- a/Android.mk +++ b/Android.mk @@ -47,10 +47,6 @@ CAMERA_HAL_VERTURAL_CAMERA_SRC:= \ vircam/VirtualCamHal.cpp \ vircam/AppCbNotifier.cpp \ vircam/V4LCamAdpt.cpp - -CAMERA_HAL_JPEG_SRC:=\ - mjpeg/jpegdec.c \ - mjpeg/colorspaces.c CAMERA_HAL_HW_JPEGENC_SRC:=\ jpegenc_hw/jpegenc.cpp @@ -62,7 +58,6 @@ LOCAL_SRC_FILES:= \ $(CAMERA_V4L_SRC) \ $(CAMERA_COMMON_SRC) \ $(CAMERA_UTILS_SRC) \ - $(CAMERA_HAL_JPEG_SRC) \ $(CAMERA_USB_FMT_SRC) ifeq ($(BOARD_HAVE_HW_JPEGENC),true) @@ -88,6 +83,10 @@ LOCAL_C_INCLUDES += \ system/core/include/utils \ system/core/libion/include/ \ system/core/libion/kernel-headers \ + external/libyuv/files/include/ \ + +LOCAL_STATIC_LIBRARIES := \ + libyuv_static \ ifeq ($(BOARD_HAVE_HW_JPEGENC),true) LOCAL_C_INCLUDES += \ diff --git a/CameraHal.cpp b/CameraHal.cpp index 284cb36..fe989df 100755..100644 --- a/CameraHal.cpp +++ b/CameraHal.cpp @@ -1435,7 +1435,11 @@ status_t CameraHal::allocVideoBufs(uint32_t width, uint32_t height, uint32_t buf for (uint32_t i = 0; i< bufferCount; i++){ GraphicBufferAllocator &GrallocAlloc = GraphicBufferAllocator::get(); buffer_handle_t buf; +#if PLATFORM_SDK_VERSION > 22 ret = GrallocAlloc.alloc(width, height, HAL_PIXEL_FORMAT_NV12, CAMHAL_GRALLOC_USAGE, &buf, &stride); +#else + ret = GrallocAlloc.alloc(width, height, HAL_PIXEL_FORMAT_NV12, CAMHAL_GRALLOC_USAGE, &buf, (int32_t*)&stride); +#endif if (ret != NO_ERROR){ CAMHAL_LOGEA("Couldn't allocate video buffers using Gralloc"); ret = -NO_MEMORY; diff --git a/CameraHal_Module.cpp b/CameraHal_Module.cpp index e32c9c9..4f44f74 100755..100644 --- a/CameraHal_Module.cpp +++ b/CameraHal_Module.cpp @@ -101,9 +101,6 @@ camera_module_t HAL_MODULE_INFO_SYM = { set_callbacks: NULL, get_vendor_tag_ops: NULL, open_legacy: NULL, - set_torch_mode: NULL, - init: NULL, - reserved: {0}, }; typedef struct aml_camera_device { diff --git a/V4LCameraAdapter/V4LCameraAdapter.cpp b/V4LCameraAdapter/V4LCameraAdapter.cpp index 32528e0..09164f3 100755..100644 --- a/V4LCameraAdapter/V4LCameraAdapter.cpp +++ b/V4LCameraAdapter/V4LCameraAdapter.cpp @@ -52,8 +52,8 @@ #include "CameraHal.h" extern "C"{ #include "usb_fmt.h" - #include "jutils.h" } +#include "libyuv.h" //for private_handle_t TODO move out of private header #include @@ -1821,27 +1821,83 @@ int V4LCameraAdapter::previewThread() uint8_t* src = (uint8_t*) fp; #ifdef AMLOGIC_USB_CAMERA_SUPPORT - if(mFailedCnt == 0) - gettimeofday(&mStartTime, NULL); + if (mFailedCnt == 0) + gettimeofday(&mStartTime, NULL); #endif - if(mSensorFormat == V4L2_PIX_FMT_MJPEG){ //enable mjpeg - if(jpeg_decode(&dest,src,width,height, ( CameraFrame::PIXEL_FMT_NV21 == mPixelFormat)?V4L2_PIX_FMT_NV21:V4L2_PIX_FMT_YVU420) != 0){ // output format is nv21 - fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)), CameraFrame::PREVIEW_FRAME_SYNC); - CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x",src[0], src[1], src[2], src[3]); + if (mSensorFormat == V4L2_PIX_FMT_MJPEG) { //enable mjpeg + if (CameraFrame::PIXEL_FMT_YV12 == mPixelFormat) { + if(ConvertToI420(src, mVideoInfo->buf.bytesused, dest, width, + dest + width * height + width * height / 4, (width + 1) / 2, + dest + width * height, (width + 1) / 2, 0, 0, width, height, + width, height, libyuv::kRotate0, libyuv::FOURCC_MJPG) != 0) { + fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)), + CameraFrame::PREVIEW_FRAME_SYNC); + CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x", + src[0], src[1], src[2], src[3]); + #ifdef AMLOGIC_USB_CAMERA_SUPPORT - mFailedCnt++; - gettimeofday(&mEndTime, NULL); - int intreval = (mEndTime.tv_sec - mStartTime.tv_sec) * 1000000 + (mEndTime.tv_usec - mStartTime.tv_usec); - if(intreval > (int)mResetTH){ - CAMHAL_LOGIA("MJPEG Stream error ! Restart Preview"); - force_reset_sensor(); - mFailedCnt = 0; - mFirstBuff = true; - } + mFailedCnt++; + gettimeofday(&mEndTime, NULL); + int intreval = (mEndTime.tv_sec - mStartTime.tv_sec) * 1000000 + + (mEndTime.tv_usec - mStartTime.tv_usec); + if (intreval > (int)mResetTH) { + CAMHAL_LOGIA("MJPEG Stream error ! Restart Preview"); + force_reset_sensor(); + mFailedCnt = 0; + mFirstBuff = true; + } #endif - return -1; + return -1; + } + } else if (CameraFrame::PIXEL_FMT_NV21 == mPixelFormat) { + if (ConvertMjpegToNV21(src, mVideoInfo->buf.bytesused, dest, width, + dest + width * height, (width + 1) / 2, + width, height, width, height, libyuv::FOURCC_MJPG) != 0) { + uint8_t *vBuffer = new uint8_t[width * height / 4]; + if (vBuffer == NULL) + CAMHAL_LOGIA("alloc temperary v buffer failed\n"); + uint8_t *uBuffer = new uint8_t[width * height / 4]; + if (uBuffer == NULL) + CAMHAL_LOGIA("alloc temperary u buffer failed\n"); + + if(ConvertToI420(src, mVideoInfo->buf.bytesused, dest, + width, uBuffer, (width + 1) / 2, + vBuffer, (width + 1) / 2, 0, 0, width, height, + width, height, libyuv::kRotate0, libyuv::FOURCC_MJPG) != 0) { + fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)), + CameraFrame::PREVIEW_FRAME_SYNC); + CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x", + src[0], src[1], src[2], src[3]); + +#ifdef AMLOGIC_USB_CAMERA_SUPPORT + mFailedCnt++; + gettimeofday(&mEndTime, NULL); + int intreval = (mEndTime.tv_sec - mStartTime.tv_sec) * 1000000 + + (mEndTime.tv_usec - mStartTime.tv_usec); + if (intreval > (int)mResetTH) { + CAMHAL_LOGIA("MJPEG Stream error ! Restart Preview"); + force_reset_sensor(); + mFailedCnt = 0; + mFirstBuff = true; + } +#endif + + delete vBuffer; + delete uBuffer; + return -1; + } + + uint8_t *pUVBuffer = dest + width * height; + for (int i = 0; i < width * height / 4; i++) { + *pUVBuffer++ = *(vBuffer + i); + *pUVBuffer++ = *(uBuffer + i); + } + + delete vBuffer; + delete uBuffer; + } } - mFailedCnt = 0; + mFailedCnt = 0; frame.mLength = width*height*3/2; }else{ if(DEFAULT_PREVIEW_PIXEL_FORMAT == V4L2_PIX_FMT_YUYV){ // 422I @@ -2276,17 +2332,59 @@ int V4LCameraAdapter::pictureThread() height = temp; } #endif - + CAMHAL_LOGDB("mCaptureBuf=%p,dest=%p,fp=%p,index=%d\n" "w=%d h=%d,len=%d,bytesused=%d\n", mCaptureBuf, dest, fp,index, width, height, mVideoInfo->buf.length, mVideoInfo->buf.bytesused); if(mSensorFormat == V4L2_PIX_FMT_MJPEG){ - if(jpeg_decode(&dest,src,width,height,V4L2_PIX_FMT_NV21) != 0){ // output format is nv21 - //fillThisBuffer(mCaptureBuf, CameraFrame::IMAGE_FRAME); - CAMHAL_LOGEA("jpeg decode failed"); + if (CameraFrame::PIXEL_FMT_YV12 == mPixelFormat) { + if(ConvertToI420(src, mVideoInfo->buf.bytesused, dest, width, + dest + width * height + width * height / 4, (width + 1) / 2, + dest + width * height, (width + 1) / 2, 0, 0, width, height, + width, height, libyuv::kRotate0, libyuv::FOURCC_MJPG) != 0) { + fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)), + CameraFrame::PREVIEW_FRAME_SYNC); + CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x", + src[0], src[1], src[2], src[3]); + return -1; + } + } else if (CameraFrame::PIXEL_FMT_NV21 == mPixelFormat) { + if(ConvertMjpegToNV21(src, mVideoInfo->buf.bytesused, dest, + width, dest + width * height, (width + 1) / 2, + width, height, width, height, libyuv::FOURCC_MJPG) != 0) { + uint8_t *vBuffer = new uint8_t[width * height / 4]; + if (vBuffer == NULL) + CAMHAL_LOGIA("alloc temperary v buffer failed\n"); + uint8_t *uBuffer = new uint8_t[width * height / 4]; + if (uBuffer == NULL) + CAMHAL_LOGIA("alloc temperary u buffer failed\n"); + + if(ConvertToI420(src, mVideoInfo->buf.bytesused, dest, + width, uBuffer, (width + 1) / 2, + vBuffer, (width + 1) / 2, 0, 0, width, height, + width, height, libyuv::kRotate0, libyuv::FOURCC_MJPG) != 0) { + fillThisBuffer((uint8_t*) mPreviewBufs.keyAt(mPreviewIdxs.valueFor(index)), + CameraFrame::PREVIEW_FRAME_SYNC); + CAMHAL_LOGEB("jpeg decode failed,src:%02x %02x %02x %02x", + src[0], src[1], src[2], src[3]); + delete vBuffer; + delete uBuffer; + return -1; + } + + uint8_t *pUVBuffer = dest + width * height; + for (int i = 0; i < width * height / 4; i++) { + *pUVBuffer++ = *(vBuffer + i); + *pUVBuffer++ = *(uBuffer + i); + } + + delete vBuffer; + delete uBuffer; + } } + frame.mLength = width*height*3/2; frame.mQuirks = CameraFrame::ENCODE_RAW_YUV420SP_TO_JPEG | CameraFrame::HAS_EXIF_DATA; diff --git a/inc/mjpeg/colorspaces.h b/inc/mjpeg/colorspaces.h deleted file mode 100755 index 3479568..0000000 --- a/inc/mjpeg/colorspaces.h +++ b/dev/null @@ -1,288 +0,0 @@ -/*******************************************************************************# -# guvcview http://guvcview.sourceforge.net # -# # -# Paulo Assis # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -********************************************************************************/ - -#ifndef COLORSPACES_H -#define COLORSPACES_H - -#include "defs.h" -#include "jutils.h" - -/*convert yuv 420 planar (yu12) to yuv 422 -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing yuv420 planar data frame -* width: picture width -* height: picture height -*/ -void -yuv420_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yvu 420 planar (yv12) to yuv 422 (yuyv) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing yvu420 planar data frame -* width: picture width -* height: picture height -*/ -void yvu420_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yuv 420 planar (uv interleaved) (nv12) to yuv 422 -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing yuv420 (nv12) planar data frame -* width: picture width -* height: picture height -*/ -void nv12_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yuv 420 planar (vu interleaved) (nv21) to yuv 422 -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing yuv420 (nv21) planar data frame -* width: picture width -* height: picture height -*/ -void nv21_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yuv 422 planar (uv interleaved) (nv16) to yuv 422 -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing yuv422 (nv16) planar data frame -* width: picture width -* height: picture height -*/ -void nv16_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yuv 422 planar (vu interleaved) (nv61) to yuv 422 -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing yuv422 (nv61) planar data frame -* width: picture width -* height: picture height -*/ -void nv61_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert y10b (bit-packed array greyscale format) to yuyv (packed) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing y10b (bit-packed array) data frame -* width: picture width -* height: picture height -*/ -void y10b_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert y16 (grey) to yuyv (packed) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing y16 (grey) data frame -* width: picture width -* height: picture height -*/ -void y16_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yyuv to yuyv -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing a yyuv data frame -* width: picture width -* height: picture height -*/ -void -yyuv_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert uyvy (packed) to yuyv (packed) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing uyvy packed data frame -* width: picture width -* height: picture height -*/ -void uyvy_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yvyu (packed) to yuyv (packed) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing yvyu packed data frame -* width: picture width -* height: picture height -*/ -void yvyu_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yuv 411 packed (y41p) to yuv 422 -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing y41p data frame -* width: picture width -* height: picture height -*/ -void y41p_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yuv mono (grey) to yuv 422 -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing grey (y only) data frame -* width: picture width -* height: picture height -*/ -void grey_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert SPCA501 (s501) to yuv 422 -* s501 |Y0..width..Y0|U..width/2..U|Y1..width..Y1|V..width/2..V| -* signed values (-128;+127) must be converted to unsigned (0; 255) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing s501 data frame -* width: picture width -* height: picture height -*/ -void s501_to_yuyv(BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert SPCA505 (s505) to yuv 422 -* s505 |Y0..width..Y0|Y1..width..Y1|U..width/2..U|V..width/2..V| -* signed values (-128;+127) must be converted to unsigned (0; 255) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing s501 data frame -* width: picture width -* height: picture height -*/ -void s505_to_yuyv(BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert SPCA508 (s508) to yuv 422 -* s508 |Y0..width..Y0|U..width/2..U|V..width/2..V|Y1..width..Y1| -* signed values (-128;+127) must be converted to unsigned (0; 255) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing s501 data frame -* width: picture width -* height: picture height -*/ -void s508_to_yuyv(BYTE *framebuffer, BYTE *tmpbuffer, int width, int height); - -/*convert yuyv to rgb24 -* args: -* pyuv: pointer to buffer containing yuv data (yuyv) -* prgb: pointer to buffer containing rgb24 data -* width: picture width -* height: picture height -*/ -void -yuyv2rgb (BYTE *pyuv, BYTE *prgb, int width, int height); - - -/*convert yuyv to bgr with lines upsidedown -* used for bitmap files (DIB24) -* args: -* pyuv: pointer to buffer containing yuv data (yuyv) -* prgb: pointer to buffer containing rgb24 data -* width: picture width -* height: picture height -*/ -void -yuyv2bgr (BYTE *pyuv, BYTE *pbgr, int width, int height); - -/* used for rgb video (fourcc="RGB ") -* lines are in correct order -*/ -void -yuyv2bgr1 (BYTE *pyuv, BYTE *pbgr, int width, int height); - -/*convert bayer raw data to rgb24 -* args: -* pBay: pointer to buffer containing Raw bayer data data -* pRGB24: pointer to buffer containing rgb24 data -* width: picture width -* height: picture height -* pix_order: bayer pixel order (0=gb/rg 1=gr/bg 2=bg/gr 3=rg/bg) -*/ -void -bayer_to_rgb24(BYTE *pBay, BYTE *pRGB24, int width, int height, int pix_order); - -/*convert rgb24 to yuyv -* args: -* prgb: pointer to buffer containing rgb24 data -* pyuv: pointer to buffer containing yuv data (yuyv) -* width: picture width -* height: picture height -*/ -void -rgb2yuyv(BYTE *prgb, BYTE *pyuv, int width, int height); - -/*convert bgr24 to yuyv -* args: -* pbgr: pointer to buffer containing bgr24 data -* pyuv: pointer to buffer containing yuv data (yuyv) -* width: picture width -* height: picture height -*/ -void -bgr2yuyv(BYTE *pbgr, BYTE *pyuv, int width, int height); - -/*use in utils.c for jpeg decoding 420 planar to 422 -* args: -* out: pointer to data output of idct (macroblocks yyyy u v) -* pic: pointer to picture buffer (yuyv) -* width: picture width -*/ -void -yuv420pto422(int * out,unsigned char *pic,int width); - -/*use in utils.c for jpeg decoding 422 planar to 422 -* args: -* out: pointer to data output of idct (macroblocks yyyy u v) -* pic: pointer to picture buffer (yuyv) -* width: picture width -*/ -void -yuv422pto422(int * out,unsigned char *pic,int width); - -void -yuv420pto420sp(int * out,addr *pic,int width); - -void -yuv420pto420p(int * out,addr *pic,int width); - -void -yuv422pto420sp(int * out, addr *pic,int width); - -void -yuv422pto420p(int * out, addr *pic,int width); - -/*use in utils.c for jpeg decoding 444 planar to 422 -* args: -* out: pointer to data output of idct (macroblocks yyyy u v) -* pic: pointer to picture buffer (yuyv) -* width: picture width -*/ -void -yuv444pto422(int * out,unsigned char *pic,int width); - -/*use in utils.c for jpeg decoding 400 planar to 422 -* args: -* out: pointer to data output of idct (macroblocks yyyy ) -* pic: pointer to picture buffer (yuyv) -* width: picture width -*/ -void -yuv400pto422(int * out,unsigned char *pic,int width); - -#endif - diff --git a/inc/mjpeg/defs.h b/inc/mjpeg/defs.h deleted file mode 100644 index b286a08..0000000 --- a/inc/mjpeg/defs.h +++ b/dev/null @@ -1,57 +0,0 @@ -/*******************************************************************************# -# guvcview http://guvcview.sourceforge.net # -# # -# Paulo Assis # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -********************************************************************************/ - -#ifndef DEFS_H -#define DEFS_H -#include -#include - -typedef uint64_t QWORD; -typedef uint32_t DWORD; -typedef uint16_t WORD; -typedef uint8_t BYTE; -typedef unsigned int LONG; -typedef unsigned int UINT; - -typedef unsigned long long ULLONG; -typedef unsigned long ULONG; - -typedef char* pchar; - -typedef int8_t INT8; -typedef uint8_t UINT8; -typedef int16_t INT16; -typedef uint16_t UINT16; -typedef int32_t INT32; -typedef uint32_t UINT32; -typedef int64_t INT64; -typedef uint64_t UINT64; - -/*clip value between 0 and 255*/ -#define CLIP(value) (BYTE)(((value)>0xFF)?0xff:(((value)<0)?0:(value))) - -/*MAX macro - gets the bigger value*/ -#ifndef MAX -#define MAX(a,b) (((a) < (b)) ? (b) : (a)) -#endif - -#endif - diff --git a/inc/mjpeg/huffman.h b/inc/mjpeg/huffman.h deleted file mode 100755 index 4291844..0000000 --- a/inc/mjpeg/huffman.h +++ b/dev/null @@ -1,99 +0,0 @@ -/*******************************************************************************# -# guvcview http://guvcview.sourceforge.net # -# # -# Paulo Assis # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -********************************************************************************/ - -/*******************************************************************************# -# # -# huffman tables for Jpeg encoder/decoder # -# # -# Adapted for linux, Paulo Assis, 2007 # -********************************************************************************/ - -#ifndef HUFFMAN_H -#define HUFFMAN_H - -#include "defs.h" - -#define JPG_HUFFMAN_TABLE_LENGTH 0x01A0 - -static const unsigned char JPEGHuffmanTable[JPG_HUFFMAN_TABLE_LENGTH] = -{ - // luminance dc - length bits - 0x00, - 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // luminance dc - code - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x0A, 0x0B, - // chrominance dc - length bits - 0x01, - 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - // chrominance dc - code - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x0A, 0x0B, - // luminance ac - number of codes with # bits (ordered by code length 1-16) - 0x10, - 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, - 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, - // luminance ac - run size (ordered by code length) - 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, - 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, - 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, - 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, - 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, - 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, - 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, - 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, - 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, - 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, - 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, - 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, - 0xD9, 0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, - 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, - 0xF9, 0xFA, - // chrominance ac -number of codes with # bits (ordered by code length 1-16) - 0x11, - 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, - 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, - // chrominance ac - run size (ordered by code length) - 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, - 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, - 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, - 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, - 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, - 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, - 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, - 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, - 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, - 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, - 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, - 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, - 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, - 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, - 0xD7, 0xD8, 0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, - 0xF9, 0xFA -}; - -#endif - diff --git a/inc/mjpeg/jutils.h b/inc/mjpeg/jutils.h deleted file mode 100755 index f00bc10..0000000 --- a/inc/mjpeg/jutils.h +++ b/dev/null @@ -1,149 +0,0 @@ -/*******************************************************************************# -# guvcview http://guvcview.sourceforge.net # -# # -# Paulo Assis # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -********************************************************************************/ - -/*******************************************************************************# -# # -# MJpeg decoding and frame capture taken from luvcview # -# # -# # -********************************************************************************/ - -#ifndef UTILS_H -#define UTILS_H - -#include "defs.h" - -/*video defs*/ -//#define BI_RGB 0; -//#define BI_RLE4 1; -//#define BI_RLE8 2; -//#define BI_BITFIELDS 3; - -/* Fixed point arithmetic */ -//#define FIXED Sint32 -//#define FIXED_BITS 16 -//#define TO_FIXED(X) (((Sint32)(X))<<(FIXED_BITS)) -//#define FROM_FIXED(X) (((Sint32)(X))>>(FIXED_BITS)) - -#define ISHIFT 11 - -#define IFIX(a) ((int)((a) * (1 << ISHIFT) + .5)) - -#ifndef __P -# define __P(x) x -#endif - -/* special markers */ -#define M_BADHUFF -1 -#define M_EOF 0x80 - -struct jpeg_decdata -{ - int dcts[6 * 64 + 16]; - int out[64 * 6]; - int dquant[3][64]; -}; - -struct in -{ - BYTE *p; - DWORD bits; - int left; - int marker; - int (*func) __P((void *)); - void *data; -}; - -/*********************************/ -#define DECBITS 10 /* seems to be the optimum */ - -struct dec_hufftbl -{ - int maxcode[17]; - int valptr[16]; - BYTE vals[256]; - DWORD llvals[1 << DECBITS]; -}; - -//struct enc_hufftbl; - -union hufftblp -{ - struct dec_hufftbl *dhuff; - //struct enc_hufftbl *ehuff; -}; - -struct scan -{ - int dc; /* old dc value */ - - union hufftblp hudc; - union hufftblp huac; - int next; /* when to switch to next scan */ - - int cid; /* component id */ - int hv; /* horiz/vert, copied from comp */ - int tq; /* quant tbl, copied from comp */ -}; - -/******** Markers *********/ -#ifndef M_SOI -#define M_SOI 0xd8 -#define M_APP0 0xe0 -#define M_DQT 0xdb -#define M_SOF0 0xc0 -#define M_DHT 0xc4 -#define M_DRI 0xdd -#define M_SOS 0xda -#define M_RST0 0xd0 -#define M_EOI 0xd9 -#define M_COM 0xfe -#endif - -/*******Error codes *******/ -#define ERR_NO_SOI 1 -#define ERR_NOT_8BIT 2 -#define ERR_HEIGHT_MISMATCH 3 -#define ERR_WIDTH_MISMATCH 4 -#define ERR_BAD_WIDTH_OR_HEIGHT 5 -#define ERR_TOO_MANY_COMPPS 6 -#define ERR_ILLEGAL_HV 7 -#define ERR_QUANT_TABLE_SELECTOR 8 -#define ERR_NOT_YCBCR_221111 9 -#define ERR_UNKNOWN_CID_IN_SCAN 10 -#define ERR_NOT_SEQUENTIAL_DCT 11 -#define ERR_WRONG_MARKER 12 -#define ERR_NO_EOI 13 -#define ERR_BAD_TABLES 14 -#define ERR_DEPTH_MISMATCH 15 -#define ERR_NOT_SUPPORTED 16 - -typedef struct addr_s -{ - unsigned char *y; - unsigned char *v; - unsigned char *u; -}addr; - -int jpeg_decode(unsigned char **pic, unsigned char *buf, int width, int height,unsigned int outformat); - -#endif - diff --git a/mjpeg/colorspaces.c b/mjpeg/colorspaces.c deleted file mode 100755 index 723505c..0000000 --- a/mjpeg/colorspaces.c +++ b/dev/null @@ -1,2016 +0,0 @@ -/*******************************************************************************# -# guvcview http://guvcview.sourceforge.net # -# # -# Paulo Assis # -# Nobuhiro Iwamatsu # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -********************************************************************************/ - -#include -#include -#include -#include "colorspaces.h" -#include -#define TRUE 1 -#define FALSE 0 -/*------------------------------- Color space conversions --------------------*/ -/* regular yuv (YUYV) to rgb24*/ -void -yuyv2rgb (BYTE *pyuv, BYTE *prgb, int width, int height) -{ - int l=0; - int SizeYUV=height * width * 2; /* 2 bytes per pixel*/ - for(l=0;l> bitsIn) & mask; - } -} - -/*convert y10b (bit-packed array greyscale format) to yuyv (packed) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing y10b (bit-packed array) data frame -* width: picture width -* height: picture height -*/ -void y10b_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height) -{ - UINT16 *unpacked_buffer = NULL; - UINT16 *ptmp; - int h = 0; - int w = 0; - - unpacked_buffer = malloc(width * height * sizeof(UINT16)); - convert_packed_to_16bit(tmpbuffer, unpacked_buffer, 10, width * height); - - ptmp = unpacked_buffer; - - for (h = 0; h < height; h++) - { - for (w = 0; w < width; w += 2) - { - /* Y0 */ - *framebuffer++ = (BYTE) ((ptmp[0] & 0x3FF) >> 2); - /* U */ - *framebuffer++ = 0x80; - /* Y1 */ - *framebuffer++ = (BYTE) ((ptmp[1] & 0x3FF) >> 2); - /* V */ - *framebuffer++ = 0x80; - - ptmp += 2; - } - } - - free(unpacked_buffer); -} - -/*convert y16 (grey) to yuyv (packed) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing y16 (grey) data frame -* width: picture width -* height: picture height -*/ -void y16_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height) -{ - UINT16 *ptmp= (UINT16 *) tmpbuffer; - - int h=0; - int w=0; - - for(h=0;h> 8); - /* U */ - *framebuffer++ = 0x80; - /* Y1 */ - *framebuffer++ = (BYTE) ((ptmp[1] & 0xFF00) >> 8); - /* V */ - *framebuffer++ = 0x80; - - ptmp += 2; - } - } -} - -/*convert yyuv (packed) to yuyv (packed) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing yyuv packed data frame -* width: picture width -* height: picture height -*/ -void yyuv_to_yuyv (BYTE *framebuffer, BYTE *tmpbuffer, int width, int height) -{ - BYTE *ptmp=NULL; - BYTE *pfmb=NULL; - ptmp = tmpbuffer; - pfmb = framebuffer; - - int h=0; - int w=0; - - for(h=0;h= 0; ) - { - *framebuffer++ = 0x80 + *Y0++; - *framebuffer++ = 0x80 + *U; - *framebuffer++ = 0x80 + *Y0++; - *framebuffer++ = 0x80 + *V; - - *line2++ = 0x80 + *Y1++; - *line2++ = 0x80 + *U++; - *line2++ = 0x80 + *Y1++; - *line2++ = 0x80 + *V++; - } - Y0 += width * 2; /* next block of lines */ - framebuffer = line2; - } -} - -/*convert SPCA505 (s505) to yuv 422 -* s505 |Y0..width..Y0|Y1..width..Y1|U..width/2..U|V..width/2..V| -* signed values (-128;+127) must be converted to unsigned (0; 255) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing s501 data frame -* width: picture width -* height: picture height -*/ -void s505_to_yuyv(BYTE *framebuffer, BYTE *tmpbuffer, int width, int height) -{ - BYTE *U, *V, *Y0, *Y1; - BYTE *line2; - int h, w; - - Y0 = tmpbuffer; /*fisrt line*/ - for (h = 0; h < height/2; h++ ) - { - line2 = framebuffer + width * 2; /* next line */ - Y1 = Y0 + width; - U = Y1 + width; - V = U + width/2; - for (w = width / 2; --w >= 0; ) - { - *framebuffer++ = 0x80 + *Y0++; - *framebuffer++ = 0x80 + *U; - *framebuffer++ = 0x80 + *Y0++; - *framebuffer++ = 0x80 + *V; - - *line2++ = 0x80 + *Y1++; - *line2++ = 0x80 + *U++; - *line2++ = 0x80 + *Y1++; - *line2++ = 0x80 + *V++; - } - Y0 += width * 2; /* next block of lines */ - framebuffer = line2; - } -} - -/*convert SPCA508 (s508) to yuv 422 -* s508 |Y0..width..Y0|U..width/2..U|V..width/2..V|Y1..width..Y1| -* signed values (-128;+127) must be converted to unsigned (0; 255) -* args: -* framebuffer: pointer to frame buffer (yuyv) -* tmpbuffer: pointer to temp buffer containing s501 data frame -* width: picture width -* height: picture height -*/ -void s508_to_yuyv(BYTE *framebuffer, BYTE *tmpbuffer, int width, int height) -{ - BYTE *U, *V, *Y0, *Y1; - BYTE *line2; - int h, w; - - Y0 = tmpbuffer; /*fisrt line*/ - for (h = 0; h < height/2; h++ ) - { - line2 = framebuffer + width * 2; /* next line */ - U = Y0 + width; - V = U + width/2; - Y1= V + width/2; - for (w = width / 2; --w >= 0; ) - { - *framebuffer++ = 0x80 + *Y0++; - *framebuffer++ = 0x80 + *U; - *framebuffer++ = 0x80 + *Y0++; - *framebuffer++ = 0x80 + *V; - - *line2++ = 0x80 + *Y1++; - *line2++ = 0x80 + *U++; - *line2++ = 0x80 + *Y1++; - *line2++ = 0x80 + *V++; - } - Y0 += width * 2; /* next block of lines */ - framebuffer = line2; - } -} - -// raw bayer functions -// from libv4l bayer.c, (C) 2008 Hans de Goede -//Note: original bayer_to_bgr24 code from : -// 1394-Based Digital Camera Control Library -// -// Bayer pattern decoding functions -// -// Written by Damien Douxchamps and Frederic Devernay -static void convert_border_bayer_line_to_bgr24( BYTE* bayer, BYTE* adjacent_bayer, - BYTE *bgr, int width, bool start_with_green, bool blue_line) -{ - int t0, t1; - - if (start_with_green) - { - /* First pixel */ - if (blue_line) - { - *bgr++ = bayer[1]; - *bgr++ = bayer[0]; - *bgr++ = adjacent_bayer[0]; - } - else - { - *bgr++ = adjacent_bayer[0]; - *bgr++ = bayer[0]; - *bgr++ = bayer[1]; - } - /* Second pixel */ - t0 = (bayer[0] + bayer[2] + adjacent_bayer[1] + 1) / 3; - t1 = (adjacent_bayer[0] + adjacent_bayer[2] + 1) >> 1; - if (blue_line) - { - *bgr++ = bayer[1]; - *bgr++ = t0; - *bgr++ = t1; - } - else - { - *bgr++ = t1; - *bgr++ = t0; - *bgr++ = bayer[1]; - } - bayer++; - adjacent_bayer++; - width -= 2; - } - else - { - /* First pixel */ - t0 = (bayer[1] + adjacent_bayer[0] + 1) >> 1; - if (blue_line) - { - *bgr++ = bayer[0]; - *bgr++ = t0; - *bgr++ = adjacent_bayer[1]; - } - else - { - *bgr++ = adjacent_bayer[1]; - *bgr++ = t0; - *bgr++ = bayer[0]; - } - width--; - } - - if (blue_line) - { - for ( ; width > 2; width -= 2) - { - t0 = (bayer[0] + bayer[2] + 1) >> 1; - *bgr++ = t0; - *bgr++ = bayer[1]; - *bgr++ = adjacent_bayer[1]; - bayer++; - adjacent_bayer++; - - t0 = (bayer[0] + bayer[2] + adjacent_bayer[1] + 1) / 3; - t1 = (adjacent_bayer[0] + adjacent_bayer[2] + 1) >> 1; - *bgr++ = bayer[1]; - *bgr++ = t0; - *bgr++ = t1; - bayer++; - adjacent_bayer++; - } - } - else - { - for ( ; width > 2; width -= 2) - { - t0 = (bayer[0] + bayer[2] + 1) >> 1; - *bgr++ = adjacent_bayer[1]; - *bgr++ = bayer[1]; - *bgr++ = t0; - bayer++; - adjacent_bayer++; - - t0 = (bayer[0] + bayer[2] + adjacent_bayer[1] + 1) / 3; - t1 = (adjacent_bayer[0] + adjacent_bayer[2] + 1) >> 1; - *bgr++ = t1; - *bgr++ = t0; - *bgr++ = bayer[1]; - bayer++; - adjacent_bayer++; - } - } - - if (width == 2) - { - /* Second to last pixel */ - t0 = (bayer[0] + bayer[2] + 1) >> 1; - if (blue_line) - { - *bgr++ = t0; - *bgr++ = bayer[1]; - *bgr++ = adjacent_bayer[1]; - } - else - { - *bgr++ = adjacent_bayer[1]; - *bgr++ = bayer[1]; - *bgr++ = t0; - } - /* Last pixel */ - t0 = (bayer[1] + adjacent_bayer[2] + 1) >> 1; - if (blue_line) - { - *bgr++ = bayer[2]; - *bgr++ = t0; - *bgr++ = adjacent_bayer[1]; - } - else - { - *bgr++ = adjacent_bayer[1]; - *bgr++ = t0; - *bgr++ = bayer[2]; - } - } - else - { - /* Last pixel */ - if (blue_line) - { - *bgr++ = bayer[0]; - *bgr++ = bayer[1]; - *bgr++ = adjacent_bayer[1]; - } - else - { - *bgr++ = adjacent_bayer[1]; - *bgr++ = bayer[1]; - *bgr++ = bayer[0]; - } - } -} - -/* From libdc1394, which on turn was based on OpenCV's Bayer decoding */ -static void bayer_to_rgbbgr24(BYTE *bayer, - BYTE *bgr, int width, int height, - bool start_with_green, bool blue_line) -{ - /* render the first line */ - convert_border_bayer_line_to_bgr24(bayer, bayer + width, bgr, width, - start_with_green, blue_line); - bgr += width * 3; - - /* reduce height by 2 because of the special case top/bottom line */ - for (height -= 2; height; height--) - { - int t0, t1; - /* (width - 2) because of the border */ - BYTE *bayerEnd = bayer + (width - 2); - - if (start_with_green) - { - /* OpenCV has a bug in the next line, which was - t0 = (bayer[0] + bayer[width * 2] + 1) >> 1; */ - t0 = (bayer[1] + bayer[width * 2 + 1] + 1) >> 1; - /* Write first pixel */ - t1 = (bayer[0] + bayer[width * 2] + bayer[width + 1] + 1) / 3; - if (blue_line) - { - *bgr++ = t0; - *bgr++ = t1; - *bgr++ = bayer[width]; - } - else - { - *bgr++ = bayer[width]; - *bgr++ = t1; - *bgr++ = t0; - } - - /* Write second pixel */ - t1 = (bayer[width] + bayer[width + 2] + 1) >> 1; - if (blue_line) - { - *bgr++ = t0; - *bgr++ = bayer[width + 1]; - *bgr++ = t1; - } - else - { - *bgr++ = t1; - *bgr++ = bayer[width + 1]; - *bgr++ = t0; - } - bayer++; - } - else - { - /* Write first pixel */ - t0 = (bayer[0] + bayer[width * 2] + 1) >> 1; - if (blue_line) - { - *bgr++ = t0; - *bgr++ = bayer[width]; - *bgr++ = bayer[width + 1]; - } - else - { - *bgr++ = bayer[width + 1]; - *bgr++ = bayer[width]; - *bgr++ = t0; - } - } - - if (blue_line) - { - for (; bayer <= bayerEnd - 2; bayer += 2) - { - t0 = (bayer[0] + bayer[2] + bayer[width * 2] + - bayer[width * 2 + 2] + 2) >> 2; - t1 = (bayer[1] + bayer[width] + - bayer[width + 2] + bayer[width * 2 + 1] + - 2) >> 2; - *bgr++ = t0; - *bgr++ = t1; - *bgr++ = bayer[width + 1]; - - t0 = (bayer[2] + bayer[width * 2 + 2] + 1) >> 1; - t1 = (bayer[width + 1] + bayer[width + 3] + - 1) >> 1; - *bgr++ = t0; - *bgr++ = bayer[width + 2]; - *bgr++ = t1; - } - } - else - { - for (; bayer <= bayerEnd - 2; bayer += 2) - { - t0 = (bayer[0] + bayer[2] + bayer[width * 2] + - bayer[width * 2 + 2] + 2) >> 2; - t1 = (bayer[1] + bayer[width] + - bayer[width + 2] + bayer[width * 2 + 1] + - 2) >> 2; - *bgr++ = bayer[width + 1]; - *bgr++ = t1; - *bgr++ = t0; - - t0 = (bayer[2] + bayer[width * 2 + 2] + 1) >> 1; - t1 = (bayer[width + 1] + bayer[width + 3] + - 1) >> 1; - *bgr++ = t1; - *bgr++ = bayer[width + 2]; - *bgr++ = t0; - } - } - - if (bayer < bayerEnd) - { - /* write second to last pixel */ - t0 = (bayer[0] + bayer[2] + bayer[width * 2] + - bayer[width * 2 + 2] + 2) >> 2; - t1 = (bayer[1] + bayer[width] + - bayer[width + 2] + bayer[width * 2 + 1] + - 2) >> 2; - if (blue_line) - { - *bgr++ = t0; - *bgr++ = t1; - *bgr++ = bayer[width + 1]; - } - else - { - *bgr++ = bayer[width + 1]; - *bgr++ = t1; - *bgr++ = t0; - } - /* write last pixel */ - t0 = (bayer[2] + bayer[width * 2 + 2] + 1) >> 1; - if (blue_line) - { - *bgr++ = t0; - *bgr++ = bayer[width + 2]; - *bgr++ = bayer[width + 1]; - } - else - { - *bgr++ = bayer[width + 1]; - *bgr++ = bayer[width + 2]; - *bgr++ = t0; - } - bayer++; - } - else - { - /* write last pixel */ - t0 = (bayer[0] + bayer[width * 2] + 1) >> 1; - t1 = (bayer[1] + bayer[width * 2 + 1] + bayer[width] + 1) / 3; - if (blue_line) - { - *bgr++ = t0; - *bgr++ = t1; - *bgr++ = bayer[width + 1]; - } - else - { - *bgr++ = bayer[width + 1]; - *bgr++ = t1; - *bgr++ = t0; - } - } - - /* skip 2 border pixels */ - bayer += 2; - - blue_line = !blue_line; - start_with_green = !start_with_green; - } - - /* render the last line */ - convert_border_bayer_line_to_bgr24(bayer + width, bayer, bgr, width, - !start_with_green, !blue_line); -} - -/*convert bayer raw data to rgb24 -* args: -* pBay: pointer to buffer containing Raw bayer data data -* pRGB24: pointer to buffer containing rgb24 data -* width: picture width -* height: picture height -* pix_order: bayer pixel order (0=gb/rg 1=gr/bg 2=bg/gr 3=rg/bg) -*/ -void -bayer_to_rgb24(BYTE *pBay, BYTE *pRGB24, int width, int height, int pix_order) -{ - switch (pix_order) - { - //conversion functions are build for bgr, by switching b and r lines we get rgb - case 0: /* gbgbgb... | rgrgrg... (V4L2_PIX_FMT_SGBRG8)*/ - bayer_to_rgbbgr24(pBay, pRGB24, width, height, TRUE, FALSE); - break; - - case 1: /* grgrgr... | bgbgbg... (V4L2_PIX_FMT_SGRBG8)*/ - bayer_to_rgbbgr24(pBay, pRGB24, width, height, TRUE, TRUE); - break; - - case 2: /* bgbgbg... | grgrgr... (V4L2_PIX_FMT_SBGGR8)*/ - bayer_to_rgbbgr24(pBay, pRGB24, width, height, FALSE, FALSE); - break; - - case 3: /* rgrgrg... ! gbgbgb... (V4L2_PIX_FMT_SRGGB8)*/ - bayer_to_rgbbgr24(pBay, pRGB24, width, height, FALSE, TRUE); - break; - - default: /* default is 0*/ - bayer_to_rgbbgr24(pBay, pRGB24, width, height, TRUE, FALSE); - break; - } -} - - -void -rgb2yuyv(BYTE *prgb, BYTE *pyuv, int width, int height) -{ - - int i=0; - for(i=0;i<(width*height*3);i=i+6) - { - /* y */ - *pyuv++ =CLIP(0.299 * (prgb[i] - 128) + 0.587 * (prgb[i+1] - 128) + 0.114 * (prgb[i+2] - 128) + 128); - /* u */ - *pyuv++ =CLIP(((- 0.147 * (prgb[i] - 128) - 0.289 * (prgb[i+1] - 128) + 0.436 * (prgb[i+2] - 128) + 128) + - (- 0.147 * (prgb[i+3] - 128) - 0.289 * (prgb[i+4] - 128) + 0.436 * (prgb[i+5] - 128) + 128))/2); - /* y1 */ - *pyuv++ =CLIP(0.299 * (prgb[i+3] - 128) + 0.587 * (prgb[i+4] - 128) + 0.114 * (prgb[i+5] - 128) + 128); - /* v*/ - *pyuv++ =CLIP(((0.615 * (prgb[i] - 128) - 0.515 * (prgb[i+1] - 128) - 0.100 * (prgb[i+2] - 128) + 128) + - (0.615 * (prgb[i+3] - 128) - 0.515 * (prgb[i+4] - 128) - 0.100 * (prgb[i+5] - 128) + 128))/2); - } -} - -void -bgr2yuyv(BYTE *pbgr, BYTE *pyuv, int width, int height) -{ - - int i=0; - for(i=0;i<(width*height*3);i=i+6) - { - /* y */ - *pyuv++ =CLIP(0.299 * (pbgr[i+2] - 128) + 0.587 * (pbgr[i+1] - 128) + 0.114 * (pbgr[i] - 128) + 128); - /* u */ - *pyuv++ =CLIP(((- 0.147 * (pbgr[i+2] - 128) - 0.289 * (pbgr[i+1] - 128) + 0.436 * (pbgr[i] - 128) + 128) + - (- 0.147 * (pbgr[i+5] - 128) - 0.289 * (pbgr[i+4] - 128) + 0.436 * (pbgr[i+3] - 128) + 128))/2); - /* y1 */ - *pyuv++ =CLIP(0.299 * (pbgr[i+5] - 128) + 0.587 * (pbgr[i+4] - 128) + 0.114 * (pbgr[i+3] - 128) + 128); - /* v*/ - *pyuv++ =CLIP(((0.615 * (pbgr[i+2] - 128) - 0.515 * (pbgr[i+1] - 128) - 0.100 * (pbgr[i] - 128) + 128) + - (0.615 * (pbgr[i+5] - 128) - 0.515 * (pbgr[i+4] - 128) - 0.100 * (pbgr[i+3] - 128) + 128))/2); - } -} - -/*use in utils.c for jpeg decoding 420 planar to 422 -* args: -* out: pointer to data output of idct (macroblocks yyyy u v) -* pic: pointer to picture buffer (yuyv) -* width: picture width -*/ -void yuv420pto422(int * out,unsigned char *pic,int width) -{ - int j, k; - unsigned char *pic0, *pic1; - int *outy, *outu, *outv; - int outy1 = 0; - int outy2 = 8; - - //yyyyuv - pic0 = pic; - pic1 = pic + width; - outy = out; - outu = out + 64 * 4; - outv = out + 64 * 5; - for (j = 0; j < 8; j++) - { - for (k = 0; k < 8; k++) - { - if( k == 4) - { - outy1 += 56; - outy2 += 56; - } - *pic0++ = CLIP(outy[outy1]); //y1 line 1 - *pic0++ = CLIP(128 + *outu); //u line 1-2 - *pic0++ = CLIP(outy[outy1+1]); //y2 line 1 - *pic0++ = CLIP(128 + *outv); //v line 1-2 - *pic1++ = CLIP(outy[outy2]); //y1 line 2 - *pic1++ = CLIP(128 + *outu); //u line 1-2 - *pic1++ = CLIP(outy[outy2+1]); //y2 line 2 - *pic1++ = CLIP(128 + *outv); //v line 1-2 - outy1 +=2; outy2 += 2; outu++; outv++; - } - if(j==3) - { - outy = out + 128; - } - else - { - outy += 16; - } - outy1 = 0; - outy2 = 8; - pic0 += 2 * (width -16); - pic1 += 2 * (width -16); - } -} - -/*use in utils.c for jpeg decoding 422 planar to 422 -* args: -* out: pointer to data output of idct (macroblocks yyyy u v) -* pic: pointer to picture buffer (yuyv) -* width: picture width -*/ -void yuv422pto422(int * out,unsigned char *pic,int width) -{ - int j, k; - unsigned char *pic0, *pic1; - int *outy, *outu, *outv; - int outy1 = 0; - int outy2 = 8; - int outu1 = 0; - int outv1 = 0; - - //yyyyuv - pic0 = pic; - pic1 = pic + width; - outy = out; - outu = out + 64 * 4; - outv = out + 64 * 5; - for (j = 0; j < 4; j++) - { - for (k = 0; k < 8; k++) - { - if( k == 4) - { - outy1 += 56; - outy2 += 56; - } - *pic0++ = CLIP(outy[outy1]); //y1 line 1 - *pic0++ = CLIP(128 + outu[outu1]); //u line 1 - *pic0++ = CLIP(outy[outy1+1]); //y2 line 1 - *pic0++ = CLIP(128 + outv[outv1]); //v line 1 - *pic1++ = CLIP(outy[outy2]); //y1 line 2 - *pic1++ = CLIP(128 + outu[outu1+8]);//u line 2 - *pic1++ = CLIP(outy[outy2+1]); //y2 line 2 - *pic1++ = CLIP(128 + outv[outv1+8]);//v line 2 - outv1 += 1; outu1 += 1; - outy1 +=2; outy2 +=2; - } - outy += 16;outu +=8; outv +=8; - outv1 = 0; outu1=0; - outy1 = 0; - outy2 = 8; - pic0 += 2 * (width -16); - pic1 += 2 * (width -16); - } -} - -void yuv420pto420sp(int * out, addr *pic, int width) -{ - int j, k; - unsigned char *pic0, *pic1, *uv; - int *outy, *outu, *outv; - int *outy1 ; - int *outy2 ; - int *outu1 ; - int *outv1 ; - - pic0 = pic->y; - pic1 = pic->y + width; - uv = pic->v; - outy = out; - outu = out + 64 * 4; - outv = out + 64 * 5; - - for (j = 0; j < 8; j++) - { - outy1 = outy; - outy2 = outy+8; - outv1 = outv; - outu1 = outu; - - { - asm volatile( - "mov r0,#0 \n\t" - "vdup.u32 d30, r0 \n\t" - "mov r0,#255 \n\t" - "vdup.u32 d31, r0 \n\t" - - /*** line1 ***/ - "mov r0, #256 @256=64*4\n\t" - "vld4.32 {d26,d27,d28,d29}, [%[outy1]], r0 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic0]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic0]]! \n\t" - - /*** mb 2 ***/ - "vld4.32 {d26,d27,d28,d29}, [%[outy1]] \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic0]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic0]]! \n\t" - - /*** line2 ***/ - "vld4.32 {d26,d27,d28,d29}, [%[outy2]],r0 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic1]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic1]]! \n\t" - - /*** mb2 ***/ - "vld4.32 {d26,d27,d28,d29}, [%[outy2]] \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic1]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic1]]! \n\t" - - /*** uv ***/ - "mov r0, #16 @16=4*4 \n\t" - "vld4.32 {d22,d24,d26,d28}, [%[outv1]], r0 \n\t" - "vld4.32 {d23,d25,d27,d29}, [%[outu1]], r0 \n\t" - - "mov r0, #128 \n\t" - "vdup.u32 d30, r0 \n\t" - "vqadd.s32 d22, d22, d30 \n\t" - "vqadd.s32 d23, d23, d30 \n\t" - "vqadd.s32 d24, d24, d30 \n\t" - "vqadd.s32 d25, d25, d30 \n\t" - "vqadd.s32 d26, d26, d30 \n\t" - "vqadd.s32 d27, d27, d30 \n\t" - "vqadd.s32 d28, d28, d30 \n\t" - "vqadd.s32 d29, d29, d30 \n\t" - - "mov r0, #0 \n\t" - "vdup.u32 d30, r0 \n\t" - - "vmax.s32 d22, d22, d30 \n\t" - "vmin.s32 d22, d22, d31 \n\t" - "vmax.s32 d24, d24, d30 \n\t" - "vmin.s32 d24, d24, d31 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - - "vmax.s32 d23, d23, d30 \n\t" - "vmin.s32 d23, d23, d31 \n\t" - "vmax.s32 d25, d25, d30 \n\t" - "vmin.s32 d25, d25, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - - "vst4.8 {d22[0],d23[0],d24[0],d25[0]}, [%[uv]]! \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[uv]]! \n\t" - "vst4.8 {d22[4],d23[4],d24[4],d25[4]}, [%[uv]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[uv]]! \n\t" - ////////////////////////////// - - "4:@end \n\t" - : [outy1] "+r" (outy1), [outy2] "+r" (outy2), - [pic0] "+r" (pic0), [pic1] "+r" (pic1), - [outu1] "+r" (outu1), [outv1] "+r" (outv1), - [uv] "+r" (uv) - : [width] "r" (width) - : "cc", "memory", "r0","q11", "q12", "q13","q14","q15" - ); - } - if(j == 3) - outy += 80; - else - outy += 16; - outu +=8; outv +=8; - pic0 += 2 * (width - 8); - pic1 += 2 * (width - 8); - uv += width - 16; - } -} - -void yuv420pto420p(int * out, addr *pic, int width) -{ - int j, k; - unsigned char *pic0, *pic1, *u, *v; - int *outy, *outu, *outv; - int *outy1 ; - int *outy2 ; - int *outu1 ; - int *outv1 ; - - pic0 = pic->y; - pic1 = pic->y + width; - v = pic->v; - u = pic->u; - outy = out; - outu = out + 64 * 4; - outv = out + 64 * 5; - - for (j = 0; j < 8; j++) - { - outy1 = outy; - outy2 = outy+8; - outv1 = outv; - outu1 = outu; - - { - asm volatile( - "mov r0,#0 \n\t" - "vdup.u32 d30, r0 \n\t" - "mov r0,#255 \n\t" - "vdup.u32 d31, r0 \n\t" - - /*** line1 ***/ - "mov r0, #256 @256=64*4\n\t" - "vld4.32 {d26,d27,d28,d29}, [%[outy1]], r0 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic0]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic0]]! \n\t" - - /*** mb 2 ***/ - "vld4.32 {d26,d27,d28,d29}, [%[outy1]] \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic0]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic0]]! \n\t" - - /*** line2 ***/ - "vld4.32 {d26,d27,d28,d29}, [%[outy2]],r0 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic1]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic1]]! \n\t" - - /*** mb2 ***/ - "vld4.32 {d26,d27,d28,d29}, [%[outy2]] \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic1]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic1]]! \n\t" - - /*** uv ***/ - "mov r0, #16 @16=4*4 \n\t" - "vld4.32 {d22,d23,d24,d25}, [%[outv1]], r0 \n\t" - "vld4.32 {d26,d27,d28,d29}, [%[outu1]], r0 \n\t" - - "mov r0, #128 \n\t" - "vdup.u32 d30, r0 \n\t" - "vqadd.s32 d22, d22, d30 \n\t" - "vqadd.s32 d23, d23, d30 \n\t" - "vqadd.s32 d24, d24, d30 \n\t" - "vqadd.s32 d25, d25, d30 \n\t" - "vqadd.s32 d26, d26, d30 \n\t" - "vqadd.s32 d27, d27, d30 \n\t" - "vqadd.s32 d28, d28, d30 \n\t" - "vqadd.s32 d29, d29, d30 \n\t" - - "mov r0, #0 \n\t" - "vdup.u32 d30, r0 \n\t" - - "vmax.s32 d22, d22, d30 \n\t" - "vmin.s32 d22, d22, d31 \n\t" - "vmax.s32 d23, d23, d30 \n\t" - "vmin.s32 d23, d23, d31 \n\t" - "vmax.s32 d24, d24, d30 \n\t" - "vmin.s32 d24, d24, d31 \n\t" - "vmax.s32 d25, d25, d30 \n\t" - "vmin.s32 d25, d25, d31 \n\t" - - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - - "vst4.8 {d22[0],d23[0],d24[0],d25[0]}, [%[v]]! \n\t" - "vst4.8 {d22[4],d23[4],d24[4],d25[4]}, [%[v]]! \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[u]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[u]]! \n\t" - ////////////////////////////// - - "4:@end \n\t" - : [outy1] "+r" (outy1), [outy2] "+r" (outy2), - [pic0] "+r" (pic0), [pic1] "+r" (pic1), - [outu1] "+r" (outu1), [outv1] "+r" (outv1), - [u] "+r" (u), [v] "+r" (v) - : [width] "r" (width) - : "cc", "memory", "r0","q11","q12","q13","q14","q15" - ); - } - if(j == 3) - outy += 80; - else - outy += 16; - outu += 8; outv += 8; - pic0 += 2 * (width - 8); - pic1 += 2 * (width - 8); - u += width / 2 - 8; - v += width / 2 - 8; - } -} - -void yuv422pto420sp(int * out, addr *pic, int width) -{ - int j, k; - unsigned char *pic0, *pic1,*uv; - int *outy, *outu, *outv; - int *outy1 ; - int *outy2 ; - int *outu1 ; - int *outv1 ; - - //yyyyuv - pic0 = pic->y; - pic1 = pic->y + width; - uv = pic->v; - outy = out; - outu = out + 64 * 4; - outv = out + 64 * 5; - - for (j = 0; j < 4; j++) - { - outy1 = outy; - outy2 = outy+8; - outv1 = outv; - outu1 = outu; - - for (k = 0; k < 2; k++) - { - asm volatile( - "mov r0,#0 \n\t" - "vdup.u32 d30, r0 \n\t" - "mov r0,#255 \n\t" - "vdup.u32 d31, r0 \n\t" - - /////////////////////////////line1 - "mov r0, #256 @256=64*4\n\t" - "vld4.32 {d26,d27,d28,d29}, [%[outy1]], r0 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic0]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic0]]! \n\t" - - /////////////////////////////line2 - "vld4.32 {d26,d27,d28,d29}, [%[outy2]],r0 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic1]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic1]]! \n\t" - - //////////////////////////////uv - "mov r0, #16 @16=4*4 \n\t" - "vld4.32 {d22,d24,d26,d28}, [%[outv1]], r0 \n\t" - "vld4.32 {d23,d25,d27,d29}, [%[outu1]], r0 \n\t" - - "mov r0, #128 \n\t" - "vdup.u32 d30, r0 \n\t" - "vqadd.s32 d22, d22, d30 \n\t" - "vqadd.s32 d23, d23, d30 \n\t" - "vqadd.s32 d24, d24, d30 \n\t" - "vqadd.s32 d25, d25, d30 \n\t" - "vqadd.s32 d26, d26, d30 \n\t" - "vqadd.s32 d27, d27, d30 \n\t" - "vqadd.s32 d28, d28, d30 \n\t" - "vqadd.s32 d29, d29, d30 \n\t" - - "mov r0, #0 \n\t" - "vdup.u32 d30, r0 \n\t" - - "vmax.s32 d22, d22, d30 \n\t" - "vmin.s32 d22, d22, d31 \n\t" - "vmax.s32 d24, d24, d30 \n\t" - "vmin.s32 d24, d24, d31 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - - "vmax.s32 d23, d23, d30 \n\t" - "vmin.s32 d23, d23, d31 \n\t" - "vmax.s32 d25, d25, d30 \n\t" - "vmin.s32 d25, d25, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - - "vst4.8 {d22[0],d23[0],d24[0],d25[0]}, [%[uv]]! \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[uv]]! \n\t" - ////////////////////////////// - - "4:@end \n\t" - : [outy1] "+r" (outy1), [outy2] "+r" (outy2), - [pic0] "+r" (pic0), [pic1] "+r" (pic1), - [outu1] "+r" (outu1), [outv1] "+r" (outv1), - [uv] "+r" (uv) - : [width] "r" (width) - : "cc", "memory", "r0","q11","q12","q13","q14","q15" - ); - } - outy += 16;outu +=8; outv +=8; - pic0 += 2 * (width - 8); - pic1 += 2 * (width - 8); - uv += width - 16; - } -} - -void yuv422pto420p(int * out, addr *pic, int width) -{ - int j, k; - unsigned char *pic0, *pic1,*v,*u; - int *outy, *outu, *outv; - int *outy1 ; - int *outy2 ; - int *outu1 ; - int *outv1 ; - - //yyyyuv - pic0 = pic->y; - pic1 = pic->y + width; - v = pic->v; - u = pic->u; - outy = out; - outu = out + 64 * 4; - outv = out + 64 * 5; - for (j = 0; j < 4; j++) - { - outy1 = outy; - outy2 = outy+8; - outv1 = outv; - outu1 = outu; - - for (k = 0; k < 2; k++) - { - asm volatile( - "mov r0,#0 \n\t" - "vdup.u32 d30, r0 \n\t" - "mov r0,#255 \n\t" - "vdup.u32 d31, r0 \n\t" - - /////////////////////////////line1 - "mov r0, #256 @256=64*4\n\t" - "vld4.32 {d26,d27,d28,d29}, [%[outy1]], r0 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic0]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic0]]! \n\t" - - /////////////////////////////line2 - "vld4.32 {d26,d27,d28,d29}, [%[outy2]],r0 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[pic1]]! \n\t" - "vst4.8 {d26[4],d27[4],d28[4],d29[4]}, [%[pic1]]! \n\t" - - //////////////////////////////uv - "mov r0, #16 @16=4*4 \n\t" - "vld4.32 {d22,d23,d24,d25}, [%[outv1]], r0 \n\t" - "vld4.32 {d26,d27,d28,d29}, [%[outu1]], r0 \n\t" - - "mov r0, #128 \n\t" - "vdup.u32 d30, r0 \n\t" - "vqadd.s32 d22, d22, d30 \n\t" - "vqadd.s32 d23, d23, d30 \n\t" - "vqadd.s32 d24, d24, d30 \n\t" - "vqadd.s32 d25, d25, d30 \n\t" - "vqadd.s32 d26, d26, d30 \n\t" - "vqadd.s32 d27, d27, d30 \n\t" - "vqadd.s32 d28, d28, d30 \n\t" - "vqadd.s32 d29, d29, d30 \n\t" - - "mov r0, #0 \n\t" - "vdup.u32 d30, r0 \n\t" - - "vmax.s32 d22, d22, d30 \n\t" - "vmin.s32 d22, d22, d31 \n\t" - "vmax.s32 d24, d24, d30 \n\t" - "vmin.s32 d24, d24, d31 \n\t" - "vmax.s32 d26, d26, d30 \n\t" - "vmin.s32 d26, d26, d31 \n\t" - "vmax.s32 d28, d28, d30 \n\t" - "vmin.s32 d28, d28, d31 \n\t" - - "vmax.s32 d23, d23, d30 \n\t" - "vmin.s32 d23, d23, d31 \n\t" - "vmax.s32 d25, d25, d30 \n\t" - "vmin.s32 d25, d25, d31 \n\t" - "vmax.s32 d27, d27, d30 \n\t" - "vmin.s32 d27, d27, d31 \n\t" - "vmax.s32 d29, d29, d30 \n\t" - "vmin.s32 d29, d29, d31 \n\t" - - "vst4.8 {d22[0],d23[0],d24[0],d25[0]}, [%[v]]! \n\t" - "vst4.8 {d26[0],d27[0],d28[0],d29[0]}, [%[u]]! \n\t" - ////////////////////////////// - "4:@end \n\t" - : [outy1] "+r" (outy1), [outy2] "+r" (outy2), - [pic0] "+r" (pic0), [pic1] "+r" (pic1), - [outu1] "+r" (outu1), [outv1] "+r" (outv1), - [v] "+r" (v),[u] "+r" (u) - : [width] "r" (width) - : "cc", "memory", "r0","q11", "q12", "q13","q14","q15" - ); - } - outy += 16;outu +=8; outv +=8; - pic0 += 2 * (width - 8); - pic1 += 2 * (width - 8); - v += width/2 - 8; - u += width/2 - 8; - } -} - -/*use in utils.c for jpeg decoding 444 planar to 422 -* args: -* out: pointer to data output of idct (macroblocks yyyy u v) -* pic: pointer to picture buffer (yuyv) -* width: picture width -*/ -void yuv444pto422(int * out,unsigned char *pic,int width) -{ - int j, k; - unsigned char *pic0, *pic1; - int *outy, *outu, *outv; - int outy1 = 0; - int outy2 = 8; - int outu1 = 0; - int outv1 = 0; - - //yyyyuv - pic0 = pic; - pic1 = pic + width; - outy = out; - outu = out + 64 * 4; // Ooops where did i invert ?? - outv = out + 64 * 5; - for (j = 0; j < 4; j++) - { - for (k = 0; k < 4; k++) - { - *pic0++ =CLIP( outy[outy1]); //y1 line 1 - *pic0++ =CLIP( 128 + outu[outu1]); //u line 1 - *pic0++ =CLIP( outy[outy1+1]); //y2 line 1 - *pic0++ =CLIP( 128 + outv[outv1]); //v line 1 - *pic1++ =CLIP( outy[outy2]); //y1 line 2 - *pic1++ =CLIP( 128 + outu[outu1+8]);//u line 2 - *pic1++ =CLIP( outy[outy2+1]); //y2 line 2 - *pic1++ =CLIP( 128 + outv[outv1+8]);//v line 2 - outv1 += 2; outu1 += 2; - outy1 +=2; outy2 +=2; - } - outy += 16;outu +=16; outv +=16; - outv1 = 0; outu1=0; - outy1 = 0; - outy2 = 8; - pic0 += 2 * (width -8); - pic1 += 2 * (width -8); - } -} - -/*use in utils.c for jpeg decoding 400 planar to 422 -* args: -* out: pointer to data output of idct (macroblocks yyyy ) -* pic: pointer to picture buffer (yuyv) -* width: picture width -*/ -void yuv400pto422(int * out,unsigned char *pic,int width) -{ - int j, k; - unsigned char *pic0, *pic1; - int *outy ; - int outy1 = 0; - int outy2 = 8; - pic0 = pic; - pic1 = pic + width; - outy = out; - - //yyyy - for (j = 0; j < 4; j++) - { - for (k = 0; k < 4; k++) - { - *pic0++ = CLIP(outy[outy1]); //y1 line 1 - *pic0++ = 128 ; //u - *pic0++ = CLIP(outy[outy1+1]);//y2 line 1 - *pic0++ = 128 ; //v - *pic1++ = CLIP(outy[outy2]); //y1 line 2 - *pic1++ = 128 ; //u - *pic1++ = CLIP(outy[outy2+1]);//y2 line 2 - *pic1++ = 128 ; //v - outy1 +=2; outy2 +=2; - } - outy += 16; - outy1 = 0; - outy2 = 8; - pic0 += 2 * (width -8); - pic1 += 2 * (width -8); - } -} - diff --git a/mjpeg/jpegdec.c b/mjpeg/jpegdec.c deleted file mode 100755 index fb9400d..0000000 --- a/mjpeg/jpegdec.c +++ b/dev/null @@ -1,1040 +0,0 @@ -/*******************************************************************************# -# guvcview http://guvcview.sourceforge.net # -# # -# Paulo Assis # -# Nobuhiro Iwamatsu # -# Add UYVY color support(Macbook iSight) # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -********************************************************************************/ - -/*******************************************************************************# -# # -# MJpeg decoding and frame capture taken from luvcview # -# # -# # -********************************************************************************/ - -/* support for internationalization - i18n */ -//#define LOG_NDEBUG 0 -#define LOG_TAG "CameraHAL_MJPEGDecode" -//reinclude because of a bug with the log macros -#include -#include "DebugUtils.h" -#include "jutils.h" -#include "huffman.h" -#include "colorspaces.h" -#include - -/*********************************/ - -static int huffman_init(void); - -static void decode_mcus - __P((struct in *, int *, int, struct scan *, int *)); - -static int dec_readmarker __P((struct in *)); - -static void dec_makehuff - __P((struct dec_hufftbl *, int *, BYTE *)); - -static void setinput __P((struct in *, BYTE *)); -/*********************************/ - -#undef PREC -#define PREC int - -static void idctqtab __P((BYTE *, PREC *)); - -inline static void idct(int *in, int *out, int *quant, long off, int max); - -/*********************************/ -//static void col221111 __P((int *, unsigned char *, int)); - -typedef void (*ftopict) (int * out, addr *pic, int width) ; - -/*********************************/ -static BYTE *datap; - -static int getbyte(void) -{ - return *datap++; -} - -static int getword(void) -{ - int c1, c2; - c1 = *datap++; - c2 = *datap++; - return c1 << 8 | c2; -} - -struct comp -{ - int cid; - int hv; - int tq; -}; - -#define MAXCOMP 4 -struct jpginfo -{ - int nc; /* number of components */ - int ns; /* number of scans */ - int dri; /* restart interval */ - int nm; /* mcus til next marker */ - int rm; /* next restart marker */ -}; - -static struct jpginfo info; -static struct comp comps[MAXCOMP]; - -static struct scan dscans[MAXCOMP]; - -static unsigned char quant[4][64]; - -static struct dec_hufftbl dhuff[4]; - -#define dec_huffdc (dhuff + 0) -#define dec_huffac (dhuff + 2) - -static struct in in; - -/*read jpeg tables (huffman and quantization) -* args: -* till: Marker (frame - SOF0 scan - SOS) -* isDHT: flag indicating the presence of huffman tables (if 0 must use default ones - MJPG frame) -*/ -static int readtables(int till, int *isDHT) -{ - int m, l, i, j, lq, pq, tq; - int tc, th, tt; - - for (;;) - { - if (getbyte() != 0xff) - return -1; - if ((m = getbyte()) == till) - break; - - switch (m) - { - case 0xc2: - return 0; - /*read quantization tables (Lqt and Cqt)*/ - case M_DQT: - lq = getword(); - while (lq > 2) - { - pq = getbyte(); - /*Lqt=0x00 Cqt=0x01*/ - tq = pq & 15; - if (tq > 3) - return -1; - pq >>= 4; - if (pq != 0) - return -1; - for (i = 0; i < 64; i++) - quant[tq][i] = getbyte(); - lq -= 64 + 1; - } - break; - /*read huffman table*/ - case M_DHT: - l = getword(); - while (l > 2) - { - int hufflen[16], k; - BYTE huffvals[256]; - - tc = getbyte(); - th = tc & 15; - tc >>= 4; - tt = tc * 2 + th; - if (tc > 1 || th > 1) - return -1; - - for (i = 0; i < 16; i++) - hufflen[i] = getbyte(); - l -= 1 + 16; - k = 0; - for (i = 0; i < 16; i++) - { - for (j = 0; j < hufflen[i]; j++) - huffvals[k++] = getbyte(); - l -= hufflen[i]; - } - dec_makehuff(dhuff + tt, hufflen, huffvals); - } - /* has huffman tables defined (JPEG)*/ - *isDHT= 1; - break; - /*restart interval*/ - case M_DRI: - l = getword(); - info.dri = getword(); - break; - case 0xff: - l = getbyte(); - return 0; - default: - l = getword(); - while (l-- > 2) - getbyte(); - break; - } - } - return 0; -} - -static void dec_initscans(void) -{ - int i; - - info.nm = info.dri + 1; - info.rm = M_RST0; - for (i = 0; i < info.ns; i++) - dscans[i].dc = 0; -} - -static int dec_checkmarker(void) -{ - int i; - - if (dec_readmarker(&in) != info.rm) - return -1; - info.nm = info.dri; - info.rm = (info.rm + 1) & ~0x08; - for (i = 0; i < info.ns; i++) - dscans[i].dc = 0; - return 0; -} - -/*jpeg decode -* args: -* pic: pointer to picture data ( decoded image - yuyv format) -* buf: pointer to input data ( compressed jpeg ) -* with: picture width -* height: picture height -*/ -int jpeg_decode(BYTE **pic, BYTE *buf, int width, int height, unsigned int outformat) -{ - struct jpeg_decdata *decdata; - int i=0, j=0, m=0, tac=0, tdc=0; - int intwidth=0, intheight=0; - int mcusx=0, mcusy=0, mx=0, my=0; - int ypitch=0 ,xpitch=0,bpp=0,pitch=0,x=0,y=0; - int mb=0; - int max[6]; - ftopict convert; - int err = 0; - int isInitHuffman = 0; - int mb_x,mb_y; - int mc_x,mc_y; - int down_sampling = 1; - decdata = (struct jpeg_decdata *)malloc(sizeof(struct jpeg_decdata)); - memset(&info,0x0,sizeof(info)); - for(i=0;i<6;i++) - max[i]=0; - - if (!decdata) - { - err = -1; - goto error; - } - if ((buf == NULL)||(*pic == NULL)) - { - err = -1; - goto error; - } - datap = buf; - /*check SOI (0xFFD8)*/ - if (getbyte() != 0xff) - { - err = ERR_NO_SOI; - goto error; - } - if (getbyte() != M_SOI) - { - err = ERR_NO_SOI; - goto error; - } - /*read tables - if exist, up to start frame marker (0xFFC0)*/ - if (readtables(M_SOF0, &isInitHuffman)) - { - err = ERR_BAD_TABLES; - goto error; - } - getword(); /*header lenght*/ - i = getbyte(); /*precision (8 bit)*/ - if (i != 8) - { - err = ERR_NOT_8BIT; - goto error; - } - intheight = getword(); /*height*/ - intwidth = getword(); /*width */ - if ((intheight & 7) || (intwidth & 7)) /*must be even*/ - { - err = ERR_BAD_WIDTH_OR_HEIGHT; - goto error; - } - info.nc = getbyte(); /*number of components*/ - if (info.nc > MAXCOMP) - { - err = ERR_TOO_MANY_COMPPS; - goto error; - } - /*for each component*/ - for (i = 0; i < info.nc; i++) - { - int h, v; - comps[i].cid = getbyte(); /*component id*/ - comps[i].hv = getbyte(); - v = comps[i].hv & 15; /*vertical sampling */ - h = comps[i].hv >> 4; /*horizontal sampling */ - comps[i].tq = getbyte(); /*quantization table used*/ - if (h > 3 || v > 3) - { - err = ERR_ILLEGAL_HV; - goto error; - } - if (comps[i].tq > 3) - { - err = ERR_QUANT_TABLE_SELECTOR; - goto error; - } - } - /*read tables - if exist, up to start of scan marker (0xFFDA)*/ - if (readtables(M_SOS,&isInitHuffman)) - { - err = ERR_BAD_TABLES; - goto error; - } - getword(); /* header lenght */ - info.ns = getbyte(); /* number of scans */ - if (!info.ns) - { - err = ERR_NOT_YCBCR_221111; - goto error; - } - /*for each scan*/ - for (i = 0; i < info.ns; i++) - { - dscans[i].cid = getbyte(); /*component id*/ - tdc = getbyte(); - tac = tdc & 15; /*ac table*/ - tdc >>= 4; /*dc table*/ - if (tdc > 1 || tac > 1) - { - err = ERR_QUANT_TABLE_SELECTOR; - goto error; - } - for (j = 0; j < info.nc; j++) - if (comps[j].cid == dscans[i].cid) - break; - if (j == info.nc) - { - err = ERR_UNKNOWN_CID_IN_SCAN; - goto error; - } - dscans[i].hv = comps[j].hv; - dscans[i].tq = comps[j].tq; - dscans[i].hudc.dhuff = dec_huffdc + tdc; - dscans[i].huac.dhuff = dec_huffac + tac; - } - - i = getbyte(); /*0 */ - j = getbyte(); /*63*/ - m = getbyte(); /*0 */ - - if (i != 0 || j != 63 || m != 0) - { - CAMHAL_LOGDA("hmm FW error,not seq DCT ??\n"); - } - - /*build huffman tables*/ - if(!isInitHuffman) - { - if(huffman_init() < 0) - return -ERR_BAD_TABLES; - } - /* - if (dscans[0].cid != 1 || dscans[1].cid != 2 || dscans[2].cid != 3) - { - err = ERR_NOT_YCBCR_221111; - goto error; - } - - if (dscans[1].hv != 0x11 || dscans[2].hv != 0x11) - { - err = ERR_NOT_YCBCR_221111; - goto error; - } - */ - /* if internal width and external are not the same or heigth too - and pic not allocated realloc the good size and mark the change - need 1 macroblock line more ?? */ - if (intwidth != width) - { - err = ERR_WIDTH_MISMATCH; - goto error; - } - - if (intheight != height) - { - err = ERR_HEIGHT_MISMATCH; - goto error; - } - - switch (dscans[0].hv) - { - case 0x22: // 411 - mb=6; - mcusx = width >> 4; - mcusy = height >> 4; - bpp=2; - xpitch = 16 * bpp; - pitch = width * bpp; // YUYV out - ypitch = 16 * pitch; - mb_x = 16; - mb_y = 16; - mc_y = 8; - if(outformat == V4L2_PIX_FMT_NV21){ - convert = yuv420pto420sp; //choose the right conversion function - mc_x = 16; - down_sampling = 1; - }else{ - convert = yuv420pto420p; - mc_x = 8; - down_sampling = 2; - } - break; - case 0x21: //422 - mb=4; - mcusx = width >> 4; - mcusy = height >> 3; - bpp=2; - xpitch = 16 * bpp; - pitch = width * bpp; // YUYV out - ypitch = 8 * pitch; - mb_x = 16; - mb_y = 8; - mc_y = 8; - if(outformat == V4L2_PIX_FMT_NV21){ - convert = yuv422pto420sp; //choose the right conversion function - mc_x = 16; - down_sampling = 2; - }else{ - convert = yuv422pto420p; - mc_x = 8; - down_sampling = 4; - } - break; - case 0x11: //444 - mcusx = width >> 3; - mcusy = height >> 3; - bpp=2; - xpitch = 8 * bpp; - pitch = width * bpp; // YUYV out - ypitch = 8 * pitch; - if (info.ns==1) - { - mb = 1; - //convert = yuv400pto422; //choose the right conversion function - CAMHAL_LOGEA("Format YUV400 Not Supproted"); - } - else - { - mb=3; - //convert = yuv444pto422; //choose the right conversion function - CAMHAL_LOGEA("Format YUV444 Not Supproted"); - } - err = ERR_NOT_SUPPORTED; - goto error; - break; - default: - err = ERR_NOT_YCBCR_221111; - goto error; - break; - } - - addr paddr; - idctqtab(quant[dscans[0].tq], decdata->dquant[0]); - idctqtab(quant[dscans[1].tq], decdata->dquant[1]); - idctqtab(quant[dscans[2].tq], decdata->dquant[2]); - setinput(&in, datap); - dec_initscans(); - - dscans[0].next = 2; - dscans[1].next = 1; - dscans[2].next = 0; /* 4xx encoding */ - for (my = 0,y=0; my < mcusy; my++,y+=ypitch) - { - for (mx = 0,x=0; mx < mcusx; mx++,x+=xpitch) - { - if (info.dri && !--info.nm){ - if (dec_checkmarker()) - { - err = ERR_WRONG_MARKER; - goto error; - } - } - switch (mb) - { - case 6: - decode_mcus(&in, decdata->dcts, mb, dscans, max); - idct(decdata->dcts, decdata->out, decdata->dquant[0], - IFIX(128.5), max[0]); - idct(decdata->dcts + 64, decdata->out + 64, - decdata->dquant[0], IFIX(128.5), max[1]); - idct(decdata->dcts + 128, decdata->out + 128, - decdata->dquant[0], IFIX(128.5), max[2]); - idct(decdata->dcts + 192, decdata->out + 192, - decdata->dquant[0], IFIX(128.5), max[3]); - idct(decdata->dcts + 256, decdata->out + 256, - decdata->dquant[1], IFIX(0.5), max[4]); - idct(decdata->dcts + 320, decdata->out + 320, - decdata->dquant[2], IFIX(0.5), max[5]); - break; - - case 4: - decode_mcus(&in, decdata->dcts, mb, dscans, max); - idct(decdata->dcts, decdata->out, decdata->dquant[0], - IFIX(128.5), max[0]); - idct(decdata->dcts + 64, decdata->out + 64, - decdata->dquant[0], IFIX(128.5), max[1]); - idct(decdata->dcts + 128, decdata->out + 256, - decdata->dquant[1], IFIX(0.5), max[4]); - idct(decdata->dcts + 192, decdata->out + 320, - decdata->dquant[2], IFIX(0.5), max[5]); - break; - - case 3: - decode_mcus(&in, decdata->dcts, mb, dscans, max); - idct(decdata->dcts, decdata->out, decdata->dquant[0], - IFIX(128.5), max[0]); - idct(decdata->dcts + 64, decdata->out + 256, - decdata->dquant[1], IFIX(0.5), max[4]); - idct(decdata->dcts + 128, decdata->out + 320, - decdata->dquant[2], IFIX(0.5), max[5]); - break; - - case 1: - decode_mcus(&in, decdata->dcts, mb, dscans, max); - idct(decdata->dcts, decdata->out, decdata->dquant[0], - IFIX(128.5), max[0]); - break; - } // switch enc411 - - paddr.y = *pic + my * width * mb_y + mx * mb_x; - paddr.v = *pic + width * height + my * width * mc_y / down_sampling + mx * mc_x; - paddr.u = *pic + width * height*5/4 + my * width * mc_y / down_sampling + mx * mc_x; - convert(decdata->out,&paddr,width); - } - } -#if 0 - m = dec_readmarker(&in); - if (m != M_EOI) - { - err = ERR_NO_EOI; - goto error; - } -#endif - free(decdata); - return 0; -error: - CAMHAL_LOGDB("decode failed:%d",err); - free(decdata); - return err; -} - -/****************************************************************/ -/************** huffman decoder ***************/ -/****************************************************************/ -static int huffman_init(void) -{ - int tc, th, tt; - unsigned char *ptr= (unsigned char *) JPEGHuffmanTable ; - int i, j, l; - l = JPG_HUFFMAN_TABLE_LENGTH ; - while (l > 0) - { - int hufflen[16], k; - unsigned char huffvals[256]; - - tc = *ptr++; - th = tc & 15; - tc >>= 4; - tt = tc * 2 + th; - if (tc > 1 || th > 1) - return -ERR_BAD_TABLES; - for (i = 0; i < 16; i++) - hufflen[i] = *ptr++; - l -= 1 + 16; - k = 0; - for (i = 0; i < 16; i++) - { - for (j = 0; j < hufflen[i]; j++) - huffvals[k++] = *ptr++; - l -= hufflen[i]; - } - dec_makehuff(dhuff + tt, hufflen, huffvals); - } - return 0; -} - -static int fillbits __P((struct in *, int, unsigned int)); -static int dec_rec2 -__P((struct in *, struct dec_hufftbl *, int *, int, int)); - -static void setinput(in, p) -struct in *in; -unsigned char *p; -{ - in->p = p; - in->left = 0; - in->bits = 0; - in->marker = 0; -} - -static int fillbits(in, le, bi) -struct in *in; -int le; -unsigned int bi; -{ - int b, m; - - if (in->marker) - { - if (le <= 16) - in->bits = bi << 16, le += 16; - return le; - } - while (le <= 24) - { - b = *in->p++; - if (b == 0xff && (m = *in->p++) != 0) - { - if (m == M_EOF) - { - if (in->func && (m = in->func(in->data)) == 0) - continue; - } - in->marker = m; - if (le <= 16) - bi = bi << 16, le += 16; - break; - } - bi = bi << 8 | b; - le += 8; - } - in->bits = bi; /* tmp... 2 return values needed */ - return le; -} - -static int dec_readmarker(in) -struct in *in; -{ - int m; - - in->left = fillbits(in, in->left, in->bits); - if ((m = in->marker) == 0) - return 0; - in->left = 0; - in->marker = 0; - return m; -} - -#define LEBI_DCL int le, bi -#define LEBI_GET(in) (le = in->left, bi = in->bits) -#define LEBI_PUT(in) (in->left = le, in->bits = bi) - -#define GETBITS(in, n) ( \ - (le < (n) ? le = fillbits(in, le, bi), bi = in->bits : 0), \ - (le -= (n)), \ - bi >> le & ((1 << (n)) - 1) \ -) - -#define UNGETBITS(in, n) ( \ - le += (n) \ -) - - -static int dec_rec2(in, hu, runp, c, i) - struct in *in; - struct dec_hufftbl *hu; - int *runp; - int c, i; -{ - LEBI_DCL; - - LEBI_GET(in); - if (i) - { - UNGETBITS(in, i & 127); - *runp = i >> 8 & 15; - i >>= 16; - } - else - { - for (i = DECBITS; - (c = ((c << 1) | GETBITS(in, 1))) >= (hu->maxcode[i]); i++); - if (i >= 16) - { - in->marker = M_BADHUFF; - return 0; - } - i = hu->vals[hu->valptr[i] + c - hu->maxcode[i - 1] * 2]; - *runp = i >> 4; - i &= 15; - } - if (i == 0) - { /* sigh, 0xf0 is 11 bit */ - LEBI_PUT(in); - return 0; - } - /* receive part */ - c = GETBITS(in, i); - if (c < (1 << (i - 1))) - c += (-1 << i) + 1; - LEBI_PUT(in); - return c; -} - -#define DEC_REC(in, hu, r, i) ( \ - r = GETBITS(in, DECBITS), \ - i = hu->llvals[r], \ - i & 128 ? \ - ( \ - UNGETBITS(in, i & 127), \ - r = i >> 8 & 15, \ - i >> 16 \ - ) \ - : \ - ( \ - LEBI_PUT(in), \ - i = dec_rec2(in, hu, &r, r, i), \ - LEBI_GET(in), \ - i \ - ) \ -) - -static void decode_mcus(in, dct, n, sc, maxp) - struct in *in; - int *dct; - int n; - struct scan *sc; - int *maxp; -{ - struct dec_hufftbl *hu; - int i = 0, r = 0, t = 0; - LEBI_DCL; - - memset(dct, 0, n * 64 * sizeof(*dct)); - LEBI_GET(in); - while (n-- > 0) - { - hu = sc->hudc.dhuff; - *dct++ = (sc->dc += DEC_REC(in, hu, r, t)); - - hu = sc->huac.dhuff; - i = 63; - while (i > 0) - { - t = DEC_REC(in, hu, r, t); - if (t == 0 && r == 0) - { - dct += i; - break; - } - dct += r; - *dct++ = t; - i -= r + 1; - } - *maxp++ = 64 - i; - if (n == sc->next) - sc++; - } - LEBI_PUT(in); -} - -static void dec_makehuff(hu, hufflen, huffvals) - struct dec_hufftbl *hu; - int *hufflen; - unsigned char *huffvals; -{ - int code, k, i, j, d, x, c, v; - for (i = 0; i < (1 << DECBITS); i++) - hu->llvals[i] = 0; - - /* - * llvals layout: - * - * value v already known, run r, backup u bits: - * vvvvvvvvvvvvvvvv 0000 rrrr 1 uuuuuuu - * value unknown, size b bits, run r, backup u bits: - * 000000000000bbbb 0000 rrrr 0 uuuuuuu - * value and size unknown: - * 0000000000000000 0000 0000 0 0000000 - */ - code = 0; - k = 0; - for (i = 0; i < 16; i++, code <<= 1) - { /* sizes */ - hu->valptr[i] = k; - for (j = 0; j < hufflen[i]; j++) - { - hu->vals[k] = *huffvals++; - if (i < DECBITS) - { - c = code << (DECBITS - 1 - i); - v = hu->vals[k] & 0x0f; /* size */ - for (d = 1 << (DECBITS - 1 - i); --d >= 0;) - { - if (v + i < DECBITS) - { /* both fit in table */ - x = d >> (DECBITS - 1 - v - i); - if (v && x < (1 << (v - 1))) - x += (-1 << v) + 1; - x = x << 16 | (hu->vals[k] & 0xf0) << 4 | - (DECBITS - (i + 1 + v)) | 128; - } - else - x = v << 16 | (hu->vals[k] & 0xf0) << 4 | - (DECBITS - (i + 1)); - hu->llvals[c | d] = x; - } - } - code++; - k++; - } - hu->maxcode[i] = code; - } - hu->maxcode[16] = 0x20000; /* always terminate decode */ -} - -/****************************************************************/ -/************** idct ***************/ -/****************************************************************/ - -#define IMULT(a, b) (((a) * (b)) >> ISHIFT) -#define ITOINT(a) ((a) >> ISHIFT) - -#define S22 ((PREC)IFIX(2 * 0.382683432)) -#define C22 ((PREC)IFIX(2 * 0.923879532)) -#define IC4 ((PREC)IFIX(1 / 0.707106781)) - -//zigzag order used by idct -static unsigned char zig2[64] = { - 0, 2, 3, 9, 10, 20, 21, 35, - 14, 16, 25, 31, 39, 46, 50, 57, - 5, 7, 12, 18, 23, 33, 37, 48, - 27, 29, 41, 44, 52, 55, 59, 62, - 15, 26, 30, 40, 45, 51, 56, 58, - 1, 4, 8, 11, 19, 22, 34, 36, - 28, 42, 43, 53, 54, 60, 61, 63, - 6, 13, 17, 24, 32, 38, 47, 49 -}; - -/*inverse dct for jpeg decoding -* args: -* in: pointer to input data ( mcu - after huffman decoding) -* out: pointer to data with output of idct (to be filled) -* quant: pointer to quantization data tables -* off: offset value (128.5 or 0.5) -* max: maximum input mcu index? -*/ -inline static void idct(int *in, int *out, int *quant, long off, int max) -{ - long t0, t1, t2, t3, t4, t5, t6, t7; // t ; - long tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6; - long tmp[64], *tmpp; - int i, j, te; - unsigned char *zig2p; - - t0 = off; - if (max == 1) //single color mcu - { - t0 += in[0] * quant[0]; //only DC available - for (i = 0; i < 64; i++) // fill mcu with DC value - out[i] = ITOINT(t0); - return; - } - zig2p = zig2; - tmpp = tmp; - for (i = 0; i < 8; i++) //apply quantization table in zigzag order - { - j = *zig2p++; - t0 += in[j] * (long) quant[j]; - j = *zig2p++; - t5 = in[j] * (long) quant[j]; - j = *zig2p++; - t2 = in[j] * (long) quant[j]; - j = *zig2p++; - t7 = in[j] * (long) quant[j]; - j = *zig2p++; - t1 = in[j] * (long) quant[j]; - j = *zig2p++; - t4 = in[j] * (long) quant[j]; - j = *zig2p++; - t3 = in[j] * (long) quant[j]; - j = *zig2p++; - t6 = in[j] * (long) quant[j]; - - - if ((t1 | t2 | t3 | t4 | t5 | t6 | t7) == 0) - { - tmpp[0 * 8] = t0; //DC - tmpp[1 * 8] = t0; - tmpp[2 * 8] = t0; - tmpp[3 * 8] = t0; - tmpp[4 * 8] = t0; - tmpp[5 * 8] = t0; - tmpp[6 * 8] = t0; - tmpp[7 * 8] = t0; - - tmpp++; - t0 = 0; - continue; - } - //IDCT; - tmp0 = t0 + t1; - t1 = t0 - t1; - tmp2 = t2 - t3; - t3 = t2 + t3; - tmp2 = IMULT(tmp2, IC4) - t3; - tmp3 = tmp0 + t3; - t3 = tmp0 - t3; - tmp1 = t1 + tmp2; - tmp2 = t1 - tmp2; - tmp4 = t4 - t7; - t7 = t4 + t7; - tmp5 = t5 + t6; - t6 = t5 - t6; - tmp6 = tmp5 - t7; - t7 = tmp5 + t7; - tmp5 = IMULT(tmp6, IC4); - tmp6 = IMULT((tmp4 + t6), S22); - tmp4 = IMULT(tmp4, (C22 - S22)) + tmp6; - t6 = IMULT(t6, (C22 + S22)) - tmp6; - t6 = t6 - t7; - t5 = tmp5 - t6; - t4 = tmp4 - t5; - - tmpp[0 * 8] = tmp3 + t7; //t0; - tmpp[1 * 8] = tmp1 + t6; //t1; - tmpp[2 * 8] = tmp2 + t5; //t2; - tmpp[3 * 8] = t3 + t4; //t3; - tmpp[4 * 8] = t3 - t4; //t4; - tmpp[5 * 8] = tmp2 - t5; //t5; - tmpp[6 * 8] = tmp1 - t6; //t6; - tmpp[7 * 8] = tmp3 - t7; //t7; - tmpp++; - t0 = 0; - } - for (i = 0, j = 0; i < 8; i++) - { - t0 = tmp[j + 0]; - t1 = tmp[j + 1]; - t2 = tmp[j + 2]; - t3 = tmp[j + 3]; - t4 = tmp[j + 4]; - t5 = tmp[j + 5]; - t6 = tmp[j + 6]; - t7 = tmp[j + 7]; - if ((t1 | t2 | t3 | t4 | t5 | t6 | t7) == 0) - { - te = ITOINT(t0); - out[j + 0] = te; - out[j + 1] = te; - out[j + 2] = te; - out[j + 3] = te; - out[j + 4] = te; - out[j + 5] = te; - out[j + 6] = te; - out[j + 7] = te; - j += 8; - continue; - } - //IDCT; - tmp0 = t0 + t1; - t1 = t0 - t1; - tmp2 = t2 - t3; - t3 = t2 + t3; - tmp2 = IMULT(tmp2, IC4) - t3; - tmp3 = tmp0 + t3; - t3 = tmp0 - t3; - tmp1 = t1 + tmp2; - tmp2 = t1 - tmp2; - tmp4 = t4 - t7; - t7 = t4 + t7; - tmp5 = t5 + t6; - t6 = t5 - t6; - tmp6 = tmp5 - t7; - t7 = tmp5 + t7; - tmp5 = IMULT(tmp6, IC4); - tmp6 = IMULT((tmp4 + t6), S22); - tmp4 = IMULT(tmp4, (C22 - S22)) + tmp6; - t6 = IMULT(t6, (C22 + S22)) - tmp6; - t6 = t6 - t7; - t5 = tmp5 - t6; - t4 = tmp4 - t5; - - out[j + 0] = ITOINT(tmp3 + t7); - out[j + 1] = ITOINT(tmp1 + t6); - out[j + 2] = ITOINT(tmp2 + t5); - out[j + 3] = ITOINT(t3 + t4); - out[j + 4] = ITOINT(t3 - t4); - out[j + 5] = ITOINT(tmp2 - t5); - out[j + 6] = ITOINT(tmp1 - t6); - out[j + 7] = ITOINT(tmp3 - t7); - j += 8; - } -} - -static unsigned char zig[64] = { - 0, 1, 5, 6, 14, 15, 27, 28, - 2, 4, 7, 13, 16, 26, 29, 42, - 3, 8, 12, 17, 25, 30, 41, 43, - 9, 11, 18, 24, 31, 40, 44, 53, - 10, 19, 23, 32, 39, 45, 52, 54, - 20, 22, 33, 38, 46, 51, 55, 60, - 21, 34, 37, 47, 50, 56, 59, 61, - 35, 36, 48, 49, 57, 58, 62, 63 -}; - -//coef used in idct -static PREC aaidct[8] = { - IFIX(0.3535533906), IFIX(0.4903926402), - IFIX(0.4619397663), IFIX(0.4157348062), - IFIX(0.3535533906), IFIX(0.2777851165), - IFIX(0.1913417162), IFIX(0.0975451610) -}; - - -static void idctqtab(qin, qout) - unsigned char *qin; - PREC *qout; -{ - int i, j; - - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - qout[zig[i * 8 + j]] = qin[zig[i * 8 + j]] * - IMULT(aaidct[i], aaidct[j]); -} - -- cgit