tv_savemode set to jpeg not taken into account when exporting Topic is solved

A forum dedicated to George scripting questions
Post Reply
User avatar
Jeremy Richard
Posts: 53
Joined: 16 Oct 2021, 01:44
Contact:

tv_savemode set to jpeg not taken into account when exporting

Post by Jeremy Richard »

I am trying to use tv_savemode in a tv_request (with the choice between png and jpg), but it seems that tv_savemode "jpeg" is simply ignored. Even if I select jpeg I end up with pngs. What am I missing?

Here is what I would like:

Code: Select all

tv_Request "Choose format|png|jpeg"
IF RESULT == 1
    tv_SaveMode "png" "b32" "nodither" "255"
    tv_AlphaSaveMode NoPreMultiply
    background = "off"
ELSE
    tv_SaveMode "jpeg"
    background = "on"
END
Here is what I am doing for now:

Code: Select all

tv_Request "Choose format|png|jpeg"
IF RESULT == 1
    tv_SaveMode "png" "b32" "nodither" "255"
    PARSE RESULT format palette dithering colour
    export_format = format
    tv_AlphaSaveMode NoPreMultiply
    background = "off"
ELSE
    export_format = "jpg"
    background = "on"
END
I basically set a variable export_format, manually in the case of jpg.
The final export is done by using tv_clipsavestructure where the export format is set using this variable.

Here is my full script:

Code: Select all

//Export all
PARAM None
//Select colour
tv_listrequest "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z"
PARSE RESULT number letter
selectedgroup_colour = number
IF selectedgroup_colour == -1
	EXIT
ELSE
	//Request folder
	tv_reqfile "Where to save the files?"
	export_path = RESULT
	//Request file format
	tv_Request "Choose format|png|jpeg"
	IF RESULT == 1
		tv_SaveMode "png" "b32" "nodither" "255"
		PARSE RESULT format palette dithering colour
		export_format = format
		tv_AlphaSaveMode NoPreMultiply
		background = "off"
	ELSE
		//tv_SaveMode "jpeg"
		export_format = "jpg"
		background = "on"
	END
	//Export sequence according to layer colour group
	exportColourGroup(selectedgroup_colour, export_format, background)

END
//********************************************************
//	Export sequence according to layer colour group
//********************************************************
FUNCTION exportColourGroup(selectedgroup_colour, export_format, background)
	layerRun = 1
	layerPos = 0
	WHILE layerRun
		tv_LayerGetID layerPos
		layerID = RESULT
		IF CMP(layerID,"NONE") == 0
			tv_LayerColor GET LayerID
			group_colour = RESULT - 1
			IF selectedgroup_colour == group_colour
				exportSequence(export_format, background)
			END
			layerPos = layerPos + 1	
		ELSE
			layerRun = 0
		END
	END
END
//********************************************************
//	Exports image sequence using tv_clipsavestructure 
//	based on selected group and file format
//********************************************************
FUNCTION exportSequence(export_format, background)
	gabarit_dossier = "%cn-%ln"
	gabarit_fichier = "%ln.%4ii"
	tv_clipsavestructure '"'export_path'"' "JSON" "fileformat" export_format "background" background "patternfolder" gabarit_dossier "patternfile" gabarit_fichier "onlyvisiblelayers" "true" "allimages" "true"
END
Last edited by Jeremy Richard on 21 Jun 2023, 22:40, edited 1 time in total.
User avatar
Thierry
Site Admin
Posts: 2780
Joined: 07 Jan 2013, 08:28

Re: tv_savemode set to jpeg not taken into account when exporting

Post by Thierry »

Hmm, I would store the RESULT from tv_Request into a variable first, and then do the comparison after.
Can you try and see if it works?
User avatar
Jeremy Richard
Posts: 53
Joined: 16 Oct 2021, 01:44
Contact:

Re: tv_savemode set to jpeg not taken into account when exporting

Post by Jeremy Richard »

Thank you Thierry for your suggestion, unfortunately it's to no avail. It keeps ignoring tv_savemode "jpeg".

