[Bf-blender-cvs] [5e060be] KTX_support: KTX file format support

Antony Riakiotakis noreply at git.blender.org
Sat May 30 19:12:05 CEST 2015


Commit: 5e060bed27bd3e2a5e75f0c16ea65dc4534fdf04
Author: Antony Riakiotakis
Date:   Sat May 30 14:44:55 2015 +0200
Branches: KTX_support
https://developer.blender.org/rB5e060bed27bd3e2a5e75f0c16ea65dc4534fdf04

KTX file format support

This commit introduces support for the KTX format in blender.

Saving and loading of files is supported though saving compressed formats
is not yet supported.

Thumbnails are not generated because the API relies on OpenGL to load the textures,
which is not available during threaded thumbnail generation.

We hand compiled a KTX library from https://github.com/KhronosGroup/KTX
and placed KTX lib files in intern/KTX as follows:

libktx.a in intern/KTX/lib
ktx.h in intern/KTX/include

We may include the library in extern when we make sure it compiles in all platforms (Ubuntu 15.04 failed here)

Scons is not supported, only cmake for now.

===================================================================

M	CMakeLists.txt
M	build_files/cmake/macros.cmake
M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/image.c
M	source/blender/imbuf/CMakeLists.txt
M	source/blender/imbuf/IMB_imbuf.h
M	source/blender/imbuf/IMB_imbuf_types.h
M	source/blender/imbuf/intern/IMB_filetype.h
M	source/blender/imbuf/intern/filetype.c
A	source/blender/imbuf/intern/ktx.c
M	source/blender/imbuf/intern/openexr/openexr_api.cpp
M	source/blender/imbuf/intern/thumbs.c
M	source/blender/imbuf/intern/util.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/rna_scene.c

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 176d13b..a05bdce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -284,6 +284,7 @@ option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" ${_init_IMAGE_REDCODE})
 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
+option(WITH_IMAGE_KTX           "Enable KTX image support" ON)
 
 # Audio/Video format support
 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
@@ -845,6 +846,11 @@ if(UNIX AND NOT APPLE)
 		endif()
 	endif()
 
+	if(WITH_IMAGE_KTX)
+		set(KTX_LIBRARIES "${CMAKE_SOURCE_DIR}/intern/KTX/lib/libktx.a")
+		set(KTX_INCLUDE "${CMAKE_SOURCE_DIR}/intern/KTX/include")
+	endif()
+
 	if(WITH_IMAGE_OPENJPEG)
 		find_package_wrapper(OpenJPEG)
 		if(NOT OPENJPEG_FOUND)
@@ -2814,6 +2820,7 @@ if(FIRST_RUN)
 	info_cfg_option(WITH_IMAGE_CINEON)
 	info_cfg_option(WITH_IMAGE_DDS)
 	info_cfg_option(WITH_IMAGE_HDR)
+	info_cfg_option(WITH_IMAGE_KTX)
 	info_cfg_option(WITH_IMAGE_OPENEXR)
 	info_cfg_option(WITH_IMAGE_OPENJPEG)
 	info_cfg_option(WITH_IMAGE_REDCODE)
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 7de2b25..01869d7 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -377,6 +377,9 @@ macro(setup_liblinks
 			target_link_libraries(${target} ${OPENEXR_LIBRARIES})
 		endif()
 	endif()
+	if(WITH_IMAGE_KTX)
+		target_link_libraries(${target} "${KTX_LIBRARIES}")
+	endif()
 	if(WITH_IMAGE_OPENJPEG AND WITH_SYSTEM_OPENJPEG)
 		target_link_libraries(${target} ${OPENJPEG_LIBRARIES})
 	endif()
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index facf3cf..2b7eda0 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -79,7 +79,7 @@ void    BKE_image_path_from_imtype(
         const char imtype, const bool use_ext, const bool use_frames, const char *suffix);
 int     BKE_image_path_ensure_ext_from_imformat(char *string, const struct ImageFormatData *im_format);
 int     BKE_image_path_ensure_ext_from_imtype(char *string, const char imtype);
-char    BKE_image_ftype_to_imtype(const int ftype);
+char    BKE_image_ftype_to_imtype(const long long int ftype);
 int     BKE_image_imtype_to_ftype(const char imtype);
 
 bool    BKE_imtype_is_movie(const char imtype);
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 37e5b36..e62fe54 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -361,6 +361,10 @@ if(WITH_IMAGE_HDR)
 	add_definitions(-DWITH_HDR)
 endif()
 
+if(WITH_IMAGE_KTX)
+	add_definitions(-DWITH_KTX)
+endif()
+
 if(WITH_CODEC_AVI)
 	list(APPEND INC
 		../avi
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index a8c5620..1d3246d 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1249,7 +1249,7 @@ int BKE_image_imtype_to_ftype(const char imtype)
 		return JPG | 90;
 }
 
-char BKE_image_ftype_to_imtype(const int ftype)
+char BKE_image_ftype_to_imtype(const long long ftype)
 {
 	if (ftype == 0)
 		return R_IMF_IMTYPE_TARGA;
@@ -1287,6 +1287,10 @@ char BKE_image_ftype_to_imtype(const int ftype)
 	else if (ftype & JP2)
 		return R_IMF_IMTYPE_JP2;
 #endif
+#ifdef WITH_KTX
+	else if (ftype & KTX)
+		return R_IMF_IMTYPE_KTX;
+#endif
 	else
 		return R_IMF_IMTYPE_JPEG90;
 }
@@ -1371,6 +1375,7 @@ char BKE_imtype_valid_channels(const char imtype, bool write_file)
 		case R_IMF_IMTYPE_JP2:
 		case R_IMF_IMTYPE_QUICKTIME:
 		case R_IMF_IMTYPE_DPX:
+		case R_IMF_IMTYPE_KTX:
 			chan_flag |= IMA_CHAN_FLAG_ALPHA;
 			break;
 	}
