(again:) Magick++: how to "-sampling-factor XxY"

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
jbarth_ubhd
Posts: 1
Joined: 2012-09-17T04:38:17-07:00
Authentication code: 67789

(again:) Magick++: how to "-sampling-factor XxY"

Post by jbarth_ubhd » 2012-09-17T04:42:21-07:00

Dear Forum,

why does this not work?:

im.read(width, height, "RGB", CharPixel, im_rgb);
im.magick("JPEG");
im.quality(75);
im.defineValue("JPEG", "sampling-factor", "1x1,1x1,1x1");
im.write(varMap["of"].as<string>());

J. Barth

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: (again:) Magick++: how to "-sampling-factor XxY"

Post by glennrp » 2012-09-17T13:19:38-07:00

jbarth_ubhd wrote:Dear Forum,

why does this not work?:

im.read(width, height, "RGB", CharPixel, im_rgb);
im.magick("JPEG");
im.quality(75);
im.defineValue("JPEG", "sampling-factor", "1x1,1x1,1x1");
im.write(varMap["of"].as<string>());

J. Barth
There seems to be a bug in coders/jpeg.c. At line 2300

Code: Select all

value=GetImageProperty(image,"jpeg:sampling-factor");
should probably be

Code: Select all

  value=GetImageOption(image_info,"jpeg:sampling-factor");
  if (value == (char *) NULL)
    value=GetImageProperty(image,"jpeg:sampling-factor");
We have to check both Options and Properties so we handle
commandline input and also image data inherited from the
input image. With this change it works from the commandline

Code: Select all

convert logo: -define jpeg:sampling-factor="1x1,1x1,1x1" logo.jpg
convert logo.jpg logo2.jpg
logo.jpg and logo2.jpg both have the desired sampling-factors.
I assume that "im.defineValue" works the same as "-define" on the commandline.

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: (again:) Magick++: how to "-sampling-factor XxY"

Post by anthony » 2012-09-23T19:35:24-07:00

glennrp wrote: We have to check both Options and Properties so we handle
commandline input and also image data inherited from the
input image. With this change it works from the commandline

Code: Select all

convert logo: -define jpeg:sampling-factor="1x1,1x1,1x1" logo.jpg
convert logo.jpg logo2.jpg
logo.jpg and logo2.jpg both have the desired sampling-factors.
I assume that "im.defineValue" works the same as "-define" on the commandline.
-define sets an artifact, which is what is looked up by various coders and operators as needed.


in IMv7 the properity (or escape) lookup will look for "attributes" (non-string per-image values, like width), "properties" (saved image meta-data), "artefacts" (non-saved per-image settings), and options (global user settings). In IMv6 "options" are coped (repeatly) into "artefacts", IMv7 have a link to it.

Note: Artefact lookup IMv7 also does a global "option" lookup, following the link back to the containing "wand" that holds image sequences.

Many API's do not have a 'wand' of global "options", so you need to set artifacts, on every image directly.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply