~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/avi/intern/avi_rgb.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 
19
 * All rights reserved.
 
20
 *
 
21
 * The Original Code is: all of this file.
 
22
 *
 
23
 * Contributor(s): none yet.
 
24
 *
 
25
 * ***** END GPL LICENSE BLOCK *****
 
26
 *
 
27
 */
 
28
 
 
29
/** \file blender/avi/intern/avi_rgb.c
 
30
 *  \ingroup avi
 
31
 *
 
32
 * This is external code. Converts rgb-type avi-s.
 
33
 */
 
34
 
 
35
#include <stdlib.h>
 
36
#include <string.h>
 
37
 
 
38
#include "MEM_guardedalloc.h"
 
39
 
 
40
#include "AVI_avi.h"
 
41
#include "avi_rgb.h"
 
42
 
 
43
/* implementation */
 
44
 
 
45
void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size)
 
46
{
 
47
        int x, y, i, rowstride;
 
48
        unsigned char *buf;
 
49
        AviBitmapInfoHeader *bi;
 
50
        short bits = 32;
 
51
        
 
52
        (void)size; /* unused */
 
53
 
 
54
        bi = (AviBitmapInfoHeader *) movie->streams[stream].sf;
 
55
        if (bi) bits = bi->BitCount;
 
56
 
 
57
        if (bits == 16) {
 
58
                unsigned short *pxl;
 
59
                unsigned char *to;
 
60
#ifdef __BIG_ENDIAN__
 
61
                unsigned char  *pxla;
 
62
#endif
 
63
                
 
64
                buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf");
 
65
 
 
66
                y = movie->header->Height;
 
67
                to = buf;
 
68
                                
 
69
                while (y--) {
 
70
                        pxl = (unsigned short *) (buffer + y * movie->header->Width * 2);
 
71
                        
 
72
#ifdef __BIG_ENDIAN__
 
73
                        pxla = (unsigned char *)pxl;
 
74
#endif
 
75
 
 
76
                        x = movie->header->Width;
 
77
                        while (x--) {
 
78
#ifdef __BIG_ENDIAN__
 
79
                                i = pxla[0];
 
80
                                pxla[0] = pxla[1];
 
81
                                pxla[1] = i;
 
82
        
 
83
                                pxla += 2;
 
84
#endif
 
85
                        
 
86
                                *(to++) = ((*pxl >> 10) & 0x1f) * 8;
 
87
                                *(to++) = ((*pxl >> 5) & 0x1f) * 8;
 
88
                                *(to++) = (*pxl & 0x1f) * 8;
 
89
                                pxl++;
 
90
                        }
 
91
                }
 
92
 
 
93
                MEM_freeN(buffer);
 
94
                
 
95
                return buf;
 
96
        }
 
97
        else {
 
98
                buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf");
 
99
        
 
100
                rowstride = movie->header->Width * 3;
 
101
                if ((bits != 16) && (movie->header->Width % 2)) rowstride++;
 
102
        
 
103
                for (y = 0; y < movie->header->Height; y++) {
 
104
                        memcpy(&buf[y * movie->header->Width * 3], &buffer[((movie->header->Height - 1) - y) * rowstride], movie->header->Width * 3);
 
105
                }
 
106
        
 
107
                for (y = 0; y < movie->header->Height * movie->header->Width * 3; y += 3) {
 
108
                        i = buf[y];
 
109
                        buf[y] = buf[y + 2];
 
110
                        buf[y + 2] = i;
 
111
                }
 
112
        
 
113
                MEM_freeN(buffer);
 
114
        
 
115
                return buf;
 
116
        }
 
117
}
 
118
 
 
119
void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size)
 
120
{
 
121
        int y, x, i, rowstride;
 
122
        unsigned char *buf;
 
123
 
 
124
        (void)stream; /* unused */
 
125
 
 
126
        *size = movie->header->Height * movie->header->Width * 3;
 
127
        if (movie->header->Width % 2) *size += movie->header->Height;
 
128
        
 
129
        buf = MEM_mallocN(*size, "toavirgbbuf");
 
130
 
 
131
        rowstride = movie->header->Width * 3;
 
132
        if (movie->header->Width % 2) rowstride++;
 
133
 
 
134
        for (y = 0; y < movie->header->Height; y++) {
 
135
                memcpy(&buf[y * rowstride], &buffer[((movie->header->Height - 1) - y) * movie->header->Width * 3], movie->header->Width * 3);
 
136
        }
 
137
 
 
138
        for (y = 0; y < movie->header->Height; y++) {
 
139
                for (x = 0; x < movie->header->Width * 3; x += 3) {
 
140
                        i = buf[y * rowstride + x];
 
141
                        buf[y * rowstride + x] = buf[y * rowstride + x + 2];
 
142
                        buf[y * rowstride + x + 2] = i;
 
143
                }
 
144
        }
 
145
 
 
146
        MEM_freeN(buffer);
 
147
 
 
148
        return buf;
 
149
}