コード例 #1
0
ファイル: mngrepair.cpp プロジェクト: d3x0r/SACK
mng_bool MY_DECL myiterchunk (mng_handle  hMNG,
                              mng_handle  hChunk,
                              mng_chunkid iChunktype,
                              mng_uint32  iChunkseq)
{
  mng_uint32  iWidth;                  /* temps for IHDR processing */
  mng_uint32  iHeight;
  mng_uint8   iBitdepth;
  mng_uint8   iColortype;
  mng_uint8   iCompression;
  mng_uint8   iFilter;
  mng_uint8   iInterlace;
  
  mng_bool    bEmpty;                  /* temps for FRAM processing */
  mng_uint8   iMode;
  mng_uint32  iNamesize;
  mng_pchar   zName;
  mng_uint8   iChangedelay;
  mng_uint8   iChangetimeout;
  mng_uint8   iChangeclipping;
  mng_uint8   iChangesyncid;
  mng_uint32  iDelay;
  mng_uint32  iTimeout;
  mng_uint8   iBoundarytype;
  mng_int32   iBoundaryl;
  mng_int32   iBoundaryr;
  mng_int32   iBoundaryt;
  mng_int32   iBoundaryb;
  mng_uint32  iCount;
  mng_uint32p pSyncids;
                                       /* get to my userdata */
  userdatap  pMydata = (userdatap)mng_get_userdata (hMNG);

  if (pMydata->hFileO)                 /* are we writing this time ? */
  {                                    /* do we need to 'forget' the TERM ? */
    if ((iChunktype == MNG_UINT_TERM) && (pMydata->bHasTERM))
      ;
    else
    {                                  /* fix JASC AS frame_type ? */
      if ((iChunktype == MNG_UINT_FRAM) && (pMydata->bIsJASC))
      {
        if ((pMydata->iError = mng_getchunk_fram (hMNG, hChunk,
                                                  &bEmpty, &iMode, &iNamesize, &zName,
                                                  &iChangedelay, &iChangetimeout,
                                                  &iChangeclipping, &iChangesyncid,
                                                  &iDelay, &iTimeout, &iBoundarytype,
                                                  &iBoundaryl, &iBoundaryr,
                                                  &iBoundaryt, &iBoundaryb,
                                                  &iCount, &pSyncids)) != 0)
        {
          fprintf (stderr, "Cannot get FRAM fields.\n");
          return MNG_FALSE;            /* stop the process ! */
        }

        if (iMode == 1)                /* really ? */
          iMode = 3;

        if ((pMydata->iError = mng_putchunk_fram (pMydata->hHandleO,
                                                  bEmpty, iMode, iNamesize, zName,
                                                  iChangedelay, iChangetimeout,
                                                  iChangeclipping, iChangesyncid,
                                                  iDelay, iTimeout, iBoundarytype,
                                                  iBoundaryl, iBoundaryr,
                                                  iBoundaryt, iBoundaryb,
                                                  iCount, pSyncids)) != 0)
        {
          fprintf (stderr, "Cannot write FRAM chunk.\n");
          return MNG_FALSE;            /* stop the process ! */
        }
      }
      else
      {
        if ((pMydata->iError = mng_copy_chunk (hMNG, hChunk, pMydata->hHandleO)) != 0)
        {
          fprintf (stderr, "Cannot copy the chunk.\n");
          return MNG_FALSE;            /* stop the process ! */
        }
      }
    }
                                       /* need to insert TERM in the proper place ? */
    if ((iChunktype == MNG_UINT_MHDR) && (pMydata->bHasTERM))
    {
      if ((pMydata->iError = mng_putchunk_term (pMydata->hHandleO,
                                                pMydata->iTermaction,
                                                pMydata->iIteraction,
                                                pMydata->iDelay,
                                                pMydata->iItermax)) != 0)
      {
        fprintf (stderr, "Cannot write TERM chunk.\n");
        return MNG_FALSE;              /* stop the process ! */
      }
    }
  }
  else                                 /* first iteration; just checking stuff */
  {
    if (iChunktype == MNG_UINT_SAVE)  /* SAVE ? */
    {
      pMydata->bHasSAVE = MNG_TRUE;    /* we got a SAVE ! */
      pMydata->bIsJASC  = MNG_FALSE;   /* so it's definitely not an invalid AS file */
    }
    else
    {                                 /* TERM ? */
      if (iChunktype == MNG_UINT_TERM)
      {                               /* is it in the wrong place ? */
        if ((pMydata->iLastchunk != MNG_UINT_MHDR) ||
            (pMydata->iLastchunk != MNG_UINT_SAVE)    )
        {
          pMydata->bHasTERM = MNG_TRUE;

          if ((pMydata->iError = mng_getchunk_term (hMNG, hChunk,
                                                    &pMydata->iTermaction,
                                                    &pMydata->iIteraction,
                                                    &pMydata->iDelay,
                                                    &pMydata->iItermax)) != 0)
          {
            fprintf (stderr, "Cannot get TERM fields.\n");
            return MNG_FALSE;          /* stop the process ! */
          }
        }
      }
      else
      {                                /* IHDR ? */
        if (iChunktype == MNG_UINT_IHDR)
        {
          if ((pMydata->iError = mng_getchunk_ihdr (hMNG, hChunk,
                                                    &iWidth, &iHeight, &iBitdepth,
                                                    &iColortype, &iCompression,
                                                    &iFilter, &iInterlace)) != 0)
          {
            fprintf (stderr, "Cannot get IHDR fields.\n");
            return MNG_FALSE;          /* stop the process ! */
          }
                                       /* is it not a typical JASC AS file */
          if ((iBitdepth != 8) || (iColortype != 6))
            pMydata->bIsJASC = MNG_FALSE;
        }
      }
    }

    pMydata->iLastchunk = iChunktype;
  }

  return MNG_TRUE;                     /* keep'm coming... */
}
コード例 #2
0
ファイル: vo_mng.c プロジェクト: 0p1pp1/mplayer
/**
 * @brief write frame to MNG file
 * @param[in] *frame the frame to write to MNG file
 * @param[in] mng libmng handle
 * @param[in] width width of canvas
 * @param[in] height height of canvas
 * @param[in] first_frame if the frame is the first one in the file
 * @return 0 on success, 1 on error
 */
