Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[vdr] [PATCH] adding Contrast, Brightness setting to softdevice
Here a patch that enables setting contrast, brightness, etc using
XvAttributes in the setup panel for softdevice. It's not entirely
finished and doesn't store the settings yet.
Feedback welcome. It handles set only attributes, and tries to scale
down the variable attributes to the range -50 - 50, but I think this is
still too large a range. The setting could even be made into a graphical
slider, but I'm not to familiar with the osd stuff do implement it yet.
Also, I see different indentation styles, 2 chars, 3 chars etc. What is
the "official" vdr indentation style?
Lucke, the cvs repository at developer.berlios.de doesn't seem to have
any updates for the last month. Are you planning on putting together a
new prerelease?
--
Torgeir Veimo <torgeir@pobox.com>
/*
* audio.c: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: audio.c,v 1.2 2004/08/01 16:05:26 lucke Exp $
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "xvattr.h"
// If set, only the predefined values will be shown in the settings dialogue
#define ONLY_PREDEFINED 1
char *displayStrings [][2] = {
{ "XV_BRIGHTNESS", "Brightness" },
{ "XV_CONTRAST", "Contrast" },
{ "XV_SATURATION", "Saturation" },
{ "XV_COLOR", "Color" },
{ "XV_HUE", "Hue" },
{ "XV_GAMMA", "Gamma" },
{ "XV_SET_DEFAULTS", "Reset to Defaults" },
// additional display strings that we don't necessarily want in the predefined set
#ifndef ONLY_PREDEFINED
{ "XV_AUTOPAINT_COLORKEY", "Autopaint Colorkey" },
{ "XV_COLORKEY", "Colorkey" },
{ "XV_DOUBLE_BUFFER", "Double Buffer" },
{ "XV_RED_INTENSITY", "Red Intensity" },
{ "XV_GREEN_INTENSITY", "Green Intensity" },
{ "XV_BLUE_INTENSITY", "Blue Intensity" },
{ "XV_SWITCHCRT", "Switch CRT" },
{ "XV_COLORSPACE", "Colorspace" },
#endif
NULL
};
cXvAttr::~cXvAttr() {
}
cXvAttr::cXvAttr() {
// cXvVideoOut uses the same default method to get the display, so we can do the same..
if(!(this->dpy = XOpenDisplay(NULL))) {
fprintf(stderr, "[softdevice-xvattr] unable to connect to display\n");
}
items = NULL; num_items = 0;
}
void cXvAttr::GetMenuItems(cMenuSetupPage *page) {
if (!items) FindXvAttributes();
for (int i = 0; i < num_items; i++) {
page->Add(items[i]->GetMenuItem());
}
}
void cXvAttr::FindXvAttributes() {
XvQueryAdaptors(dpy, DefaultRootWindow(dpy), &num_adaptors, &adaptor_info);
num_items = 0;
// TODO: doesn't handle multiport adapters yet..
for (unsigned int n = 0; n < num_adaptors; n++) {
int base_id = adaptor_info[n].base_id;
int num_ports = adaptor_info[n].num_ports;
fprintf(stdout, "[softdevice-xvattr] Adaptor: %d, Name: %s\n", n, adaptor_info[n].name);
//for (int m = base_id; m < base_id+num_ports; m++) {
port_nr = base_id;
int num;
fprintf(stdout, "[softdevice-xvattr] using port: %d\n", port_nr);
XvAttribute *xvattr = XvQueryPortAttributes(dpy, port_nr, &num);
for (int k = 0; k < num; k++) {
if (xvattr[k].flags & XvSettable) {
#ifdef ONLY_PREDEFINED
char *displayString = LookupString(xvattr[k].name);
if (displayString != NULL)
#endif
num_items++;
}
}
items = new (cXvAttribute*)[num_items];
int l = 0;
for(int k = 0; k < num; k++) {
int value = 0;
if(xvattr[k].flags & XvSettable) {
char *displayString = LookupString(xvattr[k].name);
#ifdef ONLY_PREDEFINED
if (displayString == NULL) continue; // drop if the string is not in the predefined set
#endif
if (xvattr[k].flags & XvGettable) {
Atom atom = XInternAtom(dpy, xvattr[k].name, False);
if (XvGetPortAttribute(dpy, port_nr, atom, &value) != Success) {
fprintf(stderr, "[softdevice-xvattr] Couldn't get value for attribute %s\n", xvattr[k].name);
value = 0;
}
}
fprintf(stderr, "[softdevice-xvattr] Adding %s, min: %d, max: %d, cur: %d\n", xvattr[k].name, xvattr[k].min_value, xvattr[k].max_value, value);
items[l++] = new cXvAttribute(displayString, xvattr[k].name, value,
xvattr[k].min_value, xvattr[k].max_value, xvattr[k].flags & XvGettable ? false : true);
}
// }
}
}
}
void cXvAttr::UpdateValues() {
for (int i = 0; i < num_items; i++) {
if (items[i]->HasChanged()) {
Atom atom = XInternAtom(dpy, items[i]->GetName(), False);
if (XvSetPortAttribute(dpy, port_nr, atom, items[i]->GetValue() * items[i]->GetScale()) != Success) {
fprintf(stderr, "[softdevice-xvattr] Couldn't set value for attribute %s\n", items[i]->GetName());
} else {
int tmp;
if (!items[i]->IsWriteOnly() && XvGetPortAttribute(dpy, port_nr, atom, &tmp) != Success) {
fprintf(stderr, "[softdevice-xvattr] Unable to read back value for attribute %s\n", items[i]->GetName());
}
if (items[i]->IsWriteOnly())
items[i]->SetValue(0); // reset write only value
else
items[i]->SetValue(items[i]->GetValue());
}
}
}
}
char *cXvAttr::LookupString(char *string) {
if (string == NULL) return NULL;
for (int i = 0; displayStrings != NULL && displayStrings[i] && displayStrings[i][0]; i++) {
if (!strcmp(displayStrings[i][0], string)) {
return displayStrings[i][1];
}
}
return NULL;
}
// XvAttribute
// We want the onscreen values to be in the range between -50 and 50 except for
// boolean values;
cXvAttribute::cXvAttribute(char *displayString, char *name, int value, int min, int max, bool write_only) {
this->displayString = displayString;
this->name = name;
this->value = value;
this->old_value = value;
this->min = min;
this->max = max;
this->write_only = write_only;
if (min == 0 && max == 1 || max <= 50) scale = 1;
else scale = (max - min) / 100;
this->value = value / scale;
}
cMenuEditItem *cXvAttribute::GetMenuItem() {
if (max == 1 && min == 0)
return new cMenuEditBoolItem(tr(displayString), &value, tr("Off"), tr("On"));
return new cMenuEditIntItem(tr(displayString), &value, min / scale, max / scale);
}
/*
* xvattr.h: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id$
*/
#ifndef XVATTR_H
#define XVATTR_H
#include <vdr/plugin.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xvlib.h>
class cXvAttribute {
private:
// Atom atom;
int value, old_value, min, max, scale;
bool write_only;
char *name;
char *displayString;
protected:
public:
cXvAttribute(char *displayString, char *name, int value, int min, int max, bool write_only = false);
~cXvAttribute();
bool HasChanged() { return value == old_value ? false : true; }
int GetValue() { return value; }
char* GetName() { return name; }
void SetValue(int value) { this->value = old_value = value; }
int GetScale() { return scale; }
bool IsWriteOnly() { return write_only; }
cMenuEditItem *GetMenuItem();
};
class cXvAttr {
private:
Display *dpy;
// int base_id;
int port_nr;
unsigned int num_adaptors;
XvAdaptorInfo *adaptor_info;
//cXvAttribute *attributes;
int num_items;
cXvAttribute **items;
protected:
char* LookupString(char *string);
public:
cXvAttr();
~cXvAttr();
void GetMenuItems(cMenuSetupPage *page);
void FindXvAttributes();
void UpdateValues();
};
#endif
Index: Makefile
===================================================================
RCS file: /cvsroot/softdevice/softdevice/Makefile,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Makefile
--- Makefile 1 Aug 2004 05:07:03 -0000 1.1.1.1
+++ Makefile 13 Sep 2004 14:01:49 -0000
@@ -155,7 +161,7 @@
endif
ifdef XV_SUPPORT
-OBJS += video-xv.o
+OBJS += video-xv.o xscreensaver.o xvattr.o
DEFINES += -DXV_SUPPORT
LIBS += -L/usr/X11R6/lib -lXi -lXext -lX11 -lm -lXv
endif
@@ -166,6 +172,18 @@
INCLUDES += -I$(VIDIX_DIR)/include/vidix
DEFINES += -DVIDIX_SUPPORT -DVIDIX_DIR=\"$(VIDIX_DIR)/lib/vidix/\" -DFBDEV=\"$(FBDEV)\"
LIBS += -lvidix
+endif
+
+ifdef LIBXDPMS_SUPPORT
+# nothing to add...
+endif
+
endif
ifdef PP_LIBAVCODEC
Index: setup-softdevice.c
===================================================================
RCS file: /cvsroot/softdevice/softdevice/setup-softdevice.c,v
retrieving revision 1.2
diff -u -r1.2 setup-softdevice.c
--- setup-softdevice.c 1 Aug 2004 16:23:30 -0000 1.2
+++ setup-softdevice.c 13 Sep 2004 14:01:50 -0000
@@ -160,6 +171,7 @@
{
copyData = setupStore;
data = &setupStore;
+ attr = new cXvAttr();
if (data->outputMethod == VOUT_XV)
{
@@ -212,6 +224,16 @@
&data->syncOnFrames,
2,
syncOnFramesStr));
+#ifdef XV_SUPPORT
+ if (data->outputMethod == VOUT_XV) {
+ // need pointer to dpy
+ attr->GetMenuItems(this);
+ }
+#endif
}
/* ---------------------------------------------------------------------------
@@ -220,15 +242,18 @@
{
eOSState state = cOsdMenu::ProcessKey(Key);
+ attr->UpdateValues();
if (state == osUnknown)
{
switch (Key)
{
case kOk:
Store();
state = osBack;
break;
default:
break;
}
}
@@ -254,11 +279,18 @@
fprintf (stderr, "[setup-softdevice] storing data\n");
// setupStore = data;
SetupStore ("Xv-Aspect", setupStore.xvAspect);
SetupStore ("CropMode", setupStore.cropMode);
SetupStore ("Deinterlace Method", setupStore.deintMethod);
SetupStore ("PixelFormat", setupStore.pixelFormat);
SetupStore ("Picture mirroring", setupStore.mirror);
SetupStore ("SyncAllFrames", setupStore.syncOnFrames);
+#ifdef XV_SUPPORT
+ // xvattr store attributes
+ if (data->outputMethod == VOUT_XV) {
+ }
+#endif
}
Index: setup-softdevice.h
===================================================================
RCS file: /cvsroot/softdevice/softdevice/setup-softdevice.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 setup-softdevice.h
--- setup-softdevice.h 1 Aug 2004 05:07:04 -0000 1.1.1.1
+++ setup-softdevice.h 13 Sep 2004 14:01:50 -0000
@@ -14,6 +14,8 @@
#define VOUT_DFB 3
#define VOUT_VIDIX 4
+#include "xvattr.h"
+
/* ---------------------------------------------------------------------------
*/
class cSetupStore {
@@ -36,6 +39,7 @@
class cMenuSetupSoftdevice : public cMenuSetupPage {
private:
cSetupStore *data, copyData;
+ cXvAttr* attr;
protected:
virtual eOSState ProcessKey(eKeys Key);
virtual void Store(void);
Home |
Main Index |
Thread Index