Jump to content


Photo

SVG file format


17 replies to this topic

#1 Jiaozi

Jiaozi
  • Newbies
  • 4 posts
  • Reputation:0

Posted 03 June 2008 - 05:34 PM

I were wondering how to convert a raster image to a SVG file. I play a bit with http://vectormagic.com/ that is the best converter I know and think to this "algorithm" :

[*:15cfkgt3]Use Magic Wand to grab some area. Convert the selected boundary to SVG path and fill with a color.
[*:15cfkgt3]Iterate through the surface as long as all the pixels of the surface has not been covered by the magic wand.
A bit rough, isn't it ? No circle or rectangle tag, this is just a raster-image converter.

Is it a too naive algorithm ? While simulating it, I see that my selection with magic wand isn't as smooth as vectormagic. This is what make me feel as a bad algorithm. Am I right ?
  • 0

#2 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 13,579 posts
  • LocationKirkland, WA
  • Reputation:328

Posted 03 June 2008 - 06:05 PM

I honestly don't see any value trying to convert bitmap/raster images into a vector format. Just save it as a PNG.
  • 0
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#3 harold

harold
  • Members
  • 374 posts
  • LocationNetherlands
  • Reputation:0

Posted 03 June 2008 - 06:32 PM

For pictures that do not contain large area's of roughly the came colour, the SVG file could end up bigger than the bitmap.
IMO there is nothing to gain from converting to SVG anyway, trying to smooth the curves would destroy some detail, depending on the tolerance JPG pictures (and other noisy images) may end up being encoded as width*height squares, gradients are hard to detect, and because you can never guess the correct curve from a raster image it won't be very scalable anyway.
Unless perhaps you use a very complex algorithm that takes a lot of time - and it still probably won't look the way you'd vectorize the picture yourself in most cases.
An SVG importer may come in handy though..


edit: I just tried that vectormagic thing on a multi-coloured font - complete disaster, but a nice try anyway. It can clearly be seen that it does not use the algorithm you described, the bitmap importer of Inkscape however looks like it does.
  • 0
