sconsの設定ファイル追加。なんだか環境変数を設定しないといけないのがアレだけど、そこだけ環境毎に切り換えれば済むのでまだ幸せなんだろか。。
@@ -8,11 +8,11 @@ | ||
8 | 8 | #include "targetver.h" |
9 | 9 | |
10 | 10 | #include <stdio.h> |
11 | -#include <tchar.h> | |
11 | +//#include <tchar.h> | |
12 | 12 | |
13 | 13 | |
14 | 14 | template <typename T> |
15 | -__forceinline void OffsetPtr(T*& ptr, int offsetBytes) | |
15 | +inline void OffsetPtr(T*& ptr, int offsetBytes) | |
16 | 16 | { |
17 | 17 | ptr = (T*) ((const char*)ptr + offsetBytes); |
18 | 18 | } |
@@ -1,3 +1,5 @@ | ||
1 | + | |
2 | +#include <string.h> | |
1 | 3 | |
2 | 4 | template <typename T> |
3 | 5 | void gather( |
@@ -140,7 +142,7 @@ | ||
140 | 142 | }; |
141 | 143 | |
142 | 144 | enum RiceCoderFlag { |
143 | - None = 0xFF, | |
145 | + RiceCoderFlag_None = 0xFF, | |
144 | 146 | }; |
145 | 147 | |
146 | 148 | size_t compressSub( |
@@ -221,7 +223,7 @@ | ||
221 | 223 | size_t len = 0; |
222 | 224 | if (initialCompressedLen < compressedLen && initialCompressedLen < bytesLen) { |
223 | 225 | *dest++ = 1; |
224 | - *dest++ = RiceCoderFlag::None; | |
226 | + *dest++ = RiceCoderFlag_None; | |
225 | 227 | len = initialCompressedLen; |
226 | 228 | memcpy(dest+4, tmp, len); |
227 | 229 | }else if (compressedLen < bytesLen) { |
@@ -480,7 +482,7 @@ | ||
480 | 482 | len2 = len; |
481 | 483 | } |
482 | 484 | |
483 | - if (b == RiceCoderFlag::None) { | |
485 | + if (b == RiceCoderFlag_None) { | |
484 | 486 | memcpy(dest, tmp, len2); |
485 | 487 | for (size_t i=0; i<len2/4; ++i) { |
486 | 488 | int val = dest[i]; |
@@ -1,8 +1,8 @@ | ||
1 | -#include "stdafx.h" | |
1 | +//#include "stdafx.h" | |
2 | 2 | |
3 | 3 | #include "BZip2Compressor.h" |
4 | 4 | |
5 | -#include "bzlib.h" | |
5 | +#include <bzlib.h> | |
6 | 6 | #pragma comment(lib, "libbz2.lib") |
7 | 7 | |
8 | 8 | size_t BZip2Compressor::Compress( |
@@ -13,7 +13,7 @@ | ||
13 | 13 | ) |
14 | 14 | { |
15 | 15 | size_t compressedLen = destLen; |
16 | - BZ2_bzBuffToBuffCompress((char*)dest, &compressedLen, (char*)src, srcLen, 9, 0, 30); | |
16 | + BZ2_bzBuffToBuffCompress((char*)dest, (unsigned int*)&compressedLen, (char*)src, (unsigned int)srcLen, 9, 0, 30); | |
17 | 17 | return compressedLen; |
18 | 18 | } |
19 | 19 |
@@ -25,7 +25,7 @@ | ||
25 | 25 | ) |
26 | 26 | { |
27 | 27 | size_t decompressedLen = destLen; |
28 | - BZ2_bzBuffToBuffDecompress((char*)dest, &decompressedLen, (char*)src, srcLen, 0, 0); | |
28 | + BZ2_bzBuffToBuffDecompress((char*)dest, (unsigned int*)&decompressedLen, (char*)src, (unsigned int)srcLen, 0, 0); | |
29 | 29 | return decompressedLen; |
30 | 30 | } |
31 | 31 |
@@ -1,4 +1,6 @@ | ||
1 | 1 | #pragma once |
2 | + | |
3 | +#include <stdlib.h> | |
2 | 4 | |
3 | 5 | class ICompressor |
4 | 6 | { |
@@ -18,16 +18,16 @@ | ||
18 | 18 | #include "ReadImage/ReadImage.h" |
19 | 19 | #include "ReadImage/File.h" |
20 | 20 | |
21 | -int _tmain(int argc, _TCHAR* argv[]) | |
21 | +int main(int argc, char* argv[]) | |
22 | 22 | { |
23 | 23 | if (argc < 2) { |
24 | - _tprintf(_T("specify filename\n")); | |
24 | + printf("specify filename\n"); | |
25 | 25 | return 1; |
26 | 26 | } |
27 | 27 | |
28 | - FILE* f = _tfopen(argv[1], _T("rb")); | |
28 | + FILE* f = fopen(argv[1], "rb"); | |
29 | 29 | if (!f) { |
30 | - _tprintf(_T("failed to open file : %s\n"), argv[1]); | |
30 | + printf("failed to open file : %s\n", argv[1]); | |
31 | 31 | return 1; |
32 | 32 | } |
33 | 33 | File fo(f); |
@@ -82,6 +82,6 @@ | ||
82 | 82 | //fwrite(pOutput, 1, size, of); |
83 | 83 | //fclose(of); |
84 | 84 | |
85 | - _tprintf(_T("%f%% %d bytes"), (100.0 * compressedLen) / size, compressedLen); | |
85 | + printf("%f%% %zu bytes", (100.0 * compressedLen) / size, compressedLen); | |
86 | 86 | return 0; |
87 | 87 | } |
@@ -4,8 +4,38 @@ | ||
4 | 4 | |
5 | 5 | #define TRACE printf |
6 | 6 | #include <assert.h> |
7 | +#include <stdio.h> | |
7 | 8 | |
8 | -#include <windows.h> | |
9 | +//#include <windows.h> | |
10 | + | |
11 | +#define BI_BITFIELDS 3 | |
12 | + | |
13 | +typedef unsigned short WORD; | |
14 | +typedef unsigned int DWORD; | |
15 | +typedef long LONG; | |
16 | + | |
17 | +typedef struct tagBITMAPINFOHEADER { | |
18 | + DWORD biSize; | |
19 | + LONG biWidth; | |
20 | + LONG biHeight; | |
21 | + WORD biPlanes; | |
22 | + WORD biBitCount; | |
23 | + DWORD biCompression; | |
24 | + DWORD biSizeImage; | |
25 | + LONG biXPelsPerMeter; | |
26 | + LONG biYPelsPerMeter; | |
27 | + DWORD biClrUsed; | |
28 | + DWORD biClrImportant; | |
29 | +} BITMAPINFOHEADER; | |
30 | + | |
31 | +typedef struct tagBITMAPFILEHEADER { | |
32 | + WORD bfType; | |
33 | + DWORD bfSize; /* DWORD (4バイト) 境界にアラインされていない点に注意.*/ | |
34 | + WORD bfReserved1; | |
35 | + WORD bfReserved2; | |
36 | + DWORD bfOffBits; /* DWORD (4バイト) 境界にアラインされていない点に注意.*/ | |
37 | +} BITMAPFILEHEADER; | |
38 | + | |
9 | 39 | |
10 | 40 | bool Read_BITMAPINFOHEADER(IFile& file, BITMAPINFOHEADER& bmih) |
11 | 41 | { |
@@ -47,7 +77,7 @@ | ||
47 | 77 | |
48 | 78 | bool ReadImageData_BMP(IFile& file, unsigned char* dest, int lineOffset, void* palettes) |
49 | 79 | { |
50 | - file.Seek(0, FILE_BEGIN); | |
80 | + file.Seek(0, SEEK_SET); | |
51 | 81 | BITMAPINFOHEADER bmih; |
52 | 82 | if (!Read_BITMAPINFOHEADER(file, bmih)) { |
53 | 83 | return false; |
@@ -1,60 +1,52 @@ | ||
1 | 1 | #include "stdafx.h" |
2 | 2 | #include "File.h" |
3 | 3 | |
4 | -#include <io.h> | |
4 | +//#include <io.h> | |
5 | 5 | #include <assert.h> |
6 | 6 | #include <memory.h> |
7 | 7 | #include <stdio.h> |
8 | 8 | |
9 | -#include <windows.h> | |
10 | - | |
11 | -File::File(HANDLE hFile) | |
12 | - : | |
13 | - hFile_(hFile) | |
9 | +File::File(FILE* file) | |
14 | 10 | { |
11 | + file_ = file; | |
15 | 12 | } |
16 | 13 | |
17 | -File::File(FILE* pFile) | |
18 | -{ | |
19 | - hFile_ = (HANDLE) _get_osfhandle(_fileno(pFile)); | |
20 | -} | |
21 | - | |
22 | 14 | bool File::Read(void* pBuffer, size_t nNumberOfBytesToRead, size_t& nNumberOfBytesRead) |
23 | -{ | |
24 | - return ReadFile(hFile_, pBuffer, nNumberOfBytesToRead, (LPDWORD)&nNumberOfBytesRead, NULL); | |
15 | +{ | |
16 | + nNumberOfBytesRead = fread(pBuffer, 1, nNumberOfBytesToRead, file_); | |
17 | + return nNumberOfBytesRead; | |
25 | 18 | } |
26 | 19 | |
27 | 20 | bool File::Write(const void* pBuffer, size_t nNumberOfBytesToWrite, size_t& nNumberOfBytesWritten) |
28 | -{ | |
29 | - return WriteFile(hFile_, pBuffer, nNumberOfBytesToWrite, (LPDWORD)&nNumberOfBytesWritten, NULL); | |
21 | +{ | |
22 | + nNumberOfBytesWritten = fwrite(pBuffer, 1, nNumberOfBytesToWrite, file_); | |
23 | + return nNumberOfBytesWritten; | |
30 | 24 | } |
31 | 25 | |
32 | 26 | size_t File::Seek(long lDistanceToMove, size_t dwMoveMethod) |
33 | -{ | |
34 | - return SetFilePointer(hFile_, lDistanceToMove, NULL, dwMoveMethod); | |
27 | +{ | |
28 | + return fseek(file_, lDistanceToMove, dwMoveMethod); | |
35 | 29 | } |
36 | 30 | |
37 | 31 | size_t File::Tell() const |
38 | -{ | |
39 | - /* | |
40 | - -- Reference -- | |
41 | - http://nukz.net/reference/fileio/hh/winbase/filesio_3vhu.htm | |
42 | - */ | |
43 | - return SetFilePointer( | |
44 | - hFile_, // must have GENERIC_READ and/or GENERIC_WRITE | |
45 | - 0, // do not move pointer | |
46 | - NULL, // hFile is not large enough to need this pointer | |
47 | - FILE_CURRENT | |
48 | - ); // provides offset from current position | |
32 | +{ | |
33 | + return ftell(file_); | |
49 | 34 | } |
50 | 35 | |
51 | 36 | size_t File::Size() const |
52 | -{ | |
53 | - return GetFileSize(hFile_, NULL); | |
37 | +{ | |
38 | + fpos_t pos; | |
39 | + fgetpos( file_, &pos ); | |
40 | + fseek( file_, 0, SEEK_END ); | |
41 | + long pos2 = ftell(file_); | |
42 | +// fgetpos( file_, &pos2 ); | |
43 | + fsetpos( file_, &pos ); | |
44 | + return pos2; | |
45 | +// return GetFileSize(hFile_, NULL); | |
54 | 46 | } |
55 | 47 | |
56 | 48 | bool File::Flush() |
57 | 49 | { |
58 | - return FlushFileBuffers(hFile_); | |
50 | + fflush(file_); | |
59 | 51 | } |
60 | 52 |
@@ -2,16 +2,13 @@ | ||
2 | 2 | |
3 | 3 | #include "IFile.h" |
4 | 4 | |
5 | -#include <windows.h> | |
6 | 5 | #include <stdio.h> |
7 | 6 | |
8 | 7 | class File : public IFile |
9 | 8 | { |
10 | 9 | public: |
11 | - File(HANDLE hFile); | |
10 | + File(FILE* file); | |
12 | 11 | |
13 | - File(FILE* pFile); | |
14 | - | |
15 | 12 | bool Read(void* pBuffer, size_t nNumberOfBytesToRead, size_t& nNumberOfBytesRead); |
16 | 13 | |
17 | 14 | bool Write(const void* pBuffer, size_t nNumberOfBytesToWrite, size_t& nNumberOfBytesWritten); |
@@ -28,6 +25,6 @@ | ||
28 | 25 | virtual const void* GetBuffer() const { return 0; } |
29 | 26 | |
30 | 27 | private: |
31 | - HANDLE hFile_; | |
28 | + FILE* file_; | |
32 | 29 | }; |
33 | 30 |
@@ -15,6 +15,8 @@ | ||
15 | 15 | InterfaceをWindowsAPIのFile関数に似せています |
16 | 16 | |
17 | 17 | */ |
18 | + | |
19 | +#include <stdlib.h> | |
18 | 20 | |
19 | 21 | class IFile |
20 | 22 | { |