优化中间图像存储名称
This commit is contained in:
parent
b1af6d0d4d
commit
2c138cd89d
|
@ -265,10 +265,10 @@ void hg_scanner::process_image(image_holder_ptr img)
|
|||
char alg[128] = { 0 };
|
||||
|
||||
if (img_prc_name_.count(stage))
|
||||
sprintf(alg, "%04X_%s", stage, img_prc_name_[stage].c_str());
|
||||
sprintf(alg, "%s", img_prc_name_[stage].c_str());
|
||||
else
|
||||
sprintf(alg, "%04X_Unk", stage);
|
||||
img->save_2_file(dump_path_.c_str(), alg);
|
||||
sprintf(alg, "%s", "Unk");
|
||||
img->save_2_file(dump_path_.c_str(), stage, alg);
|
||||
}
|
||||
|
||||
if (img->get_info()->format != IMG_FMT_BMP)
|
||||
|
|
|
@ -135,15 +135,16 @@ LPPACKIMAGE image_holder::get_info(void)
|
|||
{
|
||||
return &head_;
|
||||
}
|
||||
int image_holder::save_2_file(const char* root_dir, const char* alg)
|
||||
int image_holder::save_2_file(const char* root_dir, int alg_ind, const char* alg)
|
||||
{
|
||||
std::string file(root_dir);
|
||||
FILE* dst = nullptr;
|
||||
int err = ENOTSUP;
|
||||
char buf[80] = { 0 };
|
||||
bool bmp = false;
|
||||
|
||||
file += PATH_SEPARATOR;
|
||||
sprintf(buf, "%04d", head_.pos.paper_ind);
|
||||
sprintf(buf, "%04d_%04x", (int32_t)head_.pos.paper_ind, alg_ind);
|
||||
file += buf;
|
||||
if (head_.pos.paper_side == PAPER_SIDE_FRONT)
|
||||
file += "_Front";
|
||||
|
@ -155,22 +156,31 @@ int image_holder::save_2_file(const char* root_dir, const char* alg)
|
|||
file += buf;
|
||||
if (alg && *alg)
|
||||
file += std::string("_") + alg;
|
||||
if (head_.format == IMG_FMT_BMP)
|
||||
if (head_.format == IMG_FMT_PNG)
|
||||
file += ".png";
|
||||
else if (head_.format == IMG_FMT_JPEG)
|
||||
file += ".jpg";
|
||||
else
|
||||
{
|
||||
std::string bih(utils::bitmap_info_header(head_.width, head_.height, head_.bpp * head_.channels, head_.resolution_x, head_.resolution_y)),
|
||||
bfh(utils::bitmap_file_header((BITMAPINFOHEADER*)&bih[0]));
|
||||
file += ".bmp";
|
||||
bmp = true;
|
||||
}
|
||||
dst = fopen(file.c_str(), "wb");
|
||||
if (dst)
|
||||
{
|
||||
int l = BMP_LINE_BYTES(head_.width * head_.bpp * head_.channels),
|
||||
dif = l - (head_.width * head_.bpp * head_.channels + 7) / 8;
|
||||
if (bmp)
|
||||
{
|
||||
std::string bih(utils::bitmap_info_header(head_.width, head_.height, head_.bpp * head_.channels, head_.resolution_x, head_.resolution_y)),
|
||||
bfh(utils::bitmap_file_header((BITMAPINFOHEADER*)&bih[0]));
|
||||
fwrite(bfh.c_str(), 1, bfh.length(), dst);
|
||||
fwrite(bih.c_str(), 1, bih.length(), dst);
|
||||
if(head_.data_size == ((LPBITMAPINFOHEADER)&bih[0])->biSizeImage)
|
||||
}
|
||||
if(!bmp || dif == 0)
|
||||
fwrite(data() + head_.info_size, 1, head_.data_size, dst);
|
||||
else
|
||||
{
|
||||
int l = BMP_LINE_BYTES(head_.width * head_.bpp * head_.channels),
|
||||
dif = l - (head_.width * head_.bpp * head_.channels + 7) / 8;
|
||||
char pad[4] = { 0 };
|
||||
uint8_t *ptr = data() + head_.info_size;
|
||||
for (int i = 0; i < head_.height; ++i)
|
||||
|
@ -181,7 +191,6 @@ int image_holder::save_2_file(const char* root_dir, const char* alg)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dst)
|
||||
fclose(dst);
|
||||
|
|
|
@ -135,7 +135,7 @@ protected:
|
|||
public:
|
||||
void set_info(LPPACKIMAGE head);
|
||||
LPPACKIMAGE get_info(void);
|
||||
int save_2_file(const char* root_dir, const char* alg = nullptr);
|
||||
int save_2_file(const char* root_dir, int alg_ind, const char* alg = nullptr);
|
||||
};
|
||||
|
||||
class empty_holer : public data_holder
|
||||
|
|
Loading…
Reference in New Issue