int CVxParamRemap::Finalize() { if (m_useSyncOpenCLWriteDirective) { ERROR_CHECK_AND_WARN(vxDirective((vx_reference)m_remap, VX_DIRECTIVE_AMD_COPY_TO_OPENCL), VX_ERROR_NOT_ALLOCATED); } return 0; }
int CVxParamTensor::Finalize() { // process user requested directives if (m_useSyncOpenCLWriteDirective) { ERROR_CHECK_AND_WARN(vxDirective((vx_reference)m_tensor, VX_DIRECTIVE_AMD_COPY_TO_OPENCL), VX_ERROR_NOT_ALLOCATED); } return 0; }
int CVxParamArray::Finalize() { // get attributes ERROR_CHECK(vxQueryArray(m_array, VX_ARRAY_ATTRIBUTE_ITEMSIZE, &m_itemSize, sizeof(m_itemSize))); ERROR_CHECK(vxQueryArray(m_array, VX_ARRAY_ATTRIBUTE_CAPACITY, &m_capacity, sizeof(m_capacity))); // process user requested directives if (m_useSyncOpenCLWriteDirective) { ERROR_CHECK_AND_WARN(vxDirective((vx_reference)m_array, VX_DIRECTIVE_AMD_COPY_TO_OPENCL), VX_ERROR_NOT_ALLOCATED); } return 0; }
int CVxParamTensor::ReadFrame(int frameNumber) { // check if there is no user request to read if (m_fileNameRead.length() < 1) return 0; // for single frame reads, there is no need to read the array again // as it is already read into the object if (!m_fileNameForReadHasIndex && frameNumber != m_captureFrameStart) { return 0; } // reading data from input file char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameRead.c_str(), frameNumber); if(!_stricmp(fileName + strlen(fileName) - 4, ".dat")) { ReportError("ERROR: read from .dat files not supported: %s\n", fileName); } FILE * fp = fopen(fileName, m_readFileIsBinary ? "rb" : "r"); if (!fp) { if (frameNumber == m_captureFrameStart) { ReportError("ERROR: Unable to open: %s\n", fileName); } else { return 1; // end of sequence detected for multiframe sequences } } if (fread(m_data, 1, m_size, fp) != m_size) ReportError("ERROR: not enough data (%d bytes) in %s\n", (vx_uint32)m_size, fileName); vx_status status = vxCopyTensorPatch(m_tensor, m_num_of_dims, nullptr, nullptr, m_stride, m_data, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST); fclose(fp); if (status != VX_SUCCESS) ReportError("ERROR: vxCopyTensorPatch: write failed (%d)\n", status); // process user requested directives if (m_useSyncOpenCLWriteDirective) { ERROR_CHECK_AND_WARN(vxDirective((vx_reference)m_tensor, VX_DIRECTIVE_AMD_COPY_TO_OPENCL), VX_ERROR_NOT_ALLOCATED); } return 0; }
int CVxParamArray::ReadFrame(int frameNumber) { // check if user specified input file to read from if (m_fileNameRead.length() < 1) return 0; // for single frame reads, there is no need to read the array again // as it is already read into the object if (!m_fileNameForReadHasIndex && frameNumber != m_captureFrameStart) { return 0; } // reading data from input file char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameRead.c_str(), frameNumber); FILE * fp = fopen(fileName, m_readFileIsBinary ? "rb" : "r"); if(!fp) { if (frameNumber >= (int)m_captureFrameStart) { // end of sequence detected for multiframe sequences return 1; } else ReportError("ERROR: Unable to open: %s\n", fileName); } size_t numItems = ReadFileIntoBuffer(fp, m_readFileIsBinary); fclose(fp); // set array size to numItems and write the data into array object ERROR_CHECK(vxTruncateArray(m_array, 0)); if (numItems > 0) { ERROR_CHECK(vxAddArrayItems(m_array, numItems, m_bufForRead, m_itemSize)); } // process user requested directives if (m_useSyncOpenCLWriteDirective) { ERROR_CHECK_AND_WARN(vxDirective((vx_reference)m_array, VX_DIRECTIVE_AMD_COPY_TO_OPENCL), VX_ERROR_NOT_ALLOCATED); } return 0; }
int CVxParamRemap::ReadFrame(int frameNumber) { if (m_fileNameRead.length() < 1) return 0; if (!m_usingMultiFrameCapture && frameNumber != m_captureFrameStart) { // for single frame reads, there is no need to read the array again // as it is already read into the object return 0; } // read from user specified file char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameRead.c_str(), frameNumber); FILE * fp = fopen(fileName, m_readFileIsBinary ? "rb" : "r"); if (!fp) ReportError("ERROR: unable to open: %s\n", fileName); for (vx_uint32 y = 0; y < m_dstHeight; y++){ for (vx_uint32 x = 0; x < m_dstWidth; x++){ vx_float32 src_xy[2]; if (m_readFileIsBinary) { if (fread(src_xy, sizeof(src_xy), 1, fp) != 1) ReportError("ERROR: detected EOF at (%d,%d) on remap input file: %s\n", x, y, fileName); } else { if (fscanf(fp, "%g%g", &src_xy[0], &src_xy[1]) != 2) ReportError("ERROR: detected EOF at (%d,%d) on remap input file: %s (ASCII)\n", x, y, fileName); } ERROR_CHECK(vxSetRemapPoint(m_remap, x, y, src_xy[0], src_xy[1])); } } fclose(fp); if (m_useSyncOpenCLWriteDirective) { ERROR_CHECK_AND_WARN(vxDirective((vx_reference)m_remap, VX_DIRECTIVE_AMD_COPY_TO_OPENCL), VX_ERROR_NOT_ALLOCATED); } return 0; }
int CVxParamMatrix::InitializeIO(vx_context context, vx_graph graph, vx_reference ref, const char * io_params) { // save reference object and get object attributes m_vxObjRef = ref; m_matrix = (vx_matrix)m_vxObjRef; ERROR_CHECK(vxQueryMatrix(m_matrix, VX_MATRIX_ATTRIBUTE_TYPE, &m_data_type, sizeof(m_data_type))); ERROR_CHECK(vxQueryMatrix(m_matrix, VX_MATRIX_ATTRIBUTE_COLUMNS, &m_columns, sizeof(m_columns))); ERROR_CHECK(vxQueryMatrix(m_matrix, VX_MATRIX_ATTRIBUTE_ROWS, &m_rows, sizeof(m_rows))); ERROR_CHECK(vxQueryMatrix(m_matrix, VX_MATRIX_ATTRIBUTE_SIZE, &m_size, sizeof(m_size))); // process I/O parameters if (*io_params == ':') io_params++; while (*io_params) { char ioType[64], fileName[256]; io_params = ScanParameters(io_params, "<io-operation>,<parameter>", "s,S", ioType, fileName); if (!_stricmp(ioType, "read")) { // read request syntax: read,<fileName>[,ascii|binary] m_fileNameRead.assign(RootDirUpdated(fileName)); m_fileNameForReadHasIndex = (m_fileNameRead.find("%") != m_fileNameRead.npos) ? true : false; m_readFileIsBinary = (m_fileNameRead.find(".txt") != m_fileNameRead.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_readFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_readFileIsBinary = true; } else ReportError("ERROR: invalid matrix read option: %s\n", option); } } else if (!_stricmp(ioType, "write")) { // write request syntax: write,<fileName>[,ascii|binary] m_fileNameWrite.assign(RootDirUpdated(fileName)); m_writeFileIsBinary = (m_fileNameWrite.find(".txt") != m_fileNameWrite.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_writeFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_writeFileIsBinary = true; } else ReportError("ERROR: invalid matrix write option: %s\n", option); } } else if (!_stricmp(ioType, "compare")) { // compare request syntax: compare,<fileName>[,ascii|binary][,err{<tolerance>}] m_fileNameCompare.assign(RootDirUpdated(fileName)); m_compareFileIsBinary = (m_fileNameCompare.find(".txt") != m_fileNameCompare.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary|err{<tolerance>}", ",s", option); if (!_stricmp(option, "ascii")) { m_compareFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_compareFileIsBinary = true; } else if (!_strnicmp(option, "err{", 4)) { ScanParameters(&option[3], "{<tolerance>}", "{f}", &m_errTolerance); } else ReportError("ERROR: invalid matrix compare option: %s\n", option); } } else if (!_stricmp(ioType, "init")) { // write request syntax: init,{<value1>;<value2>;...<valueN>} NULLPTR_CHECK(m_bufForAccess = new vx_uint8[m_size]); vx_size index = 0; char fmt[3] = { '{', (m_data_type == VX_TYPE_FLOAT32) ? 'f' : 'd', 0 }; for (const char * s = fileName; *s && index < (m_columns * m_rows); fmt[0] = ';', index++) { if (m_data_type == VX_TYPE_INT32 || m_data_type == VX_TYPE_UINT8) { vx_uint32 value; s = ScanParameters(s, "<value>", fmt, &value); if (m_data_type == VX_TYPE_UINT8) ((vx_uint8 *)m_bufForAccess)[index] = (vx_uint8)value; else ((vx_int32 *)m_bufForAccess)[index] = value; } else if (m_data_type == VX_TYPE_FLOAT32) { s = ScanParameters(s, "<value>", fmt, &((vx_float32 *)m_bufForAccess)[index]); } else ReportError("ERROR: matrix init option not support for data_type of %s\n", GetVxObjectName()); } if (index < (m_columns * m_rows)) ReportError("ERROR: matrix init have too few values: %s\n", fileName); ERROR_CHECK(vxWriteMatrix(m_matrix, m_bufForAccess)); } else if (!_stricmp(ioType, "directive") && !_stricmp(fileName, "readonly")) { ERROR_CHECK(vxDirective((vx_reference)m_matrix, VX_DIRECTIVE_AMD_READ_ONLY)); } else if (!_stricmp(ioType, "ui") && !_strnicmp(fileName, "f", 1) && m_data_type == VX_TYPE_FLOAT32 && m_columns == 3 && m_rows == 3) { int id = 0; float valueR = 200.0f, valueInc = 0.5f; if (sscanf(&fileName[1], "%d,%g,%g", &id, &valueR, &valueInc) != 3) { printf("ERROR: invalid matrix UI configuration '%s'\n", fileName); return -1; } id--; GuiTrackBarInitializeMatrix((vx_reference)m_matrix, id, valueR, valueInc); GuiTrackBarProcessKey(0); // just initialize the matrix } else ReportError("ERROR: invalid matrix operation: %s\n", ioType); if (*io_params == ':') io_params++; else if (*io_params) ReportError("ERROR: unexpected character sequence in parameter specification: %s\n", io_params); } return 0; }