summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--photoblaster/modules/pbconcat/__init__.py141
1 files changed, 105 insertions, 36 deletions
diff --git a/photoblaster/modules/pbconcat/__init__.py b/photoblaster/modules/pbconcat/__init__.py
index b8f7b69..11e399c 100644
--- a/photoblaster/modules/pbconcat/__init__.py
+++ b/photoblaster/modules/pbconcat/__init__.py
@@ -67,6 +67,7 @@ class PbConcat(ModuleBase):
return ([self.params.img_url1], [self.params.img_url2])
im1_frames = self.params.img_url1.get_file().get_frames()
im2_frames = self.params.img_url2.get_file().get_frames()
+ #here well it's similar but not exactly, let's just keep it local for each method
if len(im1_frames) > len(im2_frames):
if self.params.frames_match == "shorter":
im1_frames = self._reduce_frames(
@@ -94,42 +95,99 @@ class PbConcat(ModuleBase):
return frames
def _match_dimensions(self):
- im1_width, im1_height = self.params.img_url1.get_file().get_dimensions()
- im2_width, im2_height = self.params.img_url2.get_file().get_dimensions()
- if self.params.merge_direction == "right" and \
- im1_height != im2_height:
- """match heights"""
- if im1_height > im2_height:
- if self.params.dimensions_match == "smallest":
- self.params.img_url1.get_file().resize(
- height=im2_height, module=self)
- else:
- self.params.img_url2.get_file().resize(
- height=im1_height, module=self)
- else:
- if self.params.dimensions_match == "smallest":
- self.params.img_url2.get_file().resize(
- height=im1_height, module=self)
- else:
- self.params.img_url1.get_file().resize(
- height=im2_height, module=self)
- elif self.params.merge_direction == "down" and \
- im1_width != im2_width:
- """match widths"""
- if im1_width > im2_width:
- if self.params.dimensions_match == "smallest":
- self.params.img_url1.get_file().resize(
- width=im2_width, module=self)
- else:
- self.params.img_url2.get_file().resize(
- width=im1_width, module=self)
- else:
- if self.params.dimensions_match == "smallest":
- self.params.img_url2.get_file().resize(
- width=im1_width, module=self)
- else:
- self.params.img_url1.get_file().resize(
- width=im2_width, module=self)
+ #so here I get dimensions store them into variables
+ im1 = {
+ 'image': self.params.img_url1.get_file(),
+ }
+ im2 = {
+ 'image': self.params.img_url2.get_file(), # => def _im2 but without hashes, hash will be only used in this function, rest can use just plain object.
+ }
+ #thing is that I have no set_frames method for the image_file
+ #also get_frames() calls a shell command, and I'd like to avoid calling it a ton, unless you think it's fine you can make a subclass for file like giffile or
+ #something, and as for get_frames, you just add caching, call shell once and write into internal variable, if it's set - return it, if not, call shell.
+ #yeah of course but how this works is
+ #I get the frames of two gifs
+ #I add frames one of the frames arrays by looping
+ #I merge the two frame arrays of equal length
+ #then I make a new gif
+
+ #so I wouldn't want to set the frames on the original gifs at all, just need to store them into a variable, do you know what I mean?
+ #i think so, just don't call set_frames on original gifs, it's fine to have code that does something only for part of application.
+ #but if I set the frames on the original gifs, I have to recompile the gif and that will make the program run wayy slower
+ #so yu need frames only as variable, not actually change it? right
+ #i need them only to merge two gifs together frame by frame, but the gifs I'm merging I don't need to change well keep get_frames then, and make
+ #something like local variable that you can set on file, like a temporary variable inside object, this way you don't have to recomplie gif.
+ #what could it look like?
+ #gif = GifFile("some.gif"); gif.get_frames(); # calls shell, gif.get_frames() # gets from local variable. gif._temporary_frames = myframes
+ #i guess something like this. hmm. not sure about this because I only need to do this temporary frames method in this plugin
+ #I'll never need it outside of this script. shouldn't I just store it locally? yeah you can store it in local variable, or make a local subclass of file or giffile
+ #which implemente just this method. ahhh awesome
+ #so I call it MyGifFile(GifFile) something like that? PbConcatGifFile maybe.
+ #ok. I find this part of programming, learning how to structure a project, very difficult and elusive, is it essentially something that
+ #not many coders know who to do well? looks so. ok I understand, and the only way to learn is to just code a lot and make mistakes,
+ #gradually get better that way? yep I see...one more quick question
+
+
+
+ images = [ im1, im2 ]
+ map(lambda i: i['width'], i['height'] = i['image'].get_dimensions(), images)
+
+ param_name = self.params.merge_direction == "right" ? "height" : "width"
+ if self.params.merge_direction == "right" and im1[param_name] != im2[param_name]:
+ im_scale = im1[param_name] > im2[param_name] and self.params.dimensions_match == "smallest" ?
+ im1 :
+ im2
+ im_scale_by = im_scale == im1 ? im2 : im1
+ im_scale['image'].resize(height=im_scale_by[param_name], module=self)
+
+ # something like this, could be bugs but you get the idea.
+ #so the main idea that I need to ask about is that
+ #file is already a class
+ #the image url param is also already a class
+ #but it's cool to store things in hashes that refer to the classes? sure it's temporary "object" that helps to solve this
+ #so hashes are just fair game for anything procedural and I can throw them out without worrying about integrating
+ #them into the class based system? yep
+ #should im1 and im2 hashes be hidden attributes of this class? i guess no need, is there more code like this? yep
+
+# if self.params.merge_direction == "right" and \
+# im1_height != im2_height:
+# """match heights"""
+# #ok so if the first image is taller than the second,
+# #and the dimensions param says to go by the smallest, shrink
+# #the first image, if the dimensions_param says to go by the tallest
+# #make the second image bigger...do you see what I mean when I say this
+# #is sort of confusing? yeah, let's rewrite it
+# if im1_height > im2_height:
+# if self.params.dimensions_match == "smallest":
+# self.params.img_url1.get_file().resize(
+# height=im2_height, module=self)
+# else:
+# self.params.img_url2.get_file().resize(
+# height=im1_height, module=self)
+# else:
+# if self.params.dimensions_match == "smallest":
+# self.params.img_url2.get_file().resize(
+# height=im1_height, module=self)
+# else:
+# self.params.img_url1.get_file().resize(
+# height=im2_height, module=self)
+# elif self.params.merge_direction == "down" and \
+# im1_width != im2_width:
+# """match widths"""
+# if im1_width > im2_width:
+# if self.params.dimensions_match == "smallest":
+# self.params.img_url1.get_file().resize(
+# width=im2_width, module=self)
+# else:
+# self.params.img_url2.get_file().resize(
+# width=im1_width, module=self)
+# else:
+# if self.params.dimensions_match == "smallest":
+# self.params.img_url2.get_file().resize(
+# width=im1_width, module=self)
+# else:
+# self.params.img_url1.get_file().resize(
+# width=im2_width, module=self)
def _concat_static(self, image1, image2):
tempfile = File(
@@ -185,11 +243,22 @@ class PbConcat(ModuleBase):
def create(self):
self._match_dimensions()
+ #also see here how I'm passing back a tuple and just passing the tuple into the next function for no reason?
+ #if I had a global im1 and im2 hash, I could just keep the frames in there, you know? well could be
+ #so the new create would look like this
+ #match_dimensions()
+ #make_frames_count_equal()
+ #merge_frames()
+ #finalize_image()
+
+ #does that seem more clear? yeah i think you just need an alias for self.parameters.
frames1, frames2 = self._get_frames_of_equal_count()
frames_merged = self._merge_frames_of_equal_count(frames1, frames2)
self._merge_all_frames(frames_merged)
super(PbConcat, self).create()
+ #in general this looks ok, right? yeah but code in ifs that looks same way looks a bit weird
+ #yeah I was trying to think of ways to wrap it into lambdas but it was very confusing
def _add_canvas(self, image, canvas_color="transparent"):
canvasfile = File(
is_temp=True,