|
Releasing my version under the CPOL would be an option (although clause 5b says "You agree not to advertise or in any way imply that this Work is a product of Your own" so am I already breaking that clause by calling it "my version"? ).
But there are still issues around compatibility with the GPL - what happens when someone wants to write an application which uses this library and release the application under the GPL? Can they GPL everything except this library and retain the CPOL on this library?
(I already have just such an application, which really is all my own work, a Windows Forms app which reads in a GIF file and displays all the information about it which the GifDecoder class exposes. I hope to publish this at the same time as it also serves as example code for how to use the library)
My preference for the GPL over the CPOL (not that I was intending to start a debate about their relative merits) is that the GPL goes to great lengths to ensure that nobody can "close" GPL code (i.e. patent it or otherwise prevent other people taking advantage of its open source nature). The CPOL seems a bit lightweight by comparison. I'm not a lawyer, but I'm not convinced it offers the same level of protection.
Also, CPOL 5e says "You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder". How would this work with an application made of mostly GPL code and one library which is CPOL? Does GPL'ing the rest of the application count as restricting the terms of the CPOL on the library to which it applies?
Any advice welcome... I'm keen to get this library released, but I want to do it right
modified on Wednesday, October 7, 2009 3:51 PM
|
|
|
|
|
how do i resize an animated gif background transparency
modified on Thursday, August 27, 2009 4:06 AM
|
|
|
|
|
Thank you for the open source code. Works like a champ!!!
I have run into an issue with a few of the animated gifs having a transparent background when they should NOT have a transparent background.
Can I re-enforce no transparent background during the resizing process?
My implementation of your open source code...
string _tempID = Path.GetFileNameWithoutExtension(_file);
string _path = String.Format(@"~/assets/images/temp/{0}/{1}", this.Session.SessionID, _tempID.ToString());
_path = Server.MapPath(_path);
if (!System.IO.Directory.Exists(_path))
System.IO.Directory.CreateDirectory(_path);
GifDecoder _gifDecoder = new GifDecoder();
_gifDecoder.Read(_file);
for (int i = 0, count = _gifDecoder.GetFrameCount(); i < count; i++)
{
System.Drawing.Image frame = _gifDecoder.GetFrame(i);
frame.Save(String.Format(@"{0}\{1}.png", _path, Guid.NewGuid().ToString()), ImageFormat.Png);
}
AnimatedGifEncoder _encoder = new AnimatedGifEncoder();
_encoder.SetTransparent(Color.Empty);
using (FileStream imageStream =
new FileStream( _path + @"\temp.gif" ,FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
_encoder.Start(imageStream);
_encoder.SetDelay(_gifDecoder.GetDelay(0));
_encoder.SetRepeat(0);
string[] _imagePaths = System.IO.Directory.GetFiles(_path, "*.png");
for (int i = 0, count = _imagePaths.Length; i < count; i++)
_encoder.AddFrame(this.resize(_imagePaths[i], newWidth, newHeight, _increaseImageSize));
byte[] imageContent = new Byte[imageStream.Length];
imageStream.Position = 0;
imageStream.Read(imageContent, 0, (int)imageStream.Length);
this.Response.ContentType = _contentType;
this.Response.AddHeader("content-length", System.Convert.ToString(imageStream.Length));
this.Response.BinaryWrite(imageContent);
}
try
{
foreach (string _f in System.IO.Directory.GetFiles(_path))
System.IO.File.Delete(_f);
System.IO.Directory.Delete(_path);
System.IO.Directory.Delete(System.IO.Directory.GetParent(_path).ToString());
}
catch (Exception _ex) { Console.Write(_ex.ToString());}
_encoder.Finish();
_encoder = null;
_gifDecoder = null;
this.Response.End();
I'm listening but I only speak GEEK.
|
|
|
|
|
Hello friend, i tried to build animations with several pictures, but only 19 pictures could be stored.
Is this problem of the library or limitation of gif animations?
Please inform me.
Thanks.
inamullah, Pakistan.
|
|
|
|
|
Would any one be able to tell me the following?
before extracting a animated gif to still images and resizing it and putting it back together.
I need to know how to capture every frames timeline as I need some images to stay longer that others.
Then resize them greating an animated gif again.
this must happen using .net
Or if possible to resize the gif not pulling it apart..
Any help will be appreciated
|
|
|
|
|
Please visit http://www.codeplex.com/GifLib
sorry, I can't find entry for updating the article
|
|
|
|
|
|
could you provide an English version?
while looking at your new code on codeplex, it's impossible to compile it
thanks
|
|
|
|
|
Sorry but yours on CodePlex is a much worse "implement"!
You claim yours better but you don't deign to provide a "three-line sample by way of documentation, and on top of everything, it doesn't work: just a waste of time.
Kudos for NGif...
|
|
|
|
|
Is GifLib made by you? Or someone else?
|
|
|
|
|
看到有贴子把
GetPixels
改成
(bitmap.PixelFormat == PixelFormat.Format32bppArgb ||
bitmap.PixelFormat == PixelFormat.Format32bppPArgb ||
bitmap.PixelFormat == PixelFormat.Format32bppRgb)
这种方式。
可是生成的GIF图片,用Fireworks 等的GIF软件 导入导出(不做任何操作)的图片都会把体积减了很多。。
真搞不懂
|
|
|
|
|
使用中发现的一个bug
/**
* Analyzes image colors and creates color map.
*/
protected void AnalyzePixels()
{
int len = pixels.Length;
int nPix = len / 3;
indexedPixels = new byte[nPix];
NeuQuant nq = new NeuQuant(pixels, len, sample);
// initialize quantizer
colorTab = nq.Process(); // create reduced palette
// convert map from BGR to RGB
// for (int i = 0; i < colorTab.Length; i += 3)
// {
// byte temp = colorTab[i];
// colorTab[i] = colorTab[i + 2];
// colorTab[i + 2] = temp;
// usedEntry[i / 3] = false;
// }
// map image pixels to new palette
int k = 0;
//以下是我增加的。不加这三句,那么,第二帧中判断是否已经使用,就不正确。
for (int i = 0; i < usedEntry.Length; i++)
{
usedEntry[i] = false;
}
//增加结束
for (int i = 0; i < nPix; i++)
{
int index =
nq.Map(pixels[k++] & 0xff,
pixels[k++] & 0xff,
pixels[k++] & 0xff);
usedEntry[index] = true;
indexedPixels[i] = (byte) index;
}
pixels = null;
colorDepth = 8;
palSize = 7;
// get closest match to transparent color if specified
if (transparent != Color.Empty )
{
transIndex = FindClosest(transparent);
}
}
|
|
|
|
|
|
Using unsafe code only gives a small performance improvement.
The NeuQuant quantizer is the real problem.
Replacing this quantizer by for example the OctreeQuantizer (used in Paint.NET) solves the problem.
|
|
|
|
|
Can you be more precise ?
Could you explain how to do that please ?
|
|
|
|
|
In the LZWEncoder remove remaining and replace NextPixel():
private int NextPixel()
{
if (curPixel == pixAry.Length) return EOF;
curPixel++;
return pixAry[curPixel - 1] & 0xff;
}
|
|
|
|
|
Thank YOU for this FIX. It saved hours....
|
|
|
|
|
|
the original Gif File size is 9K
Use Gif.Components.GifDecoder() then Gif.Components.AnimatedGifEncoder() merge.
the result Gif file size be changed to 11K
why?
|
|
|
|
|
I am also facing the same problem. my original image is 19k animated gif.
using the code I decoded it into frames and combined together. But the new image size varies from 67 to 77 baesd on the image quality set
|
|
|
|
|
have some problem with this ,i m currently working on same application where animated image is resized but problem is that, i have completed reading of animation , i have done resizing of static images and creating of new animated images but problem is there , wen i want to combine all together, can anyone help me , if u have any relevant info,plz reply me
-- modified at 4:16 Monday 5th November, 2007
|
|
|
|
|
what is the problem u are facing when combining the frames?
|
|
|
|
|
Need to modify two methods in GifDecoder.cs:
int [] GetPixels( Bitmap bitmap )
{
int [] pixels = new int [image.Width * image.Height];
int count = 0;
for (int th = 0; th < image.Height; th++)
{
for (int tw = 0; tw < image.Width; tw++)
{
Color color = bitmap.GetPixel(tw, th);
pixels[count++] = color.ToArgb();
}
}
return pixels;
}
protected void SetPixels()
{
// expose destination image's pixels as int array
// int[] dest =
// (( int ) image.getRaster().getDataBuffer()).getData();
//int[] dest = GetPixels( bitmap );
int[] dest = null;
// fill in starting image contents based on last image's dispose code
if (lastDispose > 0)
{
if (lastDispose == 3)
{
// use image before last
int n = frameCount - 2;
if (n > 0)
{
lastImage = GetFrame(n - 1);
}
else
{
lastImage = null;
}
}
if (lastImage != null)
{
if (lastDispose == 2)
{
// fill last image rect area with background color
lastImage = new Bitmap(lastImage);
Graphics g = Graphics.FromImage(lastImage);
Color c = Color.Empty;
if (transparency)
{
c = Color.FromArgb(255, 0, 0, 0); // assume background is transparent
}
else
{
c = Color.FromArgb( lastBgColor ) ;
// c = new Color(lastBgColor); // use given background color
}
Brush brush = new SolidBrush( c );
g.FillRectangle( brush, lastRect );
brush.Dispose();
g.Dispose();
}
dest = GetPixels((Bitmap)lastImage);
}
}
if (dest == null) dest = new int[bitmap.Width * bitmap.Height];
// copy each source line to the appropriate place in the destination
int pass = 1;
int inc = 8;
int iline = 0;
for (int i = 0; i < ih; i++)
{
int line = i;
if (interlace)
{
if (iline >= ih)
{
pass++;
switch (pass)
{
case 2 :
iline = 4;
break;
case 3 :
iline = 2;
inc = 4;
break;
case 4 :
iline = 1;
inc = 2;
break;
}
}
line = iline;
iline += inc;
}
line += iy;
if (line < height)
{
int k = line * width;
int dx = k + ix; // start of line in dest
int dlim = dx + iw; // end of dest line
if ((k + width) < dlim)
{
dlim = k + width; // past dest edge
}
int sx = i * iw; // start of line in source
while (dx < dlim)
{
// map color and insert in destination
int index = ((int) pixels[sx++]) & 0xff;
int c = act[index];
if (c != 0)
{
dest[dx] = c;
}
dx++;
}
}
}
SetPixels( dest );
}
I am also try to use LockBits in GetPixels and SetPixels, without using unsafe code. I have found a way, but need some time to finish it.
|
|
|
|
|
Can you please let all know what the bug actually is ?
Thanks
A
|
|
|
|
|
Could you please send me your latest copy of this project? I'm in great need of it now, thanks a lot~
My e-mail is cmhienng1983@hotmail.com
cmhienng
|
|
|
|