Home | Reviews | GUIpedia | Forum | Fun500


pharoahImage to QML converter in the works
I've written a beta version of an image to QML converter. Now it only works on 24 bit BMP files at 640x480 or less. It's a command line app, features a view function, and is somewhat slow (depending on the gradient used) because it builds its own lookup table at each run. For a sample of the output, just point your favorite (color) QML reader to: http://pharoah.xetaspace.net/icon/examples/lena.qml or http://pharoah.xetaspace.net/icon/examples/paltest.qml EDIT: Shortened URLS (case sensitive): http://is.gd/6t4M4 http://is.gd/6t52T Here's the code: [code] '************************ '* iCon Image Converter * '* > by Pharoah/Qlink * '************************ 'Version 0.80 unoptimized '+====================================================================+ '| LICENSE | '+====================================================================+ 'This program is free software. It comes without any warranty, to 'the extent permitted by applicable law. This program is released 'under the terms of the WTFPL 2.0: ' DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE ' Version 2, December 2004 ' Copyright (C) 2004 Sam Hocevar ' 14 rue de Plaisance, 75014 Paris, France ' Everyone is permitted to copy and distribute verbatim or modified ' copies of this license document, and changing it is allowed as long ' as the name is changed. ' DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE ' TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION ' 0. You just DO WHAT THE FUCK YOU WANT TO. dim mode as string * 1 if command(1) = "ver" then print "Icon 0.80 unoptimized" end elseif command(1) = "grad" then print "Icon image converter" print "Gradients:" print " 0 - High block characters" print " 1 - Round characters" print " 2 - Libcaca gradient" print " 3 - Balanced 8 gradient" print " 4 - High balanced 8 gradient" print " 5 - All uppercase letters" print " 6 - All lowercase letters" print " 7 - All letters" print " 8 - All low ASCII characters" print " custom= [gradient] - Custom gradient" end elseif command(1) = "view" then mode = "v" elseif command(1) = "convert" then mode = "c" else print "Icon Image Converter" print "Commands:" print " view [file] [gradient] - Show image" print " convert [file] [gradient] - Convert file.bmp to file.qml" print " ver - Show application version" print " grad - Show gradient list" end end if dim path as string = command(2) dim gradients(8) as string, gradient as string gradients(0) = chr(177) + chr(178) + chr(219) gradients(1) = ".:coCOQ@" gradients(2) = ".:;tSX%@B8" gradients(3) = ":&S8$" gradients(4) = ":&S8$" + chr(225) gradients(5) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" gradients(6) = "abcdefghijklmnopqrstuvwxyz" gradients(7) = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" for i as integer = 32 to 127: gradients(8) += chr(i): next if command(3) = "custom=" then gradient = command(4) else gradient = gradients(valint(command(3))) end if if mode = "c" then open left(path, instrrev(path, "."))+ "qml" for output as #1 end if type rgbType blue as ubyte green as ubyte red as ubyte end type type colorType union all as integer component as rgbType end union end type type charType mean as rgbType code as ubyte fg as ubyte bg as ubyte end type declare function average4(x as integer, y as integer, w as integer, h as integer, buffer as any ptr) as rgbType declare function average24(x as integer, y as integer, w as integer, h as integer, buffer as any ptr) as rgbType dim shared colors(15) as colorType colors(0).all = &h000000 colors(1).all = &h0000AA colors(2).all = &h00AA00 colors(3).all = &h00AAAA colors(4).all = &hAA0000 colors(5).all = &hAA00AA colors(6).all = &hAA5500 colors(7).all = &hAAAAAA colors(8).all = &h555555 colors(9).all = &h5555FF colors(10).all = &h55FF55 colors(11).all = &h55FFFF colors(12).all = &hFF5555 colors(13).all = &hFF55FF colors(14).all = &hFFFF55 colors(15).all = &hFFFFFF dim lookup(256 * len(gradient) - 1) as charType var current = 0 screen 12 for f as ubyte = 0 to 15 for b as ubyte = 0 to 15 for p as ubyte = 1 to len(gradient) dim c as ubyte = asc(mid(gradient, p, 1)) dim canvas as any ptr = imageCreate(8, 16, b, 4) draw string canvas, (0,0), chr(c), f lookup(current).mean = average4(0,0,8,16,canvas) lookup(current).fg = f lookup(current).bg = b lookup(current).code = c current += 1 imageDestroy canvas next next next color 15 dim source as any ptr = imageCreate(640, 480, 0, 32) bload path, source dim sample as rgbType dim as ubyte oldf = 7, oldb = 0 cls randomize timer if mode = "c" then print #1, "$"; end if for row as integer = 1 to 30 for column as integer = 1 to 79 sample = average24((column-1)*8, (row - 1)*16, 8, 16, source) var bestDistance = 1024 var best = 0 for i as integer = 0 to 256 * len(gradient) - 1 var distance = abs(sample.red - lookup(i).mean.red) + _ abs(sample.green - lookup(i).mean.green) + _ abs(sample.blue - lookup(i).mean.blue) if distance < bestDistance then best = i bestDistance = distance elseif distance = bestDistance then if rnd > .5 then best = i end if next i if mode = "v" then color lookup(best).fg, lookup(best).bg print chr(lookup(best).code); else if lookup(best).fg oldf or lookup(best).bg oldb then print #1, "" if lookup(best).fg oldf then print #1, "#";lookup(best).fg oldf = lookup(best).fg end if if lookup(best).bg oldb then print #1, ":";lookup(best).bg oldb = lookup(best).bg end if print #1, "$"; end if print #1, chr(lookup(best).code); end if next if mode = "v" then color ,0 print " "; else print #1,"" if oldb 0 then print #1,":0" oldb = 0 end if print #1, "|" print #1, "$"; end if next if mode = "v" then sleep function average4(x as integer, y as integer, w as integer, h as integer, buffer as any ptr) as rgbType dim as rgbtype result dim as integer red, green, blue dim as ubyte sample for horiz as integer = 0 to w - 1 for vert as integer = 0 to h - 1 sample = point(x + horiz, y + vert, buffer) red += colors(sample).component.red green += colors(sample).component.green blue += colors(sample).component.blue next next result.red = red (w * h) result.green = green (w * h) result.blue = blue (w * h) return result end function function average24(x as integer, y as integer, w as integer, h as integer, buffer as any ptr) as rgbType dim as rgbtype result dim as colorType sample dim as integer red, green, blue for horiz as integer = 0 to w - 1 for vert as integer = 0 to h - 1 sample.all = point(x + horiz, y + vert, buffer) and &hffffff red += sample.component.red green += sample.component.green blue += sample.component.blue next next result.red = red (w * h) result.green = green (w * h) result.blue = blue (w * h) return result end function [/code]
2010-01-172:16 AM

