
    h:&                         d dl mZmZmZ d dlmZ d dlmZ ddZ G d de      Z	 G d de      Z
 G d	 d
e      Z G d de      Zy)    )Image
ImageChops	ImageDraw)
processors)TestCasec                     t        j                  | |d      }t        j                  |      }|d   dz  |d   dz  }}|j	                  ||dz  |dz  |dz  fd       |j	                  |dz  ||dz  |d	z  fd       |S )
N)   r	   r	   r   
               red   )r   newr   Draw	rectangle)modesizeimagedrawx_bity_bits         [/home/dcms/DCMS/lib/python3.12/site-packages/easy_thumbnails/tests/test_pixel_processors.pycreate_imager      s    IIdD/2E>>% D7b=$q'R-5ENNE519eai;UCNNEAIueai;UCL    c                   \    e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zy)ScaleAndCropTestNc                     |j                   |j                   k7  s$t        j                  ||      j                         | j	                  |xs d      y )Nz!The two images were not identical)r   r   
differencegetbboxfailureException)selfim1im2msgs       r   assertImagesEqualz"ScaleAndCropTest.assertImagesEqual   sP    88sxx%%c3/779E''::< < Fr   c                 H   t               }t        j                  |d      }| j                  |j                  d       t        j                  |d      }| j                  |j                  d       t        j                  |dd      }| j                  |j                  d       y )Nd   r*   r*   K     r.      X  T)upscale)r.   i  r   r   scale_and_cropassertEqualr   )r#   r   scaled
not_scaledupscaleds        r   
test_scalezScaleAndCropTest.test_scale   s}    **5*=i0..ulC
*5,,UL$O4r   c                    t               }t        j                  |dd      }| j                  |j                  d       t        j                  |dd      }| j                  |j                  d       t        j                  |dd      }|j                  g d      }| j                  ||       t        j                  |dd      }|j                  g d	      }| j                  ||       y )
Nr)   Tcropr-   r/   r1   r1   )r*   r     r1   )r.   r*   )r      r0   i^  )r   r   r4   r5   r   r<   r'   )r#   r   both_croppednot_cropped	x_croppedexpected	y_croppeds          r   	test_cropzScaleAndCropTest.test_crop"   s    !00
N**J7 //|$O)):6--eZdK	::01y(3--e[tL	::01y(3r   c                    t               }t        j                  |dd      }|j                  g d      }| j	                  ||       t        j                  |dd      }|j                  g d      }| j	                  ||       t        j                  |dd      }|j                  g d	      }| j	                  ||       t        j                  |d
d      }|j                  g d      }| j	                  ||       t        j                  |dd      }|j                  g d      }| j	                  ||       t        j                  |dd      }|j                  g d      }| j	                  ||       y )Nr*   r1   z0,0r;   r   r   r*   r1   z-0,-0r>   r   r0   r1   )   r1   z10,-10)   r      r1   )r0   rJ   )r   i  r0   iI  z0,r0   r*   z,0r   r   r0   r*   r   r   r4   r<   r'   )	r#   r   tl_croprC   br_cropx_offset_cropy_offset_croponly_x_croponly_y_crops	            r   test_crop_cornerz!ScaleAndCropTest.test_crop_corner3   sB   ++E:EJ::./w1++E:GL::01w1"11:H.::/0}h7"11%7?A::01}h7 //zM::./{H5 //zM::./{H5r   c                     t               }t        j                  |dd      }|j                  g d      }| j	                  ||       y )Nr=   smartr;   )N   r   i  r1   rO   )r#   r   
smart_croprC   s       r   test_crop_smartz ScaleAndCropTest.test_crop_smartQ   s<    ..ujwO
::/0z84r   c                 V   t        d      }t        j                  |dd      }| j                  |j                  d       t        j                  |dd      }| j                  |j                  d       t        j                  |ddd	      }| j                  |j                  d
       y )N)   i  r   r)   scaler;   )r*   r]   r=   T)r<   r2   )r1   i  r3   r#   r   r6   s      r   test_crop_scalez ScaleAndCropTest.test_crop_scaleX   s    *-**5*7Kj1**5*7Kj1**5*7379k2r   c                     t               }t        j                  |d      }| j                  |j                  d       t        j                  |d      }| j                  |j                  d       y )Nr*   r   r+   r   r*      r*   r3   r`   s      r   test_one_dimension_scalez)ScaleAndCropTest.test_one_dimension_scaled   sU    **5(;i0**5(;j1r   c                     t               }t        j                  |dd      }| j                  |j                  d       t        j                  |dd      }| j                  |j                  d       y )Nrc   Tr;   r+   rd   re   r3   )r#   r   croppeds      r   test_one_dimension_cropz(ScaleAndCropTest.test_one_dimension_cropl   sY    ++E8$Gy1++E8$Gz2r   c                     t        d      }d}t        j                  ||d      }| j                  |j                  |       y )Ni`	  i$  r^   n   r.   Tr;   r3   r#   r   r   ri   s       r   test_croup_roundingz$ScaleAndCropTest.test_croup_roundingt   s9    ,/++E4dCt,r   c                     t        d      }d}t        j                  ||d      }| j                  |j                  d       y )Nrl   r^   r)   (   )zoom)B   r*   r3   )r#   r   r   r6   s       r   test_zoom_scalez ScaleAndCropTest.test_zoom_scale{   s9    ,/**5$R@i0r   c                     t        d      }d}t        j                  ||dd      }| j                  |j                  |       y )Nrl   r^   rm   Trr   )r<   rs   r3   ro   s       r   test_zoom_cropzScaleAndCropTest.test_zoom_crop   s;    ,/++E4dLt,r   c                    t               }d}t        j                  |dd|      }|j                  g d      }| j	                  ||       t        j                  |dd|      }|j                  g d      }| j	                  ||       d}t        j                  |dd|      }|j                  g d	      }| j	                  ||       t        j                  |dd|      }|j                  g d
      }| j	                  ||       y )N)_   r*   rG   Tr   r<   targetrI   rM   )r   i  r0   r1   )r      rH   rN   rO   r#   r   r{   rP   rC   s        r   test_crop_targetz!ScaleAndCropTest.test_crop_target   s     ++
