Skip to content

Instantly share code, notes, and snippets.

@przemoc
Last active February 6, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save przemoc/2991958 to your computer and use it in GitHub Desktop.
Save przemoc/2991958 to your computer and use it in GitHub Desktop.
How to check whether alpha channel is used in ARGB32 QImage - http://stackoverflow.com/q/6157286/241521
// SPDX-License-Identifier: MIT
// Copyright (C) 2011 Przemyslaw Pawelczyk <przemoc@gmail.com>
//
// This script is licensed under the terms of the MIT license.
// https://opensource.org/licenses/MIT
bool useAlpha = false;
const uchar* pixelData = image.bits();
int bytes = image.byteCount();
for (const QRgb* pixel = reinterpret_cast<const QRgb*>(pixelData); bytes > 0; pixel++, bytes -= sizeof(QRgb)) {
if (qAlpha(*pixel) != UCHAR_MAX) {
useAlpha = true;
break;
}
}
@przemoc
Copy link
Author

przemoc commented Feb 6, 2018

commit 8da7c9bf6f34c96c80b177f15f555ec0697df568
Author: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date:   2018-02-06 15:36:44 +0100

    alpha.cpp: Add copyright notice and MIT license notice.

commit 1a05b8507b006819067a511d9e1612b00221cf67
Author: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date:   2018-02-06 15:37:49 +0100

    Add SPDX License Identifier.

    The Software Package Data Exchange (SPDX) is a good initiative, it has
    matured over time and deserves accelerated adoption in open-source.

    https://spdx.org/learn
    https://spdx.org/using-spdx
    https://spdx.org/license-list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment