Revision 635d4aed

View differences:

libswscale/swscale.h
144 144
int sws_isSupportedOutput(enum PixelFormat pix_fmt);
145 145

  
146 146
/**
147
 * Alloctaes an empty SwsContext, this must be filled and passed to sws_init_context().
148
 * For filling see AVOptions, options.c and sws_setColorspaceDetails().
149
 */
150
struct SwsContext *sws_alloc_context(void);
151

  
152
/**
153
 * Initializs the swscaler context sws_context.
154
 */
155
int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter);
156

  
157
/**
147 158
 * Frees the swscaler context swsContext.
148 159
 * If swsContext is NULL, then does nothing.
149 160
 */
......
161 172
 * @param dstFormat the destination image format
162 173
 * @param flags specify which algorithm and options to use for rescaling
163 174
 * @return a pointer to an allocated context, or NULL in case of error
175
 * @deprecated use sws_alloc_context() and sws_init_context()
164 176
 */
165 177
struct SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat,
166 178
                                  int dstW, int dstH, enum PixelFormat dstFormat,
libswscale/utils.c
672 672
    *v = av_pix_fmt_descriptors[format].log2_chroma_h;
673 673
}
674 674

  
675
static int update_flags_cpu(int flags);
676

  
675 677
int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
676 678
{
677 679
    memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4);
......
684 686
    c->dstRange  = dstRange;
685 687
    if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
686 688

  
689
    c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[c->dstFormat]);
690
    c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[c->srcFormat]);
691
    c->flags = update_flags_cpu(c->flags);
692

  
687 693
    ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation);
688 694
    //FIXME factorize
689 695

  
......
729 735
    return flags;
730 736
}
731 737

  
732
SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat,
733
                           int dstW, int dstH, enum PixelFormat dstFormat, int flags,
734
                           SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
735
{
736
    SwsContext *c;
738
SwsContext *sws_alloc_context(void){
739
    SwsContext *c= av_mallocz(sizeof(SwsContext));
740

  
741
    c->av_class = &sws_context_class;
742

  
743
    return c;
744
}
745

  
746
int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter){
737 747
    int i;
738 748
    int usesVFilter, usesHFilter;
739 749
    int unscaled;
740
    int srcRange, dstRange;
741 750
    SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};
751
    int srcW= c->srcW;
752
    int srcH= c->srcH;
753
    int dstW= c->dstW;
754
    int dstH= c->dstH;
755
    int flags;
756
    enum PixelFormat srcFormat= c->srcFormat;
757
    enum PixelFormat dstFormat= c->dstFormat;
758

  
759
    flags= c->flags = update_flags_cpu(c->flags);
742 760
#if ARCH_X86
743 761
    if (flags & SWS_CPU_CAPS_MMX)
744 762
        __asm__ volatile("emms\n\t"::: "memory");
745 763
#endif
746

  
747
    flags = update_flags_cpu(flags);
748 764
    if (!rgb15to16) sws_rgb2rgb_init(flags);
749 765

  
750 766
    unscaled = (srcW == dstW && srcH == dstH);
751 767

  
752
    srcRange = handle_jpeg(&srcFormat);
753
    dstRange = handle_jpeg(&dstFormat);
754

  
755 768
    if (!isSupportedIn(srcFormat)) {
756 769
        av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input pixel format\n", sws_format_name(srcFormat));
757
        return NULL;
770
        return AVERROR(EINVAL);
758 771
    }
759 772
    if (!isSupportedOut(dstFormat)) {
760 773
        av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output pixel format\n", sws_format_name(dstFormat));
761
        return NULL;
774
        return AVERROR(EINVAL);
762 775
    }
763 776

  
764 777
    i= flags & ( SWS_POINT
......
774 787
                |SWS_BICUBLIN);
775 788
    if(!i || (i & (i-1))) {
776 789
        av_log(NULL, AV_LOG_ERROR, "swScaler: Exactly one scaler algorithm must be chosen\n");
777
        return NULL;
790
        return AVERROR(EINVAL);
778 791
    }
779

  
780 792
    /* sanity check */
781 793
    if (srcW<4 || srcH<1 || dstW<8 || dstH<1) { //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code
782 794
        av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n",
783 795
               srcW, srcH, dstW, dstH);
784
        return NULL;
796
        return AVERROR(EINVAL);
785 797
    }
786 798
    if(srcW > VOFW || dstW > VOFW) {
787 799
        av_log(NULL, AV_LOG_ERROR, "swScaler: Compile-time maximum width is "AV_STRINGIFY(VOFW)" change VOF/VOFW and recompile\n");
788
        return NULL;
800
        return AVERROR(EINVAL);
789 801
    }
