Bläddra i källkod

Proof of concept for animated gif ingester

Kirk Trombley 3 år sedan
förälder
incheckning
e752769e4b
2 ändrade filer med 54 tillägg och 0 borttagningar
  1. 46 0
      anim-ingest.py
  2. 8 0
      database-anim.js

+ 46 - 0
anim-ingest.py

@@ -0,0 +1,46 @@
+import io
+import os
+
+from PIL import Image
+from colorspacious import cspace_convert
+import requests
+import numpy as np
+
+import ingest
+
+base = "https://play.pokemonshowdown.com/sprites/ani/"
+back_base = "https://play.pokemonshowdown.com/sprites/ani-back/"
+
+
+def get_all_pokemon() -> list[str]:
+  return ["abomasnow", "malamar", "porygon", "luxray", "eternatus", "roselia"]
+
+
+def load_image(base: str, name: str) -> Image:
+  return Image.open(io.BytesIO(requests.get(base + name + ".gif").content))
+
+
+def get_all_pixels(im: Image) -> list[tuple[int, int, int]]:
+  rgb_pixels = []
+  for fr in range(getattr(im, "n_frames", 1)):
+    im.seek(fr)
+    rgb_pixels += [
+      (r, g, b) 
+      for r, g, b, a in im.convert("RGBA").getdata() 
+      if not ingest.is_outline(r, g, b, a)
+    ]
+  return rgb_pixels
+
+
+with open("database-anim.js", "w") as outfile:
+  outfile.write("const databaseV2 = [\n")
+  for name in get_all_pokemon():
+    print("Ingesting", name, "...")
+    front = get_all_pixels(load_image(base, name))
+    back = get_all_pixels(load_image(back_base, name))
+    rgb_pixels = np.array(front + back)
+    jab_pixels = cspace_convert(rgb_pixels, "sRGB255", "CAM02-UCS")
+    stats = [len(rgb_pixels), *ingest.all_stats(jab_pixels), *ingest.all_stats(rgb_pixels)]
+    outfile.write(f'  [ "{name}", {", ".join(str(n) for n in stats)} ],\n')
+  outfile.write("];\n")
+

+ 8 - 0
database-anim.js

