Skip to content

Commit

Permalink
Improved GDI
Browse files Browse the repository at this point in the history
  • Loading branch information
webdel-dd committed Jan 25, 2021
1 parent aed7546 commit 132fea1
Show file tree
Hide file tree
Showing 43 changed files with 5,482 additions and 4,572 deletions.
8 changes: 6 additions & 2 deletions app_desktop/desktop.py
Expand Up @@ -724,7 +724,7 @@ def _get_linux_envirionment(self,uid,tty):
arcmd = scmd.split("/")
if len(arcmd)>0:
scmd=arcmd[len(arcmd)-1]
if scmd.upper()=="X" or scmd.upper()=="XORG":
if scmd.upper()=="X" or "XORG" in scmd.upper():
bok=True
elif scmd.upper()=="XWAYLAND":
bwaylanderr=True
Expand Down Expand Up @@ -769,6 +769,10 @@ def _get_linux_envirionment(self,uid,tty):
os.close(fd)
except:
None

if "XAUTHORITY" not in lstret and (uid!=-1 or tty is not None):
return self._get_linux_envirionment(-1, None)

'''
if "DISPLAY" in lstret:
self._agent_main.write_info("DISPLAY: " + lstret["DISPLAY"])
Expand Down Expand Up @@ -837,7 +841,7 @@ def _get_console(self):
try:
stty=native.get_instance().get_tty_active()
if stty is not None:
return {"id": stty}
return {"id": stty}
except:
None

Expand Down
108 changes: 108 additions & 0 deletions lib_gdi/src/imagereader.cpp
@@ -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();
}
}
33 changes: 33 additions & 0 deletions lib_gdi/src/imagereader.h
@@ -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_ */
149 changes: 149 additions & 0 deletions lib_gdi/src/jsonwriter.cpp
@@ -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;
}
}


38 changes: 38 additions & 0 deletions lib_gdi/src/jsonwriter.h
@@ -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_ */

0 comments on commit 132fea1

Please sign in to comment.