pattern matching – How can I let RegularExpression remove all colors from its regex-input string before processing it?

Regular expressions are a very powerful tool, but such expressions are often very cryptic. If you want to understand them, it is best to have colored pencils at hand to color-code the parts that belong together.

Thus, it is obvious to color-code regular expressions in Mathematica already during development, in order to add explanatory texts to the individual colored parts, explaining what they (should) do.

However, it is not possible to use such colored strings in RegularExpression in Mma: One gets then e.g. such an error message:

RegularExpression::msg8 (Range out of order in character class in RegularExpression…)

How can I teach RegularExpression to remove all color attributes contained in its search pattern and then continue as usual?

post processing – Is it possible to eliminate Moiré patterns from photos of screens?

The Moiré pattern you see is an artifact of the sampling frequency of the camera relative to that of the photographed display. If the camera sensor’s resolution isn’t somewhat close to that of the projected image of the display, you won’t see any Moiré, or the pattern you do see will be comparable in size to the screen itself.

One simple way to avoid this problem is to photograph the display subtly out of focus; this will blur the pixels together so that the space between them is less visible or completely lost, removing the sampling artifacts. Another, and probably the way used in commercial product photography, is to replace the actual display with “simulated display” (as has been done for decades with television advertisements). With modern editing software, it’s not difficult to apply the geometric distortions (keystoning and foreshortening) to make the simulated display exactly fit the photographed screen bezel — but you can start with a solid colors image or one with extremely high resolution that won’t show artifacts.

Unable to capture transparent background with post processing on while taking a screenshoot in Unity URP

I am trying to capture a screenshot of a sprite with transparent background and it works while post processing is of, but when I turn post processing on background is no longer transparent. I am not using unity’s screen capture API because I need a screenshot from specific camera that looks only on the game object I want to take screenshot off.
Here is my screenshot code:

private void createScreenshot()
{
    RenderTexture renderTexture = SpriteCamera.targetTexture;

    Texture2D renderResult = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false);
    Rect rect = new Rect(0, 0, renderTexture.width, renderTexture.height);
    renderResult.ReadPixels(rect, 0, 0);

    PreviewTex = renderResult;

    byte() byteArray = renderResult.EncodeToPNG();
    string filepath = ScreenshotName(renderResult.width, renderResult.height);
    File.WriteAllBytes(filepath, byteArray);

    RenderTexture.ReleaseTemporary(renderTexture);
    SpriteCamera.targetTexture = null;

}

 private void takeeScreenshot(int width, int height)
{
    SpriteCamera.targetTexture = RenderTexture.GetTemporary(width, height, 32);
}

post processing – How to process 360 photos without creating seam?

I shoot 360 photos with a 360 camera that takes the entire scene with two wide-angle lenses that are stitched together to obtain 360 panoramas. I use Rawtherapee for post-processing and colour correction. Unfortunately, I don’t have the original fisheye photos anymore.

The scene is stitched flawlessly by specific software for my 360 camera. The problem is that RawTherapee doesn’t account for the image wrapping around from the left edge to the right edge, even when there is the proper EXIF information for the 360 photo projection type. Every time I use settings that act “locally” within the photo (Shadows/Highlights, Local contrast, anything that involves a “radius” of action), it results in a colour discontinuity.

To overcome this, I use GIMP to enlarge the photo by ‘x’ cells on both sides (and above) by pasting part of the photo which is connected (on a 360 perspective) for each side. This allows me to use those Rawtherapee’s settings without concerns, but it takes longer to post-process photos this way.

Is there a tool/software/workaround to solve this problem in a more time-efficient way?

discontinuity

post meta – Correct processing of `$_POST`, following WordPress Coding Standards

I’m building a project that according to the specifications need to follow the WordPress Coding Standards. I am using phpcs to scan my code.

If I try to pass $_POST-data into a function without sanitizing it, I will get an error.

What I do before my code:

  • Verify that this is actually a POST request by checking that $_POST is set.
  • Verify that we have a value by checking if $_POST('faq_highlighted') is set.
  • Verify the nonce field using wp_verify_nonce to make sure that the request is from a valid source.

The code

I noticed that depending on how i pass the posted value, the the error will behave differently, or disappear, even though there is no change to the functionality of the code.

Version 1

