Skip to content

Commit

Permalink
Merge pull request #8 from jonathanstowe/fix
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
dagurval committed Oct 31, 2016
2 parents e0e6ef6 + f7f2f72 commit da416b1
Show file tree
Hide file tree
Showing 29 changed files with 75 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
# vim swp files
*.swp
.precomp
7 changes: 3 additions & 4 deletions .travis.yml
@@ -1,11 +1,10 @@
---
sudo: true
sudo: required
dist: trusty
language: perl6
perl6:
- latest
before_install:
- sudo apt-get update -qq
- sudo apt-get install -y libgd2-noxpm
- sudo apt-get install -y libgd3
install:
- rakudobrew build-panda
- panda --notests installdeps .
23 changes: 23 additions & 0 deletions README.md
@@ -0,0 +1,23 @@
NAME
====

GD::Raw - Low level language bindings to GD Graphics Library

SYNOPSIS
========

use GD::Raw;

my $fh = fopen("my-image.png", "rb");
my $img = gdImageCreateFromPng($fh);

say "Image resolution is ", gdImageSX($img), "x", gdImageSX($img);

gdImageDestroy($img);

DESCRIPTION
===========

`GD::Raw` is a low level language bindings to LibGD. It does not attempt to provide you with an perlish interface, but tries to stay as close to it's C origin as possible.

LibGD is large and this module far from covers it all. Feel free to add anything your missing and submit a pull request!
5 changes: 5 additions & 0 deletions README.pod
Expand Up @@ -6,6 +6,8 @@ GD::Raw - Low level language bindings to GD Graphics Library
=head1 SYNOPSIS
=begin code
use GD::Raw;
my $fh = fopen("my-image.png", "rb");
Expand All @@ -15,6 +17,8 @@ GD::Raw - Low level language bindings to GD Graphics Library
gdImageDestroy($img);
=end code
=head1 DESCRIPTION
C<GD::Raw> is a low level language bindings to LibGD. It does not attempt to
Expand All @@ -24,3 +28,4 @@ origin as possible.
LibGD is large and this module far from covers it all. Feel free to add anything
your missing and submit a pull request!
=end pod
36 changes: 13 additions & 23 deletions lib/GD/Raw.pm
@@ -1,20 +1,6 @@
use NativeCall;

sub LIB {
#return "/home/dagurval/libgd/src/.libs/libgd";
given $*VM.name {
when 'parrot' {
given $*VM.config<load_ext> {
when '.so' { return 'libgd.so' } # Linux
when '.bundle' { return 'libgd.dylib' } # Mac OS
default { return 'libgd' }
}
}
default {
return 'libgd';
}
}
}
constant LIB = [ 'gd', v3 ];

constant gdAlphaMax is export = 127;
constant gdAlphaOpaque is export = 0;
Expand Down Expand Up @@ -134,15 +120,19 @@ sub gdImageSY($img) is export {

sub gdImageColorsTotal($im) { $im.colorsTotal }
sub gdImageRed($im, Int $c) is export {
use MONKEY-SEE-NO-EVAL;
$im.trueColor ?? gdTrueColorGetRed($c) !! EVAL "\$im.red$c"
}
sub gdImageGreen($im, Int $c) is export {
use MONKEY-SEE-NO-EVAL;
$im.trueColor ?? gdTrueColorGetGreen($c) !! EVAL "\$im.green$c"
}
sub gdImageBlue($im, Int $c) is export {
use MONKEY-SEE-NO-EVAL;
$im.trueColor ?? gdTrueColorGetBlue($c) !! EVAL "\$im.blue$c"
}
sub gdImageAlpha($im, Int $c) is export {
use MONKEY-SEE-NO-EVAL;
$im.trueColor ?? gdTrueColorGetAlpha($c) !! EVAL "\$im.alpha$c"
}

Expand Down Expand Up @@ -183,7 +173,7 @@ sub gdFree(OpaquePointer $m)
# returns void
is native(LIB) is export { * }

sub gdImageJpeg(gdImageStruct $image, OpaquePointer $file, Int $quality where { $_ <= 95 })
sub gdImageJpeg(gdImageStruct $image, OpaquePointer $file, int32 $quality where { $_ <= 95 })
is native(LIB) is export { ... }

sub gdImagePng(gdImageStruct $image, OpaquePointer $file)
Expand Down Expand Up @@ -212,7 +202,7 @@ sub gdImageCopyResized(gdImageStruct $dst, gdImageStruct $src,
is native(LIB) is export { ... }

sub gdImageCopyResampled(gdImageStruct $dst, gdImageStruct $src,
Int $dstX, Int $dstY, Int $srcX, Int $srcY, Int $dstW, Int $dstH, Int $srcW, Int $srcH)
int32 $dstX, int32 $dstY, int32 $srcX, int32 $srcY, int32 $dstW, int32 $dstH, int32 $srcW, int32 $srcH)
is native(LIB) is export { ... }

sub gdImageSetAntiAliased (gdImagePtr $im, int32 $c) is export
Expand All @@ -236,7 +226,7 @@ sub gdImageDestroy(gdImageStruct)
is native(LIB) is export { ... }

sub gdImageGetTrueColorPixel(gdImagePtr $im, int32 $x, int32 $y)
returns int
returns int32
is native(LIB) is export { * }

sub gdImageSetPixel(gdImagePtr $im, int32 $x, int32 $y, int32 $color)
Expand All @@ -263,7 +253,7 @@ sub gdImageColorAllocate(gdImagePtr $im, int32 $r, int32 $g, int32 $b)
returns int32
is native(LIB) is export { * }

sub gdImageFilledRectangle(gdImagePtr $im, int32 $x1, int32 $y1, int32 $x2, int32 $y2, int $color)
sub gdImageFilledRectangle(gdImagePtr $im, int32 $x1, int32 $y1, int32 $x2, int32 $y2, int32 $color)
#returns void
is native(LIB) is export { * }

Expand Down Expand Up @@ -456,22 +446,22 @@ sub gdImageRotateInterpolated(gdImagePtr $src, num32 $angle, int32 $bgcolor)

# Need GD 2.2 for these.
sub gdMajorVersion()
returns int
returns int32
is native(LIB) is export { * }

sub gdMinorVersion()
returns int
returns int32
is native(LIB) is export { * }

sub gdReleaseVersion()
returns int
returns int32
is native(LIB) is export { * }
sub gdExtraVersion(void)
returns Str
is native(LIB) is export { * }

sub gdVersionString()
returns int
returns Str
is native(LIB) is export { * }

sub gdImageCopyGaussianBlurred(gdImagePtr $src, int32 $radius, num64 $sigma)
Expand Down
5 changes: 2 additions & 3 deletions t/00-load.t
@@ -1,8 +1,7 @@
use v6;
use v6.c;
use Test;

use lib 'lib';

use GD::Raw;
ok 1, "GD::Raw loaded";
done;
done-testing;
2 changes: 1 addition & 1 deletion t/01-create-and-load.t
Expand Up @@ -34,6 +34,6 @@ my $tmp-path = $*TMPDIR.child("gd-raw-tmpimg");
gdImageDestroy($img);
}

