void calPowerPara(double * power, fftw_complex * fft, int nPower, double dk, double * kk, double * dir, int * n) { for (int iPower = 0; iPower < nPower; iPower++) { power[iPower] = 0; } double kPara; int kBin; fftw_complex * p; fftw_complex coefFFT; p = fft; int i, j, k; for (int k2 = 0; k2 < n[2]; k2++) for (int j2 = 0; j2 < n[1]; j2++) for (int i2 = 0; i2 < n[0]; i2++) { i = PU(i2, n[0]); j = PU(j2, n[1]); k = PU(k2, n[2]); kPara = fabs(i*kk[0]*dir[0] + j*kk[1]*dir[1] + k*kk[2]*dir[2]); kBin = ceil(kPara/dk - 0.5); if (kBin < 0) kBin = 0; if (kBin >= nPower) kBin = nPower; coefFFT = *p++; power[kBin] += cabs(coefFFT) * cabs(coefFFT); } }
void calPowerPerp(double * power, fftw_complex * fft, int nPower, double dk, double * kk, double * dir, int * n) { fftw_complex * p; fftw_complex coefFFT; p = fft; for (int iPower = 0; iPower < nPower; iPower++) { power[iPower] = 0; } double kPerp; int kBin; double xPara, yPara, zPara; double xRemn, yRemn, zRemn; int i, j, k; for (int k2 = 0; k2 < n[2]; k2++) for (int j2 = 0; j2 < n[1]; j2++) for (int i2 = 0; i2 < n[0]; i2++) { i = PU(i2, n[0]); j = PU(j2, n[1]); k = PU(k2, n[2]); xPara = i*kk[0]*dir[0]; yPara = j*kk[1]*dir[1]; zPara = k*kk[2]*dir[2]; xRemn = i*kk[0] - xPara; yRemn = j*kk[1] - yPara; zRemn = k*kk[2] - zPara; kPerp = sqrt(xRemn*xRemn + yRemn*yRemn + zRemn*zRemn); kBin = ceil(kPerp/dk - 0.5); if (kBin >= nPower) kBin = nPower; coefFFT = *p++; power[kBin] += cabs(coefFFT) * cabs(coefFFT); } }
void ParametricSurface<Real>::GetFrame (Real u, Real v, Vector3<Real>& position, Vector3<Real>& tangent0, Vector3<Real>& tangent1, Vector3<Real>& normal) const { position = P(u, v); tangent0 = PU(u, v); tangent1 = PV(u, v); tangent0.Normalize(); // T0 tangent1.Normalize(); // temporary T1 just to compute N normal = tangent0.UnitCross(tangent1); // N // The normalized first derivatives are not necessarily orthogonal. // Recompute T1 so that {T0,T1,N} is an orthonormal set. tangent1 = normal.Cross(tangent0); }
static void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int c_idx) { #define PU(x) \ ((x) >> s->sps->log2_min_pu_size) #define MVF(x, y) \ (s->ref->tab_mvf[(x) + (y) * min_pu_width]) #define MVF_PU(x, y) \ MVF(PU(x0 + ((x) << hshift)), PU(y0 + ((y) << vshift))) #define IS_INTRA(x, y) \ (MVF_PU(x, y).pred_flag == PF_INTRA) #define MIN_TB_ADDR_ZS(x, y) \ s->pps->min_tb_addr_zs[(y) * s->sps->min_tb_width + (x)] #define EXTEND_LEFT(ptr, start, length) \ for (i = (start); i > (start) - (length); i--) \ ptr[i - 1] = ptr[i] #define EXTEND_RIGHT(ptr, start, length) \ for (i = (start); i < (start) + (length); i++) \ ptr[i] = ptr[i - 1] #define EXTEND_UP(ptr, start, length) EXTEND_LEFT(ptr, start, length) #define EXTEND_DOWN(ptr, start, length) EXTEND_RIGHT(ptr, start, length) #define EXTEND_LEFT_CIP(ptr, start, length) \ for (i = (start); i > (start) - (length); i--) \ if (!IS_INTRA(i - 1, -1)) \ ptr[i - 1] = ptr[i] #define EXTEND_RIGHT_CIP(ptr, start, length) \ for (i = (start); i < (start) + (length); i++) \ if (!IS_INTRA(i, -1)) \ ptr[i] = ptr[i - 1] #define EXTEND_UP_CIP(ptr, start, length) \ for (i = (start); i > (start) - (length); i--) \ if (!IS_INTRA(-1, i - 1)) \ ptr[i - 1] = ptr[i] #define EXTEND_UP_CIP_0(ptr, start, length) \ for (i = (start); i > (start) - (length); i--) \ ptr[i - 1] = ptr[i] #define EXTEND_DOWN_CIP(ptr, start, length) \ for (i = (start); i < (start) + (length); i++) \ if (!IS_INTRA(-1, i)) \ ptr[i] = ptr[i - 1] HEVCLocalContext *lc = s->HEVClc; int i; int hshift = s->sps->hshift[c_idx]; int vshift = s->sps->vshift[c_idx]; int size = (1 << log2_size); int size_in_luma = size << hshift; int size_in_tbs = size_in_luma >> s->sps->log2_min_tb_size; int x = x0 >> hshift; int y = y0 >> vshift; int x_tb = x0 >> s->sps->log2_min_tb_size; int y_tb = y0 >> s->sps->log2_min_tb_size; int cur_tb_addr = MIN_TB_ADDR_ZS(x_tb, y_tb); ptrdiff_t stride = s->frame->linesize[c_idx] / sizeof(pixel); pixel *src = (pixel*)s->frame->data[c_idx] + x + y * stride; int min_pu_width = s->sps->min_pu_width; enum IntraPredMode mode = c_idx ? lc->pu.intra_pred_mode_c : lc->tu.cur_intra_pred_mode; pixel left_array[2 * MAX_TB_SIZE + 1]; pixel filtered_left_array[2 * MAX_TB_SIZE + 1]; pixel top_array[2 * MAX_TB_SIZE + 1]; pixel filtered_top_array[2 * MAX_TB_SIZE + 1]; pixel *left = left_array + 1; pixel *top = top_array + 1; pixel *filtered_left = filtered_left_array + 1; pixel *filtered_top = filtered_top_array + 1; int cand_bottom_left = lc->na.cand_bottom_left && cur_tb_addr > MIN_TB_ADDR_ZS(x_tb - 1, y_tb + size_in_tbs); int cand_left = lc->na.cand_left; int cand_up_left = lc->na.cand_up_left; int cand_up = lc->na.cand_up; int cand_up_right = lc->na.cand_up_right && cur_tb_addr > MIN_TB_ADDR_ZS(x_tb + size_in_tbs, y_tb - 1); int bottom_left_size = (FFMIN(y0 + 2 * size_in_luma, s->sps->height) - (y0 + size_in_luma)) >> vshift; int top_right_size = (FFMIN(x0 + 2 * size_in_luma, s->sps->width) - (x0 + size_in_luma)) >> hshift; if (s->pps->constrained_intra_pred_flag == 1) { int size_in_luma_pu = PU(size_in_luma); int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1)); int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1)); if (!size_in_luma_pu) size_in_luma_pu++; if (cand_bottom_left == 1 && on_pu_edge_x) { int x_left_pu = PU(x0 - 1); int y_bottom_pu = PU(y0 + size_in_luma); int max = FFMIN(size_in_luma_pu, s->sps->min_pu_height - y_bottom_pu); cand_bottom_left = 0; for (i = 0; i < max; i++) cand_bottom_left |= (MVF(x_left_pu, y_bottom_pu + i).pred_flag == PF_INTRA); } if (cand_left == 1 && on_pu_edge_x) { int x_left_pu = PU(x0 - 1); int y_left_pu = PU(y0); int max = FFMIN(size_in_luma_pu, s->sps->min_pu_height - y_left_pu); cand_left = 0; for (i = 0; i < max; i++) cand_left |= (MVF(x_left_pu, y_left_pu + i).pred_flag == PF_INTRA); } if (cand_up_left == 1) { int x_left_pu = PU(x0 - 1); int y_top_pu = PU(y0 - 1); cand_up_left = MVF(x_left_pu, y_top_pu).pred_flag == PF_INTRA; } if (cand_up == 1 && on_pu_edge_y) { int x_top_pu = PU(x0); int y_top_pu = PU(y0 - 1); int max = FFMIN(size_in_luma_pu, s->sps->min_pu_width - x_top_pu); cand_up = 0; for (i = 0; i < max; i++) cand_up |= (MVF(x_top_pu + i, y_top_pu).pred_flag == PF_INTRA); } if (cand_up_right == 1 && on_pu_edge_y) { int y_top_pu = PU(y0 - 1); int x_right_pu = PU(x0 + size_in_luma); int max = FFMIN(size_in_luma_pu, s->sps->min_pu_width - x_right_pu); cand_up_right = 0; for (i = 0; i < max; i++) cand_up_right |= (MVF(x_right_pu + i, y_top_pu).pred_flag == PF_INTRA); } for (i = 0; i < 2 * MAX_TB_SIZE; i++) { left[i] = 128; top[i] = 128; } top[-1] = 128; } if (cand_bottom_left) { for (i = size + bottom_left_size; i < (size << 1); i++) if (IS_INTRA(-1, size + bottom_left_size - 1) || !s->pps->constrained_intra_pred_flag) left[i] = POS(-1, size + bottom_left_size - 1); for (i = size + bottom_left_size - 1; i >= size; i--) if (IS_INTRA(-1, i) || !s->pps->constrained_intra_pred_flag) left[i] = POS(-1, i); } if (cand_left) for (i = size - 1; i >= 0; i--) if (IS_INTRA(-1, i) || !s->pps->constrained_intra_pred_flag) left[i] = POS(-1, i); if (cand_up_left) if (IS_INTRA(-1, -1) || !s->pps->constrained_intra_pred_flag) { left[-1] = POS(-1, -1); top[-1] = left[-1]; } if (cand_up) for (i = size - 1; i >= 0; i--) if (IS_INTRA(i, -1) || !s->pps->constrained_intra_pred_flag) top[i] = POS(i, -1); if (cand_up_right) { for (i = size + top_right_size; i < (size << 1); i++) if (IS_INTRA(size + top_right_size - 1, -1) || !s->pps->constrained_intra_pred_flag) top[i] = POS(size + top_right_size - 1, -1); for (i = size + top_right_size - 1; i >= size; i--) if (IS_INTRA(i, -1) || !s->pps->constrained_intra_pred_flag) top[i] = POS(i, -1); } if (s->pps->constrained_intra_pred_flag == 1) { if (cand_bottom_left || cand_left || cand_up_left || cand_up || cand_up_right) { int size_max_x = x0 + ((2 * size) << hshift) < s->sps->width ? 2 * size : (s->sps->width - x0) >> hshift; int size_max_y = y0 + ((2 * size) << vshift) < s->sps->height ? 2 * size : (s->sps->height - y0) >> vshift; int j = size + (cand_bottom_left? bottom_left_size: 0) -1; if (!cand_up_right) { size_max_x = x0 + ((size) << hshift) < s->sps->width ? size : (s->sps->width - x0) >> hshift; } if (!cand_bottom_left) { size_max_y = y0 + (( size) << vshift) < s->sps->height ? size : (s->sps->height - y0) >> vshift; }
static av_always_inline void FUNC(intra_pred)(HEVCContext *s, int x0, int y0, int log2_size, int c_idx) { #define PU(x) \ ((x) >> s->sps->log2_min_pu_size) #define MVF(x, y) \ (s->ref->tab_mvf[(x) + (y) * min_pu_width]) #define MVF_PU(x, y) \ MVF(PU(x0 + ((x) << hshift)), PU(y0 + ((y) << vshift))) #define IS_INTRA(x, y) \ (MVF_PU(x, y).pred_flag == PF_INTRA) #define MIN_TB_ADDR_ZS(x, y) \ s->pps->min_tb_addr_zs[(y) * s->sps->min_tb_width + (x)] #define EXTEND(ptr, val, len) \ do { \ pixel4 pix = PIXEL_SPLAT_X4(val); \ for (i = 0; i < (len); i += 4) \ AV_WN4P(ptr + i, pix); \ } while (0) #define EXTEND_RIGHT_CIP(ptr, start, length) \ for (i = start; i < (start) + (length); i += 4) \ if (!IS_INTRA(i, -1)) \ AV_WN4P(&ptr[i], a); \ else \ a = PIXEL_SPLAT_X4(ptr[i+3]) #define EXTEND_LEFT_CIP(ptr, start, length) \ for (i = start; i > (start) - (length); i--) \ if (!IS_INTRA(i - 1, -1)) \ ptr[i - 1] = ptr[i] #define EXTEND_UP_CIP(ptr, start, length) \ for (i = (start); i > (start) - (length); i -= 4) \ if (!IS_INTRA(-1, i - 3)) \ AV_WN4P(&ptr[i - 3], a); \ else \ a = PIXEL_SPLAT_X4(ptr[i - 3]) #define EXTEND_DOWN_CIP(ptr, start, length) \ for (i = start; i < (start) + (length); i += 4) \ if (!IS_INTRA(-1, i)) \ AV_WN4P(&ptr[i], a); \ else \ a = PIXEL_SPLAT_X4(ptr[i + 3]) HEVCLocalContext *lc = s->HEVClc; int i; int hshift = s->sps->hshift[c_idx]; int vshift = s->sps->vshift[c_idx]; int size = (1 << log2_size); int size_in_luma_h = size << hshift; int size_in_tbs_h = size_in_luma_h >> s->sps->log2_min_tb_size; int size_in_luma_v = size << vshift; int size_in_tbs_v = size_in_luma_v >> s->sps->log2_min_tb_size; int x = x0 >> hshift; int y = y0 >> vshift; int x_tb = x0 >> s->sps->log2_min_tb_size; int y_tb = y0 >> s->sps->log2_min_tb_size; int cur_tb_addr = MIN_TB_ADDR_ZS(x_tb, y_tb); ptrdiff_t stride = s->frame->linesize[c_idx] / sizeof(pixel); pixel *src = (pixel*)s->frame->data[c_idx] + x + y * stride; int min_pu_width = s->sps->min_pu_width; enum IntraPredMode mode = c_idx ? lc->tu.cur_intra_pred_mode_c : lc->tu.cur_intra_pred_mode; pixel4 a; pixel left_array[2 * MAX_TB_SIZE + 1]; pixel filtered_left_array[2 * MAX_TB_SIZE + 1]; pixel top_array[2 * MAX_TB_SIZE + 1]; pixel filtered_top_array[2 * MAX_TB_SIZE + 1]; pixel *left = left_array + 1; pixel *top = top_array + 1; pixel *filtered_left = filtered_left_array + 1; pixel *filtered_top = filtered_top_array + 1; int cand_bottom_left = lc->na.cand_bottom_left && cur_tb_addr > MIN_TB_ADDR_ZS(x_tb - 1, y_tb + size_in_tbs_v); int cand_left = lc->na.cand_left; int cand_up_left = lc->na.cand_up_left; int cand_up = lc->na.cand_up; int cand_up_right = lc->na.cand_up_right && cur_tb_addr > MIN_TB_ADDR_ZS(x_tb + size_in_tbs_h, y_tb - 1); int bottom_left_size = (FFMIN(y0 + 2 * size_in_luma_v, s->sps->height) - (y0 + size_in_luma_v)) >> vshift; int top_right_size = (FFMIN(x0 + 2 * size_in_luma_h, s->sps->width) - (x0 + size_in_luma_h)) >> hshift; if (s->pps->constrained_intra_pred_flag == 1) { int size_in_luma_pu_v = PU(size_in_luma_v); int size_in_luma_pu_h = PU(size_in_luma_h); int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1)); int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1)); if (!size_in_luma_pu_h) size_in_luma_pu_h++; if (cand_bottom_left == 1 && on_pu_edge_x) { int x_left_pu = PU(x0 - 1); int y_bottom_pu = PU(y0 + size_in_luma_v); int max = FFMIN(size_in_luma_pu_v, s->sps->min_pu_height - y_bottom_pu); cand_bottom_left = 0; for (i = 0; i < max; i += 2) cand_bottom_left |= (MVF(x_left_pu, y_bottom_pu + i).pred_flag == PF_INTRA); } if (cand_left == 1 && on_pu_edge_x) { int x_left_pu = PU(x0 - 1); int y_left_pu = PU(y0); int max = FFMIN(size_in_luma_pu_v, s->sps->min_pu_height - y_left_pu); cand_left = 0; for (i = 0; i < max; i += 2) cand_left |= (MVF(x_left_pu, y_left_pu + i).pred_flag == PF_INTRA); } if (cand_up_left == 1) { int x_left_pu = PU(x0 - 1); int y_top_pu = PU(y0 - 1); cand_up_left = MVF(x_left_pu, y_top_pu).pred_flag == PF_INTRA; } if (cand_up == 1 && on_pu_edge_y) { int x_top_pu = PU(x0); int y_top_pu = PU(y0 - 1); int max = FFMIN(size_in_luma_pu_h, s->sps->min_pu_width - x_top_pu); cand_up = 0; for (i = 0; i < max; i += 2) cand_up |= (MVF(x_top_pu + i, y_top_pu).pred_flag == PF_INTRA); } if (cand_up_right == 1 && on_pu_edge_y) { int y_top_pu = PU(y0 - 1); int x_right_pu = PU(x0 + size_in_luma_h); int max = FFMIN(size_in_luma_pu_h, s->sps->min_pu_width - x_right_pu); cand_up_right = 0; for (i = 0; i < max; i += 2) cand_up_right |= (MVF(x_right_pu + i, y_top_pu).pred_flag == PF_INTRA); } memset(left, 128, 2 * MAX_TB_SIZE*sizeof(pixel)); memset(top , 128, 2 * MAX_TB_SIZE*sizeof(pixel)); top[-1] = 128; } if (cand_up_left) { left[-1] = POS(-1, -1); top[-1] = left[-1]; } if (cand_up) memcpy(top, src - stride, size * sizeof(pixel)); if (cand_up_right) { memcpy(top + size, src - stride + size, size * sizeof(pixel)); EXTEND(top + size + top_right_size, POS(size + top_right_size - 1, -1), size - top_right_size); } if (cand_left) for (i = 0; i < size; i++) left[i] = POS(-1, i); if (cand_bottom_left) { for (i = size; i < size + bottom_left_size; i++) left[i] = POS(-1, i); EXTEND(left + size + bottom_left_size, POS(-1, size + bottom_left_size - 1), size - bottom_left_size); } if (s->pps->constrained_intra_pred_flag == 1) { if (cand_bottom_left || cand_left || cand_up_left || cand_up || cand_up_right) { int size_max_x = x0 + ((2 * size) << hshift) < s->sps->width ? 2 * size : (s->sps->width - x0) >> hshift; int size_max_y = y0 + ((2 * size) << vshift) < s->sps->height ? 2 * size : (s->sps->height - y0) >> vshift; int j = size + (cand_bottom_left? bottom_left_size: 0) -1; if (!cand_up_right) { size_max_x = x0 + ((size) << hshift) < s->sps->width ? size : (s->sps->width - x0) >> hshift; } if (!cand_bottom_left) { size_max_y = y0 + (( size) << vshift) < s->sps->height ? size : (s->sps->height - y0) >> vshift; }
void ParametricSurface<Real>::ComputePrincipalCurvatureInfo (Real u, Real v, Real& curv0, Real& curv1, Vector3<Real>& dir0, Vector3<Real>& dir1) { // Tangents: T0 = (x_u,y_u,z_u), T1 = (x_v,y_v,z_v) // Normal: N = Cross(T0,T1)/Length(Cross(T0,T1)) // Metric Tensor: G = +- -+ // | Dot(T0,T0) Dot(T0,T1) | // | Dot(T1,T0) Dot(T1,T1) | // +- -+ // // Curvature Tensor: B = +- -+ // | -Dot(N,T0_u) -Dot(N,T0_v) | // | -Dot(N,T1_u) -Dot(N,T1_v) | // +- -+ // // Principal curvatures k are the generalized eigenvalues of // // Bw = kGw // // If k is a curvature and w=(a,b) is the corresponding solution to // Bw = kGw, then the principal direction as a 3D vector is d = a*U+b*V. // // Let k1 and k2 be the principal curvatures. The mean curvature // is (k1+k2)/2 and the Gaussian curvature is k1*k2. // Compute derivatives. Vector3<Real> derU = PU(u,v); Vector3<Real> derV = PV(u,v); Vector3<Real> derUU = PUU(u,v); Vector3<Real> derUV = PUV(u,v); Vector3<Real> derVV = PVV(u,v); // Compute the metric tensor. Matrix2<Real> metricTensor; metricTensor[0][0] = derU.Dot(derU); metricTensor[0][1] = derU.Dot(derV); metricTensor[1][0] = metricTensor[0][1]; metricTensor[1][1] = derV.Dot(derV); // Compute the curvature tensor. Vector3<Real> normal = derU.UnitCross(derV); Matrix2<Real> curvatureTensor; curvatureTensor[0][0] = -normal.Dot(derUU); curvatureTensor[0][1] = -normal.Dot(derUV); curvatureTensor[1][0] = curvatureTensor[0][1]; curvatureTensor[1][1] = -normal.Dot(derVV); // Characteristic polynomial is 0 = det(B-kG) = c2*k^2+c1*k+c0. Real c0 = curvatureTensor.Determinant(); Real c1 = ((Real)2)*curvatureTensor[0][1]* metricTensor[0][1] - curvatureTensor[0][0]*metricTensor[1][1] - curvatureTensor[1][1]*metricTensor[0][0]; Real c2 = metricTensor.Determinant(); // Principal curvatures are roots of characteristic polynomial. Real temp = Math<Real>::Sqrt(Math<Real>::FAbs(c1*c1 - ((Real)4)*c0*c2)); Real mult = ((Real)0.5)/c2; curv0 = -mult*(c1+temp); curv1 = mult*(-c1+temp); // Principal directions are solutions to (B-kG)w = 0, // w1 = (b12-k1*g12,-(b11-k1*g11)) OR (b22-k1*g22,-(b12-k1*g12)). Real a0 = curvatureTensor[0][1] - curv0*metricTensor[0][1]; Real a1 = curv0*metricTensor[0][0] - curvatureTensor[0][0]; Real length = Math<Real>::Sqrt(a0*a0 + a1*a1); if (length >= Math<Real>::ZERO_TOLERANCE) { dir0 = a0*derU + a1*derV; } else { a0 = curvatureTensor[1][1] - curv0*metricTensor[1][1]; a1 = curv0*metricTensor[0][1] - curvatureTensor[0][1]; length = Math<Real>::Sqrt(a0*a0 + a1*a1); if (length >= Math<Real>::ZERO_TOLERANCE) { dir0 = a0*derU + a1*derV; } else { // Umbilic (surface is locally sphere, any direction principal). dir0 = derU; } } dir0.Normalize(); // Second tangent is cross product of first tangent and normal. dir1 = dir0.Cross(normal); }
// WARNING: you must ensure that bins_count is big enough inline static void histogram_helper_cs_RAW_helper_process_pixel_uint16( const dt_dev_histogram_collection_params_t *const histogram_params, const uint16_t *pixel, uint32_t *histogram) { const uint16_t i = PU(*pixel, histogram_params); histogram[4 * i]++; }