In this version, I check if $_POST('faq_highlighted') is set. If it is, I update_post_meta against the meta key faq_highlighted with the value of $_POST('faq_highlighted').

// Version 1.
if ( isset( $_POST('faq_highlighted') ) ) {
    update_post_meta( $post_id, 'faq_highlighted', $_POST('faq_highlighted') ); // Error on this line.
}

This rightfully gives me the following error on row 3:

$_POST data not unslashed before sanitization. Use wp_unslash() or similar.
Detected usage of a non-sanitized input variable: $_POST(‘faq_highlighted’)

Version 2

In this version, without any unslashing, escaping or sanitazion, I pass the value of $_POST('faq_highlighted') into a variable called $value_of_post_faq_highlighted. And I get the same error, but on that line.

This makes sense, as it’s the use of a $_POST variable that is not unslashed that is triggering the error.

// Version 2.
$value_of_post_faq_highlighted = $_POST('faq_highlighted'); // Error on this line.
if ( isset( $post_faq_highlighted ) ) {
    update_post_meta( $post_id, 'faq_highlighted', $post_faq_highlighted );
}
Version 3

This is where it gets strange. I’m now passing the whole $_POST into a variable called $value_of_post. There is still no unslashing, escaping or sanitazion, but phpcs does not give me any warnings.

// Version 3 - No error!
$value_of_post = $_POST;
if ( isset( $value_of_post('faq_highlighted') ) ) {
    update_post_meta( $post_id, 'faq_highlighted', $value_of_post('faq_highlighted') );
}
  • Aren’t all the above mentioned blocks of code doing the exact same thing?
  • They should all fail the test, but why does the last one pass?
  • What would be the correct way of doing this?

As Version 3 passes, while still not looking okay to me, I’m not sure that my suggestion below is right either.

Version 4 – My suggestion

This is what I have come to use. I first wp_unslash and then sanitize_text_field, and I get no errors, which makes sense, as this is the only version that resolves the two errors from the first version.

// Version 4.
if ( isset( $_POST('faq_highlighted') ) ) {
    update_post_meta( $post_id, 'faq_highlighted', sanitize_text_field( wp_unslash( $_POST('faq_highlighted') ) ) );
}

Unreal Engine 4- Post Processing material isnt working on different viewports except perspective

I would like to render a silhouette of models, I found stencil would be the best way to capture. But when I am working with stencil post-process material its does not work with other viewports except perspective. Post fx material already enabled in the different view modes.

enter image description here

enter image description here

reinventing the wheel – Image Processing Histogram Equalization in C

base.h

/* Develop by Jimmy Hu */

#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define MAX_PATH 256
#define FILE_ROOT_PATH "./"

#define True true
#define False false

typedef struct RGB
{
    unsigned char channels(3);
} RGB;

typedef struct HSV
{
    long double channels(3);    //  Range: 0 <= H < 360, 0 <= S <= 1, 0 <= V <= 255
}HSV;

typedef struct BMPIMAGE
{
    char FILENAME(MAX_PATH);

    unsigned int XSIZE;
    unsigned int YSIZE;
    unsigned char FILLINGBYTE;
    unsigned char *IMAGE_DATA;
} BMPIMAGE;

typedef struct RGBIMAGE
{
    unsigned int XSIZE;
    unsigned int YSIZE;
    RGB *IMAGE_DATA;
} RGBIMAGE;
/* Develop by Jimmy Hu */

#include "base.h"

HSV *HSVHistogramEqualization(const int, const int, const HSV *);

HSV *RGBToHSV(const int, const int, const RGB *);

RGB *HSVToRGB(const int, const int, const HSV * const);

RGB *raw_image_to_array(const int, const int, const unsigned char *);

unsigned long bmp_read_x_size(const char *, const bool );

unsigned long bmp_read_y_size(const char *, const bool);

char bmp_read(unsigned char *, const int, const int, const char *, const bool);

BMPIMAGE bmp_file_read(const char *, const bool);

int bmp_write(const char *, const int, const int, const unsigned char *);

unsigned char *array_to_raw_image(const int, const int, const RGB*);

unsigned char bmp_filling_byte_calc(const unsigned int);

int cmpfunc (const void *, const void *);

