Mercurial > libavformat.hg
annotate sgi.c @ 1524:bffedde11b4f libavformat
update to libnut, use framecode table generator
author | ods15 |
---|---|
date | Fri, 17 Nov 2006 16:53:42 +0000 |
parents | 0899bfe4105c |
children | a782462e2497 |
rev | line source |
---|---|
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
1 /* |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
2 * SGI image format |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
3 * Todd Kirby <doubleshot@pacbell.net> |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
16 * |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
896
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
20 */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
21 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
22 #include "avformat.h" |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
23 #include "avio.h" |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
24 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
25 /* #define DEBUG */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
26 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
27 /* sgi image file signature */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
28 #define SGI_MAGIC 474 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
29 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
30 #define SGI_HEADER_SIZE 512 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
31 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
32 #define SGI_GRAYSCALE 1 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
33 #define SGI_RGB 3 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
34 #define SGI_RGBA 4 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
35 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
36 #define SGI_SINGLE_CHAN 2 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
37 #define SGI_MULTI_CHAN 3 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
38 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
39 typedef struct SGIInfo{ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
40 short magic; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
41 char rle; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
42 char bytes_per_channel; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
43 unsigned short dimension; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
44 unsigned short xsize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
45 unsigned short ysize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
46 unsigned short zsize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
47 } SGIInfo; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
48 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
49 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
50 static int sgi_probe(AVProbeData *pd) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
51 { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
52 /* test for sgi magic */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
53 if (pd->buf_size >= 2 && BE_16(&pd->buf[0]) == SGI_MAGIC) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
54 return AVPROBE_SCORE_MAX; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
55 } else { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
56 return 0; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
57 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
58 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
59 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
60 /* read sgi header fields */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
61 static void read_sgi_header(ByteIOContext *f, SGIInfo *info) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
62 { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
63 info->magic = (unsigned short) get_be16(f); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
64 info->rle = get_byte(f); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
65 info->bytes_per_channel = get_byte(f); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
66 info->dimension = (unsigned short)get_be16(f); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
67 info->xsize = (unsigned short) get_be16(f); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
68 info->ysize = (unsigned short) get_be16(f); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
69 info->zsize = (unsigned short) get_be16(f); |
885 | 70 |
71 if(info->zsize > 4096) | |
639 | 72 info->zsize= 0; |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
73 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
74 #ifdef DEBUG |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
75 printf("sgi header fields:\n"); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
76 printf(" magic: %d\n", info->magic); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
77 printf(" rle: %d\n", info->rle); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
78 printf(" bpc: %d\n", info->bytes_per_channel); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
79 printf(" dim: %d\n", info->dimension); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
80 printf(" xsize: %d\n", info->xsize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
81 printf(" ysize: %d\n", info->ysize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
82 printf(" zsize: %d\n", info->zsize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
83 #endif |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
84 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
85 return; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
86 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
87 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
88 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
89 /* read an uncompressed sgi image */ |
885 | 90 static int read_uncompressed_sgi(const SGIInfo *si, |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
91 AVPicture *pict, ByteIOContext *f) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
92 { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
93 int x, y, z, chan_offset, ret = 0; |
430 | 94 uint8_t *dest_row; |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
95 |
885 | 96 /* skip header */ |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
97 url_fseek(f, SGI_HEADER_SIZE, SEEK_SET); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
98 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
99 pict->linesize[0] = si->xsize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
100 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
101 for (z = 0; z < si->zsize; z++) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
102 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
103 #ifndef WORDS_BIGENDIAN |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
104 /* rgba -> bgra for rgba32 on little endian cpus */ |
885 | 105 if (si->zsize == 4 && z != 3) |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
106 chan_offset = 2 - z; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
107 else |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
108 #endif |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
109 chan_offset = z; |
885 | 110 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
111 for (y = si->ysize - 1; y >= 0; y--) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
112 dest_row = pict->data[0] + (y * si->xsize * si->zsize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
113 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
114 for (x = 0; x < si->xsize; x++) { |
885 | 115 dest_row[chan_offset] = get_byte(f); |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
116 dest_row += si->zsize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
117 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
118 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
119 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
120 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
121 return ret; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
122 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
123 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
124 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
125 /* expand an rle row into a channel */ |
430 | 126 static int expand_rle_row(ByteIOContext *f, unsigned char *optr, |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
127 int chan_offset, int pixelstride) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
128 { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
129 unsigned char pixel, count; |
430 | 130 int length = 0; |
885 | 131 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
132 #ifndef WORDS_BIGENDIAN |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
133 /* rgba -> bgra for rgba32 on little endian cpus */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
134 if (pixelstride == 4 && chan_offset != 3) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
135 chan_offset = 2 - chan_offset; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
136 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
137 #endif |
885 | 138 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
139 optr += chan_offset; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
140 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
141 while (1) { |
430 | 142 pixel = get_byte(f); |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
143 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
144 if (!(count = (pixel & 0x7f))) { |
430 | 145 return length; |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
146 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
147 if (pixel & 0x80) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
148 while (count--) { |
430 | 149 *optr = get_byte(f); |
150 length++; | |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
151 optr += pixelstride; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
152 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
153 } else { |
430 | 154 pixel = get_byte(f); |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
155 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
156 while (count--) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
157 *optr = pixel; |
430 | 158 length++; |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
159 optr += pixelstride; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
160 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
161 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
162 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
163 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
164 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
165 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
166 /* read a run length encoded sgi image */ |
885 | 167 static int read_rle_sgi(const SGIInfo *sgi_info, |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
168 AVPicture *pict, ByteIOContext *f) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
169 { |
430 | 170 uint8_t *dest_row; |
171 unsigned long *start_table; | |
885 | 172 int y, z, xsize, ysize, zsize, tablen; |
430 | 173 long start_offset; |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
174 int ret = 0; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
175 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
176 xsize = sgi_info->xsize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
177 ysize = sgi_info->ysize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
178 zsize = sgi_info->zsize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
179 |
885 | 180 /* skip header */ |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
181 url_fseek(f, SGI_HEADER_SIZE, SEEK_SET); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
182 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
183 /* size of rle offset and length tables */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
184 tablen = ysize * zsize * sizeof(long); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
185 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
186 start_table = (unsigned long *)av_malloc(tablen); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
187 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
188 if (!get_buffer(f, (uint8_t *)start_table, tablen)) { |
430 | 189 ret = AVERROR_IO; |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
190 goto fail; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
191 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
192 |
885 | 193 /* skip run length table */ |
430 | 194 url_fseek(f, tablen, SEEK_CUR); |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
195 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
196 for (z = 0; z < zsize; z++) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
197 for (y = 0; y < ysize; y++) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
198 dest_row = pict->data[0] + (ysize - 1 - y) * (xsize * zsize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
199 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
200 start_offset = BE_32(&start_table[y + z * ysize]); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
201 |
430 | 202 /* don't seek if already at the next rle start offset */ |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
203 if (url_ftell(f) != start_offset) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
204 url_fseek(f, start_offset, SEEK_SET); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
205 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
206 |
430 | 207 if (expand_rle_row(f, dest_row, z, zsize) != xsize) { |
208 ret = AVERROR_INVALIDDATA; | |
209 goto fail; | |
210 } | |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
211 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
212 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
213 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
214 fail: |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
215 av_free(start_table); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
216 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
217 return ret; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
218 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
219 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
220 |
885 | 221 static int sgi_read(ByteIOContext *f, |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
222 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
223 { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
224 SGIInfo sgi_info, *s = &sgi_info; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
225 AVImageInfo info1, *info = &info1; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
226 int ret; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
227 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
228 read_sgi_header(f, s); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
229 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
230 if (s->bytes_per_channel != 1) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
231 return AVERROR_INVALIDDATA; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
232 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
233 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
234 /* check for supported image dimensions */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
235 if (s->dimension != 2 && s->dimension != 3) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
236 return AVERROR_INVALIDDATA; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
237 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
238 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
239 if (s->zsize == SGI_GRAYSCALE) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
240 info->pix_fmt = PIX_FMT_GRAY8; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
241 } else if (s->zsize == SGI_RGB) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
242 info->pix_fmt = PIX_FMT_RGB24; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
243 } else if (s->zsize == SGI_RGBA) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
244 info->pix_fmt = PIX_FMT_RGBA32; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
245 } else { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
246 return AVERROR_INVALIDDATA; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
247 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
248 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
249 info->width = s->xsize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
250 info->height = s->ysize; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
251 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
252 ret = alloc_cb(opaque, info); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
253 if (ret) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
254 return ret; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
255 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
256 if (s->rle) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
257 return read_rle_sgi(s, &info->pict, f); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
258 } else { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
259 return read_uncompressed_sgi(s, &info->pict, f); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
260 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
261 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
262 return 0; /* not reached */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
263 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
264 |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
639
diff
changeset
|
265 #ifdef CONFIG_MUXERS |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
266 static void write_sgi_header(ByteIOContext *f, const SGIInfo *info) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
267 { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
268 int i; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
269 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
270 put_be16(f, SGI_MAGIC); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
271 put_byte(f, info->rle); |
885 | 272 put_byte(f, info->bytes_per_channel); |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
273 put_be16(f, info->dimension); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
274 put_be16(f, info->xsize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
275 put_be16(f, info->ysize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
276 put_be16(f, info->zsize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
277 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
278 /* The rest are constant in this implementation */ |
885 | 279 put_be32(f, 0L); /* pixmin */ |
280 put_be32(f, 255L); /* pixmax */ | |
281 put_be32(f, 0L); /* dummy */ | |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
282 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
283 /* name */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
284 for (i = 0; i < 80; i++) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
285 put_byte(f, 0); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
286 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
287 |
885 | 288 put_be32(f, 0L); /* colormap */ |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
289 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
290 /* The rest of the 512 byte header is unused. */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
291 for (i = 0; i < 404; i++) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
292 put_byte(f, 0); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
293 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
294 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
295 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
296 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
297 static int rle_row(ByteIOContext *f, char *row, int stride, int rowsize) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
298 { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
299 int length, count, i, x; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
300 char *start, repeat = 0; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
301 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
302 for (x = rowsize, length = 0; x > 0;) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
303 start = row; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
304 row += (2 * stride); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
305 x -= 2; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
306 |
885 | 307 while (x > 0 && (row[-2 * stride] != row[-1 * stride] || |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
308 row[-1 * stride] != row[0])) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
309 row += stride; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
310 x--; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
311 }; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
312 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
313 row -= (2 * stride); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
314 x += 2; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
315 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
316 count = (row - start) / stride; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
317 while (count > 0) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
318 i = count > 126 ? 126 : count; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
319 count -= i; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
320 |
885 | 321 put_byte(f, 0x80 | i); |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
322 length++; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
323 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
324 while (i > 0) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
325 put_byte(f, *start); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
326 start += stride; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
327 i--; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
328 length++; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
329 }; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
330 }; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
331 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
332 if (x <= 0) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
333 break; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
334 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
335 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
336 start = row; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
337 repeat = row[0]; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
338 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
339 row += stride; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
340 x--; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
341 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
342 while (x > 0 && *row == repeat) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
343 row += stride; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
344 x--; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
345 }; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
346 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
347 count = (row - start) / stride; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
348 while (count > 0) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
349 i = count > 126 ? 126 : count; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
350 count -= i; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
351 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
352 put_byte(f, i); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
353 length++; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
354 |
885 | 355 put_byte(f, repeat); |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
356 length++; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
357 }; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
358 }; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
359 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
360 length++; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
361 |
885 | 362 put_byte(f, 0); |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
363 return (length); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
364 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
365 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
366 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
367 static int sgi_write(ByteIOContext *pb, AVImageInfo *info) |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
368 { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
369 SGIInfo sgi_info, *si = &sgi_info; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
370 long *offsettab, *lengthtab; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
371 int i, y, z; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
372 int tablesize, chan_offset; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
373 uint8_t *srcrow; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
374 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
375 si->xsize = info->width; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
376 si->ysize = info->height; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
377 si->rle = 1; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
378 si->bytes_per_channel = 1; |
885 | 379 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
380 switch(info->pix_fmt) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
381 case PIX_FMT_GRAY8: |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
382 si->dimension = SGI_SINGLE_CHAN; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
383 si->zsize = SGI_GRAYSCALE; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
384 break; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
385 case PIX_FMT_RGB24: |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
386 si->dimension = SGI_MULTI_CHAN; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
387 si->zsize = SGI_RGB; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
388 break; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
389 case PIX_FMT_RGBA32: |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
390 si->dimension = SGI_MULTI_CHAN; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
391 si->zsize = SGI_RGBA; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
392 break; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
393 default: |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
394 return AVERROR_INVALIDDATA; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
395 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
396 |
885 | 397 write_sgi_header(pb, si); |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
398 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
399 tablesize = si->zsize * si->ysize * sizeof(long); |
885 | 400 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
401 /* skip rle offset and length tables, write them at the end. */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
402 url_fseek(pb, tablesize * 2, SEEK_CUR); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
403 put_flush_packet(pb); |
885 | 404 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
405 lengthtab = av_malloc(tablesize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
406 offsettab = av_malloc(tablesize); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
407 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
408 for (z = 0; z < si->zsize; z++) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
409 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
410 #ifndef WORDS_BIGENDIAN |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
411 /* rgba -> bgra for rgba32 on little endian cpus */ |
885 | 412 if (si->zsize == 4 && z != 3) |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
413 chan_offset = 2 - z; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
414 else |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
415 #endif |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
416 chan_offset = z; |
885 | 417 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
418 srcrow = info->pict.data[0] + chan_offset; |
885 | 419 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
420 for (y = si->ysize -1; y >= 0; y--) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
421 offsettab[(z * si->ysize) + y] = url_ftell(pb); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
422 lengthtab[(z * si->ysize) + y] = rle_row(pb, srcrow, |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
423 si->zsize, si->xsize); |
885 | 424 srcrow += info->pict.linesize[0]; |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
425 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
426 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
427 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
428 url_fseek(pb, 512, SEEK_SET); |
885 | 429 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
430 /* write offset table */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
431 for (i = 0; i < (si->ysize * si->zsize); i++) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
432 put_be32(pb, offsettab[i]); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
433 } |
885 | 434 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
435 /* write length table */ |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
436 for (i = 0; i < (si->ysize * si->zsize); i++) { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
437 put_be32(pb, lengthtab[i]); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
438 } |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
439 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
440 put_flush_packet(pb); |
885 | 441 |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
442 av_free(lengthtab); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
443 av_free(offsettab); |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
444 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
445 return 0; |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
446 } |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
639
diff
changeset
|
447 #endif // CONFIG_MUXERS |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
448 |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
449 AVImageFormat sgi_image_format = { |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
450 "sgi", |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
451 "sgi,rgb,rgba,bw", |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
452 sgi_probe, |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
453 sgi_read, |
885 | 454 (1 << PIX_FMT_GRAY8) | (1 << PIX_FMT_RGB24) | (1 << PIX_FMT_RGBA32), |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
639
diff
changeset
|
455 #ifdef CONFIG_MUXERS |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
456 sgi_write, |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
457 #else |
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
458 NULL, |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
639
diff
changeset
|
459 #endif // CONFIG_MUXERS |
382
37a29b5200d8
added SGI image format, encoding and decoding, courtesy of Todd Kirby
melanson
parents:
diff
changeset
|
460 }; |