Image Stride

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tc33
Posts: 40
Joined: 2012-10-21T22:10:21-07:00
Authentication code: 67789

Image Stride

Post by tc33 »

I'm using the latest IM and the Magick++ interface. I need to provide an image's stride, along with the image width, to a function in a 3rd party library. However, I don't see how to retrieve/calculate an image's stride via the API. Any hints on how I can determine this info? I checked the docs and Google, but was unable to find a solution. Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image Stride

Post by fmw42 »

tc33 wrote:I'm using the latest IM and the Magick++ interface. I need to provide an image's stride, along with the image width, to a function in a 3rd party library. However, I don't see how to retrieve/calculate an image's stride via the API. Any hints on how I can determine this info? I checked the docs and Google, but was unable to find a solution. Thanks!

I know nothing about Magick++, but in reviewing the documentation, I see that info is at Accessing Image Attributes at http://www.imagemagick.org/Magick++/tut ... torial.pdf. See link to Gentle Introduction at http://www.imagemagick.org/script/magick++.php
tc33
Posts: 40
Joined: 2012-10-21T22:10:21-07:00
Authentication code: 67789

Re: Image Stride

Post by tc33 »

Thanks. I re-reviewed the documentation, but was unable to determine which attribute is the 'stride'. What is the name of the stride attribute?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image Stride

Post by fmw42 »

tc33 wrote:Thanks. I re-reviewed the documentation, but was unable to determine which attribute is the 'stride'. What is the name of the stride attribute?
I expect you mean height

width is the horizontal number of pixels and height is the vertical number of pixels in an image.
tc33
Posts: 40
Joined: 2012-10-21T22:10:21-07:00
Authentication code: 67789

Re: Image Stride

Post by tc33 »

Stride is different than height or width; I'm looking for the stride (or pitch?)

http://msdn.microsoft.com/en-us/library ... 73780.aspx

Right now i'm just using stride = columns * channel count, but don't know how to account for any other padding that may exist. I'm using the BMP2 format for this operation, so additional row padding might not even be in the spec; I'll have to dig a bit deeper to be sure. Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image Stride

Post by fmw42 »

Sorry, I have never seen anything like that in IM. Is that for some special Windows video format? IM deals mostly with images not videos. Perhaps I misunderstand.


Any way, this is beyond my knowledge and this would be a question for the IM developers to answer.
tc33
Posts: 40
Joined: 2012-10-21T22:10:21-07:00
Authentication code: 67789

Re: Image Stride

Post by tc33 »

I was able to dig this up in BMP.c, line 1583, specifically for the format I'm using (BMP2):

bytes_per_line=4*((image->columns*bmp_info.bits_per_pixel+31)/32);

So I'm going to assume that stride info is determined privately by each image type handler as needed, and it isn't exposed as a property in the magick image API.

Hope this helps someone else
Post Reply