unsigned char *bubble_sort_uchar(   const unsigned char *data_input,
                                    const unsigned long long int data_input_count,
                                    const bool mode);

int main(int argc, char** argv)
{
    printf("BMP image file name:(ex:test): ");
    char *FilenameString;
    FilenameString = malloc( sizeof *FilenameString * MAX_PATH);
    scanf("%s",FilenameString);
    BMPIMAGE BMPImage1;
    BMPImage1 = bmp_file_read(FilenameString, false);
    free(FilenameString);
    printf("%sn",BMPImage1.FILENAME);

    if(BMPImage1.IMAGE_DATA == NULL)
    {    
        printf("Image contents error!");
        return -1;
    }        

    RGBIMAGE RGBImage1;
    RGBImage1.XSIZE = BMPImage1.XSIZE;
    RGBImage1.YSIZE = BMPImage1.YSIZE;
    RGBImage1.IMAGE_DATA = malloc(sizeof *RGBImage1.IMAGE_DATA * RGBImage1.XSIZE * RGBImage1.YSIZE);
    if (RGBImage1.IMAGE_DATA == NULL)
    {
        printf("Memory allocation error!");
        return -1;
    }

    RGBImage1.IMAGE_DATA = raw_image_to_array(BMPImage1.XSIZE, BMPImage1.YSIZE, BMPImage1.IMAGE_DATA);

    HSVIMAGE HSVImage1;
    HSVImage1.XSIZE = RGBImage1.XSIZE;
    HSVImage1.YSIZE = RGBImage1.YSIZE;
    HSVImage1.IMAGE_DATA = RGBToHSV(RGBImage1.XSIZE, RGBImage1.YSIZE, RGBImage1.IMAGE_DATA);

    HSVImage1.IMAGE_DATA = HSVHistogramEqualization(HSVImage1.XSIZE, HSVImage1.YSIZE, HSVImage1.IMAGE_DATA);

    RGBIMAGE RGBImage2;
    RGBImage2.XSIZE = HSVImage1.XSIZE;
    RGBImage2.YSIZE = HSVImage1.YSIZE;
    RGBImage2.IMAGE_DATA = HSVToRGB(HSVImage1.XSIZE, HSVImage1.YSIZE, HSVImage1.IMAGE_DATA);
    bmp_write("Output", RGBImage2.XSIZE, RGBImage2.YSIZE, array_to_raw_image(RGBImage2.XSIZE, RGBImage2.YSIZE, RGBImage2.IMAGE_DATA));

    return 0;
}

HSV *HSVHistogramEqualization(const int xsize, const int ysize, const HSV * const image)
{
    HSV *output;
    output = malloc(sizeof *output * xsize * ysize);             
    if (output == NULL)
    {     
        printf("Memory allocation error!");
        return NULL;
    }
    for(long long int i = 0; i < (1LL * xsize * ysize); i++)
    {
        output(i).channels(0) = image(i).channels(0);
        output(i).channels(1) = image(i).channels(1);
        output(i).channels(2) = 0;
    }
    long long int CountPixel(256);
    for(int i = 0; i < 256; i++)
    {
        CountPixel(i) = 0;
    }
    for(long long int i = 0; i < (1LL * xsize * ysize); i++)
    {
        CountPixel((int)(image(i).channels(2))) = CountPixel((int)(image(i).channels(2))) + 1;
    }
    unsigned long long int PDF(256), CDF(256);
    for(int i = 0; i < 256; i++)
    {
        PDF(i) = CountPixel(i);
    }
    CDF(0) = PDF(0);
    for(int i = 1; i < 256; i++)
    {
        CDF(i) = CDF(i - 1) + PDF(i);
    }
    unsigned char ResultPixel(256);
    for(int i = 0; i < 256; i++)
    {
        ResultPixel(i) = CDF(i) * 255 / (xsize * ysize);
    }
    for(long long int i = 0; i < (1LL * xsize * ysize); i++)
    {
        output(i).channels(2) = ResultPixel((int)(image(i).channels(2)));
    }
    return output;
}

