Beispiel #1
0
static void samplecpy(void *dst, const void *src, int n, int maxval)
{
  if (maxval <= 255) {
    memcpy(dst, src, n);
  } else {
    int i;
    for (i=0; i<n/2; i++) {
      ((uint16_t *)dst)[i] = av_be2ne16(((uint16_t *)src)[i]);
    }
  }
}
Beispiel #2
0
void TlevelsPage::onCurveLoad(void)
{
    if (dlgGetFile(false,m_hwnd,_(-IDD_LEVELS,_l("Select curve file")),_l("Adobe Photoshop Curves (*.acv)\0*.acv\0All files (*.*)\0*.*\0"),_l("acv"),curvesflnm,_l("."),0)) {
        FILE *f=fopen(curvesflnm,_l("rb"));
        if (!f) {
            return;
        }
        int16_t w;
        if (fread(&w,1,2,f)==2 && av_be2ne16(w)==4)
            if (fread(&w,1,2,f)==2 && av_be2ne16(w)==5) {
                int16_t cnt;
                if (fread(&cnt,1,2,f)==2 && (cnt=av_be2ne16(cnt))>0) {
                    cnt=std::min(cnt,int16_t(10));
                    cfgSet(IDFF_levelsNumPoints,cnt);
                    std::pair<uint8_t,uint8_t> pts[10];
                    int numpoints=0;
                    for (int i=0; i<cnt; i++) {
                        int16_t x,y;
                        if (fread(&y,1,2,f)!=2 || fread(&x,1,2,f)!=2) {
                            break;
                        }
                        pts[numpoints].first=limit_uint8(av_be2ne16(x));
                        pts[numpoints].second=limit_uint8(av_be2ne16(y));
                        numpoints++;
                    }
                    std::sort(pts,pts+numpoints);
                    for (int i=0; i<numpoints; i++) {
                        cfgSet(TwidgetCurves::idffs[2*i+0],pts[i].first);
                        cfgSet(TwidgetCurves::idffs[2*i+1],pts[i].second);
                    }
                    wCurves->reset();
                    map2dlg();
                }
            }
        fclose(f);
    }
}
Beispiel #3
0
/*
 *
 * Decode a frame
 *
 */
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
{
        const uint8_t *buf = avpkt->data;
        int buf_size = avpkt->size;
        EightBpsContext * const c = avctx->priv_data;
        const unsigned char *encoded = buf;
        unsigned char *pixptr, *pixptr_end;
        unsigned int height = avctx->height; // Real image height
        unsigned int dlen, p, row;
        const unsigned char *lp, *dp;
        unsigned char count;
        unsigned int px_inc;
        unsigned int planes = c->planes;
        unsigned char *planemap = c->planemap;

        if(c->pic.data[0])
                avctx->release_buffer(avctx, &c->pic);

        c->pic.reference = 0;
        c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
        if(avctx->get_buffer(avctx, &c->pic) < 0){
                av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
                return -1;
        }

        /* Set data pointer after line lengths */
        dp = encoded + planes * (height << 1);

        /* Ignore alpha plane, don't know what to do with it */
        if (planes == 4)
                planes--;

        px_inc = planes + (avctx->pix_fmt == PIX_FMT_RGB32);

        for (p = 0; p < planes; p++) {
                /* Lines length pointer for this plane */
                lp = encoded + p * (height << 1);

                /* Decode a plane */
                for(row = 0; row < height; row++) {
                        pixptr = c->pic.data[0] + row * c->pic.linesize[0] + planemap[p];
                        pixptr_end = pixptr + c->pic.linesize[0];
                        dlen = av_be2ne16(*(const unsigned short *)(lp+row*2));
                        /* Decode a row of this plane */
                        while(dlen > 0) {
                                if(dp + 1 >= buf+buf_size) return -1;
                                if ((count = *dp++) <= 127) {
                                        count++;
                                        dlen -= count + 1;
                                        if (pixptr + count * px_inc > pixptr_end)
                                            break;
                                        if(dp + count > buf+buf_size) return -1;
                                        while(count--) {
                                                *pixptr = *dp++;
                                                pixptr += px_inc;
                                        }
                                } else {
                                        count = 257 - count;
                                        if (pixptr + count * px_inc > pixptr_end)
                                            break;
                                        while(count--) {
                                                *pixptr = *dp;
                                                pixptr += px_inc;
                                        }
                                        dp++;
                                        dlen -= 2;
                                }
                        }
                }
        }

        if (avctx->bits_per_coded_sample <= 8) {
                const uint8_t *pal = av_packet_get_side_data(avpkt,
                                                             AV_PKT_DATA_PALETTE,
                                                             NULL);
                if (pal) {
                        c->pic.palette_has_changed = 1;
                        memcpy(c->pal, pal, AVPALETTE_SIZE);
                }

                memcpy (c->pic.data[1], c->pal, AVPALETTE_SIZE);
        }

        *data_size = sizeof(AVFrame);
        *(AVFrame*)data = c->pic;

        /* always report that the buffer was completely consumed */
        return buf_size;
}
Beispiel #4
0
static int pnm_decode_frame(AVCodecContext *avctx, void *data,
                            int *data_size, AVPacket *avpkt)
{
    const uint8_t *buf   = avpkt->data;
    int buf_size         = avpkt->size;
    PNMContext * const s = avctx->priv_data;
    AVFrame *picture     = data;
    AVFrame * const p    = (AVFrame*)&s->picture;
    int i, j, n, linesize, h, upgrade = 0;
    unsigned char *ptr;
    int components, sample_len;

    s->bytestream_start =
    s->bytestream       = buf;
    s->bytestream_end   = buf + buf_size;

    if (ff_pnm_decode_header(avctx, s) < 0)
        return -1;

    if (p->data[0])
        avctx->release_buffer(avctx, p);

    p->reference = 0;
    if (avctx->get_buffer(avctx, p) < 0) {
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return -1;
    }
    p->pict_type = FF_I_TYPE;
    p->key_frame = 1;

    switch (avctx->pix_fmt) {
    default:
        return -1;
    case PIX_FMT_RGB48BE:
        n = avctx->width * 6;
        components=3;
        sample_len=16;
        goto do_read;
    case PIX_FMT_RGB24:
        n = avctx->width * 3;
        components=3;
        sample_len=8;
        goto do_read;
    case PIX_FMT_GRAY8:
        n = avctx->width;
        components=1;
        sample_len=8;
        if (s->maxval < 255)
            upgrade = 1;
        goto do_read;
    case PIX_FMT_GRAY16BE:
    case PIX_FMT_GRAY16LE:
        n = avctx->width * 2;
        components=1;
        sample_len=16;
        if (s->maxval < 65535)
            upgrade = 2;
        goto do_read;
    case PIX_FMT_MONOWHITE:
    case PIX_FMT_MONOBLACK:
        n = (avctx->width + 7) >> 3;
        components=1;
        sample_len=1;
    do_read:
        ptr      = p->data[0];
        linesize = p->linesize[0];
        if (s->bytestream + n * avctx->height > s->bytestream_end)
            return -1;
        if(s->type < 4){
            for (i=0; i<avctx->height; i++) {
                PutBitContext pb;
                init_put_bits(&pb, ptr, linesize);
                for(j=0; j<avctx->width * components; j++){
                    unsigned int c=0;
                    int v=0;
                    while(s->bytestream < s->bytestream_end && (*s->bytestream < '0' || *s->bytestream > '9' ))
                        s->bytestream++;
                    if(s->bytestream >= s->bytestream_end)
                        return -1;
                    do{
                        v= 10*v + c;
                        c= (*s->bytestream++) - '0';
                    }while(c <= 9);
                    put_bits(&pb, sample_len, (((1<<sample_len)-1)*v + (s->maxval>>1))/s->maxval);
                }
                flush_put_bits(&pb);
                ptr+= linesize;
            }
        }else{
        for (i = 0; i < avctx->height; i++) {
            if (!upgrade)
                memcpy(ptr, s->bytestream, n);
            else if (upgrade == 1) {
                unsigned int j, f = (255 * 128 + s->maxval / 2) / s->maxval;
                for (j = 0; j < n; j++)
                    ptr[j] = (s->bytestream[j] * f + 64) >> 7;
            } else if (upgrade == 2) {
                unsigned int j, v, f = (65535 * 32768 + s->maxval / 2) / s->maxval;
                for (j = 0; j < n / 2; j++) {
                    v = av_be2ne16(((uint16_t *)s->bytestream)[j]);
                    ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15;
                }
            }
Beispiel #5
0
static int decode_frame(AVCodecContext *avctx, void *data,
                        int *got_frame, AVPacket *avpkt)
{
    AVFrame *frame = data;
    const uint8_t *buf = avpkt->data;
    int buf_size       = avpkt->size;
    EightBpsContext * const c = avctx->priv_data;
    const unsigned char *encoded = buf;
    unsigned char *pixptr, *pixptr_end;
    unsigned int height = avctx->height; // Real image height
    unsigned int dlen, p, row;
    const unsigned char *lp, *dp, *ep;
    unsigned char count;
    unsigned int px_inc;
    unsigned int planes     = c->planes;
    unsigned char *planemap = c->planemap;
    int ret;

    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return ret;
    }

    ep = encoded + buf_size;

    /* Set data pointer after line lengths */
    dp = encoded + planes * (height << 1);

    /* Ignore alpha plane, don't know what to do with it */
    if (planes == 4)
        planes--;

    px_inc = planes + (avctx->pix_fmt == AV_PIX_FMT_RGB32);

    for (p = 0; p < planes; p++) {
        /* Lines length pointer for this plane */
        lp = encoded + p * (height << 1);

        /* Decode a plane */
        for (row = 0; row < height; row++) {
            pixptr = frame->data[0] + row * frame->linesize[0] + planemap[p];
            pixptr_end = pixptr + frame->linesize[0];
            if (ep - lp < row * 2 + 2)
                return AVERROR_INVALIDDATA;
            dlen = av_be2ne16(*(const unsigned short *)(lp + row * 2));
            /* Decode a row of this plane */
            while (dlen > 0) {
                if (ep - dp <= 1)
                    return AVERROR_INVALIDDATA;
                if ((count = *dp++) <= 127) {
                    count++;
                    dlen -= count + 1;
                    if (pixptr_end - pixptr < count * px_inc)
                        break;
                    if (ep - dp < count)
                        return AVERROR_INVALIDDATA;
                    while (count--) {
                        *pixptr = *dp++;
                        pixptr += px_inc;
                    }
                } else {
                    count = 257 - count;
                    if (pixptr_end - pixptr < count * px_inc)
                        break;
                    while (count--) {
                        *pixptr = *dp;
                        pixptr += px_inc;
                    }
                    dp++;
                    dlen -= 2;
                }
            }
        }
    }

    if (avctx->bits_per_coded_sample <= 8) {
        const uint8_t *pal = av_packet_get_side_data(avpkt,
                                                     AV_PKT_DATA_PALETTE,
                                                     NULL);
        if (pal) {
            frame->palette_has_changed = 1;
            memcpy(c->pal, pal, AVPALETTE_SIZE);
        }

        memcpy (frame->data[1], c->pal, AVPALETTE_SIZE);
    }

    *got_frame = 1;

    /* always report that the buffer was completely consumed */
    return buf_size;
}
Beispiel #6
0
static int ExtractDSFrameData( uint8_t * buffer, struct DMImageData *frameData )
{
    int         retVal = AVERROR(EIO);
    int         bufIdx = 0;

    if( buffer != NULL ) {
        memcpy( frameData->identifier, &buffer[bufIdx], ID_LENGTH );
        bufIdx += ID_LENGTH;

        memcpy( &frameData->jpegLength, &buffer[bufIdx], sizeof(unsigned long) );
        bufIdx += sizeof(unsigned long);
        frameData->jpegLength = av_be2ne32(frameData->jpegLength);

        memcpy( &frameData->imgSeq, &buffer[bufIdx], sizeof(int64_t) );
        bufIdx += sizeof(int64_t);
        frameData->imgSeq = av_be2ne64(frameData->imgSeq);

        memcpy( &frameData->imgTime, &buffer[bufIdx], sizeof(int64_t) );
        bufIdx += sizeof(int64_t);

        memcpy( &frameData->camera, &buffer[bufIdx], sizeof(unsigned char) );
        bufIdx += sizeof(unsigned char);

        memcpy( &frameData->status, &buffer[bufIdx], sizeof(unsigned char) );
        bufIdx += sizeof(unsigned char);

        memcpy( &frameData->activity, &buffer[bufIdx], sizeof(unsigned short) * NUM_ACTIVITIES );
        bufIdx += sizeof(unsigned short) * NUM_ACTIVITIES;

        memcpy( &frameData->QFactor, &buffer[bufIdx], sizeof(unsigned short) );
        bufIdx += sizeof(unsigned short);
        frameData->QFactor = av_be2ne16(frameData->QFactor);

        memcpy( &frameData->height, &buffer[bufIdx], sizeof(unsigned short) );
        bufIdx += sizeof(unsigned short);
        frameData->height = av_be2ne16(frameData->height);

        memcpy( &frameData->width, &buffer[bufIdx], sizeof(unsigned short) );
        bufIdx += sizeof(unsigned short);
        frameData->width = av_be2ne16(frameData->width);

        memcpy( &frameData->resolution, &buffer[bufIdx], sizeof(unsigned short) );
        bufIdx += sizeof(unsigned short);
        frameData->resolution = av_be2ne16(frameData->resolution);

        memcpy( &frameData->interlace, &buffer[bufIdx], sizeof(unsigned short) );
        bufIdx += sizeof(unsigned short);
        frameData->interlace = av_be2ne16(frameData->interlace);

        memcpy( &frameData->subHeaderMask, &buffer[bufIdx], sizeof(unsigned short) );
        bufIdx += sizeof(unsigned short);
        frameData->subHeaderMask = av_be2ne16(frameData->subHeaderMask);

        memcpy( frameData->camTitle, &buffer[bufIdx], sizeof(char) * CAM_TITLE_LENGTH );
        bufIdx += sizeof(char) * CAM_TITLE_LENGTH;

        memcpy( frameData->alarmText, &buffer[bufIdx], sizeof(char) * ALARM_TEXT_LENGTH );
        bufIdx += sizeof(char) * ALARM_TEXT_LENGTH;

        retVal = 0;
    }

    return retVal;
}
Beispiel #7
0
static struct DMImageData * parseDSJFIFHeader( uint8_t *data, int dataSize )
{
    struct DMImageData *            frameData = NULL;
    int                         i;
    unsigned short              length, marker;
    int                         sos = FALSE;

    i = 0;
    while( ((unsigned char)data[i] != 0xff) && (i < dataSize) )
        i++;

    if ( (unsigned char) data[++i] != 0xd8)
        return NULL;  /* Bad SOI */

    i++;

    while( !sos && (i < dataSize) ) {
        memcpy(&marker, &data[i], 2 );
        i += 2;
        memcpy(&length, &data[i], 2 );
        i += 2;
        marker = av_be2ne16(marker);
        length = av_be2ne16(length);

        switch (marker) {
            case 0xffe0 : {    // APP0
                /* Have a little look at the data in this block, see if it's what we're looking for */
                if( memcmp( &data[i], DSApp0Identifier, strlen(DSApp0Identifier) ) == 0 ) {
                    int         offset = i;

                    if( (frameData = av_mallocz( sizeof(struct DMImageData) )) != NULL ) {
                        /* Extract the values into a data structure */
                        if( ExtractDSFrameData( &data[offset], frameData ) < 0 ) {
                            av_free( frameData );
                            return NULL;
                        }
                    }
                }

                i += length - 2;
            }
            break;

            case 0xffdb :    // Q table
                i += length - 2;
                break;

            case 0xffc0 :    // SOF
                i += length - 2;
                break;

            case 0xffc4 :    // Huffman table
                i += length - 2;
                break;

            case 0xffda :    // SOS
                i += length - 2;
                sos = TRUE;
                break;

            case 0xffdd :    // DRI
                i += length - 2;
                break;

            case 0xfffe :    // Comment
                i += length - 2;
                break;

            default :
                /* Unknown marker encountered, better just skip past it */
                i += length - 2;    // JCB 026 skip past the unknown field
                break;
        }
    }

    return frameData;
}