f>::01w1++
f>::01w1 ++
f>::./w1++
f>::./w1r   c                    t               }d}t        j                  |dd|      }|j                  g d      }| j	                  ||       t        j                  |dd|      }|j                  g d      }| j	                  ||       y )Nz45,55rG   Trz   )i6  r   i  r1   rM   )r   i  r0   i|  rO   r}   s        r   test_crop_target_textz&ScaleAndCropTest.test_crop_target_text   s~    ++
f>::01w1++
f>::01w1r   )N)__name__
__module____qualname__r'   r9   rE   rV   r[   ra   rg   rj   rp   ru   rw   r~   r    r   r   r   r      sC    <
54"6<5
323-1-2:2r   r   c                   $    e Zd Zd Zd Zd Zd Zy)ColorspaceTestc                     t        j                  dd      }t        j                  |      }| j	                  |j
                  d       t        j                  dd      }t        j                  |      }| j	                  |j
                  d       y )NRGBr/   Lr   r   r   
colorspacer5   r   r#   r   	processeds      r   test_standardzColorspaceTest.test_standard   sj    		%,))%0	/		#z*))%0	-r   c                     t        j                  dd      }t        j                  |      }| j	                  |j
                  d       t        j                  dd      }t        j                  |      }| j	                  |j
                  d       y )NRGBAr/   LAr   r   s      r   test_transparentzColorspaceTest.test_transparent   sj    		&*-))%0	0		$
+))%0	.r   c                 @   t        j                  dd      }| j                  |j                         d   d       t	        j
                  |d      }| j                  |j                  d       | j                  |j                         d   d       t        j                  d	d      }| j                  |j                         d   d       t	        j
                  |d      }| j                  |j                  d
       | j                  |j                         d   d       y )Nr   r/   )r   r   )r   r   r   r   z#fefdfc)replace_alphar   )         r   r   r   )r   r   r5   loadr   r   r   r   s      r   test_replace_alphaz!ColorspaceTest.test_replace_alpha   s    		&*-d+\:))%yI	/)$/A		$
+d+V4))%yI	-)$/5r   c                 L   t        j                  dd      }t        j                  |d      }| j	                  |j
                  d       t        j                  dd      }t        j                  |d      }| j	                  |j
                  d       t        j                  dd      }t        j                  |d      }| j	                  |j
                  d       t        j                  dd      }t        j                  |d      }| j	                  |j
                  d       y )Nr   r/   T)bwr   r   r   r   r   s      r   test_bwzColorspaceTest.test_bw   s    		%,))%D9	-		&*-))%D9	.		#z*))%D9	-		$
+))%D9	.r   N)r   r   r   r   r   r   r   r   r   r   r   r      s    ./6/r   r   c                       e Zd Zd Zy)AutocropTestc                 z    t        j                  t               d      }| j                  |j                  d       y )NT)autocrop)i  i  )r   r   r   r5   r   )r#   r   s     r   r   zAutocropTest.test_standard   s*    ''F	4r   N)r   r   r   r   r   r   r   r   r      s    5r   r   c                       e Zd Zd Zd Zd Zy)BackgroundTestc                     t               }t        j                  |dd      }| j                  |j                  d       y )N#fffr0   r0   
backgroundr   )r   r   r   r5   r   r   s      r   
test_basiczBackgroundTest.test_basic   s4    ))f:7	4r   c                     t               j                  d      }t        j                  |dd      }| j	                  |j
                  d       | j	                  |j                  d       y )Nr   r   r   r   r   convertr   r   r5   r   r   r   s      r   test_grayscalezBackgroundTest.test_grayscale   sS    &&s+))f:7	4-r   c                    t               j                  d      }t        j                  |dd      }| j	                  |j
                  d       | j	                  |j                  d       t               j                  d      }t        j                  |dd      }| j	                  |j
                  d       | j	                  |j                  d       y )Nr   r   r   r   r   r   r   r   r   s      r   test_mode_alphazBackgroundTest.test_mode_alpha   s    &&v.))f:7	4/&&t,))f:7	4-r   N)r   r   r   r   r   r   r   r   r   r   r      s    5..r   r   N)r   r/   )PILr   r   r   easy_thumbnailsr   unittestr   r   r   r   r   r   r   r   r   <module>r      sJ    , , & d2x d2N0/X 0/f58 5.X .r   