Skip to content

Commit 434b550

Browse files
authored
ENH: fix creation date output in header and some associated refactoring
BUG: fix creation date output in header write STYLE: Move unrelated data manipulation functions out of main class STYLE: Add and update doxygen comments for functions BUG: remove deprecated sprintf
1 parent 1d9ee25 commit 434b550

File tree

5 files changed

+505
-356
lines changed

5 files changed

+505
-356
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*=========================================================================
2+
*
3+
* Copyright NumFOCUS
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0.txt
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*=========================================================================*/
18+
#ifndef itkScancoDataManipulation_h
19+
#define itkScancoDataManipulation_h
20+
#include <cstddef>
21+
22+
/** Check the file header to see what type of file it is.
23+
*
24+
* \param header A pointer to the first 16 bytes of the file header.
25+
* \return 0 if unrecognized, 1 if ISQ/RAD,
26+
* 2 if AIM 020, 3 if AIM 030.
27+
*/
28+
int
29+
CheckVersion(const char header[16]);
30+
31+
/** Convert char data to 32-bit int (little-endian).
32+
*
33+
* \param data Pointer to a buffer of at least 4 bytes.
34+
* \return The decoded integer value.
35+
*/
36+
int
37+
DecodeInt(const void * data);
38+
39+
/** Convert 32-bit int (little-endian) to char data.
40+
*
41+
* \param data The integer to convert.
42+
* \param target Pointer to a buffer of at least 4 bytes to store the result.
43+
*/
44+
void
45+
EncodeInt(int data, void * target);
46+
47+
/** Convert char data to float (single precision).
48+
*
49+
* \param data Pointer to a buffer of at least 4 bytes.
50+
* \return The decoded float value.
51+
*/
52+
float
53+
DecodeFloat(const void * data);
54+
55+
/** Convert char data to float (double precision).
56+
*
57+
* \param data Pointer to a buffer of at least 8 bytes.
58+
* \return The decoded double value.
59+
*/
60+
double
61+
DecodeDouble(const void * data);
62+
63+
/** Convert a VMS timestamp to a calendar date.
64+
*
65+
* \param data Pointer to a buffer of at least 8 bytes containing the VMS timestamp.
66+
* \param year The extracted Gregorian year.
67+
* \param month The extracted Gregorian month (1-12).
68+
* \param day The extracted Gregorian day (1-31).
69+
* \param hour The extracted hour (0-23).
70+
* \param minute The extracted minute (0-59).
71+
* \param second The extracted second (0-59).
72+
* \param millis The extracted milliseconds (0-999).
73+
*/
74+
void
75+
DecodeDate(const void * data, int & year, int & month, int & day, int & hour, int & minute, int & second, int & millis);
76+
77+
/** Convert the current calendar date to a VMS timestamp and store in target
78+
*
79+
* \param target Pointer to a buffer of at least 8 bytes to store the VMS timestamp.
80+
*/
81+
void
82+
EncodeCurrentDate(void * target);
83+
84+
/** Convert a calendar date to VMS timestamp
85+
*
86+
* \param target Pointer to a buffer of at least 8 bytes to store the timestamp.
87+
* \param dateString A string in the format "YYYY-MM-DD HH:MM:SS.mmm"
88+
*/
89+
void
90+
EncodeDateFromString(void * target, const char dateString[32]);
91+
92+
/** Strip a string by removing trailing whitespace.
93+
*
94+
* \attention dest must have a size of at least l+1.
95+
* \param dest The destination string to be stripped.
96+
* \param source The source string to copy from.
97+
* \param length The total length of the destination string.
98+
*/
99+
void
100+
StripString(char * dest, const char * source, size_t length);
101+
102+
/** Pad a string with spaces to a specified length.
103+
*
104+
* \attention dest must have a size of at least l+1.
105+
* \param dest The destination string to be padded.
106+
* \param source The source string to copy from.
107+
* \param length The total length of the destination string after padding.
108+
*/
109+
void
110+
PadString(char * dest, const char * source, size_t length);
111+
112+
#endif // itkScancoDataManipulation_h

include/itkScancoImageIO.h

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ class IOScanco_EXPORT ScancoImageIO : public ImageIOBase
8585

8686
/** The different types of ImageIO's can support data of varying
8787
* dimensionality. For example, some file formats are strictly 2D
88-
* while others can support 2D, 3D, or even n-D. This method returns
89-
* true/false as to whether the ImageIO can support the dimension
90-
* indicated. */
88+
* while others can support 2D, 3D, or even n-D.
89+
* \param dimension The dimension to check for support.
90+
* \return True if the dimension is supported by ScancoIO, false otherwise.
91+
*/
9192
bool
9293
SupportsDimension(unsigned long dimension) override
9394
{
@@ -311,52 +312,6 @@ class IOScanco_EXPORT ScancoImageIO : public ImageIOBase
311312
PrintSelf(std::ostream & os, Indent indent) const override;
312313

313314
private:
314-
/** Check the file header to see what type of file it is.
315-
*
316-
* Return values are: 0 if unrecognized, 1 if ISQ/RAD,
317-
* 2 if AIM 020, 3 if AIM 030.
318-
*/
319-
int
320-
CheckVersion(const char header[16]);
321-
322-
/** Convert char data to 32-bit int (little-endian). */
323-
static int
324-
DecodeInt(const void * data);
325-
/** Convert 32-bit int (little-endian) to char data. */
326-
static void
327-
EncodeInt(int data, void * target);
328-
329-
/** Convert char data to float (single precision). */
330-
static float
331-
DecodeFloat(const void * data);
332-
333-
/** Convert char data to float (double precision). */
334-
static double
335-
DecodeDouble(const void * data);
336-
337-
//! Convert a VMS timestamp to a calendar date.
338-
void
339-
DecodeDate(const void * data,
340-
int & year,
341-
int & month,
342-
int & day,
343-
int & hour,
344-
int & minute,
345-
int & second,
346-
int & millis);
347-
//! Convert the current calendar date to a VMS timestamp and store in target
348-
void
349-
EncodeDate(void * target);
350-
351-
//! Strip a string by removing trailing whitespace.
352-
/*!
353-
* The dest must have a size of at least l+1.
354-
*/
355-
static void
356-
StripString(char * dest, const char * source, size_t length);
357-
static void
358-
PadString(char * dest, const char * source, size_t length);
359-
360315
/** Rescale the image data to Hounsfield Units */
361316
template <typename TBufferType>
362317
void

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(IOScanco_SRCS
2+
itkScancoDataManipulation.cxx
23
itkScancoImageIO.cxx
34
itkScancoImageIOFactory.cxx
45
)

0 commit comments

Comments
 (0)