Permalink
Browse files

Completato server con rotazione e flipping

  • Loading branch information...
indrimuska committed Apr 9, 2012
1 parent d0c08f9 commit 206fc7bbc8c587ad0c0b7489b81c9d7ca361d84f
@@ -20,7 +20,7 @@ class HorizontalFlipService : public ImageManipulation {
Response response;
string inFile = workDirectory + "/source.gif";
string outFile = workDirectory + "/flipped.gif";
- getImageFromBuffer(inParameters[0], inFile);
+ getImageFromBuffer(inParameters[0], inFile, true);
CImg<unsigned char> image(inFile.c_str());
image.mirror('x').save(outFile.c_str());
putImageInBuffer(outParameters[0], outFile);
@@ -14,18 +14,16 @@ ImageManipulation::ImageManipulation() {
ImageManipulation::ImageManipulation(string workDirectory) {
this->workDirectory = workDirectory;
}
-bool ImageManipulation::getImageFromBuffer(parameter &p, string filename) {
+bool ImageManipulation::getImageFromBuffer(parameter &p, string filename, bool hideWarning) {
FILE * file;
- if ((file = fopen(filename.c_str(), "w")) != 0) {
+ if (!hideWarning && (file = fopen(filename.c_str(), "r")) != 0) {
+ fclose(file);
char response;
cout << "Il file '" << filename << "' esiste già. Sovrascriverlo [Y/N]? ";
while (response != 'Y' && response != 'N' && response != 'S') {
cin >> response;
response = toupper(response);
- if (response == 'N') {
- fclose(file);
- return false;
- }
+ if (response == 'N') return false;
}
}
if (!(file = fopen(filename.c_str(), "w"))) {
@@ -22,7 +22,7 @@ class ImageManipulation : public Service {
protected:
string workDirectory;
- bool getImageFromBuffer(parameter &p, string filename);
+ bool getImageFromBuffer(parameter &p, string filename, bool hideWarning = false);
bool putImageInBuffer(parameter &p, string filename);
public:
ImageManipulation();
@@ -20,7 +20,7 @@ class RotateService : public ImageManipulation {
bool execute(Socket * sk) {
string inFile = workDirectory + "/source.gif";
string outFile = workDirectory + "/rotated.gif";
- getImageFromBuffer(inParameters[1], inFile);
+ getImageFromBuffer(inParameters[1], inFile, true);
int degrees;
inParameters[0].getValue(degrees);
CImg<unsigned char> image(inFile.c_str());
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit 206fc7b

Please sign in to comment.