[FFmpeg-devel] [PATCH 07/11] avfilter/vf_coreimage: fix mixed declaration and code

Marvin Scholz epirat07 at gmail.com
Fri Jul 12 20:13:39 EEST 2024


Fix several "mixing declarations and code is incompatible with
standards before C99" warnings.
---
 libavfilter/vf_coreimage.m | 60 ++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 31 deletions(-)

diff --git a/libavfilter/vf_coreimage.m b/libavfilter/vf_coreimage.m
index 4d4cdfb7c7..bfc17764b5 100644
--- a/libavfilter/vf_coreimage.m
+++ b/libavfilter/vf_coreimage.m
@@ -66,6 +66,7 @@
 static int config_output(AVFilterLink *link)
 {
     CoreImageContext *ctx = link->src->priv;
+    const AVPixFmtDescriptor *desc;
 
     link->w                   = ctx->w;
     link->h                   = ctx->h;
@@ -73,7 +74,7 @@ static int config_output(AVFilterLink *link)
     link->frame_rate          = ctx->frame_rate;
     link->time_base           = ctx->time_base;
 
-    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
+    desc                           = av_pix_fmt_desc_get(link->format);
     ctx->bits_per_component        = av_get_bits_per_pixel(desc) / desc->nb_components;
 
     return 0;
@@ -106,14 +107,13 @@ static void list_filters(CoreImageContext *ctx)
 
     NSString *filter_name;
     while (filter_name = [filters nextObject]) {
-        av_log(ctx, AV_LOG_INFO, "Filter: %s\n", [filter_name UTF8String]);
-        NSString *input;
-
         CIFilter *filter             = [CIFilter filterWithName:filter_name];
         NSDictionary *filter_attribs = [filter attributes]; // <nsstring, id>
         NSArray      *filter_inputs  = [filter inputKeys];  // <nsstring>
 
-        for (input in filter_inputs) {
+        av_log(ctx, AV_LOG_INFO, "Filter: %s\n", [filter_name UTF8String]);
+
+        for (NSString *input in filter_inputs) {
             NSDictionary *input_attribs = [filter_attribs valueForKey:input];
             NSString *input_class       = [input_attribs valueForKey:kCIAttributeClass];
             if ([input_class isEqualToString:@"NSNumber"]) {
@@ -139,6 +139,11 @@ static void list_filters(CoreImageContext *ctx)
 static int apply_filter(CoreImageContext *ctx, AVFilterLink *link, AVFrame *frame)
 {
     int i;
+    CGImageRef out;
+    CGRect out_rect;
+    CIFilter *filter        = NULL;
+    CIImage  *filter_input  = (__bridge CIImage*)ctx->input_image;
+    CIImage  *filter_output = NULL;
 
     // (re-)initialize input image
     const CGSize frame_size = {
@@ -150,26 +155,22 @@ static int apply_filter(CoreImageContext *ctx, AVFilterLink *link, AVFrame *fram
                            length:frame->height*frame->linesize[0]
                            freeWhenDone:NO];
 
-    CIImage *ret = [(__bridge CIImage*)ctx->input_image initWithBitmapData:data
-                                                        bytesPerRow:frame->linesize[0]
-                                                        size:frame_size
-                                                        format:kCIFormatARGB8
-                                                        colorSpace:ctx->color_space]; //kCGColorSpaceGenericRGB
+    CIImage *ret = [filter_input initWithBitmapData:data
+                                 bytesPerRow:frame->linesize[0]
+                                 size:frame_size
+                                 format:kCIFormatARGB8
+                                 colorSpace:ctx->color_space]; //kCGColorSpaceGenericRGB
     if (!ret) {
         av_log(ctx, AV_LOG_ERROR, "Input image could not be initialized.\n");
         return AVERROR_EXTERNAL;
     }
 
-    CIFilter *filter       = NULL;
-    CIImage *filter_input  = (__bridge CIImage*)ctx->input_image;
-    CIImage *filter_output = NULL;
-
     // successively apply all filters
     for (i = 0; i < ctx->num_filters; i++) {
         if (i) {
             // set filter input to previous filter output
             filter_input    = [(__bridge CIImage*)ctx->filters[i-1] valueForKey:kCIOutputImageKey];
-            CGRect out_rect = [filter_input extent];
+            out_rect = [filter_input extent];
             if (out_rect.size.width > frame->width || out_rect.size.height > frame->height) {
                 // do not keep padded image regions after filtering
                 out_rect.origin.x    = 0.0f;
@@ -206,7 +207,7 @@ static int apply_filter(CoreImageContext *ctx, AVFilterLink *link, AVFrame *fram
     }
 
     // do not keep padded image regions after filtering
-    CGRect out_rect = [filter_output extent];
+    out_rect = [filter_output extent];
     if (out_rect.size.width > frame->width || out_rect.size.height > frame->height) {
         av_log(ctx, AV_LOG_DEBUG, "Cropping output image.\n");
         out_rect.origin.x    = 0.0f;
@@ -215,8 +216,8 @@ static int apply_filter(CoreImageContext *ctx, AVFilterLink *link, AVFrame *fram
         out_rect.size.height = frame->height;
     }
 
-    CGImageRef out = [(__bridge CIContext*)ctx->glctx createCGImage:filter_output
-                                                      fromRect:out_rect];
+    out = [(__bridge CIContext*)ctx->glctx createCGImage:filter_output
+                                           fromRect:out_rect];
 
     if (!out) {
         av_log(ctx, AV_LOG_ERROR, "Cannot create valid output image.\n");
@@ -227,12 +228,10 @@ static int apply_filter(CoreImageContext *ctx, AVFilterLink *link, AVFrame *fram
         CGContextRelease(ctx->cgctx);
         ctx->cgctx = NULL;
     }
-    size_t out_width  = CGImageGetWidth(out);
-    size_t out_height = CGImageGetHeight(out);
 
-    if (out_width > frame->width || out_height > frame->height) { // this might result in segfault
+    if (CGImageGetWidth(out) > frame->width || CGImageGetHeight(out) > frame->height) { // this might result in segfault
         av_log(ctx, AV_LOG_WARNING, "Output image has unexpected size: %lux%lu (expected: %ix%i). This may crash...\n",
-               out_width, out_height, frame->width, frame->height);
+               CGImageGetWidth(out), CGImageGetHeight(out), frame->width, frame->height);
     }
     ctx->cgctx = CGBitmapContextCreate(frame->data[0],
                                        frame->width,
@@ -247,25 +246,25 @@ static int apply_filter(CoreImageContext *ctx, AVFilterLink *link, AVFrame *fram
     }
 
     // copy ("draw") the output image into the frame data
-    CGRect rect = {{0,0},{frame->width, frame->height}};
+    out_rect = CGRectMake(0, 0, frame->width, frame->height);
     if (ctx->output_rect) {
         @try {
             NSString *tmp_string = [NSString stringWithUTF8String:ctx->output_rect];
             NSRect tmp           = NSRectFromString(tmp_string);
-            rect                 = NSRectToCGRect(tmp);
+            out_rect             = NSRectToCGRect(tmp);
         } @catch (NSException *exception) {
             av_log(ctx, AV_LOG_ERROR, "An error occurred: %s.", [exception.reason UTF8String]);
             return AVERROR_EXTERNAL;
         }
-        if (rect.size.width == 0.0f) {
+        if (out_rect.size.width == 0.0f) {
             av_log(ctx, AV_LOG_WARNING, "Width of output rect is zero.\n");
         }
-        if (rect.size.height == 0.0f) {
+        if (out_rect.size.height == 0.0f) {
             av_log(ctx, AV_LOG_WARNING, "Height of output rect is zero.\n");
         }
     }
 
-    CGContextDrawImage(ctx->cgctx, rect, out);
+    CGContextDrawImage(ctx->cgctx, out_rect, out);
 
     return ff_filter_frame(link, frame);
 }
@@ -434,6 +433,7 @@ static void set_option(CoreImageContext *ctx, CIFilter *filter, const char *key,
 
 static av_cold int init(AVFilterContext *fctx)
 {
+    NSOpenGLPixelFormat *pixel_format;
     CoreImageContext *ctx       = fctx->priv;
     AVDictionary *filter_dict   = NULL;
     const AVDictionaryEntry *f  = NULL;
@@ -504,14 +504,12 @@ static av_cold int init(AVFilterContext *fctx)
     }
 
     // create GPU context on OSX
-    const NSOpenGLPixelFormatAttribute attr[] = {
+    pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:(const NSOpenGLPixelFormatAttribute[]){
         NSOpenGLPFAAccelerated,
         NSOpenGLPFANoRecovery,
         NSOpenGLPFAColorSize, 32,
         0
-    };
-
-    NSOpenGLPixelFormat *pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:(void *)&attr];
+    }];
     ctx->color_space                  = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
     ctx->glctx                        = CFBridgingRetain([CIContext contextWithCGLContext:CGLGetCurrentContext()
                                                          pixelFormat:[pixel_format CGLPixelFormatObj]
-- 
2.39.3 (Apple Git-146)




More information about the ffmpeg-devel mailing list