8:15:43 am - Wednesday September 26th, 2018
Search:     Cat:   
Downloads
Support
Portal
Stats
  • Total Hits: 127,756
  • Today's Hits: 238
  • Most Hits: 7/6/2018
  • Dynamic Hits: 3,394
  • Total Downloads: 552
  • Today's Downloads: 4
  • Newest: Korona
  • Members Online: 3/41
  • Guests Online: 4
Affiliates








Snippets



PNG Tiny 1-color Wallpaper or Background v1

/PNG [[/#6hex | /colorR,G,B | [/rand]] [[/wh] | [/width16-4096] [/height16-4096]] [/overwrite] [/+N] <[path\]filename.png>

Creates a very small 1-color .png image, using $compress to create the compressed data expected by the PNG format. If filename doesn't include path, image is written to your mirc.ini's folder. Quotes not needed, won't write to disk unless filename is *.png

If you want to make a wallpaper for a mobile device that mIRC can't run on, just create the .png on mIRC elsewhere and use the dimensions of the other screen.

Tested on mIRC6.35 and 7.51+, not sure how earlier it works

The syntax message always dispays every time you use the script, showing several examples. If you don't see 2 red lines at the top, then it didn't write your wallpaper to disk.

By default, creates dimensions 1366x768, but /wh overrides as whatever your current monitor resolution is. Or you can override with /widthN and/or /heightN

Color can be specified as either /# followed by 6 hex digits or /color followed by 3 comma-separated numbers 0-255. Or /rand randomly chooses 0-255 for each RGB value. Default color is of course, maroon.

/overwrite switch prevents accidental overwriting existing files, won't overwrite without it.

/+N defaults to /+3000 and is the number of extra bytes of uncompressed data. If +N isn't large enough, Explorer won't show the icon next to the filename, and some viewers won't show the image. The required number increases as width*height increases, and sometimes increasing N results in compressed data shrinking slightly.

Screenshot created with:
/png /#800000 /+972 /width1366 /height768 /overwrite maroon.png

Project icon created by converting screenshot to 64x64 .ico, results in filesize nearly 5x larger.

Uploaded By: maroon
Author: maroon
Added: 3/30/2018
Last Updated: Never
mIRC Version: used 6.35 & 7.51+
Hits: 256
Size: 12.03KB
Downloads: 6
Review By: entropy


  
  2    0


Source Code:
  1. ; syntax: -> /PNG [[/#6hex $(|) /colorR,G,B $(|) [/rand]] [[/wh] $(|) [/width16-4096] [/height16-4096]] [/overwrite] [/+N] <[path\]filename.png>
  2.  
  3. ; Creates a very small 1-color .png image, using $compress to create the compressed
  4. ; data expected by the PNG format. If filename doesn't include path, image is written
  5. ; to your mirc.ini's folder. Quotes not needed, won't write to disk unless filename is *.png
  6. ;
  7. ; If you want to make a wallpaper for a mobile device that mIRC can't run on, just create
  8. ; the .png on mIRC elsewhere and use the dimensions of the other screen.
  9. ;
  10. ; Tested on mIRC6.35 and 7.51+, not sure how earlier it works
  11. ;
  12. ; The syntax message always dispays every time you use the script, showing several examples.
  13. ; If you don't see 2 red lines at the top, then it didn't write your wallpaper to disk.
  14. ;
  15. ; By default, creates dimensions 1366x768, but /wh overrides as whatever your current monitor
  16. ; resolution is. Or you can override with /widthN and/or /heightN
  17. ;
  18. ; Color can be specified as either /# followed by 6 hex digits or /color followed by 3
  19. ; comma-separated numbers 0-255. Or /rand randomly chooses 0-255 for each RGB value.
  20. ; Default color is of course, maroon.
  21. ;
  22. ; /overwrite switch prevents accidental overwriting existing files, won't overwrite without it.
  23. ;
  24. ; /+N defaults to /+3000 and is the number of extra bytes of uncompressed data. If +N isn't
  25. ; large enough, Explorer won't show the icon next to the filename, and some viewers won't
  26. ; show the image. The required number increases as width*height increases, and sometimes
  27. ; increasing N results in compressed data shrinking slightly.
  28.  
  29. ; For example, 800x600 needs /+500 1024x768 needs /+640 1366x768 needs /+789
  30. ; i only know trial+error to find minimum /+N needed for a particular width/height. Sometimes increasing /+N shrinks filesize by 1
  31. alias PNG {
  32. var %width = 1366 , %height 768 , %rgb 128 0 0 , %extra 3000 , %filename , %OverwriteFlag 0 , %uncompressed
  33. echo -ag $str(=/,20)
  34. :parse_cmdline
  35. if (/#* iswm $1) { var %h $mid($1,3) | if (($len(%h) != 6) || (0 $+ $remove(%h,a,b,c,d,e,f) !isnum)) { goto syntax }
  36. var %rgb $regsubex(%h,/(.)(.)/g, $base(\1\2,16,10,2) $chr(32)) | goto set_rgb
  37. }
  38. elseif ($1 == /rand) { var %rgb $rand(0,255) $rand(0,255) $rand(0,255) | goto set_rgb }
  39. elseif (/color*,*,* iswm $1) {
  40. var %h $mid($1,7) | if (($remove(%h,$chr(44)) !isnum) || ($numtok(%h,44) !isnum 3)) { goto syntax }
  41. var %rgb $replace(%h,$chr(44),$chr(32))
  42. :set_rgb
  43. var %i 1 | while (%i isnum 1-3) { if ($gettok(%rgb,%i,32) !isnum 0-255) { goto syntax } | inc %i }
  44. goto nextparse
  45. }
  46. elseif ((/+* iswm $1) && ($mid($1,3) isnum 0-)) var %extra $v1
  47. elseif (/over* iswm $1) inc %OverwriteFlag
  48. elseif ($1 == /wh) var %width = $window(-1).w , %height $window(-1).h
  49. elseif (/width* iswm $1) { var %h $mid($1,7) | if (%h !isnum 16-4096) { goto syntax } | var %width %h }
  50. elseif (/height* iswm $1) { var %h $mid($1,8) | if (%h !isnum 16-4096) { goto syntax } | var %height %h }
  51. elseif ((/* iswm $1) || (*.png !iswm $1-)) goto syntax
  52. else { var %filename $noqt($1-) | goto top }
  53. ; 4096 max width/height can be changed, but uncompressed RAM image at 4096x4096 is 2048kb (2meg)
  54. :nextparse
  55. tokenize 32 $2- | if ($1 != $null) goto parse_cmdline
  56. ; finished processing the 'command line'
  57. :top
  58.  
  59. if ($isdir( %filename)) { PNG_Msg 4 Unable to Overwrite a Folder Name! %filename | goto syntax }
  60. if (($isfile(%filename)) && (!%OverwriteFlag)) { PNG_Msg 4 Unable to Overwrite without /overwrite switch: %filename | goto syntax }
  61.  
  62. ; this is extra size of extra 0x00 bytes in uncompressed image, causes minor change in .png filesize
  63. ; adding 7 then $int() causes value to round up, or could've used $ceil
  64. var %mem_needed $int($calc(%extra +(7+%width *%height)/8))
  65.  
  66. ; creating 256 byte string of 0x00's then double the length until the desired length. /bcopy doesn't allow N=S+1 to allow near unlimited copy
  67. ; if filled with values other than 0 the image will have different levels of vertical striations.
  68. ;bset &image 1 $str(0 $+ $chr(32),256) | var %image 256
  69. ;while (%mem_needed > %image) { bcopy &image $calc(1+%image) &image 1 $iif($calc(%mem_needed -%image) > %image,$v2,$v1) | var %image $bvar(&image,0) }
  70. ;bset -c &image 260280 0
  71.  
  72. bset -c &image %mem_needed 0
  73.  
  74. ; See PNG structure at top. Filling byte positions for items A thru U
  75. bset -c &pngfile 1 0
  76. png_replace 00 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52
  77. png_replace 10 00 00 07 80 00 00 04 38 01 03 00 00 00 D2 1D 53
  78. png_replace 20 00 00 00 00 03 50 4C 54 45 35 BF 5C 84 5A B5 09
  79. png_replace 30 00 00 01 13 49 44 41 54 18 19
  80.  
  81. ;width = bigendian 4 hex bytes file offset 10h
  82. /png_replace 10 $png_bigendian_dword($base(%width,10,16,8))
  83.  
  84. ;height = bigendian 4 hex bytes file offset 14h
  85. png_replace 14 $png_bigendian_dword($base(%height,10,16,8))
  86.  
  87. ;RGB colors = 3 bytes at offset 29h RR,GG,BB
  88. bset &pngfile $calc(1+$base(29,16,10)) %rgb
  89.  
  90. ;update IHDR string's CRC-32 to reflect new width/height within 17 bytes at offset 0x0C
  91. ;i have yet to encounter a pic viewer which refuses to display image because CRC32 was incorrect
  92. bcopy -c &png_temp 1 &pngfile 13 17 | var %crc $crc(&png_temp,1) | png_replace 1D $png_bigendian_dword($base(%crc,16,16,8))
  93.  
  94. ;update PLTE string's CRC-32 to reflect new colors within 7 bytes at offset 0x25
  95. bcopy -c &png_temp 1 &pngfile 38 7 | var %crc $crc(&png_temp,1) | png_replace 2C $png_bigendian_dword($base(%crc,16,16,8))
  96.  
  97. ;This uses mIRC to create the deflate compressed data which is the same as used by PNG except the first 2 bytes are different.
  98.  
  99. noop $compress(&image,bn1m2)
  100. ;Updates compressed data's length stored bigendian at offset 0x30 - convert length to hex then split into 4 byte values for storage
  101. png_replace 30 $png_bigendian_dword($base($bvar(&image,0),10,16,8))
  102.  
  103. ;$calc(1+$bvar(&pngfile,0)) is position for append. Newer mIRC allows -1 to append to destination
  104. bcopy &pngfile $calc(1+$bvar(&pngfile,0)) &image 3 $calc($bvar(&image,0) -2)
  105.  
  106. ;update PLTE string's CRC-32 to reflect new compressed data including the 4 IDAT bytes at offset 0x34
  107. bcopy -c &png_temp 1 &pngfile 53 $calc(4+$bvar(&image,0))
  108. var %crc $crc(&png_temp,1)
  109. ;append crc32 of IDAT + unchanging IEND chunk
  110. png_replace $base($calc($bvar(&pngfile,0) -0),10,16) $png_bigendian_dword($base(%crc,16,16,8)) 00 00 00 00 49 45 4E 44 AE 42 60 82
  111. if (%OverwriteFlag) btrunc $qt(%filename) 0
  112. bwrite $qt(%filename) 0 -1 &pngfile
  113. PNG_Msg 4 Success! Written $bvar(&pngfile,0) bytes to $qt(%filename) Uncompressed Mem Size: $+ %mem_needed Filesize: $file(%filename).size
  114. PNG_Msg 4 Width: $+ %width Height: $+ %Height Color:# $+ $base($rgb($gettok(%rgb,3,32),$gettok(%rgb,2,32),$gettok(%rgb,1,32)),10,16,6) Padding: $+ /+ $+ %extra
  115. :syntax
  116. PNG_Msg PNG $+ $chr(174) by maroon: Create tiny single color .png wallpaper
  117. PNG_Msg Syntax: /png [[/#6hex $(|) /colorR,G,B $(|) [/rand]] [[/wh] $(|) [/width16-4096] [/height16-4096]] [/overwrite] [/+N] <[path\]filename.png>
  118. PNG_Msg Switches in any order except filename last. List color as either hex /#d00d1e or decimal /color195,33,72 /rand = random rgb colors
  119. PNG_Msg /wh uses monitor's width/height $+($window(-1).w,x,$window(-1).h) /overwrite = allows overwriting existing file. (default 1366x768)
  120. PNG_Msg /+N increases uncompressed memory image by N bytes above 1/8*Width*Height (Default=/+3000) (some viewers need increased at larger w/h)
  121. PNG_Msg if /+N is too small, image may not be viewable
  122. PNG_Msg filesize increases along with width * height.
  123. PNG_Msg 13 Examples: /PNG /rand /overwrite random color.png
  124. PNG_Msg 5 /PNG /#C41E3A /overwrite cardinal.png
  125. PNG_Msg 12 /PNG /width1024 /height768 /color0,123,167 cerulean blue.png
  126. PNG_Msg 3 /PNG /wh /#84DE02 /overwrite alien armpit.png
  127. PNG_Msg 14 /PNG /color130,142,132 /overwrite /width4096 /height4096 /+3584 dolphin.png
  128. PNG_Msg 2 To find RGB colors, can use Alt-K, then RIGHT_CLICK on a colored square at bottom, then click 'define custom colors'
  129. PNG_Msg 13 Be sure to click CANCEL when exiting colors dialog to avoid changing mirc's own colors too
  130. PNG_Msg 2 You can also find 6-digit Hex Color Codes for many colors at https://en.wikipedia.org/wiki/Lists_of_colors
  131. }
  132.  
  133. alias PNG_Msg { var %c 12 | if ($1 isnum 0-15) { var %c $1 | tokenize 32 $2- } | echo -ag $+($chr(3),0,$chr(44),%c) $1- $chr(3) }
  134.  
  135. ; $1 is a 32-bit hex value, returns 4 hex bytes in bigendian order
  136. alias png_bigendian_dword { var %h $right(00000000 $+ $1,8) | return $mid(%h,1,2) $mid(%h,3,2) $mid(%h,5,2) $mid(%h,7,2) }
  137.  
  138. ; input = tokenized list of hex values, output = values converted from hex to decimal
  139. alias png_hex_to_dec { return $regsubex($1-,/(\w+)/g,$base(\t,16,10) $chr(32)) }
  140. ; input = tokenized list of dec values, output = values converted from dec to hex
  141. alias png_dec_to_hex { return $regsubex($1-,/(\d+)/g,$base(\t,10,16,2) $chr(32)) }
  142.  
  143. ; $1 is 0-based hex offset. $2- are variable length series of hex 0-FF values
  144. ; replaces bytes of &pngfile beginning at that offset, converting 0-based hex to 1-based decimal.
  145. ; "/png_replace 29 11 22 33" replaces 3 bytes at 1-based position 1+$base(29,16,10) with $chr($base(11,16,10)) $chr($base(22,16,10)) $chr($base(33,16,10))
  146. alias png_replace { bset -c &png_temp 1 $png_hex_to_dec($2-) | bcopy &pngfile $calc(1+$base($1,16,10)) &png_temp 1 $numtok($2-,32) }
  147.  
  148. ; assumes PNG file format is:
  149. ; <hex file offset> <hex length> <description>
  150. ; all dword values stored bytes bigendian, where 0x12345678 is stored as "0x12 0x34 0x56 0x78", 0x0D stored as "0 0 0 0x0D"
  151. ;(A) 00 8 Signature 0x89 "PNG" 0D 0A 1A 0A
  152. ;(B) 08 4 0x0D Dword length of IHDR data length excluding the "IHDR" string
  153. ;(C) 0c 4 "IHDR"
  154. ;(D) 10 4 Dword image pixel width
  155. ;(E) 14 4 Dword image pixel height
  156. ;(F) 18 1 Bit depth, bits per palette index (This image uses 0x01)
  157. ;(G) 19 1 Color type (This image uses 0x01, 'Palette used')
  158. ;(H) 1A 1 Compression method (This image uses 0x00 Deflate)
  159. ;(I) 1B 1 Filter method (This image uses 0x00)
  160. ;(J) 1C 1 Interlace method (This image uses 0x00, No Interlace)
  161. ;(K) 1D 4 Dword CRC32 of items D thru J above, the 4 bytes "IHDR" and 0x0D bytes of D thru J
  162. ;(L) 21 4 Dword Length of PLTE data excluding the "PLTE" string, 0x03
  163. ;(M) 25 4 "PLTE"
  164. ;(N) 29 1 Red Index 0x00 thru 0xFF
  165. ;(O) 2A 1 Green Index 0x00 thru 0xFF
  166. ;(P) 2B 1 Blue Index 0x00 thru 0xFF
  167. ;(Q) 2C 1 Dword CRC32 of the 7 byte string of items M thru P
  168. ;(R) 30 4 Dword length of IDAT data segment excluding the "IDAT" string, Items T-V
  169. ;(S) 34 4 "IDAT"
  170. ;(T) 38 1 Compression Method / Flags (This Image uses 0x18, Bit 0-3 CM 0x08 = Deflate, Bit 4-7 CINFO 0x01 = LZ Window size 2^(8+0x01) = 512 bytes )
  171. ;(U) 39 1 Flags (This Image uses 0x19), Bits 0-4 FCHECK = 0x19, Bit 5 FDICT=0, Bit 6-7 FLEVEL=0 - Byte "T" * 256 + FCHECK must be multiple of 31
  172. ;(V) 4A N Variable length compressed Data. Created by filling &image with 0x00's then using $compress(&image,bm1n2) substituting bytes T+U in place of 1st 2 bytes of $compress output
  173. ;(W) 4A+N 4 CRC32 of items S thru V, should be length of 4 + value in item R
  174. ;(X) 4E+N 4 Length of IEND Structure exluding "IEND" string, This Image uses 0x00
  175. ;(Y) 52+N 4 "IEND"
  176. ;(Z) 56+N 4 CRC32 of "IEND" + $null bytes following, i.e. $crc(IEND,0)
  177.  
  178. ; length of uncompressed data changes according to width/height used, which also affects size of compressed data at less than a dozen bytes per extra uncompressed 10k length.
  179. ; //var %i 32 | bset &a 1 $str(0 $+ $chr(32),32) | while (%i < 1000000) { bcopy &a %i &a 1 %i | inc %i %i } | var %j 10000 | while (%j < %i) { bcopy -c &b 1 &a 1 %j | noop $compress(&b,bn1m2) | echo -ag $bvar(&a,0) %j -> $bvar(&b,0) | inc %j 10000 }
  180.  


Comments
No Comments.