Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 /*
     19 ------------------------------------------------------------------------------
     20  INPUT AND OUTPUT DEFINITIONS
     21 
     22  Inputs:
     23     input_ptr = pointer to the buffer containing values of type UChar
     24             in a 2D block of data.
     25     min_ptr = pointer to the minimum value of type Int to be found in a
     26           square block of size BLKSIZE contained in 2D block of data.
     27     max_ptr = pointer to the maximum value of type Int to be found in a
     28           square block of size BLKSIZE contained in 2D block of data.
     29     incr = value of type Int representing the width of 2D block of data.
     30 
     31  Local Stores/Buffers/Pointers Needed:
     32     None
     33 
     34  Global Stores/Buffers/Pointers Needed:
     35     None
     36 
     37  Outputs:
     38     None
     39 
     40  Pointers and Buffers Modified:
     41     min_ptr points to the found minimum value in the square block of
     42     size BLKSIZE contained in 2D block of data.
     43 
     44     max_ptr points to the found maximum value in the square block of
     45     size BLKSIZE contained in 2D block of data.
     46 
     47  Local Stores Modified:
     48     None
     49 
     50  Global Stores Modified:
     51     None
     52 
     53 ------------------------------------------------------------------------------
     54  FUNCTION DESCRIPTION
     55 
     56  This function finds the maximum and the minimum values in a square block of
     57  data of size BLKSIZE * BLKSIZE. The data is contained in the buffer which
     58  represents a 2D block of data that is larger than BLKSIZE * BLKSIZE.
     59  This is illustrated below.
     60 
     61     mem loc x + 00h -> o o o o o o o o o o o o o o o o
     62     mem loc x + 10h -> o o o o o X X X X X X X X o o o
     63     mem loc x + 20h -> o o o o o X X X X X X X X o o o
     64     mem loc x + 30h -> o o o o o X X X X X X X X o o o
     65     mem loc x + 40h -> o o o o o X X X X X X X X o o o
     66     mem loc x + 50h -> o o o o o X X X X X X X X o o o
     67     mem loc x + 60h -> o o o o o X X X X X X X X o o o
     68     mem loc x + 70h -> o o o o o X X X X X X X X o o o
     69     mem loc x + 80h -> o o o o o X X X X X X X X o o o
     70     mem loc x + 90h -> o o o o o o o o o o o o o o o o
     71     mem loc x + A0h -> o o o o o o o o o o o o o o o o
     72     mem loc x + B0h -> o o o o o o o o o o o o o o o o
     73 
     74 For illustration purposes, the diagram assumes that BLKSIZE is equal to 8
     75 but this is not a requirement. In this diagram, the buffer starts at
     76 location x but the input pointer, input_ptr, passed into this function
     77 would be the first row of data to be searched which is at x + 15h. The
     78 value of incr passed onto this function represents the amount the input_ptr
     79 needs to be incremented to point to the next row of data.
     80 
     81 This function compares each value in a row to the current maximum and
     82 minimum. After each row, input_ptr is incremented to point to the next row.
     83 This is repeated until all rows have been processed. When the search is
     84 complete the location pointed to by min_ptr contains the minimum value
     85 found and the location pointed to by max_ptr contains the maximum value found.
     86 
     87 ------------------------------------------------------------------------------
     88 */
     89 
     90 
     91 /*----------------------------------------------------------------------------
     92 ; INCLUDES
     93 ----------------------------------------------------------------------------*/
     94 #include    "mp4dec_lib.h"
     95 #include    "post_proc.h"
     96 
     97 /*----------------------------------------------------------------------------
     98 ; MACROS
     99 ; Define module specific macros here
    100 ----------------------------------------------------------------------------*/
    101 
    102 /*----------------------------------------------------------------------------
    103 ; DEFINES
    104 ; Include all pre-processor statements here. Include conditional
    105 ; compile variables also.
    106 ----------------------------------------------------------------------------*/
    107 
    108 /*----------------------------------------------------------------------------
    109 ; LOCAL FUNCTION DEFINITIONS
    110 ; Function Prototype declaration
    111 ----------------------------------------------------------------------------*/
    112 
    113 /*----------------------------------------------------------------------------
    114 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    115 ; Variable declaration - defined here and used outside this module
    116 ----------------------------------------------------------------------------*/
    117 
    118 /*----------------------------------------------------------------------------
    119 ; EXTERNAL FUNCTION REFERENCES
    120 ; Declare functions defined elsewhere and referenced in this module
    121 ----------------------------------------------------------------------------*/
    122 
    123 /*----------------------------------------------------------------------------
    124 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    125 ; Declare variables used in this module but defined elsewhere
    126 ----------------------------------------------------------------------------*/
    127 
    128 #ifdef PV_POSTPROC_ON
    129 /*----------------------------------------------------------------------------
    130 ; FUNCTION CODE
    131 ----------------------------------------------------------------------------*/
    132 void  FindMaxMin(
    133     uint8 *input_ptr,
    134     int *min_ptr,
    135     int *max_ptr,
    136     int incr)
    137 {
    138     /*----------------------------------------------------------------------------
    139     ; Define all local variables
    140     ----------------------------------------------------------------------------*/
    141     register    uint    i, j;
    142     register    int min, max;
    143 
    144     /*----------------------------------------------------------------------------
    145     ; Function body here
    146     ----------------------------------------------------------------------------*/
    147     max = min = *input_ptr;
    148     /*  incr = incr - BLKSIZE; */   /*  09/06/2001, already passed in as width - BLKSIZE */
    149 
    150     for (i = BLKSIZE; i > 0; i--)
    151     {
    152         for (j = BLKSIZE; j > 0; j--)
    153         {
    154             if (*input_ptr > max)
    155             {
    156                 max = *input_ptr;
    157             }
    158             else if (*input_ptr < min)
    159             {
    160                 min = *input_ptr;
    161             }
    162             input_ptr += 1;
    163         }
    164 
    165         /* set pointer to the beginning of the next row*/
    166         input_ptr += incr;
    167     }
    168 
    169     *max_ptr = max;
    170     *min_ptr = min;
    171     /*----------------------------------------------------------------------------
    172     ; Return nothing or data or data pointer
    173     ----------------------------------------------------------------------------*/
    174     return;
    175 }
    176 #endif
    177