From fad893ed70126d47c9c1a3d27cb59eca103d40bb Mon Sep 17 00:00:00 2001 From: Bryan Petty Date: Sun, 22 Nov 1998 22:32:53 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'M_REFERENCE'. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/tags/M_REFERENCE@1021 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- TODO.txt | 42 + docs/gtk/welcome.html | 292 ++ docs/latex/wx/upditer.tex | 56 + docs/latex/wx/winhelp.tex | 107 + include/wx/fstream.h | 74 + install/unix/.cvsignore | 6 + misc/imlib/im_palette.pal | 64 + misc/imlib/imrc | 99 + samples/dynamic/minimal.cpp | 113 - src/gdk_imlib/AUDIT | 26 + src/gdk_imlib/AUTHORS | 1 + src/gdk_imlib/COPYING.LIB | 481 +++ src/gdk_imlib/ChangeLog | 74 + src/gdk_imlib/README | 29 + src/gdk_imlib/cache.c | 496 +++ src/gdk_imlib/colors.c | 113 + src/gdk_imlib/config.h | 2 + src/gdk_imlib/gdk_imlib.h | 78 + src/gdk_imlib/gdk_imlib_private.h | 226 ++ src/gdk_imlib/gdk_imlib_types.h | 101 + src/gdk_imlib/globals.c | 6 + src/gdk_imlib/load.c | 1498 +++++++ src/gdk_imlib/misc.c | 1165 ++++++ src/gdk_imlib/rend.c | 6170 +++++++++++++++++++++++++++++ src/gdk_imlib/save.c | 538 +++ src/gdk_imlib/utils.c | 1521 +++++++ src/msw/Y_TAB.C | 521 +++ src/msw/xfspline.inc | 355 ++ utils/ogl/src/bitmap.cpp | 123 + utils/ogl/src/bitmap.h | 54 + 30 files changed, 14318 insertions(+), 113 deletions(-) create mode 100644 TODO.txt create mode 100644 docs/gtk/welcome.html create mode 100644 docs/latex/wx/upditer.tex create mode 100644 docs/latex/wx/winhelp.tex create mode 100644 include/wx/fstream.h create mode 100644 install/unix/.cvsignore create mode 100644 misc/imlib/im_palette.pal create mode 100644 misc/imlib/imrc delete mode 100644 samples/dynamic/minimal.cpp create mode 100644 src/gdk_imlib/AUDIT create mode 100644 src/gdk_imlib/AUTHORS create mode 100644 src/gdk_imlib/COPYING.LIB create mode 100644 src/gdk_imlib/ChangeLog create mode 100644 src/gdk_imlib/README create mode 100644 src/gdk_imlib/cache.c create mode 100644 src/gdk_imlib/colors.c create mode 100644 src/gdk_imlib/config.h create mode 100644 src/gdk_imlib/gdk_imlib.h create mode 100644 src/gdk_imlib/gdk_imlib_private.h create mode 100644 src/gdk_imlib/gdk_imlib_types.h create mode 100644 src/gdk_imlib/globals.c create mode 100644 src/gdk_imlib/load.c create mode 100644 src/gdk_imlib/misc.c create mode 100644 src/gdk_imlib/rend.c create mode 100644 src/gdk_imlib/save.c create mode 100644 src/gdk_imlib/utils.c create mode 100644 src/msw/Y_TAB.C create mode 100644 src/msw/xfspline.inc create mode 100644 utils/ogl/src/bitmap.cpp create mode 100644 utils/ogl/src/bitmap.h diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000000..7fc0383153 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,42 @@ +********************* TODO list for wxWindows 2 ****************************** + +=============================== common ======================================== + +wxSocket, wxTCP etc.. + +wxMultiMedia + +=============================== generic ====================================== + +wxTreeCtrl keyboard handling +wxTreeCtrl icon support + +wxListCtrl icon support in list mode + +================================ MSW ========================================== + +Consistent keyboard interface and focus behaviour + currently, the focus is lost all the time (after a MessageBox, for example) + and sometimes TABbing through controls doesn't work + +================================ GTK ========================================== + +Add support Set colour/baclgroundcolour in GTK widgets +Correct tab navigation (seems to be a GTK feature) +Finish DnD +Add Clipboard +Help system (not sure about this one) +Show accelerator in menus +More controls with bitmaps +Speed up bitmap saving +Add wxBitmapHandler +Fix printing of bitmaps +Implement wxRadioBox layout +Finish wxTextCtrl +Finish native wxTreeCtrl +Implement wxPalette +Implement wxDirDialog +Support cooperation between Qt and wxWindows +Fix toolbar tips +TrueType support (just kidding) + diff --git a/docs/gtk/welcome.html b/docs/gtk/welcome.html new file mode 100644 index 0000000000..ac59b63028 --- /dev/null +++ b/docs/gtk/welcome.html @@ -0,0 +1,292 @@ + +wxGTK Homepage + + +

"wxWindows for the GTK" Homepage

+ +
+

Current version

+15th May '98: wxGTK v0.12 (alpha-) +

+This release is hardly more stable than the one before, but it +has many new features. It's main purpose is actually to prepare +the final merge of the Windows port and the GTK port source +trees into a common tree, developed using CVS. The growing +number of demos which compile and run with wxGTK "although" +being written for wxMSW shows that we seem to be on the right +track. One nice new feature for many potential users is that +wxGTK no longer needs any extra libraries to be installed, +other than the GTK. +

+If you have a compiler +better than gcc 2.7.2.2 then you can uncomment a line in src/common/prntbase.cpp +which defines __GOOD_COMPILER__. This should make the printing demo work. +I haven't got such a compiler, so I actually don't know. Somebody reported +problems with version 2.7.2.3 as well. +

+


+

Acknowledgements

+I'd like to thank the +Freiburg Linux User Group + for kindly providing +this site and Christian Wetzel in particular for helping me with +this site's administration. +

+ +


+

What is wxWindows?

+wxWindows is a C++ cross-platform GUI toolkit written mainly by Julian Smart. +More information about wxWindows can be found at the +wxWindows Homepage. + +

