videoeditorengine/h263decoder/src/vdeimb.cpp
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 5 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 * Individual image buffer handling.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /*
       
    22  * Includes
       
    23  */
       
    24 
       
    25 
       
    26 #include "h263dConfig.h"
       
    27 #include "vdeimb.h"
       
    28 
       
    29 #include "vde.h"
       
    30 
       
    31 
       
    32 /*
       
    33  * Global functions
       
    34  */
       
    35 
       
    36 /* {{-output"vdeImbAlloc.txt"}} */
       
    37 /*
       
    38  * vdeImbAlloc
       
    39  *
       
    40  * Parameters:
       
    41  *    width                      width of the luminance image in pixels
       
    42  *    height                     height of the luminance image in pixels
       
    43  *
       
    44  * Function:
       
    45  *    This function allocates and initializes a new image buffer of
       
    46  *    requested size.
       
    47  *
       
    48  * Returns:
       
    49  *    a pointer to the created image buffer,
       
    50  *    or NULL if the function failed
       
    51  *
       
    52  *    
       
    53  */
       
    54 
       
    55 vdeImb_t *vdeImbAlloc(int width, int height, int fYuvNeeded)
       
    56 /* {{-output"vdeImbAlloc.txt"}} */
       
    57 {
       
    58    vdeImb_t *imb;
       
    59 
       
    60    imb = (vdeImb_t *) vdeMalloc(sizeof(vdeImb_t));
       
    61    if (imb == NULL)
       
    62       return NULL;
       
    63    memset(imb, 0, sizeof(vdeImb_t));
       
    64 
       
    65 
       
    66    imb->drawItem = renDriAlloc(width, height, fYuvNeeded);
       
    67    if (imb->drawItem == NULL)
       
    68       goto errRenDriAlloc;
       
    69    {
       
    70       int numMBsInPicture;
       
    71       
       
    72       numMBsInPicture = width * height / 256;
       
    73 
       
    74       imb->yQuantParams = (int *) vdeMalloc(numMBsInPicture * sizeof(int));
       
    75       if (imb->yQuantParams == NULL)
       
    76          goto errYQuantParams;
       
    77 
       
    78       imb->uvQuantParams = (int *) vdeMalloc(numMBsInPicture * sizeof(int));
       
    79       if (imb->uvQuantParams == NULL)
       
    80          goto errUVQuantParams;
       
    81 
       
    82    }
       
    83 
       
    84    return imb;
       
    85 
       
    86    /* Error situations: release everything in reverse order */
       
    87 
       
    88 errUVQuantParams:
       
    89 
       
    90       vdeDealloc(imb->yQuantParams);
       
    91 errYQuantParams:
       
    92 
       
    93       renDriFree(imb->drawItem);
       
    94 
       
    95 errRenDriAlloc:
       
    96 
       
    97    vdeDealloc(imb);
       
    98 
       
    99    return NULL;
       
   100 }
       
   101 
       
   102 
       
   103 /* {{-output"vdeImbCopyParameters.txt"}} */
       
   104 /*
       
   105  * vdeImbCopyParameters
       
   106  *
       
   107  * Parameters:
       
   108  *    dstImb                     destination image buffer
       
   109  *    srcImb                     source image buffer
       
   110  *
       
   111  * Function:
       
   112  *    This function copies the srcImb structure to the dstImb structure.
       
   113  *    All other parameters are copied but the actual picture contents.
       
   114  *    The function handles nested structures correctly.
       
   115  *
       
   116  * Returns:
       
   117  *    (See vde.h for descriptions of return values.)
       
   118  *    VDE_OK
       
   119  *    VDE_ERROR
       
   120  *
       
   121  *    
       
   122  */
       
   123 
       
   124 int vdeImbCopyParameters(vdeImb_t *dstImb, const vdeImb_t *srcImb)
       
   125 /* {{-output"vdeImbCopyParameters.txt"}} */
       
   126 {
       
   127    /* drawItem */
       
   128    renDriCopyParameters(dstImb->drawItem, srcImb->drawItem);
       
   129 
       
   130    dstImb->fReferenced = srcImb->fReferenced;
       
   131    dstImb->tr = srcImb->tr;
       
   132    dstImb->trRef = srcImb->trRef;
       
   133 
       
   134    {
       
   135       int numOfMBs = renDriNumOfMBs(srcImb->drawItem);
       
   136 
       
   137       /* yQuantParams */
       
   138       memcpy(
       
   139          dstImb->yQuantParams, 
       
   140          srcImb->yQuantParams, 
       
   141          numOfMBs * sizeof(int));
       
   142       
       
   143       /* uvQuantParams */
       
   144       memcpy(
       
   145          dstImb->uvQuantParams, 
       
   146          srcImb->uvQuantParams, 
       
   147          numOfMBs * sizeof(int));
       
   148 
       
   149    }
       
   150 
       
   151    return VDE_OK;
       
   152 }
       
   153 
       
   154 
       
   155 /* {{-output"vdeImbDealloc.txt"}} */
       
   156 /*
       
   157  * vdeImbDealloc
       
   158  *
       
   159  * Parameters:
       
   160  *    imb                        a pointer to image buffer to destroy
       
   161  *
       
   162  * Function:
       
   163  *    This function deallocates the given image buffer.
       
   164  *
       
   165  * Returns:
       
   166  *    Nothing
       
   167  *
       
   168  *    
       
   169  */
       
   170 
       
   171 void vdeImbDealloc(vdeImb_t *imb)
       
   172 /* {{-output"vdeImbDealloc.txt"}} */
       
   173 {
       
   174    if (!imb)
       
   175       return;
       
   176 
       
   177    if (imb->drawItem)
       
   178       renDriFree(imb->drawItem);
       
   179 
       
   180     vdeDealloc(imb->yQuantParams);
       
   181     vdeDealloc(imb->uvQuantParams);
       
   182 
       
   183    vdeDealloc(imb);
       
   184 }
       
   185 // End of File