-
Notifications
You must be signed in to change notification settings - Fork 0
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
ben
committed
May 14, 2023
1 parent
6dfa05e
commit 661baa0
Showing
13 changed files
with
167 additions
and
66 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
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
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,60 @@ | ||
|
||
#include "JpgExtractor.h" | ||
#include "common/exceptions/FileAccessException.hpp" | ||
#include "common/exceptions/AllocationException.hpp" | ||
#include <future> | ||
#include <vector> | ||
#include <jpeglib.h> | ||
|
||
namespace am | ||
{ | ||
namespace extraction | ||
{ | ||
using namespace common::types; | ||
|
||
|
||
Matrix<Color24b> JpgExtractor::readFile(const std::string &fileName) | ||
{ | ||
struct jpeg_decompress_struct cinfo; | ||
struct jpeg_error_mgr jerr; | ||
|
||
FILE* infile = fopen(fileName.c_str(), "rb"); | ||
if (!infile) { | ||
std::string errMsg = "File '" + fileName + "' could not be found!"; | ||
throw common::exceptions::FileAccessException(errMsg); | ||
} | ||
|
||
cinfo.err = jpeg_std_error(&jerr); | ||
jpeg_create_decompress(&cinfo); | ||
jpeg_stdio_src(&cinfo, infile); | ||
jpeg_read_header(&cinfo, TRUE); | ||
jpeg_start_decompress(&cinfo); | ||
|
||
JSAMPARRAY buffer; | ||
buffer = (JSAMPARRAY)malloc(sizeof(JSAMPROW) * cinfo.output_height); | ||
for (int i = 0; i < cinfo.output_height; i++) | ||
{ | ||
buffer[i] = (JSAMPROW)malloc(sizeof(JSAMPLE) * cinfo.output_width * cinfo.output_components); | ||
} | ||
while (cinfo.output_scanline < cinfo.output_height) | ||
{ | ||
jpeg_read_scanlines(&cinfo, buffer + cinfo.output_scanline, cinfo.output_height - cinfo.output_scanline); | ||
} | ||
Matrix<Color24b> data(cinfo.output_width, cinfo.output_height); | ||
for (int i = 0; i < cinfo.output_height; i++) | ||
{ | ||
for (int j = 0; j < cinfo.output_width; j++) | ||
{ | ||
Color24b c24= reinterpret_cast<Color24b&>(buffer[i][j]); | ||
//printf("%d %d %d\n", c24.r, c24.g, c24.b); | ||
data(i, j) = c24; | ||
} | ||
} | ||
jpeg_finish_decompress(&cinfo); | ||
jpeg_destroy_decompress(&cinfo); | ||
fclose(infile); | ||
|
||
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,21 @@ | ||
#pragma once | ||
|
||
#include "common/types/Matrix.hpp" | ||
#include "common/types/Color24b.hpp" | ||
|
||
namespace am | ||
{ | ||
namespace extraction | ||
{ | ||
/// JpgExtractor class for RGB data extraction from JPG/JPEG file | ||
class JpgExtractor | ||
{ | ||
public: | ||
JpgExtractor() = default; | ||
~JpgExtractor() = default; | ||
|
||
static common::types::Matrix<common::types::Color24b> readFile(const std::string &filePath); | ||
}; | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
|
||
#include "MultipleExtractor.h" | ||
#include <future> | ||
#include "BmpExtractor.h" | ||
#include "JpgExtractor.h" | ||
#include "common/types/Color24b.hpp" | ||
|
||
namespace am | ||
{ | ||
namespace extraction | ||
{ | ||
using namespace common::types; | ||
|
||
MultipleExtractor::MultipleExtractor(std::shared_ptr<am::common::Logger> &logger, bool is_bmp) | ||
: mLogger(logger), | ||
mIsForBmp(is_bmp) | ||
{ | ||
} | ||
|
||
std::vector<Matrix<Color24b>> MultipleExtractor::readFiles(std::vector<std::string> &&fileNames) | ||
{ | ||
std::vector<Matrix<Color24b>> result; | ||
result.reserve(fileNames.size()); | ||
std::vector<std::future<Matrix<Color24b>>> futures; | ||
|
||
for (size_t i = 0; i < fileNames.size(); ++i) | ||
{ | ||
if(mIsForBmp) | ||
futures.emplace_back(std::async(std::launch::deferred, BmpExtractor::readFile, fileNames[i])); | ||
else | ||
futures.emplace_back(std::async(std::launch::deferred, JpgExtractor::readFile, fileNames[i])); | ||
|
||
mLogger->info("Reading of file:%s has been added in extraction queue.", fileNames[i].c_str()); | ||
} | ||
|
||
for (auto &e : futures) | ||
{ | ||
result.emplace_back(e.get()); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Affinity_Threshold: 75 | ||
Minimum_Pixels_In_Object: 3 | ||
Pixel_Step: 2 | ||
Minimum_Pixels_In_Object: 100 | ||
Pixel_Step: 10 | ||
Calculation_Time_Limit: 50 | ||
Idle_Timeout: 5 | ||
Threads_Multiplier: 10.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