Skip to content

Commit

Permalink
Awesomium
Browse files Browse the repository at this point in the history
  • Loading branch information
simonegli committed Jun 13, 2013
1 parent 27a7ad9 commit 9504b8a
Show file tree
Hide file tree
Showing 26 changed files with 159 additions and 142 deletions.
2 changes: 1 addition & 1 deletion XamlImageConverter.Awesomium/Html2PDF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Html2PDF: Snapshot.Html2PDFConverter {
public int Instances = 0;
public IDisposable FileLock = null;

public void SaveAsnc(Snapshot s) {
public void SaveAsync(Snapshot s) {
string path;
var source = ((Group.HtmlSource)s.Element).Source;
string html = null;
Expand Down
3 changes: 1 addition & 2 deletions XamlImageConverter.Exe/XamlImageConverter.Exe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="img\ImageMaps\Readme.aspx">
<SubType>
</SubType>
<SubType>ASPXCodeBehind</SubType>
</Content>
<Content Include="img\ImageMaps\usa.map.html" />
<Content Include="src\blog-banner.jpg" />
Expand Down
4 changes: 2 additions & 2 deletions XamlImageConverter.Exe/XamlImageConverter.Exe.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<StartArguments>-w -v -l C:\Code\XamlImageConverter\XamlImageConverter.Exe -p C:\Code\XamlImageConverter\XamlImageConverter.Exe ~/src/MakeImages.xic.xaml</StartArguments>
</PropertyGroup>
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<StartArguments>-p "C:\Code\Visitenkarte\Kleber" -l "C:\Code\Visitenkarte\Kleber\bin\Debug" -w -f ~/CreateImages.xic.xaml -1</StartArguments>
<StartArguments>-p "C:\Code\Visitenkarte\Kleber" -l "C:\Code\Visitenkarte\Kleber\bin\Debug" -w -f ~/CreateImages.xic.xaml</StartArguments>
</PropertyGroup>
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.ItemWizard.dll
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.ItemWizard.pdb
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.Web.dll
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.Web.pdb
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.dll
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.pdb
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/xiconvert.exe
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/xiconvert.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion XamlImageConverter.Web/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;
using System.Web.Hosting;

namespace XamlImageConverter.Web.UI {
namespace XamlImageConverter.Web {

public class Compiler {

Expand Down
128 changes: 0 additions & 128 deletions XamlImageConverter.Web/Map.cs

This file was deleted.

3 changes: 0 additions & 3 deletions XamlImageConverter.Web/XamlImageConverter.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Compiler.cs" />
<Compile Include="Map.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XamlControls.cs" />
<Compile Include="XamlImageConverterElements.cs" />
Expand Down
Binary file modified XamlImageConverter.v11.suo
Binary file not shown.
Binary file modified XamlImageConverter/Lazy/Awesomium/XamlImageConverter.Awesomium.dll
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions XamlImageConverter/XamlCapture/Interfaces.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XamlImageConverter {

public interface IPostProcessor {
IEnumerable<SnapshotImage> Process( IEnumerable<SnapshotImage> images, CaptureSettings settings );
IEnumerable<string> Close( CaptureSettings settings );
}

}
123 changes: 123 additions & 0 deletions XamlImageConverter/XamlCapture/PngHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace XamlImageConverter
{
public class PngHelper
{
// https://www.codeproject.com/KB/web-image/pnggammastrip.aspx?display=Print
// https://morris-photographics.com/photoshop/articles/png-gamma.html
public static void StripGAMA( Stream source, Stream destination )
{
// Copy header
var header = new byte[ 8 ];
source.Read( header, 0, header.Length );
destination.Write( header, 0, header.Length );

var chkLenBytes = new byte[ 4 ];
var chkTypeBytes = new byte[ 4 ];

var skipChunks = new[] { "gAMA", "iCCP", "cHRM", "sRGB", "IDAT", "PLTE" };

while ( source.Read( chkLenBytes, 0, chkLenBytes.Length ) == chkLenBytes.Length )
{
var adjustedLenBytes = chkLenBytes.ToArray();

// Reverse the byte order if we're little-endian
if ( System.BitConverter.IsLittleEndian ) System.Array.Reverse( adjustedLenBytes );

var chkLength = System.BitConverter.ToInt32( adjustedLenBytes, 0 );

// Get the type
source.Read( chkTypeBytes, 0, chkTypeBytes.Length );
var chkType = Encoding.ASCII.GetString( chkTypeBytes );

if ( chkType == "gAMA" )
{
// Skip the gamma information
source.Seek( 4 + chkLength, SeekOrigin.Current );
}
else
{
// Write chunks we've read to destination
destination.Write( chkLenBytes, 0, chkLenBytes.Length );
destination.Write( chkTypeBytes, 0, chkTypeBytes.Length );
}

if ( skipChunks.Contains( chkType )/* chkType == "gAMA" || chkType == "IDAT" || chkType == "PLTE"*/ )
{
// Nothing else of interest; copy remainder to destination
var buffer = new byte[ 64 * 1024 ];
int count;

while ( ( count = source.Read( buffer, 0, buffer.Length ) ) > 0 )
{
destination.Write( buffer, 0, count );
}

break;
}
else
{
// Write this chunk
var buffer = new byte[ 4 + chkLength ];
source.Read( buffer, 0, buffer.Length );
destination.Write( buffer, 0, buffer.Length );
}
}
}

//PNGRemoveChunks(SourceData, New String() {"gAMA", "iCCP", "cHRM", "sRGB"})
/*
private byte[] PNGRemoveChunks( ref byte[] SourceData, string[] ChunkIDsToRemove )
{
MemoryStream OutputStream = new MemoryStream();
int CurrentOffset = 0;
byte[] CurrentChunkLenData = new byte[ 4 ];
int CurrentChunkLen = 0;
string CurrentChunkType = null;
byte[] RetVal = null;
// Copy the 8 PNG header bytes directly to the output
OutputStream.Write( SourceData, 0, 8 );
CurrentOffset = 8;
// Iterate through the 'Chunks' in the PNG.
// 12 = Chunk Length Bytes + Chunk Type Bytes + CRC Bytes
while ( ( CurrentOffset <= SourceData.Length - 12 ) )
{
// Determine the length and type of this chunk (being careful to get the bytes in the right order)
CurrentChunkLenData[ 0 ] = SourceData[ CurrentOffset + 0 ];
CurrentChunkLenData[ 1 ] = SourceData[ CurrentOffset + 1 ];
CurrentChunkLenData[ 2 ] = SourceData[ CurrentOffset + 2 ];
CurrentChunkLenData[ 3 ] = SourceData[ CurrentOffset + 3 ];
if ( ( System.BitConverter.IsLittleEndian ) )
{
System.Array.Reverse( CurrentChunkLenData );
}
CurrentChunkLen = System.BitConverter.ToInt32( CurrentChunkLenData, 0 );
CurrentChunkType = System.Text.Encoding.ASCII.GetString( SourceData, CurrentOffset + 4, 4 );
// If this chunk is not in the list of chunk types to remove, add it to the output
if ( !ChunkIDsToRemove.Contains( CurrentChunkType ) )
{
OutputStream.Write( SourceData, CurrentOffset, CurrentChunkLen + 12 );
}
// Look at the next chunk in the file
CurrentOffset += CurrentChunkLen + 12;
}
// Tidy up and return the resulting PNG data
RetVal = OutputStream.ToArray();
OutputStream.Close();
return RetVal;
}*/
}
}
20 changes: 16 additions & 4 deletions XamlImageConverter/XamlCapture/Snapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,20 @@ public virtual Snapshot Save(string Culture) {
if (Filmstrip) encoder.Frames.Add(BitmapFrame.Create(MakeFilmstrip(Bitmaps, Dpi)));
else foreach (var b in Bitmaps) encoder.Frames.Add(BitmapFrame.Create(b));

using (FileLock(filename)) encoder.Save(filename);

using (FileLock(filename)) {
encoder.Save(filename);
if (encoder is PngBitmapEncoder) { // strip gamma
using (var src = new MemoryStream()) {
using (var srcf = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
srcf.CopyTo(src);
src.Seek(0, SeekOrigin.Begin);
}
using (var dest = new FileStream(filename, FileMode.Create, FileAccess.Write)) {
PngHelper.StripGAMA(src, dest);
}
}
}
}
if (Loop != 1 && ext == ".gif") {
string file = Path.GetFileName(filename);
var exe = Compiler.BinPath("ImageMagick\\convert.exe");
Expand Down Expand Up @@ -279,7 +291,7 @@ public virtual Snapshot Save(string Culture) {
private Html2PDFConverter Html2PDF = null;

public interface Html2PDFConverter {
void SaveAsnc(Snapshot s);
void SaveAsync(Snapshot s);
void AwaitSave();
}

Expand All @@ -293,7 +305,7 @@ public void SaveHtml() {
var Html2PDFType = a.GetType("XamlImageConverter.Html2PDF");
Html2PDF = (Html2PDFConverter)Activator.CreateInstance(Html2PDFType);
}
Html2PDF.SaveAsnc(this);
Html2PDF.SaveAsync(this);
}

public override void Cleanup() {
Expand Down
1 change: 1 addition & 0 deletions XamlImageConverter/XamlImageConverter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@
<None Include="XamlCapture\FastBuildCheck.cs" />
<Compile Include="XamlCapture\Hash.cs" />
<Compile Include="XamlCapture\ImageMap.cs" />
<Compile Include="XamlCapture\PngHelper.cs" />
<Compile Include="XamlCapture\Snapshot.cs" />
<Compile Include="XamlCapture\ThemeHelper.cs" />
<Compile Include="XamlCapture\WebFiles.cs" />
Expand Down
2 changes: 1 addition & 1 deletion XamlImageConverter/XamlImageConverter.csproj.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>

0 comments on commit 9504b8a

Please sign in to comment.