Merge "Add float support for set and get in CameraParameters."

This commit is contained in:
Wu-cheng Li 2010-01-31 06:09:14 -08:00 committed by Android (Google) Code Review
commit fdef2fb051
2 changed files with 16 additions and 0 deletions

View File

@ -34,8 +34,10 @@ public:
void set(const char *key, const char *value);
void set(const char *key, int value);
void setFloat(const char *key, float value);
const char *get(const char *key) const;
int getInt(const char *key) const;
float getFloat(const char *key) const;
/* preview-size=176x144 */
void setPreviewSize(int width, int height);

View File

@ -209,6 +209,13 @@ void CameraParameters::set(const char *key, int value)
set(key, str);
}
void CameraParameters::setFloat(const char *key, float value)
{
char str[16]; // 14 should be enough. We overestimate to be safe.
snprintf(str, sizeof(str), "%g", value);
set(key, str);
}
const char *CameraParameters::get(const char *key) const
{
String8 v = mMap.valueFor(String8(key));
@ -225,6 +232,13 @@ int CameraParameters::getInt(const char *key) const
return strtol(v, 0, 0);
}
float CameraParameters::getFloat(const char *key) const
{
const char *v = get(key);
if (v == 0) return -1;
return strtof(v, 0);
}
static int parse_size(const char *str, int &width, int &height)
{
// Find the width.