Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

NoLifeStory

Junior Spellweaver
Joined
Dec 21, 2008
Messages
108
Reaction score
69
The new Henesys looks great! That's good code to be generating the NX so flawlessly.

M8Pegn8 - NoLifeStory - RaGEZONE Forums
 

Attachments

You must be registered for see attachments list
Last edited:
Newbie Spellweaver
Joined
Feb 12, 2014
Messages
7
Reaction score
1
The new Henesys looks great! That's good code to be generating the NX so flawlessly.

M8Pegn8 - NoLifeStory - RaGEZONE Forums

lol.

I am positive that it looks the exact same; rather you should be "amazed" at how fast it is at processing the map.
 

Attachments

You must be registered for see attachments list
Junior Spellweaver
Joined
Dec 21, 2008
Messages
108
Reaction score
69
lol.

I am positive that it looks the exact same; rather you should be "amazed" at how fast it is at processing the map.

In saying "new Henesys", I'm referring to the graphic updates that Nexon made. It used to look different so this look is new in my mind. It is amazing how fast it works.
 
That one pokemon thing
Loyal Member
Joined
Apr 3, 2010
Messages
1,766
Reaction score
621
Heya, my apologies for the late bump.
I seem to be getting "NoLifeStory stopped working" all of sudden. It worked perfectly before.

This is what the error log shows:
Code:
Starting up NoLifeClient
Using an atlas size of 16384
Loading map 100000000.img
	bgm: Bgm00/FloralLife
	cloud: 0
	fieldLimit: 0
	fly: 0
	forcedReturn: 999999999
	hideMinimap: 0
	mapMark: Henesys
	mobRate: 1.000000
	moveLimit: 0
	noMapCmd: 0
	onUserEnter: explorationPoint
	returnMap: 100000000
	swim: 0
	town: 1
	version: 10
Unhandled exception!
Printing stack trace
7ff68c5a3110: a:\files\coding\nolifestory\src\client\main.cpp:45 nl::print_stack_trace
7ff68c5a30d0: a:\files\coding\nolifestory\src\client\main.cpp:62 nl::terminate_handler
7ff9a62c482c: a:\files\coding\nolifestory\src\client\main.cpp:62 terminate
7ff68c59c1f0: f:\dd\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:75 __scrt_unhandled_exception_filter
7ff9b0ebe020: f:\dd\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:75 UnhandledExceptionFilter
7ff9b3a2b980: f:\dd\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:75 memset
7ff9b3a19808: f:\dd\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:75 _C_specific_handler
7ff9b3a2a6e0: f:\dd\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:75 _chkstk
7ff9b39d2578: f:\dd\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:75 RtlRaiseException
7ff9b39d2578: f:\dd\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:75 RtlRaiseException
7ff9b0de8318: f:\dd\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:75 RaiseException
7ff9a62c5378: f:\dd\vctools\crt\vcstartup\src\utility\utility_desktop.cpp:75 CxxThrowException
7ff68c5a0e20: a:\files\coding\nolifestory\src\client\window.cpp:181 nl::window::check_errors
7ff68c5a1220: a:\files\coding\nolifestory\src\client\window.cpp:205 nl::window::update
7ff68c59ec70: a:\files\coding\nolifestory\src\client\game.cpp:58 nl::game::play
7ff68c5a2f90: a:\files\coding\nolifestory\src\client\main.cpp:80 nl::client
7ff68c5a2f70: a:\files\coding\nolifestory\src\client\main.cpp:89 WinMain
7ff68c59bcf0: f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:232 __scrt_common_main_seh
7ff9b2d31604: f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:232 BaseThreadInitThunk
7ff9b3a06490: f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:232 RtlUserThreadStart
End of stack trace

I'm not asking for a solution, just a push in the general direction.
 
Joined
Apr 5, 2008
Messages
663
Reaction score
537
Heya, my apologies for the late bump.
I seem to be getting "NoLifeStory stopped working" all of sudden. It worked perfectly before.

This is what the error log shows:
*snip*

I'm not asking for a solution, just a push in the general direction.

Hmmm, it looks like an OpenGL error.
Would you mind getting the OpenGL extension viewer and sending me the report?
 
