**********************************************
  apdtool
  Copyright (c) 2020 Azel

  http://azsky2.html.xdomain.jp/
  <azelpg@gmail.com>
**********************************************

This software is released under the MIT License.
Please see the file LICENSE for details.


=====================================
 * Overview
=====================================

APD(AzPaineter)/ADW(AzDrawing) file tool.


- Can read APD v1-v3 and ADW v1-v2 files.

- A single picture with layers combined can be batch converted to PNG/BMP/PSD.

- Images of each layer can be extracted as PNG/BMP/PSD.

- A16bit/A1bit layer texture can be converted to
  a specified color layer based on the texture image path.
  (You can convert a tone image to grayscale)


* If a layer texture is used, a separate texture image is required.
  In that case, please specify the directory of the texture image in the option.


=====================================
 * Operating environment
=====================================

unix like OS

(Operation confirmed below)
Linux/macOS/FreeBSD


=====================================
 * What you need to compile
=====================================

You need a C compiler, make, and development files for various libraries.

Required libraries: zlib libpng


--- Required packages for each OS / distribution ---

(Debian/Ubuntu)

  gcc or clang, make zlib1g-dev libpng-dev

(RedHat)

  gcc or clang, make zlib-devel libpng-devel

(Arch Linux)

  gcc or clang, make libpng

(macOS)

  xcode libpng

(FreeBSD)

  gmake png
  [!] Not compatible with BSD make


=====================================
 * Compile and install
=====================================

After extracting the source archive,
navigate to the extracted directory and execute the following.

$ ./configure
$ make
$ sudo make install

[!] For FreeBSD, run gmake instead of make.
[!] For macOS, root privileges are not required for make install.


--- Commentary ---

Generate various files according to the execution environment
with the configure script, and use the Makefile to generate
the executable file with the make command.
Then, install each file with make install.

By default, it is installed under '/usr/local/'.


--- Installed files ---

PREFIX/bin : executable file (apdtool)
PREFIX/doc/apdtool : document files


--- configure option ---

You can specify options at the time of ./configure.
See ./configure --help for details.


=====================================
 * Command line options
=====================================

$ apdtool [opt] <FILE...>


Multiple input files (APD/ADW) can be specified.

There are mainly three types of processing:
"output blend image", "layer output" and "layer information display",
and output the composite image by default.

If more than one processing type is specified, the last one specified is executed.


-o,--output=[DIR or FILENAME]

    Specify the image output directory or output file name.
    Output to the current directory by default.

    <blend image>
    If it is not an existing directory path name, it will be treated as an output file name.
    If the output file name is specified, the output format is determined from the extension.
    If a directory is specified, the output file name will be "input file name + extension".

    <Layer output>
    The directory is always specified.
 
-i,--info

    Outputs layer information.
    No image output is performed.

-f,--format=[TYPE]

    Specify the output format of the composite image or layer image.
    default:png

    png/bmp/psd


▼ blend image

-G,--gray

    Outputs in grayscale for blend image.
    In the case of PNG/PSD, it becomes 8-bit grayscale color.

-M,--mono

    For blend image, it is output in monochrome.
    In the case of PNG/PSD, it is 1bit grayscale color.


▼ layer output

-l,--layer

    Outputs the layer image in RGBA color.
    By default, all layers except folders are targeted.

    By default, the output file name is "input file name + '_' + serial number + extension".

-p,--layer-prefix=[PREFIX]

    Specify the prefix of the output file name when outputting layers.
    * Specify the output directory with --output.

    The output file name will be "PREFIX + serial number + extension".
    If you specify an empty string with '-p ""', you can use only the serial number.

-n,--layer-no=[n,n1-n2,...]

    When outputting a layer, specify multiple index numbers of the target layer.

    The numbers start at 0 and can be specified as a single unit,
    such as "0,1,2", or as a range, such as "0-5,10-20".
    Separate each value with ','.

    The layer index number can be checked with --info.

-z,--layer-no-tex

    Does not apply the layer texture to the image when outputting layers.


▼ layer texture

-s,--texpath-sys=[PATH]

    Specify the directory path of the system texture image.
    The default is the current directory.

-u,--texpath-user=[PATH]

    Specify the directory path of the texture image of the user.
    The default is "~/.azpainter/texture".

-T,--texlist=[FILENAME]

    Outputs the path of the layer texture of all input files to a text file.
    FILENAME is the name of the text file to be output.
    No image is output.

-t,--texcol=[FILENAME]

    (When outputting blend image or layer)
    Load texture path and color information from FILENAME text file.
    If the layer texture used in the A16bit/A1bit layer matches the path,
    replace the line color of the layer with the specified color and invalidate the texture.

    Use when you want to convert a tone image to a grayscale color.

    In the text, a leading ';' is treated as a comment.
    One line describes the texture path and the color information to be replaced.
    There are two types of color specification.

    path/file@[0-100] : Density(%). 0=white,100=black
    path/file#[0-255] : 8bit color. 0=black,255=white

    Ex: tone/60_20.png@20

    This is valid only when the end of the line is a single-byte number and
    there is an @ or # within 4 characters from the end,
    and the other lines are ignored (color replacement is not performed).

    [※important point]
    If the layer images to be replaced overlap in multiple layers,
    the lighter colors may be displayed on the darker colors unless
    the darker texture layers are arranged in order from the top.
    In that case, change the order of the layers in the original file.


▼ others

-V,--version

    Displays version information.

-h,--help

    Displays help.
