Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

refactored code to use propper python naming coventions.

  • Loading branch information...
commit f7e069479afe9dab329279c3c69e429e3142c457 1 parent ea51001
Chris Pearson authored

Showing 1 changed file with 68 additions and 68 deletions. Show diff stats Hide diff stats

  1. 136  startrail.py
136  startrail.py
@@ -28,88 +28,88 @@
28 28
 locale_directory = gimp.locale_directory
29 29
 gettext.install( "gimp20-template" , locale_directory, unicode=True )
30 30
 
31  
-allowedTypes = ["jpg","jpeg","tiff","tif","bmp","png"]
32  
-LIGHTEN = 10
33  
-DIFFERENCE = 6
  31
+allowed_import_types = ["jpg","jpeg","tiff","tif","bmp","png"]
  32
+layer_mode_lighten = 10
  33
+layer_mode_difference = 6
34 34
 
35  
-def fileIsImage(fileName):
36  
-	isImage = 0
37  
-	ext = os.path.splitext(fileName)[1] # get the extension
  35
+def file_is_image(file_name):
  36
+	is_image = 0
  37
+	ext = os.path.splitext(file_name)[1] # get the extension
38 38
 	ext = ext.replace(".", "") # rip off the . from the extension
39  
-	if ext.lower() in allowedTypes: # is this an image?
40  
-		isImage = 1
41  
-	return(isImage)
42  
-		
43  
-def processDarkFrame(fileName, image, layerCount):
44  
-	darkFrame = pdb.gimp_file_load(fileName,"")
45  
-	
  39
+	if ext.lower() in allowed_import_types: # is this an image?
  40
+		is_image = 1
  41
+	return(is_image)
  42
+
  43
+def process_dark_frame(file_name, image, layer_count):
  44
+	dark_frame = pdb.gimp_file_load(file_name,"")
  45
+
46 46
 	# have we got a base image to work with?
47 47
 	if image == None:
48 48
 		# create a base image based on the dark frame
49  
-		image = pdb.gimp_image_new(darkFrame.active_layer.width, darkFrame.active_layer.height, 0)
50  
-		
  49
+		image = pdb.gimp_image_new(dark_frame.active_layer.width, dark_frame.active_layer.height, 0)
  50
+
51 51
 	# get the main layer of the new frame
52  
-	darkLayer = pdb.gimp_layer_new_from_drawable(darkFrame.active_layer, image)
  52
+	dark_layer = pdb.gimp_layer_new_from_drawable(dark_frame.active_layer, image)
53 53
 	# set the opacity to half that of the one before so we get an average
54  
-	darkLayer.opacity = 100.0 / pow(2, layerCount - 1)
  54
+	dark_layer.opacity = 100.0 / pow(2, layer_count - 1)
55 55
 	# add the new layer and flatten down to keep memory useage down.
56  
-	image.add_layer(darkLayer,0)
  56
+	image.add_layer(dark_layer,0)
57 57
 	image.flatten()
58 58
 	# Get rid of the image we loaded up.
59  
-	gimp.delete(darkFrame)
  59
+	gimp.delete(dark_frame)
60 60
 	return(image)
61 61
 
62  
-def createDarkImage(darkFrames):
63  
-	darkImage = None	
64  
-	layerCount = 1
65  
-	
66  
-	for fileName in os.listdir(darkFrames):
67  
-		fileName = os.path.join(darkFrames, fileName)
68  
-		if fileIsImage(fileName):
69  
-			darkImage = processDarkFrame(fileName, darkImage, layerCount)
70  
-			layerCount += 1
71  
-	
72  
-	return darkImage
73  
-
74  
-def processLightFrame(fileName, image, darkImage, saveIntermediate, imageCount, saveDir):
  62
+def create_dark_image(dark_frames):
  63
+	dark_image = None
  64
+	layer_count = 1
  65
+
  66
+	for file_name in os.listdir(dark_frames):
  67
+		file_name = os.path.join(dark_frames, file_name)
  68
+		if file_is_image(file_name):
  69
+			dark_image = process_dark_frame(file_name, dark_image, layer_count)
  70
+			layer_count += 1
  71
+
  72
+	return dark_image
  73
+
  74
+def process_light_frame(file_name, image, dark_image, save_intermediate, image_count, save_directory):
75 75
 	# load up the light frame into an image
76  
-	lightFrame = pdb.gimp_file_load(fileName,"")
77  
-	
  76
+	light_frame = pdb.gimp_file_load(file_name,"")
  77
+
78 78
 	# have we got a base image to work with?
79 79
 	if image == None:
80 80
 		# create a base image based on the light frame
81  
-		image = pdb.gimp_image_new(lightFrame.active_layer.width, lightFrame.active_layer.height, 0)			
  81
+		image = pdb.gimp_image_new(light_frame.active_layer.width, light_frame.active_layer.height, 0)
82 82
 
83 83
 	# did we make a dark frame?
84  
-	if darkImage != None:
85  
-		# As we have a dark image we need to difference it against the light frame.
  84
+	if dark_image != None:
  85
+		# As we have a dark image we need to layer_mode_difference it against the light frame.
86 86
 		# create a new layer from the dark image
87  
-		darkLayer = pdb.gimp_layer_new_from_drawable(darkImage.active_layer, lightFrame)
88  
-		# set the layer to difference
89  
-		darkLayer.mode = DIFFERENCE
90  
-		# add the layer to the lightFrame
91  
-		lightFrame.add_layer(darkLayer, 0)
  87
