RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
FileIO.h
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#if !(defined(__unix__) || defined(__APPLE__))
22#ifndef NOMINMAX
23#define NOMINMAX // do not want the min()/max() macros!
24#endif
25
26#include "io/FileIOException.h"
27#include <Windows.h>
28#include <functional>
29#include <io.h>
30#include <tchar.h>
31#include <vector>
32
33namespace rawspeed {
34
35inline std::wstring widenFileName(const char* fileName) {
36 assert(fileName);
37
38 std::wstring wFileName;
39
40 auto f = std::bind(MultiByteToWideChar, CP_UTF8, 0, fileName, -1,
41 std::placeholders::_1, std::placeholders::_2);
42
43 // how many wide characters are needed to store converted string?
44 const auto expectedLen = f(nullptr, 0);
45 wFileName.resize(expectedLen);
46
47 // convert.
48 const auto actualLen = f(&wFileName[0], wFileName.size());
49
50 // did we get expected number of characters?
51 if (actualLen != expectedLen)
52 ThrowFIE("Could not convert filename \"%s\".", fileName);
53
54 return wFileName;
55}
56
57} // namespace rawspeed
58
59#endif
#define ThrowFIE(...)
assert(dim.area() >=area)
std::wstring widenFileName(const char *fileName)
Definition FileIO.h:35