
    7j                     (   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZ ddlmZ  ej                  ddd	d
d       ej                  ddd	d       ej                  dddd       ej                  ddd	ddj                   e	j                                        ej                  ddd	d
d       ej                  ddd	d
d       ej                  d d!d	d
d"       ej"                  d#      d$                                                         Zy%)&z%This script tests QGF functionality.
    )BytesIO)normpath)generate_subsrender_headerrender_sourcevalid_formats)cli)Imagez-vz	--verboseT
store_truezTurns on verbose output.)arg_onlyactionhelpz-iz--inputzSpecify input graphic file.)requiredr   z-oz--output z>Specify output directory. Defaults to same directory as input.)defaultr   z-fz--formatzOutput format, valid types: , z-rz--no-rlez-Disables the use of RLE when encoding images.z-dz--no-deltasz:Disables the use of delta frames when encoding animations.z-wz--rawz9Writes out the QGF file as raw data instead of c/h combo.z4Converts an input image to something QMK understandsc           	         | j                   j                  dk7  rt        | j                   j                        | j                   _        | j                   j                  j                         s-| j                  j                  d        | j                          yt        | j                   j                        dk(  r/| j                   j                  j                  | j                   _        t        | j                   j                        | j                   _        | j                   j                  t        j                         vrh| j                  j                  d| j                   j                  ddj                  t        j                                       | j                          yt        | j                   j                     }t        j                  | j                   j                        }t!               }g }|j#                  |d| j                   j$                   | j                   j&                   || j                   j(                  |	       |j+                         }| j                   j,                  ra| j                   j                  | j                   j                  j.                   d
z  }t        |d      5 }|j1                  |       ddd       yt3        | ||d      }t5        |      }	| j                   j                  | j                   j                  j.                   dz  }
t        |
d      5 }t7        d|
 d       |j1                  |	       ddd       t9        |      }| j                   j                  | j                   j                  j.                   dz  }t        |d      5 }t7        d| d       |j1                  |       ddd       y# 1 sw Y   yxY w# 1 sw Y   xY w# 1 sw Y   yxY w)a  Converts an image file to a format that Quantum Painter understands.

    This command uses the `qmk.painter` module to generate a Quantum Painter image defintion from an image. The generated definitions are written to a files next to the input -- `INPUT.c` and `INPUT.h`.
    -z Input image file does not exist!Fr   zOutput format z is invalid. Allowed values: r   QGF)
use_deltasuse_rle
qmk_formatverbosemetadataz.qgfwbNpainter_convert_graphics)image_metadatacommand_namez.qgf.hwzWriting z...z.qgf.c)argsinputr   existslogerrorprint_usagelenoutputparentformatr   keysjoinr
   openr   save	no_deltasno_rler   getvaluerawstemwriter   r   printr   )r	   r)   	input_imgout_datar   	out_bytesraw_filer1   subsheader_textheader_fileheadersource_textsource_filesources                  Y/home/hanthebot/chat/keyboard/qmk_firmware/lib/python/qmk/cli/painter/convert_graphics.pyr   r   
   s    xx~~!#((..1 xx~~$$&GGMM<=COO 388??q ((..//sxx/CHHO xxm0022388??\`\e\efsfxfxfz\{|} 388??+F 

388>>*I yHHNN8UCHH4F4F0FVYV^V^VeVeResy  DG  DL  DL  DT  DT  _gN  h!!#I
xx||88??(;(;'<D%AA(D! 	!SIIi 	! iOijD  %K((//sxx~~':':&;6$BBK	k3	 "6S)*[!"
  %K((//sxx~~':':&;6$BBK	k3	 "6S)*[!" "#	!" "" "s$   >O9!O)3!O5O&)O25O>N)__doc__ior   qmk.pathr   qmk.painterr   r   r   r   milcr	   PILr
   argumentr+   r*   
subcommandr        r@   <module>rK      s1     R R   dK$|JdedI3PQdJ1qrdJ6RSWS\S\]o]j]o]o]qSrRs4tudJlIxydMD  MI  JdGd<  GB  CFG;" H C J z v s R f;"rJ   