Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please consider making ktxStream public #438

Merged
merged 35 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b6a9346
Move ktxStream definitions to ktx.h
UberLambda Jun 9, 2021
78d07d7
Expose or implement ktxStream functions
UberLambda Jun 9, 2021
41f5324
Remove stream.h and all references
UberLambda Jun 9, 2021
5906f1f
Fixes + add some implementations
UberLambda Jun 9, 2021
d926f62
Remove @private
UberLambda Jun 9, 2021
0bf81a6
Rename struct, add another pointer
UberLambda Jun 10, 2021
cdbb3e3
Accept eStreamTypeCustom in two asserts
UberLambda Jun 10, 2021
23f761e
Add basic ktxStream <-> C++ integration tests
UberLambda Jun 10, 2021
3e9671e
Add a test for ktxTexture1_WriteKTX2ToStream
UberLambda Jun 10, 2021
90afb77
-Wnarrowing Windows fix
UberLambda Jun 10, 2021
0cc6a15
Reimplement std::make_unique<> for AppleClang
UberLambda Jun 11, 2021
a1a78d2
Re-add Windows fix, silence warning
UberLambda Jun 11, 2021
a01f0fc
Add WriteToStream to the publicly-visible Texture vtable
UberLambda Jun 11, 2021
1f4098b
RAIIfy stream tests, add a KTX2->KTX2 writing test
UberLambda Jun 11, 2021
5b44725
Add texture equality checking for the KTX2->KTX2 C++ test
UberLambda Jun 11, 2021
b15f92d
REUSE compliance (remove GPL2, rename dep5 entry)
UberLambda Jun 15, 2021
aa3f6f1
Fix license issues newly shown by reuse 0.13.0.
MarkCallow Jun 16, 2021
01434ed
Move ktxStream definitions to ktx.h
UberLambda Jun 9, 2021
0daa762
Expose or implement ktxStream functions
UberLambda Jun 9, 2021
27a9033
Remove stream.h and all references
UberLambda Jun 9, 2021
57114a2
Fixes + add some implementations
UberLambda Jun 9, 2021
9240b34
Remove @private
UberLambda Jun 9, 2021
9b9e93c
Rename struct, add another pointer
UberLambda Jun 10, 2021
5ae6be5
Accept eStreamTypeCustom in two asserts
UberLambda Jun 10, 2021
f27ac3d
Add basic ktxStream <-> C++ integration tests
UberLambda Jun 10, 2021
a2362e5
Add a test for ktxTexture1_WriteKTX2ToStream
UberLambda Jun 10, 2021
37cc939
-Wnarrowing Windows fix
UberLambda Jun 10, 2021
292e7c7
Reimplement std::make_unique<> for AppleClang
UberLambda Jun 11, 2021
f9d151b
Re-add Windows fix, silence warning
UberLambda Jun 11, 2021
3f7ee50
Add WriteToStream to the publicly-visible Texture vtable
UberLambda Jun 11, 2021
3b64494
RAIIfy stream tests, add a KTX2->KTX2 writing test
UberLambda Jun 11, 2021
57ee989
Add texture equality checking for the KTX2->KTX2 C++ test
UberLambda Jun 11, 2021
444613c
Merge branch 'public-stream' of github.com:UberLambda/KTX-Software in…
UberLambda Jun 16, 2021
f76a1a4
Force C++ standard for streamtests (make_unique from <memory>)
UberLambda Jun 16, 2021
05097bd
Fix doc comment
UberLambda Jun 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Files: tests/srcimages/CesiumLogoFlat_palette.png
Copyright: Analytical Graphics
License: CC-BY-4.0 WITH LicenseRef-Cesium-Trademark-Terms

