MCPcopy Create free account
hub / github.com/Autodesk/Aurora / _OpenAsset

Method _OpenAsset

Libraries/ImageProcessingResolver/Resolver.cpp:165–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163ImageProcessingResolverPlugin::~ImageProcessingResolverPlugin() {}
164
165std::shared_ptr<ArAsset> ImageProcessingResolverPlugin::_OpenAsset(
166 const ArResolvedPath& resolvedPath) const
167{
168 // Get string for path.
169 std::string pathStr = resolvedPath.GetPathString();
170
171 // Is the path an encoded URI path?
172 if (pathStr.find(assetPathPrefix) != std::string::npos)
173 {
174 // Get the cacheEntry for this URI.
175 AssetCacheEntry& cacheEntry =
176 const_cast<ImageProcessingResolverPlugin*>(this)->_assetCache[pathStr];
177
178 // If we do not have an asset cached, create one.
179 if (!cacheEntry.pAsset)
180 {
181
182 // Use the Hio image function to read the source image.
183 pxr::HioImageSharedPtr const image =
184 pxr::HioImage::OpenForReading(cacheEntry.sourceFilename);
185
186 // If image load failed, return null asset.
187 if (!image)
188 {
189 return nullptr;
190 }
191
192 // Create a temp buffer for the source image pixels.
193 // NOTE: Multiplying int values may exceed INT_MAX. Cast to size_t for security.
194 size_t sizeInBytes = static_cast<size_t>(image->GetWidth()) *
195 static_cast<size_t>(image->GetHeight()) *
196 static_cast<size_t>(image->GetBytesPerPixel());
197 std::vector<unsigned char> tempBuf(sizeInBytes);
198 // Read the source image into the temp buffer.
199 pxr::HioImage::StorageSpec imageData;
200 imageData.width = image->GetWidth();
201 imageData.height = image->GetHeight();
202 imageData.depth = 1;
203 imageData.flipped = false;
204 imageData.format = image->GetFormat();
205 imageData.data = tempBuf.data();
206 image->Read(imageData);
207
208 // Get the maxDim query parameter, default to 16k if not specified.
209 int maxDim = 16 * 1024;
210 cacheEntry.getQuery("maxDim", &maxDim);
211
212 // If the input image's dimensions are larger than maxDim shrink it, keeping the aspect
213 // ratio the same.
214 if (imageData.width > imageData.height)
215 {
216 if (imageData.width > maxDim)
217 {
218 int newWidth = maxDim;
219 float sizeRatio = float(maxDim) / float(imageData.width);
220 int newHeight = int(imageData.height * sizeRatio);
221 shrinkImage(imageData, tempBuf, newWidth, newHeight);
222 }

Callers

nothing calls this directly

Calls 13

shrinkImageFunction · 0.85
linearizeFunction · 0.85
convertEnvMapLayoutFunction · 0.85
convertToOIIODataTypeFunction · 0.85
convertToFloatFunction · 0.85
GetWidthMethod · 0.80
GetHeightMethod · 0.80
GetFormatMethod · 0.80
ReadMethod · 0.80
getQueryMethod · 0.80
dataMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected