ID:1816635
 
(See the best response by Ssj4justdale.)
Code:
mob/verb/testTextureProc()
var/Merger/Chalk/b1 = new()
var/Merger/Cobble/t1 = new()
AddTexture(b1, t1)

Merger/Chalk
name = "Chalk"
icon = 'Bases/Chalk.dmi'
icon_state = "Chalk"
subtype = "Base"

Merger/Cobble
name = "Cobble"
icon = 'Textures/Cobble.dmi'
icon_state = "Cobble"
subtype = "Texture"

proc/AddTexture(var/Merger/base, var/Merger/texture, saveas="Test.png")
var/icon/savem = base.icon //icon(base.icon, base.icon_state)
var/icon/textr = texture.icon //icon(texture.icon, texture.icon_state)
var/icon/ibase = base.icon //icon(base.icon, base.icon_state)
world << savem
world << textr
world << ibase
for(var/x = 1, x <= 16, x++)
for(var/y = 1, y <= 16, y++)
var/rgb0 = AvgRGB(texture.icon, texture.icon_state)
var/rgb1 = textr.GetPixel(x,y)
var/rgb2 = ibase.GetPixel(x,y)

var/r0=base2dec(copytext(rgb0,2,4),16)
var/b0=base2dec(copytext(rgb0,4,6),16)
var/g0=base2dec(copytext(rgb0,6,8),16)

var/r1=base2dec(copytext(rgb1,2,4),16)
var/b1=base2dec(copytext(rgb1,4,6),16)
var/g1=base2dec(copytext(rgb1,6,8),16)

var/r2=base2dec(copytext(rgb2,2,4),16)
var/b2=base2dec(copytext(rgb2,4,6),16)
var/g2=base2dec(copytext(rgb2,6,8),16)

var/rcng = r2 + (r1 - r0)
var/bcng = b2 + (b1 - b0)
var/gcng = g2 + (g1 - g0)

savem.DrawBox(rgb(rcng,bcng,gcng), x, y)
fcopy(savem, "Output/[saveas].png")


Problem description:
runtime error: Cannot execute null.GetPixel().
proc name: AddTexture (/proc/AddTexture)
source file: Run.dm,28
usr: Guest-2634703988 (/mob)
src: null
call stack:
AddTexture(Chalk (/Merger/Chalk), Cobble (/Merger/Cobble), "Test.png")
Guest-2634703988 (/mob): testTextureProc()


I can't understand why I keep getting null error. It seems to be set fine, and even outputs as the icon it's suppose to, but seems to lose it's icon before it attempts getpixel.

Edit:
Merger //Base for icons
parent_type = /obj/
var/list/mergewith = null
var/subtype = ""

(Merger is equal to object.)
Has the icon been used visually? You can't modify icons that already have been shown visually in the world. You have to initialize a copy of the icon via the icon() proc in order to use many of the icon procs on it.
You need to instantiate the new icon, like so.

texture.icon = new(base.icon)
In response to Ssj4justdale
Ssj4justdale wrote:
You need to instantiate the new icon, like so.

> texture.icon = new(base.icon)
>


Shouldn't this already be an icon, since it's from an object?

Ter13 wrote:
Has the icon been used visually? You can't modify icons that already have been shown visually in the world. You have to initialize a copy of the icon via the icon() proc in order to use many of the icon procs on it.

So like:
proc/AddTexture(var/Merger/base, var/Merger/texture, saveas="Test.png")
var/icon/savem = icon(base.icon) //icon(base.icon, base.icon_state)
var/icon/textr = icon(texture.icon) //icon(texture.icon, texture.icon_state)
var/icon/ibase = icon(base.icon) //icon(base.icon, base.icon_state)
world << savem
world << textr
world << ibase


That? When I do it that way, none of the icons show up when they are output to the chat. It doesn't give any errors though.
In response to KingCold999
Best response
KingCold999 wrote:
Ssj4justdale wrote:
You need to instantiate the new icon, like so.

> > texture.icon = new(base.icon)
> >

Shouldn't this already be an icon, since it's from an object?

Ter13 wrote:
Has the icon been used visually? You can't modify icons that already have been shown visually in the world. You have to initialize a copy of the icon via the icon() proc in order to use many of the icon procs on it.

So like:
>
> proc/AddTexture(var/Merger/base, var/Merger/texture, saveas="Test.png")
> var/icon/savem = icon(base.icon) //icon(base.icon, base.icon_state)
> var/icon/textr = icon(texture.icon) //icon(texture.icon, texture.icon_state)
> var/icon/ibase = icon(base.icon) //icon(base.icon, base.icon_state)
> world << savem
> world << textr
> world << ibase
>