HSV *RGBToHSV(const int xsize,const int ysize, const RGB * const data_input)
{
    HSV *output;
    output = malloc(sizeof *output * xsize * ysize);
    if(output == NULL)
    {    
        printf("Memory allocation error!");
        return NULL;
    }
    for(int y = 0;y<ysize;y++)
    {
        for(int x = 0;x<xsize;x++)
        {
            output(y * xsize + x).channels(0) = 0;
            output(y * xsize + x).channels(1) = 0;
            output(y * xsize + x).channels(2) = 0;
        }
    }
    for(int y = 0; y < ysize; y++)
    {
        for(int x = 0; x < xsize; x++)
        {
            unsigned char Red,Green,Blue;
            Red = data_input(y * xsize + x).channels(0);
            Green = data_input(y * xsize + x).channels(1);
            Blue = data_input(y * xsize + x).channels(2);

            unsigned char *sort_array;
            sort_array = malloc( sizeof *sort_array * 3);
            sort_array(0) = Red;
            sort_array(1) = Green;
            sort_array(2) = Blue;
            sort_array = bubble_sort_uchar(sort_array, 3, 0);
            unsigned char Max,Mid,Min;
            Max = sort_array(2);
            Mid = sort_array(1);
            Min = sort_array(0);
            long double H1 = acos(0.5 * ((Red - Green) + (Red - Blue)) /
                             sqrt(((pow((Red - Green), 2.0)) + 
                             (Red - Blue) * (Green - Blue)))) * (180.0 / M_PI);
            if( Max == Min )
            {
                output(y * xsize + x).channels(0) = 0.0;
            }
            else if(Blue <= Green)
            {
                output(y * xsize + x).channels(0) = H1;
            }
            else
            {
                output(y * xsize + x).channels(0) = 360.0 - H1;
            }
            if(Max == 0)
            {
                output(y * xsize + x).channels(1) = 0.0;
            }
            else
            {
                output(y * xsize + x).channels(1) =
                1.0 - ( (long double)Min / (long double)Max);
            }
            output(y * xsize + x).channels(2) =
            sort_array(2);
            free(sort_array);
        }
    }
    return output;
}

RGB *HSVToRGB(const int xsize, const int ysize, const HSV * const data_input)
{
    RGB *output;
    output = malloc(sizeof *output * xsize * ysize); 
    if(output == NULL)
    {    
        printf("Memory allocation error!");
        return NULL;
    }
    for(int y = 0;y<ysize;y++)
    {
        for(int x = 0;x<xsize;x++)
        {
            output(y * xsize + x).channels(0) = 0;
            output(y * xsize + x).channels(1) = 0;
            output(y * xsize + x).channels(2) = 0;
        }
    }
    for(int y = 0; y < ysize; y++)
    {
        for(int x = 0;x < xsize; x++)
        {
            long double H, S, Max;
            H = data_input(y * xsize + x).channels(0);
            S = data_input(y * xsize + x).channels(1);
            Max = data_input(y * xsize + x).channels(2);
            unsigned char hi = floor( H / 60.0);
            long double f = (H / (long double)60.0) - hi;
            long double Min, q, t;
            Min = Max * (1.0 - S);
            q = Max * (1.0 - f * S);
            t = Max * (1.0 - (1.0 - f) * S);
            if(hi == 0)
            {
                output(y * xsize + x).channels(0) = Max;
                output(y * xsize + x).channels(1) = t;
                output(y * xsize + x).channels(2) = Min;
            }
            else if(hi == 1)
            {
                output(y * xsize + x).channels(0) = q;
                output(y * xsize + x).channels(1) = Max;
                output(y * xsize + x).channels(2) = Min;
            }
            else if(hi == 2)
            {
                output(y * xsize + x).channels(0) = Min;
                output(y * xsize + x).channels(1) = Max;
                output(y * xsize + x).channels(2) = t;
            }
            else if(hi == 3)
            {
                output(y * xsize + x).channels(0) = Min;
                output(y * xsize + x).channels(1) = q;
                output(y * xsize + x).channels(2) = Max;
            }
            else if(hi == 4)
            {
                output(y * xsize + x).channels(0) = t;
                output(y * xsize + x).channels(1) = Min;
                output(y * xsize + x).channels(2) = Max;
            }
            else if(hi == 5)
            {
                output(y * xsize + x).channels(0) = Max;
                output(y * xsize + x).channels(1) = Min;
                output(y * xsize + x).channels(2) = q;
            }
        }
    }
    return output;
}

