2 /**************************************************************************
4 * This code is developed by Adam Li. This software is an *
5 * implementation of a part of one or more MPEG-4 Video tools as *
6 * specified in ISO/IEC 14496-2 standard. Those intending to use this *
7 * software module in hardware or software products are advised that its *
8 * use may infringe existing patents or copyrights, and any such use *
9 * would be at such party's own risk. The original developer of this *
10 * software module and his/her company, and subsequent editors and their *
11 * companies (including Project Mayo), will have no liability for use of *
12 * this software or modifications or derivatives thereof. *
14 * Project Mayo gives users of the Codec a license to this software *
15 * module or modifications thereof for use in hardware or software *
16 * products claiming conformance to the MPEG-4 Video Standard as *
17 * described in the Open DivX license. *
19 * The complete Open DivX license can be found at *
20 * http://www.projectmayo.com/opendivx/license.php . *
22 **************************************************************************/
24 /**************************************************************************
28 * Copyright (C) 2001 Project Mayo
32 * DivX Advance Research Center <darc@projectmayo.com>
34 **************************************************************************/
36 /* This file contains memory access for the Image, Vop and VolConfig data */
38 /* Some codes of this project come from MoMuSys MPEG-4 implementation. */
39 /* Please see seperate acknowledgement file for a list of contributors. */
41 #include "mom_access.h"
43 /***********************************************************CommentBegin******
45 * -- GetImage{xxx} -- Access components of intermediate formats
47 * Char *GetImageData(Image *image)
48 * UInt GetImageSize(Image *image)
49 * UInt GetImageSizeX(Image *image)
50 * UInt GetImageSizeY(Image *image)
51 * Int GetImageVersion(Image *image)
52 * ImageType GetImageType(Image *image)
55 * These are common functions to access specific components
56 * of the common data structures which are used for the
57 * intermediate formats.
59 ***********************************************************CommentEnd********/
62 GetImageData(Image
*image
)
64 switch(GetImageType(image
))
67 return((Char
*)image
->data
->s
);
70 return((Char
*)image
->data
->f
);
73 return((Char
*)image
->data
->u
);
76 printf("Image type >>%d<< not supported\n",image
->type
);
83 GetImageSize(Image
*image
)
85 return(image
->x
* image
->y
);
90 GetImageSizeX(Image
*image
)
97 GetImageSizeY(Image
*image
)
104 GetImageVersion(Image
*image
)
106 return(image
->version
);
111 GetImageType(Image
*image
)
118 /***********************************************************CommentBegin******
120 * -- GetVop{xxx} -- Functions to access components of the Vop structure
123 * These are common functions to access specific components
124 * of the Vop data structure.
126 ***********************************************************CommentEnd********/
129 Int
GetVopNot8Bit(Vop
*vop
)
131 return (vop
->bits_per_pixel
!= 8);
135 Int
GetVopQuantPrecision(Vop
*vop
)
137 return (vop
->quant_precision
);
141 Int
GetVopBitsPerPixel(Vop
*vop
)
143 return (vop
->bits_per_pixel
);
147 Int
GetVopMidGrey(Vop
*vop
)
149 return (1 << (vop
->bits_per_pixel
- 1));
153 Int
GetVopBrightWhite(Vop
*vop
)
155 return ((1 << vop
->bits_per_pixel
) - 1);
159 Int
GetVopTimeIncrementResolution(Vop
*vop
)
161 return (vop
->time_increment_resolution
);
166 GetVopModTimeBase(Vop
*vop
)
168 return(vop
->mod_time_base
);
173 GetVopTimeInc(Vop
*vop
)
175 return((int)vop
->time_inc
);
180 GetVopPredictionType(Vop
*vop
)
182 return(vop
->prediction_type
);
186 Int
GetVopIntraDCVlcThr(Vop
*vop
)
188 return (vop
->intra_dc_vlc_thr
);
193 GetVopRoundingType(Vop
*vop
)
195 return(vop
->rounding_type
);
200 GetVopWidth(Vop
*vop
)
207 GetVopHeight(Vop
*vop
)
214 GetVopHorSpatRef(Vop
*vop
)
216 return(vop
->hor_spat_ref
);
221 GetVopVerSpatRef(Vop
*vop
)
223 return(vop
->ver_spat_ref
);
228 GetVopQuantizer(Vop
*vop
)
230 return(vop
->quantizer
);
235 GetVopIntraQuantizer(Vop
*vop
)
237 return(vop
->intra_quantizer
);
242 GetVopIntraACDCPredDisable(Vop
*vop
)
244 return(vop
->intra_acdc_pred_disable
);
249 GetVopFCodeFor(Vop
*vop
)
251 return(vop
->fcode_for
);
256 GetVopSearchRangeFor(Vop
*vop
)
283 /***********************************************************CommentBegin******
285 * -- PutVop{xxx} -- Functions to write to components of the Vop structure
287 * These are common functions to write to specific components
288 * of the Vop structure.
290 ***********************************************************CommentEnd********/
293 Void
PutVopQuantPrecision(Int quant_precision
,Vop
*vop
)
295 vop
->quant_precision
= quant_precision
;
299 Void
PutVopBitsPerPixel(Int bits_per_pixel
,Vop
*vop
)
301 vop
->bits_per_pixel
= bits_per_pixel
;
305 Void
PutVopTimeIncrementResolution(Int time_incre_res
, Vop
*vop
)
307 vop
->time_increment_resolution
=time_incre_res
;
312 PutVopModTimeBase(Int mod_time_base
, Vop
*vop
)
314 vop
->mod_time_base
= mod_time_base
;
319 PutVopTimeInc(Int time_inc
, Vop
*vop
)
321 vop
->time_inc
= (float)time_inc
;
326 PutVopPredictionType(Int prediction_type
, Vop
*vop
)
328 vop
->prediction_type
= prediction_type
;
332 Void
PutVopIntraDCVlcThr(Int intra_dc_vlc_thr
,Vop
*vop
)
334 vop
->intra_dc_vlc_thr
=intra_dc_vlc_thr
;
339 PutVopRoundingType(Int rounding_type
, Vop
*vop
)
341 vop
->rounding_type
= rounding_type
;
346 PutVopWidth(Int width
, Vop
*vop
)
353 PutVopHeight(Int height
, Vop
*vop
)
355 vop
->height
= height
;
360 PutVopHorSpatRef(Int hor_spat_ref
, Vop
*vop
)
362 vop
->hor_spat_ref
= hor_spat_ref
;
367 PutVopVerSpatRef(Int ver_spat_ref
, Vop
*vop
)
369 vop
->ver_spat_ref
= ver_spat_ref
;
374 PutVopQuantizer(Int quantizer
, Vop
*vop
)
376 vop
->quantizer
= quantizer
;
381 PutVopIntraACDCPredDisable(Int intra_acdc_pred_disable
, Vop
*vop
)
383 vop
->intra_acdc_pred_disable
= intra_acdc_pred_disable
;
388 PutVopFCodeFor(Int fcode_for
, Vop
*vop
)
390 vop
->fcode_for
= fcode_for
;
395 PutVopSearchRangeFor(Int sr_for
, Vop
*vop
)
397 vop
->sr_for
= sr_for
;
402 PutVopY(Image
*y_chan
, Vop
*vop
)
404 FreeImage(vop
->y_chan
);
405 vop
->y_chan
= y_chan
;
410 PutVopU(Image
*u_chan
, Vop
*vop
)
412 FreeImage(vop
->u_chan
);
413 vop
->u_chan
= u_chan
;
418 PutVopV(Image
*v_chan
, Vop
*vop
)
420 FreeImage(vop
->v_chan
);
421 vop
->v_chan
= v_chan
;
426 PutVopIntraQuantizer(Int Q
,Vop
*vop
)
428 vop
->intra_quantizer
= Q
;
432 /***********************************************************CommentBegin******
434 * -- PutVolConfigXXXX -- Access functions for VolConfig
437 * To set particular fields in a VolConfig strcuture
439 ***********************************************************CommentEnd********/
443 PutVolConfigFrameRate(Float fr
, VolConfig
*cfg
)
445 cfg
->frame_rate
= fr
;
450 PutVolConfigM(Int M
, VolConfig
*cfg
)
457 PutVolConfigStartFrame(Int frame
, VolConfig
*cfg
)
459 cfg
->start_frame
= frame
;
464 PutVolConfigEndFrame(Int frame
, VolConfig
*cfg
)
466 cfg
->end_frame
= frame
;
471 PutVolConfigBitrate(Int bit_rate
,VolConfig
*cfg
)
473 cfg
->bit_rate
= bit_rate
;
478 PutVolConfigIntraPeriod(Int ir
,VolConfig
*cfg
)
480 cfg
->intra_period
= ir
;
485 PutVolConfigQuantizer(Int Q
,VolConfig
*cfg
)
492 PutVolConfigIntraQuantizer(Int Q
,VolConfig
*cfg
)
494 cfg
->intra_quantizer
= Q
;
499 PutVolConfigFrameSkip(Int frame_skip
,VolConfig
*cfg
)
501 cfg
->frame_skip
= frame_skip
;
506 PutVolConfigModTimeBase(Int time
,VolConfig
*cfg
)
508 cfg
->modulo_time_base
[0] = cfg
->modulo_time_base
[1];
509 cfg
->modulo_time_base
[1] = time
;
513 /***********************************************************CommentBegin******
515 * -- GetVolConfigXXXX -- Access functions for VolConfig
518 * To obtain the value of particular fields in a VolConfig structure
520 ***********************************************************CommentEnd********/
524 GetVolConfigFrameRate(VolConfig
*cfg
)
526 return(cfg
->frame_rate
);
531 GetVolConfigM(VolConfig
*cfg
)
538 GetVolConfigStartFrame(VolConfig
*cfg
)
540 return(cfg
->start_frame
);
545 GetVolConfigEndFrame(VolConfig
*cfg
)
547 return(cfg
->end_frame
);
552 GetVolConfigBitrate(VolConfig
*cfg
)
554 return(cfg
->bit_rate
);
559 GetVolConfigIntraPeriod(VolConfig
*cfg
)
561 return(cfg
->intra_period
);
566 GetVolConfigQuantizer(VolConfig
*cfg
)
568 return(cfg
->quantizer
);
573 GetVolConfigIntraQuantizer(VolConfig
*cfg
)
575 return(cfg
->intra_quantizer
);
580 GetVolConfigFrameSkip(VolConfig
*cfg
)
582 return(cfg
->frame_skip
);
587 GetVolConfigModTimeBase(VolConfig
*cfg
,Int i
)
589 return(cfg
->modulo_time_base
[i
]);