[media] vivid-tpg: add hor/vert downsampling fields
[deliverable/linux.git] / drivers / media / platform / vivid / vivid-tpg.h
index bd8b1c760b3f01d140085e39ef073fecfd824b98..cec5bb4f36326aa9d7f64b97ddb6398fefd3bc06 100644 (file)
@@ -41,7 +41,10 @@ enum tpg_pattern {
        TPG_PAT_GREEN,
        TPG_PAT_BLUE,
        TPG_PAT_CHECKERS_16X16,
+       TPG_PAT_CHECKERS_2X2,
        TPG_PAT_CHECKERS_1X1,
+       TPG_PAT_COLOR_CHECKERS_2X2,
+       TPG_PAT_COLOR_CHECKERS_1X1,
        TPG_PAT_ALTERNATING_HLINES,
        TPG_PAT_ALTERNATING_VLINES,
        TPG_PAT_CROSS_1_PIXEL,
@@ -87,7 +90,7 @@ enum tpg_move_mode {
 
 extern const char * const tpg_aspect_strings[];
 
-#define TPG_MAX_PLANES 2
+#define TPG_MAX_PLANES 3
 #define TPG_MAX_PAT_LINES 8
 
 struct tpg_data {
@@ -98,6 +101,7 @@ struct tpg_data {
        /* Scaled output frame size */
        unsigned                        scaled_width;
        u32                             field;
+       bool                            field_alternate;
        /* crop coordinates are frame-based */
        struct v4l2_rect                crop;
        /* compose coordinates are format-based */
@@ -134,7 +138,10 @@ struct tpg_data {
        enum tpg_pixel_aspect           pix_aspect;
        unsigned                        rgb_range;
        unsigned                        real_rgb_range;
+       unsigned                        buffers;
        unsigned                        planes;
+       u8                              vdownsampling[TPG_MAX_PLANES];
+       u8                              hdownsampling[TPG_MAX_PLANES];
        /* Used to store the colors in native format, either RGB or YUV */
        u8                              colors[TPG_COLOR_MAX][3];
        u8                              textfg[TPG_MAX_PLANES][8], textbg[TPG_MAX_PLANES][8];
@@ -184,6 +191,7 @@ void tpg_gen_text(struct tpg_data *tpg,
                u8 *basep[TPG_MAX_PLANES][2], int y, int x, char *text);
 void tpg_calc_text_basep(struct tpg_data *tpg,
                u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf);
+void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf);
 void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf);
 bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc);
 void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop,
@@ -323,6 +331,11 @@ static inline u32 tpg_g_quantization(const struct tpg_data *tpg)
        return tpg->quantization;
 }
 
+static inline unsigned tpg_g_buffers(const struct tpg_data *tpg)
+{
+       return tpg->buffers;
+}
+
 static inline unsigned tpg_g_planes(const struct tpg_data *tpg)
 {
        return tpg->planes;
@@ -340,7 +353,60 @@ static inline unsigned tpg_g_bytesperline(const struct tpg_data *tpg, unsigned p
 
 static inline void tpg_s_bytesperline(struct tpg_data *tpg, unsigned plane, unsigned bpl)
 {
-       tpg->bytesperline[plane] = bpl;
+       unsigned p;
+
+       if (tpg->buffers > 1) {
+               tpg->bytesperline[plane] = bpl;
+               return;
+       }
+
+       for (p = 0; p < tpg->planes; p++) {
+               unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0];
+
+               tpg->bytesperline[p] = plane_w / tpg->hdownsampling[p];
+       }
+}
+
+
+static inline unsigned tpg_g_line_width(const struct tpg_data *tpg, unsigned plane)
+{
+       unsigned w = 0;
+       unsigned p;
+
+       if (tpg->buffers > 1)
+               return tpg_g_bytesperline(tpg, plane);
+       for (p = 0; p < tpg->planes; p++) {
+               unsigned plane_w = tpg_g_bytesperline(tpg, p);
+
+               w += plane_w / tpg->vdownsampling[p];
+       }
+       return w;
+}
+
+static inline unsigned tpg_calc_line_width(const struct tpg_data *tpg,
+                                          unsigned plane, unsigned bpl)
+{
+       unsigned w = 0;
+       unsigned p;
+
+       if (tpg->buffers > 1)
+               return bpl;
+       for (p = 0; p < tpg->planes; p++) {
+               unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0];
+
+               plane_w /= tpg->hdownsampling[p];
+               w += plane_w / tpg->vdownsampling[p];
+       }
+       return w;
+}
+
+static inline unsigned tpg_calc_plane_size(const struct tpg_data *tpg, unsigned plane)
+{
+       if (plane >= tpg->planes)
+               return 0;
+
+       return tpg_g_bytesperline(tpg, plane) * tpg->buf_height /
+              tpg->vdownsampling[plane];
 }
 
 static inline void tpg_s_buf_height(struct tpg_data *tpg, unsigned h)
@@ -348,9 +414,10 @@ static inline void tpg_s_buf_height(struct tpg_data *tpg, unsigned h)
        tpg->buf_height = h;
 }
 
-static inline void tpg_s_field(struct tpg_data *tpg, unsigned field)
+static inline void tpg_s_field(struct tpg_data *tpg, unsigned field, bool alternate)
 {
        tpg->field = field;
+       tpg->field_alternate = alternate;
 }
 
 static inline void tpg_s_perc_fill(struct tpg_data *tpg,
This page took 0.027003 seconds and 5 git commands to generate.