That is what I tried:

Code: Select all

tv_reqfile "Where to save the files?"
export_path = RESULT
tv_Request "Choose format|png|jpeg"
request_answer = RESULT
IF request_answer == 1
	tv_SaveMode "png" "b32" "nodither" "255"
	tv_AlphaSaveMode NoPreMultiply
ELSE
	tv_SaveMode "jpeg"
END
tv_clipsavestructure '"'export_path'"' "JSON"
Although, I do observe few things.

The first observation is that whatever I put for tv_savemode (tiff, tga, psd) it exports pngs.

This script always renders pngs:

Code: Select all

tv_reqfile "Where to save the files?"
export_path = RESULT
tv_SaveMode "jpeg" //or tiff or tga or psd
tv_clipsavestructure '"'export_path'"' "JSON"
The second observation is that it seems tv_savemode records the format selected in the export panel (no matter which tab), if selected just before running the script.
By simply selecting tiff, for example, in the export panel then closing the panel (not actually doing any export) then runing the script: tv_warn shows "Mode=15". But then if I re-run the script straight after, this time tv_savemode shows "jpeg". But, in both cases, pngs are exported.

So, this script always renders pngs, and tv_savemode shows, on a first run, the format I selected in the Export panel and not the one equal to tv_reqfile's answer:

Code: Select all

tv_reqfile "Where to save the files?"
export_path = RESULT
tv_Request "Choose format|png|jpeg"
request_answer = RESULT
IF request_answer == 1
	tv_AlphaSaveMode NoPreMultiply
	tv_SaveMode "png" "b32" "nodither" "255"
ELSE
	tv_SaveMode "jpeg"	
END
tv_warn RESULT
tv_clipsavestructure '"'export_path'"' "JSON"
Finally, it actually works with tv_saveimage, for example (instead of tv_clipsavestructure); tv_savemode "jpeg" is taken into account:

Code: Select all

tv_reqfile "Where to save the files?"
export_path = RESULT
tv_Request "Choose format|png|jpeg"
IF RESULT == 1
	tv_AlphaSaveMode NoPreMultiply
	tv_SaveMode "png" "b32" "nodither" "255"
ELSE
	tv_SaveMode "jpeg"	
END
tv_saveimage  export_path
I tried Hironori Takagi's technique and it seems to make a difference with tv_warn. By adding a second tv_savemode, tv_warn shows me the right format whatever I did before:

Code: Select all

tv_SaveMode "jpeg"
tv_SaveMode
tv_warn RESULT
whereas this doesn't, it shows me what I selected in the export panel (if I did so just before):

Code: Select all

tv_SaveMode "jpeg"
tv_warn RESULT
Unfortunately, this technique of the double tv_savemode won't fix my script. This script will prompt the right format but will still export pngs:

Code: Select all

tv_reqfile "Where to save the files?"
export_path = RESULT
tv_Request "Choose format|png|jpeg"
request_answer = RESULT
IF request_answer == 1
	tv_AlphaSaveMode NoPreMultiply
	tv_SaveMode "png" "b32" "nodither" "255"
	tv_SaveMode
ELSE
	tv_SaveMode "jpeg"
	tv_SaveMode
END
tv_warn RESULT
tv_clipsavestructure '"'export_path'"' "JSON"
This simpler script will also show me the right format but will export pngs:

Code: Select all

tv_reqfile "Where to save the files?"
export_path = RESULT
tv_SaveMode "jpeg"
tv_SaveMode
tv_warn RESULT
tv_clipsavestructure '"'export_path'"' "JSON"
User avatar
Hironori Takagi
Posts: 313
Joined: 14 May 2018, 10:15
Location: Tokyo, Japan
Contact:

Re: tv_savemode set to jpeg not taken into account when exporting

Post by Hironori Takagi »

