diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 0fc1a7f..4cc282c 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -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) diff --git a/sdk/base/data.cpp b/sdk/base/data.cpp index cc7395e..b318e96 100644 --- a/sdk/base/data.cpp +++ b/sdk/base/data.cpp @@ -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,30 +156,38 @@ 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"; - dst = fopen(file.c_str(), "wb"); - if (dst) + 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) - fwrite(data() + head_.info_size, 1, head_.data_size, dst); - else + } + if(!bmp || dif == 0) + 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), - 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) - { - fwrite(ptr, 1, l - dif, dst); - fwrite(pad, 1, dif, dst); - ptr += l - dif; - } + fwrite(ptr, 1, l - dif, dst); + fwrite(pad, 1, dif, dst); + ptr += l - dif; } } } diff --git a/sdk/base/data.h b/sdk/base/data.h index f880a5b..d25a6c4 100644 --- a/sdk/base/data.h +++ b/sdk/base/data.h @@ -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