# vim: ft=python fileencoding=utf-8 sw=4 et sts=4
"""Wrapper functions for the _image_enhance C extension."""

from gi.repository import GdkPixbuf, GLib
from vimiv import _image_enhance


def enhance_bc(pixbuf, brightness, contrast):
    """Enhance brightness and contrast of a GdkPixbuf.Pixbuf.

    Args:
        pixbuf: Original GdkPixbuf.Pixbuf to work with.
        brightness: Float between -1.0 and 1.0 to change brightness.
        contrast: Float between -1.0 and 1.0 to change contrast.
    Return:
        The enhanced GdkPixbuf.Pixbuf
    """
    width = pixbuf.get_width()
    height = pixbuf.get_height()
    data = pixbuf.get_pixels()
    has_alpha = pixbuf.get_has_alpha()
    c_has_alpha = 1 if has_alpha else 0  # Numbers are easier for C
    rowstride = 4 * width if has_alpha else 3 * width
    # Update plain bytes using C extension
    # Pylint does not read this properly
    # pylint: disable=no-member
    data = _image_enhance.enhance_bc(data, c_has_alpha, brightness, contrast)
    gdata = GLib.Bytes.new(data)
    return GdkPixbuf.Pixbuf.new_from_bytes(
        gdata, GdkPixbuf.Colorspace.RGB, has_alpha, 8, width, height, rowstride)

@@ -552,72 +552,8 @@
 %22%22%22%0A
-    width = pixbuf.get_width()%0A    height = pixbuf.get_height()%0A
     
@@ -579,16 +579,16 @@
 ixels()%0A
+
     has_
@@ -690,62 +690,8 @@
 r C%0A
-    rowstride = 4 * width if has_alpha else 3 * width%0A
     
@@ -956,16 +956,22 @@
 m_bytes(
+gdata,
 %0A       
@@ -975,26 +975,55 @@
     
-gdata, GdkP
+                                   p
 ixbuf.
-C
+get_c
 olor
@@ -1031,43 +1031,320 @@
 pace
-.RGB, has_alpha, 8, width, height, 
+(),%0A                                           has_alpha,%0A                                           pixbuf.get_bits_per_sample(),%0A                                           pixbuf.get_width(),%0A                                           pixbuf.get_height(),%0A                                           pixbuf.get_
 rows
@@ -1348,10 +1348,12 @@
 owstride
+()
 )%0A

Use rowstride directly from GdkPixbuf in enhance