[longomatch] Create utils class for images
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Create utils class for images
- Date: Wed, 21 Sep 2011 21:06:24 +0000 (UTC)
commit 280b2e0242ec76e08d7d1070a587598aedec6422
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Fri Sep 16 16:07:29 2011 +0200
Create utils class for images
LongoMatch/Common/Images.cs | 54 ++++++++++++++++++++++++++++++++++++
LongoMatch/LongoMatch.mdp | 1 +
LongoMatch/Makefile.am | 1 +
LongoMatch/Store/PixbufTimeNode.cs | 25 ++--------------
Makefile.win32 | 1 +
5 files changed, 61 insertions(+), 21 deletions(-)
---
diff --git a/LongoMatch/Common/Images.cs b/LongoMatch/Common/Images.cs
new file mode 100644
index 0000000..8b71a6e
--- /dev/null
+++ b/LongoMatch/Common/Images.cs
@@ -0,0 +1,54 @@
+//
+// Copyright (C) 2011 Andoni Morales Alastruey
+//
+// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using Gdk;
+
+namespace LongoMatch.Common
+{
+ public class ImageUtils
+ {
+ public static Pixbuf Scale(Pixbuf pixbuf, int max_width, int max_height) {
+ int ow,oh,h,w;
+
+ h = ow = pixbuf.Height;
+ w = oh = pixbuf.Width;
+ ow = max_width;
+ oh = max_height;
+
+ if(w>max_width || h>max_height) {
+ Pixbuf scalledPixbuf;
+ double rate = (double)w/(double)h;
+
+ if(h>w)
+ ow = (int)(oh * rate);
+ else
+ oh = (int)(ow / rate);
+ scalledPixbuf = pixbuf.ScaleSimple(ow,oh,Gdk.InterpType.Bilinear);
+ pixbuf.Dispose();
+ return scalledPixbuf;
+ } else {
+ return pixbuf;
+ }
+ }
+
+ public static byte[] Serialize(Pixbuf pixbuf) {
+ return pixbuf.SaveToBuffer("png");
+ }
+ }
+}
+
diff --git a/LongoMatch/LongoMatch.mdp b/LongoMatch/LongoMatch.mdp
index 72d5161..edf1b74 100644
--- a/LongoMatch/LongoMatch.mdp
+++ b/LongoMatch/LongoMatch.mdp
@@ -189,6 +189,7 @@
<File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.Component.TeamTaggerWidget.cs" />
<File subtype="Code" buildaction="Compile" name="Gui/Component/TeamTaggerWidget.cs" />
<File subtype="Code" buildaction="Compile" name="Interfaces/ITag.cs" />
+ <File subtype="Code" buildaction="Compile" name="Common/Images.cs" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
diff --git a/LongoMatch/Makefile.am b/LongoMatch/Makefile.am
index ac6832f..a4040cf 100644
--- a/LongoMatch/Makefile.am
+++ b/LongoMatch/Makefile.am
@@ -10,6 +10,7 @@ SOURCES = \
Common/Constants.cs \
Common/Enums.cs \
Common/GStreamer.cs \
+ Common/Images.cs \
Common/Log.cs \
Common/ProjectUtils.cs \
Common/SerializableObject.cs \
diff --git a/LongoMatch/Store/PixbufTimeNode.cs b/LongoMatch/Store/PixbufTimeNode.cs
index 91032e6..a56bed2 100644
--- a/LongoMatch/Store/PixbufTimeNode.cs
+++ b/LongoMatch/Store/PixbufTimeNode.cs
@@ -21,6 +21,8 @@
using System;
using Gdk;
+using LongoMatch.Common;
+
namespace LongoMatch.Store
{
@@ -49,29 +51,10 @@ namespace LongoMatch.Store
return new Pixbuf(thumbnailBuf);
else return null;
} set {
- ScaleAndSave(value);
+ var pix = ImageUtils.Scale(value, MAX_WIDTH, MAX_HEIGHT);
+ thumbnailBuf = ImageUtils.Serialize(pix);
}
}
#endregion
-
- private void ScaleAndSave(Pixbuf pixbuf) {
- int ow,oh,h,w;
-
- h = ow = pixbuf.Height;
- w = oh = pixbuf.Width;
- ow = MAX_WIDTH;
- oh = MAX_HEIGHT;
-
- if(w>MAX_WIDTH || h>MAX_HEIGHT) {
- double rate = (double)w/(double)h;
- if(h>w)
- ow = (int)(oh * rate);
- else
- oh = (int)(ow / rate);
- thumbnailBuf = pixbuf.ScaleSimple(ow,oh,Gdk.InterpType.Bilinear).SaveToBuffer("png");
- pixbuf.Dispose();
- }
- else thumbnailBuf = pixbuf.SaveToBuffer("png");
- }
}
}
diff --git a/Makefile.win32 b/Makefile.win32
index c7c9132..befff9e 100644
--- a/Makefile.win32
+++ b/Makefile.win32
@@ -118,6 +118,7 @@ LONGOMATCH_FILES = \
Common/Constants.cs \
Common/Cairo.cs\
Common/GStreamer.cs\
+ Common/Images.cs\
Compat/0.0/DatabaseMigrator.cs \
Compat/0.0/DB/DataBase.cs \
Compat/0.0/DB/MediaFile.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]