22// This software is released under the 2-Clause BSD license, included
33// below.
44//
5- // Copyright (c) 2019, Aous Naman
5+ // Copyright (c) 2019, Aous Naman
66// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
77// Copyright (c) 2019, The University of New South Wales, Australia
8- //
8+ //
99// Redistribution and use in source and binary forms, with or without
1010// modification, are permitted provided that the following conditions are
1111// met:
12- //
12+ //
1313// 1. Redistributions of source code must retain the above copyright
1414// notice, this list of conditions and the following disclaimer.
15- //
15+ //
1616// 2. Redistributions in binary form must reproduce the above copyright
1717// notice, this list of conditions and the following disclaimer in the
1818// documentation and/or other materials provided with the distribution.
19- //
19+ //
2020// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
2121// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2222// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
@@ -84,10 +84,10 @@ namespace ojph {
8484
8585 virtual size_t write (const void *ptr, size_t size) = 0;
8686 virtual si64 tell () { return 0 ; }
87- virtual int seek (si64 offset, enum outfile_base::seek origin)
88- {
87+ virtual int seek (si64 offset, enum outfile_base::seek origin)
88+ {
8989 ojph_unused (offset); ojph_unused (origin);
90- return -1 ; /* always fail, to remind you to write an implementation */
90+ return -1 ; /* always fail, to remind you to write an implementation */
9191 }
9292 virtual void flush () {}
9393 virtual void close () {}
@@ -131,19 +131,19 @@ namespace ojph {
131131 /* * A destructor */
132132 ~mem_outfile () override ;
133133
134- /* *
134+ /* *
135135 * @brief Call this function to open a memory file.
136136 *
137137 * This function creates a memory buffer to be used for storing
138138 * the generated j2k codestream.
139- *
139+ *
140140 * @param initial_size is the initial memory buffer size.
141141 * The default value is 2^16.
142142 * @param clear_mem if set to true, all allocated memory is reset to 0
143143 */
144144 void open (size_t initial_size = 65536 , bool clear_mem = false );
145145
146- /* *
146+ /* *
147147 * @brief Call this function to write data to the memory file.
148148 *
149149 * This function adds new data to the memory file. The memory buffer
@@ -154,16 +154,16 @@ namespace ojph {
154154 */
155155 size_t write (const void *ptr, size_t size) override ;
156156
157- /* *
158- * @brief Call this function to know the file size (i.e., number of
157+ /* *
158+ * @brief Call this function to know the file size (i.e., number of
159159 * bytes used to store the file).
160160 *
161161 * @return the file size.
162162 */
163163 si64 tell () override { return cur_ptr - buf; }
164164
165- /* *
166- * @brief Call this function to change write pointer location; the
165+ /* *
166+ * @brief Call this function to change write pointer location; the
167167 * function can expand file storage.
168168 *
169169 * @return 0 on success, non-zero otherwise (not used).
@@ -176,7 +176,7 @@ namespace ojph {
176176 */
177177 void close () override ;
178178
179- /* *
179+ /* *
180180 * @brief Call this function to access memory file data.
181181 *
182182 * It is not recommended to store the returned value because buffer
@@ -186,8 +186,8 @@ namespace ojph {
186186 */
187187 const ui8* get_data () { return buf; }
188188
189- /* *
190- * @brief Call this function to access memory file data (for const
189+ /* *
190+ * @brief Call this function to access memory file data (for const
191191 * objects)
192192 *
193193 * This is similar to the above function, except that it can be used
@@ -197,7 +197,7 @@ namespace ojph {
197197 */
198198 const ui8* get_data () const { return buf; }
199199
200- /* *
200+ /* *
201201 * @brief Call this function to write the memory file data to a file
202202 *
203203 */
@@ -221,10 +221,10 @@ namespace ojph {
221221 private:
222222 /* *
223223 * @brief This function expands storage by x1.5 needed space.
224- *
224+ *
225225 * It sets cur_ptr correctly, and clears the extended area of the
226226 * buffer. It optionally clear the whole buffer
227- *
227+ *
228228 * @param new_size New size of the buffer
229229 * @param clear_all Set to true to clear whole buffer, not just expansion
230230 */
@@ -237,6 +237,9 @@ namespace ojph {
237237 size_t used_size;
238238 ui8 *buf;
239239 ui8 *cur_ptr;
240+
241+ private:
242+ static const size_t ALIGNED_ALLOC_MASK = 4096 - 1 ;
240243 };
241244
242245 // //////////////////////////////////////////////////////////////////////////
0 commit comments