ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

static HRESULT AVIFILE_EncodeFrame ( IAVIStreamImpl This,
LPBITMAPINFOHEADER  lpbi,
LPVOID  lpBits 
) [static]

Definition at line 752 of file icmstream.c.

Referenced by ICMStream_fnRead(), and ICMStream_fnWrite().

{
  DWORD dwMinQual, dwMaxQual, dwCurQual;
  DWORD dwRequest;
  DWORD icmFlags = 0;
  DWORD idxFlags = 0;
  BOOL  bDecreasedQual = FALSE;
  BOOL  doSizeCheck;
  BOOL  noPrev;

  /* make lKeyFrameEvery and at start a keyframe */
  if ((This->lKeyFrameEvery != 0 &&
       (This->lCurrent - This->lLastKey) >= This->lKeyFrameEvery) ||
      This->lCurrent == This->sInfo.dwStart) {
    idxFlags = AVIIF_KEYFRAME;
    icmFlags = ICCOMPRESS_KEYFRAME;
  }

  if (This->lKeyFrameEvery != 0) {
    if (This->lCurrent == This->sInfo.dwStart) {
      if (idxFlags & AVIIF_KEYFRAME) {
    /* for keyframes allow to consume all unused bytes */
    dwRequest = This->dwBytesPerFrame + This->dwUnusedBytes;
    This->dwUnusedBytes = 0;
      } else {
    /* for non-keyframes only allow something of the unused bytes to be consumed */
    DWORD tmp1 = 0;
    DWORD tmp2;

    if (This->dwBytesPerFrame >= This->dwUnusedBytes)
      tmp1 = This->dwBytesPerFrame / This->lKeyFrameEvery;
    tmp2 = (This->dwUnusedBytes + tmp1) / This->lKeyFrameEvery;

    dwRequest = This->dwBytesPerFrame - tmp1 + tmp2;
    This->dwUnusedBytes -= tmp2;
      }
    } else
      dwRequest = MAX_FRAMESIZE;
  } else {
    /* only one keyframe at start desired */
    if (This->lCurrent == This->sInfo.dwStart) {
      dwRequest = This->dwBytesPerFrame + This->dwUnusedBytes;
      This->dwUnusedBytes = 0;
    } else
      dwRequest = MAX_FRAMESIZE;
  }

  /* must we check for framesize to gain requested
   * datarate or could we trust codec? */
  doSizeCheck = (dwRequest != 0 && ((This->dwICMFlags & (VIDCF_CRUNCH|VIDCF_QUALITY)) == 0));

  dwMaxQual = dwCurQual = This->sInfo.dwQuality;
  dwMinQual = ICQUALITY_LOW;

  noPrev = TRUE;
  if ((icmFlags & ICCOMPRESS_KEYFRAME) == 0 && 
      (This->dwICMFlags & VIDCF_FASTTEMPORALC) == 0)
    noPrev = FALSE;

  do {
    DWORD   idxCkid = 0;
    DWORD   res;

    res = ICCompress(This->hic,icmFlags,This->lpbiCur,This->lpCur,lpbi,lpBits,
             &idxCkid, &idxFlags, This->lCurrent, dwRequest, dwCurQual,
             noPrev ? NULL:This->lpbiPrev, noPrev ? NULL:This->lpPrev);
    if (res == ICERR_NEWPALETTE) {
      FIXME(": codec has changed palette -- unhandled!\n");
    } else if (res != ICERR_OK)
      return AVIERR_COMPRESSOR;

    /* need to check for framesize */
    if (! doSizeCheck)
      break;

    if (dwRequest >= This->lpbiCur->biSizeImage) {
      /* frame is smaller -- try to maximize quality */
      if (dwMaxQual - dwCurQual > 10) {
    DWORD tmp = dwRequest / 8;

    if (tmp < MAX_FRAMESIZE_DIFF)
      tmp = MAX_FRAMESIZE_DIFF;

    if (tmp < dwRequest - This->lpbiCur->biSizeImage && bDecreasedQual) {
      tmp = dwCurQual;
      dwCurQual = (dwMinQual + dwMaxQual) / 2;
      dwMinQual = tmp;
      continue;
    }
      } else
    break;
    } else if (dwMaxQual - dwMinQual <= 1) {
      break;
    } else {
      dwMaxQual = dwCurQual;

      if (bDecreasedQual || dwCurQual == This->dwLastQuality)
    dwCurQual = (dwMinQual + dwMaxQual) / 2;
      else
    FIXME(": no new quality computed min=%u cur=%u max=%u last=%u\n",
          dwMinQual, dwCurQual, dwMaxQual, This->dwLastQuality);

      bDecreasedQual = TRUE;
    }
  } while (TRUE);

  /* remember some values */
  This->dwLastQuality = dwCurQual;
  This->dwUnusedBytes = dwRequest - This->lpbiCur->biSizeImage;
  if (icmFlags & ICCOMPRESS_KEYFRAME)
    This->lLastKey = This->lCurrent;

  /* Does we manage previous frame? */
  if (This->lpPrev != NULL && This->lKeyFrameEvery != 1)
    ICDecompress(This->hic, 0, This->lpbiCur, This->lpCur,
         This->lpbiPrev, This->lpPrev);

  return AVIERR_OK;
}

Generated on Fri May 25 2012 05:05:08 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.