Skip to content

cam_helper - gain depending on bit mode #286

@fiepfiep

Description

@fiepfiep

Hello,

I'm working on a v4l driver where I have the following modes:
8 bit, gain 1 up to 16x, in fine steps
10 bit, gain 1 up to 4x, in fine steps
12 bit, gain 1 and gain 2x, no intermediate steps.

I've created some cam_helper functions to convert actual gain to driver gain codes.
the cam_helper looks something like this:
Now the problem is - when changing modes - the gain codes seem to lag 1 mode behind.


uint32_t CamHelperMira016::gainCode(double gain) const
{
	if (mode_.bitdepth == 12) {
		return std::log2(gain);
	} else if (mode_.bitdepth == 10) {
		uint32_t sizeLut = sizeof(gainLut10bit) / sizeof(gainLut10bit[0]);
		uint32_t gainCode = 0;
		if (gain <= gainLut10bit[0]) {
			gainCode = 0;
		} else if (gain >= gainLut10bit[sizeLut - 1]) {
			gainCode = (sizeLut - 1);
		} else {
			while (gainCode < sizeLut - 1) {
				if (gain >= gainLut10bit[gainCode] && gain < gainLut10bit[gainCode+1]) {
					break;
				}
				gainCode++;
			}
		}
		LOG(IPARPI, Debug) << "gain: " << gain << " gainCode: " << gainCode;
		return gainCode;
	} else if (mode_.bitdepth == 8) {
		uint32_t sizeLut = sizeof(gainLut8bit) / sizeof(gainLut8bit[0]);
		uint32_t gainCode = 0;
		if (gain <= gainLut8bit[0]) {
			gainCode = 0;
		} else if (gain >= gainLut8bit[sizeLut - 1]) {
			gainCode = (sizeLut - 1);
		} else {
			while (gainCode < sizeLut - 1) {
				if (gain >= gainLut8bit[gainCode] && gain < gainLut8bit[gainCode+1]) {
					break;
				}
				gainCode++;
			}
		}
		LOG(IPARPI, Debug) << "gain: " << gain << " gainCode: " << gainCode;
		return gainCode;
	} else {
		return (uint32_t)(gain);
	}
}

double CamHelperMira016::gain(uint32_t gainCode) const
{
	if (mode_.bitdepth == 12) {
		return std::exp2(gainCode);
	} else if (mode_.bitdepth == 10){
		uint32_t sizeLut = sizeof(gainLut10bit) / sizeof(gainLut10bit[0]);
		if (gainCode >= sizeLut) {
			gainCode = sizeLut - 1;
		}
		return (double)(gainLut10bit[gainCode]);
	} else if (mode_.bitdepth == 8){
		uint32_t sizeLut = sizeof(gainLut8bit) / sizeof(gainLut8bit[0]);
		if (gainCode >= sizeLut) {
			gainCode = sizeLut - 1;
		}
		return (double)(gainLut8bit[gainCode]);
	} else {
		return (double)(gainCode);
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions