//////////////////////////////////////////////////////////////////////////////// // Helper functions //////////////////////////////////////////////////////////////////////////////// int snapTransformSize(int dataSize) { int hiBit; unsigned int lowPOT, hiPOT; dataSize = iAlignUp(dataSize, 16); for (hiBit = 31; hiBit >= 0; hiBit--) if (dataSize & (1U << hiBit)) { break; } lowPOT = 1U << hiBit; if (lowPOT == (unsigned int)dataSize) { return dataSize; } hiPOT = 1U << (hiBit + 1); if (hiPOT <= 1024) { return hiPOT; } else { return iAlignUp(dataSize, 512); } }
/////////////////////////////////////////////////////////////////////////////// /// \brief /// load 4-channel unsigned byte image /// and convert it to single channel FP32 image /// \param[out] img_data pointer to raw image data /// \param[out] img_w image width /// \param[out] img_h image height /// \param[out] img_s image row stride /// \param[in] name image file name /// \param[in] exePath executable file path /// \return true if image is successfully loaded or false otherwise /////////////////////////////////////////////////////////////////////////////// bool LoadImageAsFP32(float *&img_data, int &img_w, int &img_h, int &img_s, const char *name, const char *exePath) { printf("Loading \"%s\" ...\n", name); char *name_ = sdkFindFilePath(name, exePath); if (!name_) { printf("File not found\n"); return false; } unsigned char *data = 0; unsigned int w = 0, h = 0; bool result = sdkLoadPPM4ub(name_, &data, &w, &h); if (result == false) { printf("Invalid file format\n"); return false; } img_w = w; img_h = h; img_s = iAlignUp(img_w); img_data = new float [img_s * h]; // source is 4 channel image const int widthStep = 4 * img_w; for (int i = 0; i < img_h; ++i) { for (int j = 0; j < img_w; ++j) { img_data[j + i * img_s] = ((float) data[j * 4 + i * widthStep]) / 255.0f; } } return true; }