Re: [UPDATE] print/unpaper

2016-11-09 Thread Jiri B
On Wed, Nov 09, 2016 at 05:14:01PM +0100, Antoine Jacoutot wrote:
> New diff.

Nice, thanks!

It's strange I get failure for all F* and G* tests.

j.

~~~
===
   unpaper 6.1: ./test-suite.log
===

# TOTAL: 19
# PASS:  13
# SKIP:  0
# XFAIL: 1
# FAIL:  5
# XPASS: 0
# ERROR: 0

.. contents:: :depth: 2

FAIL: tests/runtestF1.sh


[F1] Merging 2-page layout into single output page (with input and output 
wildcard).
+ rm -f tests/resultsF11.pbm
+ ./unpaper --end-sheet 1 -v --layout double --input-pages 2 
./tests/imgsrcE%03d.png tests/resultsF1%d.pbm
[image2 @ 0x1467617a6800] Encoder did not produce proper pts, making some up.
unpaper 6.1
License GPLv2: GNU GPL version 2.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

---
Processing sheet #1: ./tests/imgsrcE001.png, ./tests/imgsrcE002.png -> 
tests/resultsF11.pbm
input-files for sheet 1: ./tests/imgsrcE001.png, ./tests/imgsrcE002.png
output-file for sheet 1: tests/resultsF11.pbm
sheet size: 7014x2480
...
noise-filter ... deleted 345 clusters.
blur-filter... deleted 0 pixels.
auto-masking (1753,1240): 0,0,3506,2479 (invalid detection, using full page 
size)
auto-masking (5261,1240): 3508,0,7014,2479 (invalid detection, using full page 
size)
gray-filter... deleted 24840220 pixels.
auto-masking (1753,1240): 0,0,3506,2479 (invalid detection, using full page 
size)
auto-masking (5261,1240): 3508,0,7014,2479 (invalid detection, using full page 
size)
detected rotation left: [0,0,3506,2479]: 0.013963
detected rotation right: [0,0,3506,2479]: -0.045379
rotation average: -0.015708  deviation: 0.041961  rotation-scan-deviation 
(maximum): 0.017453  [0,0,3506,2479]
out of deviation range - NO ROTATING
rotate (1753,1240): 0.00
detected rotation left: [3508,0,7014,2479]: 0.013963
detected rotation right: [3508,0,7014,2479]: -0.045379
rotation average: -0.015708  deviation: 0.041961  rotation-scan-deviation 
(maximum): 0.017453  [3508,0,7014,2479]
out of deviation range - NO ROTATING
rotate (5261,1240): 0.00
auto-masking (1753,1240): 0,0,3506,2479 (invalid detection, using full page 
size)
auto-masking (5261,1240): 3508,0,7014,2479 (invalid detection, using full page 
size)
centering mask [0,0,3506,2479] (1753,1240): 0, 0
centering mask [3508,0,7014,2479] (5261,1240): 0, 0 - NO CENTERING (would shift 
area outside visible image)
border detected: (0,110,3507,71) in [0,0,3507,2479]
border detected: (3507,110,1,71) in [3507,0,7013,2479]
aligning mask [0,110,3506,2408] (0,90): 0, -20
aligning mask [3507,110,7012,2408] (3507,90): 0, -20
writing output.
+ [ -f tests/resultsF11.pbm ]
+ md5sum -c -
+ << EOF 
tests/resultsF11.pbm: FAILED
md5sum: WARNING: 1 computed checksum did NOT match

FAIL: tests/runtestF2.sh


[F2] Merging 2-page layout into single output page (with output wildcard only).
+ rm -f tests/resultsF21.pbm
+ ./unpaper -v --layout double --input-pages 2 ./tests/imgsrcE001.png 
./tests/imgsrcE002.png tests/resultsF2%d.pbm
[image2 @ 0x1166a8bba000] Encoder did not produce proper pts, making some up.
unpaper 6.1
License GPLv2: GNU GPL version 2.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

