//////////////////////////////////////////////////////////////// // // CPixelsManager::ChangePixelsFormat // // JPEG <-> PNG <-> PLAIN // //////////////////////////////////////////////////////////////// bool CPixelsManager::ChangePixelsFormat ( const CPixels& oldPixels, CPixels& newPixels, EPixelsFormatType newFormat, int uiQuality ) { EPixelsFormatType oldFormat = GetPixelsFormat ( oldPixels ); if ( oldFormat == EPixelsFormat::UNKNOWN || newFormat == EPixelsFormat::UNKNOWN ) return false; if ( oldFormat == newFormat ) { // No change newPixels = oldPixels; return true; } if ( oldFormat == EPixelsFormat::PLAIN ) { // Encode uint uiWidth, uiHeight; if ( !GetPixelsSize ( oldPixels, uiWidth, uiHeight ) ) return false; if ( newFormat == EPixelsFormat::JPEG ) return JpegEncode ( uiWidth, uiHeight, uiQuality, oldPixels.GetData (), oldPixels.GetSize () - 4, newPixels.buffer ); else if ( newFormat == EPixelsFormat::PNG ) return PngEncode ( uiWidth, uiHeight, oldPixels.GetData (), oldPixels.GetSize () - 4, newPixels.buffer ); } else if ( newFormat == EPixelsFormat::PLAIN ) { // Decode if ( oldFormat == EPixelsFormat::JPEG ) { uint uiWidth, uiHeight; if ( JpegDecode ( oldPixels.GetData (), oldPixels.GetSize (), newPixels.buffer, uiWidth, uiHeight ) ) { newPixels.buffer.SetSize ( uiWidth * uiHeight * 4 + SIZEOF_PLAIN_TAIL ); return SetPlainDimensions ( newPixels, uiWidth, uiHeight ); } } else if ( oldFormat == EPixelsFormat::PNG ) { uint uiWidth, uiHeight; if ( PngDecode ( oldPixels.GetData (), oldPixels.GetSize (), newPixels.buffer, uiWidth, uiHeight ) ) { newPixels.buffer.SetSize ( uiWidth * uiHeight * 4 + SIZEOF_PLAIN_TAIL ); return SetPlainDimensions ( newPixels, uiWidth, uiHeight ); } } } else { // Recode CPixels tempPixels; if ( ChangePixelsFormat ( oldPixels, tempPixels, EPixelsFormat::PLAIN ) ) return ChangePixelsFormat ( tempPixels, newPixels, newFormat, uiQuality ); } return false; }
static int uvc_video_process_internal(struct uvc_device *dev, V4L2BUF_t *pbuf) { struct v4l2_buffer buf; int ret; memset(&buf, 0, sizeof buf); buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; buf.memory = V4L2_MEMORY_MMAP; if ((ret = ioctl(dev->fd, VIDIOC_DQBUF, &buf)) < 0) { ALOGE("Unable to dequeue buffer: %s (%d).", strerror(errno), errno); return ret; } //uvc_video_fill_buffer(dev, &buf, pbuf); //memcpy(dev->mem[buf.index], pbuf->addrVirY, pbuf->bytesused); //buf.bytesused = pbuf->bytesused; if (JpegEncode(dev, pbuf, dev->mem[buf.index], &buf.bytesused) < 0) { ALOGE("%s: JpegEncode failed.", __func__); buf.bytesused = 0; } if ((ret = ioctl(dev->fd, VIDIOC_QBUF, &buf)) < 0) { ALOGE("Unable to requeue buffer: %s (%d).", strerror(errno), errno); return ret; } return 0; }
/////////////////////////////////////////////////////////////// // // CCompressorJobQueueImpl::ProcessCommand // // // /////////////////////////////////////////////////////////////// void CCompressorJobQueueImpl::ProcessCommand ( CCompressJobData* pJobData ) { uint uiSizeX = pJobData->command.uiSizeX; uint uiSizeY = pJobData->command.uiSizeY; uint uiQuality = pJobData->command.uiQuality; const CBuffer& inBuffer = pJobData->command.buffer; CBuffer& outBuffer = pJobData->result.buffer; // JPEG compress here JpegEncode ( uiSizeX, uiSizeY, uiQuality, inBuffer.GetData (), inBuffer.GetSize (), outBuffer ); pJobData->result.status = EJobResult::SUCCESS; }