Files: tests/testimages/himark.ktx tests/testimages/himark.ktx
Files: tests/testimages/hi_mark.ktx tests/testimages/hi_mark_sq.ktx
Copyright: HI Corporation
License: LicenseRef-HI-Trademark

Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ set(KTX_MAIN_SRC
lib/ktxint.h
lib/memstream.c
lib/memstream.h
lib/stream.h
lib/strings.c
lib/swap.c
lib/texture.c
Expand Down
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ gypfiles=ktxtests.gyp \
tests/texturetests/texturetests.gypi \
tests/testimages/testimages.gypi \
tests/transcodetests/transcodetests.gypi \
tests/streamtests/streamtests.gypi \
tests/unittests/unittests.gypi \
tools/tools.gypi \
tools/ktx2ktx2/ktx2ktx2.gypi \
Expand Down
103 changes: 0 additions & 103 deletions LICENSES/GPL-2.0-or-later.txt

This file was deleted.

149 changes: 146 additions & 3 deletions include/ktx.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <stdio.h>
#include <stdbool.h>
#include <sys/types.h>

/*
* Don't use khrplatform.h in order not to break apps existing
Expand Down Expand Up @@ -202,6 +203,8 @@ typedef enum ktx_error_code_e {
*/
typedef struct ktxKVListEntry* ktxHashList;

typedef struct ktxStream ktxStream;

#define KTX_APIENTRYP KTX_APIENTRY *
/**
* @class ktxHashListEntry
Expand Down Expand Up @@ -477,6 +480,9 @@ typedef KTX_error_code
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXWRITETOMEMORY)(ktxTexture* This,
ktx_uint8_t** bytes, ktx_size_t* size);
typedef KTX_error_code
(KTX_APIENTRY* PFNKTEXWRITETOSTREAM)(ktxTexture* This,
ktxStream* dststr);

/**
* @memberof ktxTexture
Expand All @@ -497,6 +503,7 @@ typedef KTX_error_code
PFNKTEXWRITETOSTDIOSTREAM WriteToStdioStream;
PFNKTEXWRITETONAMEDFILE WriteToNamedFile;
PFNKTEXWRITETOMEMORY WriteToMemory;
PFNKTEXWRITETOSTREAM WriteToStream;
};

/****************************************************************
Expand Down Expand Up @@ -617,6 +624,14 @@ typedef KTX_error_code
#define ktxTexture_WriteToMemory(This, ppDstBytes, pSize) \
(This)->vtbl->WriteToMemory(This, ppDstBytes, pSize)

/**
* @~English
* @brief Helper for calling the WriteToStream virtual method of a ktxTexture.
* @copydoc ktxTexture2_WriteToStream
*/
#define ktxTexture_WriteToStream(This, dststr) \
(This)->vtbl->WriteToStream(This, dststr)


/**
* @class ktxTexture1
Expand Down Expand Up @@ -755,13 +770,120 @@ enum ktxTextureCreateFlagBits {
*/
typedef ktx_uint32_t ktxTextureCreateFlags;

/*===========================================================*
* ktxStream
*===========================================================*/

/*
* This is unsigned to allow ktxmemstreams to use the
* full amount of memory available. Platforms will
* limit the size of ktxfilestreams to, e.g, MAX_LONG
* on 32-bit and ktxfilestreams raises errors if
* offset values exceed the limits. This choice may
* need to be revisited if we ever start needing -ve
* offsets.
*
* Should the 2GB file size handling limit on 32-bit
* platforms become a problem, ktxfilestream will have
* to be changed to explicitly handle large files by
* using the 64-bit stream functions.
*/
#if defined(_MSC_VER) && defined(_WIN64)
typedef unsigned __int64 ktx_off_t;
#else
typedef off_t ktx_off_t;
#endif
typedef struct ktxMem ktxMem;
typedef struct ktxStream ktxStream;

enum streamType { eStreamTypeFile = 1, eStreamTypeMemory = 2, eStreamTypeCustom = 3 };

/**
* @~English
* @brief type for a pointer to a stream reading function
*/
typedef KTX_error_code (*ktxStream_read)(ktxStream* str, void* dst,
const ktx_size_t count);
/**
* @~English
* @brief type for a pointer to a stream skipping function
*/
typedef KTX_error_code (*ktxStream_skip)(ktxStream* str,
const ktx_size_t count);

/**
* @~English
* @brief type for a pointer to a stream reading function
*/
typedef KTX_error_code (*ktxStream_write)(ktxStream* str, const void *src,
const ktx_size_t size,
const ktx_size_t count);

/**
* @~English
* @brief type for a pointer to a stream position query function
*/
typedef KTX_error_code (*ktxStream_getpos)(ktxStream* str, ktx_off_t* const offset);

/**
* @~English
* @brief type for a pointer to a stream position query function
*/
typedef KTX_error_code (*ktxStream_setpos)(ktxStream* str, const ktx_off_t offset);

/**
* @~English
* @brief type for a pointer to a stream size query function
*/
typedef KTX_error_code (*ktxStream_getsize)(ktxStream* str, ktx_size_t* const size);

/**
* @~English
* @brief Destruct a stream
*/
typedef void (*ktxStream_destruct)(ktxStream* str);

/**
* @~English
*
* @brief Interface of ktxStream.
*
* @author Maksim Kolesin
* @author Georg Kolling, Imagination Technology
* @author Mark Callow, HI Corporation
*/
struct ktxStream
{
ktxStream_read read; /*!< @internal pointer to function for reading bytes. */
ktxStream_skip skip; /*!< @internal pointer to function for skipping bytes. */
ktxStream_write write; /*!< @internal pointer to function for writing bytes. */
ktxStream_getpos getpos; /*!< @internal pointer to function for getting current position in stream. */
ktxStream_setpos setpos; /*!< @internal pointer to function for setting current position in stream. */
ktxStream_getsize getsize; /*!< @internal pointer to function for querying size. */
ktxStream_destruct destruct; /*!< @internal destruct the stream. */

enum streamType type;
union {
FILE* file;
ktxMem* mem;
struct
{
void* address;
void* allocatorAddress;
ktx_size_t size;
} custom_ptr;
} data; /**< @internal pointer to the stream data. */
ktx_off_t readpos; /**< @internal used by FileStream for stdin. */
ktx_bool_t closeOnDestruct; /**< @internal Close FILE* or dispose of memory on destruct. */
};

/*
* See the implementation files for the full documentation of the following
* functions.
*/

/*
* These three create a ktxTexture1 or ktxTexture2 according to the data
* These four create a ktxTexture1 or ktxTexture2 according to the data
* header, and return a pointer to the base ktxTexture class.
*/
KTX_API KTX_error_code KTX_APIENTRY
Expand All @@ -779,6 +901,11 @@ ktxTexture_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
ktxTextureCreateFlags createFlags,
ktxTexture** newTex);

