From 640bc7546d4d8ad5228e09ed2d280ea12b0690e9 Mon Sep 17 00:00:00 2001
From: nyamatongwe
Date: Sat, 25 Jun 2011 07:58:03 +1000
Subject: Initial implementation of RGBA images.
---
cocoa/PlatCocoa.h | 1 +
cocoa/PlatCocoa.mm | 88 ++++++++++++++++++++++++++++++
cocoa/ScintillaCocoa.h | 1 +
doc/ScintillaDoc.html | 69 +++++++++++++++++++++---
gtk/PlatGTK.cxx | 116 +++++++++++++++++++++++++++++-----------
gtk/ScintillaGTK.cxx | 1 +
include/Platform.h | 2 +
include/Scintilla.h | 5 ++
include/Scintilla.iface | 15 ++++++
macosx/PlatMacOSX.cxx | 12 +++++
macosx/PlatMacOSX.h | 1 +
macosx/ScintillaMacOSX.h | 1 +
src/Editor.cxx | 17 ++++++
src/Editor.h | 1 +
src/LineMarker.cxx | 13 +++++
src/LineMarker.h | 7 +++
src/PositionCache.cxx | 1 +
src/ScintillaBase.cxx | 5 ++
src/ViewStyle.cxx | 3 ++
src/XPM.cxx | 135 +++++++++++++++++++++++++++++++++++++++++++++--
src/XPM.h | 49 ++++++++++++++++-
win32/PlatWin.cxx | 74 ++++++++++++++++++++++----
win32/ScintillaWin.cxx | 1 +
23 files changed, 562 insertions(+), 56 deletions(-)
diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h
index 0653bc728..0e3c5f2e2 100644
--- a/cocoa/PlatCocoa.h
+++ b/cocoa/PlatCocoa.h
@@ -93,6 +93,7 @@ public:
void RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back);
void AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill,
ColourAllocated outline, int alphaOutline, int flags);
+ void DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage);
void Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back);
void Copy(PRectangle rc, Scintilla::Point from, Surface &surfaceSource);
void DrawTextNoClip(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore,
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 9397e9fbd..1e81fb6e1 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -639,6 +639,73 @@ void Scintilla::SurfaceImpl::AlphaRectangle(PRectangle rc, int /*cornerSize*/, C
}
}
+static CGImageRef ImageFromRGBA(int width, int height, const unsigned char *pixelsImage, bool invert) {
+ CGImageRef image = 0;
+
+ // Create an RGB color space.
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ if (colorSpace) {
+ const int bitmapBytesPerRow = ((int) width * 4);
+ const int bitmapByteCount = (bitmapBytesPerRow * (int) height);
+
+ // Create a data provider.
+ CGDataProviderRef dataProvider = 0;
+ unsigned char *pixelsUpsideDown = 0;
+ if (invert) {
+ pixelsUpsideDown = new unsigned char[bitmapByteCount];
+
+ for (int y=0; ysecond release];
+ it->second = img;
+ }
+}
+
void ListBoxImpl::ClearRegisteredImages()
{
for (ImageMap::iterator it=images.begin();
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h
index b24938d05..80a483b06 100644
--- a/cocoa/ScintillaCocoa.h
+++ b/cocoa/ScintillaCocoa.h
@@ -20,6 +20,7 @@
#include
#include
+#include
Images
- The XPM format is supported for images.
- This format is described here.
+
+
Two formats are supported for images used in margin markers and autocompletion lists, RGBA and XPM.
+
+ RGBA
+
+ The RGBA format allows translucency with an alpha
+ value for each pixel. It is simpler than
+ XPM and more capable.
+
+ The data is a sequence of 4 byte pixel values starting with the pixels for the top line, with the
+ leftmost pixel first, then continuing with the pixels for subsequent lines. There is no gap between
+ lines for alignment reasons.
+
+ Each pixel consists of, in order, a red byte, a green byte, a blue byte and an alpha byte.
+ The colour bytes are not premultiplied by the alpha value. That is, a fully red pixel that is
+ 25% opaque will be [FF, 00, 00, 3F]
+
+ Since the RGBA pixel data does not include any size information the
+ width and height must previously been set with the
+ SCI_RGBAIMAGESETWIDTH and
+ SCI_RGBAIMAGESETHEIGHT messages.
+
+ GUI platforms often include functions for reading image file formats like PNG into memory
+ in the RGBA form or a similar form.
+ If there is no suitable platform support, the LodePNG and picoPNG libraries are small libraries
+ for loading and decoding PNG files available under a BSD-style license.
+
+ RGBA format is supported on Windows, GTK+ and OS X Cocoa.
+ It is not supported on OS X Carbon.
+
+ XPM
+
+ The XPM format is
+ described here.
Scintilla is only able to handle XPM pixmaps that use one character per pixel with no named colours.
There may be a completely transparent colour named "None".
There are two forms of data structure used for XPM images, the first "lines form" format is well suited
@@ -6609,6 +6662,8 @@ for line = lineStart to lineEnd do SCI_ENSUREVISIBLE(line) next
to determine which format: if the bytes start with "/* XPM */" then it is treated as text form,
otherwise it is treated as lines form.
+ XPM format is supported on on all platforms.
+
GTK+
On GTK+, the following functions create a Scintilla widget, communicate with it and allow
resources to be released after all Scintilla widgets have been destroyed.
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index c94847825..e323b0ad1 100644
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -9,6 +9,9 @@
#include
#include
+#include
+#include