Skip to content

Commit

Permalink
backported GIMP fixes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Mar 10, 2022
1 parent 09faaff commit e8ce80c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
2 changes: 1 addition & 1 deletion docs/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Windows fixes
* Gimp fixes
* Fixed issues when loading TIFF images
* Downgraded to ImageMagick 6 (binaries, still compatible with v7)
* Downgraded to ImageMagick 6 (still compatible with v7)

## 1.2.2 - 20191103

Expand Down
63 changes: 45 additions & 18 deletions res/gimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@
cyanversion = "1.2.3"
cyanbin = "cyan"

def plugin_maketempfile( image, src ):
def plugin_maketempfile( image, src, type ):

tempimage = pdb.gimp_image_duplicate( image )

if not tempimage:
print("Could not create temporary image file.")
print "Could not create temporary image file."
return None, None, None

tempfilename = pdb.gimp_temp_name( "tif" )
if type == 1 :
tempfilename = pdb.gimp_temp_name( "psd" )
else:
tempfilename = pdb.gimp_temp_name( "tif" )

if sys.platform == "darwin":
tempfilename = os.path.join(tempfile.gettempdir(), "cyan-tmp.tif")
if type == 1 :
tempfilename = os.path.join(tempfile.gettempdir(), "cyan-tmp.psd")
else:
tempfilename = os.path.join(tempfile.gettempdir(), "cyan-tmp.tif")

if sys.platform.startswith( "win" ):
tempfilename = tempfilename.replace( "\\", "/" )
Expand All @@ -41,33 +47,55 @@ def plugin_maketempfile( image, src ):

def plugin_export( image, src):

tempfilename, tempdrawable, tempimage = plugin_maketempfile( image, 0 )
tempfilename, tempdrawable, tempimage = plugin_maketempfile( image, 0, 0 )

if tempfilename == None:
return

pdb.gimp_image_undo_group_start(image)
#pdb.gimp_image_undo_group_start(image)
pdb.gimp_progress_pulse()
child = subprocess.Popen( [cyanbin, tempfilename], stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True )
child = subprocess.Popen( cyanbin + " " + tempfilename, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True )

pdb.gimp_progress_set_text( "Waiting on Cyan ..." )
while child.poll() is None:
pdb.gimp_progress_pulse()
time.sleep(0.2)

plugin_tidyup( tempfilename )
pdb.gimp_image_undo_group_end(image)
#pdb.gimp_image_undo_group_end(image)

def plugin_import(image,src):

tempfilename, tempdrawable, tempimage = plugin_maketempfile( image, src )
tempfilename, tempdrawable, tempimage = plugin_maketempfile( image, src, 0 )

if tempfilename == None:
return

pdb.gimp_image_undo_group_start(image)
pdb.gimp_progress_pulse()
child = subprocess.Popen( [cyanbin, "-o", tempfilename], stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True )
child = subprocess.Popen( cyanbin + " -o " + tempfilename, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True )

pdb.gimp_progress_set_text( "Waiting on Cyan ..." )
while child.poll() is None:
pdb.gimp_progress_pulse()
time.sleep(0.2)

dest = 0;
plugin_saveresult( image, dest, tempfilename, tempimage )

plugin_tidyup( tempfilename )
pdb.gimp_image_undo_group_end(image)

def plugin_import_psd(image,src):

tempfilename, tempdrawable, tempimage = plugin_maketempfile( image, src, 1 )

if tempfilename == None:
return

pdb.gimp_image_undo_group_start(image)
pdb.gimp_progress_pulse()
child = subprocess.Popen( cyanbin + " -o " + tempfilename, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True )

pdb.gimp_progress_set_text( "Waiting on Cyan ..." )
while child.poll() is None:
Expand All @@ -88,15 +116,15 @@ def plugin_saveresult( image, dest, tempfilename, tempimage ):
if dest == 0 :
# new image
try:
newimage = pdb.file_tiff_load( tempfilename, "" )
newimage = pdb.gimp_file_load( tempfilename, "" )

# Write name
if name != None:
newimage.filename = name
gimp.Display( newimage )

