Re: forcing a format when emitting a blob?

Bob Friesenhahn <[email protected]> Mon, 23 May 2011 17:47:06 -0500 (CDT)
Newsgroups gmane.comp.video.graphicsmagick.apis
Message-ID <[email protected]>
On Mon, 23 May 2011, [email protected] wrote:
>
> All sounds good.
>
> When I'm forcing formats, I'm just strcpy()'nig directly to
> image->magick. Is that correct, or am I abusing the structure? I'm
> presuming this is a correct method, considering these things are
> documented in "types", but "formats" page doesn't actually mention
> writing this out, only that it's updated internally on read and ping.

This is what you should do.  However, there are many cases where the 
"magick" field will be updated automatically.  It will be updated 
whenever the file format is determined automatically when reading a 
file, or if the file format is determined automatically when writing a 
file based on the file specification.

For example, if the file name is "JPEG:foo.bar" then magick will be 
set to "JPEG".  If the file name is "foo.bar", then it will be set to 
JPEG if it is really a JPEG file, or "BAR" if it is impossible to tell 
and there is support for a "BAR" format.

A robust way to force a format is to prefix the file name with the 
format string like

   FORMAT:filename

and then the magick value will become "FORMAT".

For details, see the documentation for the function SetImageInfo.  You 
can find that documentation in this source file:

http://cvs.graphicsmagick.org/cgi-bin/cvsweb.cgi/GraphicsMagick/magick/image.c?rev=1.1349;content-type=text%2Fx-cvsweb-markup

%  SetImageInfo() inspects the filename field of the ImageInfo
%  structure.  Based on what it finds, it may update the `affirm',
%  `filename', `magick', `subimage', `subrange', `temporary', and
%  `tile' fields in the ImageInfo structure, and may even allocate a
%  temporary file. This is a powerful, mysterious, and anchient
%  function which supports the many special features associated with
%  input and output file specifications, and is intended for use only
%  within GraphicsMagick code.
%
%  If the file will be read and the file specification includes an
%  index enclosed in brackets after the file name and the file exists,
%  then it is assumed to specify a subimage of a multi-resolution image
%  format like Photo CD (e.g.  img0001.pcd[4]).  The `tile' `subimage',
%  and `subrange' fields will be updated.  The filename specification
%  is then truncated to remove the subimage specification.
%
%  The filename is inspected for an image format prefix. For example,
%  `ps:image' returns PS indicating a Postscript image.  If a format
%  prefix was found, then `filename' is updated to remove it.  The
%  `magick' field is set to the specified format and the `affirm' field
%  is set to indicate an explicit user request for the format (which
%  will not be overridden).
%
%  If the format is not yet known, the filename is inspected for an
%  image format extension.  If format support exists for this
%  extension, then the official format designator for that format is
%  written into the `magick' field. For example, "JPEG" is set in the
%  `magick' field for the filename: `image.jpg'. Some file extensions
%  are intentionally ignored due to potential confusion or security
%  issues.  The file extension is used as a strong hint of the file
%  format but is not authoritative.
%
%  If the file will be read, then its content is inspected for its
%  type.  If the input is not seekable, then its content is copied to a
%  temporary file, `filename` is updated with the name of the temporary
%  file, and `temporary' is set to true so that the temporary file may
%  be automatically deleted later.  The `magick' field is updated if
%  file header matches a known type.
%
%  If rectify mode is requested, then the file specification is
%  inspected to see if it has a scene specifier (e.g. "foo-%02d.bar")
%  and if it does, then the 'adjoin' flag in ImageInfo is set to
%  MagickFalse.
%
%  If the file is to be written, and `adjoin' is currently true, then
%  the responsible coder is queried to see if it supports adjoin
%  (multiple frames per file) mode.  If it does not, then the 'adjoin'
%  flag is cleared.
%
%  MagickFail is returned if an error is encountered.
%
%  The format of the SetImageInfo method is:
%
%      MagickPassFail SetImageInfo(ImageInfo *image_info,
%        const unsigned int flags,ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o image_info: The image info..
%
%    o flags: Flag options based on an OR of SETMAGICK_READ, SETMAGICK_WRITE,
%        and SETMAGICK_RECTIFY. SETMAGICK_READ indicates that the file is to
%        be read, SETMAGICK_WRITE indicates that the the file will be written,
%        and SETMAGICK_RECTIFY indicates that the file specification should be
%        inspected for an embedded scene specification, and adjust the 'ajoin'
%        accordingly.
%
%    o exception: Return any errors or warnings in this structure.
%


Bob
-- 
Bob Friesenhahn
[email protected], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery, 
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now. 
http://p.sf.net/sfu/quest-d2dcopy1