Working With .pkm and .atc Files

Morningstar

Senior Member
Apr 2, 2006
1,390
2,531
0
CA
www.alliance-rom.com
Hello XDA,

Today I'm going to show you how to work with/convert the .pkm and .atc image files that are included in system apks on recent devices. It's been about a month since I've looked into these formats, so if anybody has since come up with any better/alternative methods, please share them here.

Let's begin...

.pkm
.pkm files are actually a type of ETC1_RGB8 textures. The reason manufacturers are starting to use them, is because they are fully supported by Android, and with the OpenGL ES platform that Android runs, they offer significant overhead savings vs conventional image formats. A lot of people (devs included) probably haven't realized it, but there is actually a tool that comes bundled with the Android SDK for creating .pkm textures. It's called etc1tool, and is a command line utility. Etc1tool is capable itself of converting .pkm files to .png, but unfortunately all the ones I've come across in pre-existing apks are not able to be converted this way. That would be too easy, right? So, here's what we do instead:

-First, you're going to need to download and install Mali GPU Texture Compression Tool from HERE.

-Once you've got it all set up, open it up, go to File > Open, and open up a .pkm file (or several, as it can do batch processing).

-Now, click on the .pkm file you just opened, in the left-hand pane to select it. You should see the image.


-Next, click on the yellow icon towards the upper right of the screen.


-In the window that pops up, copy the settings I have here. You can change the directory (it's only going to store a temp file anyway), but everything else must match.


-Click OK, let it do its' thing, and you should see a screen similar to this:


-Now, you're going to click on your image(s) in the left-hand pane to select them again, then click on the blue save icon towards the upper right.


-Save them to whatever directory, and with whatever extension you'd like (most likely .png). Now, the standard ETC1 format doesn't handle alpha values, and the existing .pkms seem to have been encoded using some proprietary method that preserves the alpha channel. When you save your image from Mali, it will not save the alpha values, despite the preview having them. As a result, your .png will have a black background, similar to this:

From here, though, you at least have a standard .png image, which you can then open with Photoshop or Gimp and easily remove the black background.

-If for some reason you'd like to create your own .pkm file(s) from existing images, navigate in command prompt to the your Android SDK > Tools directory, then use the following:
Code:
etc1tool pathtoinputfile.png --encode -o pathtooutputfile.pkm

.atc
.atc files aren't going to be as common as .pkm, as they are a proprietary format and can only be used on device with a Qualcomm Adreno chipset. Just like .pkm files, they offer significant gains in overhead performance compared to standard image formats, but they are a pain when you're trying to theme an app that's full of them. Let's begin...

-Start off by downloading the ASTC Evaluation Codec found HERE. This one is going to be a zip, rather than an installable program, so download it and extract it wherever you wish. Once extracted, find the location of 'astcenc' (the folder names are odd, and differ depending on your OS).

-Once you've located it, open up command prompt, and navigate to that folder.

-Like etc1tool, the ASTC Codec is capable of converting directly to .png, but also like the .pkm files, it doesn't work in this case. You can try, but the result will be unusable, so don't waste your time. Instead, we're going to convert to .tga.

-So, in command prompt, use the following to decode the .atc to a more usable .tga:
Code:
astcenc -d pathtoinputfile.atc pathtooutputfile.tga


-Unlike .pkm files and Mali, this will preserve any existing transparency, but there's a catch (there's always a catch). The resulting .tga file will be upside down.


-Fortunately, this is nothing more than a minor inconvenience lol. So, once you have your .tga file, open it up in Photoshop or Gimp, flip it, and save as .png, and you should be all set.

-If for some reason you wanted to create a new .atc file, the codec can be used for that as well. I forget the command, and documentation is very hard to find, but if you use the following, you should be able to go from there:
Code:
astcenc -help
Be aware, that there is absolutely no need to recreate any of these special formats. You can simply delete the originals and replace them with .png files of the same name, and they'll work just fine in any apk, and then you won't have to worry about it in the future. Anyway, I hope some of you learned something and find this useful....

~morningstar
 

manikant_009

Senior Member
Jan 29, 2012
1,076
1,212
153
Mumbai
I am not able to convert .atc extension files with your guide it creates a new .tga files but when i open it with Photoshop it gives me error "Could not complete your request because of a problem with the file-format module interface."
 
  • Like
Reactions: Morningstar

Morningstar

Senior Member
Apr 2, 2006
1,390
2,531
0
CA
www.alliance-rom.com
I am not able to convert .atc extension files with your guide it creates a new .tga files but when i open it with Photoshop it gives me error "Could not complete your request because of a problem with the file-format module interface."
Interesting. I don't use PhotoShop personally, so I wasn't aware of the issue. What version of PS are you using? I'll see if I can figure out a solution. In the meantime, I guess I'd have to recommend Gimp, as it's what I generally use, and doesn't seem to have any issues opening the resulting .tga files.
 

manikant_009

