优化中间图像存储名称

This commit is contained in:
gb 2024-02-28 10:29:18 +08:00
parent b1af6d0d4d
commit 2c138cd89d
3 changed files with 33 additions and 24 deletions

View File

@ -265,10 +265,10 @@ void hg_scanner::process_image(image_holder_ptr img)
char alg[128] = { 0 }; char alg[128] = { 0 };
if (img_prc_name_.count(stage)) 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 else
sprintf(alg, "%04X_Unk", stage); sprintf(alg, "%s", "Unk");
img->save_2_file(dump_path_.c_str(), alg); img->save_2_file(dump_path_.c_str(), stage, alg);
} }
if (img->get_info()->format != IMG_FMT_BMP) if (img->get_info()->format != IMG_FMT_BMP)

View File

@ -135,15 +135,16 @@ LPPACKIMAGE image_holder::get_info(void)
{ {
return &head_; 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); std::string file(root_dir);
FILE* dst = nullptr; FILE* dst = nullptr;
int err = ENOTSUP; int err = ENOTSUP;
char buf[80] = { 0 }; char buf[80] = { 0 };
bool bmp = false;
file += PATH_SEPARATOR; file += PATH_SEPARATOR;
sprintf(buf, "%04d", head_.pos.paper_ind); sprintf(buf, "%04d_%04x", (int32_t)head_.pos.paper_ind, alg_ind);
file += buf; file += buf;
if (head_.pos.paper_side == PAPER_SIDE_FRONT) if (head_.pos.paper_side == PAPER_SIDE_FRONT)
file += "_Front"; file += "_Front";
@ -155,30 +156,38 @@ int image_holder::save_2_file(const char* root_dir, const char* alg)
file += buf; file += buf;
if (alg && *alg) if (alg && *alg)
file += std::string("_") + 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"; file += ".bmp";
dst = fopen(file.c_str(), "wb"); bmp = true;
if (dst) }
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(bfh.c_str(), 1, bfh.length(), dst);
fwrite(bih.c_str(), 1, bih.length(), dst); fwrite(bih.c_str(), 1, bih.length(), dst);
if(head_.data_size == ((LPBITMAPINFOHEADER)&bih[0])->biSizeImage) }
fwrite(data() + head_.info_size, 1, head_.data_size, dst); if(!bmp || dif == 0)
else fwrite(data() + head_.info_size, 1, head_.data_size, dst);
else
{
char pad[4] = { 0 };
uint8_t *ptr = data() + head_.info_size;
for (int i = 0; i < head_.height; ++i)
{ {
int l = BMP_LINE_BYTES(head_.width * head_.bpp * head_.channels), fwrite(ptr, 1, l - dif, dst);
dif = l - (head_.width * head_.bpp * head_.channels + 7) / 8; fwrite(pad, 1, dif, dst);
char pad[4] = { 0 }; ptr += l - dif;
uint8_t *ptr = data() + head_.info_size;
for (int i = 0; i < head_.height; ++i)
{
fwrite(ptr, 1, l - dif, dst);
fwrite(pad, 1, dif, dst);
ptr += l - dif;
}
} }
} }
} }

View File

@ -135,7 +135,7 @@ protected:
public: public:
void set_info(LPPACKIMAGE head); void set_info(LPPACKIMAGE head);
LPPACKIMAGE get_info(void); 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 class empty_holer : public data_holder