2
RawSpeed - RAW file decoder.
4
Copyright (C) 2009 Klaus Post
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.
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.
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
20
http://www.klauspost.com
26
#if !defined(__unix__) && !defined(__MINGW32__)
28
#pragma intrinsic(_ReturnAddress)
29
#define MIN(a,b) min(a,b)
30
#define MAX(a,b) max(a,b)
31
typedef unsigned __int64 uint64;
33
#define _ASSERTE(a) void(a)
36
#define _RPT2(a,b,c,d)
37
#define _RPT3(a,b,c,d,e)
38
#define _RPT4(a,b,c,d,e,f)
39
#define __inline inline
40
#define _strdup(a) strdup(a)
41
void* _aligned_malloc(size_t bytes, size_t alignment);
42
#define _aligned_free(a) do { free(a); } while (0)
44
#define MIN(a, b) lmin(a,b)
45
typedef unsigned long long uint64;
48
#define MAX(a, b) lmax(a,b)
51
typedef char* LPCWSTR;
62
int rawspeed_get_number_of_processor_cores();
67
typedef signed char char8;
68
typedef unsigned char uchar8;
69
typedef unsigned int uint32;
70
typedef signed int int32;
71
typedef unsigned short ushort16;
73
typedef enum Endianness {
78
inline void BitBlt(uchar8* dstp, int dst_pitch, const uchar8* srcp, int src_pitch, int row_size, int height) {
79
if (height == 1 || (dst_pitch == src_pitch && src_pitch == row_size)) {
80
memcpy(dstp, srcp, row_size*height);
83
for (int y=height; y>0; --y) {
84
memcpy(dstp, srcp, row_size);
89
inline bool isPowerOfTwo (int val) {
90
return (val & (~val+1)) == val;
93
inline int lmin(int p0, int p1) {
94
return p1 + ((p0 - p1) & ((p0 - p1) >> 31));
96
inline int lmax(int p0, int p1) {
97
return p0 - ((p0 - p1) & ((p0 - p1) >> 31));
100
inline uint32 getThreadCount()
103
return pthread_num_processors_np();
105
return rawspeed_get_number_of_processor_cores();
109
inline Endianness getHostEndianness() {
110
ushort16 testvar = 0xfeff;
111
uint32 firstbyte = ((uchar8 *)&testvar)[0];
112
if (firstbyte == 0xff)
114
else if (firstbyte == 0xfe)
119
// Return something to make compilers happy
122
inline uint32 clampbits(int x, uint32 n) { uint32 _y_temp; if( (_y_temp=x>>n) ) x = ~_y_temp >> (32-n); return x;}
124
/* Remove all spaces at the end of a string */
126
inline void TrimSpaces(string& str) {
127
// Trim Both leading and trailing spaces
128
size_t startpos = str.find_first_not_of(" \t"); // Find the first character position after excluding leading blank spaces
129
size_t endpos = str.find_last_not_of(" \t"); // Find the first character position from reverse af
131
// if all spaces or empty return an empty string
132
if ((string::npos == startpos) || (string::npos == endpos)) {
135
str = str.substr(startpos, endpos - startpos + 1);
139
} // namespace RawSpeed