├── LICENSE ├── README.md ├── app ├── 360tools_conv │ └── 360tools_conv.c └── 360tools_metric │ ├── 360tools_metric.c │ └── sphere_655362.txt ├── build ├── x86_linux │ └── Makefile └── x86_windows │ ├── 360tools_conv_vs2008.vcproj │ ├── 360tools_conv_vs2010.vcxproj │ ├── 360tools_lib_vs2008.vcproj │ ├── 360tools_lib_vs2010.vcxproj │ ├── 360tools_metric_vs2008.vcproj │ ├── 360tools_metric_vs2010.vcxproj │ ├── 360tools_vs2008.sln │ └── 360tools_vs2010.sln └── src ├── 360tools.c ├── 360tools.h ├── 360tools_args.h ├── 360tools_cmp.c ├── 360tools_cmp.h ├── 360tools_cpp.c ├── 360tools_cpp.h ├── 360tools_def.h ├── 360tools_erp.c ├── 360tools_erp.h ├── 360tools_img.c ├── 360tools_img.h ├── 360tools_isp.c ├── 360tools_isp.h ├── 360tools_map.c ├── 360tools_map.h ├── 360tools_ohp.c ├── 360tools_ohp.h ├── 360tools_ssp.c ├── 360tools_ssp.h ├── 360tools_tbl.c ├── 360tools_tsp.c └── 360tools_tsp.h /LICENSE: -------------------------------------------------------------------------------- 1 | The copyright in this software is being made available under the BSD 2 | License, included below. This software may be subject to other third party 3 | and contributor rights, including patent rights, and no such rights are 4 | granted under this license. 5 | 6 | Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 12 | * Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | THE POSSIBILITY OF SUCH DAMAGE. 32 | 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 360tools 2 | 3 | Projection and quality evaluation tools for VR video compression exploration experiments 4 | 5 | ## Description 6 | + 360tools_conv is used for conversion between different projection formats 7 | + 360tools_metric implements various quality metrics for vR video quality evaluation 8 | 9 | The 360tools is software for VR video processing experiments. 10 | The software includes both 360 video conversion and quality metrics 11 | functionality 12 | 13 | 360tools software is useful in aiding users of a 360 VR video coding 14 | experiments to establish and test various processing techniques for VR video 15 | content. 16 | 360tools is useful to educate users. For these purposes, the software is 17 | provided as an aid for the study and implementation of 360 VR video coding and 18 | may eventually be formally published as reference software, e.g., by 19 | ITU-T and ISO/IEC. 20 | 21 | This software may be subject to other third party and contributor rights, 22 | including patent rights and no such rights are granted. 23 | 24 | ## Building 25 | 26 | Checkout the source for 360 Tools 27 | 28 | + Windows 29 | In 360tools/build/x86_windows/ 30 | select corresponding *.sln file 31 | build and run with preferred visual studio 2008 or 2010 32 | Executable files are stored to 360tools/bin/ directory 33 | 34 | + Linux 35 | In 360tools/build/x86_linux/ 36 | execute make command 37 | Executable files are stored at 360tools/bin/ directory 38 | 39 | ## Example usage for conversion tool 40 | 41 | ./360tools_conv -i [file] -o [file] -f [int] -w [int] -h [int] -l [int] -m [int] -x [int] -y [int] 42 | ./360tools_conv -i glacier_vr_24p_3840x1920.yuv -w 3840 -h 1920 -x 1 -o glacier_vr_24p_isp_4268x2016.yuv -l 4268 -m 2016 -y 1 -f 5 -n 10 43 | 44 | ## Example usage for quality metrics 45 | 46 | ./360tools_metrics -w [int] -h [int] -f [int] -o [file] -q [int] -l [int] -m [int] -t [int] -r [file] -n [int] -x [int] 47 | ./360tools_metrics -w 4096 -h 2048 -f 1 -o glacier_vr_24p_3840x1920.yuv -q 4 -l 4268 -m 2016 -t 2 -r glacier_vr_24p_isp_4268x2016.yuv -n 7 -x 1 48 | 49 | ## Supported formats 50 | + Equirectangular projection (ERP) 51 | + Icosahedral projection (ISP) 52 | + Octahedron projection (OHP) 53 | + Cubemap projection (CMP) 54 | + Truncated Square Pyramid projection (TSP) 55 | + Segmented Sphere Projection (SSP) 56 | + Reshaped Icosahedral projection (RISP) 57 | + Reshaped Octahedron projection (ROHP) 58 | + Reshaped Cubemap projection (RCMP) 59 | 60 | ## Supported quality metrics 61 | + PSNR - conventional Peak Signal to Noise Ratio quality metrics 62 | + S-PSNR - spherical PSNR (requires sphere_655362.txt file with point coordinates) 63 | + WS-PSNR - weighted Spherical PSNR (for equirectangular projection only) 64 | + CPP-PSNR - equal area common projection PSNR 65 | 66 | ## Conversion parameters 67 | + Mandatory 68 | -i input file name 69 | -o output file name 70 | -w input image width 71 | -h input image height 72 | -l output image width 73 | -m output image height 74 | -x input image colorspace 75 | -y output image colorspace 76 | -f conversion format 77 | 78 | + Optional 79 | -n number of converted frames 80 | -a align to multiple of size 81 | -u disable padding 82 | -c config file 83 | -p pitch angle 84 | -y yaw angle 85 | 86 | ## Quality metrics parameters 87 | + Mandatory 88 | -o original file 89 | -r reconstructed file 90 | -w width original 91 | -h height original 92 | -q metrics type 93 | -x original image colorspace 94 | -y reconstructed image colorspace 95 | 96 | + Optinal 97 | -l width reconstructed 98 | -m height reconstructed 99 | -n number of frames 100 | -s spheric coordinates file, mandatory for S-PSNR 101 | -f projection format original, mandatory for CPP-PSNR 102 | -t projection format reconstructed for CPP-PSNR 103 | -c config file 104 | 105 | ## Recommended equal spatial resolution: number of pixels in each projection is constant 106 | (S_ERP == S_ISP == S_CPP); Value is suggested for HM and JEM sw 107 | + ERP 3840x1920 108 | - ISP 4928x2328 109 | - OHP 5984x2592 110 | - CMP 3840x2880 111 | - TSP 1920x960 112 | - SSP 3840x2880 113 | 114 | + ERP 4096x2048 115 | - ISP 4928x2328 116 | - OHP 6208x2688 117 | - CMP 4096x3072 118 | - TSP 2048x1024 119 | - SSP 4096x3072 120 | -------------------------------------------------------------------------------- /app/360tools_conv/360tools_conv.c: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #define _CRT_SECURE_NO_WARNINGS 35 | 36 | #include 37 | #include 38 | #include 39 | #include "360tools.h" 40 | 41 | static char fname_inp[256] = "\0"; 42 | static char fname_out[256] = "\0"; 43 | static char fname_cfg[256] = "\0"; 44 | static int w_in = 0; 45 | static int h_in = 0; 46 | static int w_out = 0; 47 | static int h_out = 0; 48 | static int cfmt = 0; 49 | static int frm_num = 0; 50 | static int align = 0; 51 | static int no_pad = 0; 52 | static int cs_in = 0; 53 | static int cs_out = 0; 54 | static int pitch = 90; 55 | static int yaw = 0; 56 | static int cs_int = INT_10_BIT_DEPTH; 57 | 58 | int opt_flag[CMD_FLAG_CONV_MAX] = {0}; 59 | 60 | static S360_ARGS_OPT argopt[] = \ 61 | { 62 | { 63 | 'c', "config", S360_ARGS_VAL_TYPE_STRING, 64 | &opt_flag[CMD_FLAG_CONV_CONFIG], fname_cfg, 65 | "config file name" 66 | }, 67 | { 68 | 'i', "input", S360_ARGS_VAL_TYPE_STRING|S360_ARGS_VAL_TYPE_MANDATORY, 69 | &opt_flag[CMD_FLAG_CONV_FNAME_INP], fname_inp, 70 | "input file name" 71 | }, 72 | { 73 | 'o', "output", S360_ARGS_VAL_TYPE_STRING|S360_ARGS_VAL_TYPE_MANDATORY, 74 | &opt_flag[CMD_FLAG_CONV_FNAME_OUT], fname_out, 75 | "output file name" 76 | }, 77 | { 78 | 'w', "width", S360_ARGS_VAL_TYPE_INTEGER|S360_ARGS_VAL_TYPE_MANDATORY, 79 | &opt_flag[CMD_FLAG_CONV_WIDTH], &w_in, 80 | "width of input image" 81 | }, 82 | { 83 | 'h', "height", S360_ARGS_VAL_TYPE_INTEGER|S360_ARGS_VAL_TYPE_MANDATORY, 84 | &opt_flag[CMD_FLAG_CONV_HEIGHT], &h_in, 85 | "height of input image" 86 | }, 87 | { 88 | 'f', "convfmt", S360_ARGS_VAL_TYPE_INTEGER | S360_ARGS_VAL_TYPE_MANDATORY, 89 | &opt_flag[CMD_FLAG_CONV_CFMT], &cfmt, 90 | "converting format\n\t" 91 | "0: ERP to CPP\n\t" 92 | "1: ERP to ISP\n\t" 93 | "2: ISP to ERP\n\t" 94 | "3: ERP to CMP\n\t" 95 | "4: CMP to ERP\n\t" 96 | "5: ERP to OHP\n\t" 97 | "6: OHP to ERP\n\t" 98 | "7: ERP to TSP\n\t" 99 | "8: TSP to ERP\n\t" 100 | "9: ERP to SSP\n\t" 101 | "10: SSP to ERP\n\t" 102 | "11: ISP to RISP\n\t" 103 | "12: RISP to ISP\n\t" 104 | "13: CMP to RCMP\n\t" 105 | "14: RCMP to CMP\n\t" 106 | "15: OHP to ROHP\n\t" 107 | "16: ROHP to OHP\n\t" 108 | "21: ERP to RISP\n\t" 109 | "22: RISP to ERP\n\t" 110 | "25: ERP to COHP\n\t" 111 | "26: COHP to ERP\n\t" 112 | "31: CPP to ERP\n\t" 113 | "32: CPP to ISP\n\t" 114 | "33: CPP to CMP\n\t" 115 | "34: CPP to OHP\n\t" 116 | "35: CPP to TSP\n\t" 117 | "36: CPP to SSP\n\t" 118 | }, 119 | { 120 | 'l', "out_width", S360_ARGS_VAL_TYPE_INTEGER|S360_ARGS_VAL_TYPE_MANDATORY, 121 | &opt_flag[CMD_FLAG_CONV_OWIDTH], &w_out, 122 | "width of output image. if not set, this is same value with width of input " 123 | "image" 124 | }, 125 | { 126 | 'm', "out_height", S360_ARGS_VAL_TYPE_INTEGER|S360_ARGS_VAL_TYPE_MANDATORY, 127 | &opt_flag[CMD_FLAG_CONV_OHEIGHT], &h_out, 128 | "height of output image. if not set, this is same value with height" 129 | " of input image" 130 | }, 131 | 132 | { 133 | 'n', "frmnum", S360_ARGS_VAL_TYPE_INTEGER, 134 | &opt_flag[CMD_FLAG_CONV_FRM_NUM], &frm_num, 135 | "number of frames to be converted" 136 | }, 137 | { 138 | 'a', "align", S360_ARGS_VAL_TYPE_INTEGER, 139 | &opt_flag[CMD_FLAG_CONV_ALIGN], &align, 140 | "vertical align" 141 | }, 142 | { 143 | 'u', "no_pad", S360_ARGS_VAL_TYPE_NONE, 144 | &opt_flag[CMD_FLAG_CONV_ALIGN], &no_pad, 145 | "turn off padding" 146 | }, 147 | { 148 | 'x', "cs_in", S360_ARGS_VAL_TYPE_INTEGER, 149 | &opt_flag[CMD_FLAG_CONV_CS_IN], &cs_in, 150 | "Input Color Space\n\t 1: YUV420 8-bit\n\t 2: YUV420 10-bit" 151 | }, 152 | { 153 | 'y', "cs_out", S360_ARGS_VAL_TYPE_INTEGER, 154 | &opt_flag[CMD_FLAG_CONV_CS_OUT], &cs_out, 155 | "Output Color Space\n\t 1: YUV420 8-bit\n\t 2: YUV420 10-bit" 156 | }, 157 | { 158 | 'p', "pitch", S360_ARGS_VAL_TYPE_INTEGER, 159 | &opt_flag[CMD_FLAG_CONV_PITCH], &pitch, 160 | "TSP pitch angle [0,180] default is 90" 161 | }, 162 | { 163 | 't', "yaw", S360_ARGS_VAL_TYPE_INTEGER, 164 | &opt_flag[CMD_FLAG_CONV_YAW], &yaw, 165 | "TSP yaw angle [0,360] default is 0" 166 | }, 167 | { 0, "", S360_ARGS_VAL_TYPE_NONE, NULL, NULL, ""} /* termination */ 168 | }; 169 | 170 | #define NUM_ARGOPT ((int)(sizeof(argopt)/sizeof(argopt[0]))-1) 171 | 172 | 173 | static void print_usage(void) 174 | { 175 | int i; 176 | char str[1024]; 177 | 178 | s360_print("< Usage >\n"); 179 | 180 | for(i=0; i 0) s360_print("-%c argument should be set\n", ret); 203 | print_usage(); 204 | return 0; 205 | } 206 | 207 | fpi = fopen(fname_inp, "rb"); 208 | if(fpi == NULL) 209 | { 210 | s360_print("No input file: %s\n", fname_inp); 211 | print_usage(); 212 | goto END; 213 | } 214 | 215 | fpo = fopen(fname_out, "wb"); 216 | if(fpo == NULL) 217 | { 218 | s360_print("Failed to create output file: %s\n", fname_out); 219 | print_usage(); 220 | goto END; 221 | } 222 | fclose(fpo); 223 | 224 | if(w_in <= 0 || h_in <= 0) 225 | { 226 | s360_print("Invalid input resolution: %dx%d\n", w_in, h_in); 227 | print_usage(); 228 | goto END; 229 | } 230 | 231 | if((cfmt == CONV_FMT_ERP_TO_CPP) && (w_out != w_in || h_out != h_in)) 232 | { 233 | s360_print("Downsamplin CPP may affect your final results " 234 | "1:1 scale is recommended: %dx%d\n", w_out, h_out); 235 | s360_print("Suggested sample dimension: %dx%d\n", w_in, h_in); 236 | print_usage(); 237 | goto END; 238 | } 239 | 240 | if((cfmt == CONV_FMT_ERP_TO_CMP) && 241 | ((w_out%4 != 0 || h_out%4 != 0) || (w_out*3 != h_out*4))) 242 | { 243 | s360_print("Invalid output resolution for cubemap, suugested aspect " 244 | "ratio 4:3 and must be multiple of 4: %dx%d\n", w_out, h_out); 245 | s360_print("Suggested sample dimension: %dx%d\n", w_out, w_out*3/4); 246 | print_usage(); 247 | goto END; 248 | } 249 | 250 | if((cfmt == CONV_FMT_ERP_TO_ISP) && (((w_out<<1)%11 != 0 || 251 | h_out != 3*NEAREST_EVEN((((int)((int)((w_out)/5.5)/4)*4))*SIN_60)))) 252 | { 253 | /* some suggested dimensions */ 254 | int w_tri, h_tri; 255 | w_tri = ((int)((int)((w_out)/5.5)/4)*4); 256 | h_tri = NEAREST_EVEN((w_tri)*SIN_60); 257 | w_tri = (w_tri*11)>>1; 258 | h_tri = h_tri*3; 259 | s360_print("Invalid output resolution %dx%d, ISP recommended aspect " 260 | " ratio: 88:42\n", w_out, h_out); 261 | s360_print("Suggested sample dimension: %dx%d\n", w_tri, h_tri); 262 | print_usage(); 263 | goto END; 264 | } 265 | 266 | if((cfmt == CONV_FMT_ERP_TO_OHP) && (((w_out)%8 != 0 || 267 | h_out != 2*NEAREST_EVEN((((int)((int)((w_out)/4)/4)*4))*SIN_60)))) 268 | { 269 | /* some suggested dimensions */ 270 | int w_tri, h_tri; 271 | w_tri = ((int)((int)((w_out)/4)/4)*4); 272 | h_tri = NEAREST_EVEN((w_tri)*SIN_60); 273 | w_tri = w_tri*4; 274 | h_tri = h_tri*2; 275 | s360_print("Invalid output resolution %dx%d, OHP recommended aspect " 276 | " ratio: 224:97\n", w_out, h_out); 277 | s360_print("Suggested sample dimension: %dx%d\n", w_tri, h_tri); 278 | print_usage(); 279 | goto END; 280 | } 281 | 282 | if((cfmt == CONV_FMT_ISP_TO_RISP) && (w_out != (GET_W_TRI_ISP(w_in)>>1)*5 || 283 | (h_out) != GET_H_TRI_ISP(GET_W_TRI_ISP(w_in))*4 + (RISP2_PAD<<1))) 284 | { 285 | s360_print("Invalid output resolution %dx%d, RISP does not support " 286 | "resize\n:", w_out, h_out); 287 | s360_print("Suggested dimension: %dx%d\n", (GET_W_TRI_ISP(w_in)>>1)*5, 288 | GET_H_TRI_ISP(GET_W_TRI_ISP(w_in))*4 + (RISP2_PAD<<1)); 289 | print_usage(); 290 | goto END; 291 | } 292 | 293 | if((cfmt == CONV_FMT_OHP_TO_ROHP) && (w_out != w_in || (h_out*2) != h_in)) 294 | { 295 | s360_print("Invalid output resolution %dx%d, ROHP does not support " 296 | "resize\n:", w_out, h_out); 297 | s360_print("Suggested dimension: %dx%d\n", w_in, h_in/2); 298 | print_usage(); 299 | goto END; 300 | } 301 | 302 | if((cfmt == CONV_FMT_ERP_TO_TSP) && 303 | ((w_out%4 != 0 || h_out%4 != 0) || (w_out != h_out*2))) 304 | { 305 | s360_print("Invalid output resolution for TSP, suggested aspect " 306 | "ratio 2:1 and must be multiple of 4: %dx%d\n", w_out, h_out); 307 | s360_print("Suggested sample dimension: %dx%d\n", w_out, w_out/2); 308 | print_usage(); 309 | goto END; 310 | } 311 | 312 | if ((cfmt == CONV_FMT_ERP_TO_SSP || cfmt == CONV_FMT_CPP_TO_SSP) && 313 | ((w_out % 4 != 0 || h_out % 4 != 0) || (w_out * 3 != h_out * 4))) 314 | { 315 | s360_print("Invalid output resolution for SSP. " 316 | "Suggested aspect ratio 4:3\n"); 317 | print_usage(); 318 | goto END; 319 | } 320 | if((cfmt == CONV_FMT_ERP_TO_COHP) && (((w_out)%8 != 0 || 321 | h_out != 4*NEAREST_EVEN((((int)((int)((w_out)/4)/4)*4))*SIN_60)))) 322 | { 323 | /* some suggested dimensions */ 324 | int w_tri, h_tri; 325 | w_tri = ((int)((int)((w_out)/4)/4)*4); 326 | h_tri = NEAREST_EVEN((w_tri)*SIN_60); 327 | w_tri = w_tri*4; 328 | h_tri = h_tri*4; 329 | s360_print("Invalid output resolution %dx%d, COHP recommended aspect " 330 | " ratio: 112:97\n", w_out, h_out); 331 | s360_print("Suggested sample dimension: %dx%d\n", w_tri, h_tri); 332 | print_usage(); 333 | goto END; 334 | } 335 | 336 | if(!opt_flag[CMD_FLAG_CONV_OWIDTH]) w_out = w_in; 337 | if(!opt_flag[CMD_FLAG_CONV_OHEIGHT]) h_out = h_in; 338 | 339 | cs_in = (cs_in == 1)?S360_COLORSPACE_YUV420:S360_COLORSPACE_YUV420_10; 340 | cs_out = (cs_out == 1)?S360_COLORSPACE_YUV420:S360_COLORSPACE_YUV420_10; 341 | cs_int = (cs_int == 1)?S360_COLORSPACE_YUV420:S360_COLORSPACE_YUV420_10; 342 | 343 | if(!opt_flag[CMD_FLAG_CONV_CS_IN]) cs_in = S360_COLORSPACE_YUV420; 344 | if(!opt_flag[CMD_FLAG_CONV_CS_OUT]) cs_out = S360_COLORSPACE_YUV420; 345 | //Internal Bitdepth for 360Tools. Default 10-bit 346 | if(!opt_flag[CMD_FLAG_CONV_CS_INT]) cs_int = S360_COLORSPACE_YUV420_10; 347 | 348 | if(align > 0) 349 | { 350 | w_out = S360_ALIGN(w_out, align); 351 | h_out = S360_ALIGN(h_out, align); 352 | } 353 | 354 | if(cfmt == CONV_FMT_ISP_TO_RISP) 355 | { 356 | no_pad = 1; 357 | } 358 | 359 | if(!no_pad) 360 | { 361 | opt |= S360_OPT_PAD; 362 | } 363 | 364 | if (cfmt == CONV_FMT_ERP_TO_COHP) 365 | { 366 | imgos = s360_img_create(w_out, h_out, cs_int, opt); 367 | w_out = w_out * 2; 368 | } 369 | imgi = s360_img_create(w_in, h_in, cs_int, opt); 370 | imgo = s360_img_create(w_out, h_out, cs_int, opt); 371 | 372 | if(imgi == NULL || imgo == NULL) 373 | { 374 | s360_print("Failed to create image buffer\n"); 375 | goto END; 376 | } 377 | 378 | switch(cfmt) 379 | { 380 | case CONV_FMT_ERP_TO_CPP: 381 | fn_conv = s360_erp_to_cpp; 382 | break; 383 | case CONV_FMT_ERP_TO_ISP: 384 | fn_conv = s360_erp_to_isp; 385 | break; 386 | case CONV_FMT_ISP_TO_ERP: 387 | fn_conv = s360_isp_to_erp; 388 | break; 389 | case CONV_FMT_ERP_TO_CMP: 390 | fn_conv = s360_erp_to_cmp; 391 | break; 392 | case CONV_FMT_CMP_TO_ERP: 393 | fn_conv = s360_cmp_to_erp; 394 | break; 395 | case CONV_FMT_ERP_TO_OHP: 396 | fn_conv = s360_erp_to_ohp; 397 | break; 398 | case CONV_FMT_OHP_TO_ERP: 399 | fn_conv = s360_ohp_to_erp; 400 | break; 401 | case CONV_FMT_ERP_TO_TSP: 402 | fn_conv = s360_erp_to_tsp; 403 | break; 404 | case CONV_FMT_TSP_TO_ERP: 405 | fn_conv = s360_tsp_to_erp; 406 | break; 407 | case CONV_FMT_ERP_TO_SSP: 408 | fn_conv = o360_erp_to_ssp; 409 | break; 410 | case CONV_FMT_SSP_TO_ERP: 411 | fn_conv = o360_ssp_to_erp; 412 | break; 413 | case CONV_FMT_ISP_TO_RISP: 414 | fn_conv = s360_isp_to_risp2; 415 | break; 416 | case CONV_FMT_RISP_TO_ISP: 417 | fn_conv = s360_risp2_to_isp; 418 | break; 419 | case CONV_FMT_CMP_TO_RCMP: 420 | fn_conv = s360_cmp_to_rcmp; 421 | break; 422 | case CONV_FMT_RCMP_TO_CMP: 423 | fn_conv = s360_rcmp_to_cmp; 424 | break; 425 | case CONV_FMT_OHP_TO_ROHP: 426 | fn_conv = s360_ohp_to_rohp; 427 | break; 428 | case CONV_FMT_ROHP_TO_OHP: 429 | fn_conv = s360_rohp_to_ohp; 430 | break; 431 | case CONV_FMT_ERP_TO_RISP1: 432 | fn_conv = s360_erp_to_risp1; 433 | break; 434 | case CONV_FMT_RISP1_TO_ERP: 435 | fn_conv = s360_risp1_to_erp; 436 | break; 437 | case CONV_FMT_CPP_TO_ERP: 438 | fn_conv = s360_cpp_to_erp; 439 | break; 440 | case CONV_FMT_CPP_TO_ISP: 441 | fn_conv = s360_cpp_to_isp; 442 | break; 443 | case CONV_FMT_CPP_TO_CMP: 444 | fn_conv = s360_cpp_to_cmp; 445 | break; 446 | case CONV_FMT_CPP_TO_OHP: 447 | fn_conv = s360_cpp_to_ohp; 448 | break; 449 | case CONV_FMT_CPP_TO_SSP: 450 | fn_conv = o360_cpp_to_ssp; 451 | break; 452 | case CONV_FMT_ERP_TO_COHP: 453 | fn_conv = s360_erp_to_cohp; 454 | break; 455 | case CONV_FMT_COHP_TO_ERP: 456 | fn_conv = s360_cohp_to_erp; 457 | break; 458 | default: 459 | s360_print("Unsupprted converting format\n"); 460 | print_usage(); 461 | return -1; 462 | } 463 | 464 | ret = s360_init(); 465 | if(S360_FAILED(ret)) 466 | { 467 | s360_print("failed to initialize 360tools (ret=%d)\n", ret); 468 | print_usage(); 469 | goto END; 470 | } 471 | 472 | map = s360_map_create(w_in, h_in, w_out, h_out, cfmt, opt, pitch, yaw); 473 | 474 | while(s360_img_read(fpi, imgi, cs_in) == 0) 475 | { 476 | s360_print("[%4d]-frame: ", pic_cnt++); 477 | 478 | ret = fn_conv(imgi, imgo, opt, map); 479 | if(S360_SUCCEEDED(ret) && align != 0 && \ 480 | (imgi->width != imgo->width || imgi->height != imgo->height)) 481 | { 482 | s360_img_align(imgo, align); 483 | s360_print("%dx%d --> ", imgo->width, imgo->height); 484 | imgo->width = S360_ALIGN(imgo->width, align); 485 | imgo->height = S360_ALIGN(imgo->height, align); 486 | } 487 | 488 | if(S360_SUCCEEDED(ret)) 489 | { 490 | if (cfmt == CONV_FMT_ERP_TO_COHP) 491 | s360_print("convert succeeded: resolution= %dx%d\n", imgo->width / 2, imgo->height); 492 | else 493 | s360_print("convert succeeded: resolution= %dx%d\n", imgo->width, imgo->height); 494 | } 495 | else 496 | { 497 | s360_print("convert failed: ret = %d\n", ret); 498 | goto END; 499 | } 500 | 501 | if (cfmt == CONV_FMT_ERP_TO_COHP) 502 | { 503 | s360_img_copy(imgos, imgo); 504 | } 505 | 506 | fpo = fopen(fname_out, "ab"); 507 | if(fpo) 508 | { 509 | if (cfmt == CONV_FMT_ERP_TO_COHP) 510 | { 511 | s360_img_write(fpo, imgos, cs_out); 512 | } 513 | else 514 | { 515 | s360_img_write(fpo, imgo, cs_out); 516 | } 517 | fclose(fpo); 518 | } 519 | 520 | if(frm_num > 0 && pic_cnt >= frm_num) break; 521 | } 522 | 523 | END: 524 | if(fpi) fclose(fpi); 525 | if(imgi) s360_img_delete(imgi); 526 | if(imgo) s360_img_delete(imgo); 527 | if(imgos) s360_img_delete(imgos); 528 | if(map) s360_map_delete(map); 529 | 530 | s360_deinit(); 531 | 532 | return 0; 533 | } 534 | 535 | -------------------------------------------------------------------------------- /app/360tools_metric/360tools_metric.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samsung/360tools/54845f00f178a07ff8c52c5ca1ae3103fa8ba836/app/360tools_metric/360tools_metric.c -------------------------------------------------------------------------------- /build/x86_linux/Makefile: -------------------------------------------------------------------------------- 1 | DIR_TOP = ../.. 2 | DIR_INC = $(DIR_TOP)/src 3 | DIR_SRC = $(DIR_TOP)/src 4 | DIR_APP = $(DIR_TOP)/app 5 | DIR_LIB = $(DIR_TOP)/lib 6 | DIR_BIN = $(DIR_TOP)/bin 7 | 8 | CC = gcc 9 | AR = ar 10 | LD = ld 11 | CXX = g++ 12 | 13 | MKDIR = mkdir -p 14 | RM = rm -rf 15 | 16 | CFLAGS = -I$(DIR_INC) -g -O2 17 | LDFLAGS = -L$(DIR_LIB) -l360tools -lm 18 | ARFLAGS = r 19 | 20 | CSRCS = $(DIR_SRC)/360tools.c \ 21 | $(DIR_SRC)/360tools_img.c \ 22 | $(DIR_SRC)/360tools_erp.c \ 23 | $(DIR_SRC)/360tools_isp.c \ 24 | $(DIR_SRC)/360tools_cmp.c \ 25 | $(DIR_SRC)/360tools_cpp.c \ 26 | $(DIR_SRC)/360tools_ohp.c \ 27 | $(DIR_SRC)/360tools_tsp.c \ 28 | $(DIR_SRC)/360tools_map.c \ 29 | $(DIR_SRC)/360tools_ssp.c \ 30 | $(DIR_SRC)/360tools_tbl.c 31 | 32 | CSRCS_APP = $(DIR_APP)/360tools_conv/360tools_conv.c \ 33 | $(DIR_APP)/360tools_metric/360tools_metric.c 34 | 35 | OBJS = $(CSRCS:.c=.o) 36 | 37 | all: RELEASE 38 | 39 | # target for release mode 40 | RELEASE: depend $(OBJS) 41 | $(MKDIR) $(DIR_LIB) 42 | $(AR) $(ARFLAGS) $(DIR_LIB)/lib360tools.a $(OBJS) 43 | $(MKDIR) $(DIR_BIN) 44 | $(CC) -o $(DIR_BIN)/360tools_conv $(CFLAGS) $(DIR_APP)/360tools_conv/360tools_conv.c $(LDFLAGS) 45 | $(CC) -o $(DIR_BIN)/360tools_metric $(CFLAGS) $(DIR_APP)/360tools_metric/360tools_metric.c $(LDFLAGS) 46 | 47 | 48 | depend: Makefile $(CSRCS) $(CSRCS_APP) 49 | $(CC) -M $(CFLAGS) $(CSRCS) $(CSRCS_APP) > .$@ 50 | 51 | 52 | 53 | 54 | clean: 55 | $(RM) $(OBJS) $(DIR_LIB) $(DIR_BIN) .depend 56 | 57 | %.o: %.c 58 | $(CC) -c -o $@ $(CFLAGS) $< 59 | 60 | -include .depend 61 | 62 | -------------------------------------------------------------------------------- /build/x86_windows/360tools_conv_vs2008.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 26 | 29 | 32 | 35 | 38 | 41 | 53 | 56 | 59 | 62 | 70 | 73 | 76 | 79 | 82 | 85 | 88 | 91 | 92 | 100 | 103 | 106 | 109 | 112 | 115 | 127 | 130 | 133 | 136 | 146 | 149 | 152 | 155 | 158 | 161 | 164 | 167 | 168 | 169 | 170 | 171 | 172 | 177 | 180 | 181 | 182 | 187 | 188 | 193 | 194 | 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /build/x86_windows/360tools_conv_vs2010.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 360tools_conv 15 | {B173BC68-FBF2-412A-960B-2A47852FDB97} 16 | My360tools 17 | Win32Proj 18 | 19 | 20 | 21 | Application 22 | Unicode 23 | true 24 | 25 | 26 | Application 27 | Unicode 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | <_ProjectFileVersion>10.0.40219.1 41 | $(SolutionDir)$(Configuration)\ 42 | $(Configuration)\ 43 | true 44 | ..\..\bin\ 45 | $(Configuration)\ 46 | false 47 | 48 | 49 | 50 | Disabled 51 | ..\..\src;%(AdditionalIncludeDirectories) 52 | X86F; WIN32;%(PreprocessorDefinitions) 53 | true 54 | EnableFastChecks 55 | MultiThreadedDebugDLL 56 | 57 | 58 | Level3 59 | EditAndContinue 60 | 61 | 62 | $(SolutionDir)$(Configuration)\$(ProjectName).exe 63 | true 64 | Console 65 | MachineX86 66 | $(SolutionDir)$(Configuration)\360tools_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 67 | 68 | 69 | 70 | 71 | MaxSpeed 72 | true 73 | ..\..\src;%(AdditionalIncludeDirectories) 74 | X86F; WIN32;%(PreprocessorDefinitions) 75 | MultiThreadedDLL 76 | true 77 | 78 | 79 | Level3 80 | ProgramDatabase 81 | 82 | 83 | ..\..\bin\$(ProjectName).exe 84 | true 85 | Console 86 | true 87 | true 88 | MachineX86 89 | $(SolutionDir)$(Configuration)\360tools_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | {eceb74a8-11f9-4ca1-841f-d6d2ad7fe14c} 98 | false 99 | 100 | 101 | {1e352747-645b-4206-b373-fe98a18c5390} 102 | false 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /build/x86_windows/360tools_lib_vs2008.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 25 | 28 | 31 | 34 | 37 | 40 | 51 | 54 | 57 | 60 | 64 | 67 | 70 | 73 | 76 | 79 | 80 | 88 | 91 | 94 | 97 | 100 | 103 | 114 | 117 | 120 | 123 | 127 | 130 | 133 | 136 | 139 | 142 | 143 | 144 | 145 | 146 | 147 | 152 | 155 | 156 | 159 | 160 | 163 | 164 | 167 | 168 | 171 | 172 | 175 | 176 | 179 | 180 | 183 | 184 | 187 | 188 | 191 | 192 | 195 | 196 | 197 | 202 | 205 | 206 | 209 | 210 | 213 | 214 | 217 | 218 | 221 | 222 | 225 | 226 | 229 | 230 | 233 | 234 | 237 | 238 | 241 | 242 | 245 | 246 | 249 | 250 | 251 | 256 | 257 | 258 | 259 | 260 | 261 | -------------------------------------------------------------------------------- /build/x86_windows/360tools_lib_vs2010.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 360tools_lib 15 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C} 16 | My360tools_lib 17 | 18 | 19 | 20 | StaticLibrary 21 | MultiByte 22 | true 23 | 24 | 25 | StaticLibrary 26 | MultiByte 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | <_ProjectFileVersion>10.0.40219.1 40 | $(SolutionDir)$(Configuration)\ 41 | $(Configuration)\ 42 | $(SolutionDir)$(Configuration)\ 43 | $(Configuration)\ 44 | $(ProjectName) 45 | 46 | 47 | 48 | Disabled 49 | %(AdditionalIncludeDirectories) 50 | X86F; WIN32; _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 51 | true 52 | EnableFastChecks 53 | MultiThreadedDebugDLL 54 | Level3 55 | EditAndContinue 56 | 57 | 58 | $(SolutionDir)$(Configuration)\360tools_lib.lib 59 | 60 | 61 | 62 | 63 | MaxSpeed 64 | true 65 | %(AdditionalIncludeDirectories) 66 | X86F; WIN32; _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 67 | MultiThreadedDLL 68 | true 69 | Level3 70 | ProgramDatabase 71 | 72 | 73 | $(SolutionDir)$(Configuration)\360tools_lib.lib 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /build/x86_windows/360tools_metric_vs2008.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 25 | 28 | 31 | 34 | 37 | 40 | 50 | 53 | 56 | 59 | 65 | 68 | 71 | 74 | 77 | 80 | 83 | 86 | 87 | 95 | 98 | 101 | 104 | 107 | 110 | 120 | 123 | 126 | 129 | 137 | 140 | 143 | 146 | 149 | 152 | 155 | 158 | 159 | 160 | 161 | 162 | 163 | 168 | 171 | 172 | 173 | 178 | 179 | 184 | 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /build/x86_windows/360tools_metric_vs2010.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 360tools_metric 15 | {1E352747-645B-4206-B373-FE98A18C5390} 16 | My360tools_metric 17 | 18 | 19 | 20 | Application 21 | MultiByte 22 | true 23 | 24 | 25 | Application 26 | MultiByte 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | <_ProjectFileVersion>10.0.40219.1 40 | $(SolutionDir)$(Configuration)\ 41 | $(Configuration)\ 42 | ..\..\bin\ 43 | $(Configuration)\ 44 | 45 | 46 | 47 | Disabled 48 | ..\..\src;%(AdditionalIncludeDirectories) 49 | true 50 | EnableFastChecks 51 | MultiThreadedDebugDLL 52 | Level3 53 | EditAndContinue 54 | 55 | 56 | $(SolutionDir)$(Configuration)\$(ProjectName).exe 57 | true 58 | MachineX86 59 | 60 | 61 | 62 | 63 | MaxSpeed 64 | true 65 | ..\..\src;%(AdditionalIncludeDirectories) 66 | MultiThreadedDLL 67 | true 68 | Level3 69 | ProgramDatabase 70 | 71 | 72 | ..\..\bin\$(ProjectName).exe 73 | true 74 | true 75 | true 76 | MachineX86 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | {eceb74a8-11f9-4ca1-841f-d6d2ad7fe14c} 85 | false 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /build/x86_windows/360tools_vs2008.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "360tools_conv", "360tools_conv_vs2008.vcproj", "{B173BC68-FBF2-412A-960B-2A47852FDB97}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {1E352747-645B-4206-B373-FE98A18C5390} = {1E352747-645B-4206-B373-FE98A18C5390} 7 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C} = {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C} 8 | EndProjectSection 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "360tools_lib", "360tools_lib_vs2008.vcproj", "{ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "360tools_metric", "360tools_metric_vs2008.vcproj", "{1E352747-645B-4206-B373-FE98A18C5390}" 13 | ProjectSection(ProjectDependencies) = postProject 14 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C} = {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C} 15 | EndProjectSection 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Win32 = Debug|Win32 20 | Release|Win32 = Release|Win32 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {B173BC68-FBF2-412A-960B-2A47852FDB97}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {B173BC68-FBF2-412A-960B-2A47852FDB97}.Debug|Win32.Build.0 = Debug|Win32 25 | {B173BC68-FBF2-412A-960B-2A47852FDB97}.Release|Win32.ActiveCfg = Release|Win32 26 | {B173BC68-FBF2-412A-960B-2A47852FDB97}.Release|Win32.Build.0 = Release|Win32 27 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}.Debug|Win32.ActiveCfg = Debug|Win32 28 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}.Debug|Win32.Build.0 = Debug|Win32 29 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}.Release|Win32.ActiveCfg = Release|Win32 30 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}.Release|Win32.Build.0 = Release|Win32 31 | {1E352747-645B-4206-B373-FE98A18C5390}.Debug|Win32.ActiveCfg = Debug|Win32 32 | {1E352747-645B-4206-B373-FE98A18C5390}.Debug|Win32.Build.0 = Debug|Win32 33 | {1E352747-645B-4206-B373-FE98A18C5390}.Release|Win32.ActiveCfg = Release|Win32 34 | {1E352747-645B-4206-B373-FE98A18C5390}.Release|Win32.Build.0 = Release|Win32 35 | EndGlobalSection 36 | GlobalSection(SolutionProperties) = preSolution 37 | HideSolutionNode = FALSE 38 | EndGlobalSection 39 | EndGlobal 40 | -------------------------------------------------------------------------------- /build/x86_windows/360tools_vs2010.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "360tools_conv", "360tools_conv_vs2010.vcxproj", "{B173BC68-FBF2-412A-960B-2A47852FDB97}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "360tools_lib", "360tools_lib_vs2010.vcxproj", "{ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "360tools_metric", "360tools_metric_vs2010.vcxproj", "{1E352747-645B-4206-B373-FE98A18C5390}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Win32 = Debug|Win32 13 | Release|Win32 = Release|Win32 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {B173BC68-FBF2-412A-960B-2A47852FDB97}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {B173BC68-FBF2-412A-960B-2A47852FDB97}.Debug|Win32.Build.0 = Debug|Win32 18 | {B173BC68-FBF2-412A-960B-2A47852FDB97}.Release|Win32.ActiveCfg = Release|Win32 19 | {B173BC68-FBF2-412A-960B-2A47852FDB97}.Release|Win32.Build.0 = Release|Win32 20 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}.Debug|Win32.ActiveCfg = Debug|Win32 21 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}.Debug|Win32.Build.0 = Debug|Win32 22 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}.Release|Win32.ActiveCfg = Release|Win32 23 | {ECEB74A8-11F9-4CA1-841F-D6D2AD7FE14C}.Release|Win32.Build.0 = Release|Win32 24 | {1E352747-645B-4206-B373-FE98A18C5390}.Debug|Win32.ActiveCfg = Debug|Win32 25 | {1E352747-645B-4206-B373-FE98A18C5390}.Debug|Win32.Build.0 = Debug|Win32 26 | {1E352747-645B-4206-B373-FE98A18C5390}.Release|Win32.ActiveCfg = Release|Win32 27 | {1E352747-645B-4206-B373-FE98A18C5390}.Release|Win32.Build.0 = Release|Win32 28 | EndGlobalSection 29 | GlobalSection(SolutionProperties) = preSolution 30 | HideSolutionNode = FALSE 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /src/360tools.c: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "360tools.h" 35 | #include 36 | #include "360tools_def.h" 37 | #include "360tools_img.h" 38 | 39 | #if LANCZOS_FAST_MODE 40 | static double tbl_lanczos_coef[LANCZOS_FAST_MAX_SIZE * LANCZOS_FAST_SCALE]; 41 | #endif 42 | 43 | double v3d_norm(double v[3]) 44 | { 45 | double d = GET_DIST3D(v[0], v[1], v[2]); 46 | if (d != 0) 47 | { 48 | v[0] /= d; 49 | v[1] /= d; 50 | v[2] /= d; 51 | } 52 | return d; 53 | } 54 | 55 | double v3d_dot_product(double v1[3], double v2[3]) 56 | { 57 | return S360_ABS((v1[0] * v2[0]) + (v1[1] * v2[1]) + (v1[2] * v2[2])); 58 | } 59 | 60 | void cart_to_sph(double x, double y, double z, S360_SPH_COORD * coord) 61 | { 62 | coord->lat = (float)RAD2DEG(acos(z)); 63 | if (coord->lat > 180) coord->lat = 180; 64 | 65 | if (x < 0) 66 | { 67 | coord->lng = 180.0f - (float)RAD2DEG(-atan(y / x)); 68 | } 69 | else if (x == 0) 70 | { 71 | if (y < 0) 72 | { 73 | coord->lng = 270; 74 | } 75 | else if (y == 0) 76 | { 77 | coord->lng = (z < 0 ? 270.0f : 90.0f); 78 | } 79 | else 80 | { 81 | coord->lng = 90; 82 | } 83 | } 84 | else /* x>0 */ 85 | { 86 | coord->lng = (float)RAD2DEG(atan(y / x)); 87 | if (coord->lng < 0) coord->lng += 360; 88 | } 89 | 90 | if (coord->lng == 0) coord->lng = 0.01f; 91 | if (coord->lng == 360) coord->lng = 359.99f; 92 | } 93 | 94 | void v3d_scale_face(double eqn[3], double vec[3]) 95 | { 96 | double scale = (eqn[3]) / (eqn[0] * vec[0] + eqn[1] * vec[1] + eqn[2] * vec[2]); 97 | vec[0] = (vec[0] * scale); 98 | vec[1] = (vec[1] * scale); 99 | vec[2] = (vec[2] * scale); 100 | } 101 | 102 | void cmp_plane_offset(int *x, int *y, int squ_idx, int w_squ) 103 | { 104 | switch (squ_idx) 105 | { 106 | case 0: 107 | *x = w_squ; 108 | *y = 0; 109 | break; 110 | case 1: 111 | *x = w_squ; 112 | *y = w_squ; 113 | break; 114 | case 2: 115 | *x = w_squ; 116 | *y = 2 * w_squ; 117 | break; 118 | case 3: 119 | *x = 0; 120 | *y = w_squ; 121 | break; 122 | case 4: 123 | *x = 2 * w_squ; 124 | *y = w_squ; 125 | break; 126 | case 5: 127 | *x = 3 * w_squ; 128 | *y = w_squ; 129 | break; 130 | default: 131 | break; 132 | } 133 | } 134 | 135 | void rcmp_plane_offset(int *x, int *y, int squ_idx, int w_squ) 136 | { 137 | switch (squ_idx) 138 | { 139 | case 0: 140 | // 180 deg rotate 141 | *x = 2*w_squ; 142 | *y = w_squ; 143 | break; 144 | case 1: 145 | *x = 2*w_squ; 146 | *y = 0; 147 | break; 148 | case 2: 149 | *x = 0; 150 | *y = w_squ; 151 | break; 152 | case 3: 153 | *x = w_squ; 154 | *y = 0; 155 | break; 156 | case 4: 157 | // 90 deg rotate 158 | *x = w_squ; 159 | *y = w_squ; 160 | break; 161 | case 5: 162 | *x = 0; 163 | *y = 0; 164 | break; 165 | default: 166 | break; 167 | } 168 | 169 | } 170 | 171 | void cpp_map_plane(int w_map, int h_map, int s_map, uint8 * map) 172 | { 173 | int i, j; 174 | int idx_x, idx_y; 175 | double x, y, phi, lambda; 176 | 177 | s360_mset(map, 0, w_map * h_map); 178 | 179 | for(j=0;j= 0 && idx_x >= 0 && idx_x < w_map && idx_y < h_map) 193 | { 194 | map[i+j*w_map] = 1; 195 | } 196 | } 197 | } 198 | } 199 | 200 | void pad_cpp_plane(uint8 * buf, int w, int h, int s, uint8 * map0) 201 | { 202 | uint8 * map = map0; 203 | int i, j, cnt; 204 | 205 | for(j=0; j R */ 210 | if(map[i] == 1) 211 | { 212 | cnt = S360_MIN(PAD_SIZE, i); 213 | s360_mset(buf + i - cnt, buf[i], cnt); 214 | 215 | while(map[i] == 1 && i < w) i++; 216 | cnt = S360_MIN(PAD_SIZE, w - i); 217 | s360_mset(buf + i, buf[i-1], cnt); 218 | break; 219 | } 220 | } 221 | buf += s; 222 | map += w; 223 | } 224 | } 225 | 226 | void pad_cpp_plane_10b(uint16 * buf, int w, int h, int s, uint8 * map0) 227 | { 228 | uint8 * map = map0; 229 | int i, j, k, cnt; 230 | 231 | for(j=0; j R */ 236 | if(map[i] == 1) 237 | { 238 | cnt = S360_MIN(PAD_SIZE, i); 239 | for(k=1;k<=cnt;k++) 240 | { 241 | buf[i-k] = buf[i]; 242 | } 243 | 244 | while(map[i] == 1 && i < w) i++; 245 | cnt = S360_MIN(PAD_SIZE, w - i); 246 | for(k=0;k -0.01) 263 | { 264 | double x2 = x * x; 265 | return 1.0f + x2 * (-1.0 / 6.0 + x2 / 120.0); 266 | } 267 | else 268 | { 269 | return sin(x) / x; 270 | } 271 | } 272 | 273 | #if !LANCZOS_FAST_MODE 274 | static double lanczos_coef(double x) 275 | { 276 | return sinc(x) * sinc(x / LANCZOS_TAB_SIZE); 277 | } 278 | #else 279 | #define lanczos_coef(x) tbl_lanczos_coef[(int)(fabs(x) * LANCZOS_FAST_SCALE + 0.5)] 280 | #endif 281 | 282 | int s360_init(void) 283 | { 284 | #if LANCZOS_FAST_MODE 285 | int i; 286 | for(i=0; i= w_start && idx_y >= h_start && idx_x < w_end && idx_y < h_end) 319 | { 320 | coef = (float)(lanczos_coef(x - idx_x) * lanczos_coef(y - idx_y)); 321 | res += src_8[idx_x + idx_y * s_src] * coef; 322 | sum += coef; 323 | } 324 | } 325 | } 326 | if(sum != 0) 327 | { 328 | i = (int)(res / sum + 0.5); 329 | dst_8[x_dst] = S360_CLIP_S32_TO_U8(i); 330 | } 331 | } 332 | 333 | /* lanczos for 10-bit*/ 334 | void resample_2d_10b(void * src, int w_start, int w_end, int h_start, int h_end,\ 335 | int s_src, double x, double y, void * dst, int x_dst) 336 | { 337 | double coef, sum = 0, res = 0; 338 | int i, j, idx_x, idx_y; 339 | uint16 * src_16; 340 | uint16 * dst_16; 341 | 342 | src_16 = (uint16 *)src; 343 | dst_16 = (uint16 *)dst; 344 | 345 | for(j=-LANCZOS_TAB_SIZE; j= w_start && idx_y >= h_start && idx_x < w_end && idx_y < h_end) 352 | { 353 | coef = lanczos_coef(x - idx_x) * lanczos_coef(y - idx_y); 354 | res += src_16[idx_x + idx_y * s_src] * coef; 355 | sum += coef; 356 | } 357 | } 358 | } 359 | if(sum != 0) 360 | { 361 | i = (int)(res / sum + 0.5); 362 | dst_16[x_dst] = S360_CLIP_S32_TO_U10(i); 363 | } 364 | } 365 | 366 | /* bi-linear */ 367 | void resample_bl_2d(void * src, int w_start, int w_end, int h_start, int h_end,\ 368 | int s_src, double x, double y, void * dst, int x_dst) 369 | { 370 | int val; 371 | int w_src; 372 | uint8 * src_8; 373 | uint8 * dst_8; 374 | 375 | src_8 = (uint8 *)src; 376 | dst_8 = (uint8 *)dst; 377 | 378 | w_src = w_end - w_start; 379 | 380 | if(x > w_start-1 && y > w_end-1 && x < w_src && y < h_end) 381 | { 382 | double dx = x - (int)x; 383 | double dy = y - (int)y; 384 | double w0 = (1 - dx) * (1 - dy); 385 | double w1 = dx * (1 - dy); 386 | double w2 = (1 - dx) * dy; 387 | double w3 = dx * dy; 388 | 389 | double s0, s1, s2, s3; 390 | 391 | int ox = ((int)x + 1 < w_src ? 1 : 0); 392 | int oy = ((int)y + 1 < h_end ? s_src : 0); 393 | int off0 = ((int)x + (int)y * s_src); 394 | int off1 = off0 + ox; 395 | int off2 = off0 + oy; 396 | int off3 = off1 + oy; 397 | 398 | s0 = src_8[off0]; 399 | s1 = src_8[off1]; 400 | s2 = src_8[off2]; 401 | s3 = src_8[off3]; 402 | val = (int)(w0 * s0 + w1 * s1 + w2 * s2 + w3 * s3 + 0.5); 403 | dst_8[x_dst] = S360_CLIP_S32_TO_U8(val); 404 | } 405 | } 406 | 407 | /* bi-linear */ 408 | void resample_bl_2d_10b(void * src, int w_start, int w_end, int h_start, int h_end,\ 409 | int s_src, double x, double y, void * dst, int x_dst) 410 | { 411 | int val; 412 | int w_src; 413 | uint16 * src_16; 414 | uint16 * dst_16; 415 | 416 | src_16 = (uint16 *)src; 417 | dst_16 = (uint16 *)dst; 418 | 419 | w_src = w_end - w_start; 420 | 421 | if(x > -1 && y > -1 && x < w_src && y < h_end) 422 | { 423 | double dx = x - (int)x; 424 | double dy = y - (int)y; 425 | double w0 = (1 - dx) * (1 - dy); 426 | double w1 = dx * (1 - dy); 427 | double w2 = (1 - dx) * dy; 428 | double w3 = dx * dy; 429 | 430 | double s0, s1, s2, s3; 431 | 432 | int ox = ((int)x + 1 < w_src ? 1 : 0); 433 | int oy = ((int)y + 1 < h_end ? s_src : 0); 434 | int off0 = ((int)x + (int)y * s_src); 435 | int off1 = off0 + ox; 436 | int off2 = off0 + oy; 437 | int off3 = off1 + oy; 438 | 439 | s0 = src_16[off0]; 440 | s1 = src_16[off1]; 441 | s2 = src_16[off2]; 442 | s3 = src_16[off3]; 443 | val = (int)(w0 * s0 + w1 * s1 + w2 * s2 + w3 * s3 + 0.5); 444 | dst_16[x_dst] = S360_CLIP_S32_TO_U10(val); 445 | } 446 | } 447 | 448 | /* TSP related */ 449 | 450 | void resample_tsp_2d(void * src, int w_start, int w_end, int w_src, int h_src, int s_src, \ 451 | void * dst, int w_dst, int i, int j, S360_SPH_COORD * map) 452 | { 453 | int x, y, m, n; 454 | uint8 * src_8; 455 | uint8 * dst_8; 456 | int sub = TSPAA_S; 457 | int num = 0; 458 | int subdiv2 = (sub>>1); 459 | uint32 map_idx = 0, sum = 0, a = 0; 460 | 461 | src_8 = (uint8 *)src; 462 | dst_8 = (uint8 *)dst; 463 | 464 | for (n = -subdiv2; n <= subdiv2; n++) 465 | { 466 | for (m = -subdiv2; m <= subdiv2; m++) 467 | { 468 | int idx_x = i * sub + m; 469 | int idx_y = j * sub + n; 470 | if (idx_x < 0) idx_x = 0; 471 | if (idx_y < 0) idx_y = 0; 472 | map_idx = idx_y * w_dst * sub + idx_x; 473 | if (map[map_idx].lng != -1) 474 | { 475 | x = (int)(map[map_idx].lng * w_src / 360.0 + 0.5); 476 | y = (int)(map[map_idx].lat * h_src / 180.0 + 0.5); 477 | 478 | if(y >= 0 && x >= w_start && x < w_end && y < h_src) 479 | { 480 | sum += src_8[x + y * s_src]; 481 | num++; 482 | } 483 | } 484 | } 485 | } 486 | if (num > 0) 487 | { 488 | a = (sum + (num>>1))/num; 489 | } 490 | dst_8[i] = S360_CLIP_S32_TO_U8((int)a); 491 | } 492 | 493 | void resample_tsp_2d_10b(void * src, int w_start, int w_end, int w_src, int h_src, int s_src, \ 494 | void * dst, int w_dst, int i, int j, S360_SPH_COORD * map) 495 | { 496 | int x, y, m, n; 497 | uint16 * src_16; 498 | uint16 * dst_16; 499 | int sub = TSPAA_S; 500 | int num = 0; 501 | int subdiv2 = (sub>>1); 502 | uint32 map_idx = 0, sum = 0, a = 0; 503 | 504 | src_16 = (uint16 *)src; 505 | dst_16 = (uint16 *)dst; 506 | 507 | for (n = -subdiv2; n <= subdiv2; n++) 508 | { 509 | for (m = -subdiv2; m <= subdiv2; m++) 510 | { 511 | int idx_x = i * sub + m; 512 | int idx_y = j * sub + n; 513 | if (idx_x < 0) idx_x = 0; 514 | if (idx_y < 0) idx_y = 0; 515 | map_idx = idx_y * w_dst * sub + idx_x; 516 | if (map[map_idx].lng != -1) 517 | { 518 | x = (int)(map[map_idx].lng * w_src / 360.0 + 0.5); 519 | y = (int)(map[map_idx].lat * h_src / 180.0 + 0.5); 520 | 521 | if(y >= 0 && x >= w_start && x < w_end && y < h_src) 522 | { 523 | sum += src_16[x + y * s_src]; 524 | num++; 525 | } 526 | } 527 | } 528 | } 529 | if (num > 0) 530 | { 531 | a = (sum + (num>>1))/num; 532 | } 533 | dst_16[i] = S360_CLIP_S32_TO_U10((int)a); 534 | } 535 | 536 | resample_fn resample_fp(int cs) 537 | { 538 | if (cs == S360_COLORSPACE_YUV420) 539 | { 540 | return resample_2d; 541 | } 542 | else if (cs == S360_COLORSPACE_YUV420_10) 543 | { 544 | return resample_2d_10b; 545 | } 546 | else 547 | { 548 | return resample_2d_10b; 549 | } 550 | } 551 | -------------------------------------------------------------------------------- /src/360tools.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __360TOOLS_H__218937465289347652834659823659823746592834765__ 35 | #define __360TOOLS_H__218937465289347652834659823659823746592834765__ 36 | 37 | 38 | #ifdef __cplusplus 39 | extern "C" 40 | { 41 | #endif 42 | 43 | #include 44 | #include "360tools_def.h" 45 | #include "360tools_args.h" 46 | #include "360tools_img.h" 47 | #include "360tools_map.h" 48 | 49 | /* various options for each projections **************************************/ 50 | #define S360_OPT_PAD (1<<0) 51 | 52 | /* constants *****************************************************************/ 53 | #define PI (3.14159265358979323846f) 54 | #define SIN_60 (0.86602540378443864676f) 55 | #define SQRT_3 (1.73205080756887729352f) 56 | #define WS_PSNR_ISP_MAGIC (0.13741115595829543934f) 57 | #ifndef M_PI_2 58 | #define M_PI_2 (1.5707963f) /* pi/2 */ 59 | #endif 60 | #define M_2PI (6.2831853f) /* pi*2 */ 61 | 62 | /* utilities *****************************************************************/ 63 | #define DEG2RAD(deg) ((deg) * PI / 180.0f) 64 | #define RAD2DEG(rad) ((rad) * 180.0f / PI) 65 | #define CEILING(x) ((x) - (int)(x) > 0 ? (int)(x) + 1 : (int)(x)) 66 | #define NEAREST_EVEN(x) ((int)(x) + ((int)(x) & 1)) 67 | #define ROUNDUP_EVEN(x) ((int)((x) + 1) & 0xFFFFFFFE) 68 | #define ROUNDDN_EVEN(x) ((int)(x) & 0xFFFFFFFE) 69 | 70 | /* 3D coordinates to lat and long ********************************************/ 71 | void cart_to_sph(double x, double y, double z, S360_SPH_COORD * coord); 72 | 73 | /* resample functions ********************************************************/ 74 | #define WIDTH_CPP 3840 75 | #define HEIGHT_CPP 1920 76 | #define LANCZOS_TAB_SIZE 3 77 | #define LANCZOS_FAST_MODE 1 78 | #if LANCZOS_FAST_MODE 79 | #define LANCZOS_FAST_SCALE 100 80 | #define LANCZOS_FAST_MAX_SIZE (LANCZOS_TAB_SIZE << 1) 81 | #endif 82 | void resample_2d(void * src, int w_start, int w_end, int h_start, int h_end,\ 83 | int s_src, double x, double y, void * dst, int x_dst); 84 | void resample_2d_10b(void * src, int w_start, int w_end, int h_start, int h_end,\ 85 | int s_src, double x, double y, void * dst, int x_dst); 86 | void resample_bl_2d(void * src, int w_start, int w_end, int h_start, int h_end,\ 87 | int s_src, double x, double y, void * dst, int x_dst); 88 | void resample_bl_2d_10b(void * src, int w_start, int w_end, int h_start, int h_end,\ 89 | int s_src, double x, double y, void * dst, int x_dst); 90 | void resample_tsp_2d(void * src, int w_start, int w_end, int w_src, int h_src, \ 91 | int s_src, void * dst, int w_dst, int i, int j, S360_SPH_COORD * map); 92 | void resample_tsp_2d_10b(void * src, int w_start, int w_end, int w_src, \ 93 | int h_src, int s_src, void * dst, int w_dst, int i, int j, S360_SPH_COORD * map); 94 | resample_fn resample_fp(int cs); 95 | 96 | /* padding *******************************************************************/ 97 | #define USE_MIRROR_PADDING 1 98 | #define PAD_SIZE 16 99 | #define PAD_SIZE_RISP 16 100 | #define PAD_ALIGN 3 101 | #define RISP2_PAD 20 102 | 103 | void cpp_map_plane(int w_map, int h_map, int s_map, uint8 * map); 104 | void pad_cpp_plane(uint8 * buf, int w, int h, int s, uint8 * map0); 105 | void pad_cpp_plane_10b(uint16 * buf, int w, int h, int s, uint8 * map0); 106 | 107 | /* cube face *****************************************************************/ 108 | void cmp_plane_offset(int *x, int *y, int squ_idx, int w_squ); 109 | void rcmp_plane_offset(int *x, int *y, int squ_idx, int w_squ); 110 | void v3d_scale_face(double eqn[3], double vec[3]); 111 | 112 | /* vector calculation ********************************************************/ 113 | #define GET_DIST3D(x, y, z) sqrt((x)*(x) + (y)*(y) + (z)*(z)) 114 | #define v3d_sub(v0, v1, res) \ 115 | (res)[0] = (v0)[0] - (v1)[0]; \ 116 | (res)[1] = (v0)[1] - (v1)[1]; \ 117 | (res)[2] = (v0)[2] - (v1)[2] 118 | #define v3d_scale(v, scale) \ 119 | (v)[0] *= scale; \ 120 | (v)[1] *= scale; \ 121 | (v)[2] *= scale 122 | #define v3d_dot(v0, v1, res) \ 123 | (res)[0] = (v0)[0] * (v1)[0]; \ 124 | (res)[1] = (v0)[1] * (v1)[1]; \ 125 | (res)[2] = (v0)[2] * (v1)[2] 126 | #define v3d_affine(v, scale, trans, res) \ 127 | (res)[0] = (v)[0] * (scale) + (trans)[0]; \ 128 | (res)[1] = (v)[1] * (scale) + (trans)[1]; \ 129 | (res)[2] = (v)[2] * (scale) + (trans)[2] 130 | #define v3d_average(v0, v1, res) \ 131 | (res)[0] = ((v0)[0] + (v1)[0]) / 2; \ 132 | (res)[1] = ((v0)[1] + (v1)[1]) / 2; \ 133 | (res)[2] = ((v0)[2] + (v1)[2]) / 2 134 | double v3d_norm(double v[3]); 135 | double v3d_dot_product(double v1[3], double v2[3]); 136 | 137 | /* isp triangle calculations *************************************************/ 138 | #define GET_W_TRI_ISP(w_erp) ((int)((int)((w_erp) / 5.5) / 4) * 4) 139 | #define GET_H_TRI_ISP(w_tri) NEAREST_EVEN((w_tri) * SIN_60) 140 | 141 | /* ohp triangle calculations *************************************************/ 142 | #define GET_W_TRI_OHP(w_erp) ((int)((int)((w_erp) / 4) / 2) * 2) 143 | #define GET_H_TRI_OHP(w_tri) NEAREST_EVEN((w_tri) * SIN_60) 144 | 145 | /* tables ********************************************************************/ 146 | extern const double tbl_squ_xyz[8][3]; 147 | extern const double tbl_squ_center_xyz[6][3]; 148 | extern const int tbl_vidx_erp2cmp[6][4]; 149 | extern double tbl_face_eqn[6][4]; 150 | 151 | extern const int tbl_vidx_erp2tsp[6][4]; 152 | extern double tbl_tspface_eqn[6][4]; 153 | extern double tbl_tsp_center_xyz[6][3]; 154 | 155 | extern double tbl_tri_xyz[12][3]; 156 | extern const int tbl_vidx_erp2isp[20][3]; 157 | extern const int tbl_vidx_isp2erp[20][3]; 158 | extern const int tbl_vidx_pad_isp[20][2]; 159 | 160 | extern double tbl_tri_xyz_ohp[6][3]; 161 | extern const int tbl_vidx_erp2ohp[8][3]; 162 | extern const int tbl_vidx_ohp2erp[8][3]; 163 | 164 | /***************************************************************************** 165 | * interface functions 166 | *****************************************************************************/ 167 | int s360_init(void); 168 | void s360_deinit(void); 169 | 170 | #include "360tools_erp.h" 171 | #include "360tools_isp.h" 172 | #include "360tools_cmp.h" 173 | #include "360tools_ohp.h" 174 | #include "360tools_tsp.h" 175 | #include "360tools_cpp.h" 176 | #include "360tools_ssp.h" 177 | 178 | #ifdef __cplusplus 179 | } 180 | #endif 181 | 182 | 183 | #endif /* __360TOOLS_H__218937465289347652834659823659823746592834765__ */ 184 | 185 | -------------------------------------------------------------------------------- /src/360tools_args.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __360TOOLS_ARGS_H__4324324324324324324324324324242432432453424324__ 35 | #define __360TOOLS_ARGS_H__4324324324324324324324324324242432432453424324__ 36 | 37 | #ifdef __cplusplus 38 | extern "C" 39 | { 40 | #endif 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | #define S360_ARGS_VAL_TYPE_MANDATORY (1<<0) /* mandatory or not */ 47 | #define S360_ARGS_VAL_TYPE_NONE (0<<1) /* no value */ 48 | #define S360_ARGS_VAL_TYPE_INTEGER (10<<1) /* integer type value */ 49 | #define S360_ARGS_VAL_TYPE_STRING (20<<1) /* string type value */ 50 | 51 | #define S360_ARGS_GET_CMD_OPT_VAL_TYPE(x) ((x) & ~S360_ARGS_VAL_TYPE_MANDATORY) 52 | #define S360_CMD_FLAG_CFG 0 /* Config File Param Index */ 53 | 54 | typedef struct 55 | { 56 | char key; /* option keyword. ex) -f */ 57 | char key_long[32]; /* option long keyword, ex) --file */ 58 | int val_type; /* value type */ 59 | int * flag; /* flag to setting or not */ 60 | void * val; /* actual value */ 61 | char desc[512]; /* description of option */ 62 | } S360_ARGS_OPT; 63 | 64 | typedef enum 65 | { 66 | CMD_FLAG_CONV_CONFIG = S360_CMD_FLAG_CFG, 67 | CMD_FLAG_CONV_FNAME_INP, 68 | CMD_FLAG_CONV_FNAME_OUT, 69 | CMD_FLAG_CONV_WIDTH, 70 | CMD_FLAG_CONV_HEIGHT, 71 | CMD_FLAG_CONV_CFMT, 72 | CMD_FLAG_CONV_OWIDTH, 73 | CMD_FLAG_CONV_OHEIGHT, 74 | CMD_FLAG_CONV_FRM_NUM, 75 | CMD_FLAG_CONV_ALIGN, 76 | CMD_FLAG_CONV_CS_IN, 77 | CMD_FLAG_CONV_CS_OUT, 78 | CMD_FLAG_CONV_CS_INT, 79 | CMD_FLAG_CONV_PITCH, 80 | CMD_FLAG_CONV_YAW, 81 | CMD_FLAG_CONV_MAX 82 | } CMD_FLAG_CONV; 83 | 84 | typedef enum 85 | { 86 | CMD_FLAG_METRIC_CONFIG = S360_CMD_FLAG_CFG, 87 | CMD_FLAG_METRIC_FNAME_ORG, 88 | CMD_FLAG_METRIC_FNAME_REC, 89 | CMD_FLAG_METRIC_FNAME_SPH, 90 | CMD_FLAG_METRIC_WIDTH_ORG, 91 | CMD_FLAG_METRIC_HEIGHT_ORG, 92 | CMD_FLAG_METRIC_WIDTH_REC, 93 | CMD_FLAG_METRIC_HEIGHT_REC, 94 | CMD_FLAG_METRIC_FRM_NUM, 95 | CMD_FLAG_METRIC_QMETRIC, 96 | CMD_FLAG_METRIC_CS_ORG, 97 | CMD_FLAG_METRIC_CS_REC, 98 | CMD_FLAG_METRIC_PFMT_ORG, 99 | CMD_FLAG_METRIC_PFMT_REC, 100 | CMD_FLAG_METRIC_VERB, 101 | CMD_FLAG_METRIC_MAX 102 | } CMD_FLAG_METRIC; 103 | 104 | 105 | static int s360_args_search_long_arg(S360_ARGS_OPT * opts, const char * argv) 106 | { 107 | int oidx = 0; 108 | S360_ARGS_OPT * o; 109 | 110 | o = opts; 111 | 112 | while(o->key != 0) 113 | { 114 | if(!strcmp(argv, o->key_long)) 115 | { 116 | return oidx; 117 | } 118 | oidx++; 119 | o++; 120 | } 121 | return -1; 122 | } 123 | 124 | 125 | static int s360_args_search_short_arg(S360_ARGS_OPT * opts, const char argv) 126 | { 127 | int oidx = 0; 128 | S360_ARGS_OPT * o; 129 | 130 | o = opts; 131 | 132 | while(o->key != 0) 133 | { 134 | if(o->key == argv) 135 | { 136 | return oidx; 137 | } 138 | oidx++; 139 | o++; 140 | } 141 | return -1; 142 | } 143 | 144 | static int s360_args_read_value(S360_ARGS_OPT * opts, const char * argv) 145 | { 146 | if(argv == NULL) return -1; 147 | if(argv[0] == '-') return -1; 148 | 149 | switch(S360_ARGS_GET_CMD_OPT_VAL_TYPE(opts->val_type)) 150 | { 151 | case S360_ARGS_VAL_TYPE_INTEGER: 152 | *((int*)opts->val) = atoi(argv); 153 | break; 154 | 155 | case S360_ARGS_VAL_TYPE_STRING: 156 | strcpy((char*)opts->val, argv); 157 | break; 158 | 159 | default: 160 | return -1; 161 | } 162 | return 0; 163 | } 164 | 165 | static int s360_args_get_help(S360_ARGS_OPT * opts, int idx, char * help) 166 | { 167 | int optional = 0; 168 | char vtype[32]; 169 | S360_ARGS_OPT * o = opts + idx; 170 | 171 | switch(S360_ARGS_GET_CMD_OPT_VAL_TYPE(o->val_type)) 172 | { 173 | case S360_ARGS_VAL_TYPE_INTEGER: 174 | strcpy(vtype, "INTEGER"); 175 | break; 176 | case S360_ARGS_VAL_TYPE_STRING: 177 | strcpy(vtype, "STRING"); 178 | break; 179 | case S360_ARGS_VAL_TYPE_NONE: 180 | default: 181 | strcpy(vtype, "FLAG"); 182 | break; 183 | } 184 | optional = !(o->val_type & S360_ARGS_VAL_TYPE_MANDATORY); 185 | 186 | sprintf(help, " -%c, --%s [%s]%s\n : %s", o->key, o->key_long, 187 | vtype, (optional)? " (optional)":"", o->desc); 188 | 189 | return 0; 190 | } 191 | 192 | static int s360_args_get_arg(S360_ARGS_OPT * opts, int idx, char * result) 193 | { 194 | char vtype[32]; 195 | char value[512]; 196 | S360_ARGS_OPT * o = opts + idx; 197 | 198 | switch(S360_ARGS_GET_CMD_OPT_VAL_TYPE(o->val_type)) 199 | { 200 | case S360_ARGS_VAL_TYPE_INTEGER: 201 | strcpy(vtype, "INTEGER"); 202 | sprintf(value, "%d", *((int*)o->val)); 203 | break; 204 | 205 | case S360_ARGS_VAL_TYPE_STRING: 206 | strcpy(vtype, "STRING"); 207 | sprintf(value, "%s", (char*)o->val); 208 | break; 209 | 210 | case S360_ARGS_VAL_TYPE_NONE: 211 | default: 212 | strcpy(vtype, "FLAG"); 213 | sprintf(value, "%d", *((int*)o->val)); 214 | break; 215 | } 216 | 217 | if(o->flag != NULL && (*o->flag)) 218 | { 219 | strcat(value, " (SET)"); 220 | } 221 | else 222 | { 223 | strcat(value, " (DEFAULT)"); 224 | } 225 | 226 | sprintf(result, " -%c(--%s) = %s\n : %s", o->key, o->key_long, 227 | value, o->desc); 228 | 229 | return 0; 230 | 231 | } 232 | 233 | static int s360_parse_cfg(S360_ARGS_OPT * opts) 234 | { 235 | char * fname_cfg, * parser; 236 | FILE * fp_cfg; 237 | char line[256] = "", tag[50] = "", val[256] = ""; 238 | int oidx; 239 | 240 | fname_cfg = (char*)opts[S360_CMD_FLAG_CFG].val; 241 | fp_cfg = fopen(fname_cfg, "r"); 242 | 243 | while (fgets(line, sizeof(line), fp_cfg)) 244 | { 245 | parser = strtok(line, "= \t"); 246 | strcpy(tag, parser); 247 | 248 | parser = strtok(NULL, "= \t\n"); 249 | strcpy(val, parser); 250 | 251 | if (strlen(tag) == 1) 252 | { 253 | oidx = s360_args_search_short_arg(opts, tag[0]); 254 | if (oidx < 0) continue; 255 | } 256 | else 257 | { 258 | oidx = s360_args_search_long_arg(opts, tag); 259 | if (oidx < 0) continue; 260 | } 261 | 262 | if (S360_ARGS_GET_CMD_OPT_VAL_TYPE(opts[oidx].val_type) != S360_ARGS_VAL_TYPE_NONE) 263 | { 264 | if (s360_args_read_value(opts + oidx, val)) continue; 265 | } 266 | else 267 | { 268 | *((int*)opts[oidx].val) = 1; 269 | } 270 | *opts[oidx].flag = 1; 271 | } 272 | 273 | fclose(fp_cfg); 274 | return 0; 275 | } 276 | 277 | static int s360_parse_cmd(int argc, const char * argv[], S360_ARGS_OPT * opts, 278 | int * idx) 279 | { 280 | int aidx; /* arg index */ 281 | int oidx; /* option index */ 282 | 283 | aidx = *idx + 1; 284 | 285 | if(aidx >= argc || argv[aidx] == NULL) goto NO_MORE; 286 | if(argv[aidx][0] != '-') goto ERR; 287 | 288 | if(argv[aidx][1] == '-') 289 | { 290 | /* long option */ 291 | oidx = s360_args_search_long_arg(opts, argv[aidx] + 2); 292 | if(oidx < 0) goto ERR; 293 | } 294 | else if(strlen(argv[aidx]) == 2) 295 | { 296 | /* short option */ 297 | oidx = s360_args_search_short_arg(opts, argv[aidx][1]); 298 | if(oidx < 0) goto ERR; 299 | } 300 | else 301 | { 302 | goto ERR; 303 | } 304 | 305 | if(S360_ARGS_GET_CMD_OPT_VAL_TYPE(opts[oidx].val_type) != S360_ARGS_VAL_TYPE_NONE) 306 | { 307 | if(aidx + 1 >= argc) goto ERR; 308 | if(s360_args_read_value(opts + oidx, argv[aidx + 1])) goto ERR; 309 | if (oidx == S360_CMD_FLAG_CFG) { s360_parse_cfg(opts); } 310 | *idx = *idx + 1; 311 | } 312 | else 313 | { 314 | *((int*)opts[oidx].val) = 1; 315 | } 316 | *opts[oidx].flag = 1; 317 | *idx = *idx + 1; 318 | 319 | return opts[oidx].key; 320 | 321 | 322 | NO_MORE: 323 | return 0; 324 | 325 | ERR: 326 | return -1; 327 | } 328 | 329 | static int s360_args_parse_all(int argc, const char * argv[], S360_ARGS_OPT * opts) 330 | { 331 | int ret = 0, idx = 0; 332 | S360_ARGS_OPT * o; 333 | 334 | while(1) 335 | { 336 | ret = s360_parse_cmd(argc, argv, opts, &idx); 337 | if(ret <= 0) break; 338 | } 339 | 340 | /* check mandatory argument */ 341 | o = opts; 342 | 343 | while(o->key != 0) 344 | { 345 | if(o->val_type & S360_ARGS_VAL_TYPE_MANDATORY) 346 | { 347 | if(*o->flag == 0) 348 | { 349 | /* not filled all mandatory argument */ 350 | return o->key; 351 | } 352 | } 353 | o++; 354 | } 355 | return ret; 356 | } 357 | 358 | 359 | static int s360_args_parse_int_x_int(char * str, int * num0, int * num1) 360 | { 361 | char str0_t[64]; 362 | int i, cnt0, cnt1; 363 | char * str0, * str1 = NULL; 364 | 365 | str0 = str; 366 | cnt1 = strlen(str); 367 | 368 | /* find 'x' */ 369 | for(i=0; i<(int)strlen(str); i++) 370 | { 371 | if(str[i] == 'x' || str[i] == 'X') 372 | { 373 | str1 = str + i + 1; 374 | cnt0 = i; 375 | cnt1 = cnt1 - cnt0 - 1; 376 | break; 377 | } 378 | } 379 | 380 | /* check malformed data */ 381 | if(str1 == NULL || cnt0 == 0 || cnt1 == 0) return -1; 382 | 383 | for(i=0; i 0x39) return -1; /* not a number */ 386 | } 387 | for(i=0; i 0x39) return -1; /* not a number */ 390 | } 391 | 392 | 393 | strncpy(str0_t, str0, cnt0); 394 | str0_t[cnt0] = '\0'; 395 | 396 | *num0 = atoi(str0_t); 397 | *num1 = atoi(str1); 398 | 399 | return 0; 400 | } 401 | 402 | 403 | #ifdef __cplusplus 404 | } 405 | #endif 406 | 407 | 408 | #endif /*__360TOOLS_ARGS_H__4324324324324324324324324324242432432453424324__ */ 409 | 410 | -------------------------------------------------------------------------------- /src/360tools_cmp.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __360TOOLS_CMP_H__2346758963478562398457629384562938576234__ 35 | #define __360TOOLS_CMP_H__2346758963478562398457629384562938576234__ 36 | 37 | 38 | #ifdef __cplusplus 39 | extern "C" 40 | { 41 | #endif 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | /* to CMP */ 48 | int s360_erp_to_cmp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 49 | int s360_rcmp_to_cmp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 50 | int s360_cpp_to_cmp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 51 | 52 | /* from CMP */ 53 | int s360_cmp_to_erp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 54 | int s360_cmp_to_cpp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 55 | int s360_cmp_to_rcmp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | 62 | #endif /* __360TOOLS_CMP_H__2346758963478562398457629384562938576234__ */ 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/360tools_cpp.c: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | #include "360tools.h" 36 | #include "360tools_cpp.h" 37 | 38 | static void cpp_bypass_plane(int w_src, int h_src, int s_src, void * src, 39 | void * dst, int s_dst, int cs, int opt, int pad_sz) 40 | { 41 | int i, j, size; 42 | int w_dst, h_dst; 43 | uint8 * map; 44 | 45 | w_dst = w_src; 46 | h_dst = h_src; 47 | size = ((cs == S360_COLORSPACE_YUV420) ? sizeof(uint8) : sizeof(uint16)); 48 | 49 | map = (uint8 *)s360_malloc(sizeof(uint8) * w_dst * h_dst); 50 | cpp_map_plane(w_dst, h_dst, s_dst, map); 51 | 52 | for(j=0; jcolorspace == S360_COLORSPACE_YUV420) || ((img_src->colorspace == S360_COLORSPACE_YUV420_10))) 82 | { 83 | for(i=0; i<3; i++) 84 | { 85 | if(i == 0) 86 | { 87 | w_src = w_dst = img_src->width; 88 | h_src = img_src->height; 89 | pad_sz = (opt & S360_OPT_PAD) ? PAD_SIZE : 0; 90 | } 91 | else 92 | { 93 | w_src = w_dst = (img_src->width + 1)>> 1; 94 | h_src = (img_src->height + 1) >> 1; 95 | pad_sz = (opt & S360_OPT_PAD) ? PAD_SIZE >> 1 : 0; 96 | } 97 | cpp_bypass_plane(w_src, h_src, img_src->stride[i], img_src->buffer[i], img_dst->buffer[i], img_dst->stride[i], img_src->colorspace, opt, pad_sz); 98 | } 99 | } 100 | else 101 | { 102 | return S360_ERR_UNSUPPORTED_COLORSPACE; 103 | } 104 | return S360_OK; 105 | } -------------------------------------------------------------------------------- /src/360tools_cpp.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __360TOOLS_CPP_H__203849891889128128376984785187981283745__ 35 | #define __360TOOLS_CPP_H__203849891889128128376984785187981283745__ 36 | 37 | #ifdef __cplusplus 38 | extern "C" 39 | { 40 | #endif 41 | 42 | int s360_cpp_bypass(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 43 | int s360_pad_cpp(S360_IMAGE * img); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | 50 | #endif /* __360TOOLS_CPP_H__203849891889128128376984785187981283745__ */ 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/360tools_def.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #ifndef __360TOOLS_DEF_H__4232432432432532432432432432__ 36 | #define __360TOOLS_DEF_H__4232432432432532432432432432__ 37 | 38 | #ifdef __cplusplus 39 | extern "C" 40 | { 41 | #endif 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | /* return values and error code **********************************************/ 48 | #define S360_OK (0) 49 | #define S360_ERR (-1) 50 | #define S360_ERR_INVALID_ARGUMENT (-101) 51 | #define S360_ERR_OUT_OF_MEMORY (-102) 52 | #define S360_ERR_REACHED_MAX (-103) 53 | #define S360_ERR_UNSUPPORTED (-104) 54 | #define S360_ERR_UNSUPPORTED_COLORSPACE (-105) 55 | #define S360_ERR_INVALID_DIMENSION (-106) 56 | #define S360_PROJ_NOT_SUPPORTED (-107) 57 | 58 | /* return value checking *****************************************************/ 59 | #define S360_SUCCEEDED(ret) ((ret) >= 0) 60 | #define S360_FAILED(ret) ((ret) < 0) 61 | 62 | /* utility macros ************************************************************/ 63 | #define S360_MIN(a, b) ((a) < (b) ? (a) : (b)) 64 | #define S360_MAX(a, b) ((a) > (b) ? (a) : (b)) 65 | #define S360_MINMAX(v, a, b) S360_MAX(S360_MIN((v), (b)), (a)) 66 | #define S360_CLIP_S32_TO_U8(x) ((x) > 255 ? 255 : (x) < 0 ? 0 : (x)) 67 | #define S360_CLIP_S32_TO_U10(x) ((x) > 1023 ? 1023 : (x) < 0 ? 0 : (x)) 68 | #define S360_ALIGN(val, align) (((val) + (align) - 1) / (align) * (align)) 69 | #define S360_ABS(x) ((x) >= 0) ? (x) : (-(x)) 70 | 71 | #ifndef NULL 72 | #define NULL (void*)0 73 | #endif 74 | 75 | /* TSP macros ****************************************************************/ 76 | #define TSPAA_S 5 77 | 78 | /* redefined types ***********************************************************/ 79 | #if defined(WIN32) || defined(WIN64) 80 | typedef __int8 int8; 81 | typedef unsigned __int8 uint8; 82 | typedef __int16 int16; 83 | typedef unsigned __int16 uint16; 84 | typedef __int32 int32; 85 | typedef unsigned __int32 uint32; 86 | typedef __int64 int64; 87 | typedef unsigned __int64 uint64; 88 | #elif defined(LINUX) 89 | #include 90 | typedef int8_t int8; 91 | typedef uint8_t uint8; 92 | typedef int16_t int16; 93 | typedef uint16_t uint16; 94 | typedef int32_t int32; 95 | typedef uint32_t uint32; 96 | typedef int64_t int64; 97 | typedef uint64_t uint64; 98 | #else 99 | typedef signed char int8; 100 | typedef unsigned char uint8; 101 | typedef signed short int16; 102 | typedef unsigned short uint16; 103 | typedef signed int int32; 104 | typedef unsigned int uint32; 105 | #if defined(X86_64) && !defined(_MSC_VER) /* for 64bit-Linux */ 106 | typedef signed long int64; 107 | typedef unsigned long uint64; 108 | #else 109 | typedef signed long long int64; 110 | typedef unsigned long long uint64; 111 | #endif 112 | #endif 113 | 114 | 115 | /* trace message disable/enable **********************************************/ 116 | #ifndef S360_TRACE 117 | #define S360_TRACE 0 118 | #endif 119 | 120 | /* assert disable/enable *****************************************************/ 121 | #ifndef S360_ASSERT 122 | #define S360_ASSERT 0 123 | #endif 124 | 125 | /* memory operations *********************************************************/ 126 | #define s360_malloc(size) malloc((size)) 127 | #define s360_mfree(m) free((m)) 128 | #define s360_mcpy(dst,src,size) memcpy((dst), (src), (size)) 129 | #define s360_mset(dst,v,size) memset((dst), (v), (size)) 130 | 131 | /* print function ************************************************************/ 132 | #if defined(LINUX) 133 | #define s360_print(args...) printf(args) 134 | #else 135 | #define s360_print printf 136 | #endif 137 | 138 | /* trace function ************************************************************/ 139 | #if S360_TRACE 140 | #define s360_trace s360_print("[%s:%d] ", __FILE__, __LINE__); s360_print 141 | #else 142 | #if defined(LINUX) 143 | #define s360_trace(args...) {} 144 | #else 145 | #define s360_trace(...) {} 146 | #endif 147 | #endif 148 | 149 | /* assert function ***********************************************************/ 150 | #if S360_ASSERT 151 | #define __S360_ASSERT_MSG(x) { printf("[%s:%d] assert failed! ("#x")\n", __FILE__, __LINE__); } 152 | #define __S360_MAKE_FAULT() {*(int*)0=0;} 153 | #else 154 | #define __S360_ASSERT_MSG(x) {} 155 | #define __S360_MAKE_FAULT() {} 156 | #endif 157 | 158 | #define s360_assert(x) {if(!(x)){__S360_ASSERT_MSG(x); __S360_MAKE_FAULT();}} 159 | #define s360_assert_r(x) {if(!(x)){__S360_ASSERT_MSG(x); __S360_MAKE_FAULT(); return;}} 160 | #define s360_assert_rv(x,r) {if(!(x)){__S360_ASSERT_MSG(x); __S360_MAKE_FAULT(); return (r);}} 161 | 162 | 163 | /* various color spaces ******************************************************/ 164 | #define S360_COLORSPACE_YUV420 (10) 165 | #define S360_COLORSPACE_YUV422 (11) 166 | #define S360_COLORSPACE_YUV444 (13) 167 | 168 | #define S360_COLORSPACE_YUV420_10 (20) 169 | #define S360_COLORSPACE_YUV422_10 (21) 170 | #define S360_COLORSPACE_YUV444_10 (23) 171 | 172 | #define IS_VALID_CS(cs) (((cs)==S360_COLORSPACE_YUV420)||((cs)==S360_COLORSPACE_YUV420_10)) 173 | 174 | /* 10-bit Macro. To Be Deleted Once 10-bit content is available **************/ 175 | #define INP_10B 0 176 | #define INT_10_BIT_DEPTH 2 177 | 178 | /* Resample function *********************************************************/ 179 | typedef void(*resample_fn)(void * src, int w_start, int w_end,int h_start, \ 180 | int h_src, int s_src, double x, double y, void * dst, int x_dst); 181 | 182 | /* image buffer format *******************************************************/ 183 | typedef struct 184 | { 185 | void * buf_pad[4]; /* adress of each plane with padding */ 186 | void * buffer[4]; /* address of each plane */ 187 | int stride[4]; /* buffer stride */ 188 | int elevation[4]; /* buffer elevation */ 189 | int width; /* width */ 190 | int height; /* height */ 191 | int colorspace; /* color space */ 192 | } S360_IMAGE; 193 | 194 | /* Spherical PSNR Sampling Location Structure ********************************/ 195 | typedef struct 196 | { 197 | float lat; 198 | float lng; 199 | }S360_SPH_COORD; 200 | 201 | /* Latlong map for Y, chroma layers *****************************************/ 202 | typedef struct 203 | { 204 | S360_SPH_COORD * layer[2]; /* map for each plane*/ 205 | int width; 206 | int height; 207 | int pitch; 208 | int yaw; 209 | }S360_MAP; 210 | 211 | /* Conversion Formats ******************************************************/ 212 | typedef enum 213 | { 214 | CONV_FMT_ERP_TO_CPP = 0, 215 | CONV_FMT_ERP_TO_ISP = 1, 216 | CONV_FMT_ISP_TO_ERP, 217 | CONV_FMT_ERP_TO_CMP, 218 | CONV_FMT_CMP_TO_ERP, 219 | CONV_FMT_ERP_TO_OHP, 220 | CONV_FMT_OHP_TO_ERP, 221 | CONV_FMT_ERP_TO_TSP, 222 | CONV_FMT_TSP_TO_ERP, 223 | CONV_FMT_ERP_TO_SSP, 224 | CONV_FMT_SSP_TO_ERP, 225 | CONV_FMT_ISP_TO_RISP =11, 226 | CONV_FMT_RISP_TO_ISP, 227 | CONV_FMT_CMP_TO_RCMP, 228 | CONV_FMT_RCMP_TO_CMP, 229 | CONV_FMT_OHP_TO_ROHP, 230 | CONV_FMT_ROHP_TO_OHP, 231 | CONV_FMT_ERP_TO_RISP1 = 21, 232 | CONV_FMT_RISP1_TO_ERP, 233 | CONV_FMT_ERP_TO_COHP = 25, 234 | CONV_FMT_COHP_TO_ERP, 235 | CONV_FMT_CPP_TO_ERP = 31, 236 | CONV_FMT_CPP_TO_ISP, 237 | CONV_FMT_CPP_TO_CMP, 238 | CONV_FMT_CPP_TO_OHP, 239 | CONV_FMT_CPP_TO_TSP, 240 | CONV_FMT_CPP_TO_SSP, 241 | CONV_FMT_CPP_BYPASS, 242 | CONV_FMT_MAX 243 | } CONV_FMT; 244 | 245 | /* Projection Formats ******************************************************/ 246 | typedef enum 247 | { 248 | PROJ_FMT_ERP = 1, 249 | PROJ_FMT_ISP, 250 | PROJ_FMT_CMP, 251 | PROJ_FMT_OHP, 252 | PROJ_FMT_TSP, 253 | PROJ_FMT_CPP, 254 | PROJ_FMT_SSP, 255 | PROJ_FMT_MAX 256 | } PROJ_FMT; 257 | 258 | #ifdef __cplusplus 259 | } 260 | #endif 261 | 262 | #endif /* __360TOOLS_DEF_H__4232432432432532432432432432__ */ 263 | 264 | -------------------------------------------------------------------------------- /src/360tools_erp.c: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | #include "360tools.h" 36 | #include "360tools_erp.h" 37 | 38 | static void erp_to_cpp_plane(int w_src, int h_src, int s_src, void * src, 39 | int w_dst, int h_dst, void * dst, int s_dst, int cs, int opt, int pad_sz) 40 | { 41 | void (* fn_resample)(void * src, int w_start, int w_end, int h_start, int h_end,\ 42 | int s_src, double x, double y, void * dst, int x_dst); 43 | double lambda, phi, x, y; 44 | int offset; 45 | int i, j; 46 | void * dst0; 47 | uint8 * map; 48 | int w_start, w_end, h_start; 49 | 50 | w_start = opt ? -pad_sz : 0; 51 | w_end = opt ? w_src + pad_sz : w_src; 52 | h_start = 0; 53 | 54 | map = (uint8 *)s360_malloc(sizeof(uint8) * w_dst * h_dst); 55 | cpp_map_plane(w_dst, h_dst, s_dst, map); 56 | 57 | dst0 = dst; 58 | 59 | if(cs == S360_COLORSPACE_YUV420) 60 | { 61 | fn_resample = resample_2d; 62 | } 63 | else if(cs == S360_COLORSPACE_YUV420_10) 64 | { 65 | fn_resample = resample_2d_10b; 66 | s_dst <<= 1; 67 | } 68 | 69 | offset = 0; 70 | for(j=0; jcolorspace == S360_COLORSPACE_YUV420) || ((img_src->colorspace == S360_COLORSPACE_YUV420_10))) 111 | { 112 | for(i=0; i<3; i++) 113 | { 114 | if(i == 0) 115 | { 116 | w_src = img_src->width; 117 | w_dst = img_dst->width; 118 | h_src = img_src->height; 119 | h_dst = img_dst->height; 120 | pad_sz = (opt & S360_OPT_PAD) ? PAD_SIZE : 0; 121 | } 122 | else 123 | { 124 | w_src = (img_src->width + 1) >> 1; 125 | w_dst = (img_dst->width + 1) >> 1; 126 | h_src = (img_src->height + 1) >> 1; 127 | h_dst = (img_dst->height + 1) >> 1; 128 | pad_sz = (opt & S360_OPT_PAD) ? PAD_SIZE >> 1 : 0; 129 | } 130 | erp_to_cpp_plane(w_src, h_src, img_src->stride[i], \ 131 | img_src->buffer[i], w_dst, h_dst, img_dst->buffer[i], \ 132 | img_dst->stride[i], img_src->colorspace, opt, pad_sz); 133 | } 134 | } 135 | else 136 | { 137 | return S360_ERR_UNSUPPORTED_COLORSPACE; 138 | } 139 | return S360_OK; 140 | } 141 | 142 | static void cpp_to_erp_plane(int w_src, int h_src, int s_src, void * src, \ 143 | int w_dst, int h_dst, void * dst, int s_dst, int cs) 144 | { 145 | resample_fn fn_resample; 146 | uint8 * map; 147 | int i, j; 148 | double phi; 149 | double x, y; 150 | 151 | fn_resample = resample_fp(cs); 152 | 153 | map = (uint8 *)s360_malloc(sizeof(uint8) * w_src * h_src); 154 | cpp_map_plane(w_src, h_src, s_src, map); 155 | 156 | if(cs == S360_COLORSPACE_YUV420) 157 | { 158 | pad_cpp_plane((uint8 *)(src), w_src, h_src, s_src, map); 159 | } 160 | else if(cs == S360_COLORSPACE_YUV420_10) 161 | { 162 | pad_cpp_plane_10b((uint16 *)(src), w_src, h_src, s_src, map); 163 | s_dst <<= 1; 164 | } 165 | 166 | for(j=0; jcolorspace)) 186 | { 187 | for(i=0; i<3; i++) 188 | { 189 | if(i == 0) 190 | { 191 | w_src = img_src->width; 192 | h_src = img_src->height; 193 | w_dst = img_dst->width; 194 | h_dst = img_dst->height; 195 | } 196 | else 197 | { 198 | w_src = img_src->width >> 1; 199 | h_src = img_src->height >> 1; 200 | w_dst = img_dst->width >> 1; 201 | h_dst = img_dst->height >> 1; 202 | } 203 | cpp_to_erp_plane(w_src, h_src, img_src->stride[i], \ 204 | img_src->buffer[i], w_dst, h_dst, img_dst->buffer[i], \ 205 | img_dst->stride[i], img_src->colorspace); 206 | } 207 | return S360_OK; 208 | } 209 | else 210 | { 211 | return S360_ERR_UNSUPPORTED_COLORSPACE; 212 | } 213 | } 214 | 215 | static void pad_erp_plane(uint8 * buf, int w, int h, int s, int pad_sz) 216 | { 217 | uint8 * src; 218 | uint8 * dst; 219 | int i; 220 | 221 | // Pad Left 222 | src = buf + w - pad_sz; 223 | dst = buf - pad_sz; 224 | for(i=0;icolorspace)) 277 | { 278 | for(i=0;i<3;i++) 279 | { 280 | if(i == 0) 281 | { 282 | w = img->width; 283 | h = img->height; 284 | pad_sz = PAD_SIZE; 285 | } 286 | else 287 | { 288 | w = img->width >> 1; 289 | h = img->height >> 1; 290 | pad_sz = PAD_SIZE >> 1; 291 | } 292 | 293 | if (img->colorspace == S360_COLORSPACE_YUV420) 294 | { 295 | pad_erp_plane((uint8 *)(img->buffer[i]), w, h, img->stride[i], pad_sz); 296 | } 297 | else if (img->colorspace == S360_COLORSPACE_YUV420_10) 298 | { 299 | pad_erp_plane_10b((uint16 *)(img->buffer[i]), w, h, img->stride[i], pad_sz); 300 | } 301 | } 302 | } 303 | else 304 | { 305 | return S360_ERR_UNSUPPORTED_COLORSPACE; 306 | } 307 | return S360_OK; 308 | } -------------------------------------------------------------------------------- /src/360tools_erp.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __360TOOLS_ERP_H__138475623894765928347569283746592387645__ 35 | #define __360TOOLS_ERP_H__138475623894765928347569283746592387645__ 36 | 37 | #ifdef __cplusplus 38 | extern "C" 39 | { 40 | #endif 41 | 42 | int s360_erp_to_cpp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 43 | int s360_cpp_to_erp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 44 | int s360_pad_erp(S360_IMAGE * img); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | 51 | #endif /* __360TOOLS_ISP_H__2346758963478562398457629384562938576234__ */ 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/360tools_img.c: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "360tools.h" 35 | #include "360tools_img.h" 36 | 37 | S360_IMAGE * s360_img_create(int w, int h, int cs, int opt) 38 | { 39 | S360_IMAGE * img; 40 | int pad_sz; 41 | 42 | 43 | img = (S360_IMAGE *)s360_malloc(sizeof(S360_IMAGE)); 44 | s360_assert_rv(img, NULL); 45 | s360_mset(img, 0, sizeof(S360_IMAGE)); 46 | img->colorspace = cs; 47 | 48 | pad_sz = (opt & S360_OPT_PAD)?(PAD_SIZE<<1):0; 49 | 50 | if(img->colorspace == S360_COLORSPACE_YUV420) 51 | { 52 | img->width = w; 53 | img->height = h; 54 | img->stride[0] = (((w + 15) >> 4) << 4) + pad_sz; 55 | img->stride[1] = img->stride[2] = ((img->stride[0] + 1) >> 1); 56 | 57 | img->elevation[0] = ((h + 15) >> 4) << 4; 58 | img->elevation[1] = img->elevation[2] = (img->elevation[0] + 1) >> 1; 59 | img->buf_pad[0] = s360_malloc(img->stride[0] * img->elevation[0] * sizeof(uint8)); 60 | img->buf_pad[1] = s360_malloc(img->stride[1] * img->elevation[1] * sizeof(uint8)); 61 | img->buf_pad[2] = s360_malloc(img->stride[2] * img->elevation[2] * sizeof(uint8)); 62 | 63 | img->buffer[0] = (uint8 *)img->buf_pad[0] + (pad_sz >> 1); 64 | img->buffer[1] = (uint8 *)img->buf_pad[1] + (pad_sz >> 2); 65 | img->buffer[2] = (uint8 *)img->buf_pad[2] + (pad_sz >> 2); 66 | } 67 | else if(img->colorspace == S360_COLORSPACE_YUV420_10) 68 | { 69 | img->width = w; 70 | img->height = h; 71 | img->stride[0] = (((w + 15) >> 4) << 4) + pad_sz; 72 | img->stride[1] = img->stride[2] = ((img->stride[0] + 1) >> 1); 73 | 74 | img->elevation[0] = ((h + 15) >> 4) << 4; 75 | img->elevation[1] = img->elevation[2] = (img->elevation[0] + 1) >> 1; 76 | img->buf_pad[0] = s360_malloc(img->stride[0] * img->elevation[0] * sizeof(uint16)); 77 | img->buf_pad[1] = s360_malloc(img->stride[1] * img->elevation[1] * sizeof(uint16)); 78 | img->buf_pad[2] = s360_malloc(img->stride[2] * img->elevation[2] * sizeof(uint16)); 79 | 80 | img->buffer[0] = (uint16 *)img->buf_pad[0] + (pad_sz >> 1); 81 | img->buffer[1] = (uint16 *)img->buf_pad[1] + (pad_sz >> 2); 82 | img->buffer[2] = (uint16 *)img->buf_pad[2] + (pad_sz >> 2); 83 | } 84 | else 85 | { 86 | printf("unsupported color space\n"); 87 | s360_mfree(img); 88 | return NULL; 89 | } 90 | return img; 91 | } 92 | 93 | void s360_img_delete(S360_IMAGE * img) 94 | { 95 | s360_assert_r(img); 96 | 97 | if (img->buf_pad[0]) s360_mfree(img->buf_pad[0]); 98 | if (img->buf_pad[1]) s360_mfree(img->buf_pad[1]); 99 | if (img->buf_pad[2]) s360_mfree(img->buf_pad[2]); 100 | if (img->buf_pad[3]) s360_mfree(img->buf_pad[3]); 101 | 102 | s360_mfree(img); 103 | } 104 | 105 | void s360_img_reset(S360_IMAGE * img) 106 | { 107 | int i; 108 | 109 | if(img->colorspace == S360_COLORSPACE_YUV420) 110 | { 111 | 112 | s360_mset(img->buf_pad[0], 0, img->stride[0] * img->elevation[0] * sizeof(uint8)); 113 | s360_mset(img->buf_pad[1], 128, img->stride[1] * img->elevation[1] * sizeof(uint8)); 114 | s360_mset(img->buf_pad[2], 128, img->stride[2] * img->elevation[2] * sizeof(uint8)); 115 | 116 | } 117 | else if(img->colorspace == S360_COLORSPACE_YUV420_10) 118 | { 119 | uint16 * buf_u, * buf_v; 120 | 121 | buf_u = (uint16 *)img->buf_pad[1]; 122 | buf_v = (uint16 *)img->buf_pad[2]; 123 | 124 | s360_mset(img->buf_pad[0], 0, img->stride[0] * img->elevation[0] * sizeof(uint16)); 125 | 126 | for(i = 0;istride[1] * img->elevation[1];i++) 127 | { 128 | buf_u[i] = 512; 129 | } 130 | for(i = 0;istride[2] * img->elevation[2];i++) 131 | { 132 | buf_v[i] = 512; 133 | } 134 | } 135 | } 136 | 137 | int s360_img_read(FILE * fp, S360_IMAGE * img, int cs_int) 138 | { 139 | uint8 * p8; 140 | uint16 * p16; 141 | uint16 val16; 142 | int i, j, k, w; 143 | 144 | if((cs_int == S360_COLORSPACE_YUV420) && (img->colorspace == S360_COLORSPACE_YUV420_10)) 145 | { 146 | 147 | /* luma */ 148 | p16 = (uint16 *)img->buffer[0]; 149 | w = img->width; 150 | for(j=0; jheight; j++) 151 | { 152 | memset(p16, 0, w*sizeof(uint16)); 153 | for(k=0;kstride[0]; 160 | } 161 | 162 | /* chroma */ 163 | for(i=1; i<3; i++) 164 | { 165 | p16 = (uint16 *)img->buffer[i]; 166 | w = (img->width + 1) >> 1; 167 | for(j=0; j<((img->height+1)>>1); j++) 168 | { 169 | memset(p16, 0, w*sizeof(uint16)); 170 | for(k=0;k<(w);k++) 171 | { 172 | if(fread(p16+k, sizeof(uint8), 1, fp) != (unsigned)1) return -1; 173 | p16[k] = (p16[k])<<2; 174 | } 175 | p16 += img->stride[i]; 176 | } 177 | } 178 | } 179 | else if((cs_int == S360_COLORSPACE_YUV420) && (img->colorspace == S360_COLORSPACE_YUV420)) 180 | { 181 | /* luma */ 182 | p8 = (uint8 *)img->buffer[0]; 183 | w = img->width; 184 | for(j=0; jheight; j++) 185 | { 186 | if(fread(p8, sizeof(uint8), w, fp) != (unsigned)w) return -1; 187 | p8 += img->stride[0]; 188 | } 189 | 190 | /* chroma */ 191 | for(i=1; i<3; i++) 192 | { 193 | p8 = (uint8 *)img->buffer[i]; 194 | w = (img->width + 1) >> 1; 195 | for(j=0; j<((img->height+1)>>1); j++) 196 | { 197 | if(fread(p8, sizeof(uint8), w, fp) != (unsigned)w) return -1; 198 | p8 += img->stride[i]; 199 | } 200 | } 201 | } 202 | else if((cs_int == S360_COLORSPACE_YUV420_10) && (img->colorspace == S360_COLORSPACE_YUV420_10)) 203 | { 204 | /* luma */ 205 | p16 = (uint16 *)img->buffer[0]; 206 | w = img->width; 207 | for(j=0; jheight; j++) 208 | { 209 | if(fread(p16, sizeof(uint16), w, fp) != (unsigned)w) return -1; 210 | p16 += img->stride[0]; 211 | } 212 | 213 | /* chroma */ 214 | for(i=1; i<3; i++) 215 | { 216 | p16 = (uint16 *)img->buffer[i]; 217 | w = (img->width + 1) >> 1; 218 | for(j=0; j<((img->height+1)>>1); j++) 219 | { 220 | if(fread(p16, sizeof(uint16), w, fp) != (unsigned)w) return -1; 221 | p16 += img->stride[i]; 222 | } 223 | } 224 | } 225 | else if((cs_int == S360_COLORSPACE_YUV420_10) && (img->colorspace == S360_COLORSPACE_YUV420)) 226 | { 227 | /* luma */ 228 | p8 = (uint8 *)img->buffer[0]; 229 | w = img->width; 230 | for(j=0; jheight; j++) 231 | { 232 | for(k=0;k>2); 236 | } 237 | p8 += img->stride[0]; 238 | } 239 | 240 | /* chroma */ 241 | for(i=1; i<3; i++) 242 | { 243 | p8 = (uint8 *)img->buffer[i]; 244 | w = (img->width + 1) >> 1; 245 | for(j=0; j<((img->height+1)>>1); j++) 246 | { 247 | for(k=0;k>2); 251 | } 252 | p8 += img->stride[i]; 253 | } 254 | } 255 | } 256 | else 257 | { 258 | s360_trace("not supported color space\n"); 259 | return -1; 260 | } 261 | 262 | return 0; 263 | } 264 | 265 | int s360_img_write(FILE * fp, S360_IMAGE * img, int cs) 266 | { 267 | uint8 * p; 268 | uint16 * p16; 269 | uint16 val16; 270 | int i, j, k; 271 | 272 | if(img->colorspace == S360_COLORSPACE_YUV420_10) 273 | { 274 | if(cs == S360_COLORSPACE_YUV420) 275 | { 276 | /* luma */ 277 | p16 = (uint16 *)img->buffer[0]; 278 | for(j=0; jheight; j++) 279 | { 280 | for(k = 0;kwidth;k++) 281 | { 282 | p16[k] = S360_CLIP_S32_TO_U8((p16[k]+2)>>2); 283 | fwrite(p16+k, sizeof(uint8), 1, fp); 284 | } 285 | 286 | p16 += img->stride[0]; 287 | } 288 | 289 | /* chroma */ 290 | for(i=1; i<3; i++) 291 | { 292 | p16 = (uint16 *)img->buffer[i]; 293 | for(j=0; j<((img->height+1)>>1); j++) 294 | { 295 | for(k = 0;k<((img->width+1)>>1);k++) 296 | { 297 | p16[k] = S360_CLIP_S32_TO_U8((p16[k]+2)>>2); 298 | fwrite(p16+k, sizeof(uint8), 1, fp); 299 | } 300 | p16 += img->stride[i]; 301 | } 302 | } 303 | } 304 | if(cs == S360_COLORSPACE_YUV420_10) 305 | { 306 | /* luma */ 307 | p16 = (uint16 *)img->buffer[0]; 308 | for(j=0; jheight; j++) 309 | { 310 | for(k = 0;k<((img->width));k++) 311 | { 312 | fwrite((p16+k), sizeof(uint16), 1, fp); 313 | } 314 | p16 += img->stride[0]; 315 | } 316 | 317 | /* chroma */ 318 | for(i=1; i<3; i++) 319 | { 320 | p16 = (uint16 *)img->buffer[i]; 321 | for(j=0; j<((img->height+1)>>1); j++) 322 | { 323 | for(k = 0;k<((img->width+1)>>1);k++) 324 | { 325 | fwrite(p16+k, sizeof(uint16), 1, fp); 326 | } 327 | p16 += img->stride[i]; 328 | } 329 | } 330 | } 331 | } 332 | else if(img->colorspace == S360_COLORSPACE_YUV420) 333 | { 334 | if(cs == S360_COLORSPACE_YUV420) 335 | { 336 | /* luma */ 337 | p = (uint8 *)img->buffer[0]; 338 | 339 | for(j=0; jheight; j++) 340 | { 341 | for(k = 0;kwidth;k++) 342 | { 343 | fwrite(p+k, sizeof(uint8), 1, fp); 344 | } 345 | 346 | p += img->stride[0]; 347 | } 348 | 349 | /* chroma */ 350 | for(i=1; i<3; i++) 351 | { 352 | p = (uint8 *)img->buffer[i]; 353 | for(j=0; j<((img->height+1)>>1); j++) 354 | { 355 | for(k = 0;k<((img->width+1)>>1);k++) 356 | { 357 | fwrite(p+k, sizeof(uint8), 1, fp); 358 | } 359 | p += img->stride[i]; 360 | } 361 | } 362 | } 363 | if(cs == S360_COLORSPACE_YUV420_10) 364 | { 365 | 366 | /* luma */ 367 | p = (uint8 *)img->buffer[0]; 368 | for(j=0; jheight; j++) 369 | { 370 | for(k = 0;k<((img->width));k++) 371 | { 372 | val16 = (p[k] << 2); 373 | fwrite(&val16, sizeof(uint16), 1, fp); 374 | } 375 | p += img->stride[0]; 376 | } 377 | 378 | /* chroma */ 379 | for(i=1; i<3; i++) 380 | { 381 | p = (uint8 *)img->buffer[i]; 382 | for(j=0; j<((img->height+1)>>1); j++) 383 | { 384 | for(k = 0;k<((img->width+1)>>1);k++) 385 | { 386 | val16 = (p[k] << 2); 387 | fwrite(&val16, sizeof(uint16), 1, fp); 388 | } 389 | p += img->stride[i]; 390 | } 391 | } 392 | } 393 | } 394 | else 395 | { 396 | s360_trace("cannot support the color space\n"); 397 | return -1; 398 | } 399 | 400 | return S360_OK; 401 | } 402 | 403 | 404 | static void img_align_plane(uint8 * buf, int w, int h, int s, int align) 405 | { 406 | uint8 * src, * dst; 407 | int w_dst, h_dst; 408 | int j, size; 409 | 410 | w_dst = S360_ALIGN(w, align); 411 | h_dst = S360_ALIGN(h, align); 412 | 413 | if(w < w_dst) 414 | { 415 | dst = buf + w; 416 | for(j=0; j img->width || h > img->height) 442 | { 443 | img_new = s360_img_create(w, h, img->colorspace, opt); 444 | s360_assert_rv(img_new, S360_ERR_OUT_OF_MEMORY); 445 | 446 | for(i=0; i<4; i++) 447 | { 448 | if (img->buf_pad[i]) s360_mfree(img->buf_pad[i]); 449 | img->buf_pad[i] = img_new->buf_pad[i]; 450 | img->buffer[i] = img_new->buffer[i]; 451 | img->stride[i] = img_new->stride[i]; 452 | img->elevation[i] = img_new->elevation[i]; 453 | } 454 | 455 | s360_mfree(img_new); 456 | } 457 | 458 | img->width = w; 459 | img->height = h; 460 | 461 | return S360_OK; 462 | } 463 | 464 | static void img_align_plane_10b(uint16 * buf, int w, int h, int s, int align) 465 | { 466 | uint16 * src, * dst; 467 | int w_dst, h_dst; 468 | int i,j, size; 469 | 470 | w_dst = S360_ALIGN(w, align); 471 | h_dst = S360_ALIGN(h, align); 472 | 473 | if(w < w_dst) 474 | { 475 | dst = buf + w; 476 | for(j=0; jcolorspace == S360_COLORSPACE_YUV420) 502 | { 503 | img_align_plane(img->buffer[0], img->width, img->height, img->stride[0], align); 504 | img_align_plane(img->buffer[1], img->width>>1, img->height>>1, img->stride[1], align>>1); 505 | img_align_plane(img->buffer[2], img->width>>1, img->height>>1, img->stride[2], align>>1); 506 | return S360_OK; 507 | } 508 | if(img->colorspace == S360_COLORSPACE_YUV420_10) 509 | { 510 | img_align_plane_10b(img->buffer[0], img->width, img->height, img->stride[0], align); 511 | img_align_plane_10b(img->buffer[1], img->width>>1, img->height>>1, img->stride[1], align>>1); 512 | img_align_plane_10b(img->buffer[2], img->width>>1, img->height>>1, img->stride[2], align>>1); 513 | return S360_OK; 514 | } 515 | else 516 | { 517 | return S360_ERR_UNSUPPORTED_COLORSPACE; 518 | } 519 | } 520 | 521 | int s360_img_copy(S360_IMAGE *out, S360_IMAGE *in) 522 | { 523 | int w = out->width; 524 | int h = out->height; 525 | int s = out->stride[0]; 526 | int w_tri = GET_W_TRI_OHP(w*2); 527 | int h_tri = GET_H_TRI_OHP(w_tri); 528 | int i, j; 529 | int x; 530 | uint8 *p1, *p2; 531 | uint16 *q1, *q2; 532 | 533 | for (i=0; i<3; i++) 534 | { 535 | for (j=0; jcolorspace==S360_COLORSPACE_YUV420) { 538 | if (0) 539 | { 540 | p1 = (uint8*)out->buffer[i]; 541 | p2 = (uint8*)in->buffer[i]; 542 | memcpy(&p1[j*out->stride[i]], &p2[j*in->stride[i]+w_tri/2], w*2); 543 | } 544 | else if (out->colorspace==S360_COLORSPACE_YUV420_10) 545 | { 546 | q1 = (uint16*)out->buffer[i]; 547 | q2 = (uint16*)in->buffer[i]; 548 | memcpy(&q1[j*out->stride[i]], &q2[j*in->stride[i]+w_tri/2], w*2); 549 | } 550 | } 551 | for (j=0; jstride[i]], &q2[j*in->stride[i]+w_tri*7/2], x*2); 556 | x = CEILING((double)w_tri*(h/2-1-j)/h); 557 | if (!x) x=1; 558 | memcpy(&q1[j*out->stride[i]+w_tri*3/2+x], &q2[j*in->stride[i]+w_tri*3+x], (w_tri/2-x)*2); 559 | } 560 | for (j=h/2; jstride[i]], &q2[j*in->stride[i]+w_tri*7/2], x*2); 565 | x = CEILING((double)w_tri*(h-1-j)/h); 566 | if (!x) x=1; 567 | memcpy(&q1[j*out->stride[i]+w_tri*3/2+(w_tri/2-x)], &q2[j*in->stride[i]+w_tri*3+(w_tri/2-x)], x*2); 568 | } 569 | 570 | if (i==0) 571 | { 572 | h/=2; 573 | w/=2; 574 | w_tri/=2; 575 | } 576 | } 577 | return S360_OK; 578 | } 579 | -------------------------------------------------------------------------------- /src/360tools_img.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __360TOOLS_IMGB_H__19834765298347652938745629384562938562938456__ 35 | #define __360TOOLS_IMGB_H__19834765298347652938745629384562938562938456__ 36 | 37 | 38 | #ifdef __cplusplus 39 | extern "C" 40 | { 41 | #endif 42 | 43 | 44 | #include "360tools_def.h" 45 | 46 | 47 | #define S360_ALIGN(val, align) (((val) + (align) - 1) / (align) * (align)) 48 | 49 | /* create image buffer */ 50 | S360_IMAGE * s360_img_create(int w, int h, int cs, int opt); 51 | /* delete image buffer */ 52 | void s360_img_delete(S360_IMAGE * img); 53 | 54 | /* read an image from file */ 55 | int s360_img_read(FILE * fp, S360_IMAGE * img, int cs); 56 | /* write an image to file */ 57 | int s360_img_write(FILE * fp, S360_IMAGE * img, int cs); 58 | 59 | /* copy image */ 60 | int s360_img_copy(S360_IMAGE *out, S360_IMAGE *in); 61 | 62 | /* change width and height of the image */ 63 | int s360_img_realloc(S360_IMAGE * img, int w, int h, int opt); 64 | 65 | /* align an image's width and height */ 66 | int s360_img_align(S360_IMAGE * img, int align); 67 | 68 | /* Reset Image Buffer */ 69 | void s360_img_reset(S360_IMAGE * img); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | 76 | #endif /* __360TOOLS_IMGB_H__19834765298347652938745629384562938562938456__ */ 77 | 78 | -------------------------------------------------------------------------------- /src/360tools_isp.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __360TOOLS_ISP_H__2346758963478562398457629384562938576234__ 35 | #define __360TOOLS_ISP_H__2346758963478562398457629384562938576234__ 36 | 37 | 38 | #ifdef __cplusplus 39 | extern "C" 40 | { 41 | #endif 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | /* to ISP */ 48 | int s360_erp_to_isp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 49 | int s360_cpp_to_isp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 50 | int s360_risp2_to_isp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 51 | int s360_risp_to_isp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 52 | int s360_erp_to_risp1(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 53 | 54 | /* from ISP */ 55 | int s360_isp_to_erp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 56 | int s360_isp_to_cpp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 57 | int s360_isp_to_risp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 58 | int s360_isp_to_risp2(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 59 | int s360_risp1_to_erp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | 66 | #endif /* __360TOOLS_ISP_H__2346758963478562398457629384562938576234__ */ 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/360tools_map.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __360TOOLS_MAP_H__19834765298347652938745629384562938562938456__ 35 | #define __360TOOLS_MAP_H__19834765298347652938745629384562938562938456__ 36 | 37 | 38 | #ifdef __cplusplus 39 | extern "C" 40 | { 41 | #endif 42 | 43 | 44 | #include "360tools_def.h" 45 | 46 | 47 | #define S360_ALIGN(val, align) (((val) + (align) - 1) / (align) * (align)) 48 | 49 | /* create Map */ 50 | S360_MAP * s360_map_create(int w_src, int h_src, int w_dst, int h_dst, int cfmt, int opt, int pitch, int yaw); 51 | /* Delete Map */ 52 | void s360_map_delete(S360_MAP * map); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | 59 | #endif /* __360TOOLS_MAP_H__19834765298347652938745629384562938562938456__ */ 60 | 61 | -------------------------------------------------------------------------------- /src/360tools_ohp.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | 35 | #ifndef __360TOOLS_OHP_H__2346758963478562398457629384562938576234__ 36 | #define __360TOOLS_OHP_H__2346758963478562398457629384562938576234__ 37 | 38 | 39 | #ifdef __cplusplus 40 | extern "C" 41 | { 42 | #endif 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | /* to OHP */ 49 | int s360_erp_to_ohp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 50 | int s360_erp_to_cohp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 51 | int s360_rohp_to_ohp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 52 | int s360_cpp_to_ohp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 53 | 54 | /* from ohp */ 55 | int s360_ohp_to_erp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 56 | int s360_ohp_to_cpp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 57 | int s360_ohp_to_rohp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 58 | int s360_cohp_to_erp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | 65 | #endif /* __360TOOLS_OHP_H__2346758963478562398457629384562938576234__ */ 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/360tools_ssp.c: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, OwlReality Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of OwlReality Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | #include 34 | #include "360tools.h" 35 | #include "360tools_ssp.h" 36 | 37 | /*------------------------------- FROM ERP TO SSP -----------------------------*/ 38 | 39 | 40 | static void erp_to_ssp_sph2point(double lng, double lat, double* x, \ 41 | double* y, int w_src, int h_src) 42 | { 43 | *x = lng/M_2PI * w_src + w_src / 2; 44 | *y = h_src/2 - lat/M_PI_2 * h_src / 2; 45 | } 46 | 47 | 48 | static int erp_to_ssp_plane(void * src, int w_src, int h_src, int s_src, \ 49 | int w_dst, int h_dst, int s_dst, void * dst, int opt, int cs) 50 | { 51 | void(*fn_resample)(void * src, int w_start, int w_end, int h_start, int h_end,\ 52 | int s_src, double x, double y, void * dst, int x_dst); 53 | double lng, lat, x, y; 54 | int i, j; 55 | double w_center = w_dst; 56 | double w_square = h_dst / 3.0; 57 | double pole_x, pole_y, pole_d; 58 | 59 | if (cs == S360_COLORSPACE_YUV420) 60 | { 61 | fn_resample = resample_2d; 62 | } 63 | else if (cs == S360_COLORSPACE_YUV420_10) 64 | { 65 | fn_resample = resample_2d_10b; 66 | s_dst <<= 1; 67 | } 68 | 69 | for (j = 0; j= w_square && j < w_square*2) { 74 | lng = i / w_center * M_2PI - PI; 75 | lat = M_PI_2 / 2 - (j - w_square) * M_PI_2 / w_square; 76 | } 77 | else if (j < w_square) { 78 | if (i < (w_center - w_square) / 2 || i>= (w_center + w_square) / 2) 79 | continue; 80 | pole_x = i - w_center / 2; 81 | pole_y = j - w_square / 2; 82 | pole_d = sqrt(pole_x * pole_x + pole_y * pole_y); 83 | lat = M_PI_2 - pole_d / w_square * M_PI_2; 84 | lng = (pole_d > 0) ? acos(pole_y / pole_d) : 0; 85 | lng = (pole_x < 0) ? -lng : lng; 86 | } 87 | else { 88 | if (i < (w_center - w_square) / 2 || i >= (w_center + w_square) / 2) 89 | continue; 90 | pole_x = i - w_center / 2; 91 | pole_y = w_square * 5 / 2 - j; 92 | pole_d = sqrt(pole_x * pole_x + pole_y * pole_y); 93 | lat = pole_d / w_square * M_PI_2 - M_PI_2; 94 | lng = (pole_d > 0) ? acos(pole_y / pole_d) : 0; 95 | lng = (pole_x < 0) ? -lng : lng; 96 | } 97 | 98 | erp_to_ssp_sph2point(lng, lat, &x, &y, w_src, h_src); 99 | fn_resample(src, 0, w_src, 0, h_src, s_src, x, y, dst, i); 100 | } 101 | dst = (void *)((uint8 *)dst + s_dst); 102 | } 103 | 104 | return S360_OK; 105 | } 106 | 107 | 108 | int o360_erp_to_ssp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map) 109 | { 110 | int w_src, h_src, w_dst, h_dst; 111 | 112 | w_src = img_src->width; 113 | h_src = img_src->height; 114 | 115 | w_dst = img_dst->width; 116 | h_dst = img_dst->height; 117 | 118 | s360_img_reset(img_dst); 119 | if (opt & S360_OPT_PAD) 120 | s360_pad_erp(img_src); 121 | 122 | if (IS_VALID_CS(img_src->colorspace)) 123 | { 124 | erp_to_ssp_plane(img_src->buffer[0], w_src, h_src, img_src->stride[0], w_dst, h_dst, img_dst->stride[0], img_dst->buffer[0], opt, img_src->colorspace); 125 | w_src >>= 1; 126 | h_src >>= 1; 127 | w_dst >>= 1; 128 | h_dst >>= 1; 129 | erp_to_ssp_plane(img_src->buffer[1], w_src, h_src, img_src->stride[1], w_dst, h_dst, img_dst->stride[1], img_dst->buffer[1], opt, img_src->colorspace); 130 | erp_to_ssp_plane(img_src->buffer[2], w_src, h_src, img_src->stride[2], w_dst, h_dst, img_dst->stride[2], img_dst->buffer[2], opt, img_src->colorspace); 131 | } 132 | else 133 | { 134 | return S360_ERR_UNSUPPORTED_COLORSPACE; 135 | } 136 | return S360_OK; 137 | } 138 | 139 | static int cpp_to_ssp_plane(void * src, int w_src, int h_src, int s_src, \ 140 | int w_dst, int h_dst, int s_dst, void * dst, int opt, int cs) 141 | { 142 | resample_fn fn_resample; 143 | uint8 *map; 144 | int i, j; 145 | double phi, lat, lng; 146 | double x, y; 147 | double w_center = w_dst; 148 | double w_square = h_dst / 3.0; 149 | double pole_x, pole_y, pole_d; 150 | 151 | fn_resample = resample_fp(cs); 152 | 153 | map = (uint8 *)s360_malloc(sizeof(uint8) * w_src * h_src); 154 | cpp_map_plane(w_src, h_src, s_src, map); 155 | 156 | if(cs == S360_COLORSPACE_YUV420) 157 | { 158 | pad_cpp_plane((uint8 *)(src), w_src, h_src, s_src, map); 159 | } 160 | else if(cs == S360_COLORSPACE_YUV420_10) 161 | { 162 | pad_cpp_plane_10b((uint16 *)(src), w_src, h_src, s_src, map); 163 | s_dst <<= 1; 164 | } 165 | 166 | for(j=0; j= (w_center + w_square) / 2) 173 | continue; 174 | pole_x = i - w_center / 2; 175 | pole_y = j - w_square / 2; 176 | pole_d = sqrt(pole_x * pole_x + pole_y * pole_y); 177 | lat = M_PI_2 - pole_d / w_square * M_PI_2; 178 | lng = (pole_d > 0) ? acos(pole_y / pole_d) : 0; 179 | lng = (pole_x < 0) ? -lng : lng; 180 | y = h_src * .5f + h_src * sin(-lat/3); 181 | x = w_src * (0.5f + lng * (cos(-2*lat/3) - 0.5f) / PI); 182 | fn_resample(src, 0, w_src, 0, h_src, s_src, x, y, dst, i); 183 | } 184 | else if (j >= w_square && j < w_square * 2) 185 | { 186 | y = h_src * (.5 + sin(PI / 3 * ((double)(j - w_square/2)*3/2/h_dst -.5f))); 187 | phi = 3 * asin(y/h_src-.5); 188 | x = (w_src/2) * (1 + ((4 * cos(2* phi/3)) - 2) * ((double)i/w_dst -.5)); 189 | fn_resample(src, 0, w_src, 0, h_src, s_src, x, y, dst, i); 190 | } 191 | else 192 | { 193 | if (i < (w_center - w_square) / 2 || i>= (w_center + w_square) / 2) 194 | continue; 195 | pole_x = i - w_center / 2; 196 | pole_y = w_square * 5 / 2 - j; 197 | pole_d = sqrt(pole_x * pole_x + pole_y * pole_y); 198 | lat = pole_d / w_square * M_PI_2 - M_PI_2; 199 | lng = (pole_d > 0) ? acos(pole_y / pole_d) : 0; 200 | lng = (pole_x < 0) ? -lng : lng; 201 | y = h_src * .5f + h_src * sin(-lat/3); 202 | x = w_src * (0.5f + lng * (cos(-2*lat/3) - 0.5f) / PI); 203 | fn_resample(src, 0, w_src, 0, h_src, s_src, x, y, dst, i); 204 | } 205 | } 206 | dst = (void *)((uint8 *)dst + s_dst); 207 | } 208 | s360_mfree(map); 209 | 210 | return S360_OK; 211 | } 212 | 213 | int o360_cpp_to_ssp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map) 214 | { 215 | int w_src, h_src, w_dst, h_dst; 216 | 217 | w_src = img_src->width; 218 | h_src = img_src->height; 219 | 220 | w_dst = img_dst->width; 221 | h_dst = img_dst->height; 222 | 223 | s360_img_reset(img_dst); 224 | if (opt & S360_OPT_PAD) 225 | s360_pad_erp(img_src); 226 | 227 | if (IS_VALID_CS(img_src->colorspace)) 228 | { 229 | cpp_to_ssp_plane(img_src->buffer[0], w_src, h_src, img_src->stride[0], w_dst, h_dst, img_dst->stride[0], img_dst->buffer[0], opt, img_src->colorspace); 230 | w_src >>= 1; 231 | h_src >>= 1; 232 | w_dst >>= 1; 233 | h_dst >>= 1; 234 | cpp_to_ssp_plane(img_src->buffer[1], w_src, h_src, img_src->stride[1], w_dst, h_dst, img_dst->stride[1], img_dst->buffer[1], opt, img_src->colorspace); 235 | cpp_to_ssp_plane(img_src->buffer[2], w_src, h_src, img_src->stride[2], w_dst, h_dst, img_dst->stride[2], img_dst->buffer[2], opt, img_src->colorspace); 236 | return S360_OK; 237 | } 238 | else 239 | { 240 | return S360_ERR_UNSUPPORTED_COLORSPACE; 241 | } 242 | } 243 | 244 | /*------------------------------- FROM SSP TO ERP ---------------------------------*/ 245 | 246 | 247 | static void ssp_to_erp_sph2point(double lng, double lat, double* x, \ 248 | double* y, int w_src, int h_src, int* x_begin, int* x_end, int* y_begin, int* y_end) 249 | { 250 | int w_center = w_src; 251 | int w_square = h_src / 3; 252 | 253 | if (lat > M_PI_2 / 2) { 254 | *x = w_center/2 + w_square * sin(lng) * (M_PI_2 - lat) / M_PI_2; 255 | *y = w_square / 2 * (1 + cos(lng) * 2 * (M_PI_2 - lat) / M_PI_2); 256 | *x_begin = (w_center - w_square) / 2; 257 | *x_end = (w_center + w_square) / 2; 258 | *y_begin = 0; 259 | *y_end = w_square; 260 | } 261 | else if (lat < -M_PI_2 / 2){ 262 | *x = w_center/2 + w_square * sin(lng) * (M_PI_2 + lat) / M_PI_2; 263 | *y = w_square * 2 + w_square / 2 * (1 - cos(lng) * 2 * (M_PI_2 + lat) / M_PI_2); 264 | *x_begin = (w_center - w_square) / 2; 265 | *x_end = (w_center + w_square) / 2; 266 | *y_begin = w_square*2; 267 | *y_end = h_src; 268 | } 269 | else 270 | { 271 | *x = lng / M_2PI * w_center + w_center / 2; 272 | *y = w_square / 2 - lat / M_PI_2 * w_square + w_square; 273 | *x_begin = 0; 274 | *x_end = w_src; 275 | *y_begin = w_square; 276 | *y_end = w_square*2; 277 | } 278 | 279 | } 280 | 281 | static int ssp_to_erp_plane(void * src, int w_src, int h_src, int s_src, \ 282 | int w_dst, int h_dst, int s_dst, void * dst, int opt, int cs) 283 | { 284 | void(*fn_resample)(void * src, int w_start, int w_end, int h_start, int h_end,\ 285 | int s_src, double x, double y, void * dst, int x_dst); 286 | double lng, lat, x, y; 287 | int i, j, 288 | x_begin, x_end, y_begin, y_end; 289 | 290 | if (cs == S360_COLORSPACE_YUV420) 291 | { 292 | fn_resample = resample_2d; 293 | } 294 | else if (cs == S360_COLORSPACE_YUV420_10) 295 | { 296 | fn_resample = resample_2d_10b; 297 | s_dst <<= 1; 298 | } 299 | 300 | for (j = 0; jwidth; 321 | h_src = img_src->height; 322 | 323 | w_dst = img_dst->width; 324 | h_dst = img_dst->height; 325 | 326 | if (IS_VALID_CS(img_src->colorspace)) 327 | { 328 | ssp_to_erp_plane(img_src->buffer[0], w_src, h_src, img_src->stride[0], w_dst, h_dst, img_dst->stride[0], img_dst->buffer[0], opt, img_src->colorspace); 329 | w_src >>= 1; 330 | h_src >>= 1; 331 | w_dst >>= 1; 332 | h_dst >>= 1; 333 | ssp_to_erp_plane(img_src->buffer[1], w_src, h_src, img_src->stride[1], w_dst, h_dst, img_dst->stride[1], img_dst->buffer[1], opt, img_src->colorspace); 334 | ssp_to_erp_plane(img_src->buffer[2], w_src, h_src, img_src->stride[2], w_dst, h_dst, img_dst->stride[2], img_dst->buffer[2], opt, img_src->colorspace); 335 | } 336 | else 337 | { 338 | return S360_ERR_UNSUPPORTED_COLORSPACE; 339 | } 340 | 341 | return S360_OK; 342 | } 343 | 344 | static void ssp_to_cpp_sph2point(double lng, double lat, double* x, \ 345 | double* y, int w_src, int h_src, int* x_begin, int* x_end, int* y_begin, int* y_end) 346 | { 347 | double w_center = w_src; 348 | double w_square = h_src / 3; 349 | 350 | 351 | } 352 | 353 | static int ssp_to_cpp_plane(void * src, int w_src, int h_src, int s_src, \ 354 | int w_dst, int h_dst, int s_dst, void * dst, int opt, int cs) 355 | { 356 | void(*fn_resample)(void * src, int w_start, int w_end, int h_start, int h_end,\ 357 | int s_src, double x, double y, void * dst, int x_dst); 358 | double lambda, phi, x, y; 359 | int w_center = w_src; 360 | int w_square = h_src / 3; 361 | int i, j, 362 | x_begin, x_end, y_begin, y_end; 363 | uint8 *map; 364 | 365 | map = (uint8 *)s360_malloc(sizeof(uint8) * w_dst * h_dst); 366 | cpp_map_plane(w_dst, h_dst, s_dst, map); 367 | 368 | if (cs == S360_COLORSPACE_YUV420) 369 | { 370 | fn_resample = resample_2d; 371 | } 372 | else if (cs == S360_COLORSPACE_YUV420_10) 373 | { 374 | fn_resample = resample_2d_10b; 375 | s_dst <<= 1; 376 | } 377 | 378 | for (j = 0; j> 1; 391 | x_end = (w_center + w_square) >> 1; 392 | y_begin = 0; 393 | y_end = w_square; 394 | } 395 | else if (phi > M_PI_2 / 2){ 396 | x = w_center/2 + w_square * sin(lambda) * (M_PI_2 - phi) / M_PI_2; 397 | y = w_square * 2 + w_square / 2 * (1 - cos(lambda) * 2 * (M_PI_2 - phi) / M_PI_2); 398 | x_begin = (w_center - w_square) >> 1; 399 | x_end = (w_center + w_square) >> 1; 400 | y_begin = w_square*2; 401 | y_end = h_src; 402 | } 403 | else 404 | { 405 | x = lambda / M_2PI * w_center + w_center / 2; 406 | y = w_square / 2 + phi / M_PI_2 * w_square + w_square; 407 | x_begin = 0; 408 | x_end = w_src; 409 | y_begin = w_square; 410 | y_end = w_square*2; 411 | } 412 | 413 | fn_resample(src, 0, w_src, y_begin, y_end, s_src, x, y, dst, i); 414 | } 415 | } 416 | dst = (void *)((uint8 *)dst + s_dst); 417 | } 418 | 419 | return S360_OK; 420 | } 421 | 422 | int o360_ssp_to_cpp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map) 423 | { 424 | int w_src, h_src, w_dst, h_dst; 425 | 426 | w_src = img_src->width; 427 | h_src = img_src->height; 428 | 429 | w_dst = img_dst->width; 430 | h_dst = img_dst->height; 431 | 432 | if (IS_VALID_CS(img_src->colorspace)) 433 | { 434 | ssp_to_cpp_plane(img_src->buffer[0], w_src, h_src, img_src->stride[0], w_dst, h_dst, img_dst->stride[0], img_dst->buffer[0], opt, img_src->colorspace); 435 | w_src >>= 1; 436 | h_src >>= 1; 437 | w_dst >>= 1; 438 | h_dst >>= 1; 439 | ssp_to_cpp_plane(img_src->buffer[1], w_src, h_src, img_src->stride[1], w_dst, h_dst, img_dst->stride[1], img_dst->buffer[1], opt, img_src->colorspace); 440 | ssp_to_cpp_plane(img_src->buffer[2], w_src, h_src, img_src->stride[2], w_dst, h_dst, img_dst->stride[2], img_dst->buffer[2], opt, img_src->colorspace); 441 | return S360_OK; 442 | } 443 | else 444 | { 445 | return S360_ERR_UNSUPPORTED_COLORSPACE; 446 | } 447 | } 448 | 449 | -------------------------------------------------------------------------------- /src/360tools_ssp.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, OwlReality Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of OwlReality Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* Jisheng Li, Ziyu Wen, Sihan Li, Yikai Zhao, Bichuan Guo, and Jiangtao Wen. 35 | * "Novel tile segmentation scheme for omnidirectional video." In Image 36 | * Processing (ICIP), 2016 IEEE International Conference on, pp. 370-374. 37 | * IEEE, 2016. 38 | */ 39 | 40 | #ifndef __360TOOLS_SSP_H__ 41 | #define __360TOOLS_SSP_H__ 42 | 43 | 44 | #ifdef __cplusplus 45 | extern "C" 46 | { 47 | #endif 48 | 49 | #include 50 | #include 51 | #include 52 | 53 | /* to SSP */ 54 | int o360_erp_to_ssp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 55 | int o360_cpp_to_ssp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 56 | /* from SSP */ 57 | int o360_ssp_to_erp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 58 | int o360_ssp_to_cpp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | 64 | #endif /* __360TOOLS_SSP_H__ */ 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/360tools_tbl.c: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Samsung Electronics Co., Ltd. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "360tools.h" 35 | #include 36 | #include "360tools_def.h" 37 | 38 | double tbl_tri_xyz[12][3] = \ 39 | { 40 | { 0, 0, 1 }, 41 | { 0.894427191, 0, 0.447213595 }, 42 | { 0.276393202, 0.850650808, 0.447213595 }, 43 | { -0.723606798, 0.525731112, 0.447213595 }, 44 | { -0.723606798, -0.525731112, 0.447213595 }, 45 | { 0.276393202, -0.850650808, 0.447213595 }, 46 | { 0.723606798, 0.525731112, -0.447213595 }, 47 | { -0.276393202, 0.850650808, -0.447213595 }, 48 | { -0.894427191, 0, -0.447213595 }, 49 | { -0.276393202, -0.850650808, -0.447213595 }, 50 | { 0.723606798, -0.525731112, -0.447213595 }, 51 | { 0, 0, -1 } 52 | }; 53 | 54 | const int tbl_vidx_erp2cmp[6][4] = // Change cmp_plane_offset if needed 55 | { 56 | { 7, 0, 4, 1 }, // Top 57 | { 0, 2, 1, 3 }, // Back 58 | { 2, 6, 3, 5 }, // Bottom 59 | { 7, 6, 0, 2 }, // Left 60 | { 1, 3, 4, 5 }, // Right 61 | { 4, 5, 7, 6 }, // Front 62 | }; 63 | 64 | const int tbl_vidx_erp2tsp[6][4] = 65 | { 66 | { 4, 7, 1, 0 }, // Top 67 | { 7, 6, 0, 2 }, // Front 68 | { 6, 5, 2, 3 }, // Bottom 69 | { 4, 5, 7, 6 }, // Left 70 | { 0, 2, 1, 3 }, // Right 71 | { 1, 3, 4, 5 }, // Back 72 | }; 73 | 74 | double tbl_tspface_eqn[6][4] = \ 75 | { 76 | /* ax + by + cz = d */ 77 | { 0.0, 1.0, 0.0, 0.57735026919 }, 78 | { 1.0, 0.0, 0.0, -0.57735026919 }, 79 | { 0.0, 1.0, 0.0, -0.57735026919 }, 80 | { 0.0, 0.0, 1.0, 0.57735026919 }, 81 | { 0.0, 0.0, 1.0, -0.57735026919 }, 82 | { 1.0, 0.0, 0.0, 0.57735026919 } 83 | }; 84 | 85 | const double tbl_squ_center_xyz[6][3] = \ 86 | { 87 | { 0.0, 0.57735026919, 0.0 }, 88 | { 0.0, 0.0, -0.57735026919 }, 89 | { 0.0, -0.57735026919, 0.0 }, 90 | { -0.57735026919, 0.0, 0.0 }, 91 | { 0.57735026919, 0.0, 0.0 }, 92 | { 0.0, 0.0, 0.57735026919 } 93 | }; 94 | 95 | double tbl_tsp_center_xyz[6][3] = \ 96 | { 97 | { 0.0, 0.57735026919, 0.0 }, // top 98 | { -0.57735026919, 0.0, 0.0 }, // front 99 | { 0.0, -0.57735026919, 0.0 }, // bottom 100 | { 0.0, 0.0, 0.57735026919 }, // left 101 | { 0.0, 0.0, -0.57735026919 }, // right 102 | { 0.57735026919, 0.0, 0.0 } // back 103 | }; 104 | 105 | const double tbl_squ_xyz[8][3] = \ 106 | { 107 | { -0.57735026919, 0.57735026919, -0.57735026919 }, 108 | { 0.57735026919, 0.57735026919, -0.57735026919 }, 109 | { -0.57735026919, -0.57735026919, -0.57735026919 }, 110 | { 0.57735026919, -0.57735026919, -0.57735026919 }, 111 | { 0.57735026919, 0.57735026919, 0.57735026919 }, 112 | { 0.57735026919, -0.57735026919, 0.57735026919 }, 113 | { -0.57735026919, -0.57735026919, 0.57735026919 }, 114 | { -0.57735026919, 0.57735026919, 0.57735026919 } 115 | 116 | }; 117 | 118 | double tbl_face_eqn[6][4] = \ 119 | { 120 | /* ax + by + cz = d */ 121 | { 0.0, 1.0, 0.0, 0.57735026919 }, 122 | { 0.0, 0.0, 1.0, -0.57735026919 }, 123 | { 0.0, 1.0, 0.0, -0.57735026919 }, 124 | { 1.0, 0.0, 0.0, -0.57735026919 }, 125 | { 1.0, 0.0, 0.0, 0.57735026919 }, 126 | { 0.0, 0.0, 1.0, 0.57735026919 } 127 | }; 128 | 129 | const int tbl_vidx_erp2isp[20][3] = 130 | { 131 | { 0, 4, 5 }, 132 | { 0, 5, 1 }, 133 | { 0, 1, 2 }, 134 | { 0, 2, 3 }, 135 | { 0, 3, 4 }, 136 | { 5, 9, 10 }, 137 | { 1, 10, 6 }, 138 | { 2, 6, 7 }, 139 | { 3, 7, 8 }, 140 | { 4, 8, 9 }, 141 | /* upside-down */ 142 | { 4, 5, 9 }, 143 | { 5, 1, 10 }, 144 | { 1, 2, 6 }, 145 | { 2, 3, 7 }, 146 | { 3, 4, 8 }, 147 | { 9, 10, 11 }, 148 | { 10, 6, 11 }, 149 | { 6, 7, 11 }, 150 | { 7, 8, 11 }, 151 | { 8, 9, 11 } 152 | }; 153 | 154 | const int tbl_vidx_isp2erp[20][3] = \ 155 | { 156 | { 0, 1, 2 }, 157 | { 0, 2, 3 }, 158 | { 0, 3, 4 }, 159 | { 0, 4, 5 }, 160 | { 0, 5, 1 }, 161 | { 1, 10, 6 }, 162 | { 6, 1, 2 }, 163 | { 2, 6, 7 }, 164 | { 7, 2, 3 }, 165 | { 3, 7, 8 }, 166 | { 8, 3, 4 }, 167 | { 4, 8, 9 }, 168 | { 9, 4, 5 }, 169 | { 5, 9, 10 }, 170 | { 10, 5, 1 }, 171 | { 11, 10, 6 }, 172 | { 11, 6, 7 }, 173 | { 11, 7, 8 }, 174 | { 11, 8, 9 }, 175 | { 11, 9, 10 } 176 | }; 177 | 178 | const int tbl_vidx_pad_isp[20][2] = \ 179 | { 180 | { 1, 1 }, //1 181 | { 1, 1 }, 182 | { 1, 1 }, 183 | { 1, 1 }, 184 | { 1, 1 }, //5 185 | { 0, 0 }, 186 | { 0, 0 }, 187 | { 0, 0 }, 188 | { 0, 0 }, 189 | { 0, 1 }, //10 190 | { 1, 0 }, 191 | { 0, 0 }, 192 | { 0, 0 }, 193 | { 0, 0 }, 194 | { 0, 0 }, //15 195 | { 1, 1 }, 196 | { 1, 1 }, 197 | { 1, 1 }, 198 | { 1, 1 }, 199 | { 1, 1 } //20 200 | }; 201 | 202 | double tbl_tri_xyz_ohp[6][3] = \ 203 | { 204 | { 0, 0, 1 }, 205 | { 1, 0, 0 }, 206 | { 0, 1, 0 }, 207 | { -1, 0, 0 }, 208 | { 0, -1, 0 }, 209 | { 0, 0, -1 }, 210 | }; 211 | 212 | const int tbl_vidx_erp2ohp[8][3] = 213 | { 214 | { 0, 1, 2 }, 215 | { 0, 2, 3 }, 216 | { 0, 3, 4 }, 217 | { 0, 4, 1 }, 218 | 219 | { 1, 2, 5 }, 220 | { 2, 3, 5 }, 221 | { 3, 4, 5 }, 222 | { 4, 1, 5 } 223 | }; 224 | 225 | const int tbl_vidx_ohp2erp[8][3] = \ 226 | { 227 | { 0, 1, 2 }, 228 | { 0, 2, 3 }, 229 | { 0, 3, 4 }, 230 | { 0, 4, 1 }, 231 | 232 | { 5, 1, 2 }, 233 | { 5, 2, 3 }, 234 | { 5, 3, 4 }, 235 | { 5, 4, 1 } 236 | }; -------------------------------------------------------------------------------- /src/360tools_tsp.c: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Qualcomm inc. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Qualcomm inc. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | #include "360tools.h" 36 | #include "360tools_tsp.h" 37 | 38 | static int erp_to_tsp_plane(void * src, int w_src, int h_src, int s_src, \ 39 | int w_dst, int h_dst, int s_dst, void * dst, int w_squ, int opt, int pad_size, int cs, S360_SPH_COORD * map) 40 | { 41 | void(*fn_resample)(void * src, int w_start, int w_end, int h_start, int h_end,\ 42 | int s_src, double x, double y, void * dst, int x_dst); 43 | void(*fn_resample_tsp)(void * src, int w_start, int w_end, int w_src, int h_src, int s_src, 44 | void * dst, int w_dst, int x_dst, int y_dst, S360_SPH_COORD * map); 45 | int sub = TSPAA_S; 46 | int num = sub * sub; 47 | unsigned int map_idx; 48 | double x, y; 49 | int i, j; 50 | int w_start, w_end, h_start; 51 | 52 | w_start = opt ? -pad_size : 0; 53 | w_end = opt ? w_src + pad_size : w_src; 54 | h_start = 0; 55 | 56 | if (cs == S360_COLORSPACE_YUV420) 57 | { 58 | fn_resample = resample_2d; 59 | fn_resample_tsp = resample_tsp_2d; 60 | } 61 | else if (cs == S360_COLORSPACE_YUV420_10) 62 | { 63 | fn_resample = resample_2d_10b; 64 | fn_resample_tsp = resample_tsp_2d_10b; 65 | s_dst <<= 1; 66 | } 67 | 68 | for (j = 0; j>1); i++) 71 | { 72 | map_idx = i * sub; 73 | if (map[map_idx].lng != -1) 74 | { 75 | x = (map[map_idx].lng / 360.0) * w_src; 76 | y = (map[map_idx].lat / 180.0) * h_src; 77 | 78 | fn_resample(src, w_start, w_end, h_start, h_src, s_src, x, y, dst, i); 79 | } 80 | } 81 | dst = (void *)((uint8 *)dst + s_dst); 82 | map += w_dst * num; 83 | } 84 | map -= w_dst * h_dst * num; 85 | dst = (void *)((uint8 *)dst - s_dst * h_dst); 86 | 87 | for (j = 0; j>1); iwidth; 106 | h_src = img_src->height; 107 | 108 | w_dst = img_dst->width; 109 | h_dst = img_dst->height; 110 | w_squ = NEAREST_EVEN(w_dst / 2.0); 111 | 112 | s360_img_reset(img_dst); 113 | if (opt & S360_OPT_PAD) 114 | s360_pad_erp(img_src); 115 | 116 | if (IS_VALID_CS(img_src->colorspace)) 117 | { 118 | erp_to_tsp_plane(img_src->buffer[0], w_src, h_src, img_src->stride[0], w_dst, h_dst, img_dst->stride[0], img_dst->buffer[0], w_squ, opt, PAD_SIZE, img_src->colorspace, map->layer[0]); 119 | w_squ >>= 1; 120 | w_src >>= 1; 121 | h_src >>= 1; 122 | w_dst >>= 1; 123 | h_dst >>= 1; 124 | erp_to_tsp_plane(img_src->buffer[1], w_src, h_src, img_src->stride[1], w_dst, h_dst, img_dst->stride[1], img_dst->buffer[1], w_squ, opt, PAD_SIZE >> 1, img_src->colorspace, map->layer[1]); 125 | erp_to_tsp_plane(img_src->buffer[2], w_src, h_src, img_src->stride[2], w_dst, h_dst, img_dst->stride[2], img_dst->buffer[2], w_squ, opt, PAD_SIZE >> 1, img_src->colorspace, map->layer[1]); 126 | } 127 | else 128 | { 129 | return S360_ERR_UNSUPPORTED_COLORSPACE; 130 | } 131 | return S360_OK; 132 | } 133 | 134 | static int get_squ_idx(double x, double y, double z, const double center[6][3]){ 135 | 136 | double min_dist, dist, h1, h2, h3; 137 | int i, idx; 138 | 139 | idx = 0; 140 | min_dist = 9999.0; 141 | 142 | for (i = 0; i<6; i++) 143 | { 144 | h1 = center[i][0] - x; 145 | h2 = center[i][1] - y; 146 | h3 = center[i][2] - z; 147 | dist = (h1 * h1 + h2 * h2 + h3 * h3); 148 | if (dist < min_dist) 149 | { 150 | idx = i; 151 | min_dist = dist; 152 | } 153 | } 154 | 155 | return idx; 156 | } 157 | 158 | /*------------------------------- FROM TSP -----------------------------*/ 159 | static void tsp_to_erp_sph2point(double lng, double lat, int w_squ, double* x, \ 160 | double* y, double d12, double d13) 161 | { 162 | double xyz[3], vec_12[3], vec_13[3], vec_1_xyz[3]; 163 | double d1_xyz; 164 | double dist_ver, dist_hor; 165 | int v_1_3d, v_2_3d, v_3_3d, v_4_3d; 166 | int squ_idx; 167 | double xc, yc, xp, yp; 168 | 169 | xyz[0] = sin(lat) * cos(lng); 170 | xyz[2] = sin(lat) * sin(lng); 171 | xyz[1] = cos(lat); 172 | 173 | squ_idx = get_squ_idx(xyz[0], xyz[1], xyz[2], tbl_tsp_center_xyz); 174 | v_1_3d = tbl_vidx_erp2tsp[squ_idx][0]; 175 | v_2_3d = tbl_vidx_erp2tsp[squ_idx][1]; 176 | v_3_3d = tbl_vidx_erp2tsp[squ_idx][2]; 177 | v_4_3d = tbl_vidx_erp2tsp[squ_idx][3]; 178 | 179 | v3d_scale_face(tbl_tspface_eqn[squ_idx], xyz); 180 | v3d_sub(tbl_squ_xyz[v_2_3d], tbl_squ_xyz[v_1_3d], vec_12); 181 | v3d_sub(tbl_squ_xyz[v_3_3d], tbl_squ_xyz[v_1_3d], vec_13); 182 | v3d_sub(xyz, tbl_squ_xyz[v_1_3d], vec_1_xyz); 183 | d1_xyz = GET_DIST3D(vec_1_xyz[0], vec_1_xyz[1], vec_1_xyz[2]); 184 | 185 | dist_ver = v3d_dot_product(vec_12, vec_1_xyz) / d12; 186 | dist_hor = v3d_dot_product(vec_13, vec_1_xyz) / d13; 187 | 188 | xc = dist_hor / d13; 189 | yc = dist_ver / d12; 190 | 191 | switch (squ_idx) 192 | { 193 | case 0: 194 | xp = 0.1875 * yc - 0.375 * xc * yc - 0.125 * xc + 0.8125; 195 | yp = 0.375 - 0.375 * yc; 196 | break; 197 | case 1: 198 | xp = 0.5 * xc; 199 | yp = yc; 200 | break; 201 | case 2: 202 | xp = 1.0 - 0.1875 * yc - 0.5 * xc + 0.375 * xc * yc; 203 | yp = 1.0 - 0.375 * yc; 204 | break; 205 | case 3: 206 | xp = 0.1875 * xc + 0.8125; 207 | yp = 0.25 * yc + 0.75 * xc * yc - 0.375 * xc + 0.375; 208 | break; 209 | case 4: 210 | xp = 0.1875 * xc + 0.5; 211 | yp = 0.375 * xc - 0.75 * xc * yc + yc; 212 | break; 213 | case 5: 214 | xp = 0.125 * xc + 0.6875; 215 | yp = 0.25 * yc + 0.375; 216 | break; 217 | } 218 | 219 | *x = xp * 2*w_squ; 220 | *y = yp * w_squ; 221 | } 222 | 223 | static int tsp_to_erp_plane(void * src, int w_src, int h_src, int s_src, \ 224 | int w_dst, int h_dst, int s_dst, void * dst, int w_squ, int opt, int cs) 225 | { 226 | void(*fn_resample)(void * src, int w_start, int w_end, int h_start, int h_end,\ 227 | int s_src, double x, double y, void * dst, int x_dst); 228 | double vec_12[3], vec_13[3]; 229 | double lng, lat, x, y; 230 | double d12, d13; 231 | int v_1_3d, v_2_3d, v_3_3d; 232 | int i, j; 233 | 234 | if (cs == S360_COLORSPACE_YUV420) 235 | { 236 | fn_resample = resample_2d; 237 | } 238 | else if (cs == S360_COLORSPACE_YUV420_10) 239 | { 240 | fn_resample = resample_2d_10b; 241 | s_dst <<= 1; 242 | } 243 | 244 | v_1_3d = tbl_vidx_erp2tsp[0][0]; 245 | v_2_3d = tbl_vidx_erp2tsp[0][1]; 246 | v_3_3d = tbl_vidx_erp2tsp[0][2]; 247 | 248 | v3d_sub(tbl_squ_xyz[v_2_3d], tbl_squ_xyz[v_1_3d], vec_12); 249 | d12 = GET_DIST3D(vec_12[0], vec_12[1], vec_12[2]); 250 | v3d_sub(tbl_squ_xyz[v_3_3d], tbl_squ_xyz[v_1_3d], vec_13); 251 | d13 = GET_DIST3D(vec_13[0], vec_13[1], vec_13[2]); 252 | 253 | for (j = 0; jwidth; 275 | h_src = img_src->height; 276 | 277 | w_dst = img_dst->width; 278 | h_dst = img_dst->height; 279 | w_squ = NEAREST_EVEN(w_src / 2.0); 280 | 281 | if (IS_VALID_CS(img_src->colorspace)) 282 | { 283 | tsp_to_erp_plane(img_src->buffer[0], w_src, h_src, img_src->stride[0], w_dst, h_dst, img_dst->stride[0], img_dst->buffer[0], w_squ, opt, img_src->colorspace); 284 | w_squ >>= 1; 285 | w_src >>= 1; 286 | h_src >>= 1; 287 | w_dst >>= 1; 288 | h_dst >>= 1; 289 | tsp_to_erp_plane(img_src->buffer[1], w_src, h_src, img_src->stride[1], w_dst, h_dst, img_dst->stride[1], img_dst->buffer[1], w_squ, opt, img_src->colorspace); 290 | tsp_to_erp_plane(img_src->buffer[2], w_src, h_src, img_src->stride[2], w_dst, h_dst, img_dst->stride[2], img_dst->buffer[2], w_squ, opt, img_src->colorspace); 291 | } 292 | else 293 | { 294 | return S360_ERR_UNSUPPORTED_COLORSPACE; 295 | } 296 | 297 | return S360_OK; 298 | } 299 | 300 | static int tsp_to_cpp_plane(void * src, int w_src, int h_src, int s_src, \ 301 | int w_dst, int h_dst, int s_dst, void * dst, int w_squ, int opt, int cs) 302 | { 303 | void(*fn_resample)(void * src, int w_start, int w_end, int h_start, int h_end,\ 304 | int s_src, double x, double y, void * dst, int x_dst); 305 | 306 | double vec_12[3], vec_13[3]; 307 | double lng, lat, x, y; 308 | double d12, d13; 309 | int v_1_3d, v_2_3d, v_3_3d; 310 | int i, j; 311 | uint8 * map, *map0; 312 | 313 | if (cs == S360_COLORSPACE_YUV420) 314 | { 315 | fn_resample = resample_2d; 316 | } 317 | else if (cs == S360_COLORSPACE_YUV420_10) 318 | { 319 | fn_resample = resample_2d_10b; 320 | s_dst <<= 1; 321 | } 322 | 323 | map = (uint8 *)s360_malloc(sizeof(uint8) * h_dst * w_dst); 324 | cpp_map_plane(w_dst, h_dst, s_dst, map); 325 | map0 = map; 326 | 327 | v_1_3d = tbl_vidx_erp2tsp[0][0]; 328 | v_2_3d = tbl_vidx_erp2tsp[0][1]; 329 | v_3_3d = tbl_vidx_erp2tsp[0][2]; 330 | 331 | v3d_sub(tbl_squ_xyz[v_2_3d], tbl_squ_xyz[v_1_3d], vec_12); 332 | d12 = GET_DIST3D(vec_12[0], vec_12[1], vec_12[2]); 333 | v3d_sub(tbl_squ_xyz[v_3_3d], tbl_squ_xyz[v_1_3d], vec_13); 334 | d13 = GET_DIST3D(vec_13[0], vec_13[1], vec_13[2]); 335 | 336 | for (j = 0; jwidth; 369 | h_src = img_src->height; 370 | 371 | w_dst = img_dst->width; 372 | h_dst = img_dst->height; 373 | w_squ = NEAREST_EVEN(w_src / 2.0); 374 | 375 | s360_img_reset(img_dst); 376 | 377 | if (IS_VALID_CS(img_src->colorspace)) 378 | { 379 | tsp_to_cpp_plane(img_src->buffer[0], w_src, h_src, img_src->stride[0], w_dst, h_dst, img_dst->stride[0], img_dst->buffer[0], w_squ, opt, img_src->colorspace); 380 | w_squ >>= 1; 381 | w_src >>= 1; 382 | h_src >>= 1; 383 | w_dst >>= 1; 384 | h_dst >>= 1; 385 | tsp_to_cpp_plane(img_src->buffer[1], w_src, h_src, img_src->stride[1], w_dst, h_dst, img_dst->stride[1], img_dst->buffer[1], w_squ, opt, img_src->colorspace); 386 | tsp_to_cpp_plane(img_src->buffer[2], w_src, h_src, img_src->stride[2], w_dst, h_dst, img_dst->stride[2], img_dst->buffer[2], w_squ, opt, img_src->colorspace); 387 | } 388 | else 389 | { 390 | return S360_ERR_UNSUPPORTED_COLORSPACE; 391 | } 392 | 393 | return S360_OK; 394 | } 395 | -------------------------------------------------------------------------------- /src/360tools_tsp.h: -------------------------------------------------------------------------------- 1 | /* The copyright in this software is being made available under the BSD 2 | * License, included below. This software may be subject to other third party 3 | * and contributor rights, including patent rights, and no such rights are 4 | * granted under this license. 5 | * 6 | * Copyright (c) 2016, Qualcomm inc. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of Samsung Electronics Co., Ltd. nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __360TOOLS_TSP_H__3874507350229384795268645223468756924524__ 35 | #define __360TOOLS_TSP_H__3874507350229384795268645223468756924524__ 36 | 37 | #ifdef __cplusplus 38 | extern "C" 39 | { 40 | #endif 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | /* to TSP */ 47 | int s360_erp_to_tsp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 48 | 49 | /* from TSP */ 50 | int s360_tsp_to_erp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 51 | int s360_tsp_to_cpp(S360_IMAGE * img_src, S360_IMAGE * img_dst, int opt, S360_MAP * map); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | 58 | #endif /* __360TOOLS_CMP_H__3874507350229384795268645223468756924524__ */ 59 | 60 | 61 | --------------------------------------------------------------------------------