790 802

  
791 803
    if (!dstFilter) dstFilter= &dummyFilter;
792 804
    if (!srcFilter) srcFilter= &dummyFilter;
793 805

  
794
    FF_ALLOCZ_OR_GOTO(NULL, c, sizeof(SwsContext), fail);
795

  
796
    c->av_class = &sws_context_class;
797
    c->srcW= srcW;
798
    c->srcH= srcH;
799
    c->dstW= dstW;
800
    c->dstH= dstH;
801 806
    c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW;
802 807
    c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH;
803
    c->flags= flags;
804
    c->dstFormat= dstFormat;
805
    c->srcFormat= srcFormat;
806 808
    c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[dstFormat]);
807 809
    c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[srcFormat]);
808 810
    c->vRounder= 4* 0x0001000100010001ULL;
......
834 836
      && ((dstW>>c->chrDstHSubSample) <= (srcW>>1) || (flags&SWS_FAST_BILINEAR)))
835 837
        c->chrSrcHSubSample=1;
836 838

  
837
    if (param) {
838
        c->param[0] = param[0];
839
        c->param[1] = param[1];
840
    } else {
841
        c->param[0] =
842
        c->param[1] = SWS_PARAM_DEFAULT;
843
    }
844

  
845 839
    // Note the -((-x)>>y) is so that we always round toward +inf.
846 840
    c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample);
847 841
    c->chrSrcH= -((-srcH) >> c->chrSrcVSubSample);
848 842
    c->chrDstW= -((-dstW) >> c->chrDstHSubSample);
849 843
    c->chrDstH= -((-dstH) >> c->chrDstVSubSample);
850 844

  
851
    sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16);
852

  
853 845
    /* unscaled special cases */
854
    if (unscaled && !usesHFilter && !usesVFilter && (srcRange == dstRange || isAnyRGB(dstFormat))) {
846
    if (unscaled && !usesHFilter && !usesVFilter && (c->srcRange == c->dstRange || isAnyRGB(dstFormat))) {
855 847
        ff_get_unscaled_swscale(c);
856 848

  
857 849
        if (c->swScale) {
858 850
            if (flags&SWS_PRINT_INFO)
859 851
                av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n",
860 852
                       sws_format_name(srcFormat), sws_format_name(dstFormat));
861
            return c;
853
            return 0;
862 854
        }
863 855
    }
864 856

  
......
914 906
#endif
915 907

  
916 908
            if (!c->lumMmx2FilterCode || !c->chrMmx2FilterCode)
917
                goto fail;
909
                return AVERROR(ENOMEM);
918 910
            FF_ALLOCZ_OR_GOTO(c, c->hLumFilter   , (dstW        /8+8)*sizeof(int16_t), fail);
919 911
            FF_ALLOCZ_OR_GOTO(c, c->hChrFilter   , (c->chrDstW  /4+8)*sizeof(int16_t), fail);
920 912
            FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW      /2/8+8)*sizeof(int32_t), fail);
......
1143 1135
    }
1144 1136

  
1145 1137
    c->swScale= ff_getSwsFunc(c);
1146
    return c;
1138
    return 0;
1139
fail: //FIXME replace things by appropriate error codes
1140
    return -1;
1141
}
1147 1142

  
1148
fail:
1149
    sws_freeContext(c);
1150
    return NULL;
1143
SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat,
1144
                           int dstW, int dstH, enum PixelFormat dstFormat, int flags,
1145
                           SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
1146
{
1147
    SwsContext *c;
1148

  
1149
    if(!(c=sws_alloc_context()))
1150
        return NULL;
1151

  
1152
    c->flags= flags;
1153
    c->srcW= srcW;
1154
    c->srcH= srcH;
1155
    c->dstW= dstW;
1156
    c->dstH= dstH;
1157
    c->srcRange = handle_jpeg(&srcFormat);
1158
    c->dstRange = handle_jpeg(&dstFormat);
1159
    c->srcFormat= srcFormat;
1160
    c->dstFormat= dstFormat;
1161

  
1162
    if (param) {
1163
        c->param[0] = param[0];
1164
        c->param[1] = param[1];
1165
    } else {
1166
        c->param[0] =
1167
        c->param[1] = SWS_PARAM_DEFAULT;
1168
    }
1169
    sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], c->srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/, c->dstRange, 0, 1<<16, 1<<16);
1170

  
1171
    if(sws_init_context(c, srcFilter, dstFilter) < 0){
1172
        sws_freeContext(c);
1173
        return NULL;
1174
    }
1175

  
1176
    return c;
1151 1177
}
1152 1178

  
1153 1179
SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,

Also available in: Unified diff