Hi, Here's a Sun Rasterfile decoder. http://wiki.multimedia.cx/index.php?title=Sun_rasterfile Documentation on the format is sparse, but it can decode all files I was able to find and generate with other tools. I uploaded all sample files to: ftp://samples.mplayerhq.hu/MPlayer/incoming/sunrast --Ivo
On Wed, 26 Dec 2007 14:00:50 +0100 Ivo <ivop at euronet.nl> wrote:
Hi,
Here's a Sun Rasterfile decoder.
http://wiki.multimedia.cx/index.php?title=Sun_rasterfile
Documentation on the format is sparse, but it can decode all files I was able to find and generate with other tools.
I uploaded all sample files to:
ftp://samples.mplayerhq.hu/MPlayer/incoming/sunrast
Moved to samples/sunrast Ciao, Roberto -- Better is the enemy of good enough.
On Wed, Dec 26, 2007 at 02:00:50PM +0100, Ivo wrote:
Hi,
Here's a Sun Rasterfile decoder.
http://wiki.multimedia.cx/index.php?title=Sun_rasterfile
Documentation on the format is sparse, but it can decode all files I was able to find and generate with other tools.
I uploaded all sample files to:
ftp://samples.mplayerhq.hu/MPlayer/incoming/sunrast [...] +static int sunrast_init(AVCodecContext *avctx) { + SUNRASTContext *s = avctx->priv_data; + + avcodec_get_frame_defaults((AVFrame*)&s->picture); + avctx->coded_frame= (AVFrame*)&s->picture; + s->picture.data[0] = NULL;
hmm [...]
+ AVFrame * const p = (AVFrame *)&s->picture;
hmm [...]
+ if (depth != 1 && depth != 8 && depth != 24) { + av_log(avctx, AV_LOG_ERROR, "invalid depth\n"); + return -1; + } + if (type > RT_BYTE_ENCODED && type <= RT_FORMAT_IFF) { + av_log(avctx, AV_LOG_ERROR, "unsupported (compression) type\n"); + return -1; + } + if (type > RT_FORMAT_IFF) { + av_log(avctx, AV_LOG_ERROR, "invalid (compression) type\n"); + return -1; + } + if (maptype & ~1) { + av_log(avctx, AV_LOG_ERROR, "invalid colormap type\n"); + return -1; + } + + buf += 32; + + switch (depth) { + case 1: + avctx->pix_fmt = PIX_FMT_MONOWHITE; + break; + case 8: + avctx->pix_fmt = PIX_FMT_PAL8; + break; + case 24: + avctx->pix_fmt = PIX_FMT_BGR24; + }
that if() at the top would better fit in a default here [...]
+ ptr = p->data[1]; + for (i=0; i<len; i++, ptr+=4) + *(uint32_t *)ptr = (buf[i]<<16) + (buf[len+i]<<8) + buf[len+len+i];
duplicate relative to your previous decoder (and i somehow think more decoders use this ...) [...]
+ i = 0; + for (a=0; a<alen*h; ) { + c = 1; + if ((b = *buf++) == 0x80) { + c = *buf++ + 1; + if (c != 1) + b = *buf++; + } + for (; c; c--, a++) {
while(c--){
+ if (i < stride) + ptr[i] = b;
this should be w not stride
+ if (++i >= alen) { + i = 0; + ptr += stride; + } + } + }
s/i/x/ s/c/run/ also i think this is not guranteed to stop at the end of the array [...]
+ *picture = *(AVFrame *)&s->picture; + *data_size = sizeof(AVPicture);
hmm [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Let us carefully observe those good qualities wherein our enemies excel us and endeavor to excel them, by avoiding what is faulty, and imitating what is excellent in them. -- Plutarch
On Wednesday 26 December 2007 21:50, Michael Niedermayer wrote:
+ avcodec_get_frame_defaults((AVFrame*)&s->picture); + avctx->coded_frame= (AVFrame*)&s->picture; + s->picture.data[0] = NULL;
hmm [...]
+ AVFrame * const p = (AVFrame *)&s->picture;
hmm [...]
+ *picture = *(AVFrame *)&s->picture; + *data_size = sizeof(AVPicture);
hmm
All fixed.
+ if (depth != 1 && depth != 8 && depth != 24) { + av_log(avctx, AV_LOG_ERROR, "invalid depth\n"); + return -1; + } [...] + case 24: + avctx->pix_fmt = PIX_FMT_BGR24; + }
that if() at the top would better fit in a default here
Done.
+ ptr = p->data[1]; + for (i=0; i<len; i++, ptr+=4) + *(uint32_t *)ptr = (buf[i]<<16) + (buf[len+i]<<8) + buf[len+len+i];
duplicate relative to your previous decoder (and i somehow think more decoders use this ...)
This is not exactly the same. The people at Sun's decided it was a good idea to store the palette like: R0R1R2..Rn G0G1G2...Gn B0B1B2...Bn and that's what this code converts to normal R0G0B0 etc..
+ for (; c; c--, a++) {
while(c--){
Done.
+ if (i < stride) + ptr[i] = b;
this should be w not stride
That would not be correct for 1 and 24 bit images. I thought stride was a good idea to be sure it never overflowed the scanline but was guaranteed to be long enough without further calculations. The check is necessary because in sun rasterfiles scanlines are padded again to 16-bit boundaries and, unlike pcx which had decoding stops after every scanline, runs can span multiple lines. I could however use the len variable and sometimes skip one store. Done that in the new patch.
+ if (++i >= alen) { + i = 0; + ptr += stride; + } + } + }
s/i/x/ s/c/run/
Done.
also i think this is not guranteed to stop at the end of the array
Yes, you are right. Corrupted image data could cause it to write past the end. Fixed by adding another condition. New patch attached. --Ivo
On Thu, Dec 27, 2007 at 12:16:24AM +0100, Ivo wrote:
On Wednesday 26 December 2007 21:50, Michael Niedermayer wrote:
+ avcodec_get_frame_defaults((AVFrame*)&s->picture); + avctx->coded_frame= (AVFrame*)&s->picture; + s->picture.data[0] = NULL;
hmm [...]
+ AVFrame * const p = (AVFrame *)&s->picture;
hmm [...]
+ *picture = *(AVFrame *)&s->picture; + *data_size = sizeof(AVPicture);
hmm
All fixed.
+ if (depth != 1 && depth != 8 && depth != 24) { + av_log(avctx, AV_LOG_ERROR, "invalid depth\n"); + return -1; + } [...] + case 24: + avctx->pix_fmt = PIX_FMT_BGR24; + }
that if() at the top would better fit in a default here
Done.
+ ptr = p->data[1]; + for (i=0; i<len; i++, ptr+=4) + *(uint32_t *)ptr = (buf[i]<<16) + (buf[len+i]<<8) + buf[len+len+i];
duplicate relative to your previous decoder (and i somehow think more decoders use this ...)
This is not exactly the same. The people at Sun's decided it was a good idea to store the palette like: R0R1R2..Rn G0G1G2...Gn B0B1B2...Bn and that's what this code converts to normal R0G0B0 etc..
+ for (; c; c--, a++) {
while(c--){
Done.
+ if (i < stride) + ptr[i] = b;
this should be w not stride
That would not be correct for 1 and 24 bit images. I thought stride was a good idea to be sure it never overflowed the scanline but was guaranteed to be long enough without further calculations. The check is necessary because in sun rasterfiles scanlines are padded again to 16-bit boundaries and, unlike pcx which had decoding stops after every scanline, runs can span multiple lines. I could however use the len variable and sometimes skip one store. Done that in the new patch.
+ if (++i >= alen) { + i = 0; + ptr += stride; + } + } + }
s/i/x/ s/c/run/
Done.
also i think this is not guranteed to stop at the end of the array
Yes, you are right. Corrupted image data could cause it to write past the end. Fixed by adding another condition.
New patch attached. [...]
+ AVFrame * const p = (AVFrame *)&s->picture;
hmmmmmmmm [...]
+ if (type == RT_BYTE_ENCODED) { + int a, value, run; + uint8_t *end = ptr + h*stride; + + x = 0; + for (a=0; a < alen*h && ptr < end; ) {
and what if stride is negative? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope
On Thursday 27 December 2007 01:53, Michael Niedermayer wrote:
On Thu, Dec 27, 2007 at 12:16:24AM +0100, Ivo wrote:
+ AVFrame * const p = (AVFrame *)&s->picture;
hmmmmmmmm
Oops, forgot that one. Fixed.
+ if (type == RT_BYTE_ENCODED) { + int a, value, run; + uint8_t *end = ptr + h*stride; + + x = 0; + for (a=0; a < alen*h && ptr < end; ) {
and what if stride is negative?
Yep, won't work correctly. How about this: + if (type == RT_BYTE_ENCODED) { + int a, value, run; + uint8_t *end = ptr + h*stride; + + x = 0; + for (a=0; a < alen*h && ptr != end; ) { + run = 1; + if ((value = *buf++) == 0x80) { + run = *buf++ + 1; + if (run != 1) + value = *buf++; + } + while (run--) { + if (x < len) + ptr[x] = value; + if (++x >= alen) { + x = 0; + ptr += stride; + if (ptr == end) + break; + } + a++; + } + } + } else { --Ivo
On Thu, Dec 27, 2007 at 12:53:16PM +0100, Ivo wrote:
On Thursday 27 December 2007 01:53, Michael Niedermayer wrote:
On Thu, Dec 27, 2007 at 12:16:24AM +0100, Ivo wrote:
+ AVFrame * const p = (AVFrame *)&s->picture;
hmmmmmmmm
Oops, forgot that one. Fixed.
+ if (type == RT_BYTE_ENCODED) { + int a, value, run; + uint8_t *end = ptr + h*stride; + + x = 0; + for (a=0; a < alen*h && ptr < end; ) {
and what if stride is negative?
Yep, won't work correctly. How about this:
+ if (type == RT_BYTE_ENCODED) { + int a, value, run; + uint8_t *end = ptr + h*stride; + + x = 0; + for (a=0; a < alen*h && ptr != end; ) { + run = 1; + if ((value = *buf++) == 0x80) { + run = *buf++ + 1; + if (run != 1) + value = *buf++; + } + while (run--) { + if (x < len) + ptr[x] = value; + if (++x >= alen) { + x = 0; + ptr += stride; + if (ptr == end) + break; + } + a++; + } + } + } else {
isnt the a < alen*h redundant? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB No great genius has ever existed without some touch of madness. -- Aristotle
On Thursday 27 December 2007 15:38, Michael Niedermayer wrote:
On Thu, Dec 27, 2007 at 12:53:16PM +0100, Ivo wrote:
Yep, won't work correctly. How about this:
+ if (type == RT_BYTE_ENCODED) { + int a, value, run; + uint8_t *end = ptr + h*stride; + + x = 0; + for (a=0; a < alen*h && ptr != end; ) { + run = 1; + if ((value = *buf++) == 0x80) { + run = *buf++ + 1; + if (run != 1) + value = *buf++; + } + while (run--) { + if (x < len) + ptr[x] = value; + if (++x >= alen) { + x = 0; + ptr += stride; + if (ptr == end) + break; + } + a++; + } + } + } else {
isnt the a < alen*h redundant?
Yes, it is. I removed the whole 'a' variable and changed it to a 'while(ptr!=end)' loop: if (type == RT_BYTE_ENCODED) { int value, run; uint8_t *end = ptr + h*stride; x = 0; while (ptr != end) { run = 1; if ((value = *buf++) == 0x80) { run = *buf++ + 1; if (run != 1) value = *buf++; } while (run--) { if (x < len) ptr[x] = value; if (++x >= alen) { x = 0; ptr += stride; if (ptr == end) break; } } } } else { --Ivo
On Fri, Dec 28, 2007 at 12:18:47AM +0100, Ivo wrote:
On Thursday 27 December 2007 15:38, Michael Niedermayer wrote:
On Thu, Dec 27, 2007 at 12:53:16PM +0100, Ivo wrote:
Yep, won't work correctly. How about this:
+ if (type == RT_BYTE_ENCODED) { + int a, value, run; + uint8_t *end = ptr + h*stride; + + x = 0; + for (a=0; a < alen*h && ptr != end; ) { + run = 1; + if ((value = *buf++) == 0x80) { + run = *buf++ + 1; + if (run != 1) + value = *buf++; + } + while (run--) { + if (x < len) + ptr[x] = value; + if (++x >= alen) { + x = 0; + ptr += stride; + if (ptr == end) + break; + } + a++; + } + } + } else {
isnt the a < alen*h redundant?
Yes, it is. I removed the whole 'a' variable and changed it to a 'while(ptr!=end)' loop:
if (type == RT_BYTE_ENCODED) { int value, run; uint8_t *end = ptr + h*stride;
x = 0; while (ptr != end) { run = 1; if ((value = *buf++) == 0x80) { run = *buf++ + 1; if (run != 1) value = *buf++; } while (run--) { if (x < len) ptr[x] = value; if (++x >= alen) { x = 0; ptr += stride; if (ptr == end) break; } } } } else {
ok [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I do not agree with what you have to say, but I'll defend to the death your right to say it. -- Voltaire
On Friday 28 December 2007 04:40, Michael Niedermayer wrote:
On Fri, Dec 28, 2007 at 12:18:47AM +0100, Ivo wrote:
Yes, it is. I removed the whole 'a' variable and changed it to a 'while(ptr!=end)' loop:
if (type == RT_BYTE_ENCODED) { int value, run; uint8_t *end = ptr + h*stride;
x = 0; while (ptr != end) { run = 1; if ((value = *buf++) == 0x80) { run = *buf++ + 1; if (run != 1) value = *buf++; } while (run--) { if (x < len) ptr[x] = value; if (++x >= alen) { x = 0; ptr += stride; if (ptr == end) break; } } } } else {
ok
Comitted. --Ivo
On Wed, Dec 26, 2007 at 02:00:50PM +0100, Ivo wrote:
Here's a Sun Rasterfile decoder.
--- libavcodec/sunrast.c (revision 0) +++ libavcodec/sunrast.c (revision 0) @@ -0,0 +1,196 @@ +/* + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */
nit: Please leave out the empty line. Build system part of the patch looks OK. Diego
On Wednesday 26 December 2007 22:27, Diego Biurrun wrote:
On Wed, Dec 26, 2007 at 02:00:50PM +0100, Ivo wrote:
Here's a Sun Rasterfile decoder.
--- libavcodec/sunrast.c (revision 0) +++ libavcodec/sunrast.c (revision 0) @@ -0,0 +1,196 @@ +/* + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */
nit: Please leave out the empty line.
Done.
Build system part of the patch looks OK.
I thought so too, but after comitting I noticed I missorted two entries :) --Ivo
participants (4)
-
diego@biurrun.de -
ivop@euronet.nl -
michaelni@gmx.at -
rxt@rtogni.it