tga 16 bit
tga 16 bit
Hi
I'd love to see an option to convert to tga with 16 bit - not seeing that right now.
Thanks
Nils
I'd love to see an option to convert to tga with 16 bit - not seeing that right now.
Thanks
Nils
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: tga 16 bit
What version of IM are you using and what platform? TGA is both read/write capable as far as I know and works under Q16 compile. However, I do not know if 16-bit TGA images can be read or written? Do you have an example of a 16-bit TGA that fails to read? Or some other 16-bit image that fails to write to 16-bit tga? Does TGA support 16-bits? According to http://en.wikipedia.org/wiki/Truevision_TGA, it does not look like TGA supports 16-bits per channel (48-bits rgb). Are you looking for something different? It does seem to support 16-bits total per pixel (16-bit palette). Don't know if IM supports other than 8-bit palettes.
Re: tga 16 bit
Hi
ImageMagick 6.9.0-0 on windows reads the 16 bit fine but writes 8, 24 or 32 bit only. The special 16 bit encoding is described here
http://www.fileformat.info/format/tga/egff.htm
If I read this correctly ImageMagick writes either 8Bit or 24 bit (plus optionally one byte for alpha)
An option to write that 16bit or to write what was read would complete this. Here's how the read handles this correctly
I'll attach an example in a second. There are some consumers that only can read TGA 16 in my case (edge case, for sure).
Thanks for checking
Nils
ImageMagick 6.9.0-0 on windows reads the 16 bit fine but writes 8, 24 or 32 bit only. The special 16 bit encoding is described here
http://www.fileformat.info/format/tga/egff.htm
When a value of 15 appears in the PixelDepth field of the Image Specification section of the header, there are five bits each of red, green, and blue pixel data and one bit of overlay data in each pixel (see the section below called "Pixel Attribute Bits"). This is the format the Targa 16 uses to store data. Because these 16 bits are stored in two bytes of data, a little shifting and masking is required to read and write these pixel data values.
If I read this correctly ImageMagick writes either 8Bit or 24 bit (plus optionally one byte for alpha)
Code: Select all
static inline void WriteTGAPixel(Image *image,TGAImageType image_type,
const IndexPacket *indexes,const PixelPacket *p)
{
if (image_type == TGAColormap || image_type == TGARLEColormap)
(void) WriteBlobByte(image,(unsigned char) GetPixelIndex(indexes));
else
{
if (image_type == TGAMonochrome || image_type == TGARLEMonochrome)
(void) WriteBlobByte(image,ScaleQuantumToChar(ClampToQuantum(
GetPixelLuma(image,p))));
else
{
(void) WriteBlobByte(image,ScaleQuantumToChar(GetPixelBlue(p)));
(void) WriteBlobByte(image,ScaleQuantumToChar(GetPixelGreen(p)));
(void) WriteBlobByte(image,ScaleQuantumToChar(GetPixelRed(p)));
if (image->matte != MagickFalse)
(void) WriteBlobByte(image,ScaleQuantumToChar(GetPixelAlpha(p)));
}
}
}
Code: Select all
...
case 16:
{
QuantumAny
range;
/*
5 bits each of red green and blue.
*/
j=(unsigned char) ReadBlobByte(image);
k=(unsigned char) ReadBlobByte(image);
range=GetQuantumRange(5UL);
pixel.red=ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,range);
pixel.green=ScaleAnyToQuantum((1UL*(k & 0x03) << 3)+
(1UL*(j & 0xe0) >> 5),range);
pixel.blue=ScaleAnyToQuantum(1UL*(j & 0x1f),range);
break;
}
...
Thanks for checking
Nils
Re: tga 16 bit
The original that I've downloaded (someone made in photoshop) - 16 bit
https://www.dropbox.com/s/9rm25oa6oqt1f ... l.tga?dl=0
the output of convert
https://www.dropbox.com/s/ua3k2tyk8xsfn ... d.tga?dl=0
https://www.dropbox.com/s/9rm25oa6oqt1f ... l.tga?dl=0
the output of convert
https://www.dropbox.com/s/ua3k2tyk8xsfn ... d.tga?dl=0
Re: tga 16 bit
tga16original.tga is a PNG file that has the extension .tga. Did you upload the wrong file?
Re: tga 16 bit
Apologies, I've messed up the files - here's an actual TGA input (says 5 bit which I find weird) and the 8 bit output that ImageMagick (built from source) converts to
convert ~/Dropbox/Forum/original5bit.tga ~/Dropbox/Forum/converted8bit.tga
converts to
https://www.dropbox.com/s/4sfetbnyivj3k ... t.tga?dl=0
nils@nmeier ~/workspace/ImageMagick-6.9.0-0 $ utilities/identify ~/Dropbox/Forum/original5bit.tga
/home/nils/Dropbox/Forum/original5bit.tga TGA 128x128 128x128+0+0 5-bit sRGB 32.8KB 0.000u 0:00.000
https://www.dropbox.com/s/q5csfacvsxfnq ... t.tga?dl=0
nils@nmeier ~/workspace/ImageMagick-6.9.0-0 $ utilities/identify ~/Dropbox/Forum/converted8bit.tga
/home/nils/Dropbox/Forum/converted8bit.tga TGA 128x128 128x128+0+0 8-bit sRGB 65.6KB 0.000u 0:00.000
Files available here - I'm on the wrong computer right now to provide the 16 bit file (iirc) I was playing with yesterday. I'm reading a bit into the code to see what options for 5?/15/16 added to 8/24/32 would require. It's a hurdle for me though.
Thanks
Nils
convert ~/Dropbox/Forum/original5bit.tga ~/Dropbox/Forum/converted8bit.tga
converts to
https://www.dropbox.com/s/4sfetbnyivj3k ... t.tga?dl=0
nils@nmeier ~/workspace/ImageMagick-6.9.0-0 $ utilities/identify ~/Dropbox/Forum/original5bit.tga
/home/nils/Dropbox/Forum/original5bit.tga TGA 128x128 128x128+0+0 5-bit sRGB 32.8KB 0.000u 0:00.000
https://www.dropbox.com/s/q5csfacvsxfnq ... t.tga?dl=0
nils@nmeier ~/workspace/ImageMagick-6.9.0-0 $ utilities/identify ~/Dropbox/Forum/converted8bit.tga
/home/nils/Dropbox/Forum/converted8bit.tga TGA 128x128 128x128+0+0 8-bit sRGB 65.6KB 0.000u 0:00.000
Files available here - I'm on the wrong computer right now to provide the 16 bit file (iirc) I was playing with yesterday. I'm reading a bit into the code to see what options for 5?/15/16 added to 8/24/32 would require. It's a hurdle for me though.
Thanks
Nils
Re: tga 16 bit
It is reporting 5 bit because the depth is per channel. 5*3 + 1 = 16
Re: tga 16 bit
Ah, yes, I'm mixing up bits_per_pixel and depth, thanks
Re: tga 16 bit
I just added support for writing 16-bit TGA files. This will be available in the next release of ImageMagick (6.9.0-1). You can write it by specifying a channel depth of 5:
Code: Select all
convert logo: -depth 5 logo-16bit.tga
Re: tga 16 bit
Excellent, thank you for the quick turn-around. If you'd like I could test out the tga 5 bit depth support before the release - it's probably just a diff on tga.c required?
In any case, thanks again
In any case, thanks again
Re: tga 16 bit
You are correct, you only need to change tga.c. You can find my changes in revision 17275 of our SVN repository.
Re: tga 16 bit
Hi, built and tested and it works with one caveat and I'm not sure that's an issue or not.
If I start with an indexed png and convert it to 5 bit tga, all fine
https://www.dropbox.com/s/4p093jw4i0cd6 ... d.png?dl=0
https://www.dropbox.com/s/rm5i77zcdmz5k ... t.tga?dl=0
~/workspace/ImageMagick $ utilities/identify ~/Dropbox/test-indexed.png
~/Dropbox/test-indexed.png PNG 96x96 96x96+0+0 8-bit sRGB 149c 1.12KB 0.000u 0:00.000
~/workspace/ImageMagick $ utilities/identify ~/Dropbox/test-indexed-5bit.tga
~/Dropbox/test-indexed-5bit.tga TGA 96x96 96x96+0+0 5-bit sRGB 149c 9.53KB 0.000u 0:00.000
I can load this in Gimp (not quite the standard but hey).
If I start with an RGB png and convert it to 5 bit tga, Gimp won't show the picture anymore (again, might be gimp)
https://www.dropbox.com/s/ztprx92u2uls612/test.png?dl=0
https://www.dropbox.com/s/g26oaqdzsqu4c ... t.tga?dl=0
~/workspace/ImageMagick $ utilities/identify ~/Dropbox/test.png
~/Dropbox/test.png PNG 96x96 96x96+0+0 8-bit sRGB 1.58KB 0.000u 0:00.000
~/workspace/ImageMagick $ utilities/identify ~/Dropbox/test-5bit.tga
~/Dropbox/test-5bit.tga TGA 96x96 96x96+0+0 5-bit sRGB 36.9KB 0.000u 0:00.000
Converting both tgas back to png is fine for the indexed 5 bit, the other non-index(?) tga converts into a garbled picture.
Thanks
Nils
If I start with an indexed png and convert it to 5 bit tga, all fine
https://www.dropbox.com/s/4p093jw4i0cd6 ... d.png?dl=0
https://www.dropbox.com/s/rm5i77zcdmz5k ... t.tga?dl=0
~/workspace/ImageMagick $ utilities/identify ~/Dropbox/test-indexed.png
~/Dropbox/test-indexed.png PNG 96x96 96x96+0+0 8-bit sRGB 149c 1.12KB 0.000u 0:00.000
~/workspace/ImageMagick $ utilities/identify ~/Dropbox/test-indexed-5bit.tga
~/Dropbox/test-indexed-5bit.tga TGA 96x96 96x96+0+0 5-bit sRGB 149c 9.53KB 0.000u 0:00.000
I can load this in Gimp (not quite the standard but hey).
If I start with an RGB png and convert it to 5 bit tga, Gimp won't show the picture anymore (again, might be gimp)
https://www.dropbox.com/s/ztprx92u2uls612/test.png?dl=0
https://www.dropbox.com/s/g26oaqdzsqu4c ... t.tga?dl=0
~/workspace/ImageMagick $ utilities/identify ~/Dropbox/test.png
~/Dropbox/test.png PNG 96x96 96x96+0+0 8-bit sRGB 1.58KB 0.000u 0:00.000
~/workspace/ImageMagick $ utilities/identify ~/Dropbox/test-5bit.tga
~/Dropbox/test-5bit.tga TGA 96x96 96x96+0+0 5-bit sRGB 36.9KB 0.000u 0:00.000
Converting both tgas back to png is fine for the indexed 5 bit, the other non-index(?) tga converts into a garbled picture.
Thanks
Nils
Re: tga 16 bit
.. one more thing while you're looking if I may - an option for enabling RLE compression explicitly would be completing things
Nighty
Nils
Nighty
Nils
Re: tga 16 bit
Are you sure you applied my patch (http://trac.imagemagick.org/changeset/17275) properly? Your file "test-5bit.tga" is incorrect but when I create it with my local build I get a correct tga file.
And you can already force RLE compression:
And you can already force RLE compression:
Code: Select all
convert test.png -depth 5 -compress rle test-5bit.tga
Re: tga 16 bit
on compress - ah, yes, I missed "convert -list compress", sorry