RGB *raw_image_to_array(const int xsize, const int ysize, const unsigned char * const image)
{
    RGB *output;
    output = malloc(sizeof *output * xsize * ysize);
    if(output == NULL)
    {    
        printf("Memory allocation error!");
        return NULL;
    }        
    unsigned char filling_bytes;
    filling_bytes = bmp_filling_byte_calc(xsize);
    for(int y = 0; y < ysize; y++)
    {
        for(int x = 0; x < xsize; x++)
        {
            for (int color = 0; color < 3; color++) {
                output(y * xsize + x).channels(color) =
                    image(3 * (y * xsize + x) + y * filling_bytes + (2 - color));
            }
        }
    }
    return output;
}

//----bmp_read_x_size function----
unsigned long bmp_read_x_size(const char *filename, const bool extension)
{
    char fname_bmp(MAX_PATH);
    if(extension == false)
    {    
        sprintf(fname_bmp, "%s.bmp", filename);
    }        
    else
    {    
        strcpy(fname_bmp,filename);
    }    
    FILE *fp;
    fp = fopen(fname_bmp, "rb");
    if (fp == NULL) 
    {     
        printf("Fail to read file!n");
        return -1;
    }             
    unsigned char header(54);
    fread(header, sizeof(unsigned char), 54, fp);
    unsigned long output;
    output = header(18) + 
        ((unsigned long)header(19) << 8) +
        ((unsigned long)header(20) << 16) +
        ((unsigned long)header(21) << 24);
    fclose(fp);
    return output;
}

//---- bmp_read_y_size function ----
unsigned long bmp_read_y_size(const char * const filename, const bool extension)
{
    char fname_bmp(MAX_PATH);
    if(extension == false)
    {    
        sprintf(fname_bmp, "%s.bmp", filename);
    }        
    else
    {    
        strcpy(fname_bmp,filename);
    }    
    FILE *fp;
    fp = fopen(fname_bmp, "rb");
    if (fp == NULL)
    {
        printf("Fail to read file!n");
        return -1;
    }             
    unsigned char header(54);
    fread(header, sizeof(unsigned char), 54, fp);
    unsigned long output; 
    output= header(22) + 
        ((unsigned long)header(23) << 8) +
        ((unsigned long)header(24) << 16) +
        ((unsigned long)header(25) << 24);
    fclose(fp);
    return output;
}

//---- bmp_file_read function ---- 
char bmp_read(unsigned char *image, const int xsize, const int ysize, const char * const filename, const bool extension)
{
    char fname_bmp(MAX_PATH);
    if(extension == false)
    {    
        sprintf(fname_bmp, "%s.bmp", filename);
    }        
    else
    {    
        strcpy(fname_bmp,filename);
    }    
    unsigned char filling_bytes;
    filling_bytes = bmp_filling_byte_calc(xsize);
    FILE *fp;
    fp = fopen(fname_bmp, "rb");
    if (fp==NULL)
    {     
        printf("Fail to read file!n");
        return -1;
    }             
    unsigned char header(54);
    fread(header, sizeof(unsigned char), 54, fp);
    fread(image, sizeof(unsigned char), (size_t)(long)(xsize * 3 + filling_bytes)*ysize, fp);
    fclose(fp); 
    return 0;
}

