#!/usr/bin/env python

# rotate-video.py - rotates a stack of video frames, use with care.
# Copyright (C) 2004 Manish Singh and Carol Spears
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

import os

from gimpfu import *

def rotate_video(images_location, rotate_type):
    for filename in os.listdir(images_location):
        if filename.endswith('.xcf'):
            imagefile = os.path.join(images_location, filename)

            image = pdb.gimp_file_load(imagefile, imagefile)

            pdb.gimp_image_rotate(image, rotate_type)

            pdb.gimp_file_save(image, image.active_layer, imagefile, imagefile)

            gimp.delete(image)
 
register(
        "python_fu_rotate_video",
        "Rotates all the frames in a video.",
        "Rotates all the frames in a video.",
        "Manish Singh",
        "Manish Singh",
        "2004",
        "<Toolbox>/Xtns/Python-Fu/Rotate Video",
        "*",
        [
        (PF_FILE, "images_location", "Location of the images", ""),
	(PF_RADIO, "rotate_type", "Angle of rotation", ROTATE_90, (("90", ROTATE_90), ("180", ROTATE_180), ("270", ROTATE_270))),
        ],
        [],
        rotate_video)

main()
