[Ffmpeg-devel] [PATCH] C93 demuxer and decoder (GSoC qualification task)
Michael Niedermayer
michaelni
Thu Apr 5 23:23:42 CEST 2007
Hi
On Thu, Apr 05, 2007 at 11:39:35PM +0300, Anssi Hannula wrote:
> Michael Niedermayer wrote:
> > Hi
>
> Hi!
>
> > On Thu, Apr 05, 2007 at 10:36:15PM +0300, Anssi Hannula wrote:
> >>>> + ret = av_new_packet(pkt, datasize + 768 + 1);
> >>>> + if (ret < 0)
> >>>> + return ret;
> >>>> + pkt->data[0] = 0;
> >>>> +
> >>>> + ret = get_buffer(pb, pkt->data + 768 + 1, datasize);
> >>>> + if (ret < datasize) {
> >>>> + av_free_packet(pkt);
> >>>> + return AVERROR_IO;
> >>>> + }
> >>>> +
> >>>> + datasize = get_le16(pb); /* palette size */
> >>>> + if (datasize) {
> >>>> + if (datasize != 768) {
> >>>> + av_log(s, AV_LOG_ERROR, "invalid palette size %u\n", datasize);
> >>>> + av_free_packet(pkt);
> >>>> + return AVERROR_INVALIDDATA;
> >>>> + }
> >>>> + pkt->data[0] |= C93_HAS_PALETTE;
> >>>> + ret = get_buffer(pb, pkt->data + 1, datasize);
> >>>> + if (ret < datasize) {
> >>>> + av_free_packet(pkt);
> >>>> + return AVERROR_IO;
> >>>> + }
> >>>> + }
> >>> if there is no palette pkt->size should be decreased by 768
> >> Even when the 768 unused bytes are in the beginning of the pkt instead
> >> of the end?
> >
> > hmm, i missed that, i just thought if the packets get stored in some other
> > container (like avi) it would be better to avoid the extra useless 768 bytes
>
> I take it you don't think it is necessary to have the palette put in the
> end instead?
ive no real oppinion on the order of palette & frame, iam fine with either
though i would prefer if the extra unused 768 bytes could be avoided ....
[...]
> + case C93_8X8_2COLOR:
> + cols[0] = *buf++;
> + cols[1] = *buf++;
> + for (j = 0; j < 8; j++) {
> + for (i = 0; i < 8; i++) {
> + out[(y+j)*stride+x+i] = cols[(buf[0] >> i) & 1];
> + }
> + buf++;
> + }
> + break;
> +
> + case C93_4X4_2COLOR:
> + for (y_off = 0; y_off < 8; y_off += 4) {
> + for (x_off = 0; x_off < 8; x_off += 4) {
> + colbit = 0;
> + cols[0] = *buf++;
> + cols[1] = *buf++;
> + colmask = bytestream_get_le16(&buf);
> + for (j = 0; j < 4; j++) {
> + for (i = 0; i < 4; i++) {
> + out[(y+y_off+j)*stride+x+x_off+i] =
> + cols[(colmask >> colbit++) & 1];
> + }
> + }
> + }
> + }
> + break;
> +
> + case C93_4X4_4COLOR_GRP:
> + for (y_off = 0; y_off < 8; y_off += 4) {
> + for (x_off = 0; x_off < 8; x_off += 4) {
> + colbit = 0;
> + bytestream_get_buffer(&buf, cols, 4);
> + colmask = bytestream_get_le16(&buf);
> + for (j = 0; j < 4; j++) {
> + int curcols[2];
> + curcols[0] = j & 2 ? cols[3] : cols[0];
> + for (i = 0; i < 4; i++) {
> + curcols[1] = i & 2 ? cols[2] : cols[1];
> + out[(y+y_off+j)*stride+x+x_off+i] =
> + curcols[(colmask >> colbit++) & 1];
> + }
> + }
> + }
> + }
> + break;
> +
> + case C93_4X4_4COLOR:
> + for (y_off = 0; y_off < 8; y_off += 4) {
> + for (x_off = 0; x_off < 8; x_off += 4) {
> + colbit = 0;
> + bytestream_get_buffer(&buf, cols, 4);
> + colmask = bytestream_get_le32(&buf);
> + for (j = 0; j < 4; j++) {
> + for (i = 0; i < 4; i++) {
> + out[(y+y_off+j)*stride+x+x_off+i] =
> + cols[(colmask >> colbit) & 3];
> + colbit += 2;
> + }
> + }
the 2/4 color block draw code seems to occur 4 times, maybe that could be
simplfied?
> + }
> + }
> + break;
> +
> + case C93_NOOP:
> + break;
> +
> + case C93_8X8_INTRA:
> + for (j = 0; j < 8; j++) {
> + memcpy(&out[(y+j)*stride+x], buf, 8);
> + buf += 8;
> + }
> + break;
> +
> + default:
> + av_log(avctx, AV_LOG_ERROR, "unexpected type %x at %dx%d\n",
> + bt & 0x0F, x, y);
> + return -1;
> + }
> + bt >>= 4;
the out+y*stride+x could be factored out like
for(y=0; y<HEIGHT; y+=8){
out= newpic->data[0] + y*stride;
for(x=0; x<WIDTH; x+=8){
...
out+= 8;
}
}
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I count him braver who overcomes his desires than him who conquers his
enemies for the hardest victory is over self. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070405/927126c3/attachment.pgp>
More information about the ffmpeg-devel
mailing list