From 2f953b71af24542ddd2f510ec45dec7f7e9cdace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 13 Aug 2006 16:06:42 +0000 Subject: [PATCH] * min/max visibility scale is now between 0 and 4 * flat icon format optimizes for grays in styles git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18508 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/libs/icon/IconUtils.cpp | 2 +- src/libs/icon/flat_icon/FlatIconFormat.h | 3 + src/libs/icon/flat_icon/FlatIconImporter.cpp | 79 ++++++++++++++----- src/libs/icon/shape/Shape.cpp | 16 ++-- .../icon/transformer/StrokeTransformer.cpp | 6 +- 5 files changed, 73 insertions(+), 33 deletions(-) diff --git a/src/libs/icon/IconUtils.cpp b/src/libs/icon/IconUtils.cpp index 2cdb76bf74..afc96c646c 100644 --- a/src/libs/icon/IconUtils.cpp +++ b/src/libs/icon/IconUtils.cpp @@ -23,7 +23,7 @@ using std::nothrow; -// TODO: put into HaikuCompatibility.h +// TODO: put into HaikuBuildCompatibility.h #ifndef __HAIKU__ # define B_BITMAP_NO_SERVER_LINK 0 # define B_BAD_DATA B_ERROR diff --git a/src/libs/icon/flat_icon/FlatIconFormat.h b/src/libs/icon/flat_icon/FlatIconFormat.h index 6fe725b952..b47046c77d 100644 --- a/src/libs/icon/flat_icon/FlatIconFormat.h +++ b/src/libs/icon/flat_icon/FlatIconFormat.h @@ -20,6 +20,8 @@ enum { STYLE_TYPE_SOLID_COLOR = 1, STYLE_TYPE_GRADIENT = 2, STYLE_TYPE_SOLID_COLOR_NO_ALPHA = 3, + STYLE_TYPE_SOLID_GRAY = 4, + STYLE_TYPE_SOLID_GRAY_NO_ALPHA = 5, SHAPE_TYPE_PATH_SOURCE = 10, @@ -33,6 +35,7 @@ enum { GRADIENT_FLAG_TRANSFORM = 1 << 1, GRADIENT_FLAG_NO_ALPHA = 1 << 2, GRADIENT_FLAG_16_BIT_COLORS = 1 << 3, // not yet used + GRADIENT_FLAG_GRAYS = 1 << 4, }; enum { diff --git a/src/libs/icon/flat_icon/FlatIconImporter.cpp b/src/libs/icon/flat_icon/FlatIconImporter.cpp index 228c187c26..077e85c4c9 100644 --- a/src/libs/icon/flat_icon/FlatIconImporter.cpp +++ b/src/libs/icon/flat_icon/FlatIconImporter.cpp @@ -170,18 +170,31 @@ _ReadTranslation(LittleEndianBuffer& buffer, Transformable* transformable) // _ReadColorStyle static Style* -_ReadColorStyle(LittleEndianBuffer& buffer, bool alpha) +_ReadColorStyle(LittleEndianBuffer& buffer, bool alpha, bool gray) { rgb_color color; if (alpha) { - if (!buffer.Read((uint32&)color)) - return NULL; + if (gray) { + if (!buffer.Read(color.red) + || !buffer.Read(color.alpha)) + return NULL; + color.green = color.blue = color.red; + } else { + if (!buffer.Read((uint32&)color)) + return NULL; + } } else { color.alpha = 255; - if (!buffer.Read(color.red) - || !buffer.Read(color.green) - || !buffer.Read(color.blue)) - return NULL; + if (gray) { + if (!buffer.Read(color.red)) + return NULL; + color.green = color.blue = color.red; + } else { + if (!buffer.Read(color.red) + || !buffer.Read(color.green) + || !buffer.Read(color.blue)) + return NULL; + } } return new (nothrow) Style(color); } @@ -217,6 +230,7 @@ _ReadGradientStyle(LittleEndianBuffer& buffer) } bool alpha = !(gradientFlags & GRADIENT_FLAG_NO_ALPHA); + bool gray = gradientFlags & GRADIENT_FLAG_GRAYS; for (int32 i = 0; i < gradientStopCount; i++) { uint8 stopOffset; @@ -226,14 +240,27 @@ _ReadGradientStyle(LittleEndianBuffer& buffer) return NULL; if (alpha) { - if (!buffer.Read((uint32&)color)) - return NULL; + if (gray) { + if (!buffer.Read(color.red) + || !buffer.Read(color.alpha)) + return NULL; + color.green = color.blue = color.red; + } else { + if (!buffer.Read((uint32&)color)) + return NULL; + } } else { color.alpha = 255; - if (!buffer.Read(color.red) - || !buffer.Read(color.green) - || !buffer.Read(color.blue)) { - return NULL; + if (gray) { + if (!buffer.Read(color.red)) + return NULL; + color.green = color.blue = color.red; + } else { + if (!buffer.Read(color.red) + || !buffer.Read(color.green) + || !buffer.Read(color.blue)) { + return NULL; + } } } @@ -262,12 +289,22 @@ FlatIconImporter::_ParseStyles(LittleEndianBuffer& buffer, Style* style = NULL; if (styleType == STYLE_TYPE_SOLID_COLOR) { // solid color - style = _ReadColorStyle(buffer, true); + style = _ReadColorStyle(buffer, true, false); if (!style) return B_NO_MEMORY; } else if (styleType == STYLE_TYPE_SOLID_COLOR_NO_ALPHA) { // solid color without alpha - style = _ReadColorStyle(buffer, false); + style = _ReadColorStyle(buffer, false, false); + if (!style) + return B_NO_MEMORY; + } else if (styleType == STYLE_TYPE_SOLID_GRAY) { + // solid gray plus alpha + style = _ReadColorStyle(buffer, true, true); + if (!style) + return B_NO_MEMORY; + } else if (styleType == STYLE_TYPE_SOLID_GRAY_NO_ALPHA) { + // solid gray without alpha + style = _ReadColorStyle(buffer, false, true); if (!style) return B_NO_MEMORY; } else if (styleType == STYLE_TYPE_GRADIENT) { @@ -452,20 +489,20 @@ _ReadTransformer(LittleEndianBuffer& buffer, VertexSource& source) StrokeTransformer* stroke = new (nothrow) StrokeTransformer(source); uint8 width; - uint8 lineJoin; - uint8 lineCap; + uint8 lineOptions; uint8 miterLimit; // uint8 shorten; if (!stroke || !buffer.Read(width) - || !buffer.Read(lineJoin) - || !buffer.Read(lineCap) + || !buffer.Read(lineOptions) || !buffer.Read(miterLimit)) { delete stroke; return NULL; } stroke->width(width - 128.0); + uint8 lineJoin = lineOptions & 15; stroke->line_join((agg::line_join_e)lineJoin); + uint8 lineCap = lineOptions >> 4; stroke->line_cap((agg::line_cap_e)lineCap); stroke->miter_limit(miterLimit); return stroke; @@ -554,8 +591,8 @@ FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer, uint8 maxScale; if (!buffer.Read(minScale) || !buffer.Read(maxScale)) return NULL; - shape->SetMinVisibilityScale((float)minScale); - shape->SetMaxVisibilityScale((float)maxScale); + shape->SetMinVisibilityScale(minScale / 63.75); + shape->SetMaxVisibilityScale(maxScale / 63.75); } // transformers diff --git a/src/libs/icon/shape/Shape.cpp b/src/libs/icon/shape/Shape.cpp index a8edbde7fb..3960de6ca3 100644 --- a/src/libs/icon/shape/Shape.cpp +++ b/src/libs/icon/shape/Shape.cpp @@ -63,7 +63,7 @@ Shape::Shape(::Style* style) fHinting(false), fMinVisibilityScale(0.0), - fMaxVisibilityScale(255.0) + fMaxVisibilityScale(4.0) #ifdef ICON_O_MATIC , fListeners(8) @@ -203,16 +203,16 @@ Shape::Unarchive(const BMessage* archive) // max visibility scale if (archive->FindFloat("max visibility scale", &fMaxVisibilityScale) < B_OK) - fMaxVisibilityScale = 255.0; + fMaxVisibilityScale = 4.0; if (fMinVisibilityScale < 0.0) fMinVisibilityScale = 0.0; - if (fMinVisibilityScale > 255.0) - fMinVisibilityScale = 255.0; + if (fMinVisibilityScale > 4.0) + fMinVisibilityScale = 4.0; if (fMaxVisibilityScale < 0.0) fMaxVisibilityScale = 0.0; - if (fMaxVisibilityScale > 255.0) - fMaxVisibilityScale = 255.0; + if (fMaxVisibilityScale > 4.0) + fMaxVisibilityScale = 4.0; return B_OK; } @@ -274,10 +274,10 @@ Shape::MakePropertyObject() const object->AddProperty(new BoolProperty(PROPERTY_HINTING, fHinting)); object->AddProperty(new FloatProperty(PROPERTY_MIN_VISIBILITY_SCALE, - fMinVisibilityScale, 0, 255)); + fMinVisibilityScale, 0, 4)); object->AddProperty(new FloatProperty(PROPERTY_MAX_VISIBILITY_SCALE, - fMaxVisibilityScale, 0, 255)); + fMaxVisibilityScale, 0, 4)); return object; } diff --git a/src/libs/icon/transformer/StrokeTransformer.cpp b/src/libs/icon/transformer/StrokeTransformer.cpp index bacdb6c108..21792bb44b 100644 --- a/src/libs/icon/transformer/StrokeTransformer.cpp +++ b/src/libs/icon/transformer/StrokeTransformer.cpp @@ -193,9 +193,9 @@ StrokeTransformer::MakePropertyObject() const miter_limit())); } - // shorten - object->AddProperty(new FloatProperty(PROPERTY_STROKE_SHORTEN, - shorten())); +// // shorten +// object->AddProperty(new FloatProperty(PROPERTY_STROKE_SHORTEN, +// shorten())); return object; }