@@ -1543,6 +1548,12 @@ static bool do_add_image_extension(char *string, const char imtype, const ImageF
 		}
 	}
 #endif
+#ifdef WITH_KTX
+	else if (imtype == R_IMF_IMTYPE_KTX) {
+		if (!BLI_testextensie(string, extension_test = ".ktx"))
+			extension = extension_test;
+	}
+#endif
 	else { //   R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90, R_IMF_IMTYPE_QUICKTIME etc
 		if (!(BLI_testextensie_n(string, extension_test = ".jpg", ".jpeg", NULL)))
 			extension = extension_test;
@@ -1591,7 +1602,7 @@ void BKE_imformat_defaults(ImageFormatData *im_format)
 
 void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const ImBuf *imbuf)
 {
-	int ftype        = imbuf->ftype & ~IB_CUSTOM_FLAGS_MASK;
+	long long int ftype = imbuf->ftype & ~IB_CUSTOM_FLAGS_MASK;
 	int custom_flags = imbuf->ftype & IB_CUSTOM_FLAGS_MASK;
 
 	BKE_imformat_defaults(im_format);
@@ -1683,6 +1694,11 @@ void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const ImBuf *i
 	}
 #endif
 
+#ifdef WITH_KTX
+	else if (ftype & KTX) {
+		im_format->imtype = R_IMF_IMTYPE_KTX;
+	}
+#endif
 	else {
 		im_format->imtype = R_IMF_IMTYPE_JPEG90;
 		im_format->quality = custom_flags & ~JPG_MSK;
@@ -2263,6 +2279,11 @@ void BKE_imbuf_write_prepare(ImBuf *ibuf, ImageFormatData *imf)
 			BLI_assert(!"Unsupported jp2 codec was specified in im_format->jp2_codec");
 	}
 #endif
