View Full Version : Text to Pixel - Conversion

03-04-2013, 11:53 AM
I am asking at this point if this is possible. I have never scripted in Python, and am about to start learning. Here is the premise of what I am attempting to accomplish.

if "G" then (16 color for RED) else if "g" then (16 color for Maroon)

I need to know if Lightwave (Python) can read a text file and pull the text data to start with, then write out an image with those two color pixels.

Effectively, this would happen 'sample.txt' which contains a sequence of G's and g's would become and output an image of 8 pixels... (attached image - pixels inflated for presentation - actual image would be a line of 1x8 pixels).


03-05-2013, 06:24 AM
Python has the functionality to read text files. I don't believe LightWave has the functionality to create a texture map (image) and save that out however. You may try looking for a Python library someone else has created (maybe like PIL - Python Imaging Library (http://www.pythonware.com/library/pil/handbook/index.htm)) that can create/save a pixel image, but I don't think what you've asked is going to be directly connected to LightWave.

03-05-2013, 06:51 AM
Thanks for looking it over. Makes sense. I am getting a Python beginners code book in a few days. I have no issues starting from scratch - but wanted to check and see if the software I have (Lightwave) might be able to do it.

03-05-2013, 06:43 PM
Here's some code adapted from sdk docs - C:/Program Files/NewTek/LightWave11.0/sdk/lwsdk11.0/html/globals/imgutil.html

#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-

This is a LightWave Generic plug-in that creates an image.

import sys
import lwsdk

__author__ = ""
__date__ = ""
__copyright__ = ""
__version__ = ""
__maintainer__ = ""
__email__ = ""
__status__ = ""
__lwver__ = "11.5"

class create_image(lwsdk.IGeneric):
def __init__(self, context):
super(create_image, self).__init__()
self._imagelist = ""
self._imageID = ""
self._xsize = 0
self._ysize = 0

# LWGeneric -------------------------------------------
def process(self, ga):
filename = "D:\\testimage.tga"
imgutil = lwsdk.LWImageUtil()
pixmap = imgutil.create( 256, 20, lwsdk.LWIMTYP_RGB24 )
rgb = [0,0,0]
for x in range(256):
rgb[1] = rgb[1] + 1
for y in range(20):
rgb[0] = rgb[0] + 1
imgutil.setPixel( pixmap, x, y, rgb )

nsavers = imgutil.saverCount()
for saver in range(nsavers):
if "Targa Format (.tga)" == imgutil.saverName( saver ): break

if saver == nsavers:
print >>sys.stderr,"Couldn't find the Targa saver."
imgutil.save( pixmap, saver, filename )
imgutil.destroy( pixmap )

return lwsdk.AFUNC_OK

ServerTagInfo = [
( "Python Create Image", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "Create Image", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )

ServerRecord = { lwsdk.GenericFactory("LW_PyCreateImage", create_image) : ServerTagInfo }

03-05-2013, 08:14 PM
Thanks, that is informative.