@@ -0,0 +1,8 @@
+const databaseV2 = [
+  [ "abomasnow", 643230, 5561.683924195126, 69.61371653270888, -6.552328149810986, -3.3503899532443286, 0.9871714201603669, -0.11833094999331704, -0.050692096178482554, 166294.0, 3535.7258554772825, 57.43832996371286, -13.310106424388616, -2.3809724392633496, 0.9718977968150249, -0.22641090794474383, -0.04397266203585501, 345817.0, 8221.288657154266, 90.05465142395899, -3.7849488853143662, -4.310778732630666, 0.9973297363293017, -0.04320825431645221, -0.049841083109893776, 131119.0, 1116.6236442939894, 31.143860544943895, -5.280421063173782, -2.046914099623875, 0.9797506306646524, -0.17938736990896464, -0.06145862404857882, 97853.80921287875, 154.6996128911898, 171.7657261010836, 173.22804284626028, 0.5206800054170534, 0.6014273578939828, 0.6029890452241935, 225128.0, 95201.54762623929, 159.38666891723818, 183.1818432180804, 184.73617675278064, 0.515900933594613, 0.6041499470038564, 0.6047429822115582, 199219.0, 181351.6986682997, 241.80266440449958, 245.9067759601243, 249.2102359714686, 0.5680573742173808, 0.5778582396576014, 0.5858963475904898, 218883.0, 24585.13282895428, 70.60093748715067, 92.5435232521484, 92.23545912656533, 0.48247434690058105, 0.6200788069486696, 0.6167421909834353 ],
+  [ "malamar", 628082, 4167.084868688256, 58.89642878956935, -2.892587133702653, -8.700346537960106, 0.9768668673172857, -0.04760538372695553, -0.16219948681172827, 87506.0, 446.60274266484925, 20.507051290144, -1.3885088324457333, -3.3122678320690486, 0.982550012576519, -0.06140261351044498, -0.14711958933450495, 343692.0, 6285.2858586264765, 77.35320403328726, -4.650285652228623, -8.838701222474876, 0.9817850352468004, -0.062091583960833203, -0.1216292515264189, 196884.0, 2123.017165301362, 43.739559111797455, -0.4927423347291772, -10.853583047760482, 0.9657555313069112, -0.016185199658841846, -0.2397235457202969, 71173.07975073319, 129.18789903229197, 139.3201397269783, 155.30687394321123, 0.5229118054250865, 0.5629295245151814, 0.6349261616014913, 107120.0, 8136.777613890963, 45.66628080657207, 49.83833084391337, 55.37501867064974, 0.5306864809377827, 0.569906251440729, 0.6247841834648933, 343692.0, 109008.56156675162, 171.57871582696134, 187.57765673917345, 203.10538505406004, 0.5202296287865488, 0.5737970004471418, 0.6256972411388606, 177270.0, 35908.772584193604, 97.47046877644271, 99.82992046031477, 123.0212895583009, 0.5234139739415877, 0.5376437371544024, 0.6589477943068051 ],
+  [ "porygon", 101357, 3515.570588349243, 51.10438533343862, -1.9933199646891657, -1.2253959018218328, 0.9268833654309083, -0.02952181225354969, -0.014323399602875844, 32809.0, 3335.6550036666754, 50.39738913276146, 23.399802825578398, 7.808068746542724, 0.8927989400746245, 0.42421202738862573, 0.14339969626470986, 29963.0, 6359.117917426759, 75.77347505541844, -19.53824962030628, -9.48579708981618, 0.9569994330314935, -0.251455471686252, -0.12057764694527918, 38585.0, 1460.4103394633594, 32.54888197744337, -9.960774632423336, -2.4920161131067573, 0.9324790160184252, -0.24299221026420442, -0.0659248260431776, 50383.038102943065, 102.27037106465266, 114.27301518395375, 118.3311759424608, 0.5170798586120328, 0.557259690266675, 0.5707850936645003, 28990.0, 52352.32590548465, 186.15132804415316, 83.24832700931356, 90.28796136598827, 0.8342036127914324, 0.37557126163317467, 0.4032174088365938, 26052.0, 103255.45919699063, 105.19902502686934, 206.29379702134193, 217.1845539689851, 0.3257538056933235, 0.6482452289436921, 0.6834395627085977, 46315.0, 19409.876756990176, 48.11931339738746, 81.93101586958869, 80.27967181258771, 0.42620236097493125, 0.61980513542373, 0.6123032401757511 ],
+  [ "luxray", 481923, 1308.4453445506877, 30.793184110391618, -2.234146306534059, -0.43421944328594764, 0.9886065032994706, -0.060091391072342244, -0.019770830284091323, 406600.0, 683.706163278295, 24.438132868923358, -0.9779450079087972, -0.2789961619803096, 0.9937666626484947, -0.04565385823438134, -0.017799995524282467, 16818.0, 5701.707499793154, 69.2722123872759, 1.7639349405362836, 28.401582895372304, 0.9237142591086764, 0.02453659152887553, 0.3815574474454187, 58505.0, 4387.379934414728, 63.89844925535156, -12.11383485344978, -9.802210382733872, 0.9713983496648737, -0.18475721900480954, -0.14883467761676844, 18632.832035408148, 65.37347252569394, 69.3819635086933, 65.54597103686689, 0.5657830890363467, 0.5846924983212747, 0.5650908110457513, 407758.0, 9707.677038831856, 53.17343620480776, 53.455682046704176, 52.22502562794599, 0.5750891843537216, 0.5803113078212203, 0.5700085861915681, 10799.0, 107533.39096212613, 140.65496805259747, 199.21187146958053, 218.85109732382628, 0.4293355395690631, 0.6079459724538765, 0.6678835901398353, 63366.0, 60915.226619953915, 131.05061073761954, 149.7410756557144, 125.13912823911878, 0.5291524396753442, 0.6089223883027032, 0.5159268843488245 ],
+  [ "eternatus", 1475335, 1641.572743964594, 28.67351057036864, 6.020722815834343, -7.639587544866286, 0.7841597361805709, 0.16378861860298694, -0.358554314130898, 805836.0, 484.27706277314434, 12.995466045270197, 0.5342239355959215, -12.441105402055472, 0.6701218920121427, 0.11484768359457101, -0.6102115495744787, 233181.0, 5644.39888543137, 68.76118298312286, 24.956217432659592, 5.3497526972270935, 0.9180249125851333, 0.34069749972416186, 0.07420138446601506, 436318.0, 1639.7564541548618, 36.205285897758614, 6.034063410103737, -5.713541411079159, 0.9232348706030145, 0.1596324240253506, -0.12504560391184064, 25002.814682089152, 72.81499388274527, 51.05716057708927, 78.84307902950856, 0.5032631365557709, 0.38182459575918587, 0.6895025170804737, 797839.0, 5621.211288242364, 19.19507193807272, 20.375340137546548, 51.62586311273327, 0.38349486366884483, 0.3292917613697332, 0.7931479959979069, 254292.0, 89465.03185707769, 221.70029336353483, 114.49181256193667, 141.16060277161688, 0.7600491678597303, 0.37606901482636784, 0.4681875817231914, 423204.0, 22808.064491356414, 84.43994149393673, 70.78341178249732, 92.70898904547217, 0.5747585987870455, 0.4843197097978568, 0.6270886747977452 ],
+  [ "roselia", 219670, 3284.821239565047, 49.7895634688487, -3.8878007137815804, 3.519302100166895, 0.9420250836630227, -0.07278135882958477, 0.05237987468114377, 109786.0, 4944.650255009824, 66.44562768361519, -12.123759042178554, 5.135392537302601, 0.954561069150146, -0.17681686223527066, 0.06795729334350771, 24584.0, 4594.660495581721, 61.96569008231939, 25.443253020751037, 6.276191622446199, 0.9202546702396778, 0.37978966851418583, 0.09083152938008167, 85300.0, 771.0219833018531, 24.843015256080516, -1.7410446055401616, 0.6447478592862156, 0.9321649211876526, -0.06931552482418532, 0.021248831722512285, 44094.19095916602, 105.12171438976647, 115.61478126280329, 100.93333636818865, 0.5484351870759853, 0.6075455578942863, 0.5348427063241263, 71627.0, 52468.79072137602, 108.26610077205522, 164.40433076912336, 109.28437600346238, 0.47803308702782216, 0.7293036942850762, 0.48251719830944323, 62743.0, 81932.9491257989, 174.16769998246815, 143.45294295778015, 158.21715569864367, 0.6165364410966754, 0.49758469022770174, 0.5634512783821933, 85300.0, 9229.423540445487, 51.69410316529895, 54.16930832356389, 51.78540445486518, 0.557459973002453, 0.586186878936706, 0.5577375659481728 ],
+];