static int vomng_write_frame(struct vomng_frame *frame, mng_handle mng,
                             unsigned int width, unsigned int height,
                             int first_frame)
{
    unsigned int delay_ms;

    /* determine delay */
    if (frame->next)
        delay_ms = frame->next->time_ms - frame->time_ms;
    else
        delay_ms = VOMNG_DEFAULT_DELAY_MS; /* default delay for last frame */

    /* write frame headers to MNG file */
    if (mng_putchunk_seek(mng, 0, MNG_NULL)) {
        mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing SEEK chunk failed\n");
        return 1;
    }
    if (mng_putchunk_fram(mng, MNG_FALSE,
                          /* keep canvas if not 1st frame */
                          first_frame ? MNG_FRAMINGMODE_1
                                      : MNG_FRAMINGMODE_NOCHANGE,
                          0, MNG_NULL,              /* no frame name */
                          MNG_CHANGEDELAY_DEFAULT,  /* change only delay */
                          MNG_CHANGETIMOUT_NO,
                          MNG_CHANGECLIPPING_NO,
                          MNG_CHANGESYNCID_NO,
                          delay_ms,                 /* new delay */
                          0,                        /* no new timeout */
                          0, 0, 0, 0, 0,            /* no new boundary */
                          0, 0)) {                  /* no count, no IDs */
        mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing FRAM chunk failed\n");
        return 1;
    }
    if (mng_putchunk_defi(mng, 0,                   /* no ID */
                          MNG_DONOTSHOW_VISIBLE,
                          MNG_ABSTRACT,
                          MNG_TRUE, 0, 0,           /* top left location */
                          MNG_FALSE, 0, 0, 0, 0)) { /* no clipping */
        mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing DEFI chunk failed\n");
        return 1;
    }
    if (mng_putchunk_ihdr(mng, width, height,       /* dimensions */
                          8, MNG_COLORTYPE_RGB,     /* RBG */
                          MNG_COMPRESSION_DEFLATE,
                          MNG_FILTER_ADAPTIVE,
                          MNG_INTERLACE_NONE)) {
        mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing IHDR chunk failed\n");
        return 1;
    }

    /* write frame data */
    if (mng_putchunk_idat(mng, frame->len, frame->data)) {
        mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing IDAT chunk failed\n");
        return 1;
    }

    /* write frame footers to MNG file */
    if (mng_putchunk_iend(mng)) {
        mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing IEND chunk failed\n");
        return 1;
    }

    return 0;
}