+#ifdef WITH_KTX
+	else if (imtype == R_IMF_IMTYPE_KTX) {
+		ibuf->ftype = KTX;
+	}
+#endif
 	else {
 		/* R_IMF_IMTYPE_JPEG90, etc. default we save jpegs */
 		if (quality < 10) quality = 90;
diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt
index bdd8230..d8837ca 100644
--- a/source/blender/imbuf/CMakeLists.txt
+++ b/source/blender/imbuf/CMakeLists.txt
@@ -178,6 +178,19 @@ if(WITH_IMAGE_HDR)
 	add_definitions(-DWITH_HDR)
 endif()
 
+if(WITH_IMAGE_KTX)
+	list(APPEND INC
+		../../../intern/KTX/include
+	)
+	list(APPEND INC_SYS
+		${GLEW_INCLUDE_PATH}
+	)
+	list(APPEND SRC
+		intern/ktx.c
+	)
+	add_definitions(-DWITH_KTX)
+endif()
+
 list(APPEND INC
 	../../../intern/opencolorio
 )
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index ed16c67..805e1a7 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -391,7 +391,7 @@ struct ImBuf *IMB_prepare_write_ImBuf(const bool isfloat, struct ImBuf *ibuf);
  * \attention Defined in util.c
  */
 bool IMB_ispic(const char *name);
-int  IMB_ispic_type(const char *name);
+long long int  IMB_ispic_type(const char *name);
 
 /**
  *
diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index 862c587..1627fe7 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -113,7 +113,9 @@ typedef struct ImBuf {
 	void *userdata;					/* temporary storage */
 
 	/* file information */
-	int	ftype;							/* file type we are going to save as */
+	long long int ftype;				/* file type we are going to save as */
+	int fsubtype;						/* file subtype */
+	int pad;
 	char name[IB_FILENAME_SIZE];		/* filename associated with this image */
 	char cachename[IB_FILENAME_SIZE];	/* full filename used for reading from cache */
 
@@ -172,7 +174,7 @@ typedef struct ImBuf {
 #define IB_alphamode_premul	(1 << 12)  /* indicates whether image on disk have premul alpha */
 #define IB_alphamode_detect	(1 << 13)  /* if this flag is set, alpha mode would be guessed from file */
 #define IB_ignore_alpha		(1 << 14)  /* ignore alpha on load and substitude it with 1.0f */
-#define IB_thumbnail		(1 << 15)
+#define IB_thumbnail		(1 << 15)  /* only used as a flag during thumbnail creation */
 #define IB_multiview		(1 << 16)
 
 /*
@@ -181,6 +183,10 @@ typedef struct ImBuf {
  */
 #define IB_CUSTOM_FLAGS_MASK 0x7ff
 
+#ifdef WITH_KTX
+#define KTX				(1LL << 32)
+#endif
+
 #ifdef WITH_OPENIMAGEIO
 #define PSD				(1 << 31)
 #endif
@@ -225,7 +231,7 @@ typedef struct ImBuf {
 #define JP2_16BIT		(1 << 16)
 #define JP2_YCC			(1 << 15)
 #define JP2_CINE		(1 << 14)
-#define JP2_CINE_48FPS	(1 << 13) 
+#define JP2_CINE_48FPS	(1 << 13)
 #define JP2_JP2	(1 << 12)
 #define JP2_J2K	(1 << 11)
 #endif
diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h
index 332878b..39f9f4d 100644
--- a/source/blender/imbuf/intern/IMB_filetype.h
+++ b/source/blender/imbuf/intern/IMB_filetype.h
@@ -40,14 +40,14 @@ typedef struct ImFileType {
 
 	int (*is_a)(unsigned char *buf);
 	int (*is_a_filepath)(const char *name);
-	int (*ftype)(const struct ImFileType *type, struct ImBuf *ibuf);
+	long long int (*ftype)(const struct ImFileType *type, struct ImBuf *ibuf);
 	struct ImBuf *(*load)(unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]);
 	struct ImBuf *(*load_filepath)(const char *name, int flags, char colorspace[IM_MAX_SPACE]);
 	int (*save)(struct ImBuf *ibuf, const char *name, int flags);
 	void (*load_tile)(struct ImBuf *ibuf, unsigned char *mem, size_t size, int tx, int ty, unsigned int *rect);
 
 	int flag;
-	int filetype;
+	long long int filetype;
 	int default_save_role;
 } ImFileType;
 
@@ -121,5 +121,13 @@ void imb_loadtiletiff(struct ImBuf *ibuf, unsigned char *mem, size_t size,
 	int tx, int ty, unsigned int *rect);
 int imb_savetiff(struct ImBuf *ibuf, const char *name, int flags);
 
+/* ktx */
+void imb_initktx(void);
+int check_ktx(unsigned char *mem);
+int imb_is_a_ktx(const char *filename);
+struct ImBuf *imb_loadktx(unsigned char *mem, size_t size, int flags, char colorspace[]);
+int imb_savektx(struct ImBuf *ibuf, const char *name, int flags);
+
+
 #endif	/* __IMB_FILETYPE_H__ */
 
diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c
index e58cda0..db13700 100644
--- a/source/blender/imbuf/intern/filetype.c
+++ b/source/blender/imbuf/intern/filetype.c
@@ -51,11 +51,11 @@
 #include "quicktime_import.h"
 #endif
 
-static int imb_ftype_default(const ImFileType *type, ImBuf *ibuf)
+static long long int imb_ftype_default(const ImFileType *type, ImBuf *ibuf)
 {
 	return (ibuf->ftype & type->filetype);
 }
-static int imb_ftype_iris(const ImFileType *type, ImBuf *ibuf)
+static long long int imb_ftype_iris(const ImFileType *type, ImBuf *ibuf)
 {
 	(void)type;
 	return (ibuf->ftype == IMAGIC);
@@ -89,6 +89,9 @@ const Im

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list