HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLTF_ImageExport.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef __GLTF_IMAGE_h__
27 #define __GLTF_IMAGE_h__
28 
29 #include "GLTFZ_API.h"
30 
31 #include <GLTF/GLTF_Types.h>
32 #include <SYS/SYS_Types.h>
33 #include <UT/UT_Array.h>
34 #include <UT/UT_ArraySet.h>
35 #include <UT/UT_StringHolder.h>
36 #include <UT/UT_UniquePtr.h>
37 #include <UT/UT_SharedPtr.h>
38 #include <iosfwd>
39 
40 class IMG_Format;
41 class COP2_Node;
42 class OP_Node;
43 class UT_String;
44 class PXL_Raster;
45 class IMG_Stat;
46 
47 namespace GLTF_NAMESPACE
48 {
49 
51 {
52  // This implemented so we can obtain a lexiographic ordering
53  // of ChannelMaps in order to cache them in a map
54  bool operator<(const GLTF_ChannelMapping &r) const;
55 
59 };
60 
62 {
63  bool roundUpPowerOfTwo = false;
64  // 0 indicates that there is no max raster size
65  exint maxRasterSize = 0;
66  exint quality = 90;
67  exint max_res = 0;
68  bool flipGreen = false;
69 };
70 
71 ///
72 /// Utility functions for importing, exporting and manipulating images in
73 /// the context of GLTF textures.
74 ///
75 
77 {
78 public:
79  ///
80  /// Takes a list of images and associated channels, packs them into
81  /// a single image file, preprocesses the image and outputs it to &os
82  ///
83  static bool
84  CreateMappedTexture(const UT_Array<GLTF_ChannelMapping> &mappings,
85  std::ostream &os, const IMG_Format *format, uint32 time,
86  const GLTF_ImgExportParms &parms,
87  GLTF_BaseErrorManager &errormgr);
88 
89  ///
90  /// Converts the file format for the given images, processes it for GLTF
91  /// and outputs it to the output stream &os.
92  ///
93  static bool OutputImage(const UT_String &filename, const IMG_Format *format,
94  std::ostream &os, fpreal time,
95  const GLTF_ImgExportParms &parms,
96  GLTF_BaseErrorManager &errormgr,
97  const OP_Node* cop_node = nullptr);
98 
99 private:
100  //
101  // Gets the image rasters from the given File or COP. Any methods
102  // with "include_alpha" will return RGBA if the flag is on, or otherwise
103  // RGB. This is to avoid handling other packings.
104  //
105  static bool
106  GetImageRasters(const UT_StringHolder &filename, const uint32 time,
108  IMG_Stat &stat, bool include_alpha);
109 
110  static exint NextPowerOfTwo(exint num);
111 
112  static bool
113  OutputCopToStream(COP2_Node *node, const IMG_Format *format,
114  std::ostream &os, fpreal time,
115  const GLTF_ImgExportParms &parms);
116 
117  static bool
118  OutputImageToStream(const UT_String &filename,
119  const IMG_Format *file_format, std::ostream &os,
120  fpreal time, const GLTF_ImgExportParms &parms);
121 
122  static void
123  ApplyTransformations(IMG_Stat &stat,
125  const GLTF_ImgExportParms &parms);
126 
127  static bool
128  GetImageRastersFromFile(const UT_StringHolder &filename, const uint32 time,
130  IMG_Stat &stat, bool include_alpha);
131 
132  static bool
133  GetImageRastersFromCOP(COP2_Node *node, const uint32 time,
135  IMG_Stat &stat, bool include_alpha);
136 };
137 
138 } // namespace GLTF_NAMESPACE
139 
140 #endif
GT_API const UT_StringHolder filename
GT_API const UT_StringHolder time
int64 exint
Definition: SYS_Types.h:125
#define GLTF_NAMESPACE
Definition: GLTF_API.h:42
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:30
GLuint num
Definition: glew.h:2695
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
fpreal64 fpreal
Definition: SYS_Types.h:277
unsigned int uint32
Definition: SYS_Types.h:40
Contains the details of a specific image file, used by IMG_File. This class contains all the high-lev...
Definition: IMG_Stat.h:40
GLboolean r
Definition: glcorearb.h:1221
#define GLTFZ_API
Definition: GLTFZ_API.h:37