nvdxt 사용 방법 (구형 버전)

Posted at 2007/06/05 13:41// Posted in d3d
다운로드


#include
"dxtlib.h"
#include <stdio.h>

static FILE* gs_fp  = NULL;

void WriteDTXnFile(unsigned long count, void* buf)
{
    if (!gs_fp)
        return;

    fwrite(buf, count, 1, gs_fp);
}

void ReadDTXnFile(unsigned long count, void* buf)
{
    if (!gs_fp)
        return;

    fread(buf, count, 1, gs_fp);
}


bool Save(const void* c_data, unsigned int width, unsigned int height, unsigned int byte_pitch, const char* outFileName)
{
    if (gs_fp)
        return false;

    CompressionOptions coptions;
    memset(&coptions, 0, sizeof(coptions));
    coptions.MipMapType             = dNoMipMaps; // dNoMipMaps, dSpecifyMipMaps, dUseExistingMipMaps, dGenerateMipMaps
    coptions.MIPFilterType          = dMIPFilterBox;
    coptions.bDitherEachMIPLevel    = coptions.bDitherColor;
    coptions.TextureType            = dTextureType2D;
    coptions.TextureFormat          = dDXT3;

    gs_fp = fopen(outFileName, "wb");
    if (!gs_fp)
        return false;

    nvDXTcompress((unsigned char*)c_data, width, height, byte_pitch, &coptions, 4, 0);
    fclose(gs_fp);

    gs_fp = NULL;
    return true;
}
이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/06/05 13:41 2007/06/05 13:41
Tag , ,
# devil  http://www.myevan.net/entry/%ED%8C%8C%EC%9D%B4%EC%8D%AC-devil-%EB%AA%A8%EB%93%88
import
wx

from devil import *
from ctypes import c_ubyte, string_at

class DDSHandler(wx.PyImageHandler):
    def __init__(self, *args, **kwargs):
        wx.PyImageHandler.__init__(self)

        self.SetName("DDS Image")
        self.SetExtension("dds")
        self.SetType(wx.BITMAP_TYPE_ANI + 1)
        self.SetMimeType("image/x-dds")

    def GetImageCount(self):
        return 1

    def LoadFile(self, image, stream, verbose, index):
        data = stream.read()

        if not ilLoadL(IL_TYPE_UNKNOWN, data, len(data)):
            return False

        ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE)

        image_width = ilGetInteger(IL_IMAGE_WIDTH)
        image_height = ilGetInteger(IL_IMAGE_HEIGHT)
        image_data = string_at(ilGetData(), image_width * image_height * 3)

        image.Destroy()
        image.Create(image_width, image_height)
        image.SetData(image_data)

        return True

    def SaveFile(self, image, stream, verbose):
        raise NotImplementedError

    def DoCanRead(self, stream):
        return True

wx.Image.AddHandler(DDSHandler())

class TestFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, pos=(0, 0), size=(320, 240))
        self.CentreOnScreen(wx.BOTH)

        self.bmp = wx.BitmapFromImage(wx.Image("test.dds"))
        self.Bind(wx.EVT_PAINT, self.__OnPaint)

    def __OnPaint(self, event):
        dc = wx.PaintDC(self)
        dc.DrawBitmap(self.bmp, 10, 10, True)

class TestApp(wx.App):
    def OnInit(self):
        "OnInit"
        frame = TestFrame(None, "TestApp")
        frame.Show()
        self.SetTopWindow(frame)
        return True

    def OnExit(self):
        "OnExit"
        pass

TestApp(redirect=False).MainLoop()

참고자료:
http://www.bitpim.org/pyxr/c/projects/bitpim/src/brewcompressedimage.py.html

이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/05/14 19:32 2007/05/14 19:32