Skip to content

Commit f6c28eb

Browse files
committed
try to fix vision on non-Windows.
1 parent 914087f commit f6c28eb

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/vision_process.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,22 @@ namespace vision
154154
return r;
155155
}
156156

157+
#if defined(_WIN64)
158+
#define MAGICK_CONVERT_CMD "magick"
159+
#define MAGICK_IDENTIFY_CMD "magick identify"
160+
#else
161+
#define MAGICK_CONVERT_CMD "convert"
162+
#define MAGICK_IDENTIFY_CMD "identify"
163+
#endif
164+
157165
void image_dimension(const char *fn, int &width, int &height)
158166
{
159167
width = -1;
160168
height = -1;
161169
const static std::regex rgx(R""( ([0-9]+)x([0-9]+) )"");
162170
std::smatch matches;
163171

164-
std::string cmd = "magick identify \"" + std::string(fn) + "\"";
172+
std::string cmd = MAGICK_IDENTIFY_CMD " \"" + std::string(fn) + "\"";
165173

166174
FILE* pp = popen(cmd.c_str(), "r");
167175

@@ -215,7 +223,7 @@ namespace vision
215223
if (width <= 0) return;
216224

217225
std::ostringstream base;
218-
base << "magick -depth 8 \"" << std::string(fn) << "\"";
226+
base << MAGICK_CONVERT_CMD << " -depth 8 \"" << std::string(fn) << "\"";
219227
if (PreMaxImageSize::PreScale(width, height))
220228
base << " -resize " << width << "x" << height << "!";
221229

@@ -253,7 +261,7 @@ namespace vision
253261

254262
// resize the global one
255263
std::ostringstream oss;
256-
oss << "magick -depth 8 \"" << std::string(fn) << "\"";
264+
oss << MAGICK_CONVERT_CMD << " -depth 8 \"" << std::string(fn) << "\"";
257265
oss << " -resize " << split_width << "x" << split_height << "!";
258266
splits.emplace_back(image_pixels_t());
259267
auto &image = splits.back();
@@ -275,7 +283,7 @@ namespace vision
275283
// whole image
276284
{
277285
std::ostringstream oss;
278-
oss << "magick -depth 8 \"" << std::string(fn) << "\"";
286+
oss << MAGICK_CONVERT_CMD << " -depth 8 \"" << std::string(fn) << "\"";
279287
oss << " -resize " << crop_width << "x" << crop_height << "!";
280288
crops.emplace_back(image_pixels_t());
281289
auto &image = crops.back();
@@ -327,7 +335,7 @@ namespace vision
327335
const int start_x = c * crop_size_w;
328336

329337
std::ostringstream oss;
330-
oss << "magick -depth 8 \"" << std::string(fn) << "\"";
338+
oss << MAGICK_CONVERT_CMD << " -depth 8 \"" << std::string(fn) << "\"";
331339
oss << " -crop " << crop_size_w << "x" << crop_size_h << "+" << start_x << "+" << start_y;
332340
oss << " -resize " << crop_width << "x" << crop_height << "!";
333341

@@ -348,7 +356,7 @@ namespace vision
348356
if (width <= 0) return;
349357

350358
std::ostringstream oss;
351-
oss << "magick -depth 8 \"" << std::string(fn) << "\"";
359+
oss << MAGICK_CONVERT_CMD << " -depth 8 \"" << std::string(fn) << "\"";
352360

353361
if (params.do_resize)
354362
{
@@ -401,7 +409,7 @@ namespace vision
401409
}
402410
}
403411

404-
oss << " -resize \"" << width << "x" << height << "\\>\"";
412+
oss << " -resize \"" << width << "x" << height << ">\"";
405413

406414
int aligned_width = 0;
407415
int aligned_height = 0;
@@ -726,11 +734,12 @@ namespace vision
726734
{
727735
std::ostringstream oss;
728736
int64_t data_cnt = 0;
729-
oss << "magick";
737+
730738
#if defined(_WIN64)
739+
oss << "magick";
731740
const std::string fn = "\"" + utils::tmpname() + ".png\"";
732741
#else
733-
oss << " display";
742+
oss << "display";
734743
#endif
735744

736745
switch (fmt)

0 commit comments

Comments
 (0)