+		dark_layer = pdb.gimp_layer_new_from_drawable(dark_image.active_layer, light_frame)
  88
+		# set the layer to layer_mode_difference
  89
+		dark_layer.mode = layer_mode_difference
  90
+		# add the layer to the light_frame
  91
+		light_frame.add_layer(dark_layer, 0)
92 92
 		# flatten
93  
-		lightFrame.flatten()
94  
-				
95  
-	# Set the light frame to lighten 
96  
-	lightLayer = pdb.gimp_layer_new_from_drawable (lightFrame.active_layer, image)
97  
-	lightLayer.mode = LIGHTEN
  93
+		light_frame.flatten()
  94
+
  95
+	# Set the light frame to layer_mode_lighten
  96
+	light_layer = pdb.gimp_layer_new_from_drawable (light_frame.active_layer, image)
  97
+	light_layer.mode = layer_mode_lighten
98 98
 	# add this as new layer
99  
-	image.add_layer(lightLayer,0)
  99
+	image.add_layer(light_layer,0)
100 100
 	image.flatten()
101  
-	
  101
+
102 102
 	# are we saveing the intermediate frames?
103  
-	if saveIntermediate == 1:
104  
-		# build a save filename pad the number to 5 digits which should be plenty for any timelapse.
105  
-		intFileName = os.path.join(saveDir, "trail" + str(imageCount).zfill(5) + ".jpg")
106  
-		pdb.gimp_file_save(image,pdb.gimp_image_get_active_drawable(image),intFileName,intFileName)
107  
-	
  103
+	if save_intermediate == 1:
  104
+		# build a save file_name pad the number to 5 digits which should be plenty for any timelapse.
  105
+		intermediate_save_file_name = os.path.join(save_directory, "trail" + str(image_count).zfill(5) + ".jpg")
  106
+		pdb.gimp_file_save(image,pdb.gimp_image_get_active_drawable(image),intermediate_save_file_name,intermediate_save_file_name)
  107
+
108 108
 	# clean up our temp bits.
109  
-	gimp.delete(lightFrame)
  109
+	gimp.delete(light_frame)
110 110
 	return(image)
111 111
 
112  
-def startrail(frames, use_dark_frames, darkFrames, save_intermediate, save_directory):
  112
+def startrail(frames, use_dark_frames, dark_frames, save_intermediate, save_directory):
113 113
 	#Do some santity checking before we start
114 114
 	# Light frames
115 115
 	if len(frames) == 0:
@@ -121,7 +121,7 @@ def startrail(frames, use_dark_frames, darkFrames, save_intermediate, save_direc
121 121
 		return
122 122
 
123 123
 	# Dark frames
124  
-	if use_dark_frames == 1 and not os.path.exists(darkFrames):
  124
+	if use_dark_frames == 1 and not os.path.exists(dark_frames):
125 125
 		pdb.gimp_message("Intermediate frame save path doesn't exist.")
126 126
 		return
127 127
 
@@ -131,28 +131,28 @@ def startrail(frames, use_dark_frames, darkFrames, save_intermediate, save_direc
131 131
 		return
132 132
 
133 133
 	# create 1 dark frame averaged from all of them
134  
-	darkImage = None
  134
+	dark_image = None
135 135
 	if use_dark_frames == 1:
136  
-		darkImage = createDarkImage(darkFrames)
  136
+		dark_image = create_dark_image(dark_frames)
137 137
 
138 138
 	# Create a counter to count the frames we layer
139  
-	imageCount = 0
  139
+	image_count = 0
140 140
 
141 141
 	# Define an image to work in.
142 142
 	# This will be created from the first light frame we process
143 143
 	image = None
144  
-	for fileName in os.listdir(frames):
145  
-		fileName = os.path.join(frames, fileName)
146  
-		if fileIsImage(fileName):
147  
-			imageCount += 1
148  
-			image = processLightFrame(fileName, image, darkImage, save_intermediate, imageCount, save_directory)
  144
+	for file_name in os.listdir(frames):
  145
+		file_name = os.path.join(frames, file_name)
  146
+		if file_is_image(file_name):
  147
+			image_count += 1
  148
+			image = process_light_frame(file_name, image, dark_image, save_intermediate, image_count, save_directory)
149 149
 
150 150
 	# show the new image if we managed to make one.
151 151
 	if image == None:
152 152
 		pdb.gimp_message("No images found to stack")
153 153
 	else:
154 154
 		gimp.Display(image)
155  
-		gimp.delete(darkImage) # we don't need this any more so get rid of it so not to leak.
  155
+		gimp.delete(dark_image) # we don't need this any more so get rid of it so not to leak.
156 156
 
157 157
 register(
158 158
 	"startrail",
@@ -172,8 +172,8 @@ def startrail(frames, use_dark_frames, darkFrames, save_intermediate, save_direc
172 172
 	],
173 173
 	[],
174 174
 	startrail,
175  
-	menu="<Image>/File/Create/Python-Fu",   
176  
-	domain=("gimp20-template", locale_directory) 
  175
+	menu="<Image>/File/Create/Python-Fu",
  176
+	domain=("gimp20-template", locale_directory)
177 177
 	)
178 178
 
179 179
 main()

0 notes on commit f7e0694

Please sign in to comment.
Something went wrong with that request. Please try again.