Giter VIP home page Giter VIP logo

fpng-sequence's Introduction

Export to .mov (PNG Sequence)

Encoder is dependency on fpng (Dec 28, 2021).

inline unsigned char predictor(unsigned char a, unsigned char b, unsigned char c) {
    int p = a+b-c;
    int pa = abs(p-a);
    int pb = abs(p-b);
    int pc = abs(p-c);
    return (pa<=pb&&pa<=pc)?a:((pb<=pc)?b:c);
}

void apply_filter(int tid, uint8_t *pDst, uint8_t *pSrc, int w, int begin, int end, uint32_t ch) {

    unsigned char _blank[4] = {0,0,0,0};
    unsigned char *_filters[5] = {nullptr,nullptr,nullptr,nullptr,nullptr};

    for(int f=1; f<5; f++) {
        if(_filters[f]==nullptr) {
            _filters[f] = new unsigned char[w*ch];
        }
    }

    unsigned int src_row = w*ch;
    unsigned int dst_row = w*ch+1;

    for(int i=begin; i<end; i++) {

        unsigned char *src = pSrc+i*src_row;
        unsigned char *dst = pDst+i*dst_row+1;

        for(int j=0; j<w; j++) {
            unsigned char *W = (j==0)?_blank:src-ch;
            unsigned char *N = (i==0)?_blank:src-src_row;;
            unsigned char *NW = (i==0||j==0)?_blank:src-src_row-ch;
            for(int n=0; n<ch; n++) {
                _filters[1][j*ch+n] = (*src-*W)&0xFF;
                _filters[2][j*ch+n] = (*src-*N)&0xFF;
                _filters[3][j*ch+n] = (*src-((*W+*N)>>1))&0xFF;
                _filters[4][j*ch+n] = (*src-predictor(*W,*N,*NW))&0xFF;
                src++;
                W++;
                N++;
                NW++;
            }
        }

        const int INDEX = 0, VALUE = 1;
        int best_filter[2] = { 1, 0x7FFFFFFF };
        for(int f=1; f<5; f++) {
            for(int n=0; n<ch; n++) {
                int est = 0;
                for(int j=0; j<w; j++) {
                    est+=abs((char)_filters[f][j*ch+n]);
                }
                if(est<best_filter[VALUE]) {
                    best_filter[INDEX] = f;
                    best_filter[VALUE] = est;
                }
            }
        }

        int type = best_filter[INDEX];
        for(int j=0; j<w; j++) {
            for(int n=0; n<ch; n++) {
                *dst++ = _filters[type][j*ch+n];
            }
        }
        pDst[i*dst_row] = type;
    }

    for(int f=1; f<5; f++) {
        if(_filters[f]) {
            delete[] _filters[f];
        }
    }
}

Import from .mov (PNG Sequence)

Decoder is dependency on spng (v0.7.1).

xcodebuild -project ./spng.xcodeproj -scheme spng -sdk macosx -SKIP_INSTALL=NO
xcodebuild -project ./spng.xcodeproj -scheme spng -sdk iphoneos -SKIP_INSTALL=NO
xcodebuild -project ./spng.xcodeproj -scheme spng -sdk iphonesimulator -SKIP_INSTALL=NO

cp ./build/Release/libspng.a ./libspng.xcframework/macos-arm64/libspng.a
cp ./build/Release-iphoneos/libspng.a ./libspng.xcframework/ios-arm64/libspng.a
cp ./build/Release-iphonesimulator/libspng.a ./libspng.xcframework/ios-arm64-simulator/libspng.a

Trim .mov (PNG Sequence)

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        int begin = 100;
        int end = begin+30;
        
        NSString *path = @"./2022_01_09_21_36_56_487.mov";
        QTPNGParser *png = new QTPNGParser(path);
        if(png->length()>0) {
            QTPNGRecorder *recorder = new QTPNGRecorder(png->width(),png->height(),30,8*4,@"./trim.mov");            
            if(begin<end&&end<png->length()) {
                for(int k=begin; k<end; k++) {
                    NSData *data = png->get(k);
                    recorder->add((unsigned char *)data.bytes,data.length);
                }
                recorder->save();
            }
            else {
                NSLog(@"Error: %d,%d",begin,end);
            }
        }
        delete png;
    }
}

fpng-sequence's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

2bbb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.