forked from scantailor/scantailor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImageMetadata.cpp
82 lines (68 loc) · 2.25 KB
/
ImageMetadata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
Copyright (C) 2007-2009 Joseph Artsimovich <[email protected]>
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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "ImageMetadata.h"
#include "imageproc/Constants.h"
using namespace imageproc::constants;
bool
ImageMetadata::operator==(ImageMetadata const& other) const
{
if (m_size != other.m_size) {
return false;
} else if (m_dpi.isNull() && other.m_dpi.isNull()) {
return true;
} else {
return m_dpi == other.m_dpi;
}
}
bool
ImageMetadata::isDpiOK() const
{
return horizontalDpiStatus() == DPI_OK && verticalDpiStatus() == DPI_OK;
}
ImageMetadata::DpiStatus
ImageMetadata::horizontalDpiStatus() const
{
return dpiStatus(m_size.width(), m_dpi.horizontal());
}
ImageMetadata::DpiStatus
ImageMetadata::verticalDpiStatus() const
{
return dpiStatus(m_size.height(), m_dpi.vertical());
}
ImageMetadata::DpiStatus
ImageMetadata::dpiStatus(int pixel_size, int dpi)
{
if (dpi <= 1) {
return DPI_UNDEFINED;
}
if (dpi < 150) {
return DPI_TOO_SMALL;
}
if (dpi > 9999) {
return DPI_TOO_LARGE;
}
double const mm = INCH2MM * pixel_size / dpi;
if (mm > 500) {
// This may indicate we are working with very large printed materials,
// but most likely it indicates the DPI is wrong (too low).
// DPIs that are too low may easily cause crashes due to out of memory
// conditions. The memory consumption is proportional to:
// (real_hor_dpi / provided_hor_dpi) * (real_vert_dpi / provided_vert_dpi).
// For example, if the real DPI is 600x600 but 200x200 is specified,
// memory consumption is increased 9 times.
return DPI_TOO_SMALL_FOR_THIS_PIXEL_SIZE;
}
return DPI_OK;
}