The time now is Wed 19 Jun 2013, 11:31
All times are UTC - 4 |
| Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 3845
|
Posted: 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;
} |
 |
| Description |
|

Download |
| Filename |
mtdiff.tar.gz |
| Filesize |
11.83 KB |
| Downloaded |
216 Time(s) |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Last edited by technosaurus on Tue 09 Oct 2012, 06:27; edited 3 times in total
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3845
|
Posted: 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.
| Description |
saves as diff.gif (the initial post saves as a png)
|

Download |
| Filename |
mtdiff.tar.gz |
| Filesize |
11.83 KB |
| Downloaded |
215 Time(s) |
| Description |
|
| Filesize |
4.04 KB |
| Viewed |
263 Time(s) |

|
| Description |
|
| Filesize |
35.74 KB |
| Viewed |
275 Time(s) |

|
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
|
|
|
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
|