Senior Member
Jan 29, 2012
1,076
1,212
153
Mumbai
Interesting. I don't use PhotoShop personally, so I wasn't aware of the issue. What version of PS are you using? I'll see if I can figure out a solution. In the meantime, I guess I'd have to recommend Gimp, as it's what I generally use, and doesn't seem to have any issues opening the resulting .tga files.
I Succeeded in Converting .atc files. What I did is just renamed all .atc files to .astc extension and then used Picconv 2.1 to covert it to .png files:D
 

mikeymopar

Senior Member
Jan 14, 2011
446
922
133
hey @Morningstar...i reworked my batch file i made that resizes a folder full of xxhdpi images to xhdpi and hdpi sizes to now also convert a folder full of atc images to tga, flip them, and convert them all to png images all in one step. maybe it'll help y'all out a little...ionno...maybe.

folder structure must be exactly as shown and explained in the setup.txt file.

Image Converter

EDIT: use V2 edition on page 2 of this thread as i made it to convert .wbp images too now (HERE)
 
Last edited:

kevinoliva113

Senior Member
Sep 26, 2008
590
828
0
hey @Morningstar...i reworked my batch file i made that resizes a folder full of xxhdpi images to xhdpi and hdpi sizes to now also convert a folder full of atc images to tga, flip them, and convert them all to png images all in one step. maybe it'll help y'all out a little...ionno...maybe.
Great work Mikey.. Just tested. Full disclosure. ......... I'm lazy. I copied all images over. .9s,qmg, and atc. It ignored other formats, and hit every atc. Perfect!!!



Sent from my SM-N910P using XDA Free mobile app
 

mikeymopar

Senior Member
Jan 14, 2011
446
922
133
Great work Mikey.. Just tested. Full disclosure. ......... I'm lazy. I copied all images over. .9s,qmg, and atc. It ignored other formats, and hit every atc. Perfect!!!
big thx @kevinoliva113 for the feedback. i'm a bit out of the loop now (haven't dealt with atc before; still on kk with att) and by pure chance noticed someone mentioning how it was so time consuming converting atc images one at a time and yearning for a way to batch convert a bunch of them. so hopefully, at least for the time being, this meets the requirements for those that can use it :)
 

Morningstar

Senior Member
Apr 2, 2006
1,390
2,531
0
CA
www.alliance-rom.com
hey @Morningstar...i reworked my batch file i made that resizes a folder full of xxhdpi images to xhdpi and hdpi sizes to now also convert a folder full of atc images to tga, flip them, and convert them all to png images all in one step. maybe it'll help y'all out a little...ionno...maybe.

folder structure must be exactly as shown and explained in the setup.txt file.

Image Converter
Wow, Mikey, excellent work! Fortunately, I haven't had to deal with too many .atc files, but I know some devices have a ton of them, and that'll be a great time saver.

Fantastic job!
[emoji106]
 
  • Like
Reactions: mikeymopar

mikeymopar

Senior Member
Jan 14, 2011
446
922
133
Wow, Mikey, excellent work! Fortunately, I haven't had to deal with too many .atc files, but I know some devices have a ton of them, and that'll be a great time saver.

Fantastic job!
:eek: i only expanded on your solution by adding it to my simple script. all credit goes to you - awesome work as usual...much respect
 
  • Like
Reactions: Morningstar

Morningstar

Senior Member
Apr 2, 2006
1,390
2,531
0
CA
www.alliance-rom.com
nice. also added this new feature to my image converter (as long as you don't mind). now it BATCH resizes xxhdpi and converts .atc and .wbp images to png images

IMAGE RESIZERv2
Nice work, Mikey! ...And you know I don't mind lol. Er....if you didn't notice already, there was a slight error in my script. When converting from .wbp to .png, it renamed the files like this: file_name.wbp.png. It doesn't affect recompiling or anything, but if you're OCD it'll drive you nuts. I just haven't gotten around to fixing it yet. Lol.

Excellent work. It's nice as hell to have everything in one easy to use package, rather than mucking about with a bunch of different programs and scripts and codecs

[emoji106]
 
  • Like
Reactions: mikeymopar

parkerj7uc

Senior Member
Dec 27, 2011
1,221
1,782
0
Cincinnati
I put a pkm into the "Original_Images_to_convert" folder ran the bat it said it was complete but where does it save it to?

---------- Post added at 03:32 PM ---------- Previous post was at 03:29 PM ----------

I put a pkm into the "Original_Images_to_convert" folder ran the bat it said it was complete but where does it save it to?
Ok I see that after doing it a folder appears as "Images_converted_to_png" but the folder is empty.
 

Morningstar

Senior Member
Apr 2, 2006
1,390
2,531
0
CA
www.alliance-rom.com
I put a pkm into the "Original_Images_to_convert" folder ran the bat it said it was complete but where does it save it to?

---------- Post added at 03:32 PM ---------- Previous post was at 03:29 PM ----------


Ok I see that after doing it a folder appears as "Images_converted_to_png" but the folder is empty.
Ummm....I don't think @mikeymopar's script does .pkm files?
 
  • Like
Reactions: parkerj7uc