I would write plugins, if I knew what kind of plugins were needed.. :(

#4 Jiaozi

Jiaozi
  • Newbies
  • 4 posts
  • Reputation:0

Posted 04 June 2008 - 07:51 AM

Here is why it may be useful: I'm a developer but not a designer. Silverlight and WPF use vectorized image, so converting a raster image to svg is the first step before converting to XAML.
I don't want to pay a designer for a little game I wrote as freeware and I don't know anybody who may draw for me. So the easiest way for me is to convert png image scanned or found.
  • 0

#5 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 13,579 posts
  • LocationKirkland, WA
  • Reputation:328

Posted 04 June 2008 - 08:30 AM

WPF allows you to use a bitmap source as well. You are not restricted to vectors.
  • 0
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#6 Jiaozi

Jiaozi
  • Newbies
  • 4 posts
  • Reputation:0

Posted 04 June 2008 - 09:44 AM

Yeah yeah I know that... but the game I want to code is Carcasonne. I'll need to display hundred of tiles so to decrease the memory, I wanted to use Xaml primitives. Moreover, that is the GPU that draws the primitives so I see clearly two advantages compared to holding hundred of png files.
  • 0

#7 harold

harold
  • Members
  • 374 posts
  • LocationNetherlands
  • Reputation:0

Posted 04 June 2008 - 12:23 PM

How many hundreds will you be needing?
My guess is that it if it's just a moderately high number, there would be no trouble with memory. Of course it's always nice to use less.. But is it really crucial?

I know that game, unless you're going to substantially increase the number of tiles in the computer version there shouldn't be a problem at all, you could even sub-tile the tiles, or have base-tiles (grass, city part, combinations in various shapes) + several detail sprites (clumps of grass etc) on top (basically sub-tiling with a separate background)
  • 0
I would write plugins, if I knew what kind of plugins were needed.. :(

#8 Jiaozi

Jiaozi
  • Newbies
  • 4 posts
  • Reputation:0

Posted 04 June 2008 - 01:28 PM

Hum good idea Harold ! I didn't think about subclassing my tiles. This will really increase my possibilities :)
Thank you, I will do that way

Yes I will increase the number (I consider implementing the different extensions) and provide zooming feature (to see the table in its entirety)
  • 0

#9 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 13,579 posts
  • LocationKirkland, WA
  • Reputation:328

Posted 04 June 2008 - 05:37 PM

If you're coding a game and performance is a concern, you should probably use Direct3D and DDS textures.
  • 0
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#10 J6628426

J6628426
  • Newbies
  • 3 posts
  • Reputation:0

Posted 18 August 2008 - 12:17 PM

I tell you what. I've come across many times when I really wanted / needed to load a .SVG into Paint.NET.

I'm working on a file plugin to load .SVG files.

Unless somebody out there is beating me to it...?
  • 0

#11 barkbark00

barkbark00
  • Members
  • 3,336 posts
  • Reputation:3

Posted 18 August 2008 - 03:23 PM

There has been talk, but no one has produced anything. If you can do it, I would love to see it... :D
  • 0
Posted Image
Take responsibility for your own intelligence. ;) -Rick Brewster

#12 harold

harold
  • Members
  • 374 posts
  • LocationNetherlands
  • Reputation:0

Posted 18 August 2008 - 05:49 PM

One could just use svg2png and load the png right
  • 0
I would write plugins, if I knew what kind of plugins were needed.. :(

#13 barkbark00

barkbark00
  • Members
  • 3,336 posts
  • Reputation:3

Posted 18 August 2008 - 07:40 PM

Is that a pdn plugin?
  • 0
Posted Image
Take responsibility for your own intelligence. ;) -Rick Brewster

#14 harold

harold
  • Members
  • 374 posts
  • LocationNetherlands
  • Reputation:0

Posted 18 August 2008 - 09:18 PM

no..
http://directory.fsf...roject/svg2png/
but maybe librsvg is better, not sure
http://ftp.gnome.org...ources/librsvg/
  • 0
I would write plugins, if I knew what kind of plugins were needed.. :(

#15 Andrew D

Andrew D
  • Members
  • 2,238 posts
  • Reputation:0

Posted 19 August 2008 - 08:39 PM

If you're coding a game and performance is a concern, you should probably use Direct3D and DDS textures.


Sorry for off-topic, but one thing I've never understood about games is how textures affect performance. I mean, the texture is just covering a model, so why does it improve your performance if you have texture settings lower?
  • 0

#16 harold

harold
  • Members
  • 374 posts
  • LocationNetherlands
  • Reputation:0

Posted 19 August 2008 - 09:03 PM

1) less memory is needed to store them (leading to less paging etc)
2) less GPU bandwidth is used on textures (leading to faster transfers of vertices etc)
3) better locality of reference in the pixelshader when using the texture (since it's smaller) so better use of GPU texture caches
there are probably more reasons

For 1 less mipmap, the ram usage for that texture is approximately divided by 4
  • 0
I would write plugins, if I knew what kind of plugins were needed.. :(

#17 Simon Brown

Simon Brown
  • Members
  • 10,255 posts
  • Reputation:27

Posted 19 August 2008 - 09:13 PM

If you're coding a game and performance is a concern, you should probably use Direct3D and DDS textures.


Sorry for off-topic, but one thing I've never understood about games is how textures affect performance. I mean, the texture is just covering a model, so why does it improve your performance if you have texture settings lower?


Remember that the texture must be loaded from memory, transformed to the shape of the object and sent to the screen each time a new frame is rendered.
  • 0
Posted Image

#18 harold

harold
  • Members
  • 374 posts
  • LocationNetherlands
  • Reputation:0

Posted 19 August 2008 - 09:34 PM

Usually not..
usually, the texture will already be in the GPU's dedicated ram during rendering (if it exists and is big enough)
the texture will not be transformed:
the vertices* will be transformed (or not, depending on the vertex shader, when it exists), and a pixel shader (or fragment shader, the GL equivalent) will sample from the texture (which is probably where the GPU's texture samplers come in)
The number of pixels send to the screen per second only depends on the size of the viewport and FPS

*: someone may decide to transform per-pixel instead, but I've never heard of anyone who did
  • 0
I would write plugins, if I knew what kind of plugins were needed.. :(