That one pokemon thing
Loyal Member
Joined
Apr 3, 2010
Messages
1,766
Reaction score
621
Hmmm, it looks like an OpenGL error.
Would you mind getting the OpenGL extension viewer and sending me the report?

Code:
Renderer: GeForce GTX 675M/PCIe/SSE2
Vendor: NVIDIA Corporation
Memory: 2048 MB
Version: 4.4.0 NVIDIA 340.82
Shading language version: 4.40 NVIDIA via Cg compiler




Max texture size: 16384 x 16384
Max vertex texture image units: 32
Max texture image units: 32
Max geometry texture units: 32
Max anisotropic filtering value: 16
Max viewport size: 16384 x 16384
Max Clip Distances: 8
Max samples: 32




Extensions: 334


GL_AMD_multi_draw_indirect
GL_ARB_arrays_of_arrays
GL_ARB_base_instance
GL_ARB_blend_func_extended
GL_ARB_buffer_storage
GL_ARB_clear_buffer_object
GL_ARB_clear_texture
GL_ARB_clip_control
GL_ARB_color_buffer_float
GL_ARB_compressed_texture_pixel_storage
GL_ARB_compute_shader
GL_ARB_compute_variable_group_size
GL_ARB_conditional_render_inverted
GL_ARB_conservative_depth
GL_ARB_copy_buffer
GL_ARB_copy_image
GL_ARB_cull_distance
GL_ARB_debug_output
GL_ARB_depth_buffer_float
GL_ARB_depth_clamp
GL_ARB_depth_texture
GL_ARB_derivative_control
GL_ARB_direct_state_access
GL_ARB_draw_buffers
GL_ARB_draw_buffers_blend
GL_ARB_draw_elements_base_vertex
GL_ARB_draw_indirect
GL_ARB_draw_instanced
GL_ARB_enhanced_layouts
GL_ARB_ES2_compatibility
GL_ARB_ES3_1_compatibility
GL_ARB_ES3_compatibility
GL_ARB_explicit_attrib_location
GL_ARB_explicit_uniform_location
GL_ARB_fragment_coord_conventions
GL_ARB_fragment_layer_viewport
GL_ARB_fragment_program
GL_ARB_fragment_program_shadow
GL_ARB_fragment_shader
GL_ARB_framebuffer_no_attachments
GL_ARB_framebuffer_object
GL_ARB_framebuffer_sRGB
GL_ARB_geometry_shader4
GL_ARB_get_program_binary
GL_ARB_get_texture_sub_image
GL_ARB_gpu_shader5
GL_ARB_gpu_shader_fp64
GL_ARB_half_float_pixel
GL_ARB_half_float_vertex
GL_ARB_imaging
GL_ARB_indirect_parameters
GL_ARB_instanced_arrays
GL_ARB_internalformat_query
GL_ARB_internalformat_query2
GL_ARB_invalidate_subdata
GL_ARB_map_buffer_alignment
GL_ARB_map_buffer_range
GL_ARB_multi_bind
GL_ARB_multi_draw_indirect
GL_ARB_multisample
GL_ARB_multitexture
GL_ARB_occlusion_query
GL_ARB_occlusion_query2
GL_ARB_pipeline_statistics_query
GL_ARB_pixel_buffer_object
GL_ARB_point_parameters
GL_ARB_point_sprite
GL_ARB_program_interface_query
GL_ARB_provoking_vertex
GL_ARB_query_buffer_object
GL_ARB_robust_buffer_access_behavior
GL_ARB_robustness
GL_ARB_sample_shading
GL_ARB_sampler_objects
GL_ARB_seamless_cube_map
GL_ARB_separate_shader_objects
GL_ARB_shader_atomic_counters
GL_ARB_shader_bit_encoding
GL_ARB_shader_draw_parameters
GL_ARB_shader_group_vote
GL_ARB_shader_image_load_store
GL_ARB_shader_image_size
GL_ARB_shader_objects
GL_ARB_shader_precision
GL_ARB_shader_storage_buffer_object
GL_ARB_shader_subroutine
GL_ARB_shader_texture_image_samples
GL_ARB_shader_texture_lod
GL_ARB_shading_language_100
GL_ARB_shading_language_420pack
GL_ARB_shading_language_include
GL_ARB_shading_language_packing
GL_ARB_shadow
GL_ARB_sparse_buffer
GL_ARB_sparse_texture
GL_ARB_stencil_texturing
GL_ARB_sync
GL_ARB_tessellation_shader
GL_ARB_texture_barrier
GL_ARB_texture_border_clamp
GL_ARB_texture_buffer_object
GL_ARB_texture_buffer_object_rgb32
GL_ARB_texture_buffer_range
GL_ARB_texture_compression
GL_ARB_texture_compression_bptc
GL_ARB_texture_compression_rgtc
GL_ARB_texture_cube_map
GL_ARB_texture_cube_map_array
GL_ARB_texture_env_add
GL_ARB_texture_env_combine
GL_ARB_texture_env_crossbar
GL_ARB_texture_env_dot3
GL_ARB_texture_float
GL_ARB_texture_gather
GL_ARB_texture_mirror_clamp_to_edge
GL_ARB_texture_mirrored_repeat
GL_ARB_texture_multisample
GL_ARB_texture_non_power_of_two
GL_ARB_texture_query_levels
GL_ARB_texture_query_lod
GL_ARB_texture_rectangle
GL_ARB_texture_rg
GL_ARB_texture_rgb10_a2ui
GL_ARB_texture_stencil8
GL_ARB_texture_storage
GL_ARB_texture_storage_multisample
GL_ARB_texture_swizzle
GL_ARB_texture_view
GL_ARB_timer_query
GL_ARB_transform_feedback2
GL_ARB_transform_feedback3
GL_ARB_transform_feedback_instanced
GL_ARB_transform_feedback_overflow_query
GL_ARB_transpose_matrix
GL_ARB_uniform_buffer_object
GL_ARB_vertex_array_bgra
GL_ARB_vertex_array_object
GL_ARB_vertex_attrib_64bit
GL_ARB_vertex_attrib_binding
GL_ARB_vertex_buffer_object
GL_ARB_vertex_program
GL_ARB_vertex_shader
GL_ARB_vertex_type_10f_11f_11f_rev
GL_ARB_vertex_type_2_10_10_10_rev
GL_ARB_viewport_array
GL_ARB_window_pos
GL_ATI_draw_buffers
GL_ATI_texture_float
GL_ATI_texture_mirror_once
GL_EXT_abgr
GL_EXT_bgra
GL_EXT_bindable_uniform
GL_EXT_blend_color
GL_EXT_blend_equation_separate
GL_EXT_blend_func_separate
GL_EXT_blend_minmax
GL_EXT_blend_subtract
GL_EXT_Cg_shader
GL_EXT_compiled_vertex_array
GL_EXT_depth_bounds_test
GL_EXT_direct_state_access
GL_EXT_draw_buffers2
GL_EXT_draw_instanced
GL_EXT_draw_range_elements
GL_EXT_fog_coord
GL_EXT_framebuffer_blit
GL_EXT_framebuffer_multisample
GL_EXT_framebuffer_multisample_blit_scaled
GL_EXT_framebuffer_object
GL_EXT_framebuffer_sRGB
GL_EXT_geometry_shader4
GL_EXT_gpu_program_parameters
GL_EXT_gpu_shader4
GL_EXT_import_sync_object
GL_EXT_multi_draw_arrays
GL_EXT_packed_depth_stencil
GL_EXT_packed_float
GL_EXT_packed_pixels
GL_EXT_pixel_buffer_object
GL_EXT_point_parameters
GL_EXT_polygon_offset_clamp
GL_EXT_provoking_vertex
GL_EXT_rescale_normal
GL_EXT_secondary_color
GL_EXT_separate_shader_objects
GL_EXT_separate_specular_color
GL_EXT_shader_image_load_store
GL_EXT_shader_integer_mix
GL_EXT_shadow_funcs
GL_EXT_stencil_two_side
GL_EXT_stencil_wrap
GL_EXT_texture3D
GL_EXT_texture_array
GL_EXT_texture_buffer_object
GL_EXT_texture_compression_dxt1
GL_EXT_texture_compression_latc
GL_EXT_texture_compression_rgtc
GL_EXT_texture_compression_s3tc
GL_EXT_texture_cube_map
GL_EXT_texture_edge_clamp
GL_EXT_texture_env_add
GL_EXT_texture_env_combine
GL_EXT_texture_env_dot3
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_integer
GL_EXT_texture_lod
GL_EXT_texture_lod_bias
GL_EXT_texture_mirror_clamp
GL_EXT_texture_object
GL_EXT_texture_shared_exponent
GL_EXT_texture_sRGB
GL_EXT_texture_sRGB_decode
GL_EXT_texture_storage
GL_EXT_texture_swizzle
GL_EXT_timer_query
GL_EXT_transform_feedback2
GL_EXT_vertex_array
GL_EXT_vertex_array_bgra
GL_EXT_vertex_attrib_64bit
GL_EXTX_framebuffer_mixed_formats
GL_IBM_rasterpos_clip
GL_IBM_texture_mirrored_repeat
GL_KHR_blend_equation_advanced
GL_KHR_context_flush_control
GL_KHR_debug
GL_KHR_robust_buffer_access_behavior
GL_KHR_robustness
GL_KTX_buffer_region
GL_NV_bindless_multi_draw_indirect
GL_NV_bindless_multi_draw_indirect_count
GL_NV_blend_equation_advanced
GL_NV_blend_square
GL_NV_compute_program5
GL_NV_conditional_render
GL_NV_copy_depth_to_color
GL_NV_copy_image
GL_NV_depth_buffer_float
GL_NV_depth_clamp
GL_NV_draw_texture
GL_NV_ES1_1_compatibility
GL_NV_ES3_1_compatibility
GL_NV_explicit_multisample
GL_NV_fence
GL_NV_float_buffer
GL_NV_fog_distance
GL_NV_fragment_program
GL_NV_fragment_program2
GL_NV_fragment_program_option
GL_NV_framebuffer_multisample_coverage
GL_NV_geometry_shader4
GL_NV_gpu_program4
GL_NV_gpu_program4_1
GL_NV_gpu_program5
GL_NV_gpu_program5_mem_extended
GL_NV_gpu_program_fp64
GL_NV_gpu_shader5
GL_NV_half_float
GL_NV_light_max_exponent
GL_NV_multisample_coverage
GL_NV_multisample_filter_hint
GL_NV_occlusion_query
GL_NV_packed_depth_stencil
GL_NV_parameter_buffer_object
GL_NV_parameter_buffer_object2
GL_NV_path_rendering
GL_NV_pixel_data_range
GL_NV_point_sprite
GL_NV_primitive_restart
GL_NV_register_combiners
GL_NV_register_combiners2
GL_NV_shader_atomic_counters
GL_NV_shader_atomic_float
GL_NV_shader_buffer_load
GL_NV_shader_storage_buffer_object
GL_NV_shader_thread_group
GL_NV_texgen_reflection
GL_NV_texture_barrier
GL_NV_texture_compression_vtc
GL_NV_texture_env_combine4
GL_NV_texture_expand_normal
GL_NV_texture_multisample
GL_NV_texture_rectangle
GL_NV_texture_shader
GL_NV_texture_shader2
GL_NV_texture_shader3
GL_NV_transform_feedback
GL_NV_transform_feedback2
GL_NV_uniform_buffer_unified_memory
GL_NV_vertex_array_range
GL_NV_vertex_array_range2
GL_NV_vertex_attrib_integer_64bit
GL_NV_vertex_buffer_unified_memory
GL_NV_vertex_program
GL_NV_vertex_program1_1
GL_NV_vertex_program2
GL_NV_vertex_program2_option
GL_NV_vertex_program3
GL_NVX_conditional_render
GL_NVX_gpu_memory_info
GL_S3_s3tc
GL_SGIS_generate_mipmap
GL_SGIS_texture_lod
GL_SGIX_depth_texture
GL_SGIX_shadow
GL_SUN_slice_accum
GL_WIN_swap_hint
WGL_ARB_buffer_region
WGL_ARB_context_flush_control
WGL_ARB_create_context
WGL_ARB_create_context_profile
WGL_ARB_create_context_robustness
WGL_ARB_extensions_string
WGL_ARB_make_current_read
WGL_ARB_multisample
WGL_ARB_pbuffer
WGL_ARB_pixel_format
WGL_ARB_pixel_format_float
WGL_ARB_render_texture
WGL_ATI_pixel_format_float
WGL_EXT_create_context_es2_profile
WGL_EXT_create_context_es_profile
WGL_EXT_extensions_string
WGL_EXT_framebuffer_sRGB
WGL_EXT_pixel_format_packed_float
WGL_EXT_swap_control
WGL_EXT_swap_control_tear
WGL_NV_delay_before_swap
WGL_NV_DX_interop
WGL_NV_DX_interop2
WGL_NV_float_buffer
WGL_NV_multisample_coverage
WGL_NV_render_depth_texture
WGL_NV_render_texture_rectangle
WGL_NVX_DX_interop