---
Processing sheet #1: ./tests/imgsrcE001.png, ./tests/imgsrcE002.png -> 
tests/resultsF21.pbm
input-files for sheet 1: ./tests/imgsrcE001.png, ./tests/imgsrcE002.png
output-file for sheet 1: tests/resultsF21.pbm
sheet size: 7014x2480
...
noise-filter ... deleted 345 clusters.
blur-filter... deleted 0 pixels.
auto-masking (1753,1240): 0,0,3506,2479 (invalid detection, using full page 
size)
auto-masking (5261,1240): 3508,0,7014,2479 (invalid detection, using full page 
size)
gray-filter... deleted 24840220 pixels.
auto-masking (1753,1240): 0,0,3506,2479 (invalid detection, using full page 
size)
auto-masking (5261,1240): 3508,0,7014,2479 (invalid detection, using full page 
size)
detected rotation left: [0,0,3506,2479]: 0.013963
detected rotation right: [0,0,3506,2479]: -0.045379
rotation average: -0.015708  deviation: 0.041961  rotation-scan-deviation 
(maximum): 0.017453  [0,0,3506,2479]
out of deviation range - NO ROTATING
rotate (1753,1240): 0.00
detected rotation left: [3508,0,7014,2479]: 0.013963
detected rotation right: [3508,0,7014,2479]: -0.045379
rotation average: -0.015708  deviation: 0.041961  rotation-scan-deviation 
(maximum): 0.017453  [3508,0,7014,2479]
out of deviation range - NO ROTATING
rotate (5261,1240): 0.00
auto-masking (1753,1240): 0,0,3506,2479 (invalid detection, using full page 
size)
auto-masking (5261,1240): 3508,0,7014,2479 (invalid detection, using full page 
size)
centering mask [0,0,3506,2479] (1753,1240): 0, 0
centering mask 

Re: [UPDATE] print/unpaper

2016-11-09 Thread Antoine Jacoutot
> Agreed. And I'm not sure the unpaper.c patch is needed. There's another
> version of the ffmpeg patch at https://github.com/Flameeyes/unpaper/pull/42
> but nothing committed upstream.

That one is definitely better.
It prevents erroring out with:
unpaper: error: unable to open file ./tests/imgsrc001.png: unsupported pixel 
format

> This fixes a bunch of them:
> 
> TEST_DEPENDS=   sysutils/coreutils
> 
> pre-test:
> ln -fs ${LOCALBASE}/bin/gmd5sum ${WRKDIR}/bin/md5sum

Thanks.

New diff.

Index: Makefile
===
RCS file: /cvs/ports/print/unpaper/Makefile,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 Makefile
--- Makefile10 May 2014 07:42:47 -  1.4
+++ Makefile9 Nov 2016 16:13:32 -
@@ -1,32 +1,34 @@
 # $OpenBSD: Makefile,v 1.4 2014/05/10 07:42:47 ajacoutot Exp $
 
-COMMENT=   post-processing tool for scanned paper sheets
+COMMENT=   post-processing tool for scanned paper sheets
 
-DISTNAME=  unpaper-0.3
+DISTNAME=  unpaper-6.1
 
-CATEGORIES=print graphics
+CATEGORIES=print graphics
 
-HOMEPAGE=  http://unpaper.berlios.de/
+HOMEPAGE=  https://www.flameeyes.eu/projects/unpaper
 
-MAINTAINER=Antoine Jacoutot 
+MAINTAINER=Antoine Jacoutot 
 
 # GPLv2
 PERMIT_PACKAGE_CDROM=  Yes
 
-WANTLIB += c m
+WANTLIB += avcodec avformat avutil c m
 
-MASTER_SITES=  ${MASTER_SITE_SOURCEFORGE:=unpaper/}
+MASTER_SITES=  https://www.flameeyes.eu/files/
+EXTRACT_SUFX=  .tar.xz
 
-NO_TEST=   Yes
+BUILD_DEPENDS= textproc/libxslt # xsltproc
+LIB_DEPENDS=   graphics/ffmpeg
+TEST_DEPENDS=  sysutils/coreutils
 
-do-build:
-   cd ${WRKSRC} && \
-   ${CC} ${CFLAGS} -lm -o unpaper src/unpaper.c
+CONFIGURE_STYLE=   gnu
 
-do-install:
-   ${INSTALL_PROGRAM} ${WRKBUILD}/unpaper ${PREFIX}/bin
-   ${INSTALL_DATA_DIR} ${PREFIX}/share/doc/unpaper
-   ${INSTALL_DATA} ${WRKSRC}/README \
-   ${PREFIX}/share/doc/unpaper
+post-install:
+# useless
+   rm -rf ${PREFIX}/share/doc/unpaper
+
+pre-test:
+   ln -fs ${LOCALBASE}/bin/gmd5sum ${WRKDIR}/bin/md5sum
 
 .include 