except:
print("Could not load tmep file as new image.")
print "Could not load temp file as new image."

elif dest == 1:
# Replace current layer
Expand All @@ -110,7 +138,7 @@ def plugin_saveresult( image, dest, tempfilename, tempimage ):

image.add_layer( newlayer, pos )
except:
print("Could not load temp file into existing layer.")
print "Could not load temp file into existing layer."

elif dest == 2:
# Add as a new layer in the opened image
Expand All @@ -119,7 +147,7 @@ def plugin_saveresult( image, dest, tempfilename, tempimage ):

image.add_layer( newlayer,0 )
except:
print("Could not load temp file into new layer.")
print "Could not load temp file into new layer."

# cleanup
plugin_tidyup( tempfilename )
Expand All @@ -143,7 +171,7 @@ def plugin_tidyup( fname ):
"cyan-export",
"Export Image.",
"Export Image.",
"Ole-Andre Rodlie (olear@dracolinux.org)",
"Ole-Andre Rodlie (ole.andre.rodlie@gmail.com)",
"Copyright 2017 Ole-Andre Rodlie",
"2017",
"<Image>/Cyan/Export Image",
Expand All @@ -156,16 +184,15 @@ def plugin_tidyup( fname ):
"cyan-import",
"Import Image.",
"Import Image.",
"Ole-Andre Rodlie (olear@dracolinux.org)",
"Copyright 2017 Ole Andre Rodlie",
"Ole-Andre Rodlie (ole.andre.rodlie@gmail.com)",
"Copyright 2017 Ole-Andre Rodlie",
"2017",
"<Image>/Cyan/Import Image",
"*", # image types
[],
[],
plugin_import,
)

main()

#----------------------------------------------------------------------------------
44 changes: 11 additions & 33 deletions src/cyan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,41 +1214,19 @@ void Cyan::bitDepthChanged(int index)

void Cyan::gimpPlugin()
{
QStringList versions,folders;
versions << "2.4" << "2.6" << "2.7" << "2.8" << "2.9" << "2.10" << "3.0";
QStringList versions,folders,gimps;
versions << "2.4" << "2.6" << "2.7" << "2.8" << "2.9" << "2.10" << "2.99" << "3.0";
gimps << ".gimp-" << ".config/GIMP-AppImage/" << ".config/GIMP/" << "AppData/Roaming/GIMP/" << "Library/Application Support/GIMP/" << ".var/app/org.gimp.GIMP/config/GIMP/";
foreach (QString version, versions) {
bool hasDir = false;
QDir gimpDir;
QString gimpPath;
gimpPath.append(QDir::homePath());
gimpPath.append(QDir::separator());
#ifndef Q_OS_MAC
gimpPath.append(QString(".gimp-%1").arg(version));
if (gimpDir.exists(gimpPath)) { hasDir = true; }
if (!hasDir) {
gimpPath = QString("%1/.config/GIMP/%2").arg(QDir::homePath()).arg(version);
if (gimpDir.exists(gimpPath)) { hasDir = true; }
}
if (!hasDir) {
gimpPath = QString("%1/AppData/Roaming/GIMP/%2/").arg(QDir::homePath()).arg(version);
if (gimpDir.exists(gimpPath)) { hasDir = true; }
}
#else
gimpPath.append("Library/Application Support/GIMP/"+version);
if (gimpDir.exists(gimpPath)) {
hasDir = true;
}
#endif
if (hasDir) {
gimpPath.append(QDir::separator());
gimpPath.append("plug-ins");
if (!gimpDir.exists(gimpPath)) {
gimpDir.mkdir(gimpPath);
foreach (QString gimp, gimps) {
QString configPath = QString("%1/%2%3/plug-ins")
.arg(QDir::homePath())
.arg(gimp)
.arg(version);
if (QFile::exists(configPath)) {
folders << QString("%1/cyan.py").arg(configPath);
qDebug() << "found GIMP folder" << configPath;
}
QString result = gimpPath;
result.append(QDir::separator());
result.append("cyan.py");
folders << result;
}
}

Expand Down

0 comments on commit e8ce80c

Please sign in to comment.