Revision f47a7cb7 libavutil/pixdesc.c

View differences:

libavutil/pixdesc.c
22 22
#include "pixfmt.h"
23 23
#include "pixdesc.h"
24 24

  
25
#include "intreadwrite.h"
26

  
27
void read_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
28
               const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
29
{
30
    AVComponentDescriptor comp= desc->comp[c];
31
    int plane= comp.plane;
32
    int depth= comp.depth_minus1+1;
33
    int mask = (1<<depth)-1;
34
    int shift= comp.shift;
35
    int step = comp.step_minus1+1;
36
    int flags= desc->flags;
37

  
38
    if (flags & PIX_FMT_BITSTREAM){
39
        int skip = x*step + comp.offset_plus1-1;
40
        const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
41
        int shift = 8 - depth - (skip&7);
42

  
43
        while(w--){
44
            int val = (*p >> shift) & mask;
45
            if(read_pal_component)
46
                val= data[1][4*val + c];
47
            shift -= step;
48
            p -= shift>>3;
49
            shift &= 7;
50
            *dst++= val;
51
        }
52
    } else {
53
        const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
54

  
55
        while(w--){
56
            int val;
57
            if(flags & PIX_FMT_BE) val= AV_RB16(p);
58
            else                   val= AV_RL16(p);
59
            val = (val>>shift) & mask;
60
            if(read_pal_component)
61
                val= data[1][4*val + c];
62
            p+= step;
63
            *dst++= val;
64
        }
65
    }
66
}
67

  
68
void write_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
69
                const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
70
{
71
    AVComponentDescriptor comp = desc->comp[c];
72
    int plane = comp.plane;
73
    int depth = comp.depth_minus1+1;
74
    int step  = comp.step_minus1+1;
75
    int flags = desc->flags;
76

  
77
    if (flags & PIX_FMT_BITSTREAM) {
78
        int skip = x*step + comp.offset_plus1-1;
79
        uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
80
        int shift = 8 - depth - (skip&7);
81

  
82
        while (w--) {
83
            *p |= *src++ << shift;
84
            shift -= step;
85
            p -= shift>>3;
86
            shift &= 7;
87
        }
88
    } else {
89
        int shift = comp.shift;
90
        uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
91

  
92
        while (w--) {
93
            if (flags & PIX_FMT_BE) {
94
                uint16_t val = AV_RB16(p) | (*src++<<shift);
95
                AV_WB16(p, val);
96
            } else {
97
                uint16_t val = AV_RL16(p) | (*src++<<shift);
98
                AV_WL16(p, val);
99
            }
100
            p+= step;
101
        }
102
    }
103
}
104

  
25 105
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
26 106
    [PIX_FMT_YUV420P] = {
27 107
        .name = "yuv420p",

Also available in: Unified diff