MISR Toolkit  1.5.1
MtkUpsampleMask.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkUpsampleMask =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2008, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrRegression.h"
18 #include "MisrUtil.h"
19 #include <stdlib.h>
20 #include <math.h>
21 
37  const MTKt_DataBuffer *Source_mask,
38  int Size_factor,
39  MTKt_DataBuffer *Result_mask
40 )
41 {
42  MTKt_status status_code; /* Return status of this function */
43  MTKt_status status; /* Return status of called routines. */
44  MTKt_DataBuffer result_mask_tmp = MTKT_DATABUFFER_INIT;
45  /* Valid mask for result. */
46  int number_line_out; /* Number of lines in output grid.*/
47  int number_sample_out; /* Number of samples in output grid.*/
48  int iline; /* Loop iterator. */
49  int isample; /* Loop iterator. */
50 
51  /* ------------------------------------------------------------------ */
52  /* Argument check: Source_mask == NULL */
53  /* Source_mask->nline < 1 */
54  /* Source_mask->nsample < 1 */
55  /* Source_mask->datatype = MTKe_uint8 */
56  /* ------------------------------------------------------------------ */
57 
58  if (Source_mask == NULL) {
59  MTK_ERR_CODE_MSG_JUMP(MTK_NULLPTR,"Source_mask == NULL");
60  }
61  if (Source_mask->nline < 1) {
62  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Source_mask->nline < 1");
63  }
64  if (Source_mask->nsample < 1) {
65  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Source_mask->nsample < 1");
66  }
67  if (Source_mask->datatype != MTKe_uint8) {
68  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Source_mask->datatype != MTKe_uint8");
69  }
70 
71  /* ------------------------------------------------------------------ */
72  /* Argument check: */
73  /* Size_factor < 1 */
74  /* ------------------------------------------------------------------ */
75 
76  if (Size_factor < 1) {
77  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Size_factor < 1");
78  }
79 
80  /* ------------------------------------------------------------------ */
81  /* Argument check: Result_mask == NULL */
82  /* ------------------------------------------------------------------ */
83 
84  if (Result_mask == NULL) {
85  MTK_ERR_CODE_MSG_JUMP(MTK_NULLPTR,"Result_mask == NULL");
86  }
87 
88  /* ------------------------------------------------------------------ */
89  /* Determine size of output array. */
90  /* ------------------------------------------------------------------ */
91 
92  number_line_out = Source_mask->nline * Size_factor;
93  number_sample_out = Source_mask->nsample * Size_factor;
94 
95  /* ------------------------------------------------------------------ */
96  /* Allocate memory for result */
97  /* ------------------------------------------------------------------ */
98 
99  status = MtkDataBufferAllocate(number_line_out, number_sample_out,
100  MTKe_uint8, &result_mask_tmp);
101  MTK_ERR_COND_JUMP(status);
102 
103  /* ------------------------------------------------------------------ */
104  /* For each location in result grid... */
105  /* ------------------------------------------------------------------ */
106 
107  for (iline = 0; iline < number_line_out ; iline++) {
108  for (isample = 0; isample < number_sample_out; isample++) {
109 
110 
111  /* ------------------------------------------------------------------ */
112  /* Duplicate the corresponding value in the source grid. */
113  /* ------------------------------------------------------------------ */
114 
115  result_mask_tmp.data.u8[iline][isample] =
116  Source_mask->data.u8[iline / Size_factor][isample / Size_factor];
117 
118  /* ------------------------------------------------------------------ */
119  /* End loop for each location in result grid. */
120  /* ------------------------------------------------------------------ */
121 
122  }
123  }
124 
125  /* ------------------------------------------------------------------ */
126  /* Return. */
127  /* ------------------------------------------------------------------ */
128 
129  *Result_mask = result_mask_tmp;
130  return MTK_SUCCESS;
131 
132 ERROR_HANDLE:
133  MtkDataBufferFree(&result_mask_tmp);
134  return status_code;
135 }
MTKt_status MtkDataBufferAllocate(int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer *databuf)
Allocate Data Buffer.
MTKt_DataBufferType data
Definition: MisrUtil.h:104
2-dimensional Data Buffer
Definition: MisrUtil.h:98
#define MTKT_DATABUFFER_INIT
Definition: MisrUtil.h:109
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
MTKt_DataType datatype
Definition: MisrUtil.h:102
MTKt_uint8 ** u8
Definition: MisrUtil.h:86
#define MTK_ERR_CODE_MSG_JUMP(code, msg)
Definition: MisrError.h:181
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
MTKt_status MtkUpsampleMask(const MTKt_DataBuffer *Source_mask, int Size_factor, MTKt_DataBuffer *Result_mask)
Upsample a mask by nearest neighbor sampling.

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51