You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.0 KiB
C++
148 lines
4.0 KiB
C++
4 years ago
|
// ***************************************************************** -*- C++ -*-
|
||
|
/*
|
||
|
* Copyright (C) 2021 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.
|
||
|
*/
|
||
|
|
||
|
// *****************************************************************************
|
||
|
|
||
|
// included header files
|
||
|
#include "config.h"
|
||
|
|
||
4 years ago
|
#include "bmffimage.hpp"
|
||
4 years ago
|
#include "tiffimage.hpp"
|
||
|
#include "image.hpp"
|
||
|
#include "image_int.hpp"
|
||
|
#include "basicio.hpp"
|
||
|
#include "error.hpp"
|
||
|
#include "futils.hpp"
|
||
|
#include "types.hpp"
|
||
|
#include "safe_op.hpp"
|
||
4 years ago
|
#include "unused.h"
|
||
4 years ago
|
|
||
|
// + standard includes
|
||
|
#include <string>
|
||
|
#include <cstring>
|
||
|
#include <iostream>
|
||
|
#include <cassert>
|
||
|
#include <cstdio>
|
||
|
|
||
|
// *****************************************************************************
|
||
|
// class member definitions
|
||
|
namespace Exiv2
|
||
|
{
|
||
|
static bool enabled = false;
|
||
|
|
||
|
EXIV2API bool enableISOBMFF(bool enable)
|
||
|
{
|
||
4 years ago
|
#ifdef EXV_ENABLE_ISOBMFF
|
||
4 years ago
|
enabled = enable;
|
||
4 years ago
|
return true;
|
||
|
#endif//EXV_ENABLE_ISOBMFF
|
||
|
enable = false ;
|
||
|
return enable ;
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
BmffImage::BmffImage(BasicIo::AutoPtr io, bool /* create */)
|
||
4 years ago
|
: Image(ImageType::bmff, mdExif | mdIptc | mdXmp, std::move(io))
|
||
|
{
|
||
4 years ago
|
} // BmffImage::BmffImage
|
||
4 years ago
|
|
||
4 years ago
|
std::string BmffImage::mimeType() const
|
||
4 years ago
|
{
|
||
|
/*
|
||
|
switch (fileType)
|
||
|
{
|
||
|
case ImageType::avif:
|
||
|
return "image/avif";
|
||
|
|
||
|
case ImageType::heif:
|
||
|
return "image/heif";
|
||
|
|
||
|
default:
|
||
|
return "image/unknown";
|
||
|
}
|
||
|
*/
|
||
4 years ago
|
return "image/bmff";
|
||
|
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
void BmffImage::setComment(const std::string& /*comment*/)
|
||
4 years ago
|
{
|
||
|
// Todo: implement me!
|
||
|
throw(Error(kerInvalidSettingForImage, "Image comment", "ISO BMFF"));
|
||
|
} // ISOBMFF::setComment
|
||
|
|
||
4 years ago
|
void BmffImage::readMetadata()
|
||
4 years ago
|
{
|
||
|
} // ISOBMFF::readMetadata
|
||
|
|
||
4 years ago
|
void BmffImage::printStructure(std::ostream& out, PrintStructureOption option, int depth)
|
||
4 years ago
|
{
|
||
|
if (io_->open() != 0)
|
||
|
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
|
||
|
|
||
|
// Ensure that this is the correct image type
|
||
|
if (!isBmffType(*io_, false)) {
|
||
|
if (io_->error() || io_->eof())
|
||
|
throw Error(kerFailedToReadImageData);
|
||
|
throw Error(kerNotAnImage);
|
||
|
}
|
||
4 years ago
|
UNUSED(out);
|
||
|
UNUSED(option);
|
||
|
UNUSED(depth);
|
||
4 years ago
|
} // ISOBMFF::printStructure
|
||
|
|
||
4 years ago
|
void BmffImage::writeMetadata()
|
||
4 years ago
|
{
|
||
4 years ago
|
} // BmffImage::writeMetadata
|
||
4 years ago
|
|
||
|
// *************************************************************************
|
||
|
// free functions
|
||
|
Image::AutoPtr newBmffInstance(BasicIo::AutoPtr io, bool create)
|
||
|
{
|
||
4 years ago
|
Image::AutoPtr image(new BmffImage(std::move(io), create));
|
||
4 years ago
|
if (!image->good())
|
||
|
{
|
||
|
image.reset();
|
||
|
}
|
||
|
return image;
|
||
|
}
|
||
|
|
||
|
bool isBmffType(BasicIo& iIo, bool advance)
|
||
|
{
|
||
|
if (!enabled)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
const int32_t len = 12;
|
||
|
byte buf[len];
|
||
|
iIo.read(buf, len);
|
||
|
if (iIo.error() || iIo.eof())
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
4 years ago
|
|
||
|
bool result = buf[4] == 'f' && buf[5] == 't' && buf[6] == 'y' && buf[7] == 'p';
|
||
4 years ago
|
if (!advance)
|
||
|
{
|
||
|
iIo.seek(-len, BasicIo::cur);
|
||
|
}
|
||
4 years ago
|
return result;
|
||
4 years ago
|
}
|
||
|
} // namespace Exiv2
|