~ubuntu-branches/ubuntu/saucy/darktable/saucy

« back to all changes in this revision

Viewing changes to src/external/rawspeed/RawSpeed/Common.h

  • Committer: Bazaar Package Importer
  • Author(s): David Bremner
  • Date: 2011-08-02 21:32:31 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110802213231-r9v63trgyk1e822j
Tags: 0.9.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
    RawSpeed - RAW file decoder.
 
3
 
 
4
    Copyright (C) 2009 Klaus Post
 
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
    http://www.klauspost.com
 
21
*/
 
22
#ifndef COMMON_H
 
23
#define COMMON_H
 
24
 
 
25
 
 
26
#if !defined(__unix__) && !defined(__MINGW32__)
 
27
#include <intrin.h>
 
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;
 
32
#else // On linux
 
33
#define _ASSERTE(a) void(a)
 
34
#define _RPT0(a,b) 
 
35
#define _RPT1(a,b,c) 
 
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)
 
43
#ifndef MIN
 
44
#define MIN(a, b)  lmin(a,b)
 
45
typedef unsigned long long uint64;
 
46
#endif
 
47
#ifndef MAX
 
48
#define MAX(a, b)  lmax(a,b)
 
49
#endif
 
50
#ifndef __MINGW32__
 
51
typedef char* LPCWSTR;
 
52
#endif
 
53
#endif // __unix__
 
54
 
 
55
#ifndef TRUE
 
56
#define TRUE 1
 
57
#endif
 
58
#ifndef FALSE
 
59
#define FALSE 0
 
60
#endif
 
61
 
 
62
int rawspeed_get_number_of_processor_cores();
 
63
 
 
64
 
 
65
namespace RawSpeed {
 
66
 
 
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;
 
72
 
 
73
typedef enum Endianness {
 
74
  big, little, unknown
 
75
} Endianness;
 
76
 
 
77
 
 
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);
 
81
    return;
 
82
  }
 
83
  for (int y=height; y>0; --y) {
 
84
    memcpy(dstp, srcp, row_size);
 
85
    dstp += dst_pitch;
 
86
    srcp += src_pitch;
 
87
  }
 
88
}
 
89
inline bool isPowerOfTwo (int val) {
 
90
  return (val & (~val+1)) == val;
 
91
}
 
92
 
 
93
inline int lmin(int p0, int p1) {
 
94
  return p1 + ((p0 - p1) & ((p0 - p1) >> 31));
 
95
}
 
96
inline int lmax(int p0, int p1) {
 
97
  return p0 - ((p0 - p1) & ((p0 - p1) >> 31));
 
98
}
 
99
 
 
100
inline uint32 getThreadCount()
 
101
{
 
102
#ifdef WIN32
 
103
  return pthread_num_processors_np();
 
104
#else
 
105
  return rawspeed_get_number_of_processor_cores();
 
106
#endif
 
107
}
 
108
 
 
109
inline Endianness getHostEndianness() {
 
110
  ushort16 testvar = 0xfeff; 
 
111
  uint32 firstbyte = ((uchar8 *)&testvar)[0];
 
112
  if (firstbyte == 0xff)
 
113
    return little;
 
114
  else if (firstbyte == 0xfe)
 
115
    return big;
 
116
  else
 
117
    _ASSERTE(FALSE);
 
118
 
 
119
  // Return something to make compilers happy
 
120
  return unknown;
 
121
}
 
122
inline uint32 clampbits(int x, uint32 n) { uint32 _y_temp; if( (_y_temp=x>>n) ) x = ~_y_temp >> (32-n); return x;}
 
123
 
 
124
/* Remove all spaces at the end of a string */
 
125
 
 
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
 
130
 
 
131
  // if all spaces or empty return an empty string
 
132
  if ((string::npos == startpos) || (string::npos == endpos)) {
 
133
    str = "";
 
134
  } else
 
135
    str = str.substr(startpos, endpos - startpos + 1);
 
136
}
 
137
 
 
138
 
 
139
} // namespace RawSpeed
 
140
 
 
141
#endif