BMPIMAGE bmp_file_read(const char * const filename, const bool extension)
{
    BMPIMAGE output;
    stpcpy(output.FILENAME, "");
    output.XSIZE = 0;
    output.YSIZE = 0;
    output.IMAGE_DATA = NULL;
    if(filename == NULL)
    {    
        printf("Path is nulln");
        return output;
    }
    char fname_bmp(MAX_PATH);
    if(extension == false)
    {
        sprintf(fname_bmp, "%s.bmp", filename);
    }
    else
    {    
        strcpy(fname_bmp,filename);
    }    
    FILE *fp;
    fp = fopen(fname_bmp, "rb");
    if (fp == NULL)
    {     
        printf("Fail to read file!n");
        return output;
    }             
    stpcpy(output.FILENAME, fname_bmp);
    output.XSIZE = (unsigned int)bmp_read_x_size(output.FILENAME,true);
    output.YSIZE = (unsigned int)bmp_read_y_size(output.FILENAME,true);
    if( (output.XSIZE == -1) || (output.YSIZE == -1) )
    {     
        printf("Fail to fetch information of image!");
        return output;
    }        
    else
    {     
        printf("Width of the input image: %dn",output.XSIZE);
        printf("Height of the input image: %dn",output.YSIZE);
        printf("Size of the input image(Byte): %dn", (size_t)output.XSIZE * output.YSIZE * 3);
        output.FILLINGBYTE = bmp_filling_byte_calc(output.XSIZE);
        output.IMAGE_DATA = malloc(sizeof *output.IMAGE_DATA * (output.XSIZE * 3 + output.FILLINGBYTE) * output.YSIZE);
        if (output.IMAGE_DATA == NULL)
        { 
            printf("Memory allocation error!");
            return output;
        }     
        else
        {
            for(int i = 0; i < ((output.XSIZE * 3 + output.FILLINGBYTE) * output.YSIZE);i++)
            {
                output.IMAGE_DATA(i) = 255;
            }
            bmp_read(output.IMAGE_DATA, output.XSIZE, output.YSIZE, output.FILENAME, true);
        }
    }    
    return output;
}

//----bmp_write function---- 
int bmp_write(const char * const filename, const int xsize, const int ysize, const unsigned char * const image) 
{
    unsigned char filling_bytes;
    filling_bytes = bmp_filling_byte_calc(xsize);
    unsigned char header(54) =
    {
    0x42, 0x4d, 0, 0, 0, 0, 0, 0, 0, 0,
    54, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 24, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0                        
    };                                
    unsigned long file_size = (long)xsize * (long)ysize * 3 + 54;
    unsigned long width, height;
    char fname_bmp(MAX_PATH);
    header(2) = (unsigned char)(file_size &0x000000ff);
    header(3) = (file_size >> 8) & 0x000000ff;        
    header(4) = (file_size >> 16) & 0x000000ff;        
    header(5) = (file_size >> 24) & 0x000000ff;        

    width = xsize;
    header(18) = width & 0x000000ff;
    header(19) = (width >> 8) &0x000000ff;
    header(20) = (width >> 16) &0x000000ff;
    header(21) = (width >> 24) &0x000000ff;

    height = ysize;
    header(22) = height &0x000000ff;
    header(23) = (height >> 8) &0x000000ff;
    header(24) = (height >> 16) &0x000000ff;
    header(25) = (height >> 24) &0x000000ff;
    sprintf(fname_bmp, "%s.bmp", filename);
    FILE *fp; 
    if (!(fp = fopen(fname_bmp, "wb")))
    {    
        return -1;
    }        
    fwrite(header, sizeof(unsigned char), 54, fp);
    fwrite(image, sizeof(unsigned char), (size_t)(long)(xsize * 3 + filling_bytes) * ysize, fp);
    fclose(fp);
    return 0;
}

unsigned char *array_to_raw_image(const int xsize, const int ysize, const RGB* const data_input)
{
    unsigned char filling_bytes;
    filling_bytes = bmp_filling_byte_calc(xsize);
    unsigned char *output;
    output = malloc(sizeof *output * (xsize * 3 + filling_bytes) * ysize);
    if(output == NULL)
    {    
        printf("Memory allocation error!");
        return NULL;
    }
    for(int y = 0;y < ysize;y++)
    {
        for(int x = 0;x < (xsize * 3 + filling_bytes);x++)
        {
            output(y * (xsize * 3 + filling_bytes) + x) = 0;
        }
    }
    for(int y = 0;y<ysize;y++)
    {
        for(int x = 0;x<xsize;x++)
        {
            output(3*(y * xsize + x) + y * filling_bytes + 2)
                = data_input(y*xsize + x).channels(0);
            output(3*(y * xsize + x) + y * filling_bytes + 1)
                = data_input(y*xsize + x).channels(1);
            output(3*(y * xsize + x) + y * filling_bytes + 0)
                = data_input(y*xsize + x).channels(2);
        }
    }
    return output;
}

unsigned char bmp_filling_byte_calc(const unsigned int xsize)
{
    unsigned char filling_bytes;
    filling_bytes = ( xsize % 4);
    return filling_bytes;
}

int cmpfunc (const void * a, const void * b) {
   return ( *(int*)a - *(int*)b );
}

