转换JPEG增加对DPI属性的支持

This commit is contained in:
gb 2022-10-14 17:27:54 +08:00
parent e7a97c06c3
commit 3f139f8170
2 changed files with 15 additions and 0 deletions

View File

@ -85,6 +85,13 @@ enum
CV_IMWRITE_JPEG_RST_INTERVAL =4,
CV_IMWRITE_JPEG_LUMA_QUALITY =5,
CV_IMWRITE_JPEG_CHROMA_QUALITY =6,
// add for DPI on 2022-10-14
CV_IMWRITE_JPEG_RESOLUTION_UNIT = 7, // 0 - unknown(default value), 1 - dots/inch, 2 - dots/cm
CV_IMWRITE_JPEG_RESOLUTION_X = 8, // default value - 1
CV_IMWRITE_JPEG_RESOLUTION_Y = 9, // default value - 1
// ENDED for DPI
CV_IMWRITE_PNG_COMPRESSION =16,
CV_IMWRITE_PNG_STRATEGY =17,
CV_IMWRITE_PNG_BILEVEL =18,

View File

@ -1399,8 +1399,16 @@ namespace hg_imgproc
// MSB word[7] and word[8] are x and y resolutions
std::vector<int> cpr;
unsigned short jpeg_r = (resolution << 8) | ((resolution >> 8) & 0x0ff);
int resolution_y = bih.biYPelsPerMeter / 39.37f + .5f;
cpr.push_back(CV_IMWRITE_JPEG_QUALITY);
cpr.push_back((int)(long)conv->dst.fmt.detail);
cpr.push_back(CV_IMWRITE_JPEG_RESOLUTION_UNIT);
cpr.push_back(1);
cpr.push_back(CV_IMWRITE_JPEG_RESOLUTION_X);
cpr.push_back(resolution);
cpr.push_back(CV_IMWRITE_JPEG_RESOLUTION_Y);
cpr.push_back(resolution_y);
if (conv->dst.is_file)
{
cv::imwrite(conv->dst.data, imsg, cpr);