Local Imagemagick not converting to DDS (DXT5) correctly - opengl

I'm having some difficulty using the ImageMagick command line utility to properly convert a png to a DDS file with the DXT5 compression algorithm.
convert -format dds -define dds:compression=dxt5 leia.png leia.dds
This was done using Version: ImageMagick 6.8.9-10 Q16 x86_64 2016-09-14. I am able to view the file locally, so it appears correct. When I load it into OpenGL however, I just see artifacts all over the place (random color pixels). To confirm the generated file was a DDS file:
od -bc leia.dds | head
Which generated:
$ od -bc leia.dds | head
0000000 104 104 123 040 174 000 000 000 007 020 010 000 356 002 000 000
D D S | \0 \0 \0 \a 020 \b \0 356 002 \0 \0
0000020 024 003 000 000 120 014 000 000 000 000 000 000 001 000 000 000
024 003 \0 \0 P \f \0 \0 \0 \0 \0 \0 001 \0 \0 \0
0000040 111 115 101 107 105 115 101 107 111 103 113 000 000 000 000 000
I M A G E M A G I C K \0 \0 \0 \0 \0
0000060 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000100 000 000 000 000 000 000 000 000 000 000 000 000 040 000 000 000
\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
You can see the first part of the header which contains the DDS header.
So for giggles, I decided, hey, maybe I should try converting this image using a separate utility, just to make sure there is nothing wrong with the file. When I then loaded in this file to OpenGL, it worked correctly.
When the file downloaded, I also checked the header again and saw:
od -bc leia-online.dds | head
0000000 104 104 123 040 174 000 000 000 007 020 010 000 356 002 000 000
D D S | \0 \0 \0 \a 020 \b \0 356 002 \0 \0
0000020 024 003 000 000 300 012 011 000 000 000 000 000 001 000 000 000
024 003 \0 \0 300 \n \t \0 \0 \0 \0 \0 001 \0 \0 \0
0000040 111 115 101 107 105 115 101 107 111 103 113 000 000 000 000 000
I M A G E M A G I C K \0 \0 \0 \0 \0
0000060 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000100 000 000 000 000 000 000 000 000 000 000 000 000 040 000 000 000
\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
It appears the online tool is using ImageMagick, same as I.
If you look at the first result it, Octals 20-23 are: 120 014 000 000 vs the online result of: 300 012 011 000. According to this indexes 20-23 point to the 'byte count'
So basically, my underlying question is this: How do I properly convert a png file to a dds texture using ImageMagick?
Update:
The online imagemagick generated the image header with:
width: 788 height: 750 linearSize: 592576 mipmap_count: 1
My local version of imagemagick generated the image header with:
width: 788 height: 750 linearSize: 3152 mipmap_count: 1
So I wonder if I'm missing a flag somewhere to get it to correctly write the header that the online version might be using?

As it turns out, it was a just a matter of my ImageMagick version. Upgrading from
ImageMagick 6.8.9-10 Q16 x86_64 2016-09-14 http://www.imagemagick.org
to
ImageMagick 7.0.6-0 Q16 x86_64 2017-06-12 http://www.imagemagick.org
fixed it. Thanks for everyone's help!

Related

Find digits (below certian number) on the page from specific work until specific last word is found

Would like some support here with a Regex.
Regular expression:
(\scaptain\s.*b([1-9]|[12][0-9]|3[01])\s[0-4][0-9][0-9]\s.*morgan\s)
Test string:
bla bla bla captain bla bla 1 250 2 450 9 501 11 900 21 900 30 400 31 1023 morgan bla bla bla
Question: Match a 3 digit number below 500 after the word "captain"and until the word "morgan" appears.
Goal: Match the 3 digit number below 500
All support much appreciated!
You could do that with positive and negative lookahead:
\b[0-4][0-9][0-9]\b(?=.*morgan)(?!.*captain)
\b word break
[0-4][0-9][0-9] and number from 000 to 499
(?=.*morgan)has to be followed by morgan somewhere
(?!.*captain) can not be followed by captain anywhere
if you don't want to have 000 to 099 included then it would be
\b[1-4][0-9][0-9]\b(?=.*morgan)(?!.*captain)
What is not covered is, that the string has to contain captain.
example: https://regex101.com/r/uFtBiy/1

Regex Get Value before string or number