unsigned char *bubble_sort_uchar(   const unsigned char *data_input,
                                    const unsigned long long int data_input_count,
                                    const bool mode)
{
    unsigned char *output;
    output = malloc( sizeof *output * data_input_count);
    for(unsigned long long int y = 0; y < data_input_count;y++)
    {
        output(y) = data_input(y);
    }
    for(unsigned long long int x = 1; x < data_input_count; x++)
    {
        for(unsigned long long int y = 0; y < data_input_count - x; y++)
        {
            if( mode == 0 )
            {
                if(output(y) > output(y + 1))
                {
                    unsigned char temp;
                    temp = output(y);
                    output(y) = output(y + 1);
                    output(y + 1) = temp;
                }
            }
            else if( mode == 1 )
            {
                if(output(y) < output(y + 1))
                {
                    unsigned char temp;
                    temp = output(y);
                    output(y) = output(y + 1);
                    output(y + 1) = temp;
                }
            }
        }
    }
    return output;
}
```

apt – dpkg: error processing package apparmor

can someone help me here, i have this problem on an Ubuntu 14.04.6 LTS system.

thanks in advance
Xaxa

The following packages were automatically installed and are no longer required:   gdisk gir1.2-freedesktop gir1.2-gdkpixbuf-2.0

gir1.2-rsvg-2.0 gvfs-libs libafterimage0 libbz2-dev
libcairo-script-interpreter2 libcdt5 libcgraph6 libdjvulibre-dev
libdrm-amdgpu1 libdrm-dev libelfg0 libexif-dev libexpat1-dev
libfontconfig1-dev libgdk-pixbuf2.0-dev libgl1-mesa-dev
libglib2.0-bin libglib2.0-dev libglu1-mesa libglu1-mesa-dev
libgraphviz-dev libgvc6 libgvc6-plugins-gtk libgvpr2 libilmbase-dev
libjasper-dev libjs-jquery liblcms2-dev libopenexr-dev libpathplan4
libpcre3-dev libpcrecpp0 libpixman-1-dev libsecret-1-0 libtiff5-dev
libtiffxx5 libudisks2-0 libwmf-dev libx11-xcb-dev libxcb-dri3-dev
libxcb-shm0-dev libxdamage-dev libxdot4 libxfixes-dev libxft2
libxml2-dev libxshmfence-dev mesa-common-dev udisks2
x11proto-damage-dev x11proto-dri2-dev x11proto-fixes-dev
x11proto-gl-dev Use ‘apt-get autoremove’ to remove them. The following
packages will be upgraded: libwebp-dev libwebp5 libwebpdemux1
libwebpmux1 webp 5 upgraded, 0 newly installed, 0 to remove and 0 not
upgraded. 3 not fully installed or removed. Need to get 423 kB of
archives. After this operation, 3,072 B disk space will be freed. Do
you want to continue? (Y/n) y Get:1 https://esm.ubuntu.com/ubuntu/
trusty-infra-security/main libwebp-dev amd64 0.4.0-4ubuntu0.1~esm1
(203 kB) Get:2 https://esm.ubuntu.com/ubuntu/
trusty-infra-security/main libwebpmux1 amd64 0.4.0-4ubuntu0.1~esm1
(13.7 kB) Get:3 https://esm.ubuntu.com/ubuntu/
trusty-infra-security/main libwebpdemux1 amd64 0.4.0-4ubuntu0.1~esm1
(7,854 B) Get:4 https://esm.ubuntu.com/ubuntu/
trusty-infra-security/main libwebp5 amd64 0.4.0-4ubuntu0.1~esm1 (146
kB) Get:5 https://esm.ubuntu.com/ubuntu/ trusty-infra-security/main
webp amd64 0.4.0-4ubuntu0.1~esm1 (52.2 kB) Fetched 423 kB in 0s (1,059
kB/s) (Reading database … 211709 files and directories currently
installed.) Preparing to unpack
…/libwebp-dev_0.4.0-4ubuntu0.1~esm1_amd64.deb … Unpacking
libwebp-dev:amd64 (0.4.0-4ubuntu0.1~esm1) over (0.4.0-4) … Preparing
to unpack …/libwebpmux1_0.4.0-4ubuntu0.1~esm1_amd64.deb …
Unpacking libwebpmux1:amd64 (0.4.0-4ubuntu0.1~esm1) over (0.4.0-4) …
Preparing to unpack …/libwebpdemux1_0.4.0-4ubuntu0.1~esm1_amd64.deb
… Unpacking libwebpdemux1:amd64 (0.4.0-4ubuntu0.1~esm1) over
(0.4.0-4) … Preparing to unpack
…/libwebp5_0.4.0-4ubuntu0.1~esm1_amd64.deb … Unpacking
libwebp5:amd64 (0.4.0-4ubuntu0.1~esm1) over (0.4.0-4) … Preparing to
unpack …/webp_0.4.0-4ubuntu0.1~esm1_amd64.deb … Unpacking webp
(0.4.0-4ubuntu0.1~esm1) over (0.4.0-4) … Processing triggers for
man-db (2.6.7.1-1ubuntu1) … Setting up apparmor (2.13.6-10) … mv:
invalid option — ‘Z’ Try ‘mv –help’ for more information. dpkg:
error processing package apparmor (–configure): subprocess installed
post-installation script returned error exit status 1 dpkg: dependency
problems prevent configuration of apparmor-profiles:
apparmor-profiles depends on apparmor (>= 2.8.96~2535-0ubuntu1~);
however: Package apparmor is not configured yet.

dpkg: error processing package apparmor-profiles (–configure):
dependency problems – leaving unconfigured Setting up x11-common
(1:7.7+22) … update-rc.d: warning: default start runlevel arguments
(2 3 4 5) do not match x11-common Default-Start values (S)
update-rc.d: warning: default stop runlevel arguments (0 1 6) do not
match x11-common Default-Stop values (none) invoke-rc.d: syntax error:
unknown option “–skip-systemd-native” dpkg: error processing package
x11-common (–configure): subprocess installed post-installation
script returned error exit status 1 Setting up libwebp5:amd64
(0.4.0-4ubuntu0.1~esm1) … Setting up libwebpmux1:amd64
(0.4.0-4ubuntu0.1~esm1) … Setting up libwebpdemux1:amd64
(0.4.0-4ubuntu0.1~esm1) … Setting up libwebp-dev:amd64
(0.4.0-4ubuntu0.1~esm1) … Setting up webp (0.4.0-4ubuntu0.1~esm1)
… Processing triggers for libc-bin (2.19-0ubuntu6.15+esm2) …
Errors were encountered while processing: apparmor apparmor-profiles
x11-common E: Sub-process /usr/bin/dpkg returned an error code (1)

sudo dpkg –configure -a && sudo apt -f install -> it does not work!

 apt-cache policy apparmor

apparmor:
Installed: 2.13.6-10
Candidate: 2.13.6-10
Version table:
*** 2.13.6-10 0
100 /var/lib/dpkg/status
2.10.95-0ubuntu2.6~14.04.4 0
500 http://repo.myloc.de/ubuntu/ trusty-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
2.8.95~2430-0ubuntu5 0
500 http://repo.myloc.de/ubuntu/ trusty/main amd64 Packages
dpkg -l | egrep -v ‘^ii|rc’
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
+++-=======================================-====================================================-============-===================================================================================================
iF apparmor 2.13.6-10 amd64 user-space parser utility for AppArmor
iU apparmor-profiles 2.13.6-10 all experimental profiles for AppArmor security policies
rF x11-common 1:7.7+22 all X Window System (X.Org) infrastructure

image processing – ColorReplace with thresholds and connected components

I would like to replace the colors in this etching (called img) with colors of my choice. (For simplicity, we can assume my desired colors are ColorData("Rainbow")(i) for i = 0, .1, ..., 1.)

etching

I have used PrincipalColors(img) to extract the principal colors and then used

ColorReplace(img, ...)

where the options are a list of associations, where White -> White and each of the remaining principal colors gets mapped to the Rainbow colors. Alas, because (I think) the distributions of colors are far from uniform, and because the edges of each line “blur” colors, the process never works. Each line in the drawing that should be a single color gets split.

I’ve tried ColorQuantize, ConnectedComponents, Erosion, Dilation and EdgeDetection, in various forms, but never quite get what I seek.

I think I’m missing some image processing function that will sharpen each line and ensure each pixel is quantized to the proper color, but just can’t find that function.