[Offscreengecko-commits] SF.net SVN: offscreengecko:[87] trunk/src
Status: Pre-Alpha
Brought to you by:
res2002
|
From: <re...@us...> - 2008-11-02 01:56:51
|
Revision: 87
http://offscreengecko.svn.sourceforge.net/offscreengecko/?rev=87&view=rev
Author: res2002
Date: 2008-11-02 01:56:36 +0000 (Sun, 02 Nov 2008)
Log Message:
-----------
Add demo app to render a web page to a TGA file
Modified Paths:
--------------
trunk/src/CMakeLists.txt
Added Paths:
-----------
trunk/src/demos/
trunk/src/demos/CMakeLists.txt
trunk/src/demos/webpage2image.cpp
Modified: trunk/src/CMakeLists.txt
===================================================================
--- trunk/src/CMakeLists.txt 2008-11-02 01:56:08 UTC (rev 86)
+++ trunk/src/CMakeLists.txt 2008-11-02 01:56:36 UTC (rev 87)
@@ -2,3 +2,5 @@
add_subdirectory (common)
add_subdirectory (libosgk)
+
+add_subdirectory (demos)
Added: trunk/src/demos/CMakeLists.txt
===================================================================
--- trunk/src/demos/CMakeLists.txt (rev 0)
+++ trunk/src/demos/CMakeLists.txt 2008-11-02 01:56:36 UTC (rev 87)
@@ -0,0 +1,6 @@
+include_directories(../../include)
+add_executable(webpage2image webpage2image.cpp)
+target_link_libraries(webpage2image "-Wl,--warn-unresolved-symbols -Wl,--as-needed")
+target_link_libraries(webpage2image OffscreenGecko)
+target_link_libraries(webpage2image osgk-common)
+
Property changes on: trunk/src/demos/CMakeLists.txt
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/src/demos/webpage2image.cpp
===================================================================
--- trunk/src/demos/webpage2image.cpp (rev 0)
+++ trunk/src/demos/webpage2image.cpp 2008-11-02 01:56:36 UTC (rev 87)
@@ -0,0 +1,92 @@
+/*
+
+Copyright (c) 2008, Frank Richter <fra...@gm...>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * The name of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+#include <stdio.h>
+#include <unistd.h> // for usleep()
+
+#include <OffscreenGecko/browser.h>
+
+#include <fstream>
+#include "../common/tgawrite.h"
+
+int main (int argc, const char* const argv[])
+{
+ if (argc != 3)
+ {
+ fputs ("expecting parameters: <URI to render> <output TGA file name>\n", stderr);
+ return 1;
+ }
+
+ const char* uri = argv[1];
+ const char* outputFilename = argv[2];
+ // Rendering dimensions
+ int renderW = 1024, renderH = 1024;
+
+ // To use OSGK we first need an embedding object.
+ OSGK_GeckoResult embedInitResult;
+ OSGK::Embedding embedding (embedInitResult);
+ if (!embedding.IsValid())
+ {
+ // This means something went wrong
+ fprintf (stderr, "Error initializing OSGK embedding (%.8x)\n", embedInitResult);
+ return 1;
+ }
+
+ // The browser object is the main workhorse for web page rendering.
+ OSGK::Browser browser (embedding, renderW, renderH);
+ if (!browser.IsValid())
+ {
+ fputs ("Error creating OSGK browser\n", stderr);
+ return 1;
+ }
+
+ // Instruct browser to navigate to the given URI
+ browser.Navigate (uri);
+
+ // Wait until the URI finished loading
+ while (browser.QueryLoadState() != loadFinished)
+ {
+ usleep (500);
+ }
+
+ // Open output file
+ std::ofstream tgastream;
+ tgastream.open (outputFilename, std::ios::out | std::ios::binary);
+ // Lock pixel data from browser object for retrieval
+ const unsigned char* lockedData = browser.LockData();
+ // Write output file
+ OSGK::TGAWriter::WriteBGRAImage (renderW, renderH, lockedData, tgastream);
+ // Clean up file
+ tgastream.close ();
+ // Unlock pixel data
+ browser.UnlockData (lockedData);
+
+ return 0;
+}
Property changes on: trunk/src/demos/webpage2image.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|