HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SCCompressionFilter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_SCCompressionFilter.C (C++)
7  *
8  * COMMENTS: .
9  */
10 
11 #ifndef UT_SCCOMPRESSIONFILTER_H_
12 #define UT_SCCOMPRESSIONFILTER_H_
13 
14 #include <SYS/SYS_BoostStreams.h>
15 #include <cstdio>
16 #include <iostream>
17 #include "UT_SCFCommon.h"
18 #include "UT_SCFWriter.h"
19 
20 /// The SC compression filter is an implementation of boost multicharacter
21 /// output filter. It can be used with boost output streams to write a .sc
22 /// file to disk.
23 class UT_SCCompressionFilter : public bios::multichar_output_filter
24 {
25 public:
26  typedef char char_type;
27 
28  static const size_t theDefaultTypeSize = 4;
29  static const size_t theDefaultBlockSize = (1<<20);
30 
31  /// SC Compression Filter
32  explicit UT_SCCompressionFilter(size_t typesize,
33  size_t blocksize,
34  bool doShuffer = true,
35  int compressionLevel = 9);
36  virtual ~UT_SCCompressionFilter();
37 
38  template<typename Sink>
39  std::streamsize write(Sink& dest, const char* sourceBuffer,
40  std::streamsize sourceBufferSize);
41 
42  template<typename Sink>
43  void close(Sink& dest);
44 
45 private:
46  // Stuff to pass on to blosc
47  size_t myTypeSize;
48  size_t myBlockSize;
49  int myCompressionLevel;
50  bool myDoShuffle;
51 
52  UT_SCFWriter* myOutputWriter;
53  bios::filtering_ostream* myOutputStream;
54  std::ostream* myOutputAdapter;
55 };
56 
57 
58 inline
60  size_t typeSize,
61  size_t blockSize,
62  bool doShuffle,
63  int compressionLevel)
64  : myTypeSize(typeSize)
65  , myBlockSize(blockSize)
66  , myCompressionLevel(compressionLevel)
67  , myDoShuffle(doShuffle)
68  , myOutputWriter(NULL)
69  , myOutputStream(NULL)
70 {}
71 
72 inline
74 {
75  // This might not be nessisary can we be destroyed without a close?
76  delete myOutputWriter;
77 }
78 
79 template<typename Sink>
80 inline std::streamsize
81 UT_SCCompressionFilter::write(Sink& dest, const char* sourceBuffer,
82  std::streamsize sourceBufferSize)
83 {
84  if (!myOutputWriter)
85  {
86  myOutputWriter = new UT_SCFWriter(myDoShuffle, myTypeSize, myBlockSize,
88  myCompressionLevel);
89  myOutputAdapter = new std::ostream(&dest);
90  myOutputStream = myOutputWriter->getOutputStream(myOutputAdapter);
91  }
92 
93  if(!myOutputStream->write((const char*)sourceBuffer, sourceBufferSize))
94  {
95  return 0;
96  }
97 
98  return sourceBufferSize;
99 }
100 
101 template<typename Sink>
102 inline void
104 {
105  // Check for close without write
106  if (myOutputWriter)
107  {
108  myOutputWriter->close();
109  delete myOutputWriter;
110  delete myOutputAdapter;
111  }
112  myOutputWriter = NULL;
113 }
114 
115 #endif // UT_SCCOMPRESSIONFILTER_H_
UT_SCCompressionFilter(size_t typesize, size_t blocksize, bool doShuffer=true, int compressionLevel=9)
SC Compression Filter.
std::streamsize write(Sink &dest, const char *sourceBuffer, std::streamsize sourceBufferSize)
Interface for writing Seekable Compressed Format (SCF) files.
Definition: UT_SCFWriter.h:25
bios::filtering_ostream * getOutputStream(const char *filename)
static const size_t theDefaultBlockSize
static const size_t theDefaultTypeSize
void close()
Closes the file.
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_14 uint8_t blockSize(VULKAN_HPP_NAMESPACE::Format format)