@@ -126,6 +126,12 @@ namespace
126
126
void Update () noexcept (false )
127
127
{
128
128
png_read_info (st, info);
129
+ // check for unsupported cases
130
+ png_byte interlacing = png_get_interlace_type (st, info);
131
+ if (interlacing != PNG_INTERLACE_NONE)
132
+ {
133
+ throw std::invalid_argument{ " interlacing not supported" };
134
+ }
129
135
// color handling
130
136
png_byte color_type = png_get_color_type (st, info);
131
137
if (color_type == PNG_COLOR_TYPE_GRAY)
@@ -185,6 +191,7 @@ namespace
185
191
// / @todo More correct DXGI_FORMAT mapping
186
192
void GetHeader (TexMetadata& metadata) noexcept (false )
187
193
{
194
+ metadata = {};
188
195
metadata.width = png_get_image_width (st, info);
189
196
metadata.height = png_get_image_height (st, info);
190
197
metadata.arraySize = 1 ;
@@ -194,7 +201,7 @@ namespace
194
201
metadata.format = GuessFormat ();
195
202
png_byte color_type = png_get_color_type (st, info);
196
203
bool have_alpha = (color_type & PNG_COLOR_MASK_ALPHA);
197
- if (have_alpha == false )
204
+ if (have_alpha == false && (metadata. format != DXGI_FORMAT_R8_UNORM) )
198
205
metadata.miscFlags2 |= TEX_ALPHA_MODE_OPAQUE;
199
206
}
200
207
@@ -266,6 +273,7 @@ namespace
266
273
{
267
274
case DXGI_FORMAT_R8_UNORM:
268
275
color_type = PNG_COLOR_TYPE_GRAY;
276
+ channel = 1 ;
269
277
break ;
270
278
case DXGI_FORMAT_B8G8R8A8_UNORM:
271
279
case DXGI_FORMAT_B8G8R8X8_UNORM:
@@ -275,7 +283,7 @@ namespace
275
283
color_type = PNG_COLOR_TYPE_RGBA;
276
284
break ;
277
285
default :
278
- return E_INVALIDARG ;
286
+ return HRESULT_E_NOT_SUPPORTED ;
279
287
}
280
288
281
289
png_set_IHDR (st, info,
@@ -332,6 +340,10 @@ HRESULT DirectX::GetMetadataFromPNGFile(
332
340
return (ec.code ().value () == ENOENT) ? HRESULT_ERROR_FILE_NOT_FOUND : E_FAIL;
333
341
#endif
334
342
}
343
+ catch (const std::invalid_argument&)
344
+ {
345
+ return HRESULT_E_NOT_SUPPORTED;
346
+ }
335
347
catch (const std::exception &)
336
348
{
337
349
return E_FAIL;
@@ -373,6 +385,10 @@ HRESULT DirectX::LoadFromPNGFile(
373
385
return (ec.code ().value () == ENOENT) ? HRESULT_ERROR_FILE_NOT_FOUND : E_FAIL;
374
386
#endif
375
387
}
388
+ catch (const std::invalid_argument&)
389
+ {
390
+ return HRESULT_E_NOT_SUPPORTED;
391
+ }
376
392
catch (const std::exception &)
377
393
{
378
394
image.Release ();
0 commit comments