RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
Common.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2017 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "fuzz/Common.h"
22#include "adt/Casts.h"
23#include "adt/Point.h"
24#include "common/RawImage.h"
25#include "io/Buffer.h"
26#include "io/ByteStream.h"
27#include "io/IOException.h"
29#include <cstdint>
30
32 const uint32_t width = bs.getU32();
33 const uint32_t height = bs.getU32();
34 const uint32_t type = bs.getU32();
35 const uint32_t cpp = bs.getU32();
36 const uint32_t isCFA = bs.getU32();
37
38 if (type != static_cast<uint32_t>(rawspeed::RawImageType::UINT16) &&
39 type != static_cast<uint32_t>(rawspeed::RawImageType::F32))
40 ThrowRSE("Unknown image type: %u", type);
41
44
45 mRaw->dim =
47 static_cast<rawspeed::iPoint2D::value_type>(height));
48 mRaw->setCpp(cpp);
49 mRaw->isCFA = isCFA;
50
51 return mRaw;
52}
53
55 const int32_t cfaWidth = bs.getI32();
56 const int32_t cfaHeight = bs.getI32();
57
58 rawspeed::iPoint2D cfaSize(cfaWidth, cfaHeight);
59 if (!cfaSize.hasPositiveArea())
60 ThrowIOE("Bad CFA size.");
61
63 cfa.setSize(cfaSize);
64 (void)bs.check(
66
67 for (auto x = 0; x < cfaWidth; x++) {
68 for (auto y = 0; y < cfaHeight; y++) {
69 const uint32_t color = bs.getU32();
70 if (color >= static_cast<uint32_t>(rawspeed::CFAColor::END))
71 ThrowRSE("Unknown color: %u", color);
72
74 static_cast<rawspeed::CFAColor>(color));
75 }
76 }
77
78 return cfa;
79}
#define ThrowIOE(...)
Definition IOException.h:37
#define ThrowRSE(...)
dim y
Definition Common.cpp:51
dim x
Definition Common.cpp:50
size_type check(size_type bytes) const
Definition ByteStream.h:63
void setColorAt(iPoint2D pos, CFAColor c)
void setSize(const iPoint2D &size)
void setCpp(uint32_t val)
Definition RawImage.cpp:153
static RawImage create(RawImageType type=RawImageType::UINT16)
Definition RawImage.h:265
area_type RAWSPEED_READONLY area() const
Definition Point.h:81
bool RAWSPEED_READONLY hasPositiveArea() const
Definition Point.h:77
int32_t value_type
Definition Point.h:37
rawspeed::ColorFilterArray CreateCFA(rawspeed::ByteStream &bs)
Definition Common.cpp:54
rawspeed::RawImage CreateRawImage(rawspeed::ByteStream &bs)
Definition Common.cpp:31
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32