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 <UT/UT_Array.h>
33 #include <UT/UT_ArraySet.h>
34 #include <UT/UT_StringHolder.h>
35 #include <UT/UT_UniquePtr.h>
36 #include <SYS/SYS_Types.h>
37 #include <iosfwd>
38 
39 class IMG_Format;
40 class COP2_Node;
41 class OP_Node;
42 class UT_String;
43 class PXL_Raster;
44 class IMG_Stat;
45 
46 namespace GLTF_NAMESPACE
47 {
48 
50 {
51  // This implemented so we can obtain a lexiographic ordering
52  // of ChannelMaps in order to cache them in a map
53  bool operator<(const GLTF_ChannelMapping &r) const;
54 
58 };
59 
61 {
62  bool roundUpPowerOfTwo = false;
63  // 0 indicates that there is no max raster size
64  exint maxRasterSize = 0;
65  exint quality = 90;
66  exint max_res = 0;
67  bool flipGreen = false;
68 };
69 
70 ///
71 /// Utility functions for importing, exporting and manipulating images in
72 /// the context of GLTF textures.
73 ///
74 
76 {
77 public:
78  ///
79  /// Takes a list of images and associated channels, packs them into
80  /// a single image file, preprocesses the image and outputs it to &os
81  ///
82  static bool
83  CreateMappedTexture(const UT_Array<GLTF_ChannelMapping> &mappings,
84  std::ostream &os, const IMG_Format *format, uint32 time,
85  const GLTF_ImgExportParms &parms,
86  GLTF_BaseErrorManager &errormgr);
87 
88  ///
89  /// Converts the file format for the given images, processes it for GLTF
90  /// and outputs it to the output stream &os.
91  ///
92  static bool OutputImage(const UT_String &filename, const IMG_Format *format,
93  std::ostream &os, fpreal time,
94  const GLTF_ImgExportParms &parms,
95  GLTF_BaseErrorManager &errormgr,
96  const OP_Node* cop_node = nullptr);
97 
98 private:
99  //
100  // Gets the image rasters from the given File or COP. Any methods
101  // with "include_alpha" will return RGBA if the flag is on, or otherwise
102  // RGB. This is to avoid handling other packings.
103  //
104  static bool
105  GetImageRasters(const UT_StringHolder &filename, const uint32 time,
107  IMG_Stat &stat, bool include_alpha);
108 
109  static exint NextPowerOfTwo(exint num);
110 
111  static bool
112  OutputCop2ToStream(COP2_Node *node, const IMG_Format *format,
113  std::ostream &os, fpreal time,
114  const GLTF_ImgExportParms &parms);
115 
116  static bool
117  OutputImageToStream(const UT_String &filename,
118  const IMG_Format *file_format, std::ostream &os,
119  fpreal time, const GLTF_ImgExportParms &parms);
120 
121  static void
122  ApplyTransformations(IMG_Stat &stat,
124  const GLTF_ImgExportParms &parms);
125 
126  static bool
127  GetImageRastersFromFile(const UT_StringHolder &filename, const uint32 time,
129  IMG_Stat &stat, bool include_alpha);
130 
131  static bool
132  GetImageRastersFromCOP2(COP2_Node *node, const uint32 time,
134  IMG_Stat &stat, bool include_alpha);
135 };
136 
137 } // namespace GLTF_NAMESPACE
138 
139 #endif
GT_API const UT_StringHolder filename
GT_API const UT_StringHolder time
int64 exint
Definition: SYS_Types.h:125
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
#define GLTF_NAMESPACE
Definition: GLTF_API.h:42
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
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:38
GLboolean r
Definition: glcorearb.h:1222
#define GLTFZ_API
Definition: GLTFZ_API.h:37