Forums

Looking for a graphic library program

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Looking for a graphic library program

Postby gradha » Wed Jun 09, 2010 11:24 pm

Hi there.

I'm coming from Python+PIL background. I'm sick of it being so slow for pixel processing. Cython is much better, but I would prefer something that didn't feel awkward to write in. I haven't seen any PIL like graphic libraries for Cora. Are there any?

Also, maybe it's no point in rewriting the square wheel if you can use the shiny round one. Is there any C# library that Cobra can interface to nicely? (new to C# as well as Cobra). I'm looking for something that allows me to do pixel level manipulation at the typical rgb components.
gradha
 
Posts: 23

Re: Looking for a graphic library program

Postby Charles » Thu Jun 10, 2010 9:27 am

C#, Visual Basic and Cobra all produce "standard .NET libraries" so they can use each other's libraries seamlessly. .NET & Mono include a library called System.Drawing. Here is small program to get you started:
"""
DrawingExample.cobra

Generating bitmap images with the System.Drawing library.

References:

System.Drawing - <!-- m --><a class="postlink" href="http://msdn.microsoft.com/en-us/library/system.drawing.aspx">http://msdn.microsoft.com/en-us/library ... awing.aspx</a><!-- m -->

"""

@ref 'System.Drawing'

@number float64

use System.Drawing
use System.Drawing.Drawing2D
use System.Drawing.Imaging
use System.Drawing.Text

class Program

def main
.saveSample

def saveSample
bm = .makeBitmap
# bm.save('sample.jpg', ImageFormat.jpeg)
bm.save('sample.bmp', ImageFormat.bmp)
print 'Saved: sample.bmp'
print 'done.'

def makeBitmap as Bitmap
width = 480
height = 200

bm = Bitmap(width, height)
g = Graphics.fromImage(bm)

g.clear(Color.forestGreen)
# g.clear(Color.blue)
g.flush

g.smoothingMode = SmoothingMode.AntiAlias
g.textRenderingHint = TextRenderingHint.ClearTypeGridFit

if true
font = Font('Tahoma', 18, FontStyle.Bold)
brush = SolidBrush(Color.white)
g.drawString('The Cobra Programming Language', font, brush, 10, 50)
g.flush

if false
for i, hint in [TextRenderingHint.AntiAlias, TextRenderingHint.AntiAliasGridFit, TextRenderingHint.ClearTypeGridFit].numbered
font = Font('Tahoma', 18, FontStyle.Bold)
brush = SolidBrush(Color.white)
g.textRenderingHint = hint
g.drawString('The Cobra Programming Language', font, brush, 10, 10 + (50 * i))
g.flush

return bm
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Looking for a graphic library program

Postby Charles » Thu Jun 10, 2010 9:29 am

If you have any more questions or issues, feel free.

I have also attached the program to this message if that makes it easier to get.

-Chuck
Attachments
DrawingExample.cobra
(1.37 KiB) Downloaded 341 times
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Looking for a graphic library program

Postby gradha » Thu Jun 10, 2010 4:39 pm

That's a good starting point, thanks. Interesting convention about lower/upper case. What does cobra do if C# has two class methods or variables which are different only in the casing of the first letter?
gradha
 
Posts: 23

Re: Looking for a graphic library program

Postby Charles » Thu Jun 10, 2010 5:54 pm

You'll almost never see this. The reason is that .NET started with (at least) 2 languages: C# and Visual Basic (VB). VB is case insensitive, so people who write libraries avoid such practices. In fact, there is a "Common Language Specification" to avoid these issues. From http://blogs.msdn.com/b/brada/archive/2004/03/20/93341.aspx, "The CLS (or Common Language Specification) is simply a contract between programming language designers and class library authors."

In direct answer to your question, I couldn't remember since I'm not using any such libraries! But I constructed such a library in C#, and Cobra is binding to the first declared method.

Btw I think such a class would be poorly designed. For example, if a Color object had properties "brightness" and "Brightness", what differences between them are implied by a change in case?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Looking for a graphic library program

Postby gradha » Fri Jun 11, 2010 12:22 pm

Certainly the class would be not very nice to use. I only wanted to know if trying to use such a library would make Cobra crash or make the program unstable. I don't expect to find such a fabricated case in real life.
gradha
 
Posts: 23

Re: Looking for a graphic library program

Postby Charles » Fri Jun 11, 2010 5:54 pm

Cool. If you produce any graphics generation code that you can share back, that would be interesting to see.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Looking for a graphic library program

Postby gradha » Sat Jun 12, 2010 1:16 am

I was expecting to post the Cobra version of my Python program in one week or so to let you critizise it. It's not rocket science, I only process some input images in a way that are useful to me in another program, so I don't think it will be too interesting, especially since it makes assumptions on the input data to treat it correctly, which discards its use for other graphics.

Ouch, now I've remembered that the final part of the Python program calls a custom C module for packaging. Argh, that will be painful to port...
gradha
 
Posts: 23

Re: Looking for a graphic library program

Postby Charles » Sat Jun 12, 2010 10:49 am

You wrote this C module or its third party? Is it originally plain C code which is then wrapped up in a Python module, or is it a Python module to begin with? What platform are you on?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Looking for a graphic library program

Postby gradha » Sat Jun 12, 2010 12:42 pm

Custom modifications to an old C lib. I wanted it to work in obj-c on the iPhone and macosx build scripts in python. I guess I'll port it to C# or Cobra directly. It's not much work, just boring.
gradha
 
Posts: 23

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 90 guests