Skip to content

Commit cfd603a

Browse files
Image: fixed non-const src data pointers
1 parent 06da4cd commit cfd603a

File tree

9 files changed

+59
-55
lines changed

9 files changed

+59
-55
lines changed

TextureLoader/interface/Image.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct Image : public ObjectBase<IObject>
125125
/// \param [in] LoadInfo - Image loading information
126126
/// \param [out] ppImage - Memory location where pointer to the created image is written.
127127
/// The image should be released via Release().
128-
static void CreateFromDataBlob(IDataBlob* pFileData,
128+
static void CreateFromDataBlob(const IDataBlob* pFileData,
129129
const ImageLoadInfo& LoadInfo,
130130
Image** ppImage);
131131

@@ -176,14 +176,14 @@ struct Image : public ObjectBase<IObject>
176176
friend class MakeNewRCObj;
177177

178178
Image(IReferenceCounters* pRefCounters,
179-
IDataBlob* pFileData,
179+
const IDataBlob* pFileData,
180180
const ImageLoadInfo& LoadInfo);
181181

182182
Image(IReferenceCounters* pRefCounters,
183183
const ImageDesc& Desc,
184184
IDataBlob* pPixels);
185185

186-
void LoadTiffFile(IDataBlob* pFileData, const ImageLoadInfo& LoadInfo);
186+
void LoadTiffFile(const IDataBlob* pFileData, const ImageLoadInfo& LoadInfo);
187187

188188
ImageDesc m_Desc;
189189
RefCntAutoPtr<IDataBlob> m_pData;

TextureLoader/interface/JPEGCodec.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -69,9 +69,9 @@ DILIGENT_TYPED_ENUM(ENCODE_JPEG_RESULT, Uint32)
6969
/// (for instance, components of 3-channel image will be written as |r|g|b|r|g|b|r|g|b|...).
7070
/// \param [out] pDstImgDesc - Decoded image description.
7171
/// \return Decoding result, see Diligent::DECODE_JPEG_RESULT.
72-
DECODE_JPEG_RESULT DILIGENT_GLOBAL_FUNCTION(DecodeJpeg)(IDataBlob* pSrcJpegBits,
73-
IDataBlob* pDstPixels,
74-
ImageDesc* pDstImgDesc);
72+
DECODE_JPEG_RESULT DILIGENT_GLOBAL_FUNCTION(DecodeJpeg)(const IDataBlob* pSrcJpegBits,
73+
IDataBlob* pDstPixels,
74+
ImageDesc* pDstImgDesc);
7575

7676

7777
/// Encodes an image jpeg PNG format.

TextureLoader/interface/PNGCodec.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -75,9 +75,9 @@ DILIGENT_TYPED_ENUM(ENCODE_PNG_RESULT, Uint32)
7575
/// (for instance, components of 3-channel image will be written as |r|g|b|r|g|b|r|g|b|...).
7676
/// \param [out] pDstImgDesc - Decoded image description.
7777
/// \return Decoding result, see Diligent::DECODE_PNG_RESULT.
78-
DECODE_PNG_RESULT DILIGENT_GLOBAL_FUNCTION(DecodePng)(IDataBlob* pSrcPngBits,
79-
IDataBlob* pDstPixels,
80-
ImageDesc* pDstImgDesc);
78+
DECODE_PNG_RESULT DILIGENT_GLOBAL_FUNCTION(DecodePng)(const IDataBlob* pSrcPngBits,
79+
IDataBlob* pDstPixels,
80+
ImageDesc* pDstImgDesc);
8181

8282
/// Encodes an image into PNG format.
8383

TextureLoader/interface/SGILoader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,8 +35,8 @@ DILIGENT_BEGIN_NAMESPACE(Diligent)
3535
/// (for instance, components of a 3-channel image will be written as |r|g|b|r|g|b|r|g|b|...).
3636
/// \param [out] pDstImgDesc - Image description.
3737
/// \return true if the image has been loaded successfully, and false otherwise.
38-
bool DILIGENT_GLOBAL_FUNCTION(LoadSGI)(IDataBlob* pSGIData,
39-
IDataBlob* pDstPixels,
40-
ImageDesc* pDstImgDesc);
38+
bool DILIGENT_GLOBAL_FUNCTION(LoadSGI)(const IDataBlob* pSGIData,
39+
IDataBlob* pDstPixels,
40+
ImageDesc* pDstImgDesc);
4141

4242
DILIGENT_END_NAMESPACE // namespace Diligent

TextureLoader/src/Image.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace Diligent
6868
class TIFFClientOpenWrapper
6969
{
7070
public:
71-
explicit TIFFClientOpenWrapper(IDataBlob* pData) noexcept :
71+
explicit TIFFClientOpenWrapper(const IDataBlob* pData) noexcept :
7272
m_Offset{0},
7373
m_Size{pData->GetSize()},
7474
m_pData{pData}
@@ -86,6 +86,7 @@ class TIFFClientOpenWrapper
8686

8787
static tmsize_t TIFFWriteProc(thandle_t pClientData, void* pBuffer, tmsize_t Size)
8888
{
89+
#if 0
8990
TIFFClientOpenWrapper* pThis = static_cast<TIFFClientOpenWrapper*>(pClientData);
9091
if (pThis->m_Offset + Size > pThis->m_Size)
9192
{
@@ -96,6 +97,9 @@ class TIFFClientOpenWrapper
9697
memcpy(pDstPtr, pBuffer, Size);
9798
pThis->m_Offset += Size;
9899
return Size;
100+
#endif
101+
UNSUPPORTED("TIFF write is not supported");
102+
return 0;
99103
}
100104

101105
static toff_t TIFFSeekProc(thandle_t pClientData, toff_t Offset, int Whence)
@@ -114,8 +118,8 @@ class TIFFClientOpenWrapper
114118

115119
static int TIFFCloseProc(thandle_t pClientData)
116120
{
117-
auto* pThis = reinterpret_cast<TIFFClientOpenWrapper*>(pClientData);
118-
pThis->m_pData.Release();
121+
auto* pThis = reinterpret_cast<TIFFClientOpenWrapper*>(pClientData);
122+
pThis->m_pData = nullptr;
119123
pThis->m_Size = 0;
120124
pThis->m_Offset = 0;
121125
return 0;
@@ -139,12 +143,12 @@ class TIFFClientOpenWrapper
139143
}
140144

141145
private:
142-
size_t m_Offset;
143-
size_t m_Size;
144-
RefCntAutoPtr<IDataBlob> m_pData;
146+
size_t m_Offset = 0;
147+
size_t m_Size = 0;
148+
const IDataBlob* m_pData = nullptr;
145149
};
146150

147-
void Image::LoadTiffFile(IDataBlob* pFileData, const ImageLoadInfo& LoadInfo)
151+
void Image::LoadTiffFile(const IDataBlob* pFileData, const ImageLoadInfo& LoadInfo)
148152
{
149153
TIFFClientOpenWrapper TiffClientOpenWrpr(pFileData);
150154

@@ -283,7 +287,7 @@ void Image::LoadTiffFile(IDataBlob* pFileData, const ImageLoadInfo& LoadInfo)
283287
}
284288

285289

286-
static bool LoadHDRFile(IDataBlob* pSrcHdrBits, IDataBlob* pDstPixels, ImageDesc* pDstImgDesc)
290+
static bool LoadHDRFile(const IDataBlob* pSrcHdrBits, IDataBlob* pDstPixels, ImageDesc* pDstImgDesc)
287291
{
288292
Int32 Width = 0, Height = 0, NumComponents = 0;
289293
float* pFloatData = stbi_loadf_from_memory(pSrcHdrBits->GetConstDataPtr<stbi_uc>(), static_cast<Int32>(pSrcHdrBits->GetSize()), &Width, &Height, &NumComponents, 0);
@@ -305,7 +309,7 @@ static bool LoadHDRFile(IDataBlob* pSrcHdrBits, IDataBlob* pDstPixels, ImageDesc
305309
return true;
306310
}
307311

308-
static bool LoadTGAFile(IDataBlob* pSrcTgaBits, IDataBlob* pDstPixels, ImageDesc* pDstImgDesc)
312+
static bool LoadTGAFile(const IDataBlob* pSrcTgaBits, IDataBlob* pDstPixels, ImageDesc* pDstImgDesc)
309313
{
310314
Int32 Width = 0, Height = 0, NumComponents = 0;
311315
Uint8* pFloatData = stbi_load_from_memory(pSrcTgaBits->GetConstDataPtr<stbi_uc>(), static_cast<Int32>(pSrcTgaBits->GetSize()), &Width, &Height, &NumComponents, 0);
@@ -328,7 +332,7 @@ static bool LoadTGAFile(IDataBlob* pSrcTgaBits, IDataBlob* pDstPixels, ImageDesc
328332
}
329333

330334
Image::Image(IReferenceCounters* pRefCounters,
331-
IDataBlob* pFileData,
335+
const IDataBlob* pFileData,
332336
const ImageLoadInfo& LoadInfo) :
333337
TBase{pRefCounters},
334338
m_pData{DataBlobImpl::Create(LoadInfo.pAllocator)}
@@ -394,7 +398,7 @@ Image::Image(IReferenceCounters* pRefCounters,
394398
}
395399
}
396400

397-
void Image::CreateFromDataBlob(IDataBlob* pFileData,
401+
void Image::CreateFromDataBlob(const IDataBlob* pFileData,
398402
const ImageLoadInfo& LoadInfo,
399403
Image** ppImage)
400404
{

TextureLoader/src/JPEGCodec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ my_error_exit(j_common_ptr cinfo)
5858
longjmp(myerr->setjmp_buffer, 1);
5959
}
6060

61-
DECODE_JPEG_RESULT Diligent_DecodeJpeg(IDataBlob* pSrcJpegBits,
62-
IDataBlob* pDstPixels,
63-
ImageDesc* pDstImgDesc)
61+
DECODE_JPEG_RESULT Diligent_DecodeJpeg(const IDataBlob* pSrcJpegBits,
62+
IDataBlob* pDstPixels,
63+
ImageDesc* pDstImgDesc)
6464
{
6565
if (!pSrcJpegBits || !pDstPixels || !pDstImgDesc)
6666
return DECODE_JPEG_RESULT_INVALID_ARGUMENTS;

TextureLoader/src/PNGCodec.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535

3636
struct PNGReadFnState
3737
{
38-
IDataBlob* pPngBits;
39-
size_t Offset;
38+
const IDataBlob* pPngBits;
39+
size_t Offset;
4040
};
4141
typedef struct PNGReadFnState PNGReadFnState;
4242

@@ -48,9 +48,9 @@ static void PngReadCallback(png_structp pngPtr, png_bytep data, png_size_t lengt
4848
pState->Offset += length;
4949
}
5050

51-
DECODE_PNG_RESULT Diligent_DecodePng(IDataBlob* pSrcPngBits,
52-
IDataBlob* pDstPixels,
53-
ImageDesc* pDstImgDesc)
51+
DECODE_PNG_RESULT Diligent_DecodePng(const IDataBlob* pSrcPngBits,
52+
IDataBlob* pDstPixels,
53+
ImageDesc* pDstImgDesc)
5454
{
5555
if (!pSrcPngBits || !pDstPixels || !pDstImgDesc)
5656
return DECODE_PNG_RESULT_INVALID_ARGUMENTS;

TextureLoader/src/SGILoader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ static_assert(sizeof(SGIHeader) == 512, "must be 512 bytes");
5858
} // namespace
5959

6060
// http://paulbourke.net/dataformats/sgirgb/sgiversion.html
61-
bool LoadSGI(IDataBlob* pSGIData,
62-
IDataBlob* pDstPixels,
63-
ImageDesc* pDstImgDesc)
61+
bool LoadSGI(const IDataBlob* pSGIData,
62+
IDataBlob* pDstPixels,
63+
ImageDesc* pDstImgDesc)
6464
{
6565
VERIFY_EXPR(pSGIData != nullptr && pDstPixels != nullptr && pDstImgDesc != nullptr);
6666
const Uint8* pDataStart = pSGIData->GetConstDataPtr<Uint8>();
@@ -230,9 +230,9 @@ bool LoadSGI(IDataBlob* pSGIData,
230230

231231
extern "C"
232232
{
233-
void Diligent_LoadSGI(Diligent::IDataBlob* pSGIData,
234-
Diligent::IDataBlob* pDstPixels,
235-
Diligent::ImageDesc* pDstImgDesc)
233+
void Diligent_LoadSGI(const Diligent::IDataBlob* pSGIData,
234+
Diligent::IDataBlob* pDstPixels,
235+
Diligent::ImageDesc* pDstImgDesc)
236236
{
237237
Diligent::LoadSGI(pSGIData, pDstPixels, pDstImgDesc);
238238
}

TextureLoader/src/TextureLoaderImpl.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050

5151
extern "C"
5252
{
53-
Diligent::DECODE_PNG_RESULT Diligent_DecodePng(Diligent::IDataBlob* pSrcPngBits,
54-
Diligent::IDataBlob* pDstPixels,
55-
Diligent::ImageDesc* pDstImgDesc);
53+
Diligent::DECODE_PNG_RESULT Diligent_DecodePng(const Diligent::IDataBlob* pSrcPngBits,
54+
Diligent::IDataBlob* pDstPixels,
55+
Diligent::ImageDesc* pDstImgDesc);
5656

5757
Diligent::ENCODE_PNG_RESULT Diligent_EncodePng(const Diligent::Uint8* pSrcPixels,
5858
Diligent::Uint32 Width,
@@ -61,27 +61,27 @@ extern "C"
6161
int PngColorType,
6262
Diligent::IDataBlob* pDstPngBits);
6363

64-
Diligent::DECODE_JPEG_RESULT Diligent_DecodeJpeg(Diligent::IDataBlob* pSrcJpegBits,
65-
Diligent::IDataBlob* pDstPixels,
66-
Diligent::ImageDesc* pDstImgDesc);
64+
Diligent::DECODE_JPEG_RESULT Diligent_DecodeJpeg(const Diligent::IDataBlob* pSrcJpegBits,
65+
Diligent::IDataBlob* pDstPixels,
66+
Diligent::ImageDesc* pDstImgDesc);
6767

6868
Diligent::ENCODE_JPEG_RESULT Diligent_EncodeJpeg(Diligent::Uint8* pSrcRGBData,
6969
Diligent::Uint32 Width,
7070
Diligent::Uint32 Height,
7171
int quality,
7272
Diligent::IDataBlob* pDstJpegBits);
7373

74-
Diligent::DECODE_JPEG_RESULT Diligent_LoadSGI(Diligent::IDataBlob* pSrcJpegBits,
75-
Diligent::IDataBlob* pDstPixels,
76-
Diligent::ImageDesc* pDstImgDesc);
74+
Diligent::DECODE_JPEG_RESULT Diligent_LoadSGI(const Diligent::IDataBlob* pSrcJpegBits,
75+
Diligent::IDataBlob* pDstPixels,
76+
Diligent::ImageDesc* pDstImgDesc);
7777
}
7878

7979
namespace Diligent
8080
{
8181

82-
DECODE_PNG_RESULT DecodePng(IDataBlob* pSrcPngBits,
83-
IDataBlob* pDstPixels,
84-
ImageDesc* pDstImgDesc)
82+
DECODE_PNG_RESULT DecodePng(const IDataBlob* pSrcPngBits,
83+
IDataBlob* pDstPixels,
84+
ImageDesc* pDstImgDesc)
8585
{
8686
return Diligent_DecodePng(pSrcPngBits, pDstPixels, pDstImgDesc);
8787
}
@@ -97,9 +97,9 @@ ENCODE_PNG_RESULT EncodePng(const Uint8* pSrcPixels,
9797
}
9898

9999

100-
DECODE_JPEG_RESULT DecodeJpeg(IDataBlob* pSrcJpegBits,
101-
IDataBlob* pDstPixels,
102-
ImageDesc* pDstImgDesc)
100+
DECODE_JPEG_RESULT DecodeJpeg(const IDataBlob* pSrcJpegBits,
101+
IDataBlob* pDstPixels,
102+
ImageDesc* pDstImgDesc)
103103
{
104104
return Diligent_DecodeJpeg(pSrcJpegBits, pDstPixels, pDstImgDesc);
105105
}

0 commit comments

Comments
 (0)