Index: distinfo
===
RCS file: /cvs/ports/print/unpaper/distinfo,v
retrieving revision 1.2
diff -u -p -u -p -r1.2 distinfo
--- distinfo18 Jan 2015 03:14:58 -  1.2
+++ distinfo9 Nov 2016 16:13:32 -
@@ -1,2 +1,2 @@
-SHA256 (unpaper-0.3.tar.gz) = NDNmQECUK/djiUbiMn5cZBGcYA/eis6Rj0cQn6+95b4=
-SIZE (unpaper-0.3.tar.gz) = 546488
+SHA256 (unpaper-6.1.tar.xz) = I3yE9dpUSz93CYJ/nxLDfDRs3wKbESj7RjP5uvpcuTA=
+SIZE (unpaper-6.1.tar.xz) = 2655724
Index: patches/patch-file_c
===
RCS file: patches/patch-file_c
diff -N patches/patch-file_c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ patches/patch-file_c9 Nov 2016 16:13:32 -
@@ -0,0 +1,28 @@
+$OpenBSD$
+
+https://github.com/Flameeyes/unpaper/pull/42
+
+--- file.c.origSun Oct 26 23:35:38 2014
 file.c Wed Nov  9 16:53:16 2016
+@@ -93,10 +93,21 @@ void loadImage(const char *filename, AVFrame **image) 
+ if (pkt.stream_index != 0)
+ errOutput("unable to open file %s: invalid stream.", filename);
+ 
++while (!got_frame && pkt.data) {
++
++if (pkt.size <= 0) {
++pkt.data = NULL;
++pkt.size = 0;
++}
++
+ ret = avcodec_decode_video2(avctx, frame, _frame, );
+ if (ret < 0) {
+ av_strerror(ret, errbuff, sizeof(errbuff));
+ errOutput("unable to open file %s: %s", filename, errbuff);
++}
++
++pkt.data += ret;
++pkt.size -= ret;
+ }
+ 
+ switch(frame->format) {
Index: patches/patch-tests_runtestG3_sh
===
RCS file: patches/patch-tests_runtestG3_sh
diff -N patches/patch-tests_runtestG3_sh
--- /dev/null   1 Jan 1970 00:00:00 -
+++ patches/patch-tests_runtestG3_sh9 Nov 2016 16:13:32 -
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- tests/runtestG3.sh.origWed Nov  9 17:01:15 2016
 tests/runtestG3.sh Wed Nov  9 17:01:38 2016
+@@ -8,7 +8,7 @@ set -x
+ rm -f tests/resultsG3.pbm
+ touch tests/resultsG3.pbm
+ 
+-./unpaper -v --no-processing 1 ${srcdir:-.}/tests/imgsrc001.png 
tests/resultsG3.pbm
++./unpaper --overwrite -v --no-processing 1 ${srcdir:-.}/tests/imgsrc001.png 
tests/resultsG3.pbm
+ 
+ [ -s tests/resultsG3.pbm ]
+ 
Index: pkg/PLIST
===
RCS file: /cvs/ports/print/unpaper/pkg/PLIST,v
retrieving revision 1.1.1.1
diff -u -p -u -p -r1.1.1.1 PLIST
--- pkg/PLIST   17 Jul 2010 07:59:37 -  1.1.1.1
+++ pkg/PLIST   9 Nov 2016 16:13:32 -
@@ -1,4 +1,3 @@
 @comment $OpenBSD: PLIST,v 1.1.1.1 2010/07/17 07:59:37 ajacoutot Exp $
 @bin bin/unpaper

Re: [UPDATE] print/unpaper

2016-11-09 Thread Stuart Henderson
On 2016/11/09 16:12, Antoine Jacoutot wrote:
> On Tue, Nov 08, 2016 at 06:56:45PM -0500, Jiri B wrote:
> > Hi,
> > 
> > an update of unpaper, it needs now libav which is part of ffmpeg.
> > 
> > I tooks diffs from pkgsrc who use ffmpeg and not libav directly.
> > I can't comment those diff but it works for me on amd64.
> 
> I don't like adding random patches without an explanation about what they do.

Agreed. And I'm not sure the unpaper.c patch is needed. There's another
version of the ffmpeg patch at https://github.com/Flameeyes/unpaper/pull/42
but nothing committed upstream.

> > I removed README as it was useless anyway and new doc files are
> > markdown-based so I did not include them.
> > 
> > I'v tried my best ;)
> 
> You are probably missing a bdep on textproc/libxslt for xsltproc.
> HOMEPAGE should be set to https://www.flameeyes.eu/projects/unpaper
> NO_TEST sould be removed and oh by the way, all tests fail so you need to 
> have a look at that.
> 
> It's a good start though ;-)

This fixes a bunch of them:

TEST_DEPENDS=   sysutils/coreutils

pre-test:
ln -fs ${LOCALBASE}/bin/gmd5sum ${WRKDIR}/bin/md5sum



Re: [UPDATE] print/unpaper

2016-11-09 Thread Antoine Jacoutot
On Tue, Nov 08, 2016 at 06:56:45PM -0500, Jiri B wrote:
> Hi,
> 
> an update of unpaper, it needs now libav which is part of ffmpeg.
> 
> I tooks diffs from pkgsrc who use ffmpeg and not libav directly.
> I can't comment those diff but it works for me on amd64.

I don't like adding random patches without an explanation about what they do.

> I removed README as it was useless anyway and new doc files are
> markdown-based so I did not include them.
> 
> I'v tried my best ;)

You are probably missing a bdep on textproc/libxslt for xsltproc.
HOMEPAGE should be set to https://www.flameeyes.eu/projects/unpaper
NO_TEST sould be removed and oh by the way, all tests fail so you need to have 
a look at that.

It's a good start though ;-)

> Index: Makefile
> ===
> RCS file: /cvs/ports/print/unpaper/Makefile,v
> retrieving revision 1.4
> diff -u -p -r1.4 Makefile
> --- Makefile  10 May 2014 07:42:47 -  1.4
> +++ Makefile  8 Nov 2016 23:52:18 -
> @@ -2,31 +2,29 @@
>  
>  COMMENT= post-processing tool for scanned paper sheets
>  
> -DISTNAME=unpaper-0.3
> +DISTNAME=unpaper-6.1
>  
>  CATEGORIES=  print graphics
>  
> -HOMEPAGE=http://unpaper.berlios.de/
> +HOMEPAGE=https://github.com/Flameeyes/unpaper
>  
>  MAINTAINER=  Antoine Jacoutot 
>  
>  # GPLv2
>  PERMIT_PACKAGE_CDROM=Yes
>  
> -WANTLIB += c m
> +WANTLIB += avcodec avformat avutil c m
>  
> -MASTER_SITES=${MASTER_SITE_SOURCEFORGE:=unpaper/}
> +MASTER_SITES=https://www.flameeyes.eu/files/
>  
>  NO_TEST= Yes
> +EXTRACT_SUFX=.tar.xz
>  
> -do-build:
> - cd ${WRKSRC} && \
> - ${CC} ${CFLAGS} -lm -o unpaper src/unpaper.c
> +CONFIGURE_STYLE= gnu
> +LIB_DEPENDS= graphics/ffmpeg
>  
>  do-install:
>   ${INSTALL_PROGRAM} ${WRKBUILD}/unpaper ${PREFIX}/bin
> - ${INSTALL_DATA_DIR} ${PREFIX}/share/doc/unpaper
> - ${INSTALL_DATA} ${WRKSRC}/README \
> - ${PREFIX}/share/doc/unpaper
> + ${INSTALL_MAN} ${WRKBUILD}/unpaper.1 ${PREFIX}/man/man1/unpaper.1
>  
>  .include 
> Index: distinfo
> ===
> RCS file: /cvs/ports/print/unpaper/distinfo,v
> retrieving revision 1.2
> diff -u -p -r1.2 distinfo
> --- distinfo  18 Jan 2015 03:14:58 -  1.2
> +++ distinfo  8 Nov 2016 23:52:18 -
> @@ -1,2 +1,2 @@
> -SHA256 (unpaper-0.3.tar.gz) = NDNmQECUK/djiUbiMn5cZBGcYA/eis6Rj0cQn6+95b4=
> -SIZE (unpaper-0.3.tar.gz) = 546488
> +SHA256 (unpaper-6.1.tar.xz) = I3yE9dpUSz93CYJ/nxLDfDRs3wKbESj7RjP5uvpcuTA=
> +SIZE (unpaper-6.1.tar.xz) = 2655724
> Index: patches/patch-file_c
> ===
> RCS file: patches/patch-file_c
> diff -N patches/patch-file_c
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ patches/patch-file_c  8 Nov 2016 23:52:18 -
> @@ -0,0 +1,92 @@
> +$OpenBSD$
> +
> +From pkgsrc-wip
> +
> +--- file.c.orig  Sun Oct 26 23:35:38 2014
>  file.c   Tue Nov  8 20:13:38 2016
> +@@ -105,7 +105,7 @@ void loadImage(const char *filename, AVFrame **image) 
> + case AV_PIX_FMT_RGB24:
> + case AV_PIX_FMT_MONOBLACK:
> + case AV_PIX_FMT_MONOWHITE:
> +-*image = frame;
> ++*image = av_frame_clone(frame);
> + break;
> + 
> + case AV_PIX_FMT_PAL8:
> +@@ -123,6 +123,10 @@ void loadImage(const char *filename, AVFrame **image) 
> + default:
> + errOutput("unable to open file %s: unsupported pixel format", 
> filename);
> + }
> ++
> ++avcodec_close(avctx);
> ++av_free(avctx);
> ++avformat_close_input();
> + }
> + 
> + 
> +@@ -134,13 +138,14 @@ void loadImage(const char *filename, AVFrame **image) 
> +  * @param type filetype of the image to save
> +  * @return true on success, false on failure
> +  */
> +-void saveImage(char *filename, AVFrame *image, int outputPixFmt) {
> ++void saveImage(char *filename, AVFrame *input, int outputPixFmt) {
> + AVOutputFormat *fmt = NULL;
> + enum AVCodecID output_codec = -1;
> + AVCodec *codec;
> + AVFormatContext *out_ctx;
> + AVCodecContext *codec_ctx;
> + AVStream *video_st;
> ++AVFrame *output = input;
> + int ret;
> + char errbuff[1024];
> + 
> +@@ -174,13 +179,11 @@ void saveImage(char *filename, AVFrame *image, int out
> + break;
> + }
> + 
> +-if ( image->format != outputPixFmt ) {
> +-AVFrame *output;
> +-initImage(, image->width, image->height,
> ++if ( input->format != outputPixFmt ) {
> ++initImage(, input->width, input->height,
> +   outputPixFmt, -1);
> +-copyImageArea(0, 0, image->width, image->height,
> +-  image, 0, 0, output);
> +-image = output;
> ++copyImageArea(0, 0, input->width, input->height,
> ++  input, 0, 0, output);
> + }
> + 
> + codec = 

[UPDATE] print/unpaper

2016-11-08 Thread Jiri B
Hi,

an update of unpaper, it needs now libav which is part of ffmpeg.

I tooks diffs from pkgsrc who use ffmpeg and not libav directly.
I can't comment those diff but it works for me on amd64.

I removed README as it was useless anyway and new doc files are
markdown-based so I did not include them.

I'v tried my best ;)

j.

Index: Makefile
===
RCS file: /cvs/ports/print/unpaper/Makefile,v
retrieving revision 1.4
diff -u -p -r1.4 Makefile
--- Makefile10 May 2014 07:42:47 -  1.4
+++ Makefile8 Nov 2016 23:52:18 -
@@ -2,31 +2,29 @@
 
 COMMENT=   post-processing tool for scanned paper sheets
 
-DISTNAME=  unpaper-0.3
+DISTNAME=  unpaper-6.1
 
 CATEGORIES=print graphics
 
-HOMEPAGE=  http://unpaper.berlios.de/
+HOMEPAGE=  https://github.com/Flameeyes/unpaper
 
 MAINTAINER=Antoine Jacoutot 
 
 # GPLv2
 PERMIT_PACKAGE_CDROM=  Yes
 
-WANTLIB += c m
+WANTLIB += avcodec avformat avutil c m
 
-MASTER_SITES=  ${MASTER_SITE_SOURCEFORGE:=unpaper/}
+MASTER_SITES=  https://www.flameeyes.eu/files/
 
 NO_TEST=   Yes
+EXTRACT_SUFX=  .tar.xz
 
-do-build:
-   cd ${WRKSRC} && \
-   ${CC} ${CFLAGS} -lm -o unpaper src/unpaper.c
+CONFIGURE_STYLE=   gnu
+LIB_DEPENDS=   graphics/ffmpeg
 
 do-install:
${INSTALL_PROGRAM} ${WRKBUILD}/unpaper ${PREFIX}/bin
-   ${INSTALL_DATA_DIR} ${PREFIX}/share/doc/unpaper
-   ${INSTALL_DATA} ${WRKSRC}/README \
-   ${PREFIX}/share/doc/unpaper
+   ${INSTALL_MAN} ${WRKBUILD}/unpaper.1 ${PREFIX}/man/man1/unpaper.1
 
 .include 
Index: distinfo
===
RCS file: /cvs/ports/print/unpaper/distinfo,v
retrieving revision 1.2
diff -u -p -r1.2 distinfo
--- distinfo18 Jan 2015 03:14:58 -  1.2
+++ distinfo8 Nov 2016 23:52:18 -
@@ -1,2 +1,2 @@
-SHA256 (unpaper-0.3.tar.gz) = NDNmQECUK/djiUbiMn5cZBGcYA/eis6Rj0cQn6+95b4=
-SIZE (unpaper-0.3.tar.gz) = 546488
+SHA256 (unpaper-6.1.tar.xz) = I3yE9dpUSz93CYJ/nxLDfDRs3wKbESj7RjP5uvpcuTA=
+SIZE (unpaper-6.1.tar.xz) = 2655724
Index: patches/patch-file_c
===
RCS file: patches/patch-file_c
diff -N patches/patch-file_c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ patches/patch-file_c8 Nov 2016 23:52:18 -
@@ -0,0 +1,92 @@
+$OpenBSD$
+
+From pkgsrc-wip
+
+--- file.c.origSun Oct 26 23:35:38 2014
 file.c Tue Nov  8 20:13:38 2016
+@@ -105,7 +105,7 @@ void loadImage(const char *filename, AVFrame **image) 
+ case AV_PIX_FMT_RGB24:
+ case AV_PIX_FMT_MONOBLACK:
+ case AV_PIX_FMT_MONOWHITE:
+-*image = frame;
++*image = av_frame_clone(frame);
+ break;
+ 
+ case AV_PIX_FMT_PAL8:
+@@ -123,6 +123,10 @@ void loadImage(const char *filename, AVFrame **image) 
+ default:
+ errOutput("unable to open file %s: unsupported pixel format", 
filename);
+ }
++
++avcodec_close(avctx);
++av_free(avctx);
++avformat_close_input();
+ }
+ 
+ 
+@@ -134,13 +138,14 @@ void loadImage(const char *filename, AVFrame **image) 
+  * @param type filetype of the image to save
+  * @return true on success, false on failure
+  */
+-void saveImage(char *filename, AVFrame *image, int outputPixFmt) {
++void saveImage(char *filename, AVFrame *input, int outputPixFmt) {
+ AVOutputFormat *fmt = NULL;
+ enum AVCodecID output_codec = -1;
+ AVCodec *codec;
+ AVFormatContext *out_ctx;
+ AVCodecContext *codec_ctx;
+ AVStream *video_st;
++AVFrame *output = input;
+ int ret;
+ char errbuff[1024];
+ 
+@@ -174,13 +179,11 @@ void saveImage(char *filename, AVFrame *image, int out
+ break;
+ }
+ 
+-if ( image->format != outputPixFmt ) {
+-AVFrame *output;
+-initImage(, image->width, image->height,
++if ( input->format != outputPixFmt ) {
++initImage(, input->width, input->height,
+   outputPixFmt, -1);
+-copyImageArea(0, 0, image->width, image->height,
+-  image, 0, 0, output);
+-image = output;
++copyImageArea(0, 0, input->width, input->height,
++  input, 0, 0, output);
+ }
+ 
+ codec = avcodec_find_encoder(output_codec);
+@@ -194,9 +197,9 @@ void saveImage(char *filename, AVFrame *image, int out
+ }
+ 
+ codec_ctx = video_st->codec;
+-codec_ctx->width = image->width;
+-codec_ctx->height = image->height;
+-codec_ctx->pix_fmt = image->format;
++codec_ctx->width = output->width;
++codec_ctx->height = output->height;
++codec_ctx->pix_fmt = output->format;
+ video_st->time_base.den = codec_ctx->time_base.den = 1;
+ video_st->time_base.num = codec_ctx->time_base.num = 1;
+ 
+@@ -221,7 +224,7 @@ void saveImage(char *filename, AVFrame *image, int out
+ av_init_packet();
+ 
+ /* encode the image */
+-