Example #1
0
/**
 * @brief Query the SP thread ID.
 * Refer to "sh_css_internal.h" for details.
 */
bool ia_css_pipeline_get_sp_thread_id(unsigned int key, unsigned int *val)
{

	IA_CSS_ENTER("key=%d, val=%p", key, val);

	if ((val == NULL) || (key >= IA_CSS_PIPELINE_NUM_MAX) || (key >= IA_CSS_PIPE_ID_NUM)) {
		IA_CSS_LEAVE("return value = false");
		return false;
	}

	*val = pipeline_num_to_sp_thread_map[key];

	if (*val == (unsigned)PIPELINE_NUM_UNMAPPED) {
		IA_CSS_LOG("unmapped pipeline number");
		IA_CSS_LEAVE("return value = false");
		return false;
	}
	IA_CSS_LEAVE("return value = true");
	return true;
}
void
ia_css_shading_table_free(struct ia_css_shading_table *table)
{
	unsigned int i;

	if (table == NULL)
		return;

	/* We only output logging when the table is not NULL, otherwise
	 * logs will give the impression that a table was freed.
	 * */
	IA_CSS_ENTER("");

	for (i = 0; i < IA_CSS_SC_NUM_COLORS; i++) {
		if (table->data[i])
			sh_css_free(table->data[i]);
	}
	sh_css_free(table);

	IA_CSS_LEAVE("");
}
struct ia_css_shading_table *
ia_css_shading_table_alloc(
	unsigned int width,
	unsigned int height)
{
	unsigned int i;
	struct ia_css_shading_table *me;

	IA_CSS_ENTER("");

	me = sh_css_malloc(sizeof(*me));
	if (me == NULL) {
		IA_CSS_ERROR("out of memory");
		return me;
	}

	me->width         = width;
	me->height        = height;
	me->sensor_width  = 0;
	me->sensor_height = 0;
	me->fraction_bits = 0;
	for (i = 0; i < IA_CSS_SC_NUM_COLORS; i++) {
		me->data[i] =
		    sh_css_malloc(width * height * sizeof(*me->data[0]));
		if (me->data[i] == NULL) {
			unsigned int j;
			for (j = 0; j < i; j++)
				sh_css_free(me->data[j]);
			sh_css_free(me);
			return NULL;
		}
	}

	IA_CSS_LEAVE("");
	return me;
}
/* Assumptions:
 *	- A line is multiple of 4 bytes = 1 word.
 *	- Each frame has SOF and EOF (each 1 word).
 *	- Each line has format header and optionally SOL and EOL (each 1 word).
 *	- Odd and even lines of YUV420 format are different in bites per pixel size.
 *	- Custom size of embedded data.
 *  -- Interleaved frames are not taken into account.
 *  -- Lines are multiples of 8B, and not necessary of (custom 3B, or 7B
 *  etc.).
 * Result is given in DDR mem words, 32B or 256 bits
 */