Core features
v3.0 (100 % - 23/23)
v3.1 (100 % - 8/8)
v3.2 (100 % - 10/10)
v3.3 (100 % - 10/10)
v4.0 (100 % - 14/14)
v4.1 (100 % - 7/7)
v4.2 (100 % - 13/13)
v4.3 (100 % - 23/23)
v4.4 (100 % - 10/10)
v4.5 (90 % - 10/11)


OpenGL driver version check (Current: 4.4.0 NVIDIA 340.82, Latest known: 9.18.13.4082):
Outdated version of display drivers detected
According the database, you are might be not using the latest version of display drivers for your video card.


No ICD registry entry
The current OpenGL driver doesn't expose the SOFTWARE/Microsoft/Windows (NT)/CurrentVersion/OpenGLDrivers registry entry. Unable to detect the driver version, driver revision name and filename.


Extension verification: 
GL_EXT_color_subtable was not found, but has the entry point glColorSubTableEXT 
GL_EXT_paletted_texture was not found, but has the entry point glColorTableEXT 
GL_EXT_paletted_texture was not found, but has the entry point glGetColorTableEXT 
GL_EXT_paletted_texture was not found, but has the entry point glGetColorTableParameterfvEXT 
GL_EXT_paletted_texture was not found, but has the entry point glGetColorTableParameterivEXT 
GL_ARB_compatibility was not found, but is available in driver version 9.18.13.4082
Got it working, though. My laptop was opening the program with integrated graphics, and I had to change it to my NVIDIA-processor.

