Vzurxy

Free Draw2 PNG

Jan 1st, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.77 KB | None | 0 0
  1. local png = "cheems.png" --in workspace folder
  2.  
  3. --builderboy256
  4.  
  5. getfenv().bit32 = bit
  6.  
  7. local Unfilter = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Modules/Unfilter.lua"))()
  8. local BinaryReader = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Modules/BinaryReader.lua"))()
  9. local Deflate = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Modules/Deflate.lua"))()
  10.  
  11.  
  12. local PNG = {}
  13. PNG.__index = PNG
  14.  
  15. local chunks = {
  16.     IDAT = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/IDAT.lua"))(),
  17.     IEND = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/IEND.lua"))(),
  18.     IHDR = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/IHDR.lua"))(),
  19.     PLTE = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/PLTE.lua"))(),
  20.     bKGD = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/bKGD.lua"))(),
  21.     cHRM = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/cHRM.lua"))(),
  22.     gAMA = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/gAMA.lua"))(),
  23.     sRGB = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/sRGB.lua"))(),
  24.     tEXt = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/tEXt.lua"))(),
  25.     tIME = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/tIME.lua"))(),
  26.     tRNS = loadstring(game:HttpGet("https://raw.githubusercontent.com/CloneTrooper1019/Roblox-PNG-Library/master/Chunks/tRNS.lua"))()
  27. }
  28.  
  29. local function getBytesPerPixel(colorType)
  30.     if colorType == 0 or colorType == 3 then
  31.         return 1
  32.     elseif colorType == 4 then
  33.         return 2
  34.     elseif colorType == 2 then
  35.         return 3
  36.     elseif colorType == 6 then
  37.         return 4
  38.     else
  39.         return 0
  40.     end
  41. end
  42. local function clampInt(value, min, max)
  43.     local num = tonumber(value) or 0
  44.     num = math.floor(num + 0.5)
  45.     return math.clamp(num, min, max)
  46. end
  47. local function indexBitmap(file, x, y)
  48.     local width = file.Width
  49.     local height = file.Height
  50.     local x = clampInt(x, 1, width)
  51.     local y = clampInt(y, 1, height)
  52.     local bitmap = file.Bitmap
  53.     local bpp = file.BytesPerPixel
  54.     local i0 = ((x - 1) * bpp) + 1
  55.     local i1 = i0 + bpp
  56.     return bitmap[y], i0, i1
  57. end
  58.  
  59. function PNG:GetPixel(x, y)
  60.     local row, i0, i1 = indexBitmap(self, x, y)
  61.     local colorType = self.ColorType
  62.     local color, alpha
  63.     do
  64.         if colorType == 0 then
  65.             local gray = unpack(row, i0, i1)
  66.             color = Color3.fromHSV(0, 0, gray)
  67.             alpha = 255
  68.         elseif colorType == 2 then
  69.             local r, g, b = unpack(row, i0, i1)
  70.             color = Color3.fromRGB(r, g, b)
  71.             alpha = 255
  72.         elseif colorType == 3 then
  73.             local palette = self.Palette
  74.             local alphaData = self.AlphaData
  75.             local index = unpack(row, i0, i1)
  76.             index = index + 1
  77.             if palette then
  78.                 color = palette[index]
  79.             end
  80.             if alphaData then
  81.                 alpha = alphaData[index]
  82.             end
  83.         elseif colorType == 4 then
  84.             local gray, a = unpack(row, i0, i1)
  85.             color = Color3.fromHSV(0, 0, gray)
  86.             alpha = a
  87.         elseif colorType == 6 then
  88.             local r, g, b, a = unpack(row, i0, i1)
  89.             color = Color3.fromRGB(r, g, b, a)
  90.             alpha = a
  91.         end
  92.     end
  93.     if not color then
  94.         color = Color3.new(1, 1, 1)
  95.     end
  96.     if not alpha then
  97.         alpha = 255
  98.     end
  99.     return color, alpha
  100. end
  101. function PNG.new(buffer)
  102.     local reader = BinaryReader.new(buffer)
  103.     local file = {
  104.         Chunks = {},
  105.         Metadata = {},
  106.         Reading = true,
  107.         ZlibStream = ""
  108.     }
  109.     local header = reader:ReadString(8)
  110.     if header ~= "\137PNG\r\n\26\n" then
  111.         error("PNG - Input data is not a PNG file.", 2)
  112.     end
  113.     while file.Reading do
  114.         local length = reader:ReadInt32()
  115.         local chunkType = reader:ReadString(4)
  116.         print(length, chunkType)
  117.         local data, crc
  118.         if length > 0 then
  119.             data = reader:ForkReader(length)
  120.             crc = reader:ReadUInt32()
  121.         end
  122.         local chunk = {
  123.             Length = length,
  124.             Type = chunkType,
  125.             Data = data,
  126.             CRC = crc
  127.         }
  128.         local handler = chunks[chunkType]
  129.         if handler then
  130.             handler(file, chunk)
  131.         end
  132.         table.insert(file.Chunks, chunk)
  133.     end
  134.     local success, response = pcall(function()
  135.         local result = {}
  136.         local index = 0
  137.         Deflate:InflateZlib({
  138.             Input = BinaryReader.new(file.ZlibStream),
  139.             Output = function(byte)
  140.                 index = index + 1
  141.                 result[index] = string.char(byte)
  142.             end
  143.         })
  144.         return table.concat(result)
  145.     end)
  146.     if not success then
  147.         error("PNG - Unable to unpack PNG data. " .. tostring(response), 2)
  148.     end
  149.     local width = file.Width
  150.     local height = file.Height
  151.     local bitDepth = file.BitDepth
  152.     local colorType = file.ColorType
  153.     local buffer = BinaryReader.new(response)
  154.     file.ZlibStream = nil
  155.     local bitmap = {}
  156.     file.Bitmap = bitmap
  157.     local channels = getBytesPerPixel(colorType)
  158.     file.NumChannels = channels
  159.     local bpp = math.max(1, channels * (bitDepth / 8))
  160.     file.BytesPerPixel = bpp
  161.     for row = 1, height do
  162.         wait()
  163.         local filterType = buffer:ReadByte()
  164.         local scanline = buffer:ReadBytes(width * bpp, true)
  165.         bitmap[row] = {}
  166.         if filterType == 0 then
  167.             Unfilter:None(scanline, bitmap, bpp, row)
  168.         elseif filterType == 1 then
  169.             Unfilter:Sub(scanline, bitmap, bpp, row)
  170.         elseif FilterType == 2 then
  171.             Unfilter:Up(scanline, bitmap, bpp, row)
  172.         elseif FilterType == 3 then
  173.             Unfilter:Average(scanline, bitmap, bpp, row)
  174.         elseif FilterType == 4 then
  175.             Unfilter:Paeth(scanline, bitmap, bpp, row)
  176.         end
  177.     end
  178.     return setmetatable(file, PNG)
  179. end
  180.  
  181. local key
  182. local layerkey
  183. local old
  184. old = hookfunction(Instance.new("RemoteFunction").InvokeServer, function(self, ...)
  185.     local args = {...}
  186.     key = args[1]
  187.     layerkey = args[3].Layer
  188.     return old(self, ...)
  189. end)
  190. local h = Instance.new("Hint", workspace)
  191. h.Text = "Draw a line to load the script (getting keys)"
  192. repeat wait() until key and layerkey
  193. h:Destroy()
  194. hookfunction(Instance.new("RemoteFunction").InvokeServer, old)
  195.  
  196. local pos = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
  197. local function drawpixel(x, y, color)
  198.     spawn(function()game.ReplicatedStorage.Request:InvokeServer(key, "draw", {Color=color,Transparency=0,Layer=layerkey,Thickness=1}, {Vector3.new(x, 0, y), Vector3.new(x + 1, 0, y)})end)
  199. end
  200.  
  201. local buf = readfile(png)
  202. png = PNG.new(buf)
  203. for x = 1, png.Width do
  204.     for y = 1, png.Height do
  205.         local color, a = png:GetPixel(x, y)
  206.         if a ~= 0 then
  207.             drawpixel(pos.X + x, pos.Z + y, color)
  208.         end
  209.     end
  210.     wait()
  211. end
Add Comment
Please, Sign In to add comment