+++ /dev/null
-********************* 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)
-
--- /dev/null
+
+-------------------- High priority ---------------------
+
+wxTreeCtrl
+ -> Keyboard handling, icon support and new API.
+
+wxListCtrl
+ -> Icon support in list mode.
+
+Finish DnD
+ -> Only decoding filelist and visual feedback missing
+
+wxClipboard
+ -> Urg.
+
+wxHelpController
+ -> Karsten ?
+
+Implement wxRadioBox layout
+ -> I'm so lazy.
+
+Fix printing of bitmaps
+ -> No idea. Postponed.
+
+Add support SetForegroundColour in GTK widgets
+ -> On the way.
+
+-------------------- Low priority ---------------------
+
+Implement wxPalette
+ -> I never understood that. Postponed.
+
+Implement wxDirDialog
+ -> Not heard of. Postponed.
+
+Show accelerator in menus
+ -> Changed in GTK 1.1.X. Postponed.
+
+Correct tab navigation
+ -> seems to be broken in GTK. Postponed.
+
void Enable( bool enable );
void SetFont( const wxFont &font );
void SetBackgroundColour( const wxColour &colour );
+ void SetForegroundColour( const wxColour &colour );
};
#endif // __GTKBUTTONH__
virtual void AddChild(wxWindow *child);
virtual void SetConstraintSizes(bool recurse);
virtual bool DoPhase(int phase);
+ virtual void SetFont( const wxFont &font );
+ virtual void SetBackgroundColour( const wxColour &colour );
private:
// common part of all ctors
bool IsModified() const { return m_modified; }
void SetModified() { m_modified = TRUE; }
void DiscardEdits() { m_modified = FALSE; }
-/*
wxString GetLineText( long lineNo ) const;
void OnDropFiles( wxDropFilesEvent &event );
long PositionToXY( long pos, long *x, long *y ) const;
- long XYToPosition( long x, long y );
- int GetNumberOfLines();
-*/
+ long XYToPosition( long x, long y ) const;
+ int GetLineLength(long lineNo) const;
+ int GetNumberOfLines() const;
virtual void SetInsertionPoint( long pos );
virtual void SetInsertionPointEnd();
virtual void SetEditable( bool editable );
bool HasVMT();
virtual void ImplementSetSize();
virtual void ImplementSetPosition();
+ GtkStyle *GetWidgetStyle();
wxWindow *m_parent;
wxList m_children;
bool m_needParent;
bool m_hasScrolling;
bool m_isScrolling;
- bool m_hasOwnStyle;
bool m_hasVMT;
bool m_sizeSet;
bool m_resizing;
GdkGC *m_scrollGC;
+ GtkStyle *m_widgetStyle;
public:
void Enable( bool enable );
void SetFont( const wxFont &font );
void SetBackgroundColour( const wxColour &colour );
+ void SetForegroundColour( const wxColour &colour );
};
#endif // __GTKBUTTONH__
virtual void AddChild(wxWindow *child);
virtual void SetConstraintSizes(bool recurse);
virtual bool DoPhase(int phase);
+ virtual void SetFont( const wxFont &font );
+ virtual void SetBackgroundColour( const wxColour &colour );
private:
// common part of all ctors
bool IsModified() const { return m_modified; }
void SetModified() { m_modified = TRUE; }
void DiscardEdits() { m_modified = FALSE; }
-/*
wxString GetLineText( long lineNo ) const;
void OnDropFiles( wxDropFilesEvent &event );
long PositionToXY( long pos, long *x, long *y ) const;
- long XYToPosition( long x, long y );
- int GetNumberOfLines();
-*/
+ long XYToPosition( long x, long y ) const;
+ int GetLineLength(long lineNo) const;
+ int GetNumberOfLines() const;
virtual void SetInsertionPoint( long pos );
virtual void SetInsertionPointEnd();
virtual void SetEditable( bool editable );
bool HasVMT();
virtual void ImplementSetSize();
virtual void ImplementSetPosition();
+ GtkStyle *GetWidgetStyle();
wxWindow *m_parent;
wxList m_children;
bool m_needParent;
bool m_hasScrolling;
bool m_isScrolling;
- bool m_hasOwnStyle;
bool m_hasVMT;
bool m_sizeSet;
bool m_resizing;
GdkGC *m_scrollGC;
+ GtkStyle *m_widgetStyle;
public:
+++ /dev/null
-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
+++ /dev/null
-################################
-# 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
MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
{
+ SetBackgroundColour("cadet blue");
+
m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE );
m_text->SetBackgroundColour("wheat");
imagelist-> Add( wxBitmap( radio_xpm ));
#endif
+ wxButton *button = (wxButton*)NULL;
+
m_notebook->SetImageList(imagelist);
+ m_notebook->SetBackgroundColour("cadet blue");
wxPanel *panel = new wxPanel(m_notebook);
panel->SetBackgroundColour("cadet blue");
(void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
(void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
(void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
- (void)new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
+ button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
+ button->SetForegroundColour( "red" );
(void)new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
m_notebook->AddPage(panel, "wxList", FALSE, Image_List);
panel = new wxPanel(m_notebook);
panel->SetBackgroundColour("cadet blue");
m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 4, choices );
+ m_choice->SetBackgroundColour("wheat");
(void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
(void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
(void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
panel = new wxPanel(m_notebook);
panel->SetBackgroundColour("cadet blue");
m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 4, choices );
+ m_radio->SetBackgroundColour("wheat");
(void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
(void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
(void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(180,130), wxSize(140,30) );
+++ /dev/null
-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
+++ /dev/null
-Rasterdude :-) <raster@redhat.com>
+++ /dev/null
- 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.
-\f
- 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.
-\f
- 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.
-\f
- 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.
-\f
- 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.
-\f
- 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.
-\f
- 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.
-\f
- 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.
-\f
- 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
-\f
- 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.
-
- <one line to give the library's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- 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.
-
- <signature of Ty Coon>, 1 April 1990
- Ty Coon, President of Vice
-
-That's all there is to it!
+++ /dev/null
-1998-05-07 Raja R Harinath <harinath@cs.umn.edu>
-
- * 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 <gis@academy.cas.cz>
-
- * replaced snprintf calls with g_snprintf ones, so it
- compiles now on SunOS
-
-Sat Apr 11 12:30:13 1998 George Lebl <jirka@5z.com>
-
- * utils.c: fixed yet one more SIGFPE on alpha
-
-Fri Mar 20 00:02:43 1998 Tom Tromey <tromey@cygnus.com>
-
- * gdk_imlib.h: Replaced `()' with `(void)'.
-
-Sun Mar 15 12:34:45 1998 Owen Taylor <owt1@cornell.edu>
-
- * Makefile.am (INCLUDES): Added GTK_CFLAGS
-
-1998-02-25 Raja R Harinath <harinath@cs.umn.edu>
-
- * Makefile.am (DEFS): Define `SYSTEM_IMRC' too.
-
-1998-02-25 Federico Mena Quintero <federico@nuclecu.unam.mx>
-
- * 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 <harinath@cs.umn.edu>
-
- * Makefile.am (DEFS): New var. Moved stuff from CFLAGS.
- (INCLUDES): New var.
-
-1998-02-24 Mark Galassi <rosalia@cygnus.com>
-
- * 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 <federico@nuclecu.unam.mx>
-
- * 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 <federico@nuclecu.unam.mx>
-
- * 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 <raster@redhat.com>
-
- * 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 <raster@redhat.com>
-
- added system imrc config return function
-
-1998-02-18 The Rasterman <raster@redhat.com>
-
- Fixed load.c - missed a not (!) in an if clause
+++ /dev/null
--------------------------------------------------------------------------------
- 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.
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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;
-}
+++ /dev/null
-#undef PACKAGE
-#undef VERSION
+++ /dev/null
-
-#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
+++ /dev/null
-#ifdef _HAVE_STRING_H
-#include <string.h>
-#elif _HAVE_STRINGS_H
-#include <strings.h>
-#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 <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <math.h>
-#include <ctype.h>
-#include <time.h>
-#include <netinet/in.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/time.h>
-#include <sys/types.h>
-
-#ifdef _HAVE_STRING_H
-#include <string.h>
-#elif _HAVE_STRINGS_H
-#include <strings.h>
-#endif
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xatom.h>
-#include <X11/Xos.h>
-#include <X11/extensions/XShm.h>
-#include <X11/extensions/shape.h>
-#include <X11/cursorfont.h>
-#include <gdk/gdkprivate.h>
-
-#ifdef HAVE_LIBJPEG
-#include <jpeglib.h>
-#endif
-#ifdef HAVE_LIBPNG
-#include <../png/png.h>
-#endif
-#ifdef HAVE_LIBTIFF
-#include <tiffio.h>
-#endif
-#ifdef HAVE_LIBGIF
-#include <gif_lib.h>
-#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;
+++ /dev/null
-#include <gdk/gdk.h>
-
-#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
+++ /dev/null
-
-#define _GNU_SOURCE
-#include "../gdk_imlib/gdk_imlib.h"
-#include "../gdk_imlib/gdk_imlib_private.h"
-
-ImlibData *id;
+++ /dev/null
-
-#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;
-}
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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;
-}
+++ /dev/null
-#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;
-}
+++ /dev/null
-#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 <signal.h>
-#include <sys/wait.h>
-
-/*
- * 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);
-}
wxControl::SetFont( font );
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
}
void wxButton::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid button" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
}
+void wxButton::SetForegroundColour( const wxColour &colour )
+{
+ wxCHECK_RET( m_widget != NULL, "invalid button" );
+
+ wxControl::SetForegroundColour( colour );
+
+ if (!m_foregroundColour.Ok()) return;
+
+ gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
+}
wxControl::SetFont( font );
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
}
void wxCheckBox::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
}
gtk_widget_realize( menu_item );
gtk_widget_realize( GTK_BIN(menu_item)->child );
- if (m_hasOwnStyle)
+ if (m_widgetStyle)
{
-
- GtkBin *bin = GTK_BIN( menu_item );
-
- gtk_widget_set_style( bin->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
-
- gtk_widget_set_style( GTK_WIDGET( bin ),
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( menu_item, m_widgetStyle );
+ gtk_widget_set_style( GTK_BIN(menu_item)->child, m_widgetStyle );
}
gtk_signal_connect( GTK_OBJECT( menu_item ), "activate",
if (bin->child) label = bin->child;
if (!label) label = GTK_BUTTON(m_widget)->child;
- gtk_widget_set_style( label,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( label, GetWidgetStyle() );
child = child->next;
}
void wxChoice::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid choice" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
- GtkStyle *style = gtk_widget_get_style( m_widget );
-
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
- gtk_widget_set_style( GTK_WIDGET( menu_shell ), gtk_style_ref( style ) );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+ gtk_widget_set_style( GTK_WIDGET( menu_shell ), m_widgetStyle );
GList *child = menu_shell->children;
while (child)
{
- gtk_widget_set_style( GTK_WIDGET( child->data ), gtk_style_ref( style ) );
+ gtk_widget_set_style( GTK_WIDGET( child->data ), m_widgetStyle );
child = child->next;
}
}
GtkWidget *list_item = gtk_list_item_new_with_label( item );
- if (m_hasOwnStyle)
+ if (m_widgetStyle)
{
- GtkBin *bin = GTK_BIN( list_item );
- gtk_widget_set_style( bin->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
- gtk_widget_set_style( GTK_WIDGET(bin),
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( list_item, m_widgetStyle );
+ gtk_widget_set_style( GTK_BIN( list_item )->child, m_widgetStyle );
}
gtk_signal_connect( GTK_OBJECT(list_item), "select",
wxWindow::SetFont( font );
- GtkWidget *entry = GTK_COMBO(m_widget)->entry;
-
- gtk_widget_set_style( entry,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
- GtkWidget *list = GTK_COMBO(m_widget)->list;
+ GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
- GList *child = GTK_LIST(list)->children;
+ GList *child = list->children;
while (child)
{
GtkBin *bin = (GtkBin*) child->data;
- gtk_widget_set_style( bin->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+
+ gtk_widget_set_style( bin->child, m_widgetStyle );
child = child->next;
}
void wxComboBox::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid combobox" );
- m_backgroundColour = colour;
- if (!m_backgroundColour.Ok()) return;
+ wxControl::SetBackgroundColour( colour );
- GtkStyle *style = gtk_widget_get_style( m_widget );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( gtk_widget_get_style( m_widget ) );
- }
+ if (!m_backgroundColour.Ok()) return;
- style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
- style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
-
- gtk_widget_set_style( m_widget, style );
+// gtk_widget_set_style( m_widget, m_widgetStyle );
- gtk_widget_set_style( GTK_COMBO(m_widget)->button, gtk_style_ref( style ) );
- gtk_widget_set_style( GTK_COMBO(m_widget)->entry, gtk_style_ref( style ) );
- gtk_widget_set_style( GTK_COMBO(m_widget)->list, gtk_style_ref( style ) );
+ gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle );
+ gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
+ gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle );
GList *child = GTK_LIST( GTK_COMBO(m_widget)->list )->children;
while (child)
{
- GtkWidget *item = GTK_WIDGET(child->data);
- gtk_widget_set_style( item, gtk_style_ref( style ) );
+ gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
+
child = child->next;
}
}
// Name: dialog.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: dnd.cpp
// Purpose: wxDropTarget class
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// Name: filedlg.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: font.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: frame.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: gauge.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: gdiobj.cpp
// Purpose: wxGDIObject class
// Author: Julian Smart
-// Modified by:
-// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
// Name: icon.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
GtkWidget *list_item = gtk_list_item_new_with_label( item );
- if (m_hasOwnStyle)
+ if (m_widgetStyle)
{
- GtkBin *bin = GTK_BIN( list_item );
- gtk_widget_set_style( bin->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( list_item, m_widgetStyle );
+ gtk_widget_set_style( GTK_BIN( list_item )->child, m_widgetStyle );
}
gtk_signal_connect( GTK_OBJECT(list_item), "select",
GList *child = m_list->children;
while (child)
{
- gtk_widget_set_style( GTK_BIN(child->data)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_BIN(child->data)->child, m_widgetStyle );
child = child->next;
}
void wxListBox::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_list != NULL, "invalid listbox" );
wxControl::SetBackgroundColour( colour );
- return;
-
if (!m_backgroundColour.Ok()) return;
- gtk_widget_set_style( GTK_WIDGET(m_list),
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+// gtk_widget_set_style( GTK_WIDGET(m_list), m_widgetStyle );
+
+ GdkWindow *window = GTK_WIDGET(m_list)->window;
+ m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
+ gdk_window_set_background( window, m_backgroundColour.GetColor() );
+ gdk_window_clear( window );
GList *child = m_list->children;
while (child)
{
- gtk_widget_set_style( GTK_WIDGET(child->data),
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
-
- gtk_widget_set_style( GTK_BIN(child->data)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
+// gtk_widget_set_style( GTK_BIN(child->data)->child, m_widgetStyle );
child = child->next;
}
// Name: mdi.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: menu.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
// Id: $Id$
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: notebook.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
int wxNotebook::GetSelection() const
{
+ wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
+
if (m_pages.Number() == 0) return -1;
GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page;
wxString wxNotebook::GetPageText( int page ) const
{
+ wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page)
return nb_page->m_text;
int wxNotebook::GetPageImage( int page ) const
{
+ wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page)
return nb_page->m_image;
wxNotebookPage* wxNotebook::GetNotebookPage(int page) const
{
+ wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" );
+
wxNotebookPage *nb_page = (wxNotebookPage *) NULL;
wxNode *node = m_pages.First();
int wxNotebook::SetSelection( int page )
{
+ wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
+
int selOld = GetSelection();
wxNotebookPage* nb_page = GetNotebookPage(page);
void wxNotebook::AdvanceSelection( bool bForward )
{
+ wxCHECK_RET( m_widget != NULL, "invalid notebook" );
+
int sel = GetSelection();
int max = GetPageCount();
bool wxNotebook::SetPageText( int page, const wxString &text )
{
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (!nb_page) return FALSE;
bool wxNotebook::DeleteAllPages()
{
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
+
wxNode *page_node = m_pages.First();
while (page_node)
{
bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
bool bSelect, int imageId)
{
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
+
// we've created the notebook page in AddChild(). Now we just have to set
// the caption for the page and set the others parameters.
wxWindow *wxNotebook::GetPage( int page ) const
{
+ wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (!nb_page)
return (wxWindow *) NULL;
void wxNotebook::AddChild( wxWindow *win )
{
+ wxCHECK_RET( m_widget != NULL, "invalid notebook" );
+
m_children.Append(win);
wxNotebookPage *page = new wxNotebookPage();
return TRUE;
}
+void wxNotebook::SetFont( const wxFont &font )
+{
+ wxCHECK_RET( m_widget != NULL, "invalid notebook" );
+
+ wxControl::SetFont( font );
+
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+}
+
+void wxNotebook::SetBackgroundColour( const wxColour &colour )
+{
+ wxCHECK_RET( m_widget != NULL, "invalid notebook" );
+
+ wxControl::SetBackgroundColour( colour );
+
+ if (!m_backgroundColour.Ok()) return;
+
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+}
+
//-----------------------------------------------------------------------------
// wxNotebookEvent
//-----------------------------------------------------------------------------
// Name: pen.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
wxControl::SetFont( font );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+
wxNode *node = m_boxes.First();
while (node)
{
GtkButton *button = GTK_BUTTON( node->Data() );
- gtk_widget_set_style( button->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( button->child, m_widgetStyle );
node = node->Next();
}
void wxRadioBox::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid radiobox" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+
wxNode *node = m_boxes.First();
while (node)
{
GtkWidget *button = GTK_WIDGET( node->Data() );
- gtk_widget_set_style( button,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( button, m_widgetStyle );
node = node->Next();
}
wxControl::SetFont( font );
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
}
void wxRadioButton::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid radiobutton" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
}
// Name: statbmp.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: statbox.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: stattext.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Purpose:
// Author: Robert Roebling
// Id: $Id$
-// Copyright: (c) 1998 Robert Roebling
+// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/utils.h"
#include <wx/intl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ctype.h>
+
//-----------------------------------------------------------------------------
// "changed"
//-----------------------------------------------------------------------------
wxString wxTextCtrl::GetValue() const
{
+ wxCHECK_MSG( m_text != NULL, "", "invalid text ctrl" );
+
wxString tmp;
if (m_windowStyle & wxTE_MULTILINE)
{
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
- tmp = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+ char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+ tmp = text;
+ g_free( text );
}
else
{
}
}
-bool wxTextCtrl::LoadFile( const wxString &WXUNUSED(file) )
+bool wxTextCtrl::LoadFile( const wxString &file )
{
- wxFAIL_MSG( "wxTextCtrl::LoadFile not implemented" );
+ wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" );
+
+ if (!wxFileExists(file)) return FALSE;
+ Clear();
+
+ FILE *fp = NULL;
+ struct stat statb;
+
+ if ((stat ((char*) (const char*) file, &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
+ !(fp = fopen ((char*) (const char*) file, "r")))
+ {
+ return FALSE;
+ }
+ else
+ {
+ gint len = statb.st_size;
+ char *text;
+ if (!(text = (char*)malloc ((unsigned) (len + 1))))
+ {
+ fclose (fp);
+ return FALSE;
+ }
+ if (fread (text, sizeof (char), len, fp) != (size_t) len)
+ {
+ }
+ fclose (fp);
+
+ text[len] = 0;
+
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), text, 0, &len );
+ }
+ else
+ {
+ gtk_entry_set_text( GTK_ENTRY(m_text), text );
+ }
+
+ free (text);
+ m_modified = FALSE;
+ return TRUE;
+ }
return FALSE;
}
-bool wxTextCtrl::SaveFile( const wxString &WXUNUSED(file) )
+bool wxTextCtrl::SaveFile( const wxString &file )
{
- wxFAIL_MSG( "wxTextCtrl::SaveFile not implemented" );
+ wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" );
+
+ if (file == "") return FALSE;
+
+ FILE *fp;
- return FALSE;
+ if (!(fp = fopen ((char*) (const char*) file, "w")))
+ {
+ return FALSE;
+ }
+ else
+ {
+ char *text = NULL;
+ gint len = 0;
+
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ len = gtk_text_get_length( GTK_TEXT(m_text) );
+ text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+ }
+ else
+ {
+ text = gtk_entry_get_text( GTK_ENTRY(m_text) );
+ }
+
+ if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
+ {
+ // Did not write whole file
+ }
+
+ // Make sure newline terminates the file
+ if (text[len - 1] != '\n')
+ fputc ('\n', fp);
+
+ fclose (fp);
+
+ if (m_windowStyle & wxTE_MULTILINE) g_free( text );
+
+ m_modified = FALSE;
+ return TRUE;
+ }
+
+ return TRUE;
}
-/*
wxString wxTextCtrl::GetLineText( long lineNo ) const
{
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ gint len = gtk_text_get_length( GTK_TEXT(m_text) );
+ char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+
+ if (text)
+ {
+ wxString buf("");
+ long i;
+ int currentLine = 0;
+ for (i = 0; currentLine != lineNo && text[i]; i++ )
+ if (text[i] == '\n')
+ currentLine++;
+ // Now get the text
+ int j;
+ for (j = 0; text[i] && text[i] != '\n'; i++, j++ )
+ buf += text[i];
+
+ g_free( text );
+ return buf;
+ }
+ else
+ return wxEmptyString;
+ }
+ else
+ {
+ if (lineNo == 0) return GetValue();
+ return wxEmptyString;
+ }
}
+void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
+{
+ wxFAIL_MSG( "wxTextCtrl::GetLineText( lineNo ) not implemented" );
+}
-void wxTextCtrl::OnDropFiles( wxDropFilesEvent &event )
+long wxTextCtrl::PositionToXY( long WXUNUSED(pos), long *WXUNUSED(x), long *WXUNUSED(y) ) const
{
+ wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" );
+
+ return 0;
}
-long wxTextCtrl::PositionToXY( long pos, long *x, long *y ) const
+long wxTextCtrl::XYToPosition( long WXUNUSED(x), long WXUNUSED(y) ) const
{
+ wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" );
+
+ return 0;
}
-long wxTextCtrl::XYToPosition( long x, long y )
+int wxTextCtrl::GetLineLength(long lineNo) const
{
+ wxString str = GetLineText (lineNo);
+ return (int) str.Length();
}
-int wxTextCtrl::GetNumberOfLines()
+int wxTextCtrl::GetNumberOfLines() const
{
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ gint len = gtk_text_get_length( GTK_TEXT(m_text) );
+ char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+
+ if (text)
+ {
+ int currentLine = 0;
+ for (int i = 0; i < len; i++ )
+ if (text[i] == '\n')
+ currentLine++;
+
+ g_free( text );
+ return currentLine;
+ }
+ else
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
}
-*/
void wxTextCtrl::SetInsertionPoint( long pos )
{
+ wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
+
int tmp = (int) pos;
if (m_windowStyle & wxTE_MULTILINE)
gtk_text_set_point( GTK_TEXT(m_text), tmp );
{
wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
- if (((wxFont*)&font)->Ok())
- m_font = font;
- else
- m_font = *wxSWISS_FONT;
-
- GtkStyle *style = gtk_widget_get_style( m_text );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( gtk_widget_get_style( m_text ) );
- }
-
- gdk_font_unref( style->font );
- style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
+ wxControl::SetFont( font );
- gtk_widget_set_style( m_text, style );
+ // doesn't work
}
void wxTextCtrl::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
-
- m_backgroundColour = colour;
+
+ wxControl::SetBackgroundColour( colour );
+
if (!m_backgroundColour.Ok()) return;
if (m_windowStyle & wxTE_MULTILINE)
}
else
{
- GtkStyle *style = gtk_widget_get_style( m_text );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( gtk_widget_get_style( m_text ) );
- }
-
- m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_text->window ) );
- style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
- style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
-
- gtk_widget_set_style( m_text, style );
+ gtk_widget_set_style( m_text, m_widgetStyle );
}
}
// Name: timer.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: utils.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
if (gdk_event->count > 0) return;
/*
- printf( "OnExpose from " );
+ printf( "OnExpose from " );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() );
printf( ".\n" );
m_isEnabled = TRUE;
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
- m_hasOwnStyle = FALSE;
m_scrollGC = (GdkGC*) NULL;
+ m_widgetStyle = (GtkStyle*) NULL;
}
bool wxWindow::Create( wxWindow *parent, wxWindowID id,
DestroyChildren();
+ if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
+
if (m_scrollGC) gdk_gc_unref( m_scrollGC );
if (m_wxwindow) gtk_widget_destroy( m_wxwindow );
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
m_windowValidator = (wxValidator *) NULL;
- m_hasOwnStyle = FALSE;
m_scrollGC = (GdkGC*) NULL;
+ m_widgetStyle = (GtkStyle*) NULL;
}
void wxWindow::PostCreation()
}
else
{
- GtkStyle *style = gtk_widget_get_style( m_widget );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( style );
- }
-
+ GtkStyle *style = GetWidgetStyle();
m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
-
- gtk_widget_set_style( m_widget, style );
+ style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
}
}
void wxWindow::SetForegroundColour( const wxColour &colour )
{
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
+
m_foregroundColour = colour;
+ if (!m_foregroundColour.Ok()) return;
+
+ if (!m_wxwindow)
+ {
+ GtkStyle *style = GetWidgetStyle();
+ m_foregroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
+ style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor();
+ style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor();
+ style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor();
+ }
+}
+
+GtkStyle *wxWindow::GetWidgetStyle()
+{
+ if (!m_widgetStyle)
+ m_widgetStyle =
+ gtk_style_copy(
+ gtk_widget_get_style( m_widget ) );
+ return m_widgetStyle;
}
bool wxWindow::Validate()
else
m_font = *wxSWISS_FONT;
- GtkStyle *style = gtk_widget_get_style( m_widget );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( style );
- }
-
+ GtkStyle *style = GetWidgetStyle();
gdk_font_unref( style->font );
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
-
- gtk_widget_set_style( m_widget, style );
}
wxFont *wxWindow::GetFont()
wxControl::SetFont( font );
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
}
void wxButton::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid button" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
}
+void wxButton::SetForegroundColour( const wxColour &colour )
+{
+ wxCHECK_RET( m_widget != NULL, "invalid button" );
+
+ wxControl::SetForegroundColour( colour );
+
+ if (!m_foregroundColour.Ok()) return;
+
+ gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
+}
wxControl::SetFont( font );
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
}
void wxCheckBox::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
}
gtk_widget_realize( menu_item );
gtk_widget_realize( GTK_BIN(menu_item)->child );
- if (m_hasOwnStyle)
+ if (m_widgetStyle)
{
-
- GtkBin *bin = GTK_BIN( menu_item );
-
- gtk_widget_set_style( bin->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
-
- gtk_widget_set_style( GTK_WIDGET( bin ),
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( menu_item, m_widgetStyle );
+ gtk_widget_set_style( GTK_BIN(menu_item)->child, m_widgetStyle );
}
gtk_signal_connect( GTK_OBJECT( menu_item ), "activate",
if (bin->child) label = bin->child;
if (!label) label = GTK_BUTTON(m_widget)->child;
- gtk_widget_set_style( label,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( label, GetWidgetStyle() );
child = child->next;
}
void wxChoice::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid choice" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
- GtkStyle *style = gtk_widget_get_style( m_widget );
-
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
- gtk_widget_set_style( GTK_WIDGET( menu_shell ), gtk_style_ref( style ) );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+ gtk_widget_set_style( GTK_WIDGET( menu_shell ), m_widgetStyle );
GList *child = menu_shell->children;
while (child)
{
- gtk_widget_set_style( GTK_WIDGET( child->data ), gtk_style_ref( style ) );
+ gtk_widget_set_style( GTK_WIDGET( child->data ), m_widgetStyle );
child = child->next;
}
}
GtkWidget *list_item = gtk_list_item_new_with_label( item );
- if (m_hasOwnStyle)
+ if (m_widgetStyle)
{
- GtkBin *bin = GTK_BIN( list_item );
- gtk_widget_set_style( bin->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
- gtk_widget_set_style( GTK_WIDGET(bin),
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( list_item, m_widgetStyle );
+ gtk_widget_set_style( GTK_BIN( list_item )->child, m_widgetStyle );
}
gtk_signal_connect( GTK_OBJECT(list_item), "select",
wxWindow::SetFont( font );
- GtkWidget *entry = GTK_COMBO(m_widget)->entry;
-
- gtk_widget_set_style( entry,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
- GtkWidget *list = GTK_COMBO(m_widget)->list;
+ GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
- GList *child = GTK_LIST(list)->children;
+ GList *child = list->children;
while (child)
{
GtkBin *bin = (GtkBin*) child->data;
- gtk_widget_set_style( bin->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+
+ gtk_widget_set_style( bin->child, m_widgetStyle );
child = child->next;
}
void wxComboBox::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid combobox" );
- m_backgroundColour = colour;
- if (!m_backgroundColour.Ok()) return;
+ wxControl::SetBackgroundColour( colour );
- GtkStyle *style = gtk_widget_get_style( m_widget );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( gtk_widget_get_style( m_widget ) );
- }
+ if (!m_backgroundColour.Ok()) return;
- style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
- style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
-
- gtk_widget_set_style( m_widget, style );
+// gtk_widget_set_style( m_widget, m_widgetStyle );
- gtk_widget_set_style( GTK_COMBO(m_widget)->button, gtk_style_ref( style ) );
- gtk_widget_set_style( GTK_COMBO(m_widget)->entry, gtk_style_ref( style ) );
- gtk_widget_set_style( GTK_COMBO(m_widget)->list, gtk_style_ref( style ) );
+ gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle );
+ gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
+ gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle );
GList *child = GTK_LIST( GTK_COMBO(m_widget)->list )->children;
while (child)
{
- GtkWidget *item = GTK_WIDGET(child->data);
- gtk_widget_set_style( item, gtk_style_ref( style ) );
+ gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
+
child = child->next;
}
}
// Name: dialog.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: dnd.cpp
// Purpose: wxDropTarget class
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// Name: filedlg.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: font.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: frame.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: gauge.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: gdiobj.cpp
// Purpose: wxGDIObject class
// Author: Julian Smart
-// Modified by:
-// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
// Name: icon.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
GtkWidget *list_item = gtk_list_item_new_with_label( item );
- if (m_hasOwnStyle)
+ if (m_widgetStyle)
{
- GtkBin *bin = GTK_BIN( list_item );
- gtk_widget_set_style( bin->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( list_item, m_widgetStyle );
+ gtk_widget_set_style( GTK_BIN( list_item )->child, m_widgetStyle );
}
gtk_signal_connect( GTK_OBJECT(list_item), "select",
GList *child = m_list->children;
while (child)
{
- gtk_widget_set_style( GTK_BIN(child->data)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_BIN(child->data)->child, m_widgetStyle );
child = child->next;
}
void wxListBox::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_list != NULL, "invalid listbox" );
wxControl::SetBackgroundColour( colour );
- return;
-
if (!m_backgroundColour.Ok()) return;
- gtk_widget_set_style( GTK_WIDGET(m_list),
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+// gtk_widget_set_style( GTK_WIDGET(m_list), m_widgetStyle );
+
+ GdkWindow *window = GTK_WIDGET(m_list)->window;
+ m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
+ gdk_window_set_background( window, m_backgroundColour.GetColor() );
+ gdk_window_clear( window );
GList *child = m_list->children;
while (child)
{
- gtk_widget_set_style( GTK_WIDGET(child->data),
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
-
- gtk_widget_set_style( GTK_BIN(child->data)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
+// gtk_widget_set_style( GTK_BIN(child->data)->child, m_widgetStyle );
child = child->next;
}
// Name: mdi.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: menu.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
// Id: $Id$
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: notebook.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
int wxNotebook::GetSelection() const
{
+ wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
+
if (m_pages.Number() == 0) return -1;
GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page;
wxString wxNotebook::GetPageText( int page ) const
{
+ wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page)
return nb_page->m_text;
int wxNotebook::GetPageImage( int page ) const
{
+ wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page)
return nb_page->m_image;
wxNotebookPage* wxNotebook::GetNotebookPage(int page) const
{
+ wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" );
+
wxNotebookPage *nb_page = (wxNotebookPage *) NULL;
wxNode *node = m_pages.First();
int wxNotebook::SetSelection( int page )
{
+ wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
+
int selOld = GetSelection();
wxNotebookPage* nb_page = GetNotebookPage(page);
void wxNotebook::AdvanceSelection( bool bForward )
{
+ wxCHECK_RET( m_widget != NULL, "invalid notebook" );
+
int sel = GetSelection();
int max = GetPageCount();
bool wxNotebook::SetPageText( int page, const wxString &text )
{
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (!nb_page) return FALSE;
bool wxNotebook::DeleteAllPages()
{
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
+
wxNode *page_node = m_pages.First();
while (page_node)
{
bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
bool bSelect, int imageId)
{
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
+
// we've created the notebook page in AddChild(). Now we just have to set
// the caption for the page and set the others parameters.
wxWindow *wxNotebook::GetPage( int page ) const
{
+ wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (!nb_page)
return (wxWindow *) NULL;
void wxNotebook::AddChild( wxWindow *win )
{
+ wxCHECK_RET( m_widget != NULL, "invalid notebook" );
+
m_children.Append(win);
wxNotebookPage *page = new wxNotebookPage();
return TRUE;
}
+void wxNotebook::SetFont( const wxFont &font )
+{
+ wxCHECK_RET( m_widget != NULL, "invalid notebook" );
+
+ wxControl::SetFont( font );
+
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+}
+
+void wxNotebook::SetBackgroundColour( const wxColour &colour )
+{
+ wxCHECK_RET( m_widget != NULL, "invalid notebook" );
+
+ wxControl::SetBackgroundColour( colour );
+
+ if (!m_backgroundColour.Ok()) return;
+
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+}
+
//-----------------------------------------------------------------------------
// wxNotebookEvent
//-----------------------------------------------------------------------------
// Name: pen.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
wxControl::SetFont( font );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+
wxNode *node = m_boxes.First();
while (node)
{
GtkButton *button = GTK_BUTTON( node->Data() );
- gtk_widget_set_style( button->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( button->child, m_widgetStyle );
node = node->Next();
}
void wxRadioBox::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid radiobox" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+
wxNode *node = m_boxes.First();
while (node)
{
GtkWidget *button = GTK_WIDGET( node->Data() );
- gtk_widget_set_style( button,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( button, m_widgetStyle );
node = node->Next();
}
wxControl::SetFont( font );
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
}
void wxRadioButton::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_widget != NULL, "invalid radiobutton" );
wxControl::SetBackgroundColour( colour );
if (!m_backgroundColour.Ok()) return;
- gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
- gtk_style_ref(
- gtk_widget_get_style( m_widget ) ) );
+ gtk_widget_set_style( m_widget, m_widgetStyle );
}
// Name: statbmp.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: statbox.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: stattext.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Purpose:
// Author: Robert Roebling
// Id: $Id$
-// Copyright: (c) 1998 Robert Roebling
+// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/utils.h"
#include <wx/intl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ctype.h>
+
//-----------------------------------------------------------------------------
// "changed"
//-----------------------------------------------------------------------------
wxString wxTextCtrl::GetValue() const
{
+ wxCHECK_MSG( m_text != NULL, "", "invalid text ctrl" );
+
wxString tmp;
if (m_windowStyle & wxTE_MULTILINE)
{
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
- tmp = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+ char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+ tmp = text;
+ g_free( text );
}
else
{
}
}
-bool wxTextCtrl::LoadFile( const wxString &WXUNUSED(file) )
+bool wxTextCtrl::LoadFile( const wxString &file )
{
- wxFAIL_MSG( "wxTextCtrl::LoadFile not implemented" );
+ wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" );
+
+ if (!wxFileExists(file)) return FALSE;
+ Clear();
+
+ FILE *fp = NULL;
+ struct stat statb;
+
+ if ((stat ((char*) (const char*) file, &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
+ !(fp = fopen ((char*) (const char*) file, "r")))
+ {
+ return FALSE;
+ }
+ else
+ {
+ gint len = statb.st_size;
+ char *text;
+ if (!(text = (char*)malloc ((unsigned) (len + 1))))
+ {
+ fclose (fp);
+ return FALSE;
+ }
+ if (fread (text, sizeof (char), len, fp) != (size_t) len)
+ {
+ }
+ fclose (fp);
+
+ text[len] = 0;
+
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), text, 0, &len );
+ }
+ else
+ {
+ gtk_entry_set_text( GTK_ENTRY(m_text), text );
+ }
+
+ free (text);
+ m_modified = FALSE;
+ return TRUE;
+ }
return FALSE;
}
-bool wxTextCtrl::SaveFile( const wxString &WXUNUSED(file) )
+bool wxTextCtrl::SaveFile( const wxString &file )
{
- wxFAIL_MSG( "wxTextCtrl::SaveFile not implemented" );
+ wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" );
+
+ if (file == "") return FALSE;
+
+ FILE *fp;
- return FALSE;
+ if (!(fp = fopen ((char*) (const char*) file, "w")))
+ {
+ return FALSE;
+ }
+ else
+ {
+ char *text = NULL;
+ gint len = 0;
+
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ len = gtk_text_get_length( GTK_TEXT(m_text) );
+ text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+ }
+ else
+ {
+ text = gtk_entry_get_text( GTK_ENTRY(m_text) );
+ }
+
+ if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
+ {
+ // Did not write whole file
+ }
+
+ // Make sure newline terminates the file
+ if (text[len - 1] != '\n')
+ fputc ('\n', fp);
+
+ fclose (fp);
+
+ if (m_windowStyle & wxTE_MULTILINE) g_free( text );
+
+ m_modified = FALSE;
+ return TRUE;
+ }
+
+ return TRUE;
}
-/*
wxString wxTextCtrl::GetLineText( long lineNo ) const
{
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ gint len = gtk_text_get_length( GTK_TEXT(m_text) );
+ char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+
+ if (text)
+ {
+ wxString buf("");
+ long i;
+ int currentLine = 0;
+ for (i = 0; currentLine != lineNo && text[i]; i++ )
+ if (text[i] == '\n')
+ currentLine++;
+ // Now get the text
+ int j;
+ for (j = 0; text[i] && text[i] != '\n'; i++, j++ )
+ buf += text[i];
+
+ g_free( text );
+ return buf;
+ }
+ else
+ return wxEmptyString;
+ }
+ else
+ {
+ if (lineNo == 0) return GetValue();
+ return wxEmptyString;
+ }
}
+void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
+{
+ wxFAIL_MSG( "wxTextCtrl::GetLineText( lineNo ) not implemented" );
+}
-void wxTextCtrl::OnDropFiles( wxDropFilesEvent &event )
+long wxTextCtrl::PositionToXY( long WXUNUSED(pos), long *WXUNUSED(x), long *WXUNUSED(y) ) const
{
+ wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" );
+
+ return 0;
}
-long wxTextCtrl::PositionToXY( long pos, long *x, long *y ) const
+long wxTextCtrl::XYToPosition( long WXUNUSED(x), long WXUNUSED(y) ) const
{
+ wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" );
+
+ return 0;
}
-long wxTextCtrl::XYToPosition( long x, long y )
+int wxTextCtrl::GetLineLength(long lineNo) const
{
+ wxString str = GetLineText (lineNo);
+ return (int) str.Length();
}
-int wxTextCtrl::GetNumberOfLines()
+int wxTextCtrl::GetNumberOfLines() const
{
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ gint len = gtk_text_get_length( GTK_TEXT(m_text) );
+ char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+
+ if (text)
+ {
+ int currentLine = 0;
+ for (int i = 0; i < len; i++ )
+ if (text[i] == '\n')
+ currentLine++;
+
+ g_free( text );
+ return currentLine;
+ }
+ else
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
}
-*/
void wxTextCtrl::SetInsertionPoint( long pos )
{
+ wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
+
int tmp = (int) pos;
if (m_windowStyle & wxTE_MULTILINE)
gtk_text_set_point( GTK_TEXT(m_text), tmp );
{
wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
- if (((wxFont*)&font)->Ok())
- m_font = font;
- else
- m_font = *wxSWISS_FONT;
-
- GtkStyle *style = gtk_widget_get_style( m_text );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( gtk_widget_get_style( m_text ) );
- }
-
- gdk_font_unref( style->font );
- style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
+ wxControl::SetFont( font );
- gtk_widget_set_style( m_text, style );
+ // doesn't work
}
void wxTextCtrl::SetBackgroundColour( const wxColour &colour )
{
- return;
-
wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
-
- m_backgroundColour = colour;
+
+ wxControl::SetBackgroundColour( colour );
+
if (!m_backgroundColour.Ok()) return;
if (m_windowStyle & wxTE_MULTILINE)
}
else
{
- GtkStyle *style = gtk_widget_get_style( m_text );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( gtk_widget_get_style( m_text ) );
- }
-
- m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_text->window ) );
- style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
- style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
-
- gtk_widget_set_style( m_text, style );
+ gtk_widget_set_style( m_text, m_widgetStyle );
}
}
// Name: timer.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Name: utils.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
if (gdk_event->count > 0) return;
/*
- printf( "OnExpose from " );
+ printf( "OnExpose from " );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() );
printf( ".\n" );
m_isEnabled = TRUE;
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
- m_hasOwnStyle = FALSE;
m_scrollGC = (GdkGC*) NULL;
+ m_widgetStyle = (GtkStyle*) NULL;
}
bool wxWindow::Create( wxWindow *parent, wxWindowID id,
DestroyChildren();
+ if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
+
if (m_scrollGC) gdk_gc_unref( m_scrollGC );
if (m_wxwindow) gtk_widget_destroy( m_wxwindow );
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
m_windowValidator = (wxValidator *) NULL;
- m_hasOwnStyle = FALSE;
m_scrollGC = (GdkGC*) NULL;
+ m_widgetStyle = (GtkStyle*) NULL;
}
void wxWindow::PostCreation()
}
else
{
- GtkStyle *style = gtk_widget_get_style( m_widget );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( style );
- }
-
+ GtkStyle *style = GetWidgetStyle();
m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
-
- gtk_widget_set_style( m_widget, style );
+ style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
}
}
void wxWindow::SetForegroundColour( const wxColour &colour )
{
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
+
m_foregroundColour = colour;
+ if (!m_foregroundColour.Ok()) return;
+
+ if (!m_wxwindow)
+ {
+ GtkStyle *style = GetWidgetStyle();
+ m_foregroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
+ style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor();
+ style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor();
+ style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor();
+ }
+}
+
+GtkStyle *wxWindow::GetWidgetStyle()
+{
+ if (!m_widgetStyle)
+ m_widgetStyle =
+ gtk_style_copy(
+ gtk_widget_get_style( m_widget ) );
+ return m_widgetStyle;
}
bool wxWindow::Validate()
else
m_font = *wxSWISS_FONT;
- GtkStyle *style = gtk_widget_get_style( m_widget );
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( style );
- }
-
+ GtkStyle *style = GetWidgetStyle();
gdk_font_unref( style->font );
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
-
- gtk_widget_set_style( m_widget, style );
}
wxFont *wxWindow::GetFont()