EDIT: Nevermind. When I tried the second time, it crashed like before.
EDIT: After installing some drivers, it seems to be working. Updated the report.
 
Last edited:
Joined
Oct 7, 2010
Messages
4
Reaction score
1
Cool story bro.
Looks like my project.
But my client is reading resources from the original WZ files instead of reformating them first.
And looks like you only got client by now while I already got server side working ^_^
 
Joined
Oct 7, 2010
Messages
4
Reaction score
1
Is your project on Git? Can we see it?

I don't use any kind of version control system sorry.
But I think I will open a Thread about it very soon.
Basically its made to run on linux as well as on windows so I used LWJGL and JWzLib to create a standalone java opengl client.
The server is also written in java.
More detail soon ^_^
 
Joined
Apr 5, 2008
Messages
663
Reaction score
537
Cool story bro.
Looks like my project.
But my client is reading resources from the original WZ files instead of reformating them first.
And looks like you only got client by now while I already got server side working ^_^
NoLifeStory used to use WZ file reading, however I switched to using the NX format for performance reasons.
At one point NLS was working with Vana ( , ), but networking has not yet been re-added because I hate networking in C++.
I do wish you luck on your project.
But do please share your project to the world over Github.
 
Joined
Oct 7, 2010
Messages
4
Reaction score
1
NoLifeStory used to use WZ file reading, however I switched to using the NX format for performance reasons.
At one point NLS was working with Vana ( , ), but networking has not yet been re-added because I hate networking in C++.
I do wish you luck on your project.
But do please share your project to the world over Github.