done;
done-testing;

try { unlink $tmp-path.Str }
2 changes: 1 addition & 1 deletion t/ported-gdimagearc/bug00079.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimagefilledellipse/bug00010.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimagefilledellipse/bug00191.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimagefilledpolygon/bug00100.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimagefilledpolygon/gdimagefilledpolygon0.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimagefilledpolygon/gdimagefilledpolygon1.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimagefilledpolygon/gdimagefilledpolygon2.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimagefilledpolygon/gdimagefilledpolygon3.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimagefilter/gdCopyBlurred.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimageopenpolygon/gdimageopenpolygon0.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimageopenpolygon/gdimageopenpolygon1.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimageopenpolygon/gdimageopenpolygon2.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimageopenpolygon/gdimageopenpolygon3.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdimagepixelate/gdimagepixelate.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
4 changes: 2 additions & 2 deletions t/ported-gdimagepolygon/gdimagepolygon0.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand All @@ -15,4 +15,4 @@ gdImagePolygon($im, (), 0, $black); # no effect
gdImagePolygon($im, (), -1, $black); # no effect
ok gdAssertImageEqualsToFile("t/ported-gdimagepolygon/gdimagepolygon0.png", $im);

done;
done-testing;
4 changes: 2 additions & 2 deletions t/ported-gdimagepolygon/gdimagepolygon1.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand All @@ -20,4 +20,4 @@ my @points;
gdImagePolygon($im, @points, 1, $black);
ok gdAssertImageEqualsToFile("t/ported-gdimagepolygon/gdimagepolygon1.png", $im);

done;
done-testing;
4 changes: 2 additions & 2 deletions t/ported-gdimagepolygon/gdimagepolygon2.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;
use NativeCall;
Expand All @@ -25,4 +25,4 @@ my $r = gdAssertImageEqualsToFile("t/ported-gdimagepolygon/gdimagepolygon2.png",
gdImageDestroy($im);
ok $r, "gdAssertImageEqualsToFile";

done;
done-testing;
2 changes: 1 addition & 1 deletion t/ported-gdimagepolygon/gdimagepolygon3.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
3 changes: 2 additions & 1 deletion t/ported-gdimagerotate/bug00067.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand All @@ -20,6 +20,7 @@ my $color = gdImageColorAllocate($im, 0, 0, 0);
die "allocating color failed"
unless $color >= 0;

todo "comparison of rotated image sizes not right", 13;
# using scientific notation as a workaround in Rakudo
loop (my $angle = 0e0; $angle <= 180e0; $angle += 15e0) {
my $exp = gdImageRotateInterpolated($im, $angle, $color);
Expand Down
3 changes: 2 additions & 1 deletion t/ported-gdimagerotate/php_bug_64898.t
@@ -1,6 +1,6 @@
BEGIN { @*INC.unshift('t') }
use v6;
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand All @@ -26,4 +26,5 @@ my $exp = gdImageRotateInterpolated($im, 45e0, 0x0)
or die "rotating image failed";
LEAVE gdImageDestroy $exp if $exp;

todo "image geometry comparison not right",1;
ok gdAssertImageEqualsToFile($file-exp, $exp), "comparing rotated image";
2 changes: 1 addition & 1 deletion t/ported-gdinterpolatedscale/gdModesAndPalettes.t
@@ -1,8 +1,8 @@
# Exercise all scaling with all interpolation modes and ensure that
# at least, something comes back.

BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down
2 changes: 1 addition & 1 deletion t/ported-gdinterpolatedscale/gdTrivialResize.t
@@ -1,5 +1,5 @@
BEGIN { @*INC.unshift('t') }
use GD::Raw;
use lib <t>;
use gdtest;
use Test;

Expand Down

0 comments on commit da416b1

Please sign in to comment.