-
Notifications
You must be signed in to change notification settings - Fork 0
/
djpls.cpp
73 lines (65 loc) · 1.82 KB
/
djpls.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
// Copyright (c) Mathieu Malaterre
// SPDX-License-Identifier: BSD-3-Clause
#include "cjpls_options.h"
#include "djpls_options.h"
#include "factory.h"
#include "image.h"
#include "jls.h"
#include "pnm.h"
#include "raw.h"
#include <iostream>
#include <vector>
// compute output format (do not inspect source)
static std::unique_ptr<jlst::format> get_format(jlst::djpls_options& options)
{
jlst::format* ptr = jlst::factory::instance().get_format_from_type(options.get_type());
if (ptr)
return std::unique_ptr<jlst::format>(ptr);
throw std::invalid_argument("no format");
}
static void decode(jlst::djpls_options& options)
{
jlst::image input_image;
std::unique_ptr<jlst::format> jls_format(jlst::factory::instance().get_format_from_type("jls"));
input_image = jls_format->load(options.get_source(0), input_image.get_image_info());
auto format = get_format(options);
jlst::jls_options jo{};
format->save(options.get_dest(0), input_image, jo);
}
int main(int argc, char* argv[])
{
jlst::djpls_options options{};
try
{
if (!options.process(argc, argv))
{
// help, or version requested. Return without error
return EXIT_SUCCESS;
}
}
catch (std::exception& e)
{
std::cerr << "Invalid options: " << e.what() << std::endl;
return EXIT_FAILURE;
}
catch (...)
{
std::cerr << "unknown exception during options parsing" << std::endl;
return EXIT_FAILURE;
}
try
{
decode(options);
}
catch (std::exception& e)
{
std::cerr << "Error during decoding: " << e.what() << std::endl;
return EXIT_FAILURE;
}
catch (...)
{
std::cerr << "unknown exception during decoding" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}