Skip to content

Latest commit

 

History

History
347 lines (248 loc) · 9.41 KB

graphics.md

File metadata and controls

347 lines (248 loc) · 9.41 KB

+

entropy

(echo "P5 512 4096 255"; cat ./foo.bin) > foo.pgm

graphs

textures

graphics api

GLSL

if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
    alert(gl.getShaderInfoLog(shader));
}
void main() {
  float bug = 0.0;
  vec3 tile = texture2D(colMap, coords.st).xyz;
  vec4 col = vec4(tile, 1.0);

  if (crash) {
    bug = 1.0;
  }
  col.x += bug;

  gl_FragColor = col;
}

image from bytes

  • ~/code/guides/ctf/write-ups-2015/pragyan-ctf-2015/misc/255_255_255_is_the_best_color/go.py

animation

ffmpeg -framerate 75 -i 'input%04d0000.png' output.gif

# `-delay n`: 100/n FPS
# `-loop 0`: repeat forever
convert -delay 2 -loop 0 input*.png output.gif

convert

# SVG to PNG
for i in *.svg ; do inkscape -z -f "${i}" -w48 -h48 -e "${i%.svg}.png" ; done

# PhotoCD (PCD) to PNG
# FIXME: Low brightness using `-colorspace RGB`
find . -name "*.pcd" -type f -exec convert '{}[5]' ../../pngs/'{}'.png \;
# Alternatives:
g++ main.cpp pcdDecode.cpp -ljpeg -lpthread -o pcdtojpeg
find . -name "*.pcd" -type f -exec pcdtojpeg -r 5 '{}' \;

# PDF to JPEG
pdfimages -all foo.pdf ./out/
pdftoppm -tiff -r 300 foo.pdf ./out/pg
pdftoppm -jpeg -jpegopt quality=100 -r 300 foo.pdf ./out/pg

# LBM to PNG
ilbmtoppm foo.lbm | pnmtopng > foo.png

write / export from plaintext

{
  # magic, width, height, max component value
  echo "P3 250 250 255"
  for ((y=0; y<250; y++)) {
    for ((x=0; x<250; x++)) {
      # r, g, b
      echo "$((x^y)) $((x^y)) $((x|y))"
    }
  }
} | convert ppm:- png:- >foo.png

Alternatives:

seams

layer > transform > offset

light balance

duplicate layer gaussian blur invert colours layer tab > mode > overlay

lighten

duplicate layer gradient tool layer tab > mode > addition

posterize, alpha channel

https://orbitingweb.com/blog/optimizing-png-images/

xor

# highlight differences
compare i1.png i2.png -metric RMSE o.png
# render differences
composite i1.png i2.png -compose difference o.png

combine, tile

import numpy as np
from PIL import Image

data = np.zeros((2000,2000,4), dtype=np.uint8)

for i in range(100):
    for j in range(100):
        #modify_file("flag_{}_{}.jpg".format(i,j))
        im = Image.open("flag_{}_{}.png".format(i,j))
        array = np.array(im.getdata()).reshape(20,20,4)
        data[20*i:20*(i+1), 20*j:20*(j+1)] = array

img = Image.fromarray(data, 'RGBA')
img.save('flag.png')
montage -mode concatenate -tile 1x in-*.jpg out.jpg

# With padding
montage -tile 4x2 -geometry +2+2 -background none in-*.jpg out.jpg

https://superuser.com/questions/290656/combine-multiple-images-using-imagemagick

cut

# 1366x768
convert in.png +repage -crop "$((1366-$((1366-752+2))))x$((768-$((768-464+26))))+1+26" out.png
# 1/3 of 1366x768
convert in.png +repage -crop "$((490-20-2))x$((736-10-34))+11+34" out.png
# multiple tiles
convert in.png +repage -crop 32x32 %04d.png

scale

for i in *.png; do convert -strip -quality 92% -resize x2600\>  "$i" "$i".jpg; done

stitch, panorama

metadata

  • if distinct colors across apps, then check:
    • app color management enabled vs. disabled;
    • system default ICC profile vs. app built-in ICC profile vs. embedded ICC profile;
identify -verbose in.png

# Remove ICC profile
convert -strip in.png out.png
# ||
ect -strip --strict in.png

# Add ICC profile
icc=$HOME/.local/share/icc/edid-01230123012301230123012301230123.icc; pngcrush -iccp $(wc -c "$icc" | awk '{print $1}') "Profile" "$icc" foo.png && mv pngout.png foo.png

# Edit ICC v2
dcamprof dcp2json foo.dcp foo.json
dcamprof make-icc -p matrix foo.json foo.icc

# Remove all exif metadata
exiftool -all= foo.jpg

# Remove all exif metadata except orientation
exiftool -all= -tagsfromfile @ -Orientation foo.jpg

visual regression testing

responsive layouts

raw bitmap / 3 bytes per pixel

convert image.bmp -depth 8 image.rgb
convert -size 512x512 -depth 8 image.rgb image.bmp

preserve indexed palette on resize

convert _ -filter point -resize 50% o50.png
# ||
convert _ -sample 50% o50.png
# With custom sampling point
# Reference: https://imagemagick.org/script/command-line-options.php#sample
convert _ -define sample:offset=75x25 -sample 50% o50.png

apply transformation from color lookup table

convert -hald:16 hald_16.png
# [Apply transform with e.g. GIMP, take hald_16_processed.png]
convert foo.png hald_16_processed.png -hald-clut foo_processed.jpg

levels

http://www.imagemagick.org/discourse-server/viewtopic.php?t=27719

reversing gaussian blur

With G'MIC plugin:

Details > Sharpening

  • Richardson-Lucy Deconvolution
  • Gold-Meinel Deconvolution

lossless rotation

# Orientation values:
# - 1 = Horizontal (normal)
# - 2 = Mirror horizontal
# - 3 = Rotate 180
# - 4 = Mirror vertical
# - 5 = Mirror horizontal and rotate 270 CW
# - 6 = Rotate 90 CW
# - 7 = Mirror horizontal and rotate 90 CW
# - 8 = Rotate 270 CW
# References:
# - https://exiftool.org/TagNames/EXIF.html
exiftool -n -Orientation=8 -o output.jpg input.jpg
exiftool -n -Orientation="Rotate 270 CW" -o output.jpg input.jpg

aligning rotations

By FFT, what rotation?

unskew

Perspective Tool

untwist

Filters > Distorts > Whirl and Pinch...

frequency domain

Frequency Domain Image Compression and Filtering | Hacker News

seam carving, content aware resizing

ocr

small size / lossy compression

svgo foo.svg

pngquant --quality 40-60 -s1 --skip-if-larger -f foo.png && \
  ect -9 --allfilters --pal_sort=20 --mt-deflate foo-fs8.png
# ||
mogrify -strip PNG8:foo.png
# ||
cwebp -psnr 40 foo.png -o foo.webp