That? When I do it that way, none of the icons show up when they are output to the chat. It doesn't give any errors though.

Well it generates the final output. I have no idea why it doesn't show nor why
<IMG>
and such doesn't work for it either.

Here is a work around 'til you find a plausible solution.

    var/icon/savem =  icon(base.icon, base.icon_state)
var/icon/textr = icon(texture.icon, texture.icon_state)
var/icon/ibase = icon(base.icon, base.icon_state)
world<<base.icon
world<<texture.icon
world<<base.icon
@Ssj4justdale

    world<<base.icon
world<<texture.icon
world<<base.icon


This is just outputting the object's icon. The only reason these are here was to test that the icons were working - they're not actually important. The problem lies in the icons do not seem to be actually created when, well, told to be created. So in the later part of the code when I try to draw to saveme (using DrawBox) there is nothing to draw to, and the file that is outputted from the code is blank.

What the code is suppose to do
Take 2 object's icons
-> One as the base (say, a color, or stone)
-> One as a grayscaled texture (Like a brick texture, or here a cobble texture)
Then it goes through each pixel, and changes the color of the bases' pixel depending on the texture's pixel subtracted from the average colour of the texture.

Basically, puts texture T onto icon I (Based on T's average, from -127 to +127) then saves it as a file.

Edit: I have an old version of the code that used static files that ~works~ (outputs the textures as it's suppose to). I was trying to make it dynamic, so that I could add a bunch of different bases or textures in the code, then select which textures go on which base.

Also, I can post the full zip project if necessary. It's a small file (>700kb)
In response to KingCold999
KingCold999 wrote:
@Ssj4justdale

>     world<<base.icon
> world<<texture.icon
> world<<base.icon
>

This is just outputting the object's icon. The only reason these are here was to test that the icons were working - they're not actually important. The problem lies in the icons do not seem to be actually created when, well, told to be created. So in the later part of the code when I try to draw to saveme (using DrawBox) there is nothing to draw to, and the file that is outputted from the code is blank.

What the code is suppose to do
Take 2 object's icons
-> One as the base (say, a color, or stone)
-> One as a grayscaled texture (Like a brick texture, or here a cobble texture)
Then it goes through each pixel, and changes the color of the bases' pixel depending on the texture's pixel subtracted from the average colour of the texture.

Basically, puts texture T onto icon I (Based on T's average, from -127 to +127) then saves it as a file.

Hmm? Well from my test, I generated a final result. I'll leave this to somebody else since I don't know what the issue is o.o
https://www.dropbox.com/s/ct0ji9rk2r7fmqi/ Texture%20Merger%20Advanced_src.zip?dl=0

Dropbox for the source code. Included is YMIHere.BaseConverter (used for RGB -> DEC)
In response to KingCold999
KingCold999 wrote:
https://www.dropbox.com/s/ct0ji9rk2r7fmqi/ Texture%20Merger%20Advanced_src.zip?dl=0

Dropbox for the source code. Included is YMIHere.BaseConverter (used for RGB -> DEC)


Thank you, that helped alot. The file you want is definitely being generated, its just the code you are using is generating the color #FFFFFF which is defined as white.
Update:

Ugh -.- fixed the problem.

Had to do with the way the AvgRGB was outputting. It was outputting directly as a number, which was then processed by copytext and base2dec, which just outputted it as 0.

Thanks Ter, Ssj4justdale. You guys are lifesavers >.< <3

Still one confusing part though: Why the icons would not output directly into the chat, when objects did. Must be built-in or something?

Edit: Updated version, if anyone needs the code.
https://www.dropbox.com/s/ad2liu7nhgsvxn0/ Texture%20Merger%20Advanced_src_fixed.zip?dl=0

Bonus points to whoever can tell me what I just did (artwise) because I have no idea if there is a name for this type of icon-texture-merging. o.o
In response to KingCold999
KingCold999 wrote:
Update:

Ugh -.- fixed the problem.

Had to do with the way the AvgRGB was outputting. It was outputting directly as a number, which was then processed by copytext and base2dec, which just outputted it as 0.

Thanks Ter, Ssj4justdale. You guys are lifesavers >.< <3

Still one confusing part though: Why the icons would not output directly into the chat, when objects did. Must be built-in or something?

I'm assuming so. Probably best to report it as a bug? Even if it isn't, it's best to be safe.