simplify loops
Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
df91578250
commit
498f4ce273
@ -82,6 +82,7 @@ class EXIV2API Jp2Image : public Image {
|
||||
void encodeJp2Header(const DataBuf& boxBuf, DataBuf& outBuf);
|
||||
//@}
|
||||
|
||||
static std::string toAscii(uint32_t n);
|
||||
}; // class Jp2Image
|
||||
|
||||
// *****************************************************************************
|
||||
|
||||
@ -84,17 +84,16 @@ BmffImage::BmffImage(BasicIo::UniquePtr io, bool /* create */) :
|
||||
|
||||
std::string BmffImage::toAscii(uint32_t n) {
|
||||
const auto p = reinterpret_cast<const char*>(&n);
|
||||
std::string result;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
char c = p[isBigEndianPlatform() ? i : (3 - i)];
|
||||
result += [c]() {
|
||||
if (32 <= c && c < 127)
|
||||
return c; // only allow 7-bit printable ascii
|
||||
if (c == 0)
|
||||
return '_'; // show 0 as _
|
||||
return '.'; // others .
|
||||
}();
|
||||
}
|
||||
std::string result(4, '.');
|
||||
std::transform(p, p + 4, result.begin(), [](char c) {
|
||||
if (32 <= c && c < 127)
|
||||
return c; // only allow 7-bit printable ascii
|
||||
if (c == 0)
|
||||
return '_'; // show 0 as _
|
||||
return '.'; // others .
|
||||
});
|
||||
if (!isBigEndianPlatform())
|
||||
std::reverse(result.begin(), result.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -72,26 +72,6 @@ void lf(std::ostream& out, bool& bLF) {
|
||||
}
|
||||
}
|
||||
|
||||
bool isBigEndian() {
|
||||
union {
|
||||
uint32_t i;
|
||||
char c[4];
|
||||
} e = {0x01000000};
|
||||
|
||||
return e.c[0] != 0;
|
||||
}
|
||||
|
||||
// Obtains the ascii version from the box.type
|
||||
std::string toAscii(long n) {
|
||||
const auto p = reinterpret_cast<const char*>(&n);
|
||||
std::string result;
|
||||
bool bBigEndian = isBigEndian();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
result += p[bBigEndian ? i : (3 - i)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void boxes_check(size_t b, size_t m) {
|
||||
if (b > m) {
|
||||
#ifdef EXIV2_DEBUG_MESSAGES
|
||||
@ -117,6 +97,15 @@ Jp2Image::Jp2Image(BasicIo::UniquePtr io, bool create) : Image(ImageType::jp2, m
|
||||
}
|
||||
}
|
||||
|
||||
// Obtains the ascii version from the box.type
|
||||
std::string Jp2Image::toAscii(uint32_t n) {
|
||||
const auto p = reinterpret_cast<const char*>(&n);
|
||||
std::string result(p, p + 4);
|
||||
if (!isBigEndianPlatform())
|
||||
std::reverse(result.begin(), result.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Jp2Image::mimeType() const {
|
||||
return "image/jp2";
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user