I would like to ask is that possible to get digit or string after The word.
e.g
Abc ddd 1 0.4 44 USD 99 00 99
cc gg 1 0.4 445 66 USD 100 00 999
bb dd xx cc 56 78 99 65 35.45 USD 99 00 88 66 99
Out put target any value before USD
44
66
35.45
meaning that any value before USD.
Try using below code but couldnt get
(?<=USD\s\d+)\S+
Your regex attempts to match one or more non-whitespace chars that are immediately preceded with USD + a whitespace + one or more digits. However, you need to get the numbers that are to the left of the USD substring.
You can use a lookahead based solution here:
\d+(?:\.\d+)?(?=\s+USD\b)
See the regex demo.
Details:
\d+(?:\.\d+)? - one or more digits followed with an optional sequence of a dot and one or more digits
(?=\s+USD\b) - the positive lookahead makes sure there are
\s+ - one or more whitespace chars
USD\b - and an USD substring as a whole word (as \b is a word boundary).

Regular Expression to match amounts

I have this regular expression:
^-?([0-9]{1,3})+([ 0-9]{3})*([\.0-9]{2})?$
Format should be marked as valid:
190 254 254
10 254 254
1 254 982
250 254
10 254
1 154
190 254 254.22
10 254 254.22
1 254 982.22
250 254.22
10 254.22
1 154.22
-190 254 254
-10 254 254
-1 254 982
-250 254
-10 254
-1 154
-190 254 254.22
-10 254 254.22
-1 254 982.22
-250 254.22
-10 254.22
-1 154.22
But after I tested it here I got only partial matching.
UPDATE:
After correcting the regular expression by Mr #anubhava, the QLineEdit now accepts other formats too:
4654d654
55d54
444444
These is how I validate the input:
QRegExp rx("^-?[0-9]{1,3}(?: [0-9]{3})*(?:\.[0-9]{0,2})?$");
QValidator *currencyValidator = new QRegExpValidator(rx, this);
ui->unitPrice->setValidator(currencyValidator);
It turns out that I didn't escape the backslash:
QRegExp rx("^-?[0-9]{1,3}(?: [0-9]{3})*(?:\\.[0-9]{0,2})?$");
^
You can fix it by modifying your regex to this:
^-?[0-9]{1,3}(?: [0-9]{3})*(?:\.[0-9]{0,2})?$
Rather than keeping space and DOT inside the character class match them before the character classes.
Updated Regex Demo
This segment ([0-9]{1,3})+ means:
( Start of capturing group
[0-9] Match digit
{1,3} Match 1-3 of previous (digit)
) End of capturing group
+ Match 1 or more of previous (capturing group)
The result is that it will match 1 or more digits, capturing the last 1-3 digits.
Since {1,3} is greedy, it prefers matching 3, so for input 12345678, that means:
123 First repetition of capturing group
456 Second repetition of capturing group
78 Third repetition of capturing group
And since only the last repetition of the group is actually captured, you get 78, which is not what you want. See this regex101 for more info.
That was just the first of three segments of your regex. All three segments are mixing {n,m} with + or *. + is just shorthand for {1,}, * is shorthand for {0,}, and ? is shorthand for {0,1}.
So, x{1,3}+ really means x{1,3}{1,}, and that makes no sense, so stop doubling the repetitions.
So, what should your regex be? Probably something like this:
(-?[0-9]{1,3})(?: ([0-9]{3}))? ([0-9]{3}(?:\.[0-9]{2})?)
For input -190 254 254.22, that will return -190, 254, and 254.22. See this regex101 for full test.

How to exclude exact strings (not substrings) from matches in regex?

I've found lots of questions on here on how to exclude a substring from results, but I want to exclude lines that are exact matches and simply can't figure out how to do it.
With the test data below, how would I match everything except for 11 and 111?
0
1
00
01
10
11
000
001
010
011
100
101
110
111
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
I've tried various things, such as this:
^((?!11|111).)*$
But that excludes substring matches, when again I'm wanting to exclude exact matches.
Is this possible with regex? If so, how can excluding exact matches be achieved?
You need to have the end-of-line included in the negative look ahead:
^(?!(11|111)$).*$
See live demo (using your data)
Without including the end-of-line, you are only asserting that the input doesn't start with 11 or 111, when what you want is to assert is that the entire input (start to end) isn't 11 or 111.
Through PCRE verb (*SKIP)(*F),
^(?:11|111)$(*SKIP)(*F)|.+
DEMO
OR
^(?:(?!^(?:111|11)$).)++$
DEMO

regex replace preceding zeros with equal amount of space

I am searching for a regexp that replaces preceding zeros with equal amount of spaces in notepad++.
^(0+) gets all the zeros but how can i replace them with an equal amount of spaces?
00000000
00000001
00000072
00000073
00000070
00001105
00000176
should become
0
1
72
73
70
1105
176
(?<![1-9])0(?=\d)
Then just replace with the space character