well for the truth this project was made for a private use... for me and my buddies to play sometimes
like at the old good days.
but I guess it will be fine if I release the code, because after all its doesn't have any of Nexon's code/content so its absolutely my own property.

its still used the Wz files to read from but I don't have to attache them to my software so basically its legal ?
 
Newbie Spellweaver
Joined
Aug 30, 2014
Messages
56
Reaction score
31
At one point NLS was working with Vana ( , ), but networking has not yet been re-added because I hate networking in C++.
Too bad it will never be re-added because C++ networking is bad, and you're too lazy to recode the entire client it in rust. ;_;
 
Joined
Aug 10, 2008
Messages
858
Reaction score
516
any way I made few tests...
JWzLib parsing time: 1220ms
Zip file parsing time: 15ms
retep998 I SEE WHAT YOU DID THERE XD

WZ = SLOW AS HELL

Wizet's packaging method is fairly dated and it hasn't changed since I started in 2008 (and probably earlier, but I've never touched versions before v53/5). I doubt Nexon really cares about optimizing the format, so third party changes would be necessary. Though the impractical aspect is if you want to take content from the official game, it may be a pain in the butt to do so. Furthermore, the amount of tools for manipulating NX files also seems lacking compared to the WZ format (which has many C# tools for doing edits -> as well as some Delphi tools, etc). Keep in mind that Nexon's server files (based on the BMS server files leak) are segmented into IMG files rather than full WZ files as well.
 
Initiate Mage
Joined
Nov 27, 2014
Messages
3
Reaction score
1
Hello, kinda off-topic here, but maybe it would be of interest for the original poster.

There's a new format for the bitmaps inside the wz files. Besides the existing ones (1, 2, 513, 517) the new format (1026) holds scrambled pixel data. If you try to dump the data into a png, you might see a MapleStory picture in it but with alpha + colors distorted, a correct width and 1/4 the height registered in the bitmap node.

For test purposes, I am using the kms 1.2.221 client. If you navigate to Mob/8940039.img, you will notice bitmap nodes with this new format. Supposedly you should be seeing this thing over here .
 
Joined
Apr 5, 2008
Messages
663
Reaction score
537
Hello, kinda off-topic here, but maybe it would be of interest for the original poster.

There's a new format for the bitmaps inside the wz files. Besides the existing ones (1, 2, 513, 517) the new format (1026) holds scrambled pixel data. If you try to dump the data into a png, you might see a MapleStory picture in it but with alpha + colors distorted, a correct width and 1/4 the height registered in the bitmap node.

For test purposes, I am using the kms 1.2.221 client. If you navigate to Mob/8940039.img, you will notice bitmap nodes with this new format. Supposedly you should be seeing this thing over here .

I've noticed those bitmaps too, but as of yet I have been unable to piece together something sensible.
If you manage to figure it out I'd very much appreciate it.
 
Initiate Mage
Joined
Nov 27, 2014
Messages
3
Reaction score
1
Ok, this is what I got so far:
The format flag should no longer be considered as the sum of format1 and format2. Why? There are combinations that are format1=1, format2=1 and format1=2, format2=0. Both combinations generate different results with current algorithms.

All possible combinations so far in all clients are: 1-0, 1-1, 1-2, 2-0, 513-0, 513-4, 1026-0.

It seems that combinations with the same format1 share similar procedures to generate the correct bitmap. For example, 1-0 and 1-1 both needs to expand the pixels from 2 to 4 bytes. With 513 occurs something similar.

They are using some kind of interpolation technique to generate missing pixels. In 1-1 bitmaps, for every pixel there are 3 missing as opposed to 1-0, where all the pixels exists. Nearest neighbor, bilinear or bicubic doesnt produce the expected results.
 
Experienced Elementalist
Joined
Feb 15, 2010
Messages
201
Reaction score
296
The format 1026 is dds image.I steal someone's code(from China)

Code:
enum {
	kDxt1 = 1 << 0,
	kDxt3 = 1 << 1,
	kDxt5 = 1 << 2,
	kColourClusterFit = 1 << 3,
	kColourRangeFit = 1 << 4,
	kColourMetricPerceptual = 1 << 5,
	kColourMetricUniform = 1 << 6,
	kWeightColourByAlpha = 1 << 7,
	kColourIterativeClusterFit = 1 << 8,
};

void dxt_alpha_dxt3(unsigned char *argb, unsigned char *block) {
	unsigned char *bytes = block;
	int i;

	// unpack the alpha values pairwise
	for (i = 0; 8 > i; ++i) {
		// quantise down to 4 bits
		unsigned char quant = bytes[i];

		// unpack the values
		unsigned char lo = quant & 0x0f;
		unsigned char hi = quant & 0xf0;

		// convert back up to bytes
		argb[8 * i + 3] = lo | (lo << 4);
		argb[8 * i + 7] = hi | (hi >> 4);
	}
}

void dxt_alpha_dxt5(unsigned char *argb, unsigned char *block) {
	// get the two alpha values
	unsigned char *bytes = block;
	int alpha0 = bytes[0];
	int alpha1 = bytes[1];

	// compare the values to build the codebook
	unsigned char codes[8];

	// decode the indices
	unsigned char indices[16];
	unsigned char *src = bytes + 2;
	unsigned char *dest = indices;

	int i, j;

	codes[0] = alpha0;
	codes[1] = alpha1;

	if (alpha0 <= alpha1) {
		// use 5-alpha codebook
		for (i = 1; 5 > i; ++i) codes[1 + i] = ((5 - i) * alpha0 + i * alpha1) / 5;

		codes[6] = 0;
		codes[7] = 255;
	} else {
		// use 7-alpha codebook
		for (i = 1; 7 > i; ++i) codes[1 + i] = ((7 - i) * alpha0 + i * alpha1) / 7;
	}

	for (i = 0; 2 > i; ++i) {
		// grab 3 bytes
		int value = 0;

		for (j = 0; 3 > j; ++j) {
			int byte_ = *src++;

			value |= (byte_ << 8 * j);
		}

		// unpack 8 3-bit values from it
		for (j = 0; 8 > j; ++j) {
			int index = (value >> 3 * j) & 0x7;

			*dest++ = index;
		}
	}

	// write out the indexed codebook values
	for (i = 0; 16 > i; ++i) argb[4 * i + 3] = codes[indices[i]];
}

int dxt_unpack565(unsigned char *packed, unsigned char *colour) {
	// build the packed value
	int value = packed[0] | (packed[1] << 8);

	// get the components in the stored range
	unsigned char red = (value >> 11) & 0x1f;
	unsigned char green = (value >> 5) & 0x3f;
	unsigned char blue = value & 0x1f;

	// scale up to 8 bits
	colour[0] = (blue << 3) | (blue >> 2);
	colour[1] = (green << 2) | (green >> 4);
	colour[2] = (red << 3) | (red >> 2);
	colour[3] = 255;

	// return the value
	return value;
}

void dxt_colour(unsigned char *argb, unsigned char *block, int isDxt1) {
	// get the block bytes
	unsigned char *bytes = block;

	// unpack the endpoints
	unsigned char codes[16];
	int a = dxt_unpack565(bytes, codes);
	int b = dxt_unpack565(bytes + 2, codes + 4);

	// unpack the indices
	unsigned char indices[16];

	int i, j;

	// generate the midpoints
	for (i = 0; 3 > i; ++i) {
		int c = codes[i];
		int d = codes[4 + i];

		if (isDxt1 && a <= b) {
			codes[8 + i] = (c + d) >> 1;
			codes[12 + i] = 0;
		} else {
			codes[8 + i] = (2 * c + d) / 3;
			codes[12 + i] = (c + 2 * d) / 3;
		}
	}

	// fill in alpha for the intermediate values
	codes[8 + 3] = 255;
	codes[12 + 3] = (isDxt1 && a <= b) ? 0 : 255;

	for (i = 0; 4 > i; ++i) {
		unsigned char *ind = indices + (i << 2);
		unsigned char packed = bytes[4 + i];

		ind[0] = packed & 0x3;
		ind[1] = (packed >> 2) & 0x3;
		ind[2] = (packed >> 4) & 0x3;
		ind[3] = (packed >> 6) & 0x3;
	}

	// store out the colours
	for (i = 0; 16 > i; ++i) {
		unsigned char offset = indices[i] << 2;

		for (j = 0; 4 > j; ++j) argb[(i << 2) + j] = codes[offset + j];
	}
}

int dxt_fix_flags(int flags) {
	// grab the flag bits
	int method = flags & (kDxt1 | kDxt3 | kDxt5);
	int fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit);
	int metric = flags & (kColourMetricPerceptual | kColourMetricUniform);
	int extra = flags & kWeightColourByAlpha;

	// set defaults
	if (method != kDxt3 && method != kDxt5) method = kDxt1;
	if (fit != kColourRangeFit) fit = kColourClusterFit;
	if (metric != kColourMetricUniform) metric = kColourMetricPerceptual;

	// done
	return method | fit | metric | extra;
}

