int litehtml::document::cvt_units(css_length& val, int fontSize) const { if (val.is_predefined() || !val.is_predefined() && val.units() == css_units_percentage) { return 0; } int ret = 0; switch (val.units()) { case css_units_px: ret = (int) val.val(); break; case css_units_em: ret = round_f(val.val() * fontSize); val.set_value((float) ret, css_units_px); break; case css_units_pt: ret = m_container->pt_to_px((int) val.val()); val.set_value((float) ret, css_units_px); break; case css_units_in: ret = m_container->pt_to_px((int) (val.val() * 72)); val.set_value((float) ret, css_units_px); break; case css_units_cm: ret = m_container->pt_to_px((int) (val.val() * 0.3937 * 72)); val.set_value((float) ret, css_units_px); break; case css_units_mm: ret = m_container->pt_to_px((int) (val.val() * 0.3937 * 72) / 10); val.set_value((float) ret, css_units_px); break; } return ret; }
void litehtml::table_grid::distribute_width( int width, int start, int end, table_column_accessor* acc ) { if(!(start >= 0 && start < m_cols_count && end >= 0 && end < m_cols_count)) { return; } int cols_width = 0; for(int col = start; col <= end; col++) { cols_width += m_columns[col].max_width; } int add = width / (end - start + 1); int added_width = 0; for(int col = start; col <= end; col++) { if(cols_width) { add = round_f( (float) width * ((float) m_columns[col].max_width / (float) cols_width) ); } added_width += add; acc->get(m_columns[col]) += add; } if(added_width < width) { acc->get(m_columns[start]) += width - added_width; } }
/** ************************************************************************** * Copies float plane to byte plane (with clamp) * * \param ImgSrc [IN] - Source float plane * \param StrideF [IN] - Source plane stride * \param ImgDst [OUT] - Destination byte plane * \param StrideB [IN] - Destination plane stride * \param Size [IN] - Size of area to copy * * \return None */ void CopyFloat2Byte(float *ImgSrc, int StrideF, byte *ImgDst, int StrideB, ROI Size) { for (int i=0; i<Size.height; i++) { for (int j=0; j<Size.width; j++) { ImgDst[i*StrideB+j] = (byte)clamp_0_255((int)(round_f(ImgSrc[i*StrideF+j]))); } } }
int main() { float f; int d; printf("Enter the float: "); scanf("%f",&f); printf("Enter the place of decimal to round off: "); scanf("%d",&d); printf("Ans: %.*f \n",d,round_f(f,d)); return 0; }
/** ************************************************************************** * Performs in-place quantization of given coefficients plane using * predefined quantization matrices (float elements) * * \param fSrcDst [IN/OUT] - Coefficients plane * \param Stride [IN] - Stride of SrcDst * \param Size [IN] - Size of the plane * * \return None */ void quantizeGoldFloat(float* fSrcDst, int Stride, ROI Size) { //perform block wise in-place quantization using Q //Q(A) = round(A ./ Q) .* Q; for (int i=0; i<Size.height; i++) { for (int j=0; j<Size.width; j++) { int qx = j % BLOCK_SIZE; int qy = i % BLOCK_SIZE; float quantized = round_f(fSrcDst[i*Stride+j] / Q[(qy<<BLOCK_SIZE_LOG2)+qx]); fSrcDst[i*Stride+j] = quantized * Q[(qy<<BLOCK_SIZE_LOG2)+qx]; } } }
HRESULT convert_to_int16(enum AVSampleFormat avsf, WORD nChannels, DWORD nSamples, BYTE* pIn, int16_t* pOut) { size_t allsamples = nSamples * nChannels; switch (avsf) { case AV_SAMPLE_FMT_U8: for (size_t i = 0; i < allsamples; ++i) { *pOut++ = (int16_t)(*(int8_t*)pIn ^ 0x80) << 8; pIn += sizeof(uint8_t); } break; case AV_SAMPLE_FMT_S16: memcpy(pOut, pIn, allsamples * sizeof(int16_t)); break; case AV_SAMPLE_FMT_S32: for (size_t i = 0; i < allsamples; ++i) { *pOut++ = *(int16_t*)(pIn + sizeof(int16_t)); // read the high bits only pIn += sizeof(int32_t); } break; case AV_SAMPLE_FMT_FLT: for (size_t i = 0; i < allsamples; ++i) { float f = *(float*)pIn; limit(-1, f, F16MAX); *pOut++ = (int16_t)round_f(f * INT16_PEAK); pIn += sizeof(float); } break; case AV_SAMPLE_FMT_DBL: for (size_t i = 0; i < allsamples; ++i) { float f = (float) * (double*)pIn; limit(-1, f, F16MAX); *pOut++ = (int16_t)round_f(f * INT16_PEAK); pIn += sizeof(double); } break; // planar case AV_SAMPLE_FMT_U8P: for (size_t i = 0; i < nSamples; ++i) { for (int ch = 0; ch < nChannels; ++ch) { int8_t b = ((int8_t*)pIn)[nSamples * ch + i]; *pOut++ = (int16_t)(b ^ 0x80) << 8; } } break; case AV_SAMPLE_FMT_S16P: for (size_t i = 0; i < nSamples; ++i) { for (int ch = 0; ch < nChannels; ++ch) { *pOut++ = ((int16_t*)pIn)[nSamples * ch + i]; } } break; case AV_SAMPLE_FMT_S32P: for (size_t i = 0; i < nSamples; ++i) { for (int ch = 0; ch < nChannels; ++ch) { *pOut++ = *(int16_t*)(pIn + (nSamples * ch + i) * sizeof(int32_t) + sizeof(int16_t)); // read the high bits only } } break; case AV_SAMPLE_FMT_FLTP: for (size_t i = 0; i < nSamples; ++i) { for (int ch = 0; ch < nChannels; ++ch) { float f = ((float*)pIn)[nSamples * ch + i]; limit(-1, f, F16MAX); *pOut++ = (int16_t)round_f(f * INT16_PEAK); } } break; case AV_SAMPLE_FMT_DBLP: for (size_t i = 0; i < nSamples; ++i) { for (int ch = 0; ch < nChannels; ++ch) { float f = (float)((double*)pIn)[nSamples * ch + i]; limit(-1, f, F16MAX); *pOut++ = (int16_t)round_f(f * INT16_PEAK); } } break; default: return E_INVALIDARG; } return S_OK; }
int round_d(double x){ return round_f((float)x); }
void litehtml::table_grid::distribute_width( int width, int start, int end ) { if(!(start >= 0 && start < m_cols_count && end >= 0 && end < m_cols_count)) { return; } std::vector<table_column*> distribute_columns; for(int step = 0; step < 3; step++) { distribute_columns.clear(); switch(step) { case 0: { // distribute between the columns with width == auto for(int col = start; col <= end; col++) { if(m_columns[col].css_width.is_predefined()) { distribute_columns.push_back(&m_columns[col]); } } } break; case 1: { // distribute between the columns with percents for(int col = start; col <= end; col++) { if(!m_columns[col].css_width.is_predefined() && m_columns[col].css_width.units() == css_units_percentage) { distribute_columns.push_back(&m_columns[col]); } } } break; case 2: { //well distribute between all columns for(int col = start; col <= end; col++) { distribute_columns.push_back(&m_columns[col]); } } break; } int added_width = 0; if(!distribute_columns.empty() || step == 2) { int cols_width = 0; for(std::vector<table_column*>::iterator col = distribute_columns.begin(); col != distribute_columns.end(); col++) { cols_width += (*col)->max_width - (*col)->min_width; } if(cols_width) { int add = width / (int) distribute_columns.size(); for(std::vector<table_column*>::iterator col = distribute_columns.begin(); col != distribute_columns.end(); col++) { add = round_f( (float) width * ((float) ((*col)->max_width - (*col)->min_width) / (float) cols_width) ); if((*col)->width + add >= (*col)->min_width) { (*col)->width += add; added_width += add; } else { added_width += ((*col)->width - (*col)->min_width) * (add / abs(add)); (*col)->width = (*col)->min_width; } } if(added_width < width && step) { distribute_columns.front()->width += width - added_width; added_width = width; } } else { distribute_columns.back()->width += width; added_width = width; } } if(added_width == width) { break; } else { width -= added_width; } } }