[image_int] Move internal functions into separate translation unit
This commit is contained in:
parent
98bca06592
commit
7a7ae7a1df
@ -103,6 +103,7 @@ set( LIBEXIV2_PRIVATE_SRC
|
||||
cr2header_int.cpp
|
||||
crwimage_int.cpp
|
||||
fujimn_int.cpp
|
||||
image_int.cpp
|
||||
makernote_int.cpp
|
||||
minoltamn_int.cpp
|
||||
nikonmn_int.cpp
|
||||
@ -128,6 +129,7 @@ set( LIBEXIV2_PRIVATE_HDR
|
||||
cr2header_int.hpp
|
||||
crwimage_int.hpp
|
||||
fujimn_int.hpp
|
||||
image_int.hpp
|
||||
makernote_int.hpp
|
||||
minoltamn_int.hpp
|
||||
nikonmn_int.hpp
|
||||
|
||||
116
src/image.cpp
116
src/image.cpp
@ -72,7 +72,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdarg.h>
|
||||
#ifdef _MSC_VER
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
@ -984,118 +983,3 @@ namespace Exiv2 {
|
||||
} // append
|
||||
|
||||
} // namespace Exiv2
|
||||
|
||||
namespace Exiv2 {
|
||||
namespace Internal {
|
||||
|
||||
#ifdef MSDEV_2003
|
||||
#undef vsnprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
||||
std::string stringFormat(const char* format, ...)
|
||||
{
|
||||
std::string result;
|
||||
std::vector<char> buffer;
|
||||
size_t need = std::strlen(format); // initial guess
|
||||
int rc = -1;
|
||||
|
||||
// vsnprintf writes at most size (2nd parameter) bytes (including \0)
|
||||
// returns the number of bytes required for the formatted string excluding \0
|
||||
// the following loop goes through:
|
||||
// one iteration (if 'need' was large enough for the for formatted string)
|
||||
// or two iterations (after the first call to vsnprintf we know the required length)
|
||||
do {
|
||||
buffer.resize(need + 1);
|
||||
va_list args; // variable arg list
|
||||
va_start(args, format); // args start after format
|
||||
rc = vsnprintf(&buffer[0], buffer.size(), format, args);
|
||||
va_end(args); // free the args
|
||||
assert(rc >= 0); // rc < 0 => we have made an error in the format string
|
||||
if ( rc > 0 )
|
||||
need = static_cast<size_t>(rc);
|
||||
} while ( buffer.size() <= need );
|
||||
|
||||
if ( rc > 0 )
|
||||
result = std::string(&buffer[0], need);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string binaryToString(const byte* buff, size_t size, size_t start /*=0*/)
|
||||
{
|
||||
std::string result = "";
|
||||
size += start;
|
||||
|
||||
while (start < size) {
|
||||
int c = (int) buff[start++] ;
|
||||
bool bTrailingNull = c == 0 && start == size;
|
||||
if ( !bTrailingNull ) {
|
||||
if (c < ' ' || c >= 127) c = '.' ;
|
||||
result += (char) c ;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string binaryToString(DataBuf& buf, size_t size, size_t start /*=0*/)
|
||||
{
|
||||
if ( size > (size_t) buf.size_ ) size = (size_t) buf.size_;
|
||||
return binaryToString(buf.pData_,size,start);
|
||||
}
|
||||
|
||||
std::string binaryToHex(const byte *data, size_t size)
|
||||
{
|
||||
std::stringstream hexOutput;
|
||||
|
||||
unsigned long tl = (unsigned long)((size / 16) * 16);
|
||||
unsigned long tl_offset = (unsigned long)(size - tl);
|
||||
|
||||
for (unsigned long loop = 0; loop < (unsigned long)size; loop++) {
|
||||
if (data[loop] < 16) {
|
||||
hexOutput << "0";
|
||||
}
|
||||
hexOutput << std::hex << (int)data[loop];
|
||||
if ((loop % 8) == 7) {
|
||||
hexOutput << " ";
|
||||
}
|
||||
if ((loop % 16) == 15 || loop == (tl + tl_offset - 1)) {
|
||||
int max = 15;
|
||||
if (loop >= tl) {
|
||||
max = tl_offset - 1;
|
||||
for (int offset = 0; offset < (int)(16 - tl_offset); offset++) {
|
||||
if ((offset % 8) == 7) {
|
||||
hexOutput << " ";
|
||||
}
|
||||
hexOutput << " ";
|
||||
}
|
||||
}
|
||||
hexOutput << " ";
|
||||
for (int offset = max; offset >= 0; offset--) {
|
||||
if (offset == (max - 8)) {
|
||||
hexOutput << " ";
|
||||
}
|
||||
byte c = '.';
|
||||
if (data[loop - offset] >= 0x20 && data[loop - offset] <= 0x7E) {
|
||||
c = data[loop - offset] ;
|
||||
}
|
||||
hexOutput << (char) c ;
|
||||
}
|
||||
hexOutput << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
hexOutput << std::endl << std::endl << std::endl;
|
||||
|
||||
return hexOutput.str();
|
||||
}
|
||||
|
||||
std::string indent(int32_t d)
|
||||
{
|
||||
std::string result ;
|
||||
if ( d > 0 )
|
||||
while ( d--)
|
||||
result += " ";
|
||||
return result;
|
||||
}
|
||||
|
||||
}} // namespace Internal, Exiv2
|
||||
|
||||
145
src/image_int.cpp
Normal file
145
src/image_int.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2018 Exiv2 authors
|
||||
* This program is part of the Exiv2 distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "image_int.hpp"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace Exiv2
|
||||
{
|
||||
namespace Internal
|
||||
{
|
||||
#ifdef MSDEV_2003
|
||||
#undef vsnprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
||||
std::string stringFormat(const char* format, ...)
|
||||
{
|
||||
std::string result;
|
||||
std::vector<char> buffer;
|
||||
size_t need = std::strlen(format); // initial guess
|
||||
int rc = -1;
|
||||
|
||||
// vsnprintf writes at most size (2nd parameter) bytes (including \0)
|
||||
// returns the number of bytes required for the formatted string excluding \0
|
||||
// the following loop goes through:
|
||||
// one iteration (if 'need' was large enough for the for formatted string)
|
||||
// or two iterations (after the first call to vsnprintf we know the required length)
|
||||
do {
|
||||
buffer.resize(need + 1);
|
||||
va_list args; // variable arg list
|
||||
va_start(args, format); // args start after format
|
||||
rc = vsnprintf(&buffer[0], buffer.size(), format, args);
|
||||
va_end(args); // free the args
|
||||
assert(rc >= 0); // rc < 0 => we have made an error in the format string
|
||||
if (rc > 0)
|
||||
need = static_cast<size_t>(rc);
|
||||
} while (buffer.size() <= need);
|
||||
|
||||
if (rc > 0)
|
||||
result = std::string(&buffer[0], need);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string binaryToString(const byte* buff, size_t size, size_t start /*=0*/)
|
||||
{
|
||||
std::string result = "";
|
||||
size += start;
|
||||
|
||||
while (start < size) {
|
||||
int c = (int)buff[start++];
|
||||
bool bTrailingNull = c == 0 && start == size;
|
||||
if (!bTrailingNull) {
|
||||
if (c < ' ' || c >= 127)
|
||||
c = '.';
|
||||
result += (char)c;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string binaryToString(const DataBuf& buf, size_t size, size_t start /*=0*/)
|
||||
{
|
||||
if (size > (size_t)buf.size_)
|
||||
size = (size_t)buf.size_;
|
||||
return binaryToString(buf.pData_, size, start);
|
||||
}
|
||||
|
||||
std::string binaryToHex(const byte* data, size_t size)
|
||||
{
|
||||
std::stringstream hexOutput;
|
||||
|
||||
unsigned long tl = (unsigned long)((size / 16) * 16);
|
||||
unsigned long tl_offset = (unsigned long)(size - tl);
|
||||
|
||||
for (unsigned long loop = 0; loop < (unsigned long)size; loop++) {
|
||||
if (data[loop] < 16) {
|
||||
hexOutput << "0";
|
||||
}
|
||||
hexOutput << std::hex << (int)data[loop];
|
||||
if ((loop % 8) == 7) {
|
||||
hexOutput << " ";
|
||||
}
|
||||
if ((loop % 16) == 15 || loop == (tl + tl_offset - 1)) {
|
||||
int max = 15;
|
||||
if (loop >= tl) {
|
||||
max = tl_offset - 1;
|
||||
for (int offset = 0; offset < (int)(16 - tl_offset); offset++) {
|
||||
if ((offset % 8) == 7) {
|
||||
hexOutput << " ";
|
||||
}
|
||||
hexOutput << " ";
|
||||
}
|
||||
}
|
||||
hexOutput << " ";
|
||||
for (int offset = max; offset >= 0; offset--) {
|
||||
if (offset == (max - 8)) {
|
||||
hexOutput << " ";
|
||||
}
|
||||
byte c = '.';
|
||||
if (data[loop - offset] >= 0x20 && data[loop - offset] <= 0x7E) {
|
||||
c = data[loop - offset];
|
||||
}
|
||||
hexOutput << (char)c;
|
||||
}
|
||||
hexOutput << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
hexOutput << std::endl << std::endl << std::endl;
|
||||
|
||||
return hexOutput.str();
|
||||
}
|
||||
|
||||
std::string indent(int32_t d)
|
||||
{
|
||||
std::string result;
|
||||
if (d > 0)
|
||||
while (d--)
|
||||
result += " ";
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
} // namespace Exiv2
|
||||
@ -56,7 +56,7 @@ namespace Exiv2 {
|
||||
/*!
|
||||
@brief format binary for display in \em printStructure() \em .
|
||||
*/
|
||||
std::string binaryToString(DataBuf& buf, size_t size, size_t start =0);
|
||||
std::string binaryToString(const DataBuf& buf, size_t size, size_t start =0);
|
||||
|
||||
/*!
|
||||
@brief format binary for display in \em printStructure() \em .
|
||||
|
||||
Loading…
Reference in New Issue
Block a user