Changeset 8e7c9fe in mainline for uspace/lib/softrend/filter.c


Ignore:
Timestamp:
2014-09-12T03:45:25Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c53b58e
Parents:
3eb0c85 (diff), 105d8d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge mainline changes

most usb changes were reverted. blink and usbmass were fixed
known problems:
ehci won't initialize
usbmast asserts on unmount (happens on mainline too)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/softrend/filter.c

    r3eb0c85 r8e7c9fe  
    11/*
    22 * Copyright (c) 2012 Petr Koupy
     3 * Copyright (c) 2014 Martin Sucha
    34 * All rights reserved.
    45 *
     
    3536
    3637#include "filter.h"
     38#include <io/pixel.h>
    3739
    38 pixel_t filter_nearest(pixelmap_t *pixmap, double x, double y, bool tile)
     40
     41static long round(double val)
    3942{
    40         long _x = x > 0 ? (long) (x + 0.5) : (long) (x - 0.5);
    41         long _y = y > 0 ? (long) (y + 0.5) : (long) (y - 0.5);
    42 
    43         if (tile) {
    44                 _x %= pixmap->width;
    45                 _y %= pixmap->height;
    46         }
    47 
    48         return pixelmap_get_pixel(pixmap, (sysarg_t) _x, (sysarg_t) _y);
     43        return val > 0 ? (long) (val + 0.5) : (long) (val - 0.5);
    4944}
    5045
    51 pixel_t filter_bilinear(pixelmap_t *pixmap, double x, double y, bool tile)
     46static long floor(double val)
    5247{
    53         // TODO
    54         return 0;
     48        long lval = (long) val;
     49        if (val < 0 && lval != val)
     50                return lval - 1;
     51        return lval;
    5552}
    5653
    57 pixel_t filter_bicubic(pixelmap_t *pixmap, double x, double y, bool tile)
     54static long ceil(double val)
     55{
     56        long lval = (long) val;
     57        if (val > 0 && lval != val)
     58                return lval + 1;
     59        return lval;
     60}
     61
     62
     63static inline pixel_t blend_pixels(size_t count, float *weights,
     64    pixel_t *pixels)
     65{
     66        float alpha = 0, red = 0, green = 0, blue = 0;
     67        for (size_t index = 0; index < count; index++) {
     68                alpha += weights[index] * ALPHA(pixels[index]);
     69                red   += weights[index] *   RED(pixels[index]);
     70                green += weights[index] * GREEN(pixels[index]);
     71                blue  += weights[index] *  BLUE(pixels[index]);
     72        }
     73       
     74        return PIXEL((uint8_t) alpha, (uint8_t) red, (uint8_t) green,
     75            (uint8_t) blue);
     76}
     77
     78pixel_t filter_nearest(pixelmap_t *pixmap, double x, double y,
     79    pixelmap_extend_t extend)
     80{
     81        return pixelmap_get_extended_pixel(pixmap, round(x), round(y), extend);
     82}
     83
     84pixel_t filter_bilinear(pixelmap_t *pixmap, double x, double y,
     85    pixelmap_extend_t extend)
     86{
     87        long x1 = floor(x);
     88        long x2 = ceil(x);
     89        long y1 = floor(y);
     90        long y2 = ceil(y);
     91       
     92        if (y1 == y2 && x1 == x2) {
     93                return pixelmap_get_extended_pixel(pixmap,
     94                    (sysarg_t) x1, (sysarg_t) y1, extend);
     95        }
     96       
     97        double x_delta = x - x1;
     98        double y_delta = y - y1;
     99       
     100        pixel_t pixels[4];
     101        pixels[0] = pixelmap_get_extended_pixel(pixmap, x1, y1, extend);
     102        pixels[1] = pixelmap_get_extended_pixel(pixmap, x2, y1, extend);
     103        pixels[2] = pixelmap_get_extended_pixel(pixmap, x1, y2, extend);
     104        pixels[3] = pixelmap_get_extended_pixel(pixmap, x2, y2, extend);
     105       
     106        float weights[4];
     107        weights[0] = (1 - x_delta) * (1 - y_delta);
     108        weights[1] = (    x_delta) * (1 - y_delta);
     109        weights[2] = (1 - x_delta) * (    y_delta);
     110        weights[3] = (    x_delta) * (    y_delta);
     111       
     112        return blend_pixels(4, weights, pixels);
     113}
     114
     115pixel_t filter_bicubic(pixelmap_t *pixmap, double x, double y,
     116    pixelmap_extend_t extend)
    58117{
    59118        // TODO
Note: See TracChangeset for help on using the changeset viewer.