void dxt_decompress(unsigned char *argb, unsigned char *block, int flags) {
	// get the block locations
	unsigned char *colourBlock = block;
	unsigned char *alphaBock = block;

	// fix any bad flags
	flags = dxt_fix_flags(flags);

	if (flags & (kDxt3 | kDxt5)) colourBlock = block + 8;

	// decompress colour
	dxt_colour(argb, colourBlock, flags & kDxt1);

	// decompress alpha separately if necessary
	if (flags & kDxt3) dxt_alpha_dxt3(argb, alphaBock);
	else if (flags & kDxt5) dxt_alpha_dxt5(argb, alphaBock);
}

[B][COLOR="#FF0000"]void dxt_decompress_image(unsigned char *argb, int width, int height, unsigned char *blocks, int flags)[/COLOR][/B] {
	// initialise the block input
	unsigned char *sourceBlock = blocks;
	int bytesPerBlock = (flags & kDxt1) ? 8 : 16;

	int i, x, y, px, py;

	// fix any bad flags
	flags = dxt_fix_flags(flags);

	// loop over blocks
	for (y = 0; y < height; y += 4) {
		for (x = 0; x < width; x += 4) {
			// decompress the block
			unsigned char targetRgba[16 << 2];

			// write the decompressed pixels to the correct image locations
			unsigned char *sourcePixel = targetRgba;

			dxt_decompress(targetRgba, sourceBlock, flags);

			for (py = 0; 4 > py; ++py) {
				for (px = 0; 4 > px; ++px) {
					// get the target location
					int sx = x + px;
					int sy = y + py;

					if (sx < width && sy < height) {
						unsigned char *targetPixel = argb + 4 * (width * sy + sx);

						// copy the rgba value
						for (i = 0; 4 > i; ++i) *targetPixel++ = *sourcePixel++;
					} else {
						// skip this pixel as its outside the image
						sourcePixel += 4;
					}
				}
			}

			// advance
			sourceBlock += bytesPerBlock;
		}
	}
}