KTX_API KTX_error_code KTX_APIENTRY
ktxTexture_CreateFromStream(ktxStream* stream,
ktxTextureCreateFlags createFlags,
ktxTexture** newTex);

/*
* Returns a pointer to the image data of a ktxTexture object.
*/
Expand Down Expand Up @@ -824,7 +951,7 @@ ktxTexture1_Create(ktxTextureCreateInfo* createInfo,
ktxTexture1** newTex);

/*
* These three create a ktxTexture1 provided the data is in KTX format.
* These four create a ktxTexture1 provided the data is in KTX format.
*/
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture1_CreateFromStdioStream(FILE* stdioStream,
Expand All @@ -841,6 +968,11 @@ ktxTexture1_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
ktxTextureCreateFlags createFlags,
ktxTexture1** newTex);

KTX_API KTX_error_code KTX_APIENTRY
ktxTexture1_CreateFromStream(ktxStream* stream,
ktxTextureCreateFlags createFlags,
ktxTexture1** newTex);

KTX_API ktx_bool_t KTX_APIENTRY
ktxTexture1_NeedsTranscoding(ktxTexture1* This);

Expand All @@ -863,6 +995,12 @@ KTX_API KTX_error_code KTX_APIENTRY
ktxTexture1_WriteKTX2ToMemory(ktxTexture1* This,
ktx_uint8_t** bytes, ktx_size_t* size);

/*
* Write a ktxTexture object to a ktxStream in KTX format.
*/
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture1_WriteKTX2ToStream(ktxTexture1* This, ktxStream *dststr);

/*
* Create a new ktxTexture2.
*/
Expand All @@ -878,7 +1016,7 @@ KTX_API KTX_error_code KTX_APIENTRY
ktxTexture2_CreateCopy(ktxTexture2* orig, ktxTexture2** newTex);

/*
* These three create a ktxTexture2 provided the data is in KTX2 format.
* These four create a ktxTexture2 provided the data is in KTX2 format.
*/
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture2_CreateFromStdioStream(FILE* stdioStream,
Expand All @@ -895,6 +1033,11 @@ ktxTexture2_CreateFromMemory(const ktx_uint8_t* bytes, ktx_size_t size,
ktxTextureCreateFlags createFlags,
ktxTexture2** newTex);

KTX_API KTX_error_code KTX_APIENTRY
ktxTexture2_CreateFromStream(ktxStream* stream,
ktxTextureCreateFlags createFlags,
ktxTexture2** newTex);

KTX_API KTX_error_code KTX_APIENTRY
ktxTexture2_CompressBasis(ktxTexture2* This, ktx_uint32_t quality);

Expand Down
1 change: 0 additions & 1 deletion lib/filestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#define FILESTREAM_H

#include "ktx.h"
#include "stream.h"

/*
* ktxFileInit: Initialize a ktxStream to a ktxFileStream with a FILE object
Expand Down
1 change: 0 additions & 1 deletion lib/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <ktx.h>

#include "dfdutils/dfd.h"
#include "stream.h"
#include "filestream.h"
#include "memstream.h"
#include "ktxint.h"
Expand Down
1 change: 0 additions & 1 deletion lib/ktxint.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#define KTXINT_H

#include <math.h>
#include "stream.h"

/* Define this to include the ETC unpack software in the library. */
#ifndef SUPPORT_SOFTWARE_ETC_UNPACK
Expand Down
1 change: 0 additions & 1 deletion lib/libktx.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
'ktxint.h',
'memstream.c',
'memstream.h',
'stream.h',
'strings.c',
'swap.c',
'texture.c',
Expand Down
1 change: 0 additions & 1 deletion lib/memstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define MEMSTREAM_H

#include "ktx.h"
#include "stream.h"

/*
* Initialize a ktxStream to a ktxMemStream with internally
Expand Down
Loading