Searching for a way to change image appearance in image viewer

hi all :slight_smile:
this is my first post in coding forum, as i thing my only solution relies here.

I need to change the colors of an image in image viewer.

Eg: with python, i add a flag in the props menu saying ‘my way to show image’

and image appears, say… colors inverted ^^

in unity this kind of thing can be done in minutes and i guess it’s the same in blender with python.

But where to start with that ?
could any kind python-master write the 15 lines of code so that i start with it and go further in the way i want to customize image display ?

this would be great !

or at least gimme some clue on where to start for what i wanna do ?
or mebe find some piece of python code concerning image viewer ?

thanks a lot ! can’t wait for your answers !

Happy blending !

Replying to my own post…

Okay: i found a way to draw things with GL in image editor :))

from bgl import *
import bpy


def draw_line():

    glColor3f(1.0, 0.0, 0.0)
    glLineWidth(2.0)
    glBegin(GL_LINES)
    glVertex3f(0.0, 0.0, 0.0)
    glVertex3f(1.0, 1.0, 1.0)
    glEnd()


handle = bpy.types.SpaceImageEditor.draw_handler_add(draw_line, (), 'WINDOW', 'POST_VIEW')

at least it’s a beginning !

now i need…

to get the common image drawn, whange bits and draw it over ^^

any help ?

ahahah passing parameters in a func is damn simple with python, even if i hate unformally typed languages :frowning:

from bgl import *
import bpy


def draw_line(r,g,b):

    glColor3f(r,g,b)
    glLineWidth(2.0)
    glBegin(GL_LINES)
    glVertex3f(0.0, 1.0, 1.0)
    glVertex3f(1.0, 0.0, 0.0)
    glEnd()


handle = bpy.types.SpaceImageEditor.draw_handler_add(draw_line, (0.0,1.0,0.0), 'WINDOW', 'POST_VIEW')

well… i’m stuck here :((

lack of python and blender api structure and referencing knowledge :’(

from bgl import *
import bpy


def draw_line(r,g,b):

    image = bpy.types.SpaceImageEditor.Image
    print("x="+image.size.x)
    print("y="+image.size.y)
    for x in range(0, image.size.x):
       for y in range(0, image.size.y):
          image.pixels[x+y*image.size.x]=x+y
   
    glColor3f(r,g,b)
    glLineWidth(2.0)
    glBegin(GL_LINES)
    glVertex3f(0.0, 1.0, 1.0)
    glVertex3f(1.0, 0.0, 0.0)
    glEnd()



handle = bpy.types.SpaceImageEditor.draw_handler_add(draw_line, (0.0,1.0,0.0), 'WINDOW', 'POST_VIEW')

The console keeps saying that SpaceImageEditor has no attribute Image…

any help please ?

omg !!! :open_mouth:

python is a real shit !!! XD lol
and no doubt i’m also a shitty programmer :smiley:

this:

from bgl import *
import bpy


done=0


def draw_line(r,g,b):

    global done
    if done == 1:
       return
    else:
        done=1 
        img = bpy.data.images[0]
        print("x=",img.size[0])
        print("y=",img.size[1])
       
        for x in range(0, img.size[0]):
           for y in range(0, 10):
              img.pixels[x*4+y*img.size[0]]=x
              img.pixels[x*4+y*img.size[0]+1]=y
              img.pixels[x*4+y*img.size[0]+2]=x-y
              img.pixels[x*4+y*img.size[0]+3]=1
       
        glColor3f(r,g,b)
        glLineWidth(2.0)
        glBegin(GL_LINES)
        glVertex3f(0.0, 1.0, 1.0)
        glVertex3f(1.0, 0.0, 0.0)
        glEnd()



handle = bpy.types.SpaceImageEditor.draw_handler_add(draw_line, (0.0,1.0,0.0), 'WINDOW', 'POST_VIEW')

take 4 minutes to run on a 881x600 image XD

wich makes python a totally useless language !

dev team should hardly think about adding another language support like c#
Even if c# is slow it’s at least 10K times faster ^^

gotta dig on this…

any advices ?

hmmm… any ppl using python over here ? XD

happy blending !

finally… tupple ( lol what a stupid word ) seems to copy a series of bytes in a python hardcoded buffer access thingie wich speeds up things by a factor… i’d say 2 or 3K :smiley:

from bgl import *
import bpy


done=0


def draw_line(r,g,b):

    global done
    if done == 1:
       return
    else:
        done=1 
        img = bpy.data.images[0]
        print("x=",img.size[0])
        print("y=",img.size[1])
        
        pixels = list(img.pixels) # tuple ??? wtf does this mean ???? XD
       
        for i in range(0, len(pixels), 4):
              pixels[i]  =1.0-pixels[i]       # red
              pixels[i+1]=1.0-pixels[i+1]     # green
              pixels[i+2]=1.0-pixels[i+2]     # bloo
              pixels[i+3]=1                   # A
       
        img.pixels[:] = pixels
        img.update()
        
        
handle = bpy.types.SpaceImageEditor.draw_handler_add(draw_line, (0.0,1.0,0.0), 'WINDOW', 'POST_VIEW')

well. as a conclusion python ( or mebe it’s a blender limit ? ) is unable to access an image buffer in
an efficient way.

As usual you gotta always know limits of a language, and it’s specificities for using it ( almost ) properly ^^

anyway, this seems to work :slight_smile: i can invert my image channels as i want, internally in blender.

Now i have to link this lil piece of code with a toggle that i’ll put on the N menu in the image editor…
This shouldn’t be that hard… x))

okay…

In an absolute honesty… sorry guys… but…
with python blender UI API, you just made a fat useless piece of shit !

it’s damn deeply obfuscated for those not digging in blender since years !

plz take some lessons from unity !
all is clear/simple/explained etc…

a toggle !!! i want to make a stoopid toggle in a N bar !!!

where must i specify it’s a f***ing toggle and not a button ???

am sad to see so much crap ! blender would be paradise with a clear and simple API…

but i’ll dig and post here what i found. mebe in ages, it could help some of the rare crazieslike me who dig in blender customization :stuck_out_tongue:

happy blending !

i’ll stop ask for help as it appears noone knows anything about this in BA x))
too bad :-/

Switch to 3dmax and be happy! :wink:

1 Like

ahahah XD

i NEVER switch to max :stuck_out_tongue:
better kik some asses here to get info and get mine kiked too :wink:

thx for your kind help anyway :stuck_out_tongue:

1 Like

Wow, so sad the only response you got out of 61 views from the community was a snippy reply to switch to max. I’m learning Python as well and hoped for better interaction. It’s seams this forum is not that active judging from the last post was 15 days ago.