+The current version of wxWindows (v1.68) supports Windows ('95 and NT), Motif and +XView (aka OpenLook). There is another port (wxXt) available, which uses the +free-ware widget set from the Free Widget Foundation (FSF). Ports have been +started for the Mac, OS/2 and NextStep. +

+For different reasons, it was decided to start a complete rewrite of wxWindows, +which will then be called wxWindows 2.0. For a list of new features and changes +from the current version, you may read the wxWindows Homepage (see above). +

+Currently, work is being done on four ports of wxWindows 2.0: +

+
  • Windows (wxMSW, main author Julian Smart) +
  • Unix, Motif (wxMotif, main author Markus Holzhem) +
  • Unix, GIMP Toolkit (wxGTK, main author Robert Roebling) +
  • Macintosh (wxMac, main author Greg Whitehead) +
  • +

    +wxWindows provides a rich set of classes which help to make cross-platform +GUI programming easy. In many aspect, it is modelled after MFC, making transition +from MFC to wxWindows relatively painless. The main technical +difference between most other free or commercial cross platform libraries is +that wxWindows is a wrapper around existing widget sets, whereas the other +toolkits (Qt, Tk, Java, Amulet, OPaC, JX, Fresko) draw their widgets themselves, +which results in applications having a different look than native applications +for that specific platform. +

    +There are classes for the following categories +

    +
  • Window classes: wxWindow, wxFrame, wxDialogBox, wxPanel, wxCanvas etc. +
  • Widget classes: wxButton, wxCheckbox, wxChoice, wxListBox, wxListCtrl, wxText, wxGauge etc. +
  • Data structures: wxList, wxString, wxHashTable, wxDate etc. +
  • Layout/constraint system +
  • GDI classes: wxPen, wxBrush, wxFont, wxBitmap etc. +
  • Events: wxCommandEvent, wxMouseEvent, wxKeyEvent etc. +
  • Devices contexts: wxCanvasDC, wxPostScriptDC, wxMemoryDC, wxPrinterDC +
  • Base classes for runtime-type information: wxObject +
  • Interprocess communication: wxClient, wxConnection, wxSocket, wxServer etc. +
  • Document-view architecture: wxDocument, wxView, wxDocManager etc. +
  • Printing framework: wxPreviewFrame, wxPrintDialog, wxPrinter etc. +
  • Many helper classes, wxApplication, wxTypeTree, wxPathList etc. +
  • Classes for internationalization +
  • Built-in memory leak checking, log-files +
  • A multitude of functions and macros +
  • + +
    +

    Copyright

    +The choice of a suitable copyright has been subject to endless discussions. It +has always been the aim, to put wxWindows under a copyright, which protects +the work of its authors while at the same time encouraging the use of wxWindows +in as many projects as possible. +

    +The (so far) last decision has been to put the whole of wxWindows +under a modified (less restrictive) version of the GNU library general +public license. +

    +The only exception is that wxGTK now contains code (gdk_imlib) which is +under the GNU library general public license. When you make changes to +this part of wxGTK, you'll have to make these changes public (in contrast +to changes to the rest). +

    +It is obviously encouraged that anybody who uses wxWindows and who +makes any improvements to it will make these changes available to +wxWindows' authors. +

    +


    +

    What can I do with wxWindows 2.0?

    +wxWindows is still in alpha stage, which means that there are still bugs +waiting for you and several features are not yet (fully) implemented, but +you can expect the interface to be more or less stable, so no major +modifications will have to be made to your source code. wxGTK is already +used in a number of medium sized projects and is it being developped +in close cooperation with the authors of these applications. +

    +


    +

    Can I write a GNOME application with wxGTK 2.0?

    +Good question. The idea to use wxGTK for the GNOME desktop environment is +quite obvious. When this topic came up on the GNOME mailing list, the GNOME +people have shown an amazingly negative opinion about wxWindows. One reason +might be that several of the main authors of the GNOME-project consider +C++ a "broken language". I don't share that view and I am sure many people +find C++ easier to handle and better suited for GUI programming than C. +

    +Just recently, the topic of C++ in general and wxGTK in particular appeared +again on the GNOME list. It has shown that - at least - the opinion on C++ +on the GNOME list is split. +

    +There is already a C++ wrapper for the GTK called GTK-- written by Tero Pulkkinen. +It is very small and adds very little overhead to the GTK. If platform +independence is no issue for you and you want to write a small tool +for Linux, you should probably use GTK--. Of course you can use wxGTK +for that, too :-) +

    +


    +

    Screenshots

    +What would a home page of a GUI be without a screenshot? Well, as wxWindows +is a wrapper around existing widget/item sets, a wxWindows application will +look like any other native Windows, Motif, GTK or Mac application. +

    +But for those of you, who wouldn't download wxGTK only because there +is no screenshot, +here it comes. +

    +


    +

    Download 1.68

    +Go to the +FTP +section directly. +

    +There is documentation for version 1.68 in html available. +here. Not yet. +

    +You can download current wxWindows version 1.68 for Windows, Motif and +XView from +here. Not yet. +

    +You can download wxXt 1.66d from +here. +

    +


    +

    Download 2.0 alpha

    +There is documentation for version 2.0 in html available. +here. +

    +You can download the first alpha for wxWindows 2.0 for Windows from +here. Not yet. +

    +You can download the current alpha for wxWindows 2.0 for GTK from +here. +

    + +


    +

    News from wxGTK 0.12

    +

    +PNG, zlib and gdk_imlib code included. +

    +MDI implementation. More a basis for further testing +than of real value. +

    +Split "--with-debug" option into two options: "--with-debug_info" +and "--with-debug_flag". The first one sets the "-g" flag when +compiling, the second defines "DEBUG" in setup.h (which is included +from defs.h). +

    +Merged DocView framework. The sample doesn't compile yet, because +it uses features from wxTextCtrl, which I haven't implemented yet. +

    +Merged TabCtrl. Doesn't look perfect, but it seems to work. +

    +Merged remaining classes from the newest wxMSW alpha. (wxDynArray, +wxModule etc.). +

    +Further updates, bug fixes or additions: +

    +

    +
  • wxYield() (again) +
  • postscript support for bitmaps +
  • spline code merged +
  • several bug fixes +
  • new samples +
  • + +

    +


    +

    Known problems

    + +Missing implementation of: +
    +
  • Impossible to set new font in GTK's widgets +
  • Items containing bitmaps +
  • Masks, bitmap handlers (partially done) +
  • Gauge +
  • Combobox +
  • Palettes (colormaps) +
  • Keyboard accelerators for menus +
  • Validation +
  • Clipboard functions +
  • Resources (for use with wxIDE-to-be) +
  • Drag and Drop +
  • Threads, Interprocess communication +
  • Sockets +
  • Database classes +
  • + +

    +


    +

    Installation of wxGTK under Linux

    + +GTK requires an up-to-date version of the +
    +
  • GTK (GIMP ToolKit) +
  • +to be installed as a shared lib on your system. wxGTK is being developped with +version 1.0.1 and it is known not to work with earlier versions. +The GTK library is available from +somewhere here (gtk.org). +After having typed "make install" the GTK header files should be +in "/usr/local/include". Correct me, if I am wrong. +

    +Compilation itself works as usual with autoconf: +

    +
  • Unpack it to a suitable subdirectory, let's say ~/wxGTK +
  • Type "cd wxGTK" +
  • Type "configure" +
  • Type "make" +
  • +Some demos use files stored in the source directory of those demos +(e.g. internat uses files in samples/internat) whereas the binaries +will end up in samples/internat/linux. You'll have to copy the binaries +down or call them like "linux/test" from samples/internat. This is +also the case for wxTest (which should display a horse). +

    +You can create a shared library by adding the option "--with-shared" to +the "configure" command. Afterwards, you'll have to copy the library +~/wxGTK/lib/linux (if you have Linux) to a directory in your LDPATH (e.g. /usr/X11R6/lib) +and run "ldconfig". +

    + +


    +

    Mailing list for wxGTK

    +The mailing list (as well as this page) is called wxxt for more +or less historical reasons. +

    +You can subsribe to the mailing list by sending a mail to +majordomo@wesley.informatik.uni-freiburg.de. +This mail must contain the text "subscribe wxxt" in the body (not the subject) of the +mail. You will then get a confirmation that somebody asked majordomo to put you +on the list and you will have to confirm this once again by sending back +the authentisation, which comes in the confirmation mail. The last step +is also described in the actual confirmation mail (I think). +

    +You can send a mail to the mailing list to the address +wxxt@www.freiburg.linux.de. + +

    +Unsubscribe by sending "unsubscribe wxxt" to majordomo (see above). Not to +the actual mailing list. +

    +


    +
    +
    This page is maintained by Robert Roebling. +Comments, in contrast to junk and flames, welcome. +

    +Last changed 15th Mai '98. +

    + + + + + diff --git a/docs/latex/wx/upditer.tex b/docs/latex/wx/upditer.tex new file mode 100644 index 0000000000..148d4960da --- /dev/null +++ b/docs/latex/wx/upditer.tex @@ -0,0 +1,56 @@ +\section{\class{wxUpdateIterator}}\label{wxupdateiterator} + +This class is used to iterate through all damaged regions of a window, within an OnPaint call. + +To use it, construct an iterator object on the stack and loop through the +regions, testing the object and incrementing the iterator at the end of the loop. + +See \helpref{wxScrolledWindow::OnPaint}{wxscrolledwindowonpaint} for an example of use. + +\wxheading{Derived from} + +\helpref{wxObject}{wxobject} + +\wxheading{See also} + +\helpref{wxScrolledWindow::OnPaint}{wxscrolledwindowonpaint} + +\latexignore{\rtfignore{\wxheading{Members}}} + +\membersection{wxUpdateIterator::wxUpdateIterator} + +\func{}{wxUpdateIterator}{\param{wxWindow* }{window}} + +Creates an iterator object. + +\membersection{wxUpdateIterator::GetX} + +\func{int}{GetX}{\void} + +Returns the x value for the current region. + +\membersection{wxUpdateIterator::GetY} + +\func{int}{GetY}{\void} + +Returns the y value for the current region. + +\membersection{wxUpdateIterator::GetWidth} + +\func{int}{GetWidth}{\void} + +Returns the width value for the current region. + +\membersection{wxUpdateIterator::GetHeight} + +\func{int}{GetWidth}{\void} + +Returns the width value for the current region. + +\membersection{wxUpdateIterator::operator $++$} + +\func{void}{operator $++$}{\void} + +Increments the iterator to the next region. + + diff --git a/docs/latex/wx/winhelp.tex b/docs/latex/wx/winhelp.tex new file mode 100644 index 0000000000..0bf137c8b8 --- /dev/null +++ b/docs/latex/wx/winhelp.tex @@ -0,0 +1,107 @@ +\section{\class{wxWinHelpController}}\label{wxwinhelpcontroller} + +This class provides the means to control a WinHelp instance. +Under Windows, wxHelpController is defined to be a synonym for wxWinHelpController. + +A help controller allows an application to display help, at the contents +or at a particular topic, and shut the help program down on termination. +This avoids proliferation of many instances of the help viewer whenever the +user requests a different topic via the application's menus or buttons. + +Typically, an application will create a help controller instance +when it starts, and immediately call {\bf Initialize}\rtfsp +to associate a filename with it. The help viewer will only get run, however, +just before the first call to display something. + +\wxheading{Derivation} + +\helpref{wxObject}{wxobject} + +\wxheading{See also} + +\helpref{wxHelpControllerBase}{wxhelpcontrollerbase} + +\wxheading{Include file} + +{\tt } + +\latexignore{\rtfignore{\wxheading{Members}}} + +\membersection{wxWinHelpController::wxWinHelpController} + +\func{}{wxWinHelpController}{\void} + +Constructs a help instance object, but does not invoke the help viewer. + +\membersection{wxWinHelpController::\destruct{wxWinHelpController}} + +\func{}{\destruct{wxWinHelpController}}{\void} + +Destroys the help instance, closing down the viewer if it is running. + +\membersection{wxWinHelpController::Initialize}\label{wxwinhelpcontrollerinitialize} + +\func{void}{Initialize}{\param{const wxString\& }{file}} + +Initializes the help instance with a help filename. Does not invoke the help viewer. +This must be called directly after the help instance object is created and before +any attempts to communicate with the viewer. + +You may omit the file extension and a suitable one will be chosen. + +\membersection{wxWinHelpController::DisplayBlock}\label{wxwinhelpcontrollerdisplayblock} + +\func{bool}{DisplayBlock}{\param{long}{ blockNo}} + +If the help viewer is not running, runs it and displays the file at the given block number. +The interpretation of {\it blockNo} differs between help viewers. If using Windows Help, this +refers to the context number. + +\membersection{wxWinHelpController::DisplayContents}\label{wxwinhelpcontrollerdisplaycontents} + +\func{bool}{DisplayContents}{\void} + +If the help viewer is not running, runs it and displays the +contents. + +\membersection{wxWinHelpController::DisplaySection}\label{wxwinhelpcontrollerdisplaysection} + +\func{bool}{DisplaySection}{\param{int}{ sectionNo}} + +DisplaySection does not apply to WinHelp. + +\membersection{wxWinHelpController::KeywordSearch}\label{wxwinhelpcontrollerkeywordsearch} + +\func{bool}{KeywordSearch}{\param{const wxString\& }{keyWord}} + +If the help viewer is not running, runs it, and searches for sections matching the given keyword. If one +match is found, the file is displayed at this section. If more than one +match is found, the first topic is displayed (Windows Help). + +\membersection{wxWinHelpController::LoadFile}\label{wxwinhelpcontrollerloadfile} + +\func{bool}{LoadFile}{\param{const wxString\& }{file = NULL}} + +If the help viewer is not running, runs it and loads the given file. +If the filename is not supplied or is +NULL, the file specified in {\bf Initialize} is used. If the viewer is +already displaying the specified file, it will not be reloaded. This +member function may be used before each display call in case the user +has opened another file. + +\membersection{wxWinHelpController::OnQuit}\label{wxwinhelpcontrolleronquit} + +\func{bool}{OnQuit}{\void} + +Overridable member called when this application's viewer is quit by the user. + +Not implemented. + +\membersection{wxWinHelpController::Quit}\label{wxwinhelpcontrollerquit} + +\func{bool}{Quit}{\void} + +If the viewer is running, quits it by disconnecting. + +For Windows Help, the viewer will only close if no other application is using it. + diff --git a/include/wx/fstream.h b/include/wx/fstream.h new file mode 100644 index 0000000000..76a78cf227 --- /dev/null +++ b/include/wx/fstream.h @@ -0,0 +1,74 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: fstream.h +// Purpose: File stream classes +// Author: Guilhem Lavaux +// Modified by: +// Created: 11/07/98 +// RCS-ID: $Id$ +// Copyright: (c) Guilhem Lavaux +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_WXFSTREAM_H__ +#define _WX_WXFSTREAM_H__ + +#ifdef __GNUG__ +#pragma interface "fstream.h" +#endif + +#include +#include +#include +#include + +class wxFileInputStream: public wxInputStream { + public: + wxFileInputStream(const wxString& ifileName); + wxFileInputStream(wxFile& file); + wxFileInputStream(int fd); + virtual ~wxFileInputStream(); + + virtual char Peek(); + + bool Ok() const { return m_file->IsOpened(); } + + protected: + wxFileInputStream(); + + size_t OnSysRead(void *buffer, size_t size); + off_t OnSysSeek(off_t pos, wxSeekMode mode); + off_t OnSysTell() const; + + protected: + wxFile *m_file; + bool m_file_destroy; +}; + +class wxFileOutputStream: public wxOutputStream { + public: + wxFileOutputStream(const wxString& fileName); + wxFileOutputStream(wxFile& file); + wxFileOutputStream(int fd); + virtual ~wxFileOutputStream(); + + // To solve an ambiguity on GCC + inline wxOutputStream& Write(const void *buffer, size_t size) + { return wxOutputStream::Write(buffer, size); } + + void Sync(); + + bool Ok() const { return m_file->IsOpened(); } + + protected: + wxFileOutputStream(); + + size_t OnSysWrite(const void *buffer, size_t size); + off_t OnSysSeek(off_t pos, wxSeekMode mode); + off_t OnSysTell() const; + + protected: + wxFile *m_file; + bool m_file_destroy; +}; + +#endif diff --git a/install/unix/.cvsignore b/install/unix/.cvsignore new file mode 100644 index 0000000000..33c4fd3c62 --- /dev/null +++ b/install/unix/.cvsignore @@ -0,0 +1,6 @@ +configure +config.cache +config.status +Linux.system.cache +linux-gnu.system.cache +system.list diff --git a/misc/imlib/im_palette.pal b/misc/imlib/im_palette.pal new file mode 100644 index 0000000000..7464319c3f --- /dev/null +++ b/misc/imlib/im_palette.pal @@ -0,0 +1,64 @@ +0x0 0x0 0x0 +0xff 0xff 0xff +0xdd 0xdd 0xdd +0xbb 0xbb 0xbb +0x99 0x99 0x99 +0x77 0x77 0x77 +0x55 0x55 0x55 +0x33 0x33 0x33 +0x88 0x0 0x0 +0xcc 0x0 0x0 +0xff 0x0 0x0 +0xff 0x44 0x0 +0xff 0x88 0x0 +0xff 0xcc 0x0 +0xff 0xff 0x0 +0xcc 0xcc 0x0 +0x88 0x88 0x0 +0x60 0x60 0x0 +0x0 0x43 0x0 +0x0 0x7f 0x0 +0x0 0xcc 0x0 +0x0 0xff 0x0 +0x0 0x44 0x44 +0x0 0x88 0x88 +0x0 0xff 0xff +0x0 0x0 0x44 +0x0 0x0 0x88 +0x0 0x0 0xff +0xff 0xcc 0x97 +0xef 0xb1 0x7b +0xdf 0x98 0x5f +0xbf 0x87 0x56 +0x9f 0x6b 0x42 +0x7f 0x57 0x26 +0x5f 0x39 0xc +0x3f 0x1c 0x0 +0x21 0x0 0x0 +0x0 0x43 0x87 +0x2d 0x70 0xaf +0x5a 0x9e 0xd7 +0x87 0xcc 0xff +0xff 0xe0 0xba +0x21 0x43 0xf +0x3d 0x5d 0x25 +0x59 0x78 0x3a +0x75 0x93 0x4f +0x91 0xae 0x64 +0xad 0xc8 0x7a +0xf0 0xa8 0xef +0xd0 0x88 0xd0 +0xaf 0x66 0xaf +0x8e 0x44 0x8e +0x6d 0x22 0x6d +0x4b 0x0 0x4b +0xff 0xc0 0xbc +0xff 0x93 0x91 +0xff 0x66 0x67 +0xd8 0xf2 0xbf +0xff 0xc9 0x68 +0xff 0x96 0x67 +0xa5 0x60 0xff +0x51 0xff 0x99 +0x3f 0xa5 0x63 +0x98 0x90 0x67 diff --git a/misc/imlib/imrc b/misc/imlib/imrc new file mode 100644 index 0000000000..5849d45bb7 --- /dev/null +++ b/misc/imlib/imrc @@ -0,0 +1,99 @@ +################################ +# Config file for Imlib # +################################ + +# The file that contains palette entries for a global palette for all Imlib +# based programs. +# options: full path to palette file +PaletteFile /etc/im_palette.pal +# This defines if when the display is greater than 8 bit, that it still remaps +# the images to the palette defined, rather than using "perfect" rendering +# options: yes/no +PaletteOverride no +# If remapping to the palette, whether to use Floyd-Steinberg dithering. Saying +# yes will slow things down though. +# options: yes/no +Dither yes +# when remapping to the palette, saying fast will reduce accuracy, but improve +# speed quite considerably +# options: fast/slow +Remap fast +# This turns on dithering for 15/16 bpp. This makes smooth gradients look much +# smoother - in fact almost perfect. You will find it nigh impossible to tell +# the difference between 15/16bpp dithered and 24bpp. Unless you have extra +# CPU to burn, its not recommended, unless you are a image quality freak, and +# you insist on maximum quality in 15/16bpp. It does slow things down. It +# would be best to leave it off and let the applications themselves allow +# you to select it for certain purposes only. +HighQuality off +# This option if specified off will force MIT-SHM off, otherwise will allow +# Imlib to work it out itself. +Mit-Shm on +# This will turn shared pixmaps on or off (off forces off, on lets imlib +# work it out). This is yet another speedup. leave it on unless it doesn't +# work.. then turn it off. +SharedPixmaps off +# This speeds up rendering considerably, but may not work on your hardware +# due to it bypassing a few layers and byte-twiddling the rendered image data +# manually, and due to endianess, bit-ordering or RGB ordering it may screw up +# and not work, so try it.. if things work great!, if not, wait until a +# renderer for your situation is written, or write one yourself and donate +# it. It's easy to do, just look at rend.c +FastRender on +# This is in fact a workaround due to Solaris's shared memory theories. +# This specifies the maximum size of a shared memory chunk in bytes. If an +# image is larger that this in bytes for the video mode you're in, imlib will +# not use MIT-SHM. if you comment this out, imlib will use as much memory as +# necessary to render the image. +# Shm_Max_Size 1000000 +# This turns Image loading (24) bit caching on or off. HIGHLY suggested to be +# turned ON! +Image_Cache on +# Image cache size in bytes. As with any cache, the more, the better. If you +# load the same image more than once. Imlib will used a previously loaded +# copy, and if its freed, the Image_Cache_Size amount of bytes of image data +# are kept even after being freed, in case the same image is loaded again soon +# afterwards. Neat eh? +Image_Cache_Size 4000000 +# This turns the pixmap caching system on or off. If on, only well-behaved +# programs that conform to the specs for using Imlib will exhibit the +# behavior as expected. It is suggested to leave this on, as it will boost +# performance considerably, speed-wise and memory-wise. The reason apps need +# to be well-behaved is so that they don't go drawing on, and XFreePixmap'ing +# these pixmaps themselves, because this will trample all over the cache +# and give very horrid effects, or even make the apps crash with segfaults or +# Xlib errors. +Pixmap_Cache on +# Pixmap cache is in **-> BITS <-**... the end result is APPROXIMATELY +# 10000000 bits of pixmap make your Xserver grow by 1Mb of RAM (VERY rough). +# As with any cache, the more, the better. The more you have, the less likely +# it is that you will get cache misses and so performance on scaling the same +# image to commonly used sizes (ie if 3 or 4 sizes of the same image are used) +# will be lightning fast, in fact in some tests I did, in 16bpp up to 38 times +# as fast, and in 8bpp (with dithering on) up to 105 times faster!!! (these +# are nominal figures obtained on my machine. these are MAXIMUM speedup +# results. Results may vary on other machines and according to the way +# programs are written and use Imlib) +Pixmap_Cache_Size 40000000 +# This FORCES Imlib to use the hexadecimal visual id stated here if it is +# defined in the imrc. This bypasses Imlib's routines that hunt for the best +# visual. You can obtain a list of visual ID's using the xdpyinfo command. +# You should only need this if Imlib doesn't pick the correct visual or you +# have strange hardware/Xserver combinations. +#ForceVisualID 22 +# This allows Imlib to fall back on Imagemagick and/or NETPBM +# utilities if it can't load the file. +Fallback on +# Default Gamma, Brightness and Contrast stuff.... +Gamma 1.0 +Brightness 1.0 +Contrast 1.0 +Red_Gamma 1.0 +Red_Brightness 1.0 +Red_Contrast 1.0 +Green_Gamma 1.0 +Green_Brightness 1.0 +Green_Contrast 1.0 +Blue_Gamma 1.0 +Blue_Brightness 1.0 +Blue_Contrast 1.0 diff --git a/samples/dynamic/minimal.cpp b/samples/dynamic/minimal.cpp deleted file mode 100644 index 354d3aaec4..0000000000 --- a/samples/dynamic/minimal.cpp +++ /dev/null @@ -1,113 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: minimal.cpp -// Purpose: Dynamic events wxWindows sample -// Author: Julian Smart -// Modified by: -// Created: 04/01/98 -// RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "minimal.cpp" -#pragma interface "minimal.cpp" -#endif - -// For compilers that support precompilation, includes "wx/wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WX_PRECOMP -#include "wx/wx.h" -#endif - -#ifdef __WXGTK__ -#include "mondrian.xpm" -#endif - -// Define a new application type -class MyApp: public wxApp -{ public: - bool OnInit(void); -}; - -// Define a new frame type -class MyFrame: public wxFrame -{ public: - MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); - - public: - void OnQuit(wxCommandEvent& event); - void OnAbout(wxCommandEvent& event); - bool OnClose(void) { return TRUE; } -}; - -// ID for the menu commands -#define MINIMAL_QUIT 1 -#define MINIMAL_TEXT 101 -#define MINIMAL_ABOUT 102 - -// Create a new application object -IMPLEMENT_APP (MyApp) - -// `Main program' equivalent, creating windows and returning main app frame -bool MyApp::OnInit(void) -{ - // Create the main frame window - MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "Minimal wxWindows App", 50, 50, 450, 340); - - frame->Connect( MINIMAL_QUIT, -1, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)MyFrame::OnQuit ); - frame->Connect( MINIMAL_ABOUT, -1, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)MyFrame::OnAbout ); - - // Give it an icon -#ifdef __WXMSW__ - frame->SetIcon(wxIcon("mondrian")); -#else - frame->SetIcon(wxIcon(mondrian_xpm)); -#endif - - // Make a menubar - wxMenu *file_menu = new wxMenu; - - file_menu->Append(MINIMAL_ABOUT, "&About"); - file_menu->Append(MINIMAL_QUIT, "E&xit"); - wxMenuBar *menu_bar = new wxMenuBar; - menu_bar->Append(file_menu, "&File"); - frame->SetMenuBar(menu_bar); - - // Make a panel with a message - wxPanel *panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL); - - (void)new wxStaticText(panel, 311, "Hello!", wxPoint(10, 10), wxSize(-1, -1), 0); - - // Show the frame - frame->Show(TRUE); - - SetTopWindow(frame); - - return TRUE; -} - -// My frame constructor -MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): - wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) -{} - -void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) -{ - Close(TRUE); -} - -void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) -{ - wxMessageDialog dialog(this, "This is a minimal sample\nA second line in the message box", - "About Minimal", wxYES_NO|wxCANCEL); - - dialog.ShowModal(); -} - - diff --git a/src/gdk_imlib/AUDIT b/src/gdk_imlib/AUDIT new file mode 100644 index 0000000000..e69b50738d --- /dev/null +++ b/src/gdk_imlib/AUDIT @@ -0,0 +1,26 @@ +Audit status of gdk_imlib so far: + +cache.c appears clean +globals.c appears clean + +load.c: + JPEG, PNG, GIF and TIFF loaders seem safe but the underlying + yet libraries have not been checked + Helper stuff should now be safe. + +misc.c + The obvious screwups have been remedied with the usual + length checking sscanfs and snprintfs. + Rewrote a little of the parsing code to avoid future problems. + +rend.c + Appears ok + +save.c + Some stuff has been fixed. The helpers should be safe but + are incomplete + +utils.c + Ok this seems clean now. There's a few FIXME's but they are + either new features (helper needs %Q) or bogus but non fatal + stuff diff --git a/src/gdk_imlib/AUTHORS b/src/gdk_imlib/AUTHORS new file mode 100644 index 0000000000..2c8f9861b2 --- /dev/null +++ b/src/gdk_imlib/AUTHORS @@ -0,0 +1 @@ +Rasterdude :-) diff --git a/src/gdk_imlib/COPYING.LIB b/src/gdk_imlib/COPYING.LIB new file mode 100644 index 0000000000..eb685a5ec9 --- /dev/null +++ b/src/gdk_imlib/COPYING.LIB @@ -0,0 +1,481 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/src/gdk_imlib/ChangeLog b/src/gdk_imlib/ChangeLog new file mode 100644 index 0000000000..67cab52052 --- /dev/null +++ b/src/gdk_imlib/ChangeLog @@ -0,0 +1,74 @@ +1998-05-07 Raja R Harinath + + * save.c (gdk_imlib_save_image): Replaces `snprintf' with + `g_snprintf' calls. + * utils.c (gdk_imlib_create_image_from_data): Likewise. + +Tue May 5 15:11:59 1998 Radek Doulik + + * replaced snprintf calls with g_snprintf ones, so it + compiles now on SunOS + +Sat Apr 11 12:30:13 1998 George Lebl + + * utils.c: fixed yet one more SIGFPE on alpha + +Fri Mar 20 00:02:43 1998 Tom Tromey + + * gdk_imlib.h: Replaced `()' with `(void)'. + +Sun Mar 15 12:34:45 1998 Owen Taylor + + * Makefile.am (INCLUDES): Added GTK_CFLAGS + +1998-02-25 Raja R Harinath + + * Makefile.am (DEFS): Define `SYSTEM_IMRC' too. + +1998-02-25 Federico Mena Quintero + + * misc.c (gdk_imlib_copy_image): The drawable passed to gdk_gc_new + should be the dest drawable, not the base imlib window. This + caused BadMatches all over the place (especially in copy_mask). + (gdk_imlib_copy_mask): Likewise. + +1998-02-24 Raja R Harinath + + * Makefile.am (DEFS): New var. Moved stuff from CFLAGS. + (INCLUDES): New var. + +1998-02-24 Mark Galassi + + * Makefile.am (libgdk_imlib_la_SOURCES): + (lib_LTLIBRARIES): changed gdk_imlib to use the libtool+automake + formalisms. + + * load.c (gdk_imlib_load_image): changed JPEG_PATH to DJPEG_PROG + and removed %s/djpeg, sine DJPEG_PROG is the full program path. + +1998-02-17 Federico Mena Quintero + + * Makefile.in (install): Make directory for config files. + + * configure.in: Fixed ENL_LIB_SUPPORT function for non-existing libraries. + +1998-02-16 Federico Mena Quintero + + * misc.c (gdk_imlib_init): I create a colormap specific to the + visual the base_window will be using. This fixes BadMatch errors + on machines with multiple visual/depth combinations. + +1998-02-17 The Rasterman + + * misc.c (gdk_imlib_init) Fixed visual stuff slightly, and Colormap + creation (so it only does so if the visual for the default and the + chosen visual mismatch), added function calls to retrieve Imlib's + visual and Colormap, plus endianess fixes for network displaying. + +1998-02-17 The Rasterman + + added system imrc config return function + +1998-02-18 The Rasterman + + Fixed load.c - missed a not (!) in an if clause diff --git a/src/gdk_imlib/README b/src/gdk_imlib/README new file mode 100644 index 0000000000..ac167f6462 --- /dev/null +++ b/src/gdk_imlib/README @@ -0,0 +1,29 @@ +------------------------------------------------------------------------------- + I M L I B + 1.4 +------------------------------------------------------------------------------- + +This software is Copyright (C) 1998 By The Rasterman (Carsten Haitzler). I +accept no responsability for anythign this software may or may not do to +your system - you use it completely at your own risk. This software comes +under the LGPL and GPL licences. The library itself is LGPL (all software in +Imlib and gdk_imlib directories) see the COPYING and COPYING.LIB files for +full legal details. + +------------------------------------------------------------------------------- + +If you have picked up a net release of imlib you should be able to +just follow the instructions in the INSTALL file. + +If you are using imlib out of the CVS repository, then you need to +have some extra tools installed, and the configuration process is +lengthier. the HACKING file has all the details for building from a +CVS checkout. + +Imlib will run MARKEDLY better if you get certain libraries. Notably, +libjpeg, libpng, libtiff and libgif. For more information please go look at: + +http://www.labs.redhat.com/imlib/ + +This will give links to everything you need or may want for Imlib's optimal +functionality. diff --git a/src/gdk_imlib/cache.c b/src/gdk_imlib/cache.c new file mode 100644 index 0000000000..561097404d --- /dev/null +++ b/src/gdk_imlib/cache.c @@ -0,0 +1,496 @@ +#define _GNU_SOURCE +#include "../gdk_imlib/gdk_imlib.h" +#include "../gdk_imlib/gdk_imlib_private.h" + +/* uncomment this to compile imlib's cahce with pixmap accounting output */ +/*#define PIXMAP_ACCOUNTING */ + +void +gdirty_pixmaps(GdkImlibImage * im) +{ + struct pixmap_cache *ptr; + + ptr = id->cache.pixmap; + while (ptr) + { + if ((ptr->im == im) && ((!ptr->file) || (!strcmp(im->filename, ptr->file)))) + ptr->dirty = 1; + ptr = ptr->next; + } +} + +void +gdirty_images(GdkImlibImage * im) +{ + struct image_cache *ptr; + + ptr = id->cache.image; + while (ptr) + { + if ((!strcmp(im->filename, ptr->file)) && (im == ptr->im)) + { + ptr->dirty = 1; + return; + } + ptr = ptr->next; + } +} + +void +gfind_pixmap(GdkImlibImage * im, int width, int height, GdkPixmap ** pmap, GdkBitmap ** mask) +{ + struct pixmap_cache *ptr; + + ptr = id->cache.pixmap; + while (ptr) + { + if ((ptr->im == im) && (ptr->width == width) && (ptr->height == height) && + ((!ptr->file) || (!strcmp(im->filename, ptr->file))) && + (!ptr->dirty)) + { + if (ptr->refnum > 0) + ptr->refnum++; + else + { + ptr->refnum++; + id->cache.num_pixmap++; + if (ptr->pmap) + id->cache.used_pixmap -= width * height * id->x.depth; + if (ptr->shape_mask) + id->cache.used_pixmap -= width * height; + if (id->cache.used_pixmap < 0) + { + id->cache.used_pixmap = 0; + fprintf(stderr, "IMLIB: uhoh.. caching problems.... meep meep\n"); + } + } + if (ptr->prev) + { + ptr->prev->next = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + ptr->next = id->cache.pixmap; + ptr->next->prev = ptr; + id->cache.pixmap = ptr; + ptr->prev = NULL; + } + *pmap = ptr->pmap; + *mask = ptr->shape_mask; + return; + } + ptr = ptr->next; + } + *pmap = NULL; + *mask = NULL; +} + +GdkImlibImage * +gfind_image(char *file) +{ + struct image_cache *ptr; + + ptr = id->cache.image; + while (ptr) + { + if ((!strcmp(file, ptr->file)) && (!ptr->dirty)) + { + if (ptr->refnum) + ptr->refnum++; + else + { + ptr->refnum++; + id->cache.num_image++; + id->cache.used_image -= ptr->im->rgb_width * ptr->im->rgb_height * 3; + if (id->cache.used_image < 0) + { + id->cache.used_image = 0; + fprintf(stderr, "IMLIB: uhoh.. caching problems.... meep meep\n"); + } + } + if (ptr->prev) + { + ptr->prev->next = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + ptr->next = id->cache.image; + ptr->next->prev = ptr; + id->cache.image = ptr; + ptr->prev = NULL; + } + return ptr->im; + } + ptr = ptr->next; + } + return NULL; +} + +void +gfree_pixmappmap(GdkPixmap * pmap) +{ + struct pixmap_cache *ptr; + + ptr = id->cache.pixmap; + while (ptr) + { + if ((ptr->pmap == pmap) || (ptr->shape_mask == pmap)) + { + if (ptr->shape_mask == pmap) + return; + if (ptr->refnum > 0) + { + ptr->refnum--; + if (ptr->refnum == 0) + { + id->cache.num_pixmap--; + if (ptr->pmap) + id->cache.used_pixmap += ptr->width * ptr->height * id->x.depth; + if (ptr->shape_mask) + id->cache.used_pixmap += ptr->width * ptr->height; + } + } + return; + } + ptr = ptr->next; + } + gdk_pixmap_unref(pmap); +} + +void +gfree_image(GdkImlibImage * im) +{ + struct image_cache *ptr; + + ptr = id->cache.image; + while (ptr) + { + if (im == ptr->im) + { + if (ptr->refnum) + { + ptr->refnum--; + if (!ptr->refnum) + { + id->cache.num_image--; + id->cache.used_image += ptr->im->rgb_width * ptr->im->rgb_height * 3; + } + } + return; + } + ptr = ptr->next; + } + gnullify_image(im); +} + +void +gflush_image(GdkImlibImage * im) +{ + if (im) + im->cache = 0; +} + +void +gadd_image(GdkImlibImage * im, char *file) +{ + struct image_cache *ptr; + struct image_cache *n; + + if ((!im) || (!file)) + return; + ptr = id->cache.image; + n = malloc(sizeof(struct image_cache)); + + if (!n) + return; + n->prev = NULL; + n->next = ptr; + n->file = malloc(strlen(file) + 1); + if (!n->file) + { + free(n); + return; + } + strcpy(n->file, file); + n->im = im; + n->refnum = 1; + n->dirty = 0; + if (n->next) + n->next->prev = n; + id->cache.image = n; + id->cache.num_image++; +} + +void +gadd_pixmap(GdkImlibImage * im, int width, int height, XImage * xim, XImage * sxim) +{ + struct pixmap_cache *ptr; + struct pixmap_cache *n; + + if (!im) + return; + ptr = id->cache.pixmap; + n = malloc(sizeof(struct pixmap_cache)); + + if (!n) + return; + n->prev = NULL; + n->next = ptr; + n->im = im; + if (im->filename) + { + n->file = malloc(strlen(im->filename) + 1); + if (n->file) + strcpy(n->file, im->filename); + } + else + n->file = NULL; + n->refnum = 1; + n->dirty = 0; + n->width = width; + n->height = height; + n->pmap = im->pixmap; + n->shape_mask = im->shape_mask; + n->xim = xim; + n->sxim = sxim; + if (n->next) + n->next->prev = n; + id->cache.pixmap = n; + id->cache.num_pixmap++; +} + +void +gclean_caches() +{ + { + struct image_cache *ptr = NULL; + struct image_cache *pptr = NULL; + struct image_cache *last = NULL; + int newlast; + + /* find the back of the list */ + ptr = id->cache.image; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + newlast = 0; + ptr = last; + /* remove all images that are tagged non-cachable, and have 0 */ + /* references , even if the cache has spare room. */ + while (ptr) + { + if (!ptr->refnum) + { + if (!ptr->im->cache) + { + if (ptr == last) + newlast = 1; + id->cache.used_image -= ptr->im->rgb_width * ptr->im->rgb_height * 3; + gnullify_image(ptr->im); + if (pptr) + ptr = pptr->prev; + if (ptr->prev) + ptr->prev->next = ptr->next; + else + id->cache.image = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + if (ptr->file) + free(ptr->file); + free(ptr); + ptr = NULL; + } + } + if (ptr) + ptr = ptr->prev; + if (newlast) + { + last = NULL; + ptr = id->cache.image; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + newlast = 0; + ptr = last; + } + } + /* find the back of the list */ + ptr = id->cache.image; + last = NULL; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + newlast = 0; + ptr = last; + /* while the amount of data in the cache is greater than the set */ + /* amount, delete the last entry (last used) from the unreferenced */ + /* cached 24-bit images */ + while (id->cache.used_image > id->cache.size_image) + { + while (ptr) + { + if (ptr->refnum < 1) + { + if (ptr == last) + newlast = 1; + id->cache.used_image -= ptr->im->rgb_width * ptr->im->rgb_height * 3; + gnullify_image(ptr->im); + if (ptr->prev) + ptr->prev->next = ptr->next; + else + id->cache.image = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + if (ptr->file) + free(ptr->file); + free(ptr); + ptr = NULL; + break; + } + if (ptr) + ptr = ptr->prev; + } + if (newlast) + { + last = NULL; + ptr = id->cache.image; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + newlast = 0; + ptr = last; + } + if (!ptr) + break; + } + } + { + struct pixmap_cache *ptr; + struct pixmap_cache *last; + int newlast; + +#ifdef PIXMAP_ACCOUNTING + int total, total2, num, num2; + + printf("--------- Pixmap cashe zise %i / %i with %i pixmaps referenced\n", + id->cache.used_pixmap, id->cache.size_pixmap, + id->cache.num_pixmap); + ptr = id->cache.pixmap; + total = 0; + total2 = 0; + num = 0; + num2 = 0; + while (ptr) + { + printf("Pmap for file %s REFNUM %3i SIZE %4ix%4i PMAP %8x MASK %8x\n", + ptr->file, ptr->refnum, ptr->width, ptr->height, ptr->pmap, + ptr->shape_mask); + if (ptr->refnum > 0) + { + total += (ptr->width * ptr->height * id->x.depth); + if (ptr->shape_mask) + total += (ptr->width * ptr->height); + num++; + } + else + { + total2 += (ptr->width * ptr->height * id->x.depth); + if (ptr->shape_mask) + total2 += (ptr->width * ptr->height); + num2++; + } + ptr = ptr->next; + } + printf("Accounting Data:\n"); + printf("*** total pixmap's in cache %i with %i pixmaps\n", + total, num); + printf("*** total unreffed pixmap's in cache %i with %i pixmaps\n\n", + total2, num2); +#endif + /* find the back of the list */ + ptr = id->cache.pixmap; + last = NULL; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + newlast = 0; + ptr = last; + /* while the amount of data in the cache is greater than the set */ + /* amount, delete the last entry (last used) from the unreferenced */ + /* cached pixmaps */ + while (id->cache.used_pixmap > id->cache.size_pixmap) + { + while (ptr) + { + if (ptr->refnum < 1) + { + if (ptr == last) + newlast = 1; + if (ptr->pmap) + id->cache.used_pixmap -= ptr->width * ptr->height * id->x.depth; + if (ptr->shape_mask) + id->cache.used_pixmap -= ptr->width * ptr->height; + if (ptr->pmap) + gdk_pixmap_unref(ptr->pmap); + if (ptr->shape_mask) + gdk_pixmap_unref(ptr->shape_mask); + if (ptr->xim) + XDestroyImage(ptr->xim); + if (ptr->sxim) + XDestroyImage(ptr->sxim); + if (ptr->prev) + ptr->prev->next = ptr->next; + else + id->cache.pixmap = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + if (ptr->file) + free(ptr->file); + free(ptr); + ptr = NULL; + break; + } + if (ptr) + ptr = ptr->prev; + } + if (newlast) + { + last = NULL; + ptr = id->cache.pixmap; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + newlast = 0; + ptr = last; + } + if (!ptr) + break; + } + } +} + +void +gnullify_image(GdkImlibImage * im) +{ + if (!im) + return; + if (im->rgb_data) + free(im->rgb_data); + if (im->alpha_data) + free(im->alpha_data); + if (im->pixmap) + gfree_pixmappmap(im->pixmap); + if (im->filename) + free(im->filename); + free(im); +} diff --git a/src/gdk_imlib/colors.c b/src/gdk_imlib/colors.c new file mode 100644 index 0000000000..768440dc8f --- /dev/null +++ b/src/gdk_imlib/colors.c @@ -0,0 +1,113 @@ +#define _GNU_SOURCE +#include "../gdk_imlib/gdk_imlib.h" +#include "../gdk_imlib/gdk_imlib_private.h" + +void +g_PaletteAlloc(int num, int *cols) +{ + XColor xcl; + int i; + int r, g, b; + + if (id->palette) + free(id->palette); + id->palette = malloc(sizeof(GdkImlibColor) * num); + if (id->palette_orig) + free(id->palette_orig); + id->palette_orig = malloc(sizeof(GdkImlibColor) * num); + for (i = 0; i < num; i++) + { + r = cols[(i * 3) + 0]; + g = cols[(i * 3) + 1]; + b = cols[(i * 3) + 2]; + xcl.red = (unsigned short)((r << 8) | (r)); + xcl.green = (unsigned short)((g << 8) | (g)); + xcl.blue = (unsigned short)((b << 8) | (b)); + xcl.flags = DoRed | DoGreen | DoBlue; + XAllocColor(id->x.disp, id->x.root_cmap, &xcl); + id->palette[i].r = xcl.red >> 8; + id->palette[i].g = xcl.green >> 8; + id->palette[i].b = xcl.blue >> 8; + id->palette[i].pixel = xcl.pixel; + id->palette_orig[i].r = r; + id->palette_orig[i].g = g; + id->palette_orig[i].b = b; + id->palette_orig[i].pixel = xcl.pixel; + } + id->num_colors = num; +} + +gint +gdk_imlib_load_colors(char *file) +{ + FILE *f; + char s[256]; + int i; + int pal[768]; + int r, g, b; + int rr, gg, bb; + + f = fopen(file, "r"); + if (!f) + { + fprintf(stderr, "GImLib ERROR: Cannot find palette file %s\n", file); + return 0; + } + i = 0; + while (fgets(s, 256, f)) + { + if (s[0] == '0') + { + sscanf(s, "%x %x %x", &r, &g, &b); + if (r < 0) + r = 0; + if (r > 255) + r = 255; + if (g < 0) + g = 0; + if (g > 255) + g = 255; + if (b < 0) + b = 0; + if (b > 255) + b = 255; + pal[i++] = r; + pal[i++] = g; + pal[i++] = b; + } + if (i >= 768) + break; + } + fclose(f); + g_PaletteAlloc((i / 3), pal); + if (id->fast_rgb) + free(id->fast_rgb); + id->fast_rgb = malloc(sizeof(int) * 32 * 32 * 32); + + for (r = 0; r < 32; r++) + { + for (g = 0; g < 32; g++) + { + for (b = 0; b < 32; b++) + { + rr = (r << 3) | (r >> 2); + gg = (g << 3) | (g >> 2); + bb = (b << 3) | (b >> 2); + INDEX_RGB(r, g, b) = gindex_best_color_match(&rr, &gg, &bb); + } + } + } + return 1; +} + +void +gdk_imlib_free_colors() +{ + int i; + unsigned long pixels[256]; + + for (i = 0; i < id->num_colors; i++) + pixels[i] = id->palette[i].pixel; + XFreeColors(id->x.disp, id->x.root_cmap, pixels, id->num_colors, 0); + id->num_colors = 0; +} diff --git a/src/gdk_imlib/config.h b/src/gdk_imlib/config.h new file mode 100644 index 0000000000..225d595547 --- /dev/null +++ b/src/gdk_imlib/config.h @@ -0,0 +1,2 @@ +#undef PACKAGE +#undef VERSION diff --git a/src/gdk_imlib/gdk_imlib.h b/src/gdk_imlib/gdk_imlib.h new file mode 100644 index 0000000000..6513b1873f --- /dev/null +++ b/src/gdk_imlib/gdk_imlib.h @@ -0,0 +1,78 @@ + +#ifndef __GDK_IMLIB_H__ +#define __GDK_IMLIB_H__ + +/* we need this funny include path, because the working directory when */ +/* including this might actually be ../gdk/ instead of . */ +#include "../gdk_imlib/gdk_imlib_types.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + void gdk_imlib_init(void); + void gdk_imlib_init_params(GdkImlibInitParams * p); + gint gdk_imlib_get_render_type(void); + void gdk_imlib_set_render_type(gint rend_type); + gint gdk_imlib_load_colors(char *file); + GdkImlibImage *gdk_imlib_load_image(char *file); + gint gdk_imlib_best_color_match(gint * r, gint * g, gint * b); + gint gdk_imlib_render(GdkImlibImage * image, gint width, gint height); + GdkPixmap *gdk_imlib_copy_image(GdkImlibImage * image); + GdkBitmap *gdk_imlib_copy_mask(GdkImlibImage * image); + GdkPixmap *gdk_imlib_move_image(GdkImlibImage * image); + GdkBitmap *gdk_imlib_move_mask(GdkImlibImage * image); + void gdk_imlib_destroy_image(GdkImlibImage * image); + void gdk_imlib_kill_image(GdkImlibImage * image); + void gdk_imlib_free_colors(void); + void gdk_imlib_free_pixmap(GdkPixmap * pixmap); + void gdk_imlib_free_bitmap(GdkBitmap * bitmap); + void gdk_imlib_get_image_border(GdkImlibImage * image, GdkImlibBorder * border); + void gdk_imlib_set_image_border(GdkImlibImage * image, GdkImlibBorder * border); + void gdk_imlib_get_image_shape(GdkImlibImage * image, GdkImlibColor * color); + void gdk_imlib_set_image_shape(GdkImlibImage * image, GdkImlibColor * color); + gint gdk_imlib_save_image_to_eim(GdkImlibImage * image, char *file); + gint gdk_imlib_add_image_to_eim(GdkImlibImage * image, char *file); + gint gdk_imlib_save_image_to_ppm(GdkImlibImage * image, char *file); + gint gdk_imlib_load_file_to_pixmap(char *filename, GdkPixmap ** pmap, GdkBitmap ** mask); + void gdk_imlib_set_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_set_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_set_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_set_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_get_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_get_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_get_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_get_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_set_image_red_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_set_image_green_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_set_image_blue_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_get_image_red_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_get_image_green_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_get_image_blue_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_apply_modifiers_to_rgb(GdkImlibImage * im); + void gdk_imlib_changed_image(GdkImlibImage * im); + void gdk_imlib_apply_image(GdkImlibImage * im, GdkWindow * p); + void gdk_imlib_paste_image(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h); + void gdk_imlib_paste_image_border(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h); + void gdk_imlib_flip_image_horizontal(GdkImlibImage * im); + void gdk_imlib_flip_image_vertical(GdkImlibImage * im); + void gdk_imlib_rotate_image(GdkImlibImage * im, gint d); + GdkImlibImage *gdk_imlib_create_image_from_data(unsigned char *data, unsigned char *alpha, gint w, gint h); + GdkImlibImage *gdk_imlib_clone_image(GdkImlibImage * im); + GdkImlibImage *gdk_imlib_clone_scaled_image(GdkImlibImage * im, int w, int h); + gint gdk_imlib_get_fallback(void); + void gdk_imlib_set_fallback(gint fallback); + GdkVisual *gdk_imlib_get_visual(void); + GdkColormap *gdk_imlib_get_colormap(void); + gchar *gdk_imlib_get_sysconfig(void); + GdkImlibImage *gdk_imlib_create_image_from_xpm_data(char **data); + gint gdk_imlib_data_to_pixmap(char **data, GdkPixmap ** pmap, GdkBitmap ** mask); + void gdk_imlib_crop_image(GdkImlibImage * im, gint x, gint y, gint w, gint h); + gint gdk_imlib_save_image(GdkImlibImage * im, char *file, GdkImlibSaveInfo * info); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/src/gdk_imlib/gdk_imlib_private.h b/src/gdk_imlib/gdk_imlib_private.h new file mode 100644 index 0000000000..94ba61c187 --- /dev/null +++ b/src/gdk_imlib/gdk_imlib_private.h @@ -0,0 +1,226 @@ +#ifdef _HAVE_STRING_H +#include +#elif _HAVE_STRINGS_H +#include +#endif + +#ifndef CONVERT_PATH +#define CONVERT_PATH "/usr/X11/bin" +#endif + +#ifndef NETPBM_PATH +#define NETPBM_PATH "/usr/local/bin" +#endif + +#ifndef CJPEG_PROG +#define CJPEG_PROG "/usr/bin/cjpeg" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _HAVE_STRING_H +#include +#elif _HAVE_STRINGS_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_LIBJPEG +#include +#endif +#ifdef HAVE_LIBPNG +#include <../png/png.h> +#endif +#ifdef HAVE_LIBTIFF +#include +#endif +#ifdef HAVE_LIBGIF +#include +#endif + +#define BYTE_ORD_24_RGB 0 +#define BYTE_ORD_24_RBG 1 +#define BYTE_ORD_24_BRG 2 +#define BYTE_ORD_24_BGR 3 +#define BYTE_ORD_24_GRB 4 +#define BYTE_ORD_24_GBR 5 + +struct image_cache + { + gchar *file; + GdkImlibImage *im; + gint refnum; + gchar dirty; + struct image_cache *prev; + struct image_cache *next; + }; + +struct pixmap_cache + { + GdkImlibImage *im; + gchar *file; + gchar dirty; + gint width, height; + GdkPixmap *pmap; + GdkBitmap *shape_mask; + XImage *xim, *sxim; + gint refnum; + struct pixmap_cache *prev; + struct pixmap_cache *next; + }; + +typedef struct _xdata + { + Display *disp; + gint screen; + Window root; + Visual *visual; + gint depth; + gint render_depth; + Colormap root_cmap; + gchar shm; + gchar shmp; + gint shm_event; + XImage *last_xim; + XImage *last_sxim; + XShmSegmentInfo last_shminfo; + XShmSegmentInfo last_sshminfo; + Window base_window; + GdkWindow *gdk_win; + GdkColormap *gdk_cmap; + } +Xdata; + +typedef struct _imlibdata + { + gint num_colors; + GdkImlibColor *palette; + GdkImlibColor *palette_orig; + unsigned char *fast_rgb; + gint *fast_err; + gint *fast_erg; + gint *fast_erb; + gint render_type; + gint max_shm; + Xdata x; + gint byte_order; + struct _cache + { + gchar on_image; + gint size_image; + gint num_image; + gint used_image; + struct image_cache *image; + gchar on_pixmap; + gint size_pixmap; + gint num_pixmap; + gint used_pixmap; + struct pixmap_cache *pixmap; + } + cache; + gchar fastrend; + gchar hiq; + GdkImlibColorModifier mod, rmod, gmod, bmod; + unsigned char rmap[256], gmap[256], bmap[256]; + gchar fallback; + gchar ordered_dither; + } +ImlibData; + +extern ImlibData *id; + +gint gindex_best_color_match(gint * r, gint * g, gint * b); + +void gdirty_pixmaps(GdkImlibImage * im); +void gdirty_images(GdkImlibImage * im); +void gfind_pixmap(GdkImlibImage * im, int width, int height, GdkPixmap ** pmap, GdkBitmap ** mask); +GdkImlibImage *gfind_image(char *file); +void gfree_pixmappmap(GdkPixmap * pmap); +void gfree_image(GdkImlibImage * im); +void gflush_image(GdkImlibImage * im); +void gadd_image(GdkImlibImage * im, char *file); +void gadd_pixmap(GdkImlibImage * im, int width, int height, XImage * xim, XImage * sxim); +void gclean_caches(); +void gnullify_image(GdkImlibImage * im); + +/* char *g_SplitID(char *file); */ +char *g_GetExtension(char *file); + +#ifdef HAVE_LIBJPEG +unsigned char *g_LoadJPEG(FILE * f, int *w, int *h); + +#endif /* HAVE_LIBJPEG */ +#ifdef HAVE_LIBPNG +unsigned char *g_LoadPNG(FILE * f, int *w, int *h, int *t); + +#endif /* HAVE_LIBPNG */ +#ifdef HAVE_LIBTIFF +unsigned char *g_LoadTIFF(char *f, int *w, int *h, int *t); + +#endif /* HAVE_LIBTIFF */ +#ifdef HAVE_LIBGIF +unsigned char *g_LoadGIF(char *f, int *w, int *h, int *t); + +#endif /* HAVE_LIBGIF */ +unsigned char *g_LoadXPM(char *f, int *w, int *h, int *t); +unsigned char *g_LoadPPM(FILE * f, int *w, int *h); + +/* +static int gispnm(char *file); +static int gisjpeg(char *file); +static int gispng(char *file); +static int gistiff(char *file); +static int giseim(char *file); +static int gisgif(char *file); +static int gisxpm(char *file); +*/ + +GdkPixmap *gdk_imlib_pixmap_foreign_new(gint width, gint height, gint depth, Pixmap pmap); + +void gcalc_map_tables(GdkImlibImage * im); + +void g_PaletteAlloc(int num, int *cols); + +FILE *open_helper(const char *, const char *, const char *); +int close_helper(FILE *); + +#define INDEX_RGB(r,g,b) id->fast_rgb[(r<<10)|(g<<5)|(b)] +#define COLOR_INDEX(i) id->palette[i].pixel +#define COLOR_RGB(r,g,b) id->palette[INDEX_RGB(r,g,b)].pixel +#define ERROR_RED(rr,i) rr-id->palette[i].r; +#define ERROR_GRN(gg,i) gg-id->palette[i].g; +#define ERROR_BLU(bb,i) bb-id->palette[i].b; + +#define DITHER_ERROR(Der1,Der2,Dex,Der,Deg,Deb) \ +ter=&(Der1[Dex]);\ +(*ter)+=(Der*7)>>4;ter++;\ +(*ter)+=(Deg*7)>>4;ter++;\ +(*ter)+=(Deb*7)>>4;\ +ter=&(Der2[Dex-6]);\ +(*ter)+=(Der*3)>>4;ter++;\ +(*ter)+=(Deg*3)>>4;ter++;\ +(*ter)+=(Deb*3)>>4;ter++;\ +(*ter)+=(Der*5)>>4;ter++;\ +(*ter)+=(Deg*5)>>4;ter++;\ +(*ter)+=(Deb*5)>>4;ter++;\ +(*ter)+=Der>>4;ter++;\ +(*ter)+=Deg>>4;ter++;\ +(*ter)+=Deb>>4; diff --git a/src/gdk_imlib/gdk_imlib_types.h b/src/gdk_imlib/gdk_imlib_types.h new file mode 100644 index 0000000000..fa3d894080 --- /dev/null +++ b/src/gdk_imlib/gdk_imlib_types.h @@ -0,0 +1,101 @@ +#include + +#ifndef SYSTEM_IMRC +#define SYSTEM_IMRC "/etc/imrc" +#endif /* endef SYSTEM_IMRC */ + +typedef struct _GdkImlibBorder + { + gint left, right; + gint top, bottom; + } +GdkImlibBorder; + +typedef struct _GdkImlibColor + { + gint r, g, b; + gint pixel; + } +GdkImlibColor; + +typedef struct _GdkImlibColorModifier + { + gint gamma; + gint brightness; + gint contrast; + } +GdkImlibColorModifier; + +typedef struct _GdkImlibImage + { + gint rgb_width, rgb_height; + unsigned char *rgb_data; + unsigned char *alpha_data; + gchar *filename; +/* the below information is private */ + gint width, height; + GdkImlibColor shape_color; + GdkImlibBorder border; + GdkPixmap *pixmap; + GdkBitmap *shape_mask; + gchar cache; + GdkImlibColorModifier mod, rmod, gmod, bmod; + unsigned char rmap[256], gmap[256], bmap[256]; + } +GdkImlibImage; + +typedef struct _GdkImlibSaveInfo + { + int quality; + int scaling; + int xjustification; + int yjustification; + int page_size; + char color; + } +GdkImlibSaveInfo; + +typedef struct _GdkImlibInitParams + { + int flags; + int visualid; + char *palettefile; + char sharedmem; + char sharedpixmaps; + char paletteoverride; + char remap; + char fastrender; + char hiquality; + char dither; + int imagecachesize; + int pixmapcachesize; + } +GdkImlibInitParams; + +#define PARAMS_VISUALID 1<<0 +#define PARAMS_PALETTEFILE 1<<1 +#define PARAMS_SHAREDMEM 1<<2 +#define PARAMS_SHAREDPIXMAPS 1<<3 +#define PARAMS_PALETTEOVERRIDE 1<<4 +#define PARAMS_REMAP 1<<5 +#define PARAMS_FASTRENDER 1<<6 +#define PARAMS_HIQUALITY 1<<7 +#define PARAMS_DITHER 1<<8 +#define PARAMS_IMAGECACHESIZE 1<<9 +#define PARAMS_PIXMAPCACHESIZE 1<<10 + +#define PAGE_SIZE_EXECUTIVE 0 +#define PAGE_SIZE_LETTER 1 +#define PAGE_SIZE_LEGAL 2 +#define PAGE_SIZE_A4 3 +#define PAGE_SIZE_A3 4 +#define PAGE_SIZE_A5 5 +#define PAGE_SIZE_FOLIO 6 + +#define RT_PLAIN_PALETTE 0 +#define RT_PLAIN_PALETTE_FAST 1 +#define RT_DITHER_PALETTE 2 +#define RT_DITHER_PALETTE_FAST 3 +#define RT_PLAIN_TRUECOL 4 +/* a special high-quality renderer for people with 15 and 16bpp that dithers */ +#define RT_DITHER_TRUECOL 5 diff --git a/src/gdk_imlib/globals.c b/src/gdk_imlib/globals.c new file mode 100644 index 0000000000..ab506d6815 --- /dev/null +++ b/src/gdk_imlib/globals.c @@ -0,0 +1,6 @@ + +#define _GNU_SOURCE +#include "../gdk_imlib/gdk_imlib.h" +#include "../gdk_imlib/gdk_imlib_private.h" + +ImlibData *id; diff --git a/src/gdk_imlib/load.c b/src/gdk_imlib/load.c new file mode 100644 index 0000000000..ef5913da87 --- /dev/null +++ b/src/gdk_imlib/load.c @@ -0,0 +1,1498 @@ + +#define _GNU_SOURCE +#include "../gdk_imlib/config.h" + +#include "../gdk_imlib/gdk_imlib.h" +#include "../gdk_imlib/gdk_imlib_private.h" + +/* Split the ID - damages input */ + +static char * +g_SplitID(char *file) +{ + char *p = strrchr(file, ':'); + + if (p == NULL) + return ""; + else + { + *p++ = 0; + return p; + } +} + +/* + * Doesn't damage the input + */ + +char * +g_GetExtension(char *file) +{ + char *p = strrchr(file, '.'); + + if (p == NULL) + return ""; + else + return p + 1; +} + +#ifdef HAVE_LIBJPEG +unsigned char * +g_LoadJPEG(FILE * f, int *w, int *h) +{ + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + unsigned char *data, *line[16], *ptr; + int x, y, i; + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, f); + jpeg_read_header(&cinfo, TRUE); + cinfo.do_fancy_upsampling = FALSE; + cinfo.do_block_smoothing = FALSE; + jpeg_start_decompress(&cinfo); + *w = cinfo.output_width; + *h = cinfo.output_height; + data = malloc(*w ** h * 3); + if (!data) + { + jpeg_destroy_decompress(&cinfo); + return NULL; + } + ptr = data; + + if (cinfo.rec_outbuf_height > 16) + { + fprintf(stderr, "gdk_imlib ERROR: JPEG uses line buffers > 16. Cannot load.\n"); + return NULL; + } + if (cinfo.output_components == 3) + { + for (y = 0; y < *h; y += cinfo.rec_outbuf_height) + { + for (i = 0; i < cinfo.rec_outbuf_height; i++) + { + line[i] = ptr; + ptr += *w * 3; + } + jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); + } + } + else if (cinfo.output_components == 1) + { + for (i = 0; i < cinfo.rec_outbuf_height; i++) + { + if ((line[i] = malloc(*w)) == NULL) + { + int t = 0; + + for (t = 0; t < i; t++) + free(line[t]); + jpeg_destroy_decompress(&cinfo); + return NULL; + } + } + for (y = 0; y < *h; y += cinfo.rec_outbuf_height) + { + jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); + for (i = 0; i < cinfo.rec_outbuf_height; i++) + { + for (x = 0; x < *w; x++) + { + *ptr++ = line[i][x]; + *ptr++ = line[i][x]; + *ptr++ = line[i][x]; + } + } + } + for (i = 0; i < cinfo.rec_outbuf_height; i++) + free(line[i]); + } + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + return data; +} +#endif /* HAVE_LIBJPEG */ + +#ifdef HAVE_LIBPNG +unsigned char * +g_LoadPNG(FILE * f, int *w, int *h, int *t) +{ + png_structp png_ptr; + png_infop info_ptr; + unsigned char *data, *ptr, **lines, *ptr2, r, g, b, a; + int i, x, y, transp, bit_depth, color_type, interlace_type; + png_uint_32 *ww, *hh; + + /* Init PNG Reader */ + transp = 0; + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + return NULL; + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, NULL, NULL); + return NULL; + } + + if (setjmp(png_ptr->jmpbuf)) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + + if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + png_init_io(png_ptr, f); + /* Read Header */ + png_read_info(png_ptr, info_ptr); + ww = (png_uint_32 *) w; + hh = (png_uint_32 *) h; + png_get_IHDR(png_ptr, info_ptr, ww, hh, &bit_depth, &color_type, &interlace_type, + NULL, NULL); + /* Setup Translators */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_expand(png_ptr); + png_set_strip_16(png_ptr); + png_set_packing(png_ptr); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_expand(png_ptr); + png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); + *w = info_ptr->width; + *h = info_ptr->height; + data = malloc(*w ** h * 3); + if (!data) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + lines = (unsigned char **)malloc(*h * sizeof(unsigned char *)); + + if (lines == NULL) + { + free(data); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + for (i = 0; i < *h; i++) + { + if ((lines[i] = malloc(*w * (sizeof(unsigned char) * 4))) == NULL) + { + int n; + + free(data); + for (n = 0; n < i; n++) + free(lines[n]); + free(lines); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + } + png_read_image(png_ptr, lines); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + ptr = data; + if (color_type == PNG_COLOR_TYPE_GRAY) + { + for (y = 0; y < *h; y++) + { + ptr2 = lines[y]; + for (x = 0; x < *w; x++) + { + r = *ptr2++; + *ptr++ = r; + *ptr++ = r; + *ptr++ = r; + } + } + } + else + { + for (y = 0; y < *h; y++) + { + ptr2 = lines[y]; + for (x = 0; x < *w; x++) + { + r = *ptr2++; + g = *ptr2++; + b = *ptr2++; + a = *ptr2++; + if (a < 128) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + transp = 1; + } + else + { + if ((r == 255) && (g == 0) && (b == 255)) + r = 254; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + } + for (i = 0; i < *h; i++) + free(lines[i]); + free(lines); + *t = transp; + return data; +} +#endif /* HAVE_LIBPNG */ + +#ifdef HAVE_LIBTIFF +unsigned char * +g_LoadTIFF(char *f, int *w, int *h, int *t) +{ + TIFF *tif; + unsigned char *data, *ptr, r, g, b, a; + int x, y; + uint32 ww, hh, *rast, *tptr; + size_t npix; + int istransp; + + istransp = 0; + if (!f) + return NULL; + + tif = TIFFOpen(f, "r"); + if (!tif) + return NULL; + + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &ww); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &hh); + npix = ww * hh; + *w = (int)ww; + *h = (int)hh; + rast = (uint32 *) _TIFFmalloc(npix * sizeof(uint32)); + if (!rast) + { + TIFFClose(tif); + return NULL; + } + data = NULL; + if (TIFFReadRGBAImage(tif, ww, hh, rast, 0)) + { + data = (unsigned char *)malloc(*w ** h * 3); + if (!data) + { + _TIFFfree(rast); + TIFFClose(tif); + return NULL; + } + ptr = data; + for (y = 0; y < *h; y++) + { + tptr = rast; + tptr += ((*h - y - 1) ** w); + for (x = 0; x < *w; x++) + { + a = TIFFGetA(*tptr); + b = TIFFGetB(*tptr); + g = TIFFGetG(*tptr); + r = TIFFGetR(*tptr); + tptr++; + if (a < 128) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + istransp = 1; + } + else + { + if ((r == 255) && (g == 0) && (b == 255)) + r = 254; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + } + _TIFFfree(rast); + TIFFClose(tif); + *t = istransp; + return data; +} + +#endif /* HAVE_LIBTIFF */ + +#ifdef HAVE_LIBGIF +unsigned char * +g_LoadGIF(char *f, int *w, int *h, int *t) +{ + unsigned char *data, *ptr; + GifFileType *gif; + GifRowType *rows; + GifRecordType rec; + ColorMapObject *cmap; + int i, j, done, bg, csize, r, g, b; + int intoffset[] = + {0, 4, 2, 1}; + int intjump[] = + {8, 8, 4, 2}; + int istransp, transp; + + done = 0; + istransp = 0; + gif = DGifOpenFileName(f); + if (!gif) + return NULL; + + do + { + DGifGetRecordType(gif, &rec); + if ((rec == IMAGE_DESC_RECORD_TYPE) && (!done)) + { + DGifGetImageDesc(gif); + *w = gif->Image.Width; + *h = gif->Image.Height; + rows = malloc(*h * sizeof(GifRowType *)); + if (!rows) + { + DGifCloseFile(gif); + return NULL; + } + data = malloc(*w ** h * 3); + if (!data) + { + DGifCloseFile(gif); + free(rows); + return NULL; + } + for (i = 0; i < *h; i++) + rows[i] = NULL; + for (i = 0; i < *h; i++) + { + rows[i] = malloc(*w * sizeof(GifPixelType)); + if (!rows[i]) + { + DGifCloseFile(gif); + for (i = 0; i < *h; i++) + if (rows[i]) + free(rows[i]); + free(rows); + free(data); + return NULL; + } + } + if (gif->Image.Interlace) + { + for (i = 0; i < 4; i++) + { + for (j = intoffset[i]; j < *h; j += intjump[i]) + DGifGetLine(gif, rows[j], *w); + } + } + else + { + for (i = 0; i < *h; i++) + DGifGetLine(gif, rows[i], *w); + } + done = 1; + } + else if (rec == EXTENSION_RECORD_TYPE) + { + int ext_code; + GifByteType *ext; + + DGifGetExtension(gif, &ext_code, &ext); + if (ext) + { + if ((ext[1] & 1)) + { + istransp = 1; + transp = (int)ext[4]; + } + } + do + { + DGifGetExtensionNext(gif, &ext); + } + while (ext); + } + } + while (rec != TERMINATE_RECORD_TYPE); + bg = gif->SBackGroundColor; + cmap = (gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap); + csize = cmap->ColorCount; + ptr = data; + if (!istransp) + { + for (i = 0; i < *h; i++) + { + for (j = 0; j < *w; j++) + { + r = cmap->Colors[rows[i][j]].Red; + g = cmap->Colors[rows[i][j]].Green; + b = cmap->Colors[rows[i][j]].Blue; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + else + { + for (i = 0; i < *h; i++) + { + for (j = 0; j < *w; j++) + { + if (rows[i][j] == transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + r = cmap->Colors[rows[i][j]].Red; + g = cmap->Colors[rows[i][j]].Green; + b = cmap->Colors[rows[i][j]].Blue; + if (r == 255 && g == 0 && b == 255) + r = 254; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + } + DGifCloseFile(gif); + for (i = 0; i < *h; i++) + free(rows[i]); + free(rows); + *t = istransp; + return data; +} + +#endif /* HAVE_LIBGIF */ + +unsigned char * +g_LoadXPM(char *f, int *w, int *h, int *t) +{ + FILE *file; + unsigned char *data, *ptr; + int pc, c, i, j, k, ncolors, cpp, comment, transp, quote, + context, len, /*token,*/ done; + char line[65536], s[65536], tok[65536], col[65536]; + XColor xcol; + struct _cmap + { + char str[8]; + char transp; + int r, g, b; + } + *cmap; + int lookup[128][128]; + + i = 0; + j = 0; + + transp = 0; + done = 0; + cmap = NULL; + + file = fopen(f, "r"); + if (!file) + return NULL; + + *w = 10; + *h = 10; + + ptr = NULL; + data = NULL; + c = ' '; + comment = 0; + quote = 0; + context = 0; + + while (!done) + { + pc = c; + c = fgetc(file); + if (c == EOF) + break; + if (!quote) + { + if (pc == '/' && c == '*') + comment = 1; + else if (pc == '*' && c == '/' && comment) + comment = 0; + } + if (!comment) + { + if (!quote && c == '"') + { + quote = 1; + i = 0; + } + else if (quote && c == '"') + { + line[i] = 0; + quote = 0; + if (context == 0) + { + /* Header */ + sscanf(line, "%i %i %i %i", w, h, &ncolors, &cpp); + if (cpp > 7) + { + fprintf(stderr, "gdk_imlib ERROR: XPM files with characters per pixel > 7 not supported\n"); + return NULL; + } + if (*w > 32767) + { + fprintf(stderr, "gdk_imlib ERROR: Image width > 32767 pixels for file\n"); + return NULL; + } + if (*h > 32767) + { + fprintf(stderr, "gdk_imlib ERROR: Image height > 32767 pixels for file\n"); + return NULL; + } + cmap = malloc(sizeof(struct _cmap) * ncolors); + + if (!cmap) + return NULL; + data = malloc(*w ** h * 3); + if (!data) + { + free(cmap); + return NULL; + } + ptr = data; + j = 0; + context++; + } + else if (context == 1) + { + /* Color Table */ + if (j < ncolors) + { + /* int colptr = 0; not used */ + int slen; + + tok[0] = 0; + col[0] = 0; + s[0] = 0; + len = strlen(line); + strncpy(cmap[j].str, line, cpp); + cmap[j].str[cpp] = 0; + cmap[j].r = -1; + cmap[j].transp = 0; + for (k = cpp; k < len; k++) + { + if (line[k] != ' ') + { + s[0] = 0; + sscanf(&line[k], "%65535s", s); + slen = strlen(s); + k += slen; + if ((!strcmp(s, "m")) || (!strcmp(s, "s")) || + (!strcmp(s, "g4")) || (!strcmp(s, "g")) || + (!strcmp(s, "c")) || (k >= len)) + { + if (k >= len) + { + if (col[0]) + strcat(col, " "); + strcat(col, s); + } + if (col[0]) + { + if (!strcasecmp(col, "none")) + { + transp = 1; + cmap[j].transp = 1; + } + else + { + if ((cmap[j].r < 0) || + (!strcmp(tok, "c"))) + { + XParseColor(id->x.disp, + id->x.root_cmap, + col, &xcol); + cmap[j].r = xcol.red >> 8; + cmap[j].g = xcol.green >> 8; + cmap[j].b = xcol.blue >> 8; + if ((cmap[j].r == 255) && + (cmap[j].g == 0) && + (cmap[j].b == 255)) + cmap[j].r = 254; + } + } + } + strcpy(tok, s); + col[0] = 0; + } + else + { + if (col[0]) + strcat(col, " "); + strcat(col, s); + } + } + } + } + j++; + if (j >= ncolors) + { + if (cpp == 1) + for (i = 0; i < ncolors; i++) + lookup[(int)cmap[i].str[0]][(int)cmap[i].str[1]] = i; + if (cpp == 2) + for (i = 0; i < ncolors; i++) + lookup[(int)cmap[i].str[0]][(int)cmap[i].str[1]] = i; + context++; + } + } + else + { + /* Image Data */ + i = 0; + if (cpp == 0) + { + /* Chars per pixel = 0? well u never know */ + } + if (cpp == 1) + { + if (transp) + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + col[0] = line[i]; + if (cmap[lookup[(int)col[0]][0]].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].b; + } + } + } + else + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + col[0] = line[i]; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].b; + } + } + } + else if (cpp == 2) + { + if (transp) + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + col[0] = line[i++]; + col[1] = line[i]; + if (cmap[lookup[(int)col[0]][(int)col[1]]].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].b; + } + } + } + else + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + col[0] = line[i++]; + col[1] = line[i]; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].b; + } + } + } + else + { + if (transp) + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + for (j = 0; j < cpp; j++, i++) + { + col[j] = line[i]; + } + col[j] = 0; + i--; + for (j = 0; j < ncolors; j++) + { + if (!strcmp(col, cmap[j].str)) + { + if (cmap[j].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[j].r; + *ptr++ = (unsigned char)cmap[j].g; + *ptr++ = (unsigned char)cmap[j].b; + } + j = ncolors; + } + } + } + } + else + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + for (j = 0; j < cpp; j++, i++) + { + col[j] = line[i]; + } + col[j] = 0; + i--; + for (j = 0; j < ncolors; j++) + { + if (!strcmp(col, cmap[j].str)) + { + *ptr++ = (unsigned char)cmap[j].r; + *ptr++ = (unsigned char)cmap[j].g; + *ptr++ = (unsigned char)cmap[j].b; + j = ncolors; + } + } + } + } + } + } + } + } + /* Scan in line from XPM file (limit line length 65k) */ + if (i < 65536) + { + if ((!comment) && (quote) && (c != '"')) + { + line[i++] = c; + } + } + if ((ptr) && ((ptr - data) >= *w ** h * 3)) + done = 1; + } + fclose(file); + if (transp) + *t = 1; + else + *t = 0; + free(cmap); + return data; +} + +unsigned char * +g_LoadPPM(FILE * f, int *w, int *h) +{ + int done; + unsigned char *ptr; + unsigned char chr; + char s[256]; + int a, b; + int color, scale; + + a = b = scale = 0; + fgets(s, 256, f); + s[strlen(s) - 1] = 0; + + if (!strcmp(s, "P6")) + color = 1; + else if (!strcmp(s, "P5")) + color = 0; + else + return NULL; + + done = 1; + ptr = NULL; + while (done) + { + if (fgets(s, 256, f) == NULL) + break; + + s[strlen(s) - 1] = 0; + if (s[0] != '#') + { + done = 0; + sscanf(s, "%i %i", w, h); + a = *w; + b = *h; + if (a > 32767) + { + fprintf(stderr, "gdk_imlib ERROR: Image width > 32767 pixels for file\n"); + return NULL; + } + if (b > 32767) + { + fprintf(stderr, "gdk_imlib ERROR: Image height > 32767 pixels for file\n"); + return NULL; + } + fgets(s, 256, f); + sscanf(s, "%i", &scale); + s[strlen(s) - 1] = 0; + ptr = (unsigned char *)malloc(a * b * 3); + if (!ptr) + { + fprintf(stderr, "gdk_imlib ERROR: Cannot allocate RAM for RGB data in file"); + return ptr; + } + if (color) + { + if (!fread(ptr, a * b * 3, 1, f)) + { + free(ptr); + return NULL; + } + } + else + { + b = (a * b * 3); + a = 0; + while ((fread(&chr, 1, 1, f)) && (a < b)) + { + ptr[a++] = chr; + ptr[a++] = chr; + ptr[a++] = chr; + } + } + } + } + if (scale == 0) + { + free(ptr); + return NULL; + } + if (scale < 255) + { + int rot; + unsigned char *po; + + if (scale <= 1) + rot = 7; + else if (scale <= 3) + rot = 6; + else if (scale <= 7) + rot = 5; + else if (scale <= 15) + rot = 4; + else if (scale <= 31) + rot = 3; + else if (scale <= 63) + rot = 2; + else + rot = 1; + + if (rot > 0) + { + po = ptr; + while (po < (ptr + (*w ** h * 3))) + { + *po++ <<= rot; + *po++ <<= rot; + *po++ <<= rot; + } + } + } + return ptr; +} + +static int +gispnm(char *file) +{ + FILE *f; + char buf[8]; + + f = fopen(file, "rb"); + if (!f) + return 0; + fgets(buf, 8, f); + fclose(f); + if (!strcmp("P6\n", buf)) + return 1; + if (!strcmp("P5\n", buf)) + return 1; + return 0; +} + +static int +gisjpeg(char *file) +{ + FILE *f; + unsigned char buf[8]; + + f = fopen(file, "rb"); + if (!f) + return 0; + fread(buf, 1, 2, f); + fclose(f); + if ((buf[0] == 0xff) && (buf[1] == 0xd8)) + return 1; + return 0; +} + +static int +gispng(char *file) +{ +#ifdef HAVE_LIBPNG + FILE *f; + unsigned char buf[8]; + + f = fopen(file, "rb"); + if (!f) + return 0; + fread(buf, 1, 8, f); + fclose(f); + return (int)png_check_sig(buf, 8); +#else + return 0; +#endif +} + +static int +gistiff(char *file) +{ + FILE *f; + char buf[8]; + + f = fopen(file, "rb"); + if (!f) + return 0; + fgets(buf, 5, f); + fclose(f); + if ((buf[0] == 'M') && (buf[1] == 'M') && (buf[2] == 0x00) && (buf[3] == 0x2a)) + return 1; + if ((buf[0] == 'I') && (buf[1] == 'I') && (buf[2] == 0x2a) && (buf[3] == 0x00)) + return 1; + return 0; +} + +static int +giseim(char *file) +{ + FILE *f; + char buf[8]; + + f = fopen(file, "rb"); + if (!f) + return 0; + fread(buf, 1, 4, f); + fclose(f); + if (!strncmp("EIM ", buf, 4)) + return 1; + return 0; +} + +static int +gisgif(char *file) +{ + FILE *f; + char buf[8]; + + f = fopen(file, "rb"); + if (!f) + return 0; + fread(buf, 1, 4, f); + fclose(f); + buf[4] = 0; + if (!strcmp("GIF8", buf)) + return 1; + return 0; +} + +static int +gisxpm(char *file) +{ + FILE *f; + char buf[11]; + + f = fopen(file, "rb"); + if (!f) + return 0; + fread(buf, 1, 9, f); + fclose(f); + buf[9] = 0; + if (!strcmp("/* XPM */", buf)) + return 1; + return 0; +} + +GdkImlibImage * +gdk_imlib_load_image(char *file) +{ + int w, h; + int needs_conv = 1; + unsigned char *data; + GdkImlibImage *im; + char s[4096]; + char fil[4096]; + char *iden; + char *e; + char cmd[4096]; + FILE *p; + int eim; + int fmt; + int trans; + + eim = 0; + fmt = 0; + p = NULL; + data = NULL; + + if (!file) + return NULL; + if (id->cache.on_image) + if ((im = gfind_image(file))) + return im; + + strncpy(fil, file, sizeof(fil)); + iden = g_SplitID(fil); + e = g_GetExtension(fil); + + if (gispnm(fil)) + { + needs_conv = 0; + fmt = 0; + } + else if (gisjpeg(fil)) + { +#ifdef HAVE_LIBJPEG + needs_conv = 0; + fmt = 2; +#else + needs_conv = 1; + fmt = 0; +#endif + } + else if (gistiff(fil)) + { +#ifdef HAVE_LIBTIFF + needs_conv = 0; + fmt = 3; +#else + needs_conv = 1; + fmt = 0; +#endif + } + else if (giseim(fil)) + { + needs_conv = 0; + eim = 1; + fmt = 9999; + } + else if (gisxpm(fil)) + { + needs_conv = 0; + fmt = 5; + } + else if (gispng(fil)) + { +#ifdef HAVE_LIBPNG + needs_conv = 0; + fmt = 1; +#else + needs_conv = 1; + fmt = 0; +#endif + } + else if (gisgif(fil)) + { +#ifdef HAVE_LIBGIF + needs_conv = 0; + fmt = 4; +#else + needs_conv = 1; + fmt = 0; +#endif + } + if (needs_conv && id->fallback) + { + p = open_helper("%C/convert %s pnm:-", fil, "rb"); + } + else if ((fmt == 2) || (fmt == 1) || (fmt == 0)) + p = fopen(fil, "rb"); + + trans = 0; + if (!eim && !data) + { + switch (fmt) + { + case 5: + data = g_LoadXPM(fil, &w, &h, &trans); + break; +#ifdef HAVE_LIBGIF + case 4: + data = g_LoadGIF(fil, &w, &h, &trans); + break; +#endif +#ifdef HAVE_LIBTIFF + case 3: + data = g_LoadTIFF(fil, &w, &h, &trans); + break; +#endif +#ifdef HAVE_LIBJPEG + case 2: + if (p) + data = g_LoadJPEG(p, &w, &h); + break; +#endif +#ifdef HAVE_LIBPNG + case 1: + if (p) + data = g_LoadPNG(p, &w, &h, &trans); + break; +#endif + default: + if (p) + data = g_LoadPPM(p, &w, &h); + break; + } + } + + if (p && !needs_conv) + fclose(p); + else if (p) + close_helper(p); + + if ((!data) && (id->fallback)) + { + p = open_helper("%C/convert %s pnm:-", fil, "rb"); + if (p) + { + data = g_LoadPPM(p, &w, &h); + close_helper(p); + } + } + if ((!eim) && (!data) && (id->fallback)) + { + if (!strcasecmp(s, "jpeg")) + strcpy(cmd, "%J %s"); + else if (!strcasecmp(s, "jpg")) + strcpy(cmd, "%J %s"); + else if (!strcasecmp(s, "bmp")) + strcpy(cmd, "%P/bmptoppm %s"); + else if (!strcasecmp(s, "ilbm")) + strcpy(cmd, "%P/ilbmtoppm %s"); + else if (!strcasecmp(s, "ilb")) + strcpy(cmd, "%P/ilbmtoppm %s"); + else if (!strcasecmp(s, "iff")) + strcpy(cmd, "%P/ilbmtoppm %s"); + else if (!strcasecmp(s, "img")) + strcpy(cmd, "%P/imgtoppm %s"); + else if (!strcasecmp(s, "mtv")) + strcpy(cmd, "%P/mtvtoppm %s"); + else if (!strcasecmp(s, "pcx")) + strcpy(cmd, "%P/pcxtoppm %s"); + else if (!strcasecmp(s, "pgm")) + strcpy(cmd, "%P/pgmtoppm rgb:ffff/ffff/ffff %s"); + else if (!strcasecmp(s, "pi1")) + strcpy(cmd, "%P/pi1toppm %s"); + else if (!strcasecmp(s, "pict")) + strcpy(cmd, "%P/picttoppm %s"); + else if (!strcasecmp(s, "pic")) + strcpy(cmd, "%P/picttoppm %s"); + else if (!strcasecmp(s, "pj")) + strcpy(cmd, "%P/pjtoppm %s"); + else if (!strcasecmp(s, "qrt")) + strcpy(cmd, "%P/qrttoppm %s"); + else if (!strcasecmp(s, "sld")) + strcpy(cmd, "%P/sldtoppm %s"); + else if (!strcasecmp(s, "spc")) + strcpy(cmd, "%P/spctoppm %s"); + else if (!strcasecmp(s, "spu")) + strcpy(cmd, "%P/sputoppm %s"); + else if (!strcasecmp(s, "tga")) + strcpy(cmd, "%P/tgatoppm %s"); + else if (!strcasecmp(s, "xim")) + strcpy(cmd, "%P/ximtoppm %s"); + else if (!strcasecmp(s, "xpm")) + strcpy(cmd, "%P/xpmtoppm %s"); + else if (!strcasecmp(s, "gif")) + strcpy(cmd, "%P/giftopnm %s"); + else if (!strcasecmp(s, "rast")) + strcpy(cmd, "%P/rasttopnm %s"); + else if (!strcasecmp(s, "ras")) + strcpy(cmd, "%P/rasttopnm %s"); + else if (!strcasecmp(s, "sgi")) + strcpy(cmd, "%P/sgitopnm %s"); + else if (!strcasecmp(s, "sir")) + strcpy(cmd, "%P/sirtopnm %s"); + else if (!strcasecmp(s, "tiff")) + strcpy(cmd, "%P/tifftopnm %s"); + else if (!strcasecmp(s, "tif")) + strcpy(cmd, "%P/tifftopnm %s"); + else if (!strcasecmp(s, "wxd")) + strcpy(cmd, "%P/wxdtopnm %s"); + else if (!strcasecmp(s, "zeiss")) + strcpy(cmd, "%P/zeisstopnm -ppm %s"); + else if (!strcasecmp(s, "zei")) + strcpy(cmd, "%P/zeisstopnm -ppm %s"); + else if (!strcasecmp(s, "zis")) + strcpy(cmd, "%P/zeisstopnm -ppm %s"); + else + strcpy(cmd, "%P/anytopnm %s"); + p = open_helper(cmd, fil, "rb"); + if (p) + { + data = g_LoadPPM(p, &w, &h); + close_helper(p); + } + } + + if (!eim && !data) + { + fprintf(stderr, "gdk_imlib ERROR: Cannot load image: %s\nAll fallbacks failed.\n", fil); + return NULL; + } + + im = (GdkImlibImage *) malloc(sizeof(GdkImlibImage)); + if (!im) + { + fprintf(stderr, "gdk_imlib ERROR: Cannot allocate RAM for image data\n"); + if (data) + free(data); + return NULL; + } + im->alpha_data = NULL; + if (trans) + { + im->shape_color.r = 255; + im->shape_color.g = 0; + im->shape_color.b = 255; + } + else + { + im->shape_color.r = -1; + im->shape_color.g = -1; + im->shape_color.b = -1; + } + im->border.left = 0; + im->border.right = 0; + im->border.top = 0; + im->border.bottom = 0; + im->cache = 1; + im->rgb_data = data; + im->rgb_width = w; + im->rgb_height = h; + im->pixmap = NULL; + im->shape_mask = NULL; + if (eim) + { + char s1[256], s2[256]; + int num, size; + int r, g, b; + int br, bl, bt, bb; + + /* Load Native-as-can-be EIM format (Enlightenment IMlib format) */ + p = fopen(fil, "r"); + if (!p) + { + free(im); + return NULL; + } + fgets(s, 4096, p); + if ((s[0] != 'E') && (s[1] != 'I') && (s[2] != 'M') && (s[3] != ' ')) + { + fclose(p); + free(im); + return NULL; + } + sscanf(s, "%256s %i", s1, &num); + if (num <= 0) + { + fclose(p); + free(im); + return NULL; + } + while (fgets(s, 4096, p)) + { + sscanf(s, "%256s", s1); + if (!strcmp("IMAGE", s1)) + { + sscanf(s, "%256s %i %256s %i %i %i %i %i %i %i %i %i", s1, &size, s2, &w, &h, &r, &g, &b, &bl, &br, &bt, &bb); + if (!iden[0]) + break; + else if (!strcmp(iden, s2)) + break; + if (size > 0) + fseek(p, size, SEEK_CUR); + } + } + im->rgb_data = malloc(w * h * 3); + if (!im->rgb_data) + { + fclose(p); + free(im); + return NULL; + } + im->shape_color.r = r; + im->shape_color.g = g; + im->shape_color.b = b; + im->rgb_width = w; + im->rgb_height = h; + im->border.left = bl; + im->border.right = br; + im->border.top = bt; + im->border.bottom = bb; + fread(im->rgb_data, 1, w * h * 3, p); + fclose(p); + if (iden[0]) + { + strncat(fil, ":", sizeof(fil) - strlen(fil)); + strncat(fil, iden, sizeof(fil) - strlen(fil)); + } + } + im->mod.gamma = id->mod.gamma; + im->mod.brightness = id->mod.brightness; + im->mod.contrast = id->mod.contrast; + im->rmod.gamma = id->rmod.gamma; + im->rmod.brightness = id->rmod.brightness; + im->rmod.contrast = id->rmod.contrast; + im->gmod.gamma = id->gmod.gamma; + im->gmod.brightness = id->gmod.brightness; + im->gmod.contrast = id->gmod.contrast; + im->bmod.gamma = id->bmod.gamma; + im->bmod.brightness = id->bmod.brightness; + im->bmod.contrast = id->bmod.contrast; + im->filename = malloc(strlen(file) + 1); + if (im->filename) + strcpy(im->filename, file); + if ((id->cache.on_image && im)) + gadd_image(im, fil); + gcalc_map_tables(im); + return im; +} + +gint +gdk_imlib_save_image_to_eim(GdkImlibImage * im, char *file) +{ + char fil[4096]; + char *iden; + FILE *f; + int size; + + if ((!id) || (!im) || (!file)) + return 0; + strncpy(fil, file, sizeof(fil)); + iden = g_SplitID(fil); + if (!iden[0]) + iden = "default"; + f = fopen(fil, "w"); + if (!f) + return 0; + + size = im->rgb_width * im->rgb_height * 3; + fprintf(f, "EIM 1\n"); + fprintf(f, "IMAGE %i %s %i %i %i %i %i %i %i %i %i\n", + size, + iden, + im->rgb_width, + im->rgb_height, + im->shape_color.r, + im->shape_color.g, + im->shape_color.b, + im->border.left, + im->border.right, + im->border.top, + im->border.bottom); + if (fwrite(im->rgb_data, size, 1, f) != 1) + { + fclose(f); + return 0; + } + fclose(f); + return 1; +} + +gint +gdk_imlib_add_image_to_eim(GdkImlibImage * im, char *file) +{ + char fil[4096]; + char *iden; + FILE *f; + int size; + + if ((!id) || (!im) || (!file)) + return 0; + strncpy(fil, file, sizeof(fil)); + + iden = g_SplitID(file); + if (!iden[0]) + strcpy(iden, "default"); + + f = fopen(fil, "a"); + if (!f) + return 0; + + size = im->rgb_width * im->rgb_height * 3; + fprintf(f, "IMAGE %i %s %i %i %i %i %i %i %i %i %i\n", + size, + iden, + im->rgb_width, + im->rgb_height, + im->shape_color.r, + im->shape_color.g, + im->shape_color.b, + im->border.left, + im->border.right, + im->border.top, + im->border.bottom); + + if (fwrite(im->rgb_data, size, 1, f) != 1) + { + fclose(f); + return 0; + } + fclose(f); + return 1; +} + +gint +gdk_imlib_save_image_to_ppm(GdkImlibImage * im, char *file) +{ + FILE *f; + + if ((!id) || (!im) || (!file)) + return 0; + f = fopen(file, "w"); + if (!f) + return 0; + + fprintf(f, "P6\n"); + fprintf(f, "%i %i\n255\n", + im->rgb_width, + im->rgb_height); + if (fwrite(im->rgb_data, im->rgb_width * im->rgb_height * 3, 1, f) != 1) + { + fclose(f); + return 0; + } + fclose(f); + return 1; +} diff --git a/src/gdk_imlib/misc.c b/src/gdk_imlib/misc.c new file mode 100644 index 0000000000..d18964373c --- /dev/null +++ b/src/gdk_imlib/misc.c @@ -0,0 +1,1165 @@ +#define _GNU_SOURCE +#include "../gdk_imlib/gdk_imlib.h" +#include "../gdk_imlib/gdk_imlib_private.h" + +gint +gdk_imlib_get_render_type() +{ + if (id) + return id->render_type; + else + return -1; +} + +void +gdk_imlib_set_render_type(gint rend_type) +{ + if (id) + { + if (id->x.depth > 8) + id->render_type = rend_type; + else + { + if ((rend_type == RT_PLAIN_TRUECOL) || + (rend_type == RT_DITHER_TRUECOL)) + id->render_type = RT_DITHER_PALETTE_FAST; + else + id->render_type = rend_type; + } + return; + } + else + return; +} + +static void +gdk_imlib_set_fast_render(ImlibData * id, Display * disp) +{ + /* Turn off fastrender if there is an endianess diff between */ + /* client and Xserver */ + int byt, bit; + + byt = ImageByteOrder(id->x.disp); /* LSBFirst | MSBFirst */ + bit = BitmapBitOrder(id->x.disp); /* LSBFirst | MSBFirst */ + /* if little endian && server big */ + if (htonl(1) != 1 && byt == MSBFirst) + id->fastrend = 0; + /* if big endian && server little */ + if (htonl(1) == 1 && byt == LSBFirst) + id->fastrend = 0; +} + +static int +gdk_imlib_set_color_map(ImlibData * id, Display * disp) +{ + XSetWindowAttributes at; + unsigned long mask; + int newcm = 0; + + at.border_pixel = 0; + at.backing_store = NotUseful; + at.background_pixel = 0; + at.save_under = False; + at.override_redirect = True; + mask = CWOverrideRedirect | CWBackPixel | CWBorderPixel | + CWBackingStore | CWSaveUnder; + newcm = 0; + if (id->x.visual != DefaultVisual(disp, id->x.screen)) + { + Colormap cm; + + cm = XCreateColormap(id->x.disp, id->x.root, + id->x.visual, AllocNone); + if (cm) + { + mask |= CWColormap; + id->x.root_cmap = cm; + at.colormap = cm; + newcm = 1; + } + } + id->x.base_window = XCreateWindow(id->x.disp, id->x.root, + -100, -100, 10, 10, 0, + id->x.depth, InputOutput, + id->x.visual, mask, &at); + id->x.gdk_win = gdk_window_foreign_new(id->x.base_window); + if (newcm) + id->x.gdk_cmap = gdk_colormap_new(gdk_window_get_visual + (id->x.gdk_win), FALSE); + else + id->x.gdk_cmap = gdk_colormap_get_system(); + return newcm; +} + +void +gdk_imlib_init() +{ + Display *disp; + XWindowAttributes xwa; + XVisualInfo xvi, *xvir; + char *homedir; + char s[4096]; + char *s1; + char *s2; + FILE *f; + int override = 0; + int dither = 0; + int remap = 1; + int num; + int i, max, maxn; + int clas; + char *palfile = NULL; + int loadpal; + int vis; + int newcm; + + disp = (Display *) gdk_display; + if (!disp) + { + fprintf(stderr, "gdk_imlib ERROR: gdk has not connected to the display\n"); + return; + } + vis = -1; + loadpal = 0; + if (id) + return; + id = (ImlibData *) malloc(sizeof(ImlibData)); + if (!id) + { + fprintf(stderr, "gdk_imlib ERROR: Cannot alloc RAM for Initial data struct\n"); + return; + } + id->palette = NULL; + id->palette_orig = NULL; + id->fast_rgb = NULL; + id->fast_err = NULL; + id->fast_erg = NULL; + id->fast_erb = NULL; + id->x.disp = disp; + id->x.screen = DefaultScreen(disp); /* the screen number */ + id->x.root = DefaultRootWindow(disp); /* the root window id */ + id->x.visual = DefaultVisual(disp, id->x.screen); /* the visual type */ + id->x.depth = DefaultDepth(disp, id->x.screen); /* the depth of the screen in bpp */ + if (XShmQueryExtension(id->x.disp)) + { + id->x.shm = 1; + id->x.shm_event = XShmGetEventBase(id->x.disp) + ShmCompletion; + id->x.last_xim = NULL; + id->x.last_sxim = NULL; + id->max_shm = 0x7fffffff; + if (XShmPixmapFormat(id->x.disp) == ZPixmap) + id->x.shmp = 1; + } + else + { + id->x.shm = 0; + id->x.shmp = 0; + } + id->cache.on_image = 0; + id->cache.size_image = 0; + id->cache.num_image = 0; + id->cache.used_image = 0; + id->cache.image = NULL; + id->cache.on_pixmap = 0; + id->cache.size_pixmap = 0; + id->cache.num_pixmap = 0; + id->cache.used_pixmap = 0; + id->cache.pixmap = NULL; + id->byte_order = 0; + id->fastrend = 0; + id->hiq = 0; + id->fallback = 1; + id->mod.gamma = 256; + id->mod.brightness = 256; + id->mod.contrast = 256; + id->rmod.gamma = 256; + id->rmod.brightness = 256; + id->rmod.contrast = 256; + id->gmod.gamma = 256; + id->gmod.brightness = 256; + id->gmod.contrast = 256; + id->bmod.gamma = 256; + id->bmod.brightness = 256; + id->bmod.contrast = 256; + id->ordered_dither = 1; + + if (XGetWindowAttributes(disp, id->x.root, &xwa)) + { + if (xwa.colormap) + id->x.root_cmap = xwa.colormap; + else + id->x.root_cmap = 0; + } + else + id->x.root_cmap = 0; + + id->num_colors = 0; + homedir = getenv("HOME"); + g_snprintf(s, sizeof(s), "%s/.imrc", homedir); + f = fopen(s, "r"); + if (!f) + f = fopen(SYSTEM_IMRC, "r"); + if (f) + { + while (fgets(s, 4096, f)) + { + if (s[0] == '#') + continue; + + s1 = strtok(s, " \t\n"); + + /* Blank line ? */ + + if (s1 == NULL) + continue; + + s2 = strtok(NULL, " \t\n"); + if (s2 == NULL) + s2 = ""; /* NULL argument */ + + if (!strcasecmp("PaletteFile", s1)) + { + palfile = strdup(s2); + } + else if (!strcasecmp("PaletteOverride", s1)) + { + if (!strcasecmp("yes", s2)) + override = 1; + else + override = 0; + } + else if (!strcasecmp("Dither", s1)) + { + if (!strcasecmp("yes", s2)) + dither = 1; + else + dither = 0; + } + else if (!strcasecmp("Remap", s1)) + { + if (!strcasecmp("fast", s2)) + remap = 1; + else + remap = 0; + } + else if (!strcasecmp("Mit-Shm", s1)) + { + if (!strcasecmp("off", s2)) + { + id->x.shm = 0; + id->x.shmp = 0; + } + } + else if (!strcasecmp("SharedPixmaps", s1)) + { + if (!strcasecmp("off", s2)) + id->x.shmp = 0; + } + else if (!strcasecmp("FastRender", s1)) + { + if (!strcasecmp("on", s2)) + id->fastrend = 1; + } + else if (!strcasecmp("HighQuality", s1)) + { + if (!strcasecmp("on", s2)) + id->hiq = 1; + } + else if (!strcasecmp("Shm_Max_Size", s1)) + { + num = atoi(s2); + id->max_shm = num; + } + else if (!strcasecmp("Image_Cache_Size", s1)) + { + num = atoi(s2); + id->cache.size_image = num; + } + else if (!strcasecmp("Pixmap_Cache_Size", s1)) + { + num = atoi(s2); + id->cache.size_pixmap = num; + } + else if (!strcasecmp("Image_Cache", s1)) + { + if (!strcasecmp("on", s2)) + id->cache.on_image = 1; + } + else if (!strcasecmp("Pixmap_Cache", s1)) + { + if (!strcasecmp("on", s2)) + id->cache.on_pixmap = 1; + } + else if (!strcasecmp("ForceVisualID", s1)) + { + sscanf(s, "%1024s %x", s1, &num); + vis = num; + } + else if (!strcasecmp("Fallback", s1)) + { + if (!strcasecmp("off", s2)) + id->fallback = 0; + else + id->fallback = 1; + } + else if (!strcasecmp("Gamma", s1)) + { + id->mod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Brightness", s1)) + { + id->mod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Contrast", s1)) + { + id->mod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Gamma", s1)) + { + id->rmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Brightness", s1)) + { + id->rmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Contrast", s1)) + { + id->rmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Gamma", s1)) + { + id->gmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Brightness", s1)) + { + id->gmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Contrast", s1)) + { + id->gmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Gamma", s1)) + { + id->bmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Brightness", s1)) + { + id->bmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Contrast", s1)) + { + id->bmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Ordered_Dither", s1)) + { + if (!strcasecmp("off", s2)) + id->ordered_dither = 0; + else + id->ordered_dither = 1; + } + } + fclose(f); + } + /* list all visuals for the default screen */ + xvi.screen = id->x.screen; + xvir = XGetVisualInfo(disp, VisualScreenMask, &xvi, &num); + if (vis >= 0) + { + /* use the forced visual id */ + maxn = 0; + for (i = 0; i < num; i++) + { + if (xvir[i].visualid == (VisualID) vis) + maxn = i; + } + if (maxn >= 0) + { + unsigned long rmsk, gmsk, bmsk; + + id->x.depth = xvir[maxn].depth; + id->x.visual = xvir[maxn].visual; + rmsk = xvir[maxn].red_mask; + gmsk = xvir[maxn].green_mask; + bmsk = xvir[maxn].blue_mask; + + if ((rmsk > gmsk) && (gmsk > bmsk)) + id->byte_order = BYTE_ORD_24_RGB; + else if ((rmsk > bmsk) && (bmsk > gmsk)) + id->byte_order = BYTE_ORD_24_RBG; + else if ((bmsk > rmsk) && (rmsk > gmsk)) + id->byte_order = BYTE_ORD_24_BRG; + else if ((bmsk > gmsk) && (gmsk > rmsk)) + id->byte_order = BYTE_ORD_24_BGR; + else if ((gmsk > rmsk) && (rmsk > bmsk)) + id->byte_order = BYTE_ORD_24_GRB; + else if ((gmsk > bmsk) && (bmsk > rmsk)) + id->byte_order = BYTE_ORD_24_GBR; + else + id->byte_order = 0; + } + else + fprintf(stderr, "Visual Id no 0x%x specified in the imrc file is invalid on this display.\nUsing Default Visual.\n", vis); + } + else + { + if (xvir) + { + /* find the highest bit-depth supported by visuals */ + max = 0; + for (i = 0; i < num; i++) + { + if (xvir[i].depth > max) + max = xvir[i].depth; + } + if (max > 8) + { + id->x.depth = max; + clas = -1; + maxn = -1; + for (i = 0; i < num; i++) + { + if (xvir[i].depth == id->x.depth) + { + if ((xvir[i].class > clas) && (xvir[i].class != DirectColor)) + { + maxn = i; + clas = xvir[i].class; + } + } + } + if (maxn >= 0) + { + unsigned long rmsk, gmsk, bmsk; + + id->x.visual = xvir[maxn].visual; + rmsk = xvir[maxn].red_mask; + gmsk = xvir[maxn].green_mask; + bmsk = xvir[maxn].blue_mask; + + if ((rmsk > gmsk) && (gmsk > bmsk)) + id->byte_order = BYTE_ORD_24_RGB; + else if ((rmsk > bmsk) && (bmsk > gmsk)) + id->byte_order = BYTE_ORD_24_RBG; + else if ((bmsk > rmsk) && (rmsk > gmsk)) + id->byte_order = BYTE_ORD_24_BRG; + else if ((bmsk > gmsk) && (gmsk > rmsk)) + id->byte_order = BYTE_ORD_24_BGR; + else if ((gmsk > rmsk) && (rmsk > bmsk)) + id->byte_order = BYTE_ORD_24_GRB; + else if ((gmsk > bmsk) && (bmsk > rmsk)) + id->byte_order = BYTE_ORD_24_GBR; + else + id->byte_order = 0; + } + } + } + } + id->x.render_depth = id->x.depth; + XFree(xvir); + + if (id->x.depth == 16) + { + xvi.visual = id->x.visual; + xvi.visualid = XVisualIDFromVisual(id->x.visual); + xvir = XGetVisualInfo(disp, VisualIDMask, &xvi, &num); + if (xvir) + { + if (xvir->red_mask != 0xf800) + id->x.render_depth = 15; + XFree(xvir); + } + } + if (id->x.depth <= 8 || override == 1) + loadpal = 1; + + if (loadpal) + { + if (dither == 1) + { + if (remap == 1) + id->render_type = RT_DITHER_PALETTE_FAST; + else + id->render_type = RT_DITHER_PALETTE; + } + else + { + if (remap == 1) + id->render_type = RT_PLAIN_PALETTE_FAST; + else + id->render_type = RT_PLAIN_PALETTE; + } + /* Should we error this case or default it nicely */ + if (palfile != NULL) + gdk_imlib_load_colors(palfile); + if (id->num_colors == 0) + { + fprintf(stderr, "gdk_imlib: Cannot Find Palette. A Palette is required for this mode\n"); + free(id); + id = NULL; + if (palfile) + free(palfile); + return; + } + } + else + { + if (id->hiq == 1) + id->render_type = RT_DITHER_TRUECOL; + else + id->render_type = RT_PLAIN_TRUECOL; + } + + newcm = gdk_imlib_set_color_map(id, disp); + + gdk_imlib_set_fast_render(id, disp); + + if (palfile) + free(palfile); +} + +void +gdk_imlib_init_params(GdkImlibInitParams * p) +{ + Display *disp; + XWindowAttributes xwa; + XVisualInfo xvi, *xvir; + char *homedir; +/* char file[4096]; */ + char s[4096], *s1, *s2; + FILE *f; + int override = 0; + int dither = 0; + int remap = 1; + int num; + int i, max, maxn; + int clas; + char *palfile = NULL; + int loadpal; + int vis; + int newcm; + + disp = (Display *) gdk_display; + if (!disp) + { + fprintf(stderr, "gdk_imlib ERROR: gdk has not connected to the display\n"); + return; + } + vis = -1; + loadpal = 0; + if (id) + return; + id = (ImlibData *) malloc(sizeof(ImlibData)); + if (!id) + { + fprintf(stderr, "gdk_imlib ERROR: Cannot alloc RAM for Initial data struct\n"); + return; + } + id->palette = NULL; + id->palette_orig = NULL; + id->fast_rgb = NULL; + id->fast_err = NULL; + id->fast_erg = NULL; + id->fast_erb = NULL; + id->x.disp = disp; + id->x.screen = DefaultScreen(disp); /* the screen number */ + id->x.root = DefaultRootWindow(disp); /* the root window id */ + id->x.visual = DefaultVisual(disp, id->x.screen); /* the visual type */ + id->x.depth = DefaultDepth(disp, id->x.screen); /* the depth of the screen in bpp */ + if (XShmQueryExtension(id->x.disp)) + { + id->x.shm = 1; + id->x.shm_event = XShmGetEventBase(id->x.disp) + ShmCompletion; + id->x.last_xim = NULL; + id->x.last_sxim = NULL; + id->max_shm = 0x7fffffff; + if (XShmPixmapFormat(id->x.disp) == ZPixmap) + id->x.shmp = 1; + } + else + { + id->x.shm = 0; + id->x.shmp = 0; + } + id->cache.on_image = 0; + id->cache.size_image = 0; + id->cache.num_image = 0; + id->cache.used_image = 0; + id->cache.image = NULL; + id->cache.on_pixmap = 0; + id->cache.size_pixmap = 0; + id->cache.num_pixmap = 0; + id->cache.used_pixmap = 0; + id->cache.pixmap = NULL; + id->byte_order = 0; + id->fastrend = 0; + id->hiq = 0; + id->fallback = 1; + id->mod.gamma = 256; + id->mod.brightness = 256; + id->mod.contrast = 256; + id->rmod.gamma = 256; + id->rmod.brightness = 256; + id->rmod.contrast = 256; + id->gmod.gamma = 256; + id->gmod.brightness = 256; + id->gmod.contrast = 256; + id->bmod.gamma = 256; + id->bmod.brightness = 256; + id->bmod.contrast = 256; + + if (XGetWindowAttributes(disp, id->x.root, &xwa)) + { + if (xwa.colormap) + id->x.root_cmap = xwa.colormap; + else + id->x.root_cmap = 0; + } + else + id->x.root_cmap = 0; + id->num_colors = 0; + homedir = getenv("HOME"); + g_snprintf(s, sizeof(s), "%s/.imrc", homedir); + f = fopen(s, "r"); + if (!f) + f = fopen(SYSTEM_IMRC, "r"); + if (f) + { + while (fgets(s, 4096, f)) + { + if (s[0] == '#') + continue; + + s1 = strtok(s, " \t\n"); + + /* Blank line ? */ + + if (s1 == NULL) + continue; + + s2 = strtok(NULL, " \t\n"); + if (s2 == NULL) + s2 = ""; /* NULL argument */ + + if (!strcasecmp("PaletteFile", s1)) + { + palfile = strdup(s2); + } + else if (!strcasecmp("PaletteOverride", s1)) + { + if (!strcasecmp("yes", s2)) + override = 1; + else + override = 0; + } + else if (!strcasecmp("Dither", s1)) + { + if (!strcasecmp("yes", s2)) + dither = 1; + else + dither = 0; + } + else if (!strcasecmp("Remap", s1)) + { + if (!strcasecmp("fast", s2)) + remap = 1; + else + remap = 0; + } + else if (!strcasecmp("Mit-Shm", s1)) + { + if (!strcasecmp("off", s2)) + { + id->x.shm = 0; + id->x.shmp = 0; + } + } + else if (!strcasecmp("SharedPixmaps", s1)) + { + if (!strcasecmp("off", s2)) + id->x.shmp = 0; + } + else if (!strcasecmp("FastRender", s1)) + { + if (!strcasecmp("on", s2)) + id->fastrend = 1; + } + else if (!strcasecmp("HighQuality", s1)) + { + if (!strcasecmp("on", s2)) + id->hiq = 1; + } + else if (!strcasecmp("Shm_Max_Size", s1)) + { + num = atoi(s2); + id->max_shm = num; + } + if (!strcasecmp("Image_Cache_Size", s1)) + { + num = atoi(s2); + id->cache.size_image = num; + } + else if (!strcasecmp("Pixmap_Cache_Size", s1)) + { + num = atoi(s2); + id->cache.size_pixmap = num; + } + else if (!strcasecmp("Image_Cache", s1)) + { + if (!strcasecmp("on", s2)) + id->cache.on_image = 1; + } + else if (!strcasecmp("Pixmap_Cache", s1)) + { + if (!strcasecmp("on", s2)) + id->cache.on_pixmap = 1; + } + else if (!strcasecmp("ForceVisualID", s1)) + { + sscanf(s, "%1024s %x", s1, &num); + vis = num; + } + else if (!strcasecmp("Fallback", s1)) + { + if (!strcasecmp("off", s2)) + id->fallback = 0; + else + id->fallback = 1; + } + else if (!strcasecmp("Gamma", s1)) + { + id->mod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Brightness", s1)) + { + id->mod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Contrast", s1)) + { + id->mod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Gamma", s1)) + { + id->rmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Brightness", s1)) + { + id->rmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Contrast", s1)) + { + id->rmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Gamma", s1)) + { + id->gmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Brightness", s1)) + { + id->gmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Contrast", s1)) + { + id->gmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Gamma", s1)) + { + id->bmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Brightness", s1)) + { + id->bmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Contrast", s1)) + { + id->bmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Ordered_Dither", s1)) + { + if (!strcasecmp("off", s2)) + id->ordered_dither = 0; + else + id->ordered_dither = 1; + } + } + fclose(f); + } + if (p) + { + if (p->flags & PARAMS_VISUALID) + vis = p->visualid; + if (p->flags & PARAMS_PALETTEFILE) + palfile = strdup(p->palettefile); + if (p->flags & PARAMS_SHAREDMEM) + { + if (!p->sharedmem) + { + id->x.shm = 0; + id->x.shmp = 0; + } + else + { + id->x.shm = 1; + id->x.shmp = 0; + } + } + if (p->flags & PARAMS_SHAREDPIXMAPS) + { + if (id->x.shm) + id->x.shmp = p->sharedpixmaps; + } + if (p->flags & PARAMS_PALETTEOVERRIDE) + override = p->paletteoverride; + if (p->flags & PARAMS_REMAP) + remap = p->remap; + if (p->flags & PARAMS_FASTRENDER) + id->fastrend = p->fastrender; + if (p->flags & PARAMS_HIQUALITY) + id->hiq = p->hiquality; + if (p->flags & PARAMS_DITHER) + dither = p->dither; + if (p->flags & PARAMS_IMAGECACHESIZE) + id->cache.size_image = p->imagecachesize; + if (p->flags & PARAMS_PIXMAPCACHESIZE) + id->cache.size_pixmap = p->pixmapcachesize; + } + /* list all visuals for the default screen */ + xvi.screen = id->x.screen; + xvir = XGetVisualInfo(disp, VisualScreenMask, &xvi, &num); + if (vis >= 0) + { + /* use the forced visual id */ + maxn = 0; + for (i = 0; i < num; i++) + { + if (xvir[i].visualid == (VisualID) vis) + maxn = i; + } + if (maxn >= 0) + { + unsigned long rmsk, gmsk, bmsk; + + id->x.depth = xvir[maxn].depth; + id->x.visual = xvir[maxn].visual; + rmsk = xvir[maxn].red_mask; + gmsk = xvir[maxn].green_mask; + bmsk = xvir[maxn].blue_mask; + + if ((rmsk > gmsk) && (gmsk > bmsk)) + id->byte_order = BYTE_ORD_24_RGB; + else if ((rmsk > bmsk) && (bmsk > gmsk)) + id->byte_order = BYTE_ORD_24_RBG; + else if ((bmsk > rmsk) && (rmsk > gmsk)) + id->byte_order = BYTE_ORD_24_BRG; + else if ((bmsk > gmsk) && (gmsk > rmsk)) + id->byte_order = BYTE_ORD_24_BGR; + else if ((gmsk > rmsk) && (rmsk > bmsk)) + id->byte_order = BYTE_ORD_24_GRB; + else if ((gmsk > bmsk) && (bmsk > rmsk)) + id->byte_order = BYTE_ORD_24_GBR; + else + id->byte_order = 0; + } + else + fprintf(stderr, "Visual Id no 0x%x specified in the imrc file is invalid on this display.\nUsing Default Visual.\n", vis); + } + else + { + if (xvir) + { + /* find the highest bit-depth supported by visuals */ + max = 0; + for (i = 0; i < num; i++) + { + if (xvir[i].depth > max) + max = xvir[i].depth; + } + if (max > 8) + { + id->x.depth = max; + clas = -1; + maxn = -1; + for (i = 0; i < num; i++) + { + if (xvir[i].depth == id->x.depth) + { + if ((xvir[i].class > clas) && (xvir[i].class != DirectColor)) + { + maxn = i; + clas = xvir[i].class; + } + } + } + if (maxn >= 0) + { + unsigned long rmsk, gmsk, bmsk; + + id->x.visual = xvir[maxn].visual; + rmsk = xvir[maxn].red_mask; + gmsk = xvir[maxn].green_mask; + bmsk = xvir[maxn].blue_mask; + + if ((rmsk > gmsk) && (gmsk > bmsk)) + id->byte_order = BYTE_ORD_24_RGB; + else if ((rmsk > bmsk) && (bmsk > gmsk)) + id->byte_order = BYTE_ORD_24_RBG; + else if ((bmsk > rmsk) && (rmsk > gmsk)) + id->byte_order = BYTE_ORD_24_BRG; + else if ((bmsk > gmsk) && (gmsk > rmsk)) + id->byte_order = BYTE_ORD_24_BGR; + else if ((gmsk > rmsk) && (rmsk > bmsk)) + id->byte_order = BYTE_ORD_24_GRB; + else if ((gmsk > bmsk) && (bmsk > rmsk)) + id->byte_order = BYTE_ORD_24_GBR; + else + id->byte_order = 0; + } + } + } + } + id->x.render_depth = id->x.depth; + XFree(xvir); + if (id->x.depth == 16) + { + xvi.visual = id->x.visual; + xvi.visualid = XVisualIDFromVisual(id->x.visual); + xvir = XGetVisualInfo(disp, VisualIDMask, &xvi, &num); + if (xvir) + { + if (xvir->red_mask != 0xf800) + id->x.render_depth = 15; + XFree(xvir); + } + } + if ((id->x.depth <= 8) || (override == 1)) + loadpal = 1; + if (loadpal) + { + if (dither == 1) + { + if (remap == 1) + id->render_type = RT_DITHER_PALETTE_FAST; + else + id->render_type = RT_DITHER_PALETTE; + } + else + { + if (remap == 1) + id->render_type = RT_PLAIN_PALETTE_FAST; + else + id->render_type = RT_PLAIN_PALETTE; + } + gdk_imlib_load_colors(palfile); + if (id->num_colors == 0) + { + fprintf(stderr, "gdk_imlib: Cannot Find Palette. A Palette is required for this mode\n"); + free(id); + id = NULL; + if (palfile) + free(palfile); + return; + } + } + else + { + if (id->hiq == 1) + id->render_type = RT_DITHER_TRUECOL; + else + id->render_type = RT_PLAIN_TRUECOL; + } + + newcm = gdk_imlib_set_color_map(id, disp); + gdk_imlib_set_fast_render(id, disp); + if (palfile) + free(palfile); +} + +GdkPixmap * +gdk_imlib_copy_image(GdkImlibImage * im) +{ + GdkPixmap *p; + GdkGC *gc; + + if ((!im) || (!im->pixmap)) + return NULL; + p = gdk_pixmap_new(id->x.gdk_win, im->width, im->height, id->x.depth); + gc = gdk_gc_new(p); + gdk_draw_pixmap(p, gc, im->pixmap, 0, 0, 0, 0, im->width, im->height); + gdk_gc_destroy(gc); + return p; +} + +GdkPixmap * +gdk_imlib_move_image(GdkImlibImage * im) +{ + GdkPixmap *p; + + if (!im) + return NULL; + p = im->pixmap; + im->pixmap = NULL; + return p; +} + +GdkBitmap * +gdk_imlib_copy_mask(GdkImlibImage * im) +{ + GdkBitmap *p; + GdkGC *gc; + + if ((!im) || (!im->shape_mask)) + return NULL; + p = gdk_pixmap_new(id->x.gdk_win, im->width, im->height, 1); + gc = gdk_gc_new(p); + gdk_draw_pixmap(p, gc, im->shape_mask, 0, 0, 0, 0, im->width, im->height); + gdk_gc_destroy(gc); + return p; +} + +GdkBitmap * +gdk_imlib_move_mask(GdkImlibImage * im) +{ + GdkBitmap *p; + + if (!im) + return NULL; + p = im->shape_mask; + im->shape_mask = NULL; + return p; +} + +void +gdk_imlib_destroy_image(GdkImlibImage * im) +{ + if (im) + { + if (id->cache.on_image) + { + gfree_image(im); + gclean_caches(); + } + else + gnullify_image(im); + } +} + +void +gdk_imlib_kill_image(GdkImlibImage * im) +{ + if (im) + { + if (id->cache.on_image) + { + gfree_image(im); + gflush_image(im); + gclean_caches(); + } + else + gnullify_image(im); + } +} + +void +gdk_imlib_free_pixmap(GdkPixmap * pmap) +{ + if (pmap) + { + gfree_pixmappmap(pmap); + gclean_caches(); + } +} + +void +gdk_imlib_free_bitmap(GdkBitmap * pmap) +{ + if (pmap) + { + gfree_pixmappmap(pmap); + gclean_caches(); + } +} + +void +gdk_imlib_set_image_border(GdkImlibImage * im, GdkImlibBorder * border) +{ + if ((im) && (border)) + { + im->border.left = border->left; + im->border.right = border->right; + im->border.top = border->top; + im->border.bottom = border->bottom; + gdirty_pixmaps(im); + } +} + +void +gdk_imlib_get_image_border(GdkImlibImage * im, GdkImlibBorder * border) +{ + if ((im) && (border)) + { + border->left = im->border.left; + border->right = im->border.right; + border->top = im->border.top; + border->bottom = im->border.bottom; + } +} + +void +gdk_imlib_get_image_shape(GdkImlibImage * im, GdkImlibColor * color) +{ + if ((!im) || (!color)) + return; + color->r = im->shape_color.r; + color->g = im->shape_color.g; + color->b = im->shape_color.b; +} + +void +gdk_imlib_set_image_shape(GdkImlibImage * im, GdkImlibColor * color) +{ + if ((!im) || (!color)) + return; + im->shape_color.r = color->r; + im->shape_color.g = color->g; + im->shape_color.b = color->b; + gdirty_pixmaps(im); +} + +gint +gdk_imlib_get_fallback() +{ + if (!id) + return 0; + return id->fallback; +} + +void +gdk_imlib_set_fallback(gint fallback) +{ + if (!id) + return; + id->fallback = fallback; +} + +GdkVisual * +gdk_imlib_get_visual() +{ + if (!id) + return NULL; + return gdk_window_get_visual(id->x.gdk_win); +} + +GdkColormap * +gdk_imlib_get_colormap() +{ + if (!id) + return NULL; + return (id->x.gdk_cmap); +} + +gchar * +gdk_imlib_get_sysconfig() +{ + if (!id) + return NULL; + return strdup(SYSTEM_IMRC); +} diff --git a/src/gdk_imlib/rend.c b/src/gdk_imlib/rend.c new file mode 100644 index 0000000000..09b277ee9c --- /dev/null +++ b/src/gdk_imlib/rend.c @@ -0,0 +1,6170 @@ +#define _GNU_SOURCE +#include "../gdk_imlib/gdk_imlib.h" +#include "../gdk_imlib/gdk_imlib_private.h" + +GdkPixmap * +gdk_imlib_pixmap_foreign_new(gint width, gint height, + gint depth, Pixmap pmap) +{ + GdkPixmap *pixmap; + GdkWindowPrivate *private; + GdkWindowPrivate *window_private; + + private = g_new(GdkWindowPrivate, 1); + pixmap = (GdkPixmap *) private; + + window_private = (GdkWindowPrivate *) id->x.gdk_win; + + private->xdisplay = window_private->xdisplay; + private->window_type = GDK_WINDOW_PIXMAP; + private->xwindow = pmap; + private->colormap = id->x.gdk_cmap; + private->children = NULL; + private->parent = NULL; + private->x = 0; + private->y = 0; + private->width = width; + private->height = height; + private->resize_count = 0; + private->ref_count = 1; + private->destroyed = 0; + + gdk_xid_table_insert(&private->xwindow, pixmap); + + return pixmap; +} + +gint +gdk_imlib_best_color_match(gint * r, gint * g, gint * b) +{ + int i; + int dif; + int dr, dg, db; + int col; + int mindif = 0x7fffffff; + XColor xcl; + + col = 0; + if (!id) + { + fprintf(stderr, "ImLib ERROR: No ImlibData initialised\n"); + return -1; + } + if ((id->render_type == RT_PLAIN_TRUECOL) || + (id->render_type == RT_DITHER_TRUECOL)) + { + xcl.red = (unsigned short)((*r << 8) | (*r)); + xcl.green = (unsigned short)((*g << 8) | (*g)); + xcl.blue = (unsigned short)((*b << 8) | (*b)); + xcl.flags = DoRed | DoGreen | DoBlue; + XAllocColor(id->x.disp, id->x.root_cmap, &xcl); + *r = xcl.red >> 8; + *g = xcl.green >> 8; + *b = xcl.blue >> 8; + return xcl.pixel; + } + for (i = 0; i < id->num_colors; i++) + { + dr = *r - id->palette[i].r; + if (dr < 0) + dr = -dr; + dg = *g - id->palette[i].g; + if (dg < 0) + dg = -dg; + db = *b - id->palette[i].b; + if (db < 0) + db = -db; + dif = dr + dg + db; + if (dif < mindif) + { + mindif = dif; + col = i; + } + } + *r -= id->palette[col].r; + *g -= id->palette[col].g; + *b -= id->palette[col].b; + col = id->palette[col].pixel; + return col; +} + +gint +gindex_best_color_match(gint * r, gint * g, gint * b) +{ + int i; + int dif; + int dr, dg, db; + int col; + int mindif = 0x7fffffff; + XColor xcl; + + col = 0; + if (!id) + { + fprintf(stderr, "ImLib ERROR: No ImlibData initialised\n"); + return -1; + } + if ((id->render_type == RT_PLAIN_TRUECOL) || + (id->render_type == RT_DITHER_TRUECOL)) + { + xcl.red = (unsigned short)((*r << 8) | (*r)); + xcl.green = (unsigned short)((*g << 8) | (*g)); + xcl.blue = (unsigned short)((*b << 8) | (*b)); + xcl.flags = DoRed | DoGreen | DoBlue; + XAllocColor(id->x.disp, id->x.root_cmap, &xcl); + *r = xcl.red >> 8; + *g = xcl.green >> 8; + *b = xcl.blue >> 8; + return xcl.pixel; + } + for (i = 0; i < id->num_colors; i++) + { + dr = *r - id->palette[i].r; + if (dr < 0) + dr = -dr; + dg = *g - id->palette[i].g; + if (dg < 0) + dg = -dg; + db = *b - id->palette[i].b; + if (db < 0) + db = -db; + dif = dr + dg + db; + if (dif < mindif) + { + mindif = dif; + col = i; + } + } + *r -= id->palette[col].r; + *g -= id->palette[col].g; + *b -= id->palette[col].b; + return col; +} + +void +grender_shaped_15_fast_dither(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_shaped_15_fast_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_15_fast_dither(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } +} + +void +grender_15_fast_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +grender_shaped_16_fast_dither(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_shaped_16_fast_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_16_fast_dither(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } +} + +void +grender_16_fast_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex, */ er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +grender_shaped_15_dither(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_shaped_15_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + } + else + { + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_15_dither(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_15_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex, */ er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_16_dither(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_shaped_16_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex, */ er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + } + else + { + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_16_dither(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_16_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_15_fast(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_15_fast(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +grender_shaped_16_fast(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_16_fast(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +grender_shaped_24_fast(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, r, g, b; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w; + img = (unsigned char *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = r; + *img++ = g; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = r; + *img++ = b; + *img++ = g; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = b; + *img++ = r; + *img++ = g; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = b; + *img++ = g; + *img++ = r; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = r; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = b; + *img++ = r; + } + } + img += jmp; + } + } +} + +void +grender_24_fast(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, r, g, b; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w; + img = (unsigned char *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = r; + *img++ = g; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = r; + *img++ = b; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = b; + *img++ = r; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = b; + *img++ = g; + *img++ = r; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = g; + *img++ = r; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = g; + *img++ = b; + *img++ = r; + } + img += jmp; + } + } +} + +void +grender_shaped_32_fast(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned int *img; + int jmp; + + jmp = (xim->bytes_per_line >> 2) - w; + img = (unsigned int *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (r << 16) | (g << 8) | b; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (r << 16) | (b << 8) | g; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (b << 16) | (r << 8) | g; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (b << 16) | (g << 8) | r; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (g << 16) | (r << 8) | b; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + } + img += jmp; + } + } +} + +void +grender_32_fast(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned int *img; + int jmp; + + jmp = (xim->bytes_per_line >> 2) - w; + img = (unsigned int *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (r << 16) | (g << 8) | b; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (r << 16) | (b << 8) | g; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (b << 16) | (r << 8) | g; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (b << 16) | (g << 8) | r; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (g << 16) | (r << 8) | b; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + img += jmp; + } + } +} + +void +grender_shaped_15(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_15(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_16(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_16(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_24(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (r << 16) | (g << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (r << 16) | (b << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (b << 16) | (r << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (b << 16) | (g << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (g << 16) | (r << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + } +} + +void +grender_24(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (r << 16) | (g << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (r << 16) | (b << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (b << 16) | (r << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (b << 16) | (g << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (g << 16) | (r << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_shaped(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray, int bpp) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w; + img = (unsigned char *)xim->data; + switch (id->render_type) + { + case RT_PLAIN_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = gdk_imlib_best_color_match(&r, &g, &b); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = gdk_imlib_best_color_match(&r, &g, &b); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_PLAIN_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_DITHER_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + { + XPutPixel(sxim, x, y, 0); + img++; + } + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = gdk_imlib_best_color_match(&er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = gdk_imlib_best_color_match(&er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_DITHER_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + { + XPutPixel(sxim, x, y, 0); + img++; + } + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = COLOR_INDEX(val); + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, COLOR_INDEX(val)); + } + } + } + } + break; + default: + if (id->fastrend) + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_15_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_15_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_15_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_16_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_16_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_16_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + grender_shaped_24_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_32_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_15_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_15_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_15(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_16_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_16_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_16(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + grender_shaped_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); + case 32: + grender_shaped_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + break; + } +} + +void +grender(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray, int bpp) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w; + img = (unsigned char *)xim->data; + switch (id->render_type) + { + case RT_PLAIN_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = gdk_imlib_best_color_match(&r, &g, &b); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = gdk_imlib_best_color_match(&r, &g, &b); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_PLAIN_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_DITHER_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = gdk_imlib_best_color_match(&er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = gdk_imlib_best_color_match(&er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_DITHER_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = COLOR_INDEX(val); + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, COLOR_INDEX(val)); + } + } + } + break; + default: + if (id->fastrend) + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_15_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_15_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_15_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_16_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_16_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_16_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + grender_24_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_32_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_15_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_15_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_15(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_16_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_16_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_16(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + grender_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 32: + grender_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + break; + } + } +} + +void +grender_shaped_15_fast_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + ex += 3; + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_shaped_15_fast_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_15_fast_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } +} + +void +grender_15_fast_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +grender_shaped_16_fast_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_shaped_16_fast_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_16_fast_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } +} + +void +grender_16_fast_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +grender_shaped_15_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex, */ er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_15_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex, */ er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_16_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex,*/ er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_16_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, /* *ter, ex, */ er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_15_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_15_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_16_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_16_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_15_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_15_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +grender_shaped_16_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +grender_16_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +grender_shaped_24_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, r, g, b; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w; + img = (unsigned char *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = g; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = b; + *img++ = g; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = r; + *img++ = g; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = g; + *img++ = r; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = r; + *img++ = b; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = b; + *img++ = r; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + } + } + img += jmp; + } + } +} + +void +grender_24_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, r, g, b; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w; + img = (unsigned char *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = g; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = b; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = r; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = g; + *img++ = r; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = g; + *img++ = r; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = g; + *img++ = b; + *img++ = r; + } + img += jmp; + } + } +} + +void +grender_shaped_32_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned int *img; + int jmp; + + jmp = (xim->bytes_per_line >> 2) - w; + img = (unsigned int *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (g << 8) | b; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (b << 8) | g; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (r << 8) | g; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (g << 8) | r; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (r << 8) | b; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + } + img += jmp; + } + } +} + +void +grender_32_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned int *img; + int jmp; + + jmp = (xim->bytes_per_line >> 2) - w; + img = (unsigned int *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (g << 8) | b; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (b << 8) | g; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (r << 8) | g; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (g << 8) | r; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (r << 8) | b; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + img += jmp; + } + } +} + +void +grender_shaped_15_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_15_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_16_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_16_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +grender_shaped_24_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (g << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (b << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (r << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (g << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (r << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + } +} + +void +grender_24_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (g << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (b << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (r << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (g << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (r << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } +} + +void +grender_shaped_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray, int bpp) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w; + img = (unsigned char *)xim->data; + switch (id->render_type) + { + case RT_PLAIN_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = gdk_imlib_best_color_match(&r, &g, &b); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = gdk_imlib_best_color_match(&r, &g, &b); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_PLAIN_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_DITHER_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + { + XPutPixel(sxim, x, y, 0); + img++; + } + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = gdk_imlib_best_color_match(&er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = gdk_imlib_best_color_match(&er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_DITHER_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + { + XPutPixel(sxim, x, y, 0); + img++; + } + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = COLOR_INDEX(val); + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, COLOR_INDEX(val)); + } + } + } + } + break; + default: + if (id->fastrend) + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_15_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_15_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_15_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_16_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_16_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_16_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + grender_shaped_24_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_32_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_15_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + grender_shaped_15_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_15_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_16_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_16_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_16_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + grender_shaped_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + case 32: + grender_shaped_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + break; + } +} + +void +grender_mod(GdkImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray, int bpp) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w; + img = (unsigned char *)xim->data; + switch (id->render_type) + { + case RT_PLAIN_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = gdk_imlib_best_color_match(&r, &g, &b); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = gdk_imlib_best_color_match(&r, &g, &b); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_PLAIN_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_DITHER_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = gdk_imlib_best_color_match(&er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = gdk_imlib_best_color_match(&er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_DITHER_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = COLOR_INDEX(val); + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, COLOR_INDEX(val)); + } + } + } + break; + default: + if (id->fastrend) + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_15_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_15_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_15_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_16_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_16_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_16_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + grender_24_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_32_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_15_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_15_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_15_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_16_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_16_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_16_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + grender_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 32: + grender_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + break; + } + } +} + +gint +gdk_imlib_render(GdkImlibImage * im, gint w, gint h) +{ + XImage *xim, *sxim; + GC tgc, stgc; + XGCValues gcv; + unsigned char *tmp, *stmp, **yarray, *ptr22; + int w3, x, inc, pos, *error, *er1, *er2, *xarray, ex, + bpp, huge; + Pixmap pmap, mask; + GdkPixmap *pm, *mm; + int shared_pixmap, shared_image, ok; + + sxim = NULL; + xim = NULL; + tmp = NULL; + stmp = NULL; + pmap = 0; + mask = 0; + tgc = 0; + stgc = 0; + inc = 0; + if (!im) + return 0; + if (w <= 0) + return 0; + if (h <= 0) + return 0; + gcv.graphics_exposures = False; + +/* look for the pixmap in cache first */ + if (id->cache.on_pixmap) + { + pmap = 0; + gfind_pixmap(im, w, h, &pm, &mm); + if (pm) + { + im->width = w; + im->height = h; + im->pixmap = pm; + if (mm) + im->shape_mask = mm; + else + im->shape_mask = NULL; + return 1; + } + } + + if (im->pixmap) + gfree_pixmappmap(im->pixmap); + im->pixmap = NULL; + im->shape_mask = NULL; +/* setup stuff */ + huge = 0; + if (id->x.depth <= 8) + bpp = 1; + else if (id->x.depth <= 16) + bpp = 2; + else + bpp = 4; + if ((id->max_shm) && ((bpp * w * h) > id->max_shm)) + huge = 1; + im->width = w; + im->height = h; + +/* dithering array */ + error = (int *)malloc(sizeof(int) * (w + 2) * 2 * 3); + + if (!error) + { + fprintf(stderr, "ERROR: Cannot allocate RAM for image dither buffer\n"); + return 0; + } + +/* setup pointers to point right */ + er1 = error; + er2 = error + ((w + 2) * 3); + w3 = im->rgb_width * 3; + ptr22 = im->rgb_data; + +/* setup coord-mapping array (specially for border scaling) */ + xarray = malloc(sizeof(int) * w); + + if (!xarray) + { + fprintf(stderr, "ERROR: Cannot allocate X co-ord buffer\n"); + free(error); + return 0; + } + yarray = malloc(sizeof(unsigned char *) * h); + + if (!yarray) + { + fprintf(stderr, "ERROR: Cannot allocate Y co-ord buffer\n"); + free(xarray); + free(error); + return 0; + } + for (ex = 0; ex < ((w + 2) * 3 * 2); ex++) + error[ex] = 0; + { + int l, r, m; + + if (w < im->border.left + im->border.right) + { + l = w >> 1; + r = w - l; + m = 0; + } + else + { + l = im->border.left; + r = im->border.right; + m = w - l - r; + } + if (m > 0) + inc = ((im->rgb_width - im->border.left - im->border.right) << 16) / m; + pos = 0; + if (l) + for (x = 0; x < l; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += 0x10000; + } + if (m) + { + for (x = l; x < l + m; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += inc; + } + } + pos = (im->rgb_width - r) << 16; + for (x = w - r; x < w; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += 0x10000; + } + + if (h < im->border.top + im->border.bottom) + { + l = h >> 1; + r = h - l; + m = 0; + } + else + { + l = im->border.top; + r = im->border.bottom; + m = h - l - r; + } + if (m > 0) + inc = ((im->rgb_height - im->border.top - im->border.bottom) << 16) / m; + pos = 0; + for (x = 0; x < l; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += 0x10000; + } + if (m) + { + for (x = l; x < l + m; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += inc; + } + } + pos = (im->rgb_height - r) << 16; + for (x = h - r; x < h; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += 0x10000; + } + } + +/* work out if we should use shared pixmap. images etc */ + shared_pixmap = 0; + shared_image = 0; + if ((id->x.shmp) && (id->x.shm) && (!huge)) + { + shared_pixmap = 1; + shared_image = 0; + } + else if ((id->x.shm) && (!huge)) + { + shared_pixmap = 0; + shared_image = 1; + } + else + shared_pixmap = 0; + shared_image = 0; + +/* init images and pixmaps */ + ok = 1; + if (shared_pixmap) + { + xim = XShmCreateImage(id->x.disp, id->x.visual, id->x.depth, ZPixmap, NULL, &id->x.last_shminfo, w, h); + if (!xim) + { + fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create XImage for Shared Pixmap Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + shared_pixmap = 0; + shared_image = 1; + ok = 0; + } + if (ok) + { + id->x.last_shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height, IPC_CREAT | 0777); + if (id->x.last_shminfo.shmid == -1) + { + fprintf(stderr, "IMLIB ERROR: SHM can't get SHM Identifier for Shared Pixmap Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + XDestroyImage(xim); + shared_pixmap = 0; + shared_image = 1; + ok = 1; + } + if (ok) + { + id->x.last_shminfo.shmaddr = xim->data = shmat(id->x.last_shminfo.shmid, 0, 0); + id->x.last_shminfo.readOnly = False; + XShmAttach(id->x.disp, &id->x.last_shminfo); + tmp = (unsigned char *)xim->data; + id->x.last_xim = xim; + pmap = XShmCreatePixmap(id->x.disp, id->x.base_window, + id->x.last_shminfo.shmaddr, + &id->x.last_shminfo, w, h, id->x.depth); + tgc = XCreateGC(id->x.disp, pmap, GCGraphicsExposures, &gcv); + if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) + { + sxim = XShmCreateImage(id->x.disp, id->x.visual, 1, ZPixmap, NULL, &id->x.last_sshminfo, w, h); + if (!sxim) + { + fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create XImage for Shared Pixmap mask Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + shared_pixmap = 0; + shared_image = 1; + ok = 0; + } + if (ok) + { + id->x.last_sshminfo.shmid = shmget(IPC_PRIVATE, sxim->bytes_per_line * sxim->height, IPC_CREAT | 0777); + if (id->x.last_sshminfo.shmid == -1) + { + fprintf(stderr, "IMLIB ERROR: SHM can't get SHM Identifier for Shared Pixmap mask Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + XDestroyImage(sxim); + shared_pixmap = 0; + shared_image = 1; + ok = 0; + } + id->x.last_sshminfo.shmaddr = sxim->data = shmat(id->x.last_sshminfo.shmid, 0, 0); + id->x.last_sshminfo.readOnly = False; + XShmAttach(id->x.disp, &id->x.last_sshminfo); + stmp = (unsigned char *)sxim->data; + id->x.last_sxim = sxim; + mask = XShmCreatePixmap(id->x.disp, id->x.base_window, + id->x.last_sshminfo.shmaddr, + &id->x.last_sshminfo, w, h, 1); + stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); + } + } + } + } + } + ok = 1; + if (shared_image) + { + xim = XShmCreateImage(id->x.disp, id->x.visual, id->x.depth, ZPixmap, NULL, &id->x.last_shminfo, w, h); + if (!xim) + { + fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create Shared XImage\n"); + fprintf(stderr, " Falling back on XImages\n"); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + if (ok) + { + id->x.last_shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height, IPC_CREAT | 0777); + if (id->x.last_shminfo.shmid == -1) + { + fprintf(stderr, "IMLIB ERROR: SHM can't get SHM Identifier for Shared XImage\n"); + fprintf(stderr, " Falling back on XImages\n"); + XDestroyImage(xim); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + if (ok) + { + id->x.last_shminfo.shmaddr = xim->data = shmat(id->x.last_shminfo.shmid, 0, 0); + id->x.last_shminfo.readOnly = False; + XShmAttach(id->x.disp, &id->x.last_shminfo); + tmp = (unsigned char *)xim->data; + id->x.last_xim = xim; + pmap = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); + tgc = XCreateGC(id->x.disp, pmap, GCGraphicsExposures, &gcv); + if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) + { + sxim = XShmCreateImage(id->x.disp, id->x.visual, 1, ZPixmap, NULL, &id->x.last_sshminfo, w, h); + if (!sxim) + { + fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create Shared XImage mask\n"); + fprintf(stderr, " Falling back on XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + if (ok) + { + id->x.last_sshminfo.shmid = shmget(IPC_PRIVATE, sxim->bytes_per_line * sxim->height, IPC_CREAT | 0777); + if (id->x.last_sshminfo.shmid == -1) + { + fprintf(stderr, "Imlib ERROR: SHM can't get SHM Identifierfor Shared XImage mask\n"); + fprintf(stderr, " Falling back on XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + XDestroyImage(sxim); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + if (ok) + { + id->x.last_sshminfo.shmaddr = sxim->data = shmat(id->x.last_sshminfo.shmid, 0, 0); + id->x.last_sshminfo.readOnly = False; + XShmAttach(id->x.disp, &id->x.last_sshminfo); + stmp = (unsigned char *)sxim->data; + id->x.last_sxim = sxim; + mask = XCreatePixmap(id->x.disp, id->x.base_window, w, h, 1); + stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); + } + } + } + } + } + } + ok = 1; + if ((!shared_pixmap) && (!shared_image)) + { + tmp = (unsigned char *)malloc(w * h * bpp); + if (!tmp) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for XImage data\n"); + free(xarray); + free(yarray); + free(error); + return 0; + } + xim = XCreateImage(id->x.disp, id->x.visual, id->x.depth, ZPixmap, 0, (char *)tmp, w, h, 8, 0); + if (!xim) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate XImage buffer\n"); + free(xarray); + free(yarray); + free(error); + free(tmp); + return 0; + } + pmap = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); + if (!pmap) + { + fprintf(stderr, "IMLIB ERROR: Cannot create pixmap\n"); + free(xarray); + free(yarray); + free(error); + XDestroyImage(xim); + return 0; + } + tgc = XCreateGC(id->x.disp, pmap, GCGraphicsExposures, &gcv); + if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) + { + stmp = (unsigned char *)malloc(((w >> 3) + 8) * h); + if (!stmp) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for shape XImage data\n"); + free(xarray); + free(yarray); + free(error); + XDestroyImage(xim); + return 0; + } + sxim = XCreateImage(id->x.disp, id->x.visual, 1, ZPixmap, 0, (char *)stmp, w, h, 8, 0); + if (!sxim) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate XImage shape buffer\n"); + free(xarray); + free(yarray); + free(error); + free(stmp); + XDestroyImage(xim); + return 0; + } + mask = XCreatePixmap(id->x.disp, id->x.base_window, w, h, 1); + if (!mask) + { + fprintf(stderr, "IMLIB ERROR: Cannot create shape pixmap\n"); + free(xarray); + free(yarray); + free(error); + XDestroyImage(sxim); + XDestroyImage(xim); + return 0; + } + stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); + } + } + +/* copy XImage to the pixmap, if not a shared pixmap */ + if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) + { + if ((im->mod.gamma == 256) && (im->mod.brightness == 256) && (im->mod.contrast == 256) && + (im->rmod.gamma == 256) && (im->rmod.brightness == 256) && (im->rmod.contrast == 256) && + (im->gmod.gamma == 256) && (im->gmod.brightness == 256) && (im->gmod.contrast == 256) && + (im->bmod.gamma == 256) && (im->bmod.brightness == 256) && (im->bmod.contrast == 256)) + { + if (id->x.depth <= 8) + grender_shaped(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + grender_shaped(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } + else + { + if (id->x.depth <= 8) + grender_shaped_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + grender_shaped_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } + if (shared_image) + { + XShmPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h, False); + XShmPutImage(id->x.disp, mask, stgc, sxim, 0, 0, 0, 0, w, h, False); + XSync(id->x.disp, False); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); + im->shape_mask = gdk_imlib_pixmap_foreign_new(w, h, 1, mask); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + XShmDetach(id->x.disp, &id->x.last_sshminfo); + XDestroyImage(sxim); + shmdt(id->x.last_sshminfo.shmaddr); + shmctl(id->x.last_sshminfo.shmid, IPC_RMID, 0); + id->x.last_xim = NULL; + id->x.last_sxim = NULL; + xim = NULL; + sxim = NULL; + XFreeGC(id->x.disp, tgc); + XFreeGC(id->x.disp, stgc); + } + else if (shared_pixmap) + { + Pixmap p2, m2; + + p2 = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); + m2 = XCreatePixmap(id->x.disp, id->x.base_window, w, h, 1); + XCopyArea(id->x.disp, pmap, p2, tgc, 0, 0, w, h, 0, 0); + XCopyArea(id->x.disp, mask, m2, stgc, 0, 0, w, h, 0, 0); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, p2); + im->shape_mask = gdk_imlib_pixmap_foreign_new(w, h, 1, m2); + XFreeGC(id->x.disp, tgc); + XFreeGC(id->x.disp, stgc); + XFreePixmap(id->x.disp, pmap); + XFreePixmap(id->x.disp, mask); + XSync(id->x.disp, False); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + XShmDetach(id->x.disp, &id->x.last_sshminfo); + XDestroyImage(sxim); + shmdt(id->x.last_sshminfo.shmaddr); + shmctl(id->x.last_sshminfo.shmid, IPC_RMID, 0); + id->x.last_xim = NULL; + id->x.last_sxim = NULL; + xim = NULL; + sxim = NULL; + } + else + { + XPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h); + XPutImage(id->x.disp, mask, stgc, sxim, 0, 0, 0, 0, w, h); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); + im->shape_mask = gdk_imlib_pixmap_foreign_new(w, h, 1, mask); + XDestroyImage(xim); + XDestroyImage(sxim); + xim = NULL; + sxim = NULL; + XFreeGC(id->x.disp, tgc); + XFreeGC(id->x.disp, stgc); + } + } + else + { + if ((im->mod.gamma == 256) && (im->mod.brightness == 256) && (im->mod.contrast == 256) && + (im->rmod.gamma == 256) && (im->rmod.brightness == 256) && (im->rmod.contrast == 256) && + (im->gmod.gamma == 256) && (im->gmod.brightness == 256) && (im->gmod.contrast == 256) && + (im->bmod.gamma == 256) && (im->bmod.brightness == 256) && (im->bmod.contrast == 256)) + { + if (id->x.depth <= 8) + grender(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + grender(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } + else + { + if (id->x.depth <= 8) + grender_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + grender_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } + if (shared_image) + { + XShmPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h, False); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); + im->shape_mask = NULL; + XSync(id->x.disp, False); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + id->x.last_xim = NULL; + xim = NULL; + sxim = NULL; + XFreeGC(id->x.disp, tgc); + } + else if (shared_pixmap) + { + Pixmap p2; + + p2 = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); + XCopyArea(id->x.disp, pmap, p2, tgc, 0, 0, w, h, 0, 0); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, p2); + im->shape_mask = NULL; + XFreeGC(id->x.disp, tgc); + XFreePixmap(id->x.disp, pmap); + XSync(id->x.disp, False); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + id->x.last_xim = NULL; + xim = NULL; + sxim = NULL; + } + else + { + XPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); + im->shape_mask = NULL; + XDestroyImage(xim); + xim = NULL; + sxim = NULL; + XFreeGC(id->x.disp, tgc); + } + } + +/* cleanup */ + XSync(id->x.disp, False); + free(error); + free(xarray); + free(yarray); + +/* add this pixmap to the cache */ + gadd_pixmap(im, w, h, xim, sxim); + return 1; +} diff --git a/src/gdk_imlib/save.c b/src/gdk_imlib/save.c new file mode 100644 index 0000000000..59d4e9c5bc --- /dev/null +++ b/src/gdk_imlib/save.c @@ -0,0 +1,538 @@ +#define _GNU_SOURCE +#include "../gdk_imlib/config.h" + +#include "../gdk_imlib/gdk_imlib.h" +#include "../gdk_imlib/gdk_imlib_private.h" + +gint +gdk_imlib_save_image(GdkImlibImage * im, char *file, GdkImlibSaveInfo * info) +{ + char *ext; + char cmd[10240]; + FILE *f; + GdkImlibSaveInfo defaults; + + if (!im || !file) + return 0; + + defaults.quality = 208; + defaults.scaling = 1024; + defaults.xjustification = 512; + defaults.yjustification = 512; + defaults.page_size = PAGE_SIZE_LETTER; + defaults.color = 1; + + if (!info) + info = &defaults; + ext = g_GetExtension(file); + + if ((!strcasecmp(ext, "ppm")) || (!strcasecmp(ext, "pnm"))) + { + f = fopen(file, "wb"); + if (f) + { + if (!fprintf(f, "P6\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height)) + { + fclose(f); + return 0; + } + if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f)) + { + fclose(f); + return 0; + } + fclose(f); + return 1; + } + } + else if (!strcasecmp(ext, "pgm")) + { + int x, y; + unsigned char *ptr, val; + int v; + + f = fopen(file, "wb"); + if (f) + { + if (!fprintf(f, "P5\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height)) + { + fclose(f); + return 0; + } + ptr = im->rgb_data; + for (y = 0; y < im->rgb_height; y++) + { + for (x = 0; x < im->rgb_width; x++) + { + v = (int)(*ptr++); + v += (int)(*ptr++); + v += (int)(*ptr++); + val = (unsigned char)(v / 3); + if (!fwrite(&val, 1, 1, f)) + { + fclose(f); + return 0; + } + } + } + fclose(f); + return 1; + } + } + else if (!strcasecmp(ext, "ps")) + { + int bx, by, bxx, byy; + int w, h; + int sx = 0, sy = 0; + int tx = 35, ty = 35; + int x, y; + unsigned char *ptr; + int v; + + f = fopen(file, "wb"); + + if (f == NULL) + return 0; + + w = im->rgb_width; + h = im->rgb_height; + + switch (info->page_size) + { + case PAGE_SIZE_EXECUTIVE: + sx = 540; + sy = 720; + break; + case PAGE_SIZE_LETTER: + sx = 612; + sy = 792; + break; + case PAGE_SIZE_LEGAL: + sx = 612; + sy = 1008; + break; + case PAGE_SIZE_A4: + sx = 595; + sy = 842; + break; + case PAGE_SIZE_A3: + sx = 842; + sy = 1190; + break; + case PAGE_SIZE_A5: + sx = 420; + sy = 595; + break; + case PAGE_SIZE_FOLIO: + sx = 612; + sy = 936; + break; + } + bxx = ((sx - (tx * 2)) * info->scaling) >> 10; + byy = ((h * bxx / w) * info->scaling) >> 10; + if ((((sy - (ty * 2)) * info->scaling) >> 10) < byy) + { + byy = ((sy - (ty * 2)) * info->scaling) >> 10; + bxx = ((w * byy / h) * info->scaling) >> 10; + } + bx = tx + ((((sx - (tx * 2)) - bxx) * info->xjustification) >> 10); + by = ty + ((((sy - (ty * 2)) - byy) * info->yjustification) >> 10); + if (f) + { + fprintf(f, "%%!PS-Adobe-2.0 EPSF-2.0\n"); + fprintf(f, "%%%%Title: %s\n", file); + fprintf(f, "%%%%Creator: Imlib by The Rasterman\n"); + fprintf(f, "%%%%BoundingBox: %i %i %i %i\n", bx, by, bxx, byy); + fprintf(f, "%%%%Pages: 1\n"); + fprintf(f, "%%%%DocumentFonts:\n"); + fprintf(f, "%%%%EndComments\n"); + fprintf(f, "%%%%EndProlog\n"); + fprintf(f, "%%%%Page: 1 1\n"); + fprintf(f, "/origstate save def\n"); + fprintf(f, "20 dict begin\n"); + if (info->color) + { + fprintf(f, "/pix %i string def\n", w * 3); + fprintf(f, "/grays %i string def\n", w); + fprintf(f, "/npixls 0 def\n"); + fprintf(f, "/rgbindx 0 def\n"); + fprintf(f, "%i %i translate\n", bx, by); + fprintf(f, "%i %i scale\n", bxx, byy); + fprintf(f, + "/colorimage where\n" + "{ pop }\n" + "{\n" + "/colortogray {\n" + "/rgbdata exch store\n" + "rgbdata length 3 idiv\n" + "/npixls exch store\n" + "/rgbindx 0 store\n" + "0 1 npixls 1 sub {\n" + "grays exch\n" + "rgbdata rgbindx get 20 mul\n" + "rgbdata rgbindx 1 add get 32 mul\n" + "rgbdata rgbindx 2 add get 12 mul\n" + "add add 64 idiv\n" + "put\n" + "/rgbindx rgbindx 3 add store\n" + "} for\n" + "grays 0 npixls getinterval\n" + "} bind def\n" + "/mergeprocs {\n" + "dup length\n" + "3 -1 roll\n" + "dup\n" + "length\n" + "dup\n" + "5 1 roll\n" + "3 -1 roll\n" + "add\n" + "array cvx\n" + "dup\n" + "3 -1 roll\n" + "0 exch\n" + "putinterval\n" + "dup\n" + "4 2 roll\n" + "putinterval\n" + "} bind def\n" + "/colorimage {\n" + "pop pop\n" + "{colortogray} mergeprocs\n" + "image\n" + "} bind def\n" + "} ifelse\n"); + fprintf(f, "%i %i 8\n", w, h); + fprintf(f, "[%i 0 0 -%i 0 %i]\n", w, h, h); + fprintf(f, "{currentfile pix readhexstring pop}\n"); + fprintf(f, "false 3 colorimage\n"); + fprintf(f, "\n"); + ptr = im->rgb_data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + v = (int)(*ptr++); + if (v < 0x10) + fprintf(f, "0%x", v); + else + fprintf(f, "%x", v); + v = (int)(*ptr++); + if (v < 0x10) + fprintf(f, "0%x", v); + else + fprintf(f, "%x", v); + v = (int)(*ptr++); + if (v < 0x10) + fprintf(f, "0%x", v); + else + fprintf(f, "%x", v); + } + fprintf(f, "\n"); + } + } + else + { + fprintf(f, "/pix %i string def\n", w); + fprintf(f, "/grays %i string def\n", w); + fprintf(f, "/npixls 0 def\n"); + fprintf(f, "/rgbindx 0 def\n"); + fprintf(f, "%i %i translate\n", bx, by); + fprintf(f, "%i %i scale\n", bxx, byy); + fprintf(f, "%i %i 8\n", w, h); + fprintf(f, "[%i 0 0 -%i 0 %i]\n", w, h, h); + fprintf(f, "{currentfile pix readhexstring pop}\n"); + fprintf(f, "image\n"); + fprintf(f, "\n"); + ptr = im->rgb_data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + v = (int)(*ptr++); + v += (int)(*ptr++); + v += (int)(*ptr++); + v /= 3; + if (v < 0x10) + fprintf(f, "0%x", v); + else + fprintf(f, "%x", v); + } + fprintf(f, "\n"); + } + } + fprintf(f, "\n"); + fprintf(f, "showpage\n"); + fprintf(f, "end\n"); + fprintf(f, "origstate restore\n"); + fprintf(f, "%%%%Trailer\n"); + fclose(f); + return 1; + } + } + else if ((!strcasecmp(ext, "jpeg")) || (!strcasecmp(ext, "jpg"))) + { +#ifdef HAVE_LIBJPEG + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + JSAMPROW row_pointer[1]; + int row_stride; + int y; + + f = fopen(file, "wb"); + if (f) + { + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + jpeg_stdio_dest(&cinfo, f); + cinfo.image_width = im->rgb_width; + cinfo.image_height = im->rgb_height; + cinfo.input_components = 3; + cinfo.in_color_space = JCS_RGB; + jpeg_set_defaults(&cinfo); + jpeg_set_quality(&cinfo, (100 * info->quality) >> 8, TRUE); + jpeg_start_compress(&cinfo, TRUE); + row_stride = cinfo.image_width * 3; + while (cinfo.next_scanline < cinfo.image_height) + { + row_pointer[0] = im->rgb_data + (cinfo.next_scanline * row_stride); + jpeg_write_scanlines(&cinfo, row_pointer, 1); + } + jpeg_finish_compress(&cinfo); + fclose(f); + return 1; + } +#endif + } + else if (!strcasecmp(ext, "png")) + { +#ifdef HAVE_LIBPNG + png_structp png_ptr; + png_infop info_ptr; + unsigned char *data, *ptr; + int x, y; + png_bytep row_ptr; + png_color_8 sig_bit; + + f = fopen(file, "wb"); + if (f) + { + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + if (!png_ptr) + { + fclose(f); + return 0; + } + info_ptr = png_create_info_struct(png_ptr); + if (info_ptr == NULL) + { + fclose(f); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + return 0; + } + if (setjmp(png_ptr->jmpbuf)) + { + fclose(f); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + return 0; + } + png_init_io(png_ptr, f); + png_set_IHDR(png_ptr, info_ptr, im->rgb_width, im->rgb_height, 8, + PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + sig_bit.red = 8; + sig_bit.green = 8; + sig_bit.blue = 8; + sig_bit.alpha = 8; + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + png_write_info(png_ptr, info_ptr); + png_set_shift(png_ptr, &sig_bit); + png_set_packing(png_ptr); + data = malloc(im->rgb_width * 4); + if (!data) + { + fclose(f); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + return 0; + } + for (y = 0; y < im->rgb_height; y++) + { + ptr = im->rgb_data + (y * im->rgb_width * 3); + for (x = 0; x < im->rgb_width; x++) + { + data[(x << 2) + 0] = *ptr++; + data[(x << 2) + 1] = *ptr++; + data[(x << 2) + 2] = *ptr++; + if ((data[(x << 2) + 0] == im->shape_color.r) && + (data[(x << 2) + 1] == im->shape_color.g) && + (data[(x << 2) + 2] == im->shape_color.b)) + data[(x << 2) + 3] = 0; + else + data[(x << 2) + 3] = 255; + } + row_ptr = data; + png_write_rows(png_ptr, &row_ptr, 1); + } + free(data); + png_write_end(png_ptr, info_ptr); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + + fclose(f); + return 1; + } +#endif + } + else if ((!strcasecmp(ext, "tiff")) || (!strcasecmp(ext, "tif"))) + { +#ifdef HAVE_LIBTIFF + TIFF *tif; + unsigned char *ptr, *data; + int x, y; + int w; + + tif = TIFFOpen(file, "w"); + if (tif) + { + TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, im->rgb_width); + TIFFSetField(tif, TIFFTAG_IMAGELENGTH, im->rgb_height); + TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); + TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW); + { + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3); + TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); + w = TIFFScanlineSize(tif); + TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, + TIFFDefaultStripSize(tif, -1)); + for (y = 0; y < im->rgb_height; y++) + { + data = im->rgb_data + (y * im->rgb_width * 3); + TIFFWriteScanline(tif, data, y, 0); + } + } + TIFFClose(tif); + return 1; + } +#endif + } + if (id->fallback) + { + f = open_helper("%C/convert pnm:- %s", file, "wb"); + if (f) + { + if (!fprintf(f, "P6\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height)) + { + close_helper(f); + return 0; + } + if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f)) + { + close_helper(f); + return 0; + } + if (close_helper(f)) + return 0; + return 1; + } + + if (!strcasecmp(ext, "jpeg")) + g_snprintf(cmd, sizeof(cmd), "%%H -quality %i -progressive -outfile %%s", 100 * info->quality / 256); + else if (!strcasecmp(ext, "jpg")) + g_snprintf(cmd, sizeof(cmd), "%%H -quality %i -progressive -outfile %%s", 100 * info->quality / 256); + else if (!strcasecmp(ext, "bmp")) + strcpy(cmd, "%Q %N/ppmtobmp >%s"); + else if (!strcasecmp(ext, "gif")) + strcpy(cmd, "%Q %N/ppmtogif -interlace >%s"); + else if (!strcasecmp(ext, "ilbm")) + strcpy(cmd, "%N/ppmtoilbm -24if -hires -lace -compress >%s"); + else if (!strcasecmp(ext, "ilb")) + strcpy(cmd, "%N/ppmtoilbm -24if -hires -lace -compress >%s"); + else if (!strcasecmp(ext, "iff")) + strcpy(cmd, "%N/ppmtoilbm -24if -hires -lace -compress >%s"); + else if (!strcasecmp(ext, "icr")) + strcpy(cmd, "%N/ppmtoicr >%s"); + else if (!strcasecmp(ext, "map")) + strcpy(cmd, "%N/ppmtomap >%s"); + else if (!strcasecmp(ext, "mit")) + strcpy(cmd, "%N/ppmtomitsu -sharpness 4 >%s"); + else if (!strcasecmp(ext, "mitsu")) + strcpy(cmd, "%N/ppmtomitsu -sharpness 4 >%s"); + else if (!strcasecmp(ext, "pcx")) + strcpy(cmd, "%N/ppmtopcx -24bit -packed >%s"); + else if (!strcasecmp(ext, "pgm")) + strcpy(cmd, "%N/ppmtopgm >%s"); + else if (!strcasecmp(ext, "pi1")) + strcpy(cmd, "%N/ppmtopi1 >%s"); + else if (!strcasecmp(ext, "pic")) + strcpy(cmd, "%Q %N/ppmtopict >%s"); + else if (!strcasecmp(ext, "pict")) + strcpy(cmd, "%Q %N/ppmtopict >%s"); + else if (!strcasecmp(ext, "pj")) + strcpy(cmd, "%N/ppmtopj >%s"); + else if (!strcasecmp(ext, "pjxl")) + strcpy(cmd, "%N/ppmtopjxl >%s"); + else if (!strcasecmp(ext, "puz")) + strcpy(cmd, "%N/ppmtopuzz >%s"); + else if (!strcasecmp(ext, "puzz")) + strcpy(cmd, "%N/ppmtopuzz >%s"); + else if (!strcasecmp(ext, "rgb3")) + strcpy(cmd, "%N/ppmtorgb3 >%s"); + else if (!strcasecmp(ext, "six")) + strcpy(cmd, "%N/ppmtosixel >%s"); + else if (!strcasecmp(ext, "sixel")) + strcpy(cmd, "%N/ppmtosizel >%s"); + else if (!strcasecmp(ext, "tga")) + strcpy(cmd, "%N/ppmtotga -rgb >%s"); + else if (!strcasecmp(ext, "targa")) + strcpy(cmd, "%N/ppmtotga -rgb >%s"); + else if (!strcasecmp(ext, "uil")) + strcpy(cmd, "%N/ppmtouil >%s"); + else if (!strcasecmp(ext, "xpm")) + strcpy(cmd, "%Q %N/ppmtoxpm >%s"); + else if (!strcasecmp(ext, "yuv")) + strcpy(cmd, "%N/ppmtoyuv >%s"); + else if (!strcasecmp(ext, "png")) + strcpy(cmd, "%N/pnmtopng >%s"); + else if (!strcasecmp(ext, "ps")) + strcpy(cmd, "%N/pnmtops -center -scale 100 >%s"); + else if (!strcasecmp(ext, "rast")) + strcpy(cmd, "%N/pnmtorast -rle >%s"); + else if (!strcasecmp(ext, "ras")) + strcpy(cmd, "%N/pnmtorast -rle >%s"); + else if (!strcasecmp(ext, "sgi")) + strcpy(cmd, "%N/pnmtosgi >%s"); + else if (!strcasecmp(ext, "sir")) + strcpy(cmd, "%N/pnmtosir >%s"); + else if (!strcasecmp(ext, "tif")) + strcpy(cmd, "%N/pnmtotiff -lzw >%s"); + else if (!strcasecmp(ext, "tiff")) + strcpy(cmd, "%N/pnmtotiff -lzw >%s"); + else if (!strcasecmp(ext, "xwd")) + strcpy(cmd, "%N/pnmtoxwd >%s"); + else + ext = ""; + if (ext[0]) + { + f = open_helper(cmd, file, "wb"); + if (f) + { + if (!fprintf(f, "P6\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height)) + { + close_helper(f); + return 0; + } + if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f)) + { + close_helper(f); + return 0; + } + if (close_helper(f)) + return 0; + return 1; + } + } + } + return 0; +} diff --git a/src/gdk_imlib/utils.c b/src/gdk_imlib/utils.c new file mode 100644 index 0000000000..039e93c4ea --- /dev/null +++ b/src/gdk_imlib/utils.c @@ -0,0 +1,1521 @@ +#define _GNU_SOURCE + +#include "../gdk_imlib/gdk_imlib.h" +#include "../gdk_imlib/gdk_imlib_private.h" + +void +gcalc_map_tables(GdkImlibImage * im) +{ + int i; + double g, b, c, ii, v; + + if (!im) + return; + + g = ((double)im->mod.gamma) / 256; + b = ((double)im->mod.brightness) / 256; + c = ((double)im->mod.contrast) / 256; + if (g < 0.01) + g = 0.01; + + for (i = 0; i < 256; i++) + { + ii = ((double)i) / 256; + v = ((ii - 0.5) * c) + 0.5 + (b - 1); + if (v > 0) + v = pow(((ii - 0.5) * c) + 0.5 + (b - 1), 1 / g) * 256; + else + v = 0; + if (v > 255) + v = 255; + else if (v < 0) + v = 0; + im->rmap[i] = (unsigned char)v; + im->gmap[i] = (unsigned char)v; + im->bmap[i] = (unsigned char)v; + } + g = ((double)im->rmod.gamma) / 256; + b = ((double)im->rmod.brightness) / 256; + c = ((double)im->rmod.contrast) / 256; + if (g < 0.01) + g = 0.01; + + for (i = 0; i < 256; i++) + { + ii = ((double)im->rmap[i]) / 256; + v = ((ii - 0.5) * c) + 0.5 + (b - 1); + if (v > 0) + v = pow(((ii - 0.5) * c) + 0.5 + (b - 1), 1 / g) * 256; + else + v = 0; + if (v > 255) + v = 255; + else if (v < 0) + v = 0; + im->rmap[i] = (unsigned char)v; + } + g = ((double)im->gmod.gamma) / 256; + b = ((double)im->gmod.brightness) / 256; + c = ((double)im->gmod.contrast) / 256; + if (g < 0.01) + g = 0.01; + + for (i = 0; i < 256; i++) + { + ii = ((double)im->gmap[i]) / 256; + v = ((ii - 0.5) * c) + 0.5 + (b - 1); + if (v > 0) + v = pow(((ii - 0.5) * c) + 0.5 + (b - 1), 1 / g) * 256; + else + v = 0; + if (v > 255) + v = 255; + else if (v < 0) + v = 0; + im->gmap[i] = (unsigned char)v; + } + g = ((double)im->bmod.gamma) / 256; + b = ((double)im->bmod.brightness) / 256; + c = ((double)im->bmod.contrast) / 256; + if (g < 0.01) + g = 0.01; + for (i = 0; i < 256; i++) + { + ii = ((double)im->bmap[i]) / 256; + v = ((ii - 0.5) * c) + 0.5 + (b - 1); + if (v > 0) + v = pow(((ii - 0.5) * c) + 0.5 + (b - 1), 1 / g) * 256; + else + v = 0; + if (v > 255) + v = 255; + else if (v < 0) + v = 0; + im->bmap[i] = (unsigned char)v; + } + gdirty_pixmaps(im); +} + +gint +gdk_imlib_load_file_to_pixmap(char *filename, GdkPixmap ** pmap, GdkBitmap ** mask) +{ + GdkImlibImage *im; + + im = gdk_imlib_load_image(filename); + if (!im) + { + if (pmap) + *pmap = NULL; + if (mask) + *mask = NULL; + return 0; + } + if (!gdk_imlib_render(im, im->rgb_width, im->rgb_height)) + { + gdk_imlib_destroy_image(im); + if (pmap) + *pmap = NULL; + if (mask) + *mask = NULL; + return 0; + } + if (pmap) + *pmap = gdk_imlib_move_image(im); + if (mask) + *mask = gdk_imlib_move_mask(im); + gdk_imlib_destroy_image(im); + return 1; +} + +void +gdk_imlib_set_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + if (!im || !mod) + return; + im->mod.gamma = mod->gamma; + im->mod.brightness = mod->brightness; + im->mod.contrast = mod->contrast; + gcalc_map_tables(im); +} + +void +gdk_imlib_set_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + if (!im || !mod) + return; + im->rmod.gamma = mod->gamma; + im->rmod.brightness = mod->brightness; + im->rmod.contrast = mod->contrast; + gcalc_map_tables(im); +} + +void +gdk_imlib_set_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + if (!im || !mod) + return; + im->gmod.gamma = mod->gamma; + im->gmod.brightness = mod->brightness; + im->gmod.contrast = mod->contrast; + gcalc_map_tables(im); +} + +void +gdk_imlib_set_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + if (!im | !mod) + return; + im->bmod.gamma = mod->gamma; + im->bmod.brightness = mod->brightness; + im->bmod.contrast = mod->contrast; + gcalc_map_tables(im); +} + +void +gdk_imlib_get_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + if (!im || !mod) + return; + mod->gamma = im->mod.gamma; + mod->brightness = im->mod.brightness; + mod->contrast = im->mod.contrast; + gcalc_map_tables(im); +} + +void +gdk_imlib_get_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + if (!im || !mod) + return; + mod->gamma = im->rmod.gamma; + mod->brightness = im->rmod.brightness; + mod->contrast = im->rmod.contrast; +} + +void +gdk_imlib_get_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + if (!im || !mod) + return; + mod->gamma = im->gmod.gamma; + mod->brightness = im->gmod.brightness; + mod->contrast = im->gmod.contrast; +} + +void +gdk_imlib_get_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + if (!im || !mod) + return; + mod->gamma = im->bmod.gamma; + mod->brightness = im->bmod.brightness; + mod->contrast = im->bmod.contrast; +} + +void +gdk_imlib_set_image_red_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + + if (!im || !mod) + return; + for (i = 0; i < 256; i++) + im->rmap[i] = mod[i]; + gdirty_pixmaps(im); + im->mod.contrast = 257; +} + +void +gdk_imlib_set_image_green_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + + if (!im || !mod) + return; + for (i = 0; i < 256; i++) + im->gmap[i] = mod[i]; + gdirty_pixmaps(im); + im->mod.contrast = 257; +} + +void +gdk_imlib_set_image_blue_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + + if (!im || !mod) + return; + for (i = 0; i < 256; i++) + im->bmap[i] = mod[i]; + gdirty_pixmaps(im); + im->mod.contrast = 257; +} + +void +gdk_imlib_get_image_red_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + + if ((!im) || (!mod)) + return; + for (i = 0; i < 256; i++) + mod[i] = im->rmap[i]; +} + +void +gdk_imlib_get_image_green_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + + if (!im || !mod) + return; + for (i = 0; i < 256; i++) + mod[i] = im->gmap[i]; +} + +void +gdk_imlib_get_image_blue_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + + if (!im || !mod) + return; + for (i = 0; i < 256; i++) + mod[i] = im->bmap[i]; +} + +void +gdk_imlib_apply_modifiers_to_rgb(GdkImlibImage * im) +{ + int x, y; + unsigned char *ptr; + + if (!im) + return; + ptr = im->rgb_data; + for (y = 0; y < im->rgb_height; y++) + { + for (x = 0; x < im->rgb_width; x++) + { + *ptr = im->rmap[*ptr]; + ptr++; + *ptr = im->gmap[*ptr]; + ptr++; + *ptr = im->bmap[*ptr]; + ptr++; + } + } + im->mod.gamma = 256; + im->mod.brightness = 256; + im->mod.contrast = 256; + im->rmod.gamma = 256; + im->rmod.brightness = 256; + im->rmod.contrast = 256; + im->gmod.gamma = 256; + im->gmod.brightness = 256; + im->gmod.contrast = 256; + im->bmod.gamma = 256; + im->bmod.brightness = 256; + im->bmod.contrast = 256; + gcalc_map_tables(im); + gdirty_images(im); + gdirty_pixmaps(im); +} + +void +gdk_imlib_crop_image(GdkImlibImage * im, gint x, gint y, gint w, gint h) +{ + unsigned char *data; + int xx, yy, w3, w4; + unsigned char *ptr1, *ptr2; + + if (!im) + return; + if (x < 0) + { + w += x; + x = 0; + } + if (y < 0) + { + h += y; + y = 0; + } + if (x >= im->rgb_width) + return; + if (y >= im->rgb_height) + return; + if (w <= 0) + return; + if (h <= 0) + return; + if (x + w > im->rgb_width) + w = im->rgb_width - x; + if (y + h > im->rgb_height) + h = im->rgb_height - y; + if (w <= 0) + return; + if (h <= 0) + return; + + w3 = im->rgb_width * 3; + w4 = (im->rgb_width - w) * 3; + data = malloc(w * h * 3); + if (data == NULL) + return; + ptr1 = im->rgb_data + (y * w3) + (x * 3); + ptr2 = data; + for (yy = 0; yy < h; yy++) + { + for (xx = 0; xx < w; xx++) + { + *ptr2++ = *ptr1++; + *ptr2++ = *ptr1++; + *ptr2++ = *ptr1++; + } + ptr1 += w4; + } + free(im->rgb_data); + im->rgb_data = data; + if (im->border.left > x) + im->border.left = im->border.left - x; + else + im->border.left = 0; + if (im->border.top > y) + im->border.top = im->border.top - y; + else + im->border.top = 0; + if (im->rgb_width - im->border.right < x + w) + im->border.right = im->border.right - (im->rgb_width - (x + w)); + else + im->border.right = 0; + if (im->rgb_height - im->border.bottom < y + h) + im->border.bottom = im->border.bottom - (im->rgb_height - (y + h)); + else + im->border.bottom = 0; + im->rgb_width = w; + im->rgb_height = h; + gdirty_images(im); + gdirty_pixmaps(im); +} + +void +gdk_imlib_changed_image(GdkImlibImage * im) +{ + if (!im) + return; + gdirty_images(im); + gdirty_pixmaps(im); +} + +void +gdk_imlib_apply_image(GdkImlibImage * im, GdkWindow * p) +{ + GdkPixmap *pp, *mm; + int w, h; + + if (!im || !p) + return; + gdk_window_get_size(p, &w, &h); + if (w <= 0 || h <= 0) + return; + gdk_imlib_render(im, w, h); + pp = gdk_imlib_move_image(im); + mm = gdk_imlib_move_mask(im); + gdk_window_set_back_pixmap(p, pp, 0); + if (mm) + gdk_window_shape_combine_mask(p, mm, 0, 0); + gdk_window_clear(p); + gdk_imlib_free_pixmap(pp); +} + +void +gdk_imlib_paste_image(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h) +{ + GdkGC *gc; + GdkPixmap *pp, *mm; + + if (!im || !p) + return; + if ((w <= 0) || (h <= 0)) + return; + gc = gdk_gc_new(p); + gdk_imlib_render(im, w, h); + pp = gdk_imlib_move_image(im); + mm = gdk_imlib_move_mask(im); + if (mm) + { + gdk_gc_set_clip_mask(gc, mm); + gdk_gc_set_clip_origin(gc, x, y); + } + gdk_draw_pixmap(p, gc, pp, 0, 0, x, y, w, h); + gdk_imlib_free_pixmap(pp); + gdk_gc_destroy(gc); +} + +void +gdk_imlib_paste_image_border(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h) +{ + GdkGC *gc; + GdkPixmap *pp, *mm; + + if (!im) + return; + + if (w <= 0 || h <= 0) + return; + gc = gdk_gc_new(p); + gdk_imlib_render(im, w, h); + pp = gdk_imlib_move_image(im); + mm = gdk_imlib_move_mask(im); + if (mm) + { + gdk_gc_set_clip_mask(gc, mm); + gdk_gc_set_clip_origin(gc, x, y); + } + if ((w <= (im->border.left + im->border.right)) || + (h <= (im->border.top + im->border.bottom))) + gdk_draw_pixmap(p, gc, pp, 0, 0, x, y, w, h); + else + { + gdk_draw_pixmap(p, gc, pp, 0, 0, x, y, w, im->border.top); + gdk_draw_pixmap(p, gc, pp, 0, h - im->border.bottom, + x, y + (h - im->border.bottom), + w, im->border.bottom); + gdk_draw_pixmap(p, gc, pp, 0, im->border.top, + x, y + im->border.top, + im->border.left, h - (im->border.top + im->border.bottom)); + gdk_draw_pixmap(p, gc, pp, w - im->border.right, h - im->border.bottom, + x + (w - im->border.right), y + (h - im->border.bottom), + im->border.right, h - (im->border.top + im->border.bottom)); + } + gdk_imlib_free_pixmap(pp); + gdk_gc_destroy(gc); +} + +void +gdk_imlib_flip_image_horizontal(GdkImlibImage * im) +{ + unsigned char *ptr1, *ptr2, r, rr; + int x, y; + int w3; + + if (!im) + return; + w3 = im->rgb_width * 3; + for (y = 0; y < im->rgb_height; y++) + { + ptr1 = im->rgb_data + (y * w3); + ptr2 = im->rgb_data + (y * w3) + w3 - 3; + for (x = 0; x < im->rgb_width >> 1; x++) + { + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + + r = *ptr1; + rr = *ptr2; + *ptr2 = r; + *ptr1++ = rr; + + ptr2 -= 5; + } + } + w3 = im->border.left; + im->border.left = im->border.right; + im->border.right = w3; + gdirty_images(im); + gdirty_pixmaps(im); +} + +void +gdk_imlib_flip_image_vertical(GdkImlibImage * im) +{ + unsigned char *ptr1, *ptr2, r, rr; + int x, y, yy; + int w3; + + if (!im) + return; + + w3 = im->rgb_width * 3; + for (yy = im->rgb_height - 1, y = 0; y < im->rgb_height >> 1; y++, yy--) + { + ptr1 = im->rgb_data + (y * w3); + ptr2 = im->rgb_data + (yy * w3); + for (x = 0; x < im->rgb_width; x++) + { + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + } + } + w3 = im->border.top; + im->border.top = im->border.bottom; + im->border.bottom = w3; + gdirty_images(im); + gdirty_pixmaps(im); +} + +void +gdk_imlib_rotate_image(GdkImlibImage * im, gint d) +{ + unsigned char *data; + int x, y, w3, w4; + unsigned char *ptr1, *ptr2; + + if (!im) + return; + w3 = im->rgb_width * 3; + w4 = im->rgb_height * 3; + + data = malloc(im->rgb_width * im->rgb_height * 3); + if (data == NULL) + return; + + for (y = 0; y < im->rgb_height; y++) + { + ptr1 = im->rgb_data + (y * w3); + ptr2 = data + (y * 3); + for (x = 0; x < im->rgb_width; x++) + { + *ptr2++ = *ptr1++; + *ptr2++ = *ptr1++; + *ptr2 = *ptr1++; + ptr2 += w4 - 2; + } + } + free(im->rgb_data); + im->rgb_data = data; + w3 = im->rgb_width; + im->rgb_width = im->rgb_height; + im->rgb_height = w3; + w3 = im->border.top; + im->border.top = im->border.left; + im->border.left = w3; + w3 = im->border.bottom; + im->border.bottom = im->border.right; + im->border.right = w3; + gdirty_images(im); + gdirty_pixmaps(im); +} + +GdkImlibImage * +gdk_imlib_create_image_from_data(unsigned char *data, unsigned char *alpha, gint w, gint h) +{ + GdkImlibImage *im; + char s[128]; + + if (!data || w <= 0 || h <= 0) + return NULL; + + im = malloc(sizeof(GdkImlibImage)); + if (!im) + return NULL; + + im->rgb_width = w; + im->rgb_height = h; + im->rgb_data = malloc(im->rgb_width * im->rgb_height * 3); + if (!im->rgb_data) + { + free(im); + return NULL; + } + + memcpy(im->rgb_data, data, im->rgb_width * im->rgb_height * 3); +/* im->alpha_data=alpha; */ + im->alpha_data = NULL; + g_snprintf(s, sizeof(s), "creat_%x_%x", (int)time(NULL), (int)rand()); + im->filename = malloc(strlen(s) + 1); + if (im->filename) + strcpy(im->filename, s); + im->width = 0; + im->height = 0; + im->shape_color.r = -1; + im->shape_color.g = -1; + im->shape_color.b = -1; + im->border.left = 0; + im->border.right = 0; + im->border.top = 0; + im->border.bottom = 0; + im->pixmap = NULL; + im->shape_mask = NULL; + im->cache = 1; + im->mod.gamma = id->mod.gamma; + im->mod.brightness = id->mod.brightness; + im->mod.contrast = id->mod.contrast; + im->rmod.gamma = id->rmod.gamma; + im->rmod.brightness = id->rmod.brightness; + im->rmod.contrast = id->rmod.contrast; + im->gmod.gamma = id->gmod.gamma; + im->gmod.brightness = id->gmod.brightness; + im->gmod.contrast = id->gmod.contrast; + im->bmod.gamma = id->bmod.gamma; + im->bmod.brightness = id->bmod.brightness; + im->bmod.contrast = id->bmod.contrast; + if (id->cache.on_image) + gadd_image(im, im->filename); + gcalc_map_tables(im); + return im; +} + +GdkImlibImage * +gdk_imlib_clone_image(GdkImlibImage * im) +{ + GdkImlibImage *im2; + char *s; + + if (!im) + return NULL; + im2 = malloc(sizeof(GdkImlibImage)); + if (!im2) + return NULL; + im2->rgb_width = im->rgb_width; + im2->rgb_height = im->rgb_height; + im2->rgb_data = malloc(im2->rgb_width * im2->rgb_height * 3); + if (!im2->rgb_data) + { + free(im2); + return NULL; + } + + memcpy(im2->rgb_data, im->rgb_data, im2->rgb_width * im2->rgb_height * 3); + if (im->alpha_data) + { + im2->alpha_data = malloc(im2->rgb_width * im2->rgb_height); + if (!im2->alpha_data) + { + free(im2->rgb_data); + free(im2); + return NULL; + } + memcpy(im2->alpha_data, im->alpha_data, im2->rgb_width * im2->rgb_height); + } + else + im2->alpha_data = NULL; + s = malloc(strlen(im->filename) + 320); + if (s) + { + g_snprintf(s, sizeof(s), "%s_%x_%x", im->filename, (int)time(NULL), (int)rand()); + im2->filename = malloc(strlen(s) + 1); + if (im2->filename) + strcpy(im2->filename, s); + free(s); + } + else + im2->filename = NULL; + im2->width = 0; + im2->height = 0; + im2->shape_color.r = im->shape_color.r; + im2->shape_color.g = im->shape_color.g; + im2->shape_color.b = im->shape_color.b; + im2->border.left = im->border.left; + im2->border.right = im->border.right; + im2->border.top = im->border.top; + im2->border.bottom = im->border.bottom; + im2->pixmap = NULL; + im2->shape_mask = NULL; + im2->cache = 1; + im2->mod.gamma = im->mod.gamma; + im2->mod.brightness = im->mod.brightness; + im2->mod.contrast = im->mod.contrast; + im2->rmod.gamma = im->rmod.gamma; + im2->rmod.brightness = im->rmod.brightness; + im2->rmod.contrast = im->rmod.contrast; + im2->gmod.gamma = im->gmod.gamma; + im2->gmod.brightness = im->gmod.brightness; + im2->gmod.contrast = im->gmod.contrast; + im2->bmod.gamma = im->bmod.gamma; + im2->bmod.brightness = im->bmod.brightness; + im2->bmod.contrast = im->bmod.contrast; + gcalc_map_tables(im2); + if (id->cache.on_image) + gadd_image(im2, im2->filename); + return im2; +} + +GdkImlibImage * +gdk_imlib_clone_scaled_image(GdkImlibImage * im, int w, int h) +{ + GdkImlibImage *im2; + char *s; + + if (!im || w <= 0 || h <= 0) + return NULL; + + im2 = malloc(sizeof(GdkImlibImage)); + if (!im2) + return NULL; + im2->rgb_width = w; + im2->rgb_height = h; + im2->rgb_data = malloc(w * h * 3); + if (!im2->rgb_data) + { + free(im2); + return NULL; + } + { + int x, y, *xarray; + unsigned char **yarray, *ptr, *ptr2, *ptr22; + int l, r, m, pos, inc, w3; + + xarray = malloc(sizeof(int) * w); + + if (!xarray) + { + fprintf(stderr, "ERROR: Cannot allocate X co-ord buffer\n"); + free(im2->rgb_data); + free(im2); + return NULL; + } + yarray = malloc(sizeof(unsigned char *) * h); + + if (!yarray) + { + fprintf(stderr, "ERROR: Cannot allocate Y co-ord buffer\n"); + free(xarray); + free(im2->rgb_data); + free(im2); + return NULL; + } + ptr22 = im->rgb_data; + w3 = im->rgb_width * 3; + inc = 0; + if (w < im->border.left + im->border.right) + { + l = w >> 1; + r = w - l; + m = 0; + } + else + { + l = im->border.left; + r = im->border.right; + m = w - l - r; + } + if (m > 0) + inc = ((im->rgb_width - im->border.left - im->border.right) << 16) / m; + pos = 0; + if (l) + { + for (x = 0; x < l; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += 0x10000; + } + } + if (m) + { + for (x = l; x < l + m; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += inc; + } + } + pos = (im->rgb_width - r) << 16; + for (x = w - r; x < w; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += 0x10000; + } + + if (h < im->border.top + im->border.bottom) + { + l = h >> 1; + r = h - l; + m = 0; + } + else + { + l = im->border.top; + r = im->border.bottom; + m = h - l - r; + } + if (m > 0) + inc = ((im->rgb_height - im->border.top - im->border.bottom) << 16) / m; + pos = 0; + for (x = 0; x < l; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += 0x10000; + } + if (m) + { + for (x = l; x < l + m; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += inc; + } + } + pos = (im->rgb_height - r) << 16; + for (x = h - r; x < h; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += 0x10000; + } + + ptr = im2->rgb_data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + *ptr++ = (int)*ptr2++; + *ptr++ = (int)*ptr2++; + *ptr++ = (int)*ptr2; + } + } + } + if (im->alpha_data) + { + im2->alpha_data = NULL; + /* yet to be filled in */ + } + else + im2->alpha_data = NULL; + + s = malloc(strlen(im->filename) + 320); + if (s) + { + g_snprintf(s, sizeof(s), "%s_%x_%x_%x_%x", im->filename, (int)time(NULL), w, h, (int)rand()); + im2->filename = malloc(strlen(s) + 1); + if (im2->filename) + strcpy(im2->filename, s); + free(s); + } + else + im2->filename = NULL; + im2->width = 0; + im2->height = 0; + im2->shape_color.r = im->shape_color.r; + im2->shape_color.g = im->shape_color.g; + im2->shape_color.b = im->shape_color.b; + im2->border.left = im->border.left; + im2->border.right = im->border.right; + im2->border.top = im->border.top; + im2->border.bottom = im->border.bottom; + im2->pixmap = NULL; + im2->shape_mask = NULL; + im2->cache = 1; + im2->mod.gamma = im->mod.gamma; + im2->mod.brightness = im->mod.brightness; + im2->mod.contrast = im->mod.contrast; + im2->rmod.gamma = im->rmod.gamma; + im2->rmod.brightness = im->rmod.brightness; + im2->rmod.contrast = im->rmod.contrast; + im2->gmod.gamma = im->gmod.gamma; + im2->gmod.brightness = im->gmod.brightness; + im2->gmod.contrast = im->gmod.contrast; + im2->bmod.gamma = im->bmod.gamma; + im2->bmod.brightness = im->bmod.brightness; + im2->bmod.contrast = im->bmod.contrast; + gcalc_map_tables(im2); + if (id->cache.on_image) + gadd_image(im2, im2->filename); + return im2; +} + +GdkImlibImage * +gdk_imlib_create_image_from_xpm_data(char **data) +{ + GdkImlibImage *im; + unsigned char *ptr; + int /* pc, */ c, i, j, k, ncolors, cpp, comment, transp, quote, + context, len, count, done; + int w, h; + char *line, s[65536], tok[65536], col[65536]; + XColor xcol; + struct _cmap + { + char str[8]; + char transp; + int r, g, b; + } + *cmap; + + int lookup[128][128]; + + cmap = NULL; + j = 0; + if (!data) + return NULL; + im = malloc(sizeof(GdkImlibImage)); + if (!im) + return NULL; + count = 0; + transp = 0; + done = 0; + + c = ' '; + comment = 0; + quote = 0; + context = 0; + ptr = NULL; + + while (!done) + { + line = data[count++]; + if (context == 0) + { + /* Header */ + sscanf(line, "%i %i %i %i", &w, &h, &ncolors, &cpp); + if (cpp > 7) + { + fprintf(stderr, "gdk_imlib ERROR: XPM data with characters per pixel > 7 not supported\n"); + free(im); + return NULL; + } + if (w > 32767) + { + fprintf(stderr, "gdk_imlib ERROR: Image width > 32767 pixels for data\n"); + free(im); + return NULL; + } + if (h > 32767) + { + fprintf(stderr, "gdk_imlib ERROR: Image height > 32767 pixels for data\n"); + free(im); + return NULL; + } + cmap = malloc(sizeof(struct _cmap) * ncolors); + + if (!cmap) + { + free(im); + return NULL; + } + im->rgb_width = w; + im->rgb_height = h; + im->rgb_data = malloc(im->rgb_width * im->rgb_height * 3); + if (!im->rgb_data) + { + free(cmap); + free(im); + return NULL; + } + im->alpha_data = NULL; + g_snprintf(s, sizeof(s), "creat_%x_%x", (int)time(NULL), (int)rand()); + im->filename = malloc(strlen(s) + 1); + if (im->filename) + strcpy(im->filename, s); + im->width = 0; + im->height = 0; + im->border.left = 0; + im->border.right = 0; + im->border.top = 0; + im->border.bottom = 0; + im->pixmap = NULL; + im->shape_mask = NULL; + im->cache = 1; + im->mod.gamma = id->mod.gamma; + im->mod.brightness = id->mod.brightness; + im->mod.contrast = id->mod.contrast; + im->rmod.gamma = id->rmod.gamma; + im->rmod.brightness = id->rmod.brightness; + im->rmod.contrast = id->rmod.contrast; + im->gmod.gamma = id->gmod.gamma; + im->gmod.brightness = id->gmod.brightness; + im->gmod.contrast = id->gmod.contrast; + im->bmod.gamma = id->bmod.gamma; + im->bmod.brightness = id->bmod.brightness; + im->bmod.contrast = id->bmod.contrast; + ptr = im->rgb_data; + j = 0; + context++; + } + else if (context == 1) + { + int colptr; + + /* Color Table */ + if (j < ncolors) + { + tok[0] = 0; + col[0] = 0; + s[0] = 0; + colptr = 0; + len = strlen(line); + strncpy(cmap[j].str, line, cpp); + cmap[j].str[cpp] = 0; + cmap[j].r = -1; + cmap[j].transp = 0; + for (k = cpp; k < len; k++) + { + if (line[k] != ' ') + { + sscanf(&line[k], "%65536s", s); + k += strlen(s); + if ((!strcmp(s, "m")) || (!strcmp(s, "s")) || + (!strcmp(s, "g4")) || (!strcmp(s, "g")) || + (!strcmp(s, "c")) || (k >= len)) + { + if (k >= len) + { + int ls; + + ls = strlen(s); + + if (col[0] && colptr < sizeof(col)) + { + strcpy(col + colptr, " "); + colptr++; + } + if (colptr + ls <= sizeof(col)) + { + strcpy(col + colptr, s); + colptr += ls; + } + + } + if (col[0]) + { + if (!strcasecmp(col, "none")) + { + transp = 1; + cmap[j].transp = 1; + } + else + { + if ((cmap[j].r < 0) || + (!strcmp(tok, "c"))) + { + XParseColor(id->x.disp, + id->x.root_cmap, + col, &xcol); + cmap[j].r = xcol.red >> 8; + cmap[j].g = xcol.green >> 8; + cmap[j].b = xcol.blue >> 8; + if ((cmap[j].r == 255) && + (cmap[j].g == 0) && + (cmap[j].b == 255)) + cmap[j].r = 254; + } + } + } + if (strlen(s) < sizeof(tok)) + strcpy(tok, s); + col[0] = 0; + } + else + { + int ls; + + ls = strlen(s); + + if (col[0] && colptr < sizeof(col)) + { + strcpy(col + colptr, " "); + colptr++; + } + if (ls + colptr < sizeof(col)) + { + strcpy(col + colptr, s); + colptr += ls; + } + } + } + } + } + j++; + if (j >= ncolors) + { + if (cpp == 1) + for (i = 0; i < ncolors; i++) + lookup[(int)cmap[i].str[0]][(int)cmap[i].str[1]] = i; + if (cpp == 2) + for (i = 0; i < ncolors; i++) + lookup[(int)cmap[i].str[0]][(int)cmap[i].str[1]] = i; + context++; + } + } + else + { + /* Image Data */ + i = 0; + if (cpp == 0) + { + } + else if (cpp == 1) + { + if (transp) + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + col[0] = line[i]; + if (cmap[lookup[(int)col[0]][0]].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].b; + } + } + } + else + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + col[0] = line[i]; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][0]].b; + } + } + } + else if (cpp == 2) + { + if (transp) + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + col[0] = line[i++]; + col[1] = line[i]; + if (cmap[lookup[(int)col[0]][(int)col[1]]].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].b; + } + } + } + else + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + col[0] = line[i++]; + col[1] = line[i]; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0]][(int)col[1]]].b; + } + } + } + else + { + if (transp) + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + for (j = 0; j < cpp; j++, i++) + { + col[j] = line[i]; + } + col[j] = 0; + i--; + for (j = 0; j < ncolors; j++) + { + if (!strcmp(col, cmap[j].str)) + { + if (cmap[j].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[j].r; + *ptr++ = (unsigned char)cmap[j].g; + *ptr++ = (unsigned char)cmap[j].b; + } + j = ncolors; + } + } + } + } + else + { + for (i = 0; ((i < 65536) && (line[i])); i++) + { + for (j = 0; j < cpp; j++, i++) + { + col[j] = line[i]; + } + col[j] = 0; + i--; + for (j = 0; j < ncolors; j++) + { + if (!strcmp(col, cmap[j].str)) + { + *ptr++ = (unsigned char)cmap[j].r; + *ptr++ = (unsigned char)cmap[j].g; + *ptr++ = (unsigned char)cmap[j].b; + j = ncolors; + } + } + } + } + } + } + if ((ptr) && ((ptr - im->rgb_data) >= w * h * 3)) + done = 1; + } + if (!transp) + { + im->shape_color.r = -1; + im->shape_color.g = -1; + im->shape_color.b = -1; + } + else + { + im->shape_color.r = 255; + im->shape_color.g = 0; + im->shape_color.b = 255; + } + if (id->cache.on_image) + gadd_image(im, im->filename); + gcalc_map_tables(im); + free(cmap); + return im; +} + +gint +gdk_imlib_data_to_pixmap(char **data, GdkPixmap ** pmap, GdkBitmap ** mask) +{ + GdkImlibImage *im; + + im = gdk_imlib_create_image_from_xpm_data(data); + if (!im) + { + if (pmap) + *pmap = NULL; + if (mask) + *mask = NULL; + return 0; + } + if (!gdk_imlib_render(im, im->rgb_width, im->rgb_height)) + { + gdk_imlib_destroy_image(im); + if (pmap) + *pmap = NULL; + if (mask) + *mask = NULL; + return 0; + } + if (pmap) + *pmap = gdk_imlib_move_image(im); + if (mask) + *mask = gdk_imlib_move_mask(im); + gdk_imlib_kill_image(im); + return 1; +} + +#include +#include + +/* + * Helper library + */ + +static int hpid; +void *oldpiper; /* actually sighandler_t but BSD uses sig_t. */ + +FILE * +open_helper(const char *instring, const char *fn, const char *mode) +{ + char buf[256]; /* This is safe since our input strings + + * + * * are bounded */ + static char *vec[16]; + char *p = strdup(instring); + char *pp; + char *ep; + int vn = 0; + int pid; + FILE *fp = NULL; + char *ofil = NULL; + int ofd = -1; + + int pfd[2]; + + if (p == NULL) + return NULL; + + if (strncmp(instring, "%Q", 2) == 0) + { + /* + * Generate a quanting pipeline + */ + fprintf(stderr, "Not currently supported: install ImageMagic.\n"); + return NULL; + } + /* + * Ok split the instring on spaces and translate + * %C %P %F and %s + * + * FIXME: We need to handle a format string that begins + * %Q to indicate an 8bit quant in the pipeline first. + */ + + pp = p; + + while (vn < 15) + { + while (*pp && isspace(*pp)) + pp++; + ep = pp; + while (*ep && !isspace(*ep)) + ep++; + if (*pp == 0) + break; + /* pp->ep is now the input string block */ + if (*ep) + *ep++ = 0; + + if (strcmp(pp, "%s") == 0) + vec[vn] = strdup(fn); + else if (strncmp(pp, "%P/", 3) == 0) + { + strcpy(buf, NETPBM_PATH); + strcat(buf, pp + 2); + if ((vec[vn] = strdup(buf)) == NULL) + break; + } + else if (strncmp(pp, "%J", 3) == 0) + { + if ((vec[vn] = strdup(DJPEG_PROG)) == NULL) + break; + } + else if (strncmp(pp, "%H", 3) == 0) + { + if ((vec[vn] = strdup(CJPEG_PROG)) == NULL) + break; + } + else if (strncmp(pp, "%C/", 3) == 0) + { + strcpy(buf, CONVERT_PATH); + strcat(buf, pp + 2); + if ((vec[vn] = strdup(buf)) == NULL) + break; + } + else if (strncmp(pp, ">%s", 3) == 0) + { + ofil = pp; + vn++; + pp = ep; + continue; + } + else + { + if ((vec[vn] = strdup(pp)) == NULL) + break; + } + vn++; + pp = ep; + } + + vec[vn] = NULL; + + if (pipe(pfd) == -1) + goto oops; + + if (*mode == 'r') + { + fp = fdopen(pfd[0], "r"); + if (fp == NULL) + goto oops; + } + else if (*mode == 'w') + { + fp = fdopen(pfd[1], "w"); + if (fp == NULL) + goto oops; + } + else + goto oops; + + if (ofil != NULL) + if ((ofd = open(ofil, O_WRONLY | O_TRUNC | O_CREAT)) == -1) + goto oops; + + switch (pid = fork()) + { + case -1: + break; + case 0: + signal(SIGPIPE, SIG_DFL); + if (*mode == 'r') + dup2(pfd[1], 1); + if (*mode == 'w') + { + dup2(pfd[0], 0); + if (ofd != -1) + { + dup2(ofd, 1); + close(1); + } + } + close(pfd[0]); + close(pfd[1]); + execv(vec[0], vec); + perror(vec[0]); + /* + * This MUST be _exit or we will hit the SIGPIPE + * handler in ways we dont want. We want our parent + * to flush the inherited file buffers not us. + */ + _exit(1); + default: + hpid = pid; + + if (ofd != -1) + close(ofd); + if (*mode == 'r') + close(pfd[1]); + else + close(pfd[0]); + } + for (vn = 0; vn < 16; vn++) + if (vec[vn]) + free(vec[vn]); + oldpiper = signal(SIGPIPE, SIG_IGN); + return fp; + + oops: + if (ofd != -1) + close(ofd); + if (fp) + fclose(fp); + for (vn = 0; vn < 16; vn++) + if (vec[vn]) + free(vec[vn]); + return NULL; +} + +int +close_helper(FILE * fp) +{ + int info; + + fclose(fp); + signal(SIGPIPE, oldpiper); + waitpid(hpid, &info, 0); + return WEXITSTATUS(info); +} diff --git a/src/msw/Y_TAB.C b/src/msw/Y_TAB.C new file mode 100644 index 0000000000..e1e62c59f6 --- /dev/null +++ b/src/msw/Y_TAB.C @@ -0,0 +1,521 @@ +#ifndef lint +static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 +#define yyclearin (yychar=(-1)) +#define yyerrok (yyerrflag=0) +#define YYRECOVERING (yyerrflag!=0) +#define YYPREFIX "yy" +#line 2 "../common/parser.y" +#include +#include "wx/expr.h" + +#ifndef __EXTERN_C__ +#define __EXTERN_C__ 1 +#endif + +#if defined(__cplusplus) || defined(__STDC__) +#if defined(__cplusplus) && defined(__EXTERN_C__) +extern "C" { +#endif +#endif +int yylex(void); +int yylook(void); +int yywrap(void); +int yyback(int *, int); +void yyerror(char *); + +/* You may need to put /DLEX_SCANNER in your makefile + * if you're using LEX! + */ +#ifdef LEX_SCANNER +/* int yyoutput(int); */ +void yyoutput(int); +#else +void yyoutput(int); +#endif + +#if defined(__cplusplus) || defined(__STDC__) +#if defined(__cplusplus) && defined(__EXTERN_C__) +} +#endif +#endif +#line 37 "../common/parser.y" +typedef union { + char *s; +/* struct pexpr *expr; */ +} YYSTYPE; +#line 51 "y_tab.c" +#define INTEGER 1 +#define WORD 2 +#define STRING 3 +#define PERIOD 13 +#define OPEN 4 +#define CLOSE 5 +#define COMMA 6 +#define NEWLINE 7 +#define ERROR 8 +#define OPEN_SQUARE 9 +#define CLOSE_SQUARE 10 +#define EQUALS 11 +#define EXP 14 +#define YYERRCODE 256 +short yylhs[] = { -1, + 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, + 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, +}; +short yylen[] = { 2, + 0, 2, 2, 2, 2, 4, 2, 3, 0, 1, + 3, 3, 1, 1, 1, 1, 3, 3, 5, 1, +}; +short yydefred[] = { 1, + 0, 0, 0, 0, 2, 0, 5, 3, 0, 0, + 0, 15, 7, 20, 0, 0, 13, 4, 0, 0, + 0, 0, 8, 0, 6, 0, 18, 0, 12, 11, + 0, 19, +}; +short yydgoto[] = { 1, + 5, 14, 15, 16, 17, +}; +short yysindex[] = { 0, + -2, 9, 2, 1, 0, 10, 0, 0, 11, -5, + 17, 0, 0, 0, 14, -1, 0, 0, 33, 38, + 41, 16, 0, 11, 0, 29, 0, 40, 0, 0, + 44, 0, +}; +short yyrindex[] = { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 42, 21, + 24, 0, 0, 0, 0, 30, 0, 0, 0, 0, + 0, 0, 0, 31, 0, 27, 0, 24, 0, 0, + 0, 0, +}; +short yygindex[] = { 0, + 0, 45, -8, 0, 26, +}; +#define YYTABLESIZE 254 +short yytable[] = { 3, + 19, 10, 11, 12, 24, 9, 4, 20, 21, 4, + 13, 10, 11, 12, 8, 30, 10, 28, 12, 4, + 9, 7, 18, 23, 4, 16, 16, 22, 14, 14, + 16, 17, 17, 14, 10, 9, 17, 25, 26, 10, + 9, 27, 31, 9, 32, 6, 9, 29, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 2, +}; +short yycheck[] = { 2, + 9, 1, 2, 3, 6, 4, 9, 13, 14, 9, + 10, 1, 2, 3, 13, 24, 1, 2, 3, 9, + 4, 13, 13, 10, 9, 5, 6, 11, 5, 6, + 10, 5, 6, 10, 5, 5, 10, 5, 1, 10, + 10, 1, 14, 4, 1, 1, 5, 22, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 256, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 14 +#if YYDEBUG +char *yyname[] = { +"end-of-file","INTEGER","WORD","STRING","OPEN","CLOSE","COMMA","NEWLINE", +"ERROR","OPEN_SQUARE","CLOSE_SQUARE","EQUALS",0,"PERIOD","EXP", +}; +char *yyrule[] = { +"$accept : commands", +"commands :", +"commands : commands command", +"command : WORD PERIOD", +"command : expr PERIOD", +"command : error PERIOD", +"expr : WORD OPEN arglist CLOSE", +"expr : OPEN_SQUARE CLOSE_SQUARE", +"expr : OPEN_SQUARE arglist CLOSE_SQUARE", +"arglist :", +"arglist : arg", +"arglist : arg COMMA arglist", +"arg : WORD EQUALS arg1", +"arg : arg1", +"arg1 : WORD", +"arg1 : STRING", +"arg1 : INTEGER", +"arg1 : INTEGER PERIOD INTEGER", +"arg1 : INTEGER EXP INTEGER", +"arg1 : INTEGER PERIOD INTEGER EXP INTEGER", +"arg1 : expr", +}; +#endif +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif +int yydebug; +int yynerrs; +int yyerrflag; +int yychar; +short *yyssp; +YYSTYPE *yyvsp; +YYSTYPE yyval; +YYSTYPE yylval; +short yyss[YYSTACKSIZE]; +YYSTYPE yyvs[YYSTACKSIZE]; +#define yystacksize YYSTACKSIZE +#line 119 "../common/parser.y" + +#include "../common/lex_yy.c" + +/* +void yyerror(s) +char *s; +{ + syntax_error(s); +} +*/ + +/* Ansi prototype. If this doesn't work for you... uncomment + the above instead. + */ + +void yyerror(char *s) +{ + syntax_error(s); +} + +/* + * Unfortunately, my DOS version of FLEX + * requires yywrap to be #def'ed, whereas + * the UNIX flex expects a proper function. + */ + +/* Not sure if __SC__ is the appropriate thing + * to test + */ + +#ifndef __SC__ +#ifdef USE_DEFINE +#ifndef yywrap +#define yywrap() 1 +#endif +#else if !defined(__alpha) && !defined(__ultrix) +int yywrap() { return 1; } +#endif +#endif +#line 251 "y_tab.c" +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab +int +yyparse() +{ + register int yym, yyn, yystate; +#if YYDEBUG + register char *yys; + extern char *getenv(); + + if (yys = getenv("YYDEBUG")) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = (-1); + + yyssp = yyss; + yyvsp = yyvs; + *yyssp = yystate = 0; + +yyloop: + if (yyn = yydefred[yystate]) goto yyreduce; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + yychar = (-1); + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; +#ifdef lint + goto yynewerror; +#endif +yynewerror: + yyerror("syntax error"); +#ifdef lint + goto yyerrlab; +#endif +yyerrlab: + ++yynerrs; +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yyssp); +#endif + if (yyssp <= yyss) goto yyabort; + --yyssp; + --yyvsp; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = (-1); + goto yyloop; + } +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + yyval = yyvsp[1-yym]; + switch (yyn) + { +case 3: +#line 69 "../common/parser.y" +{process_command(proio_cons(make_word(yyvsp[-1].s), NULL)); free(yyvsp[-1].s);} +break; +case 4: +#line 71 "../common/parser.y" +{process_command(yyvsp[-1].s);} +break; +case 5: +#line 73 "../common/parser.y" +{syntax_error("Unrecognized command.");} +break; +case 6: +#line 77 "../common/parser.y" +{yyval.s = proio_cons(make_word(yyvsp[-3].s), yyvsp[-1].s); free(yyvsp[-3].s);} +break; +case 7: +#line 79 "../common/parser.y" +{yyval.s = proio_cons(NULL, NULL);} +break; +case 8: +#line 81 "../common/parser.y" +{yyval.s = yyvsp[-1].s; } +break; +case 9: +#line 85 "../common/parser.y" +{yyval.s = NULL;} +break; +case 10: +#line 87 "../common/parser.y" +{yyval.s = proio_cons(yyvsp[0].s, NULL);} +break; +case 11: +#line 90 "../common/parser.y" +{yyval.s = proio_cons(yyvsp[-2].s, yyvsp[0].s);} +break; +case 12: +#line 94 "../common/parser.y" +{yyval.s = proio_cons(make_word("="), proio_cons(make_word(yyvsp[-2].s), proio_cons(yyvsp[0].s, NULL))); + free(yyvsp[-2].s); } +break; +case 13: +#line 97 "../common/parser.y" +{yyval.s = yyvsp[0].s; } +break; +case 14: +#line 100 "../common/parser.y" +{yyval.s = make_word(yyvsp[0].s); free(yyvsp[0].s);} +break; +case 15: +#line 102 "../common/parser.y" +{yyval.s = make_string(yyvsp[0].s); free(yyvsp[0].s);} +break; +case 16: +#line 104 "../common/parser.y" +{yyval.s = make_integer(yyvsp[0].s); free(yyvsp[0].s);} +break; +case 17: +#line 106 "../common/parser.y" +{yyval.s = make_real(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); } +break; +case 18: +#line 108 "../common/parser.y" +{yyval.s = make_exp(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); } +break; +case 19: +#line 111 "../common/parser.y" +{yyval.s = make_exp2(yyvsp[-4].s, yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-4].s); free(yyvsp[-2].s); + free(yyvsp[0].s); } +break; +case 20: +#line 115 "../common/parser.y" +{yyval.s = yyvsp[0].s;} +break; +#line 466 "y_tab.c" + } + yyssp -= yym; + yystate = *yyssp; + yyvsp -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yyssp = YYFINAL; + *++yyvsp = yyval; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yyssp, yystate); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate; + *++yyvsp = yyval; + goto yyloop; +yyoverflow: + yyerror("yacc stack overflow"); +yyabort: + return (1); +yyaccept: + return (0); +} diff --git a/src/msw/xfspline.inc b/src/msw/xfspline.inc new file mode 100644 index 0000000000..792cf3e23f --- /dev/null +++ b/src/msw/xfspline.inc @@ -0,0 +1,355 @@ +/* + * File: xfspline.cc + * Purpose: + * Author: Julian Smart + * Created: 1993 + * Updated: August 1994 + * RCS_ID: $Id$ + * Copyright: (c) 1993, AIAI, University of Edinburgh + */ + +// Must be a comment as this file is #include\'d by wb_dc.cc +/* static const char sccsid[] = "@(#)xfspline.cc 1.3 5/9/94"; */ + +/* + * FIG : Facility for Interactive Generation of figures + * Copyright (c) 1985 by Supoj Sutanthavibul + */ + + +#if USE_SPLINES + +////#define wx_round(a) (int)((a)+.5) +//#define wx_round(a) (a) + +class wxSpline: public wxObject +{ + public: + int type; + wxList *points; + + wxSpline(wxList *list); + void DeletePoints(void); + + // Doesn't delete points + ~wxSpline(void); +}; + +void wx_draw_open_spline(wxDC *dc, wxSpline *spline); + +#if USE_POSTSCRIPT +void wx_draw_open_spline_ps(wxPostScriptDC *dc, wxSpline *s); +#endif + +void wx_quadratic_spline(double a1, double b1, double a2, double b2, + double a3, double b3, double a4, double b4); +void wx_clear_stack(void); +int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, + double *y3, double *x4, double *y4); +void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, + double x4, double y4); +static bool wx_spline_add_point(double x, double y); +static void wx_spline_draw_point_array(wxDC *dc); +wxSpline *wx_make_spline(int x1, int y1, int x2, int y2, int x3, int y3); + +void wxDC::DrawSpline(int n, wxPoint points[]) +{ + wxList list; + int i; + for (i =0; i < n; i++) + list.Append((wxObject*)&points[i]); + DrawSpline((wxList *)&list); +} + +void wxDC::DrawSpline(wxList *list) +{ + wxSpline spline(list); + + wx_draw_open_spline(this, &spline); +} + + +wxList wx_spline_point_list; + +void wx_draw_open_spline(wxDC *dc, wxSpline *spline) +{ + wxPoint *p; + double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; + double x1, y1, x2, y2; + + wxNode *node = spline->points->First(); + p = (wxPoint *)node->Data(); + + x1 = p->x; + y1 = p->y; + + node = node->Next(); + p = (wxPoint *)node->Data(); + + x2 = p->x; + y2 = p->y; + cx1 = (double)((x1 + x2) / 2); + cy1 = (double)((y1 + y2) / 2); + cx2 = (double)((cx1 + x2) / 2); + cy2 = (double)((cy1 + y2) / 2); + + wx_spline_add_point(x1, y1); + + while ((node = node->Next()) != NULL) + { + p = (wxPoint *)node->Data(); + x1 = x2; + y1 = y2; + x2 = p->x; + y2 = p->y; + cx4 = (double)(x1 + x2) / 2; + cy4 = (double)(y1 + y2) / 2; + cx3 = (double)(x1 + cx4) / 2; + cy3 = (double)(y1 + cy4) / 2; + + wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4); + + cx1 = cx4; + cy1 = cy4; + cx2 = (double)(cx1 + x2) / 2; + cy2 = (double)(cy1 + y2) / 2; + } + + wx_spline_add_point((double)wx_round(cx1), (double)wx_round(cy1)); + wx_spline_add_point(x2, y2); + + wx_spline_draw_point_array(dc); + +} + +#if USE_POSTSCRIPT +void wx_draw_open_spline_ps(wxPostScriptDC *dc, wxSpline *s) +{ + double a, b, c, d, x1, y1, x2, y2, x3, y3; + wxPoint *p, *q; + wxNode *node = s->points->First(); + p = (wxPoint *)node->Data(); + + x1 = p->x; y1 = p->y; + + node = node->Next(); + p = (wxPoint *)node->Data(); + c = p->x; d = p->y; + x3 = a = (double)(x1 + c) / 2; + y3 = b = (double)(y1 + d) / 2; + + *(dc->GetStream()) << "newpath " << x1 << " " << dc->GetYOrigin() - y1 << " moveto " << x3 << " " << dc->GetYOrigin() - y3; + *(dc->GetStream()) << " lineto\n"; + dc->CalcBoundingBox((double)x1, (double)(dc->GetYOrigin() - y1)); + dc->CalcBoundingBox((double)x3, (double)(dc->GetYOrigin() - y3)); + + while ((node = node->Next()) != NULL) + { + q = (wxPoint *)node->Data(); + + x1 = x3; y1 = y3; + x2 = c; y2 = d; + c = q->x; d = q->y; + x3 = (double)(x2 + c) / 2; + y3 = (double)(y2 + d) / 2; + *(dc->GetStream()) << x1 << " " << dc->GetYOrigin() - y1 << " " << x2 << " " << dc->GetYOrigin() - y2 << " "; + *(dc->GetStream()) << x3 << " " << dc->GetYOrigin() - y3 << " DrawSplineSection\n"; + + dc->CalcBoundingBox((double)x1, (double)(dc->GetYOrigin() - y1)); + dc->CalcBoundingBox((double)x3, (double)(dc->GetYOrigin() - y3)); + } + /* + * At this point, (x2,y2) and (c,d) are the position of the + * next-to-last and last point respectively, in the point list + */ + *(dc->GetStream()) << c << " " << dc->GetYOrigin() - d << " lineto stroke\n"; +} +#endif + +/********************* CURVES FOR SPLINES ***************************** + + The following spline drawing routine is from + + "An Algorithm for High-Speed Curve Generation" + by George Merrill Chaikin, + Computer Graphics and Image Processing, 3, Academic Press, + 1974, 346-349. + + and + + "On Chaikin's Algorithm" by R. F. Riesenfeld, + Computer Graphics and Image Processing, 4, Academic Press, + 1975, 304-310. + +***********************************************************************/ + +#define half(z1, z2) ((z1+z2)/2.0) +#define THRESHOLD 5 + +/* iterative version */ + +void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4, + double b4) +{ + register double xmid, ymid; + double x1, y1, x2, y2, x3, y3, x4, y4; + + wx_clear_stack(); + wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4); + + while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) { + xmid = (double)half(x2, x3); + ymid = (double)half(y2, y3); + if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD && + fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) { + wx_spline_add_point((double)wx_round(x1), (double)wx_round(y1)); + wx_spline_add_point((double)wx_round(xmid), (double)wx_round(ymid)); + } else { + wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3), + (double)half(x3, x4), (double)half(y3, y4), x4, y4); + wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2), + (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid); + } + } +} + + +/* utilities used by spline drawing routines */ + + +typedef struct wx_spline_stack_struct { + double x1, y1, x2, y2, x3, y3, x4, y4; +} + Stack; + +#define SPLINE_STACK_DEPTH 20 +static Stack wx_spline_stack[SPLINE_STACK_DEPTH]; +static Stack *wx_stack_top; +static int wx_stack_count; + +void wx_clear_stack(void) +{ + wx_stack_top = wx_spline_stack; + wx_stack_count = 0; +} + +void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) +{ + wx_stack_top->x1 = x1; + wx_stack_top->y1 = y1; + wx_stack_top->x2 = x2; + wx_stack_top->y2 = y2; + wx_stack_top->x3 = x3; + wx_stack_top->y3 = y3; + wx_stack_top->x4 = x4; + wx_stack_top->y4 = y4; + wx_stack_top++; + wx_stack_count++; +} + +int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, + double *x3, double *y3, double *x4, double *y4) +{ + if (wx_stack_count == 0) + return (0); + wx_stack_top--; + wx_stack_count--; + *x1 = wx_stack_top->x1; + *y1 = wx_stack_top->y1; + *x2 = wx_stack_top->x2; + *y2 = wx_stack_top->y2; + *x3 = wx_stack_top->x3; + *y3 = wx_stack_top->y3; + *x4 = wx_stack_top->x4; + *y4 = wx_stack_top->y4; + return (1); +} + +static bool wx_spline_add_point(double x, double y) +{ + wxPoint *point = new wxPoint ; + point->x = (int) x; + point->y = (int) y; + wx_spline_point_list.Append((wxObject*)point); + return TRUE; +} + +static void wx_spline_draw_point_array(wxDC *dc) +{ + dc->DrawLines(&wx_spline_point_list, (double)0.0, (double)0.0); + wxNode *node = wx_spline_point_list.First(); + while (node) + { + wxPoint *point = (wxPoint *)node->Data(); + delete point; + delete node; + node = wx_spline_point_list.First(); + } +} + +wxSpline::wxSpline(wxList *list) +{ + points = list; +} + +wxSpline::~wxSpline(void) +{ +} + +void wxSpline::DeletePoints(void) +{ + for(wxNode *node = points->First(); node; node = points->First()) + { + wxPoint *point = (wxPoint *)node->Data(); + delete point; + delete node; + } + delete points; +} + +#if USE_POSTSCRIPT + +// Make a 3-point spline +void wxPostScriptDC::DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3) +{ + wxList *point_list = new wxList; + + wxPoint *point1 = new wxPoint; + point1->x = x1; point1->y = y1; + point_list->Append((wxObject*)point1); + + wxPoint *point2 = new wxPoint; + point2->x = x2; point2->y = y2; + point_list->Append((wxObject*)point2); + + wxPoint *point3 = new wxPoint; + point3->x = x3; point3->y = y3; + point_list->Append((wxObject*)point3); + + wxSpline spline(point_list); + + wx_draw_open_spline_ps(this, &spline); + spline.DeletePoints(); +} + +void wxPostScriptDC::DrawSpline(wxList *list) +{ + wxSpline spline(list); + + wx_draw_open_spline_ps(this, &spline); +} + +void wxPostScriptDC::DrawSpline(int n, wxPoint points[]) +{ + wxList list; + int i; + for (i =0; i < n; i++) + list.Append((wxObject*)&points[i]); + DrawSpline((wxList *)&list); +} + + +#endif // USE_POSTSCRIPT + +#endif // USE_SPLINES + diff --git a/utils/ogl/src/bitmap.cpp b/utils/ogl/src/bitmap.cpp new file mode 100644 index 0000000000..8004f4a8d9 --- /dev/null +++ b/utils/ogl/src/bitmap.cpp @@ -0,0 +1,123 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: bitmap.cpp +// Purpose: Bitmap shape class +// Author: Julian Smart +// Modified by: +// Created: 12/07/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "bitmap.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include +#endif + +#ifdef PROLOGIO +#include +#endif + +#include "basic.h" +#include "basicp.h" +#include "canvas.h" +#include "bitmap.h" +#include "misc.h" + +/* + * Bitmap object + * + */ + +IMPLEMENT_DYNAMIC_CLASS(wxBitmapShape, wxShape) + +wxBitmapShape::wxBitmapShape():wxRectangleShape(100.0, 50.0) +{ + m_filename = ""; +} + +wxBitmapShape::~wxBitmapShape() +{ +} + +void wxBitmapShape::OnDraw(wxDC& dc) +{ + if (!m_bitmap.Ok()) + return; + + wxMemoryDC tempDC; + tempDC.SelectObject(m_bitmap); + double x, y; + x = WXROUND(m_xpos - m_bitmap.GetWidth() / 2.0); + y = WXROUND(m_ypos - m_bitmap.GetHeight() / 2.0); + dc.Blit(x, y, m_bitmap.GetWidth(), m_bitmap.GetHeight(), &tempDC, 0, 0); +} + +void wxBitmapShape::SetSize(double w, double h, bool recursive) +{ + if (m_bitmap.Ok()) + { + w = m_bitmap.GetWidth(); + h = m_bitmap.GetHeight(); + } + + SetAttachmentSize(w, h); + + m_width = w; + m_height = h; + SetDefaultRegionSize(); +} + +#ifdef PROLOGIO +// Prolog database stuff +char *wxBitmapShape::GetFunctor() +{ + return "node_image"; +} + +void wxBitmapShape::WritePrologAttributes(wxExpr *clause) +{ + // Can't really save the bitmap; so instantiate the bitmap + // at a higher level in the application, from a symbol library. + wxRectangleShape::WritePrologAttributes(clause); + clause->AddAttributeValueString("filename", m_filename); +} + +void wxBitmapShape::ReadPrologAttributes(wxExpr *clause) +{ + wxRectangleShape::ReadPrologAttributes(clause); + clause->GetAttributeValue("filename", m_filename); +} +#endif + +// Does the copying for this object +void wxBitmapShape::Copy(wxShape& copy) +{ + wxRectangleShape::Copy(copy); + + wxASSERT( copy.IsKindOf(CLASSINFO(wxBitmapShape)) ) ; + + wxBitmapShape& bitmapCopy = (wxBitmapShape&) copy; + + bitmapCopy.m_bitmap = m_bitmap; + bitmapCopy.SetFilename(m_filename); +} + +void wxBitmapShape::SetBitmap(const wxBitmap& bm) +{ + m_bitmap = bm; + if (m_bitmap.Ok()) + SetSize(m_bitmap.GetWidth(), m_bitmap.GetHeight()); +} + + diff --git a/utils/ogl/src/bitmap.h b/utils/ogl/src/bitmap.h new file mode 100644 index 0000000000..8527c49088 --- /dev/null +++ b/utils/ogl/src/bitmap.h @@ -0,0 +1,54 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: bitmap.h +// Purpose: wxBitmapShape +// Author: Julian Smart +// Modified by: +// Created: 12/07/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _OGL_BITMAP_H_ +#define _OGL_BITMAP_H_ + +#ifdef __GNUG__ +#pragma interface "bitmap.h" +#endif + +#include "basic.h" + +class wxBitmapShape: public wxRectangleShape +{ + DECLARE_DYNAMIC_CLASS(wxBitmapShape) + public: + wxBitmapShape(); + ~wxBitmapShape(); + + void OnDraw(wxDC& dc); + +#ifdef PROLOGIO + // Prolog database stuff + char *GetFunctor(); + void WritePrologAttributes(wxExpr *clause); + void ReadPrologAttributes(wxExpr *clause); +#endif + + // Does the copying for this object + void Copy(wxShape& copy); + + void SetSize(double w, double h, bool recursive = TRUE); + inline wxBitmap& GetBitmap() const { return (wxBitmap&) m_bitmap; } + void SetBitmap(const wxBitmap& bm); + inline void SetFilename(const wxString& f) { m_filename = f; }; + inline wxString GetFilename() const { return m_filename; } + +private: + wxBitmap m_bitmap; + wxString m_filename; +}; + +#endif + // _OGL_BITMAP_H_ + +