The attached .grg will definitely work with jpeg.
It may be because it is specified as "JPG".
Attachments
ExportFrameJPEG_220606.grg
(5.63 KiB) Downloaded 675 times
TVPaint 11.7.2(Nov 14 2023), Windows11 Pro, HP Spectre x360 Convertible 14-ea0xxx / TVPaint 11.7.1(Dec 22 2022) Mac OS 11.6, Apple MacBookPro M1 2020
User avatar
Jeremy Richard
Posts: 53
Joined: 16 Oct 2021, 01:44
Contact:

Re: tv_savemode set to jpeg not taken into account when exporting

Post by Jeremy Richard »

Thank you Hironori, your script does export a jpg indeed, but if I replace tv_SaveDisplay by tv_clipsavestructure, it exports pngs.

Based on what I tested, only tv_clipsavestructure seems to have an issue with tv_savemode.

If instead of tv_clipsavestructure I put: tv_saveimage, tv_SaveDisplay or tv_savesequence I will end up with jpgs (or whatever format I set) as intended.

With this script (using tv_savesequence), jpgs are exported (whether I put JPG or JPEG)

Code: Select all

tv_reqfile "Where to save the files?"
export_path = RESULT
tv_SaveMode "JPG" "80"
tv_savesequence export_path
Also, whatever format I set for tv_savemode, and while using tv_clipsavestructure, I will end up with pngs.

This, for example, gives me pngs:

Code: Select all

tv_reqfile "Where to save the files?"
export_path = RESULT
tv_SaveMode "TGA"
tv_clipsavestructure '"'export_path'"' "JSON"
I tried on a different machine, using Linux, and I also end up with pngs.
User avatar
Hironori Takagi
Posts: 313
Joined: 14 May 2018, 10:15
Location: Tokyo, Japan
Contact:

Re: tv_savemode set to jpeg not taken into account when exporting

Post by Hironori Takagi »

I understand what you want to do. If you want to export jpeg with tv_ClipSaveStructure, you need to specify "fileformat" "jpg" in this command. I just recently created an in-house export tool, so I'm sharing the source code.
This code has a slightly special export rule (ignoring the layer name and exporting it in the same folder with only the instance name as the file name), so please refer only to the necessary parts.
Attachments
ExportKey_230526.grg
(2.53 KiB) Downloaded 708 times
TVPaint 11.7.2(Nov 14 2023), Windows11 Pro, HP Spectre x360 Convertible 14-ea0xxx / TVPaint 11.7.1(Dec 22 2022) Mac OS 11.6, Apple MacBookPro M1 2020
User avatar
Jeremy Richard
Posts: 53
Joined: 16 Oct 2021, 01:44
Contact:

Re: tv_savemode set to jpeg not taken into account when exporting

Post by Jeremy Richard »

Thank you very much Hironori.

I think I know where I misunderstood the tv_clipsavestructure command.

By reading this in the documentation, under tv_clipsavestructure:

Code: Select all

The tv_savemode command may be called before this command to manage the file format options (added in 11.0.8)
_ "png"
_ "jpg"
_ "bmp"
_ "tga"
_ "tiff"
somehow I thought that you didn't need to precise "fileformat"; that having tv_savemode made it optional. But I guess what it really means is that anything else that is taken into account by tv_savemode, like the power option (in the case of jpeg) doesn't need to be specified in the tv_clipsavestructure command.

Due to my misunderstanding of the command all my tests were prone to error. :roll:

So, in my case of a tv_Request between png and jpeg I'll have to assign a variable:

Code: Select all

tv_Request "Choose format|png|jpeg"
request_choice = RESULT
IF request_choice == 1
	tv_SaveMode "png" "b32" "nodither" "255"
	PARSE RESULT format palette dithering colour
	export_format = format
ELSE
	tv_SaveMode "jpeg" "100"
	export_format = "jpg"
END
then I can specify it in the tv_clipsavestructure command:

Code: Select all

tv_clipsavestructure '"'export_path'"' "JSON" "fileformat" export_format
Thank you for the sharing of your scripts Hironori, they are very instructive.

And here is my working script:
Export_image_seq_chosen_colour_group.grg
(2.29 KiB) Downloaded 729 times
Post Reply