summaryrefslogtreecommitdiff
path: root/tests/image_data_ycbcr601pl.lua
blob: 876213449de66c599c851783e3fb3af95bcff95f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local ffi = require("ffi")
local util = require("util")
local C = ffi.C
local levas = util.get_lib("evas")

ffi.cdef [[
    void  *fopen(const char *fname, const char *mode);
    int   fclose(void *stream);
    size_t fread(void *ptr, size_t size, size_t n, void *stream);
]]

return function(ui)
    return "data.png", "Image Data YCbCr 601 Pointer List", 14.7573, function()
        local image, yp, up, vp
        local win_w, win_h = ui.win_w, ui.win_h
        ui.func_set(function() levas.evas_object_del(image) end, function(t, f)
            local w = 640
            local h = 480
            local x = (win_w / 2) - (w / 2)
            local y = (win_h / 2) - (h / 2)
            levas.evas_object_move(image, x, y)
            levas.evas_object_resize(image, w, h)
            levas.evas_object_image_fill_set(image, 0, 0, w, h)
            levas.evas_object_image_data_update_add(image, 0, 0, 640, 480)
        end)
        local evas = ui.evas
        image = levas.evas_object_image_add(evas)
        levas.evas_object_image_content_hint_set(image,
            levas.EVAS_IMAGE_CONTENT_HINT_DYNAMIC)
        levas.evas_object_image_colorspace_set(image,
            levas.EVAS_COLORSPACE_YCBCR422P601_PL)
        levas.evas_object_image_size_set(image, 640, 480)
        levas.evas_object_image_alpha_set(image, 0)
        levas.evas_object_image_fill_set(image, 0, 0, 640, 480)
        levas.evas_object_resize(image, 640, 480)
        levas.evas_object_show(image)
        local f = C.fopen(util.build_path("tp.yuv"), "rb")
        yp = ffi.new("unsigned char[?]", 640 * 480)
        up = ffi.new("unsigned char[?]", 320 * 240)
        vp = ffi.new("unsigned char[?]", 320 * 240)
        C.fread(yp, 640 * 480, 1, f)
        C.fread(up, 320 * 240, 1, f)
        C.fread(vp, 320 * 240, 1, f)
        C.fclose(f)
        local data = ffi.cast("unsigned char**",
            levas.evas_object_image_data_get(image, 1))
        local lp = data
        for y = 0, 479 do
            lp[0] = yp + (y * 640)
            lp = lp + 1
        end
        for y = 0, 239 do
            lp[0] = up + (y * 320)
            lp = lp + 1
        end
        for y = 0, 239 do
            lp[0] = vp + (y * 320)
            lp = lp + 1
        end
        levas.evas_object_image_data_set(image, data)
    end
end