Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
5,482 additions
and
4,572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla | ||
Public License, v. 2.0. If a copy of the MPL was not distributed | ||
with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "imagereader.h" | ||
|
||
|
||
ImageReader::ImageReader(){ | ||
bloaded=false; | ||
width=0; | ||
height=0; | ||
bits=0; | ||
} | ||
|
||
void ImageReader::destroy() { | ||
bloaded=false; | ||
width=0; | ||
height=0; | ||
bits=0; | ||
} | ||
|
||
void ImageReader::load(const wchar_t* iconPath){ | ||
readBMP(iconPath); | ||
} | ||
|
||
bool ImageReader::isLoaded(){ | ||
return bloaded; | ||
} | ||
|
||
int ImageReader::getWidth(){ | ||
return width; | ||
} | ||
|
||
int ImageReader::getHeight(){ | ||
return height; | ||
} | ||
|
||
void ImageReader::getPixel(unsigned int x, unsigned int y, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a){ | ||
if (bloaded && x<(unsigned int)width && y<(unsigned int)height){ | ||
y=(height-1)-y; | ||
unsigned int chl = bits/8; | ||
*b = data[chl*(y*width+x)+0]; | ||
*g = data[chl*(y*width+x)+1]; | ||
*r = data[chl*(y*width+x)+2]; | ||
if (chl==4){ | ||
*a = data[chl*(y*width+x)+3]; | ||
}else{ | ||
*a = 255; | ||
} | ||
} | ||
} | ||
|
||
void ImageReader::readBMP(const wchar_t* iconPath) { | ||
int sz=wcstombs(NULL,iconPath,0); | ||
char fname[sz]; | ||
wcstombs(fname,iconPath,sz*sizeof(wchar_t)); | ||
std::ifstream inp(fname, std::ios_base::binary); | ||
if (inp) { | ||
int posType=0; | ||
int posOffset=posType+2+4+2+2; | ||
int posWidthHeight=posOffset+4+4; | ||
int posBits=posWidthHeight+4+4+2; | ||
|
||
//READ TYPE | ||
unsigned short type; | ||
inp.read((char*)&type, 2); | ||
if(type == 0x4D42) { | ||
//READ OFFSET | ||
unsigned int offset; | ||
inp.seekg(posOffset, inp.beg); | ||
inp.read((char*)&offset, 4); | ||
|
||
//READ width/weight | ||
inp.seekg(posWidthHeight, inp.beg); | ||
inp.read((char*)&width, 4); | ||
inp.read((char*)&height, 4); | ||
|
||
//READ bits | ||
inp.seekg(posBits, inp.beg); | ||
inp.read((char*)&bits, 2); | ||
|
||
if ((width>0) && (height>0)){ | ||
data.resize(width * height * bits / 8); | ||
inp.seekg(offset, inp.beg); | ||
if (width % 4 == 0) { | ||
inp.read((char*)data.data(), data.size()); | ||
}else{ | ||
unsigned int sizerow = width * (bits / 8); | ||
unsigned int sizeapp = sizerow; | ||
while (sizeapp % 4 != 0) { | ||
sizeapp++; | ||
} | ||
int skiprow = sizeapp-sizerow; | ||
for (int y = 0; y < height; ++y) { | ||
inp.read((char*)(data.data() + sizerow * y), sizerow); | ||
if (skiprow>0){ | ||
inp.seekg(skiprow, inp.cur); | ||
} | ||
} | ||
} | ||
bloaded=true; | ||
} | ||
} | ||
inp.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla | ||
Public License, v. 2.0. If a copy of the MPL was not distributed | ||
with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#ifndef IMAGEREADER_H_ | ||
#define IMAGEREADER_H_ | ||
|
||
#include <fstream> | ||
#include <vector> | ||
#include <iostream> | ||
|
||
class ImageReader{ | ||
public: | ||
ImageReader(); | ||
void load(const wchar_t* iconPath); | ||
int getWidth(); | ||
int getHeight(); | ||
void getPixel(unsigned int x, unsigned int y, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a); | ||
bool isLoaded(); | ||
void destroy(); | ||
|
||
private: | ||
void readBMP(const wchar_t* iconPath); | ||
std::vector<unsigned char> data; | ||
int width; | ||
int height; | ||
int bits; | ||
bool bloaded; | ||
}; | ||
|
||
#endif /* IMAGEREADER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla | ||
Public License, v. 2.0. If a copy of the MPL was not distributed | ||
with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "jsonwriter.h" | ||
|
||
|
||
JSONWriter::JSONWriter(){ | ||
} | ||
|
||
void JSONWriter::beginObject(){ | ||
data.append(L"{"); | ||
} | ||
|
||
void JSONWriter::endObject(){ | ||
if (data.substr(data.length()-1).compare(L",")==0){ | ||
data.erase(data.length()-1); | ||
} | ||
data.append(L"},"); | ||
} | ||
|
||
void JSONWriter::beginArray(){ | ||
data.append(L"["); | ||
} | ||
|
||
void JSONWriter::endArray(){ | ||
if (data.substr(data.length()-1).compare(L",")==0){ | ||
data.erase(data.length()-1); | ||
} | ||
data.append(L"],"); | ||
} | ||
|
||
void JSONWriter::addProp(wstring name){ | ||
data.append(L"\""); | ||
data.append(name); | ||
data.append(L"\""); | ||
data.append(L": "); | ||
} | ||
|
||
void JSONWriter::addString(wstring name, wstring value){ | ||
addProp(name); | ||
data.append(L"\""); | ||
wstring escstr; | ||
escstr.reserve(value.length()); | ||
for (std::string::size_type i = 0; i < value.length(); ++i){ | ||
switch (value[i]) { | ||
case L'"': | ||
escstr += L"\\\""; | ||
break; | ||
case L'/': | ||
escstr += L"\\/"; | ||
break; | ||
case L'\b': | ||
escstr += L"\\b"; | ||
break; | ||
case L'\f': | ||
escstr += L"\\f"; | ||
break; | ||
case L'\n': | ||
escstr += L"\\n"; | ||
break; | ||
case L'\r': | ||
escstr += L"\\r"; | ||
break; | ||
case L'\t': | ||
escstr += L"\\t"; | ||
break; | ||
case L'\\': | ||
escstr += L"\\\\"; | ||
break; | ||
default: | ||
escstr += value[i]; | ||
break; | ||
} | ||
|
||
} | ||
data.append(escstr); | ||
data.append(L"\","); | ||
} | ||
|
||
|
||
void JSONWriter::addNumber(wstring name,int value){ | ||
addProp(name); | ||
//data.append(std::to_wstring(value)); | ||
wostringstream appss; | ||
appss << value; | ||
data.append(appss.str()); | ||
data.append(L","); | ||
} | ||
|
||
void JSONWriter::addNumber(wstring name, long value){ | ||
addProp(name); | ||
//data.append(std::to_wstring(value)); | ||
wostringstream appss; | ||
appss << value; | ||
data.append(appss.str()); | ||
data.append(L","); | ||
} | ||
|
||
void JSONWriter::addNumber(wstring name, unsigned long value){ | ||
addProp(name); | ||
//data.append(std::to_wstring(value)); | ||
wostringstream appss; | ||
appss << value; | ||
data.append(appss.str()); | ||
data.append(L","); | ||
} | ||
|
||
void JSONWriter::addNumber(wstring name, unsigned long long value){ | ||
addProp(name); | ||
//data.append(std::to_wstring(value)); | ||
wostringstream appss; | ||
appss << value; | ||
data.append(appss.str()); | ||
data.append(L","); | ||
} | ||
|
||
void JSONWriter::addBoolean(wstring name, bool value){ | ||
addProp(name); | ||
//data.append(std::to_wstring(value)); | ||
wostringstream appss; | ||
appss << value; | ||
data.append(appss.str()); | ||
data.append(L","); | ||
} | ||
|
||
void JSONWriter::clear(){ | ||
data.clear(); | ||
} | ||
|
||
int JSONWriter::length(){ | ||
if ((data.length()>0) && (data.substr(data.length()-1).compare(L",")==0)){ | ||
return data.length()-1; | ||
}else{ | ||
return data.length(); | ||
} | ||
} | ||
|
||
wstring JSONWriter::getString(){ | ||
if ((data.length()>0) && (data.substr(data.length()-1).compare(L",")==0)){ | ||
return data.substr(0,data.length()-1); | ||
}else{ | ||
return data; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla | ||
Public License, v. 2.0. If a copy of the MPL was not distributed | ||
with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <string> | ||
#include <sstream> | ||
|
||
using namespace std; | ||
|
||
#ifndef JSONWRITER_H_ | ||
#define JSONWRITER_H_ | ||
|
||
class JSONWriter{ | ||
public: | ||
JSONWriter(); | ||
void beginObject(); | ||
void endObject(); | ||
void beginArray(); | ||
void endArray(); | ||
void addString(wstring name, wstring value); | ||
void addNumber(wstring name,int value); | ||
void addNumber(wstring name,long value); | ||
void addNumber(wstring name,unsigned long value); | ||
void addNumber(wstring name,unsigned long long value); | ||
void addBoolean(wstring name, bool value); | ||
void clear(); | ||
int length(); | ||
wstring getString(); | ||
|
||
|
||
private: | ||
wstring data; | ||
void addProp(wstring name); | ||
}; | ||
|
||
#endif /* JSONWRITER_H_ */ |
Oops, something went wrong.