Fastest way to create a palettized image? #1828
Replies: 3 comments
-
Manually constructing a TGA file in a buffer (almost instantaneous) then passing it to the MagickImage constructor reduces the construction time to about 2 sec; not great, but tolerable. However this really isn't an answer to the question as the entire point of using Magick.NET was so that I wouldn't need to write any file format code... |
Beta Was this translation helpful? Give feedback.
-
Right now there is no way to create an image with a colormap without taking the steps that you wrote. But I could probably add a method that creates an image that has a colormap with a single color. This should be possible with the internal api of ImageMagick. am not sure what would be a good place to add this to the current api. I don't think I can/want to add it as a constructor overload. Maybe as a setting inside the |
Beta Was this translation helpful? Give feedback.
-
I'm not the best person to ask as this is my first time using ImageMagick, but if it were me I'd be inclined to make it a new constructor (actually I wasn't even aware of MagickImageFactory until you mentioned it). There's already a constructor for a blank image of specified size with a single color, and it seemed odd to me that it didn't allow you to specify a color mode. Though even if you leave the API exactly the same if the step to change to palettized were fast it wouldn't be an issue to begin with. I'm not at all clear why it takes that long at all, when the entire image is a single color. While we're at it, if there isn't already a way to do it that I don't know (and there very well might be), it would be good to make a function for IPixelCollection that took a simple byte array/list (1 byte per pixel) and would put it in the right place for a palettized image, rather than having to manually expand it into multiple bytes per pixel. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to use ImageMagick to save palettized images generated by my program. Currently I'm using the following process:
MagickImage img = new(MagickColors.Green, (uint)Width, (uint)Height);
img.ColorType = ColorType.Palette;
andimg.ColormapSize = 256;
. Note that for the purpose of my issue (slow), it does not matter if step 2 is merged into the construction step 1.SetByteArea
, passing 4 identical bytes of the palette index for each pixel (so I don't have to care which byte is used to store the palette index).SetColormapColor
This works, but step 2 (specifically setting
ColorType
is EXTREMELY slow; for the image I'm working with (8192x7680) it takes 18 seconds. Step 1 is also slower than I'd expect, taking about 2 seconds. How can I drastically speed up this process?Beta Was this translation helpful? Give feedback.
All reactions