agumaRe:Image to QML converter in the works
neato
2010-01-171:23 PM

pharoahRe:Image to QML converter in the works
I added shortened URLs to the example pages, to save people a lot of typing into QML readers that don't have copy and paste. In case you're interested, I made them using my tool at http://pharoah.xetaspace.net/isgd (http://is.gd/6t5ua).
2010-01-174:13 PM

BrandonRe:Image to QML converter in the works
For CQML, I usually just open up bkmk.txt and paste the line there, launch CQML and open the bookmark.
2010-01-177:29 PM

trollyRe:Image to QML converter in the works
it's how my qml viewer render the first picture. [img size=696]http://theguiblog.com/images/fbfiles/images/lena.jpg[/img]
2010-01-211:25 PM

pharoahRe:Image to QML converter in the works
It looks like the palette you're using to display your 16 colors is a bit off. It's probably the 16 color palette of windows, but what you want is the EGA palette. The listing for that is here: http://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter You can also see it in my code above, because I use it to calculate the best character values. With so few colors to work with, the change is significant, which is probably why your output looks fairly ugly (compared with CQML's for example). Try using the EGA palette and see how that looks.
2010-01-216:50 PM

pharoahRe:Image to QML converter in the works
Icon now has a QML site, with a bunch of examples and an explanation of use, at http://pharoah.xetaspace.net/icon. Any seizures you get from viewing this page in CQML aren't my fault, although it seems to be the browser that renders such art best at the moment (at least until Trolly fixes his palette).
2010-01-233:29 PM

Other


2021 Brandon Cornell