-
Notifications
You must be signed in to change notification settings - Fork 2
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
37 changed files
with
2,931 additions
and
1,830 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: \n" | ||
"Report-Msgid-Bugs-To: [email protected]\n" | ||
"POT-Creation-Date: 2023-11-04 10:14+0000\n" | ||
"POT-Creation-Date: 2023-11-06 13:28+0000\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
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,100 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
|
||
#include "Plugin.h" | ||
#include "stb_image.h" | ||
|
||
class ImageProcessingPlugin : public Plugin | ||
{ | ||
public: | ||
ImageProcessingPlugin(const std::string &path, const std::string &version, const std::string &author, const std::string &description) | ||
: Plugin(path, version, author, description) | ||
{ | ||
} | ||
|
||
void Execute(const std::vector<std::string> &args) override | ||
{ | ||
if (args.empty()) | ||
{ | ||
std::cout << "Usage: image_processing_plugin <image_path>" << std::endl; | ||
return; | ||
} | ||
|
||
std::string imagePath = args[0]; | ||
|
||
// Load the image using stb_image | ||
int width, height, channels; | ||
unsigned char *imageData = stbi_load(imagePath.c_str(), &width, &height, &channels, 0); | ||
if (!imageData) | ||
{ | ||
std::cout << "Failed to load image: " << imagePath << std::endl; | ||
return; | ||
} | ||
|
||
// Perform image processing operations here | ||
// Example: Convert the image to grayscale | ||
unsigned char *grayImageData = convertToGrayscale(imageData, width, height, channels); | ||
|
||
// Save the processed image | ||
std::string outputPath = "processed_image.jpg"; | ||
if (stbi_write_jpg(outputPath.c_str(), width, height, 1, grayImageData, 100) == 0) | ||
{ | ||
std::cout << "Failed to save processed image." << std::endl; | ||
} | ||
else | ||
{ | ||
std::cout << "Processed image saved to: " << outputPath << std::endl; | ||
} | ||
|
||
// Free the allocated memory | ||
stbi_image_free(imageData); | ||
stbi_image_free(grayImageData); | ||
} | ||
|
||
private: | ||
unsigned char *convertToGrayscale(unsigned char *imageData, int width, int height, int channels) | ||
{ | ||
unsigned char *grayImageData = new unsigned char[width * height]; | ||
|
||
if (channels == 1) | ||
{ | ||
memcpy(grayImageData, imageData, width * height); | ||
} | ||
else if (channels == 3) | ||
{ | ||
for (int i = 0; i < width * height; ++i) | ||
{ | ||
unsigned char r = imageData[i * channels]; | ||
unsigned char g = imageData[i * channels + 1]; | ||
unsigned char b = imageData[i * channels + 2]; | ||
unsigned char gray = static_cast<unsigned char>(0.2989 * r + 0.587 * g + 0.114 * b); | ||
grayImageData[i] = gray; | ||
} | ||
} | ||
else if (channels == 4) | ||
{ | ||
for (int i = 0; i < width * height; ++i) | ||
{ | ||
unsigned char r = imageData[i * channels]; | ||
unsigned char g = imageData[i * channels + 1]; | ||
unsigned char b = imageData[i * channels + 2]; | ||
unsigned char a = imageData[i * channels + 3]; | ||
unsigned char gray = static_cast<unsigned char>(0.2989 * r + 0.587 * g + 0.114 * b); | ||
grayImageData[i] = gray; | ||
} | ||
} | ||
|
||
return grayImageData; | ||
} | ||
}; | ||
|
||
// Example usage | ||
int main() | ||
{ | ||
ImageProcessingPlugin plugin("path/to/plugin", "1.0", "Author", "Image processing plugin"); | ||
std::vector<std::string> args = {"path/to/image.jpg"}; | ||
plugin.Execute(args); | ||
|
||
return 0; | ||
} |
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,182 @@ | ||
/* | ||
* hydrogenbasic.cpp | ||
* | ||
* Copyright (C) 2023 Max Qian <lightapt.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/************************************************* | ||
Copyright: 2023 Max Qian. All rights reserved | ||
Author: Max Qian | ||
E-mail: [email protected] | ||
Date: 2023-4-10 | ||
Description: Hydrogen Basic Template | ||
**************************************************/ | ||
|
||
#include "hydrogenbasic.hpp" | ||
|
||
#include "modules/utils/switch.hpp" | ||
|
||
#include "config.h" | ||
|
||
#include "loguru/loguru.hpp" | ||
|
||
HydrogenBasic::HydrogenBasic(const std::string &name) | ||
{ | ||
DLOG_F(INFO, "Hydrogen basic {} init successfully", name); | ||
|
||
m_number_switch = std::make_unique<StringSwitch<INumberVectorProperty *>>(); | ||
m_switch_switch = std::make_unique<StringSwitch<ISwitchVectorProperty *>>(); | ||
m_text_switch = std::make_unique<StringSwitch<ITextVectorProperty *>>(); | ||
} | ||
|
||
HydrogenBasic::~HydrogenBasic() | ||
{ | ||
} | ||
|
||
bool HydrogenBasic::connect(const json ¶ms) | ||
{ | ||
std::string name = params["name"]; | ||
std::string hostname = params["host"]; | ||
int port = params["port"]; | ||
DLOG_F(INFO, "Trying to connect to {}", name); | ||
setServer(hostname.c_str(), port); | ||
// Receive messages only for our camera. | ||
watchDevice(name.c_str()); | ||
// Connect to server. | ||
if (connectServer()) | ||
{ | ||
DLOG_F(INFO, "{}: connectServer done ready", getDeviceName()); | ||
connectDevice(name.c_str()); | ||
return !is_ready.load(); | ||
} | ||
return false; | ||
} | ||
|
||
bool HydrogenBasic::disconnect(const json ¶ms) | ||
{ | ||
DLOG_F(INFO, "%s is disconnected", getDeviceName()); | ||
return true; | ||
} | ||
|
||
bool HydrogenBasic::reconnect(const json ¶ms) | ||
{ | ||
return true; | ||
} | ||
|
||
bool HydrogenBasic::isConnected() | ||
{ | ||
return true; | ||
} | ||
|
||
void HydrogenBasic::newDevice(HYDROGEN::BaseDevice *dp) | ||
{ | ||
if (strcmp(dp->getDeviceName(), getDeviceName().c_str()) == 0) | ||
{ | ||
telescope_device = dp; | ||
} | ||
} | ||
|
||
void HydrogenBasic::newSwitch(ISwitchVectorProperty *svp) | ||
{ | ||
m_switch_switch->match(svp->name, svp); | ||
} | ||
|
||
void HydrogenBasic::newMessage(HYDROGEN::BaseDevice *dp, int messageID) | ||
{ | ||
DLOG_F(INFO, "{} Received message: {}", _name, dp->messageQueue(messageID)); | ||
} | ||
|
||
inline static const char *StateStr(IPState st) | ||
{ | ||
switch (st) | ||
{ | ||
default: | ||
case IPS_IDLE: | ||
return "Idle"; | ||
case IPS_OK: | ||
return "Ok"; | ||
case IPS_BUSY: | ||
return "Busy"; | ||
case IPS_ALERT: | ||
return "Alert"; | ||
} | ||
} | ||
|
||
void HydrogenBasic::newNumber(INumberVectorProperty *nvp) | ||
{ | ||
m_number_switch->match(nvp->name, nvp); | ||
} | ||
|
||
void HydrogenBasic::newText(ITextVectorProperty *tvp) | ||
{ | ||
m_text_switch->match(tvp->name, tvp); | ||
} | ||
|
||
void HydrogenBasic::newBLOB(IBLOB *bp) | ||
{ | ||
DLOG_F(INFO, "{} Received BLOB {} len = {} size = {}", _name, bp->name, bp->bloblen, bp->size); | ||
} | ||
|
||
void HydrogenBasic::newProperty(HYDROGEN::Property *property) | ||
{ | ||
std::string PropName(property->getName()); | ||
HYDROGEN_PROPERTY_TYPE Proptype = property->getType(); | ||
|
||
// DLOG_F(INFO,"{} Property: {}", getDeviceName(), property->getName()); | ||
|
||
if (Proptype == HYDROGEN_NUMBER) | ||
{ | ||
newNumber(property->getNumber()); | ||
} | ||
else if (Proptype == HYDROGEN_SWITCH) | ||
{ | ||
newSwitch(property->getSwitch()); | ||
} | ||
else if (Proptype == HYDROGEN_TEXT) | ||
{ | ||
newText(property->getText()); | ||
} | ||
} | ||
|
||
void HydrogenBasic::IndiServerConnected() | ||
{ | ||
DLOG_F(INFO, "{} connection succeeded", _name); | ||
is_connected.store(true); | ||
} | ||
|
||
void HydrogenBasic::IndiServerDisconnected(int exit_code) | ||
{ | ||
DLOG_F(INFO, "{}: serverDisconnected", _name); | ||
// after disconnection we reset the connection status and the properties pointers | ||
ClearStatus(); | ||
// in case the connection lost we must reset the client socket | ||
if (exit_code == -1) | ||
DLOG_F(INFO, "{} : Hydrogen server disconnected", _name); | ||
} | ||
|
||
void HydrogenBasic::removeDevice(HYDROGEN::BaseDevice *dp) | ||
{ | ||
ClearStatus(); | ||
DLOG_F(INFO, "{} disconnected", _name); | ||
} | ||
|
||
void HydrogenBasic::ClearStatus() | ||
{ | ||
} |
Oops, something went wrong.