* 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
This commit is contained in:
Stephan Aßmus 2006-08-13 16:06:42 +00:00
parent d83f3c1a45
commit 2f953b71af
5 changed files with 73 additions and 33 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}