enum ia_css_err
ia_css_mipi_frame_calculate_size(const unsigned int width,
                                 const unsigned int height,
                                 const enum ia_css_stream_format format,
                                 const bool hasSOLandEOL,
                                 const unsigned int embedded_data_size_words,
                                 unsigned int *size_mem_words)
{
    enum ia_css_err err = IA_CSS_SUCCESS;

    unsigned int bits_per_pixel = 0;
    unsigned int even_line_bytes = 0;
    unsigned int odd_line_bytes = 0;
    unsigned int words_per_odd_line = 0;
    unsigned int words_for_first_line = 0;
    unsigned int words_per_even_line = 0;
    unsigned int mem_words_per_even_line = 0;
    unsigned int mem_words_per_odd_line = 0;
    unsigned int mem_words_for_first_line = 0;
    unsigned int mem_words_for_EOF = 0;
    unsigned int mem_words = 0;
    unsigned int width_padded = width;

#if defined(USE_INPUT_SYSTEM_VERSION_2401)
    /* The changes will be reverted as soon as RAW
     * Buffers are deployed by the 2401 Input System
     * in the non-continuous use scenario.
     */
    width_padded += (2 * ISP_VEC_NELEMS);
#endif

    IA_CSS_ENTER("padded_width=%d, height=%d, format=%d, hasSOLandEOL=%d, embedded_data_size_words=%d\n",
    width_padded, height, format, hasSOLandEOL, embedded_data_size_words);

    switch (format) {
    case IA_CSS_STREAM_FORMAT_RAW_6:		/* 4p, 3B, 24bits */
        bits_per_pixel = 6;
        break;
    case IA_CSS_STREAM_FORMAT_RAW_7:		/* 8p, 7B, 56bits */
        bits_per_pixel = 7;
        break;
    case IA_CSS_STREAM_FORMAT_RAW_8:		/* 1p, 1B, 8bits */
    case IA_CSS_STREAM_FORMAT_BINARY_8:		/*  8bits, TODO: check. */
    case IA_CSS_STREAM_FORMAT_YUV420_8:		/* odd 2p, 2B, 16bits, even 2p, 4B, 32bits */
        bits_per_pixel = 8;
        break;
    case IA_CSS_STREAM_FORMAT_YUV420_10:		/* odd 4p, 5B, 40bits, even 4p, 10B, 80bits */
    case IA_CSS_STREAM_FORMAT_RAW_10:		/* 4p, 5B, 40bits */
#if !defined(HAS_NO_PACKED_RAW_PIXELS)
        /* The changes will be reverted as soon as RAW
         * Buffers are deployed by the 2401 Input System
         * in the non-continuous use scenario.
         */
        bits_per_pixel = 10;
#else
        bits_per_pixel = 16;
#endif
        break;
    case IA_CSS_STREAM_FORMAT_YUV420_8_LEGACY:	/* 2p, 3B, 24bits */
    case IA_CSS_STREAM_FORMAT_RAW_12:		/* 2p, 3B, 24bits */
        bits_per_pixel = 12;
        break;
    case IA_CSS_STREAM_FORMAT_RAW_14:		/* 4p, 7B, 56bits */
        bits_per_pixel = 14;
        break;
    case IA_CSS_STREAM_FORMAT_RGB_444:		/* 1p, 2B, 16bits */
    case IA_CSS_STREAM_FORMAT_RGB_555:		/* 1p, 2B, 16bits */
    case IA_CSS_STREAM_FORMAT_RGB_565:		/* 1p, 2B, 16bits */
    case IA_CSS_STREAM_FORMAT_YUV422_8:		/* 2p, 4B, 32bits */
        bits_per_pixel = 16;
        break;
    case IA_CSS_STREAM_FORMAT_RGB_666:		/* 4p, 9B, 72bits */
        bits_per_pixel = 18;
        break;
    case IA_CSS_STREAM_FORMAT_YUV422_10:		/* 2p, 5B, 40bits */
        bits_per_pixel = 20;
        break;
    case IA_CSS_STREAM_FORMAT_RGB_888:		/* 1p, 3B, 24bits */
        bits_per_pixel = 24;
        break;

    case IA_CSS_STREAM_FORMAT_YUV420_16:		/* Not supported */
    case IA_CSS_STREAM_FORMAT_YUV422_16:		/* Not supported */
    case IA_CSS_STREAM_FORMAT_RAW_16:		/* TODO: not specified in MIPI SPEC, check */
    default:
        return IA_CSS_ERR_INVALID_ARGUMENTS;
    }

    odd_line_bytes = (width_padded * bits_per_pixel + 7) >> 3; /* ceil ( bits per line / 8) */

    /* Even lines for YUV420 formats are double in bits_per_pixel. */
    if (format == IA_CSS_STREAM_FORMAT_YUV420_8
    || format == IA_CSS_STREAM_FORMAT_YUV420_10
    || format == IA_CSS_STREAM_FORMAT_YUV420_16) {
        even_line_bytes = (width_padded * 2 * bits_per_pixel + 7) >> 3; /* ceil ( bits per line / 8) */
    } else {