and use it:
C# code
Code:
	unsafe private Image generate_image(byte[] pixels)
	{
		Bitmap bitmap = new Bitmap(width, height, 0x0205 == format ? PixelFormat.Format1bppIndexed : 0x0201 == format ? PixelFormat.Format16bppRgb565 : PixelFormat.Format32bppArgb);
		BitmapData data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat);
		byte* pointer = (byte*)data.Scan0;

		switch (format)
		{
			case 0x0001:
				for (int index = 0, length = 2 * width * height; length > index; pointer = pointer + 4)
				{
					pointer[0] = (byte)((pixels[index] & 0x0f) + (pixels[index] << 0x04));
					pointer[1] = (byte)((pixels[index] & 0xf0) + (pixels[index++] >> 0x04));
					pointer[2] = (byte)((pixels[index] & 0x0f) + (pixels[index] << 0x04));
					pointer[3] = (byte)((pixels[index] & 0xf0) + (pixels[index++] >> 0x04));
				}
				break;

			case 0x0002: Marshal.Copy(pixels, 0, data.Scan0, data.Stride * height); break;

			case 0x0201:
				for (int index = 0, stride = 2 * width; height > index; ++index)
					Marshal.Copy(pixels, stride * index, new IntPtr((int)data.Scan0 + data.Stride * index), stride);

				break;

			case 0x0205:
				ColorPalette palette = bitmap.Palette;

				palette.Entries[0] = Color.FromArgb(0xff, 0x52, 0x86, 0xef);

				bitmap.Palette = palette;

				break;

			case 0x0402:
				fixed (byte* raw = pixels)
					[B]decompress_image[/B]((byte*)data.Scan0, width, height, raw, 2);

				break;
		}

		bitmap.UnlockBits(data);

		return bitmap;
	}
 
Back
Top