Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 19 Dec 2014, 14:24
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Graphics
mtdiff image differencer (useful for animate gifs etc...)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [2 Posts]  
Author Message
technosaurus


Joined: 18 May 2008
Posts: 4424

PostPosted: Tue 09 Oct 2012, 04:54    Post subject:  mtdiff image differencer (useful for animate gifs etc...)  

This is a modification of Mark Tyler's micmp.c example program from the most recent mtcelledit package.

I recalled looking for something like this once and all I found was other people looking, so just in case I need it later, here is mtdiff

Basically all it does is take 2 images of the same size and outputs an image ("diff.png") that shows only the differences (all other pixels get the first color of image 1 which is typically a transparency color) ... nice for reducing the size of animations (this is how webp animations work iirc)

sorry, it only does a static file name, so you'll have to write some kind of script for renaming if you wish to batch process a large number of files.

Code:
/*   micmp.c
   Copyright (C) 2007-2008 Mark Tyler

   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 3 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 in the file COPYING.
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mtpixel.h>

static void compare_images( mtImage *ia, mtImage *ib ){
   mtImage *ic=ia;
   int      i, j, k, rgb[3][3] = { {0,0,0}, {0,0,0}, {0,0,0} };
   unsigned char   *a, *b, *c;
   a = ia->channel[MTPIXEL_CHANNEL_IMAGE];
   b = ib->channel[MTPIXEL_CHANNEL_IMAGE];
   c = ic->channel[MTPIXEL_CHANNEL_IMAGE];

   if ( ia->width == ib->width && ia->height == ib->height && ia->type == ib->type ){
      j = ia->width * ia->height;
      if ( ia->type == MTPIXEL_IMAGE_INDEXED ){
         for ( i=0; i<j; i++ ){
            if ( a[0] != b[0] ) c[0]=b[0];
            else c[0]=0;
            rgb[0][0] = abs( a[0] - b[0] );
            if ( rgb[0][0] > rgb[0][1] ) rgb[0][1] = rgb[0][0];
            rgb[0][2] += rgb[0][0];
            a ++; b ++; c ++;
         }
      }

      if ( ia->type == MTPIXEL_IMAGE_RGB ){
         for ( i=0; i<j; i++ ){
            for ( k=0; k<3; k++ ){
               rgb[k][0] = abs( a[k] - b[k] );
               if ( rgb[k][0] > rgb[k][1] ) rgb[k][1] = rgb[k][0];
               rgb[k][2] += rgb[k][0];
            }
            if ( a[0] == b[0] && a[1] == b[1] && a[2] == b[2] )
               {c[0]=0;c[1]=0;c[2]=0;}
            else
               {c[0]=b[0];c[1]=b[1];c[2]=b[2];}
            a += 3; b += 3; c += 3;
         }
      }
      ic->palette.trans=0;
      mtpixel_image_save( ic, "diff.png", MTPIXEL_FILE_TYPE_PNG, 5 );
   }
}

int main( int argc, char *argv[] ){
   mtImage   *ia, *ib;
   int   res = 0;

mtpixel_init();
if ( argc != 3 ){
   res = 2;
}else{
   ia = mtpixel_image_load( argv[1] );
   if ( !ia ){
      res = 1;
   }else{
      ib = mtpixel_image_load( argv[2] );
      if ( !ib ){
         res = 1;
      }else{
         compare_images( ia, ib );
         mtpixel_image_destroy( ib );
      }
      mtpixel_image_destroy( ia );
   }
}
mtpixel_quit();
return res;
}
mtdiff.tar.gz
Description 
gz

 Download 
Filename  mtdiff.tar.gz 
Filesize  11.83 KB 
Downloaded  462 Time(s) 

_________________
Web Programming - Pet Packaging 100 & 101

Last edited by technosaurus on Tue 09 Oct 2012, 06:27; edited 3 times in total
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4424

PostPosted: Tue 09 Oct 2012, 05:00    Post subject:  

here is an example:
two images that were compared on the left and their diff.png on the right

Edit: if you are 1 of the 2 who already downloaded this, I have transparency working now.
mtdiff.tar.gz
Description  saves as diff.gif (the initial post saves as a png)
gz

 Download 
Filename  mtdiff.tar.gz 
Filesize  11.83 KB 
Downloaded  453 Time(s) 
example2.png
 Description   
 Filesize   4.04 KB
 Viewed   505 Time(s)

example2.png

example.png
 Description   
 Filesize   35.74 KB
 Viewed   511 Time(s)

example.png


_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [2 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Graphics
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0569s